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
.trace
;
15 import static org
.junit
.Assert
.assertEquals
;
16 import static org
.junit
.Assert
.assertNotNull
;
17 import static org
.junit
.Assert
.assertNull
;
18 import static org
.junit
.Assert
.assertTrue
;
19 import static org
.junit
.Assume
.assumeTrue
;
21 import org
.eclipse
.core
.resources
.IProject
;
22 import org
.eclipse
.core
.resources
.IResource
;
23 import org
.eclipse
.core
.runtime
.IStatus
;
24 import org
.eclipse
.tracecompass
.internal
.tmf
.pcap
.core
.event
.PcapEvent
;
25 import org
.eclipse
.tracecompass
.internal
.tmf
.pcap
.core
.trace
.PcapTrace
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfTraceException
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfEndSynchSignal
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignal
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
30 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
31 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfContext
;
32 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.location
.TmfLongLocation
;
33 import org
.eclipse
.tracecompass
.tmf
.pcap
.core
.tests
.shared
.PcapTmfTestTrace
;
34 import org
.junit
.After
;
35 import org
.junit
.Before
;
36 import org
.junit
.Test
;
39 * JUnit that test the PcapTrace class.
41 * @author Vincent Perot
43 public class PcapTraceTest
{
45 private static final PcapTmfTestTrace TEST_TRACE
= PcapTmfTestTrace
.MOSTLY_TCP
;
47 private PcapTrace fFixture
;
50 * Perform pre-test initialization.
52 * @throws TmfTraceException
53 * If the test trace is not found
56 public void setUp() throws TmfTraceException
{
57 assumeTrue(TEST_TRACE
.exists());
58 fFixture
= new PcapTrace();
59 fFixture
.initTrace((IResource
) null, TEST_TRACE
.getPath(), PcapEvent
.class);
63 * Perform post-test clean-up.
66 public void tearDown() {
67 if (fFixture
!= null) {
73 * Run the PcapTrace() constructor test.
76 public void testPcapTrace() {
77 try (PcapTrace result
= new PcapTrace();) {
78 assertNotNull(result
);
79 assertEquals(1000, result
.getCacheSize());
80 assertEquals(0L, result
.getNbEvents());
81 assertEquals(0L, result
.getStreamingInterval());
82 assertNull(result
.getResource());
83 assertNull(result
.getType());
88 * Test the parseEvent() method
91 public void testParseEvent() {
92 ITmfContext ctx
= fFixture
.seekEvent(0);
93 fFixture
.getNext(ctx
);
94 PcapEvent event
= fFixture
.parseEvent(ctx
);
99 * Run the void broadcast(TmfSignal) method test.
102 public void testBroadcast() {
103 TmfSignal signal
= new TmfEndSynchSignal(1);
104 fFixture
.broadcast(signal
);
108 * Run the void dispose() method test.
111 public void testClose() {
112 try (PcapTrace emptyFixture
= new PcapTrace();) {
117 * Run the int getCacheSize() method test.
120 public void testGetCacheSize() {
121 try (PcapTrace emptyFixture
= new PcapTrace();) {
122 int result
= emptyFixture
.getCacheSize();
123 assertEquals(1000, result
);
128 * Run the ITmfLocation<Comparable> getCurrentLocation() method test.
131 public void testGetCurrentLocation() {
132 TmfLongLocation result
= (TmfLongLocation
) fFixture
.getCurrentLocation();
133 assertEquals(new TmfLongLocation(0), result
);
137 * Test the seekEvent() method with a null location.
140 public void testSeekEventLoc_null() {
141 TmfLongLocation loc
= null;
142 fFixture
.seekEvent(loc
);
143 assertNotNull(fFixture
);
147 * Test the seekEvent() method with a normal location.
150 public void testSeekEventLoc_normal() {
151 TmfLongLocation loc
= new TmfLongLocation(3L);
152 fFixture
.seekEvent(loc
);
153 assertNotNull(fFixture
);
157 * Run the ITmfTimestamp getEndTime() method test.
160 public void testGetEndTime() {
161 ITmfTimestamp result
= fFixture
.getEndTime();
162 assertNotNull(result
);
166 * Test the {@link PcapTrace#getEventType()} method.
169 public void testGetEventType() {
170 Class
<?
> result
= fFixture
.getEventType();
171 assertNotNull(result
);
172 assertEquals(PcapEvent
.class, result
);
176 * Run the double getLocationRatio(ITmfLocation<?>) method test.
179 public void testGetLocationRatio() {
180 TmfLongLocation location
= new TmfLongLocation(20L);
181 double result
= fFixture
.getLocationRatio(location
);
183 assertEquals(20.0 / 43.0, result
, 0.01);
187 * Run the String getName() method test.
190 public void testGetName() {
191 String result
= fFixture
.getName();
192 assertNotNull(result
);
196 * Run the getTraceProperties() method test.
199 public void testGetTraceProperties() {
200 int result
= fFixture
.getTraceProperties().size();
201 assertEquals(6, result
);
205 * Run the long getNbEvents() method test.
208 public void testGetNbEvents() {
209 long result
= fFixture
.getNbEvents();
210 assertEquals(0, result
);
214 * Run the String getPath() method test.
217 public void testGetPath() {
218 String result
= fFixture
.getPath();
219 assertNotNull(result
);
223 * Run the IResource getResource() method test.
226 public void testGetResource() {
227 IResource result
= fFixture
.getResource();
232 * Run the ITmfTimestamp getStartTime() method test.
235 public void testGetStartTime() {
236 ITmfTimestamp result
= fFixture
.getStartTime();
237 assertNotNull(result
);
241 * Run the long getStreamingInterval() method test.
244 public void testGetStreamingInterval() {
245 long result
= fFixture
.getStreamingInterval();
246 assertEquals(0L, result
);
250 * Run the TmfTimeRange getTimeRange() method test.
253 public void testGetTimeRange() {
254 TmfTimeRange result
= fFixture
.getTimeRange();
255 assertNotNull(result
);
259 * Run the ITmfContext seekEvent(double) method test.
262 public void testSeekEvent_ratio() {
263 double ratio
= 21.0 / 43.0;
264 ITmfContext result
= fFixture
.seekEvent(ratio
);
265 assertNotNull(result
);
269 * Run the ITmfContext seekEvent(long) method test.
272 public void testSeekEvent_rank() {
274 ITmfContext result
= fFixture
.seekEvent(rank
);
275 assertNotNull(result
);
279 * Run the ITmfContext seekEvent(ITmfLocation<?>) method test.
282 public void testSeekEvent_location() {
283 TmfLongLocation pcapLocation
= new TmfLongLocation(10L);
284 ITmfContext result
= fFixture
.seekEvent(pcapLocation
);
285 assertNotNull(result
);
289 * Run the boolean validate(IProject,String) method test.
292 public void testValidate() {
293 IProject project
= null;
294 IStatus result
= fFixture
.validate(project
, TEST_TRACE
.getPath());
295 assertTrue(result
.isOK());
299 * Run the String getHostId() method test
302 public void getSource() {
303 String a
= fFixture
.getHostId();
304 assertEquals("mostlyTCP.pcap", a
);