pcap: Rename packages to org.eclipse.tracecompass.*
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.pcap.core.tests / src / org / eclipse / tracecompass / tmf / pcap / core / tests / analysis / StreamListAnalysisTest.java
1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Vincent Perot - Initial API and implementation
11 ******************************************************************************/
12
13 package org.eclipse.tracecompass.tmf.pcap.core.tests.analysis;
14
15 import static org.junit.Assert.assertEquals;
16 import static org.junit.Assert.assertFalse;
17 import static org.junit.Assert.assertNotNull;
18 import static org.junit.Assert.assertTrue;
19 import static org.junit.Assert.fail;
20 import static org.junit.Assume.assumeTrue;
21
22 import org.eclipse.tracecompass.internal.tmf.pcap.core.analysis.StreamListAnalysis;
23 import org.eclipse.tracecompass.internal.tmf.pcap.core.event.TmfPacketStreamBuilder;
24 import org.eclipse.tracecompass.internal.tmf.pcap.core.protocol.TmfPcapProtocol;
25 import org.eclipse.tracecompass.internal.tmf.pcap.core.trace.PcapTrace;
26 import org.eclipse.tracecompass.pcap.core.tests.shared.PcapTestTrace;
27 import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
28 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
29 import org.junit.Test;
30
31 /**
32 * JUnit that test the StreamListAnalysis class.
33 *
34 * @author Vincent Perot
35 */
36 public class StreamListAnalysisTest {
37
38 /**
39 * Method that tests the constructor.
40 */
41 @Test
42 public void constructorTest() {
43 try (StreamListAnalysis analysis = new StreamListAnalysis();) {
44 analysis.setId(StreamListAnalysis.ID);
45 for (TmfPcapProtocol protocol : TmfPcapProtocol.values()) {
46 if (protocol.supportsStream()) {
47 assertNotNull(analysis.getBuilder(protocol));
48 }
49 }
50 assertFalse(analysis.isFinished());
51 }
52 }
53
54 /**
55 * Method that tests canExecute().
56 *
57 * @throws TmfTraceException
58 * Thrown when the trace cannot be initialized. Fails the test.
59 */
60 @Test
61 public void canExecuteTest() throws TmfTraceException {
62 PcapTestTrace trace = PcapTestTrace.MOSTLY_TCP;
63 assumeTrue(trace.exists());
64 String path = trace.getPath().toString();
65 try (PcapTrace pcapTrace = new PcapTrace();
66 StreamListAnalysis analysis = new StreamListAnalysis();) {
67 analysis.setId(StreamListAnalysis.ID);
68 pcapTrace.initTrace(null, path, null);
69 assertTrue(analysis.canExecute(pcapTrace));
70 }
71 }
72
73 /**
74 * Method that execute the analysis and verify the results.
75 *
76 * @throws TmfAnalysisException
77 * Thrown when an analysis error occurs during the setup or
78 * execution. Fails the test.
79 * @throws TmfTraceException
80 * Thrown when the trace cannot be initialized. Fails the test.
81 */
82 @Test
83 public void executeAnalysisTest() throws TmfAnalysisException, TmfTraceException {
84 PcapTestTrace trace = PcapTestTrace.MOSTLY_TCP;
85 assumeTrue(trace.exists());
86 String path = trace.getPath().toString();
87 try (PcapTrace pcapTrace = new PcapTrace();
88 StreamListAnalysis analysis = new StreamListAnalysis();) {
89 pcapTrace.initTrace(null, path, null);
90 analysis.setId(StreamListAnalysis.ID);
91 analysis.setTrace(pcapTrace);
92 analysis.schedule();
93 analysis.waitForCompletion();
94
95 // Verify that builders are not empty.
96 TmfPacketStreamBuilder builder = analysis.getBuilder(TmfPcapProtocol.ETHERNET_II);
97 if (builder == null) {
98 fail("The PacketStreamBuilder is null!");
99 return;
100 }
101 assertEquals(1, builder.getNbStreams());
102
103 builder = analysis.getBuilder(TmfPcapProtocol.IPV4);
104 if (builder == null) {
105 fail("The PacketStreamBuilder is null!");
106 return;
107 }
108 assertEquals(3, builder.getNbStreams());
109
110 builder = analysis.getBuilder(TmfPcapProtocol.TCP);
111 if (builder == null) {
112 fail("The PacketStreamBuilder is null!");
113 return;
114 }
115 assertEquals(2, builder.getNbStreams());
116
117 builder = analysis.getBuilder(TmfPcapProtocol.UDP);
118 if (builder == null) {
119 fail("The PacketStreamBuilder is null!");
120 return;
121 }
122 assertEquals(1, builder.getNbStreams());
123 }
124 }
125
126 }
This page took 0.03772 seconds and 5 git commands to generate.