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 / trace / PcapTraceTest.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.trace;
14
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;
20
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;
37
38 /**
39 * JUnit that test the PcapTrace class.
40 *
41 * @author Vincent Perot
42 */
43 public class PcapTraceTest {
44
45 private static final PcapTmfTestTrace TEST_TRACE = PcapTmfTestTrace.MOSTLY_TCP;
46
47 private PcapTrace fFixture;
48
49 /**
50 * Perform pre-test initialization.
51 *
52 * @throws TmfTraceException
53 * If the test trace is not found
54 */
55 @Before
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);
60 }
61
62 /**
63 * Perform post-test clean-up.
64 */
65 @After
66 public void tearDown() {
67 if (fFixture != null) {
68 fFixture.dispose();
69 }
70 }
71
72 /**
73 * Run the PcapTrace() constructor test.
74 */
75 @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());
84 }
85 }
86
87 /**
88 * Test the parseEvent() method
89 */
90 @Test
91 public void testParseEvent() {
92 ITmfContext ctx = fFixture.seekEvent(0);
93 fFixture.getNext(ctx);
94 PcapEvent event = fFixture.parseEvent(ctx);
95 assertNotNull(event);
96 }
97
98 /**
99 * Run the void broadcast(TmfSignal) method test.
100 */
101 @Test
102 public void testBroadcast() {
103 TmfSignal signal = new TmfEndSynchSignal(1);
104 fFixture.broadcast(signal);
105 }
106
107 /**
108 * Run the void dispose() method test.
109 */
110 @Test
111 public void testClose() {
112 try (PcapTrace emptyFixture = new PcapTrace();) {
113 }
114 }
115
116 /**
117 * Run the int getCacheSize() method test.
118 */
119 @Test
120 public void testGetCacheSize() {
121 try (PcapTrace emptyFixture = new PcapTrace();) {
122 int result = emptyFixture.getCacheSize();
123 assertEquals(1000, result);
124 }
125 }
126
127 /**
128 * Run the ITmfLocation<Comparable> getCurrentLocation() method test.
129 */
130 @Test
131 public void testGetCurrentLocation() {
132 TmfLongLocation result = (TmfLongLocation) fFixture.getCurrentLocation();
133 assertEquals(new TmfLongLocation(0), result);
134 }
135
136 /**
137 * Test the seekEvent() method with a null location.
138 */
139 @Test
140 public void testSeekEventLoc_null() {
141 TmfLongLocation loc = null;
142 fFixture.seekEvent(loc);
143 assertNotNull(fFixture);
144 }
145
146 /**
147 * Test the seekEvent() method with a normal location.
148 */
149 @Test
150 public void testSeekEventLoc_normal() {
151 TmfLongLocation loc = new TmfLongLocation(3L);
152 fFixture.seekEvent(loc);
153 assertNotNull(fFixture);
154 }
155
156 /**
157 * Run the ITmfTimestamp getEndTime() method test.
158 */
159 @Test
160 public void testGetEndTime() {
161 ITmfTimestamp result = fFixture.getEndTime();
162 assertNotNull(result);
163 }
164
165 /**
166 * Test the {@link PcapTrace#getEventType()} method.
167 */
168 @Test
169 public void testGetEventType() {
170 Class<?> result = fFixture.getEventType();
171 assertNotNull(result);
172 assertEquals(PcapEvent.class, result);
173 }
174
175 /**
176 * Run the double getLocationRatio(ITmfLocation<?>) method test.
177 */
178 @Test
179 public void testGetLocationRatio() {
180 TmfLongLocation location = new TmfLongLocation(20L);
181 double result = fFixture.getLocationRatio(location);
182
183 assertEquals(20.0 / 43.0, result, 0.01);
184 }
185
186 /**
187 * Run the String getName() method test.
188 */
189 @Test
190 public void testGetName() {
191 String result = fFixture.getName();
192 assertNotNull(result);
193 }
194
195 /**
196 * Run the getTraceProperties() method test.
197 */
198 @Test
199 public void testGetTraceProperties() {
200 int result = fFixture.getTraceProperties().size();
201 assertEquals(6, result);
202 }
203
204 /**
205 * Run the long getNbEvents() method test.
206 */
207 @Test
208 public void testGetNbEvents() {
209 long result = fFixture.getNbEvents();
210 assertEquals(0, result);
211 }
212
213 /**
214 * Run the String getPath() method test.
215 */
216 @Test
217 public void testGetPath() {
218 String result = fFixture.getPath();
219 assertNotNull(result);
220 }
221
222 /**
223 * Run the IResource getResource() method test.
224 */
225 @Test
226 public void testGetResource() {
227 IResource result = fFixture.getResource();
228 assertNull(result);
229 }
230
231 /**
232 * Run the ITmfTimestamp getStartTime() method test.
233 */
234 @Test
235 public void testGetStartTime() {
236 ITmfTimestamp result = fFixture.getStartTime();
237 assertNotNull(result);
238 }
239
240 /**
241 * Run the long getStreamingInterval() method test.
242 */
243 @Test
244 public void testGetStreamingInterval() {
245 long result = fFixture.getStreamingInterval();
246 assertEquals(0L, result);
247 }
248
249 /**
250 * Run the TmfTimeRange getTimeRange() method test.
251 */
252 @Test
253 public void testGetTimeRange() {
254 TmfTimeRange result = fFixture.getTimeRange();
255 assertNotNull(result);
256 }
257
258 /**
259 * Run the ITmfContext seekEvent(double) method test.
260 */
261 @Test
262 public void testSeekEvent_ratio() {
263 double ratio = 21.0 / 43.0;
264 ITmfContext result = fFixture.seekEvent(ratio);
265 assertNotNull(result);
266 }
267
268 /**
269 * Run the ITmfContext seekEvent(long) method test.
270 */
271 @Test
272 public void testSeekEvent_rank() {
273 long rank = 1L;
274 ITmfContext result = fFixture.seekEvent(rank);
275 assertNotNull(result);
276 }
277
278 /**
279 * Run the ITmfContext seekEvent(ITmfLocation<?>) method test.
280 */
281 @Test
282 public void testSeekEvent_location() {
283 TmfLongLocation pcapLocation = new TmfLongLocation(10L);
284 ITmfContext result = fFixture.seekEvent(pcapLocation);
285 assertNotNull(result);
286 }
287
288 /**
289 * Run the boolean validate(IProject,String) method test.
290 */
291 @Test
292 public void testValidate() {
293 IProject project = null;
294 IStatus result = fFixture.validate(project, TEST_TRACE.getPath());
295 assertTrue(result.isOK());
296 }
297
298 /**
299 * Run the String getHostId() method test
300 */
301 @Test
302 public void getSource() {
303 String a = fFixture.getHostId();
304 assertEquals("mostlyTCP.pcap", a);
305 }
306
307 }
This page took 0.059572 seconds and 5 git commands to generate.