pcap: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / pcap / org.eclipse.tracecompass.tmf.pcap.core.tests / src / org / eclipse / tracecompass / tmf / pcap / core / tests / analysis / StreamListAnalysisTest.java
CommitLineData
527c3a79
VP
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
2bdf0193 13package org.eclipse.tracecompass.tmf.pcap.core.tests.analysis;
527c3a79
VP
14
15import static org.junit.Assert.assertEquals;
16import static org.junit.Assert.assertFalse;
17import static org.junit.Assert.assertNotNull;
18import static org.junit.Assert.assertTrue;
19import static org.junit.Assert.fail;
20import static org.junit.Assume.assumeTrue;
21
2bdf0193
AM
22import org.eclipse.tracecompass.internal.tmf.pcap.core.analysis.StreamListAnalysis;
23import org.eclipse.tracecompass.internal.tmf.pcap.core.event.TmfPacketStreamBuilder;
24import org.eclipse.tracecompass.internal.tmf.pcap.core.protocol.TmfPcapProtocol;
25import org.eclipse.tracecompass.internal.tmf.pcap.core.trace.PcapTrace;
71f2817f 26import org.eclipse.tracecompass.pcap.core.tests.shared.PcapTestTrace;
2bdf0193
AM
27import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
28import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
527c3a79
VP
29import org.junit.Test;
30
31/**
32 * JUnit that test the StreamListAnalysis class.
33 *
34 * @author Vincent Perot
35 */
36public class StreamListAnalysisTest {
37
38 /**
39 * Method that tests the constructor.
40 */
41 @Test
42 public void constructorTest() {
03f0b0b1
AM
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));
527c3a79 48 }
527c3a79 49 }
03f0b0b1
AM
50 assertFalse(analysis.isFinished());
51
52 analysis.dispose();
527c3a79
VP
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());
333a2acb 65 String path = trace.getPath().toString();
03f0b0b1
AM
66 try (PcapTrace pcapTrace = new PcapTrace();) {
67 StreamListAnalysis analysis = new StreamListAnalysis();
527c3a79
VP
68 analysis.setId(StreamListAnalysis.ID);
69 pcapTrace.initTrace(null, path, null);
70 assertTrue(analysis.canExecute(pcapTrace));
03f0b0b1
AM
71
72 analysis.dispose();
527c3a79
VP
73 }
74 }
75
76 /**
77 * Method that execute the analysis and verify the results.
78 *
79 * @throws TmfAnalysisException
80 * Thrown when an analysis error occurs during the setup or
81 * execution. Fails the test.
82 * @throws TmfTraceException
83 * Thrown when the trace cannot be initialized. Fails the test.
84 */
85 @Test
86 public void executeAnalysisTest() throws TmfAnalysisException, TmfTraceException {
87 PcapTestTrace trace = PcapTestTrace.MOSTLY_TCP;
88 assumeTrue(trace.exists());
333a2acb 89 String path = trace.getPath().toString();
03f0b0b1
AM
90 try (PcapTrace pcapTrace = new PcapTrace();) {
91 StreamListAnalysis analysis = new StreamListAnalysis();
92
527c3a79
VP
93 pcapTrace.initTrace(null, path, null);
94 analysis.setId(StreamListAnalysis.ID);
95 analysis.setTrace(pcapTrace);
96 analysis.schedule();
97 analysis.waitForCompletion();
98
99 // Verify that builders are not empty.
c88feda9 100 TmfPacketStreamBuilder builder = analysis.getBuilder(TmfPcapProtocol.ETHERNET_II);
527c3a79
VP
101 if (builder == null) {
102 fail("The PacketStreamBuilder is null!");
103 return;
104 }
105 assertEquals(1, builder.getNbStreams());
106
c88feda9 107 builder = analysis.getBuilder(TmfPcapProtocol.IPV4);
527c3a79
VP
108 if (builder == null) {
109 fail("The PacketStreamBuilder is null!");
110 return;
111 }
112 assertEquals(3, builder.getNbStreams());
113
c88feda9 114 builder = analysis.getBuilder(TmfPcapProtocol.TCP);
527c3a79
VP
115 if (builder == null) {
116 fail("The PacketStreamBuilder is null!");
117 return;
118 }
119 assertEquals(2, builder.getNbStreams());
120
c88feda9 121 builder = analysis.getBuilder(TmfPcapProtocol.UDP);
527c3a79
VP
122 if (builder == null) {
123 fail("The PacketStreamBuilder is null!");
124 return;
125 }
126 assertEquals(1, builder.getNbStreams());
03f0b0b1
AM
127
128 analysis.dispose();
527c3a79
VP
129 }
130 }
131
132}
This page took 0.051831 seconds and 5 git commands to generate.