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