1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
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
10 * Vincent Perot - Initial API and implementation
11 ******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.pcap
.core
.tests
.analysis
;
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
;
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
;
32 * JUnit that test the StreamListAnalysis class.
34 * @author Vincent Perot
36 public class StreamListAnalysisTest
{
39 * Method that tests the constructor.
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
));
50 assertFalse(analysis
.isFinished());
56 * Method that tests canExecute().
58 * @throws TmfTraceException
59 * Thrown when the trace cannot be initialized. Fails the test.
62 public void canExecuteTest() throws TmfTraceException
{
63 PcapTestTrace trace
= PcapTestTrace
.MOSTLY_TCP
;
64 assumeTrue(trace
.exists());
65 String path
= trace
.getPath().toString();
66 try (PcapTrace pcapTrace
= new PcapTrace();) {
67 StreamListAnalysis analysis
= new StreamListAnalysis();
68 analysis
.setId(StreamListAnalysis
.ID
);
69 pcapTrace
.initTrace(null, path
, null);
70 assertTrue(analysis
.canExecute(pcapTrace
));
77 * Method that execute the analysis and verify the results.
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.
86 public void executeAnalysisTest() throws TmfAnalysisException
, TmfTraceException
{
87 PcapTestTrace trace
= PcapTestTrace
.MOSTLY_TCP
;
88 assumeTrue(trace
.exists());
89 String path
= trace
.getPath().toString();
90 try (PcapTrace pcapTrace
= new PcapTrace();) {
91 StreamListAnalysis analysis
= new StreamListAnalysis();
93 pcapTrace
.initTrace(null, path
, null);
94 analysis
.setId(StreamListAnalysis
.ID
);
95 analysis
.setTrace(pcapTrace
);
97 analysis
.waitForCompletion();
99 // Verify that builders are not empty.
100 TmfPacketStreamBuilder builder
= analysis
.getBuilder(TmfPcapProtocol
.ETHERNET_II
);
101 if (builder
== null) {
102 fail("The PacketStreamBuilder is null!");
105 assertEquals(1, builder
.getNbStreams());
107 builder
= analysis
.getBuilder(TmfPcapProtocol
.IPV4
);
108 if (builder
== null) {
109 fail("The PacketStreamBuilder is null!");
112 assertEquals(3, builder
.getNbStreams());
114 builder
= analysis
.getBuilder(TmfPcapProtocol
.TCP
);
115 if (builder
== null) {
116 fail("The PacketStreamBuilder is null!");
119 assertEquals(2, builder
.getNbStreams());
121 builder
= analysis
.getBuilder(TmfPcapProtocol
.UDP
);
122 if (builder
== null) {
123 fail("The PacketStreamBuilder is null!");
126 assertEquals(1, builder
.getNbStreams());