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 PcapTrace result
= new PcapTrace();
79 assertNotNull(result
);
80 assertEquals(1000, result
.getCacheSize());
81 assertEquals(0L, result
.getNbEvents());
82 assertEquals(0L, result
.getStreamingInterval());
83 assertNull(result
.getResource());
84 assertNull(result
.getEventType());
90 * Test the parseEvent() method
93 public void testParseEvent() {
94 ITmfContext ctx
= fFixture
.seekEvent(0);
95 fFixture
.getNext(ctx
);
96 PcapEvent event
= fFixture
.parseEvent(ctx
);
101 * Run the void broadcast(TmfSignal) method test.
104 public void testBroadcast() {
105 TmfSignal signal
= new TmfEndSynchSignal(1);
106 fFixture
.broadcast(signal
);
110 * Run the int getCacheSize() method test.
113 public void testGetCacheSize() {
114 PcapTrace emptyFixture
= new PcapTrace();
115 int result
= emptyFixture
.getCacheSize();
116 assertEquals(1000, result
);
117 emptyFixture
.dispose();
121 * Run the ITmfLocation<Comparable> getCurrentLocation() method test.
124 public void testGetCurrentLocation() {
125 TmfLongLocation result
= (TmfLongLocation
) fFixture
.getCurrentLocation();
126 assertEquals(new TmfLongLocation(0), result
);
130 * Test the seekEvent() method with a null location.
133 public void testSeekEventLoc_null() {
134 TmfLongLocation loc
= null;
135 fFixture
.seekEvent(loc
);
136 assertNotNull(fFixture
);
140 * Test the seekEvent() method with a normal location.
143 public void testSeekEventLoc_normal() {
144 TmfLongLocation loc
= new TmfLongLocation(3L);
145 fFixture
.seekEvent(loc
);
146 assertNotNull(fFixture
);
150 * Run the ITmfTimestamp getEndTime() method test.
153 public void testGetEndTime() {
154 ITmfTimestamp result
= fFixture
.getEndTime();
155 assertNotNull(result
);
159 * Test the {@link PcapTrace#getEventType()} method.
162 public void testGetEventType() {
163 Class
<?
> result
= fFixture
.getEventType();
164 assertNotNull(result
);
165 assertEquals(PcapEvent
.class, result
);
169 * Run the double getLocationRatio(ITmfLocation<?>) method test.
172 public void testGetLocationRatio() {
173 TmfLongLocation location
= new TmfLongLocation(20L);
174 double result
= fFixture
.getLocationRatio(location
);
176 assertEquals(20.0 / 43.0, result
, 0.01);
180 * Run the String getName() method test.
183 public void testGetName() {
184 String result
= fFixture
.getName();
185 assertNotNull(result
);
189 * Run the getTraceProperties() method test.
192 public void testGetTraceProperties() {
193 int result
= fFixture
.getTraceProperties().size();
194 assertEquals(6, result
);
198 * Run the long getNbEvents() method test.
201 public void testGetNbEvents() {
202 long result
= fFixture
.getNbEvents();
203 assertEquals(0, result
);
207 * Run the String getPath() method test.
210 public void testGetPath() {
211 String result
= fFixture
.getPath();
212 assertNotNull(result
);
216 * Run the IResource getResource() method test.
219 public void testGetResource() {
220 IResource result
= fFixture
.getResource();
225 * Run the ITmfTimestamp getStartTime() method test.
228 public void testGetStartTime() {
229 ITmfTimestamp result
= fFixture
.getStartTime();
230 assertNotNull(result
);
234 * Run the long getStreamingInterval() method test.
237 public void testGetStreamingInterval() {
238 long result
= fFixture
.getStreamingInterval();
239 assertEquals(0L, result
);
243 * Run the TmfTimeRange getTimeRange() method test.
246 public void testGetTimeRange() {
247 TmfTimeRange result
= fFixture
.getTimeRange();
248 assertNotNull(result
);
252 * Run the ITmfContext seekEvent(double) method test.
255 public void testSeekEvent_ratio() {
256 double ratio
= 21.0 / 43.0;
257 ITmfContext result
= fFixture
.seekEvent(ratio
);
258 assertNotNull(result
);
262 * Run the ITmfContext seekEvent(long) method test.
265 public void testSeekEvent_rank() {
267 ITmfContext result
= fFixture
.seekEvent(rank
);
268 assertNotNull(result
);
272 * Run the ITmfContext seekEvent(ITmfLocation<?>) method test.
275 public void testSeekEvent_location() {
276 TmfLongLocation pcapLocation
= new TmfLongLocation(10L);
277 ITmfContext result
= fFixture
.seekEvent(pcapLocation
);
278 assertNotNull(result
);
282 * Run the boolean validate(IProject,String) method test.
285 public void testValidate() {
286 IProject project
= null;
287 IStatus result
= fFixture
.validate(project
, TEST_TRACE
.getPath());
288 assertTrue(result
.isOK());
292 * Run the String getHostId() method test
295 public void getSource() {
296 String a
= fFixture
.getHostId();
297 assertEquals("mostlyTCP.pcap", a
);