pcap: Remove AutoCloseable from PcapTrace
[deliverable/tracecompass.git] / pcap / 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 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 analysis.dispose();
53 }
54
55 /**
56 * Method that tests canExecute().
57 *
58 * @throws TmfTraceException
59 * Thrown when the trace cannot be initialized. Fails the test.
60 */
61 @Test
62 public void canExecuteTest() throws TmfTraceException {
63 PcapTestTrace trace = PcapTestTrace.MOSTLY_TCP;
64 assumeTrue(trace.exists());
65 String path = trace.getPath().toString();
66 PcapTrace pcapTrace = new PcapTrace();
67 StreamListAnalysis analysis = new StreamListAnalysis();
68
69 analysis.setId(StreamListAnalysis.ID);
70 pcapTrace.initTrace(null, path, null);
71 assertTrue(analysis.canExecute(pcapTrace));
72
73 analysis.dispose();
74 pcapTrace.dispose();
75 }
76
77 /**
78 * Method that execute the analysis and verify the results.
79 *
80 * @throws TmfAnalysisException
81 * Thrown when an analysis error occurs during the setup or
82 * execution. Fails the test.
83 * @throws TmfTraceException
84 * Thrown when the trace cannot be initialized. Fails the test.
85 */
86 @Test
87 public void executeAnalysisTest() throws TmfAnalysisException, TmfTraceException {
88 PcapTestTrace trace = PcapTestTrace.MOSTLY_TCP;
89 assumeTrue(trace.exists());
90 String path = trace.getPath().toString();
91 PcapTrace pcapTrace = new PcapTrace();
92 StreamListAnalysis analysis = new StreamListAnalysis();
93
94 pcapTrace.initTrace(null, path, null);
95 analysis.setId(StreamListAnalysis.ID);
96 analysis.setTrace(pcapTrace);
97 analysis.schedule();
98 analysis.waitForCompletion();
99
100 // Verify that builders are not empty.
101 TmfPacketStreamBuilder builder = analysis.getBuilder(TmfPcapProtocol.ETHERNET_II);
102 if (builder == null) {
103 fail("The PacketStreamBuilder is null!");
104 return;
105 }
106 assertEquals(1, builder.getNbStreams());
107
108 builder = analysis.getBuilder(TmfPcapProtocol.IPV4);
109 if (builder == null) {
110 fail("The PacketStreamBuilder is null!");
111 return;
112 }
113 assertEquals(3, builder.getNbStreams());
114
115 builder = analysis.getBuilder(TmfPcapProtocol.TCP);
116 if (builder == null) {
117 fail("The PacketStreamBuilder is null!");
118 return;
119 }
120 assertEquals(2, builder.getNbStreams());
121
122 builder = analysis.getBuilder(TmfPcapProtocol.UDP);
123 if (builder == null) {
124 fail("The PacketStreamBuilder is null!");
125 return;
126 }
127 assertEquals(1, builder.getNbStreams());
128
129 analysis.dispose();
130 pcapTrace.dispose();
131 }
132
133 }
This page took 0.036611 seconds and 6 git commands to generate.