ctf: Allow the test traces to be used by other plugins
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / trace / CTFTraceTest.java
1 package org.eclipse.linuxtools.ctf.core.tests.trace;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertFalse;
5 import static org.junit.Assert.assertNotNull;
6 import static org.junit.Assert.assertNull;
7 import static org.junit.Assert.assertTrue;
8 import static org.junit.Assume.assumeTrue;
9
10 import java.io.File;
11 import java.nio.ByteOrder;
12 import java.util.Map;
13 import java.util.UUID;
14
15 import org.eclipse.linuxtools.ctf.core.event.CTFClock;
16 import org.eclipse.linuxtools.ctf.core.event.types.Definition;
17 import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
18 import org.eclipse.linuxtools.ctf.core.tests.shared.CtfTestTraces;
19 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
20 import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
21 import org.eclipse.linuxtools.ctf.core.trace.Stream;
22 import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
23 import org.junit.After;
24 import org.junit.Before;
25 import org.junit.Test;
26
27 /**
28 * The class <code>CTFTraceTest</code> contains tests for the class
29 * <code>{@link CTFTrace}</code>.
30 *
31 * @author ematkho
32 * @version $Revision: 1.0 $
33 */
34 @SuppressWarnings("javadoc")
35 public class CTFTraceTest {
36
37 private static final int TRACE_INDEX = 0;
38
39 private CTFTrace fixture;
40
41 /**
42 * Launch the test.
43 *
44 * @param args
45 * the command line arguments
46 */
47 public static void main(String[] args) {
48 new org.junit.runner.JUnitCore().run(CTFTraceTest.class);
49 }
50
51 /**
52 * Perform pre-test initialization.
53 */
54 @Before
55 public void setUp() {
56 assumeTrue(CtfTestTraces.tracesExist());
57 fixture = CtfTestTraces.getTestTraceFromFile(TRACE_INDEX);
58 fixture.setMinor(1L);
59 fixture.setUUID(UUID.randomUUID());
60 fixture.setPacketHeader(new StructDeclaration(1L));
61 fixture.setMajor(1L);
62 fixture.setByteOrder(ByteOrder.BIG_ENDIAN);
63 }
64
65 /**
66 * Perform post-test clean-up.
67 */
68 @After
69 public void tearDown() {
70 // Add additional tear down code here
71 }
72
73 /**
74 * Run the CTFTrace(File) constructor test with a known existing trace.
75 */
76 @Test
77 public void testOpen_existing() {
78 CTFTrace result = CtfTestTraces.getTestTraceFromFile(TRACE_INDEX);
79 assertNotNull(result.getUUID());
80 }
81
82 /**
83 * Run the CTFTrace(File) constructor test with an invalid path.
84 *
85 * @throws CTFReaderException
86 */
87 @Test(expected = org.eclipse.linuxtools.ctf.core.trace.CTFReaderException.class)
88 public void testOpen_invalid() throws CTFReaderException {
89 File path = new File(""); //$NON-NLS-1$
90 CTFTrace result = new CTFTrace(path);
91 assertNotNull(result);
92 }
93
94 /**
95 * Run the boolean UUIDIsSet() method test.
96 */
97 @Test
98 public void testUUIDIsSet() {
99 boolean result = fixture.UUIDIsSet();
100 assertTrue(result);
101 }
102
103 /**
104 * Run the void addStream(Stream) method test.
105 *
106 * @throws ParseException
107 * @throws CTFReaderException
108 */
109 @Test
110 public void testAddStream() throws ParseException, CTFReaderException {
111 // test number of streams
112 int nbStreams = fixture.nbStreams();
113 assertEquals(1, nbStreams);
114 // Add a stream
115 Stream stream = new Stream(CtfTestTraces.getTestTrace(TRACE_INDEX));
116 stream.setId(1234);
117 fixture.addStream(stream);
118 // test number of streams
119 nbStreams = fixture.nbStreams();
120 assertEquals(2, nbStreams);
121 }
122
123 /**
124 * Run the boolean byteOrderIsSet() method test.
125 */
126 @Test
127 public void testByteOrderIsSet() {
128 boolean result = fixture.byteOrderIsSet();
129 assertTrue(result);
130 }
131
132 /**
133 * Run the ByteOrder getByteOrder() method test.
134 */
135 @Test
136 public void testGetByteOrder_1() {
137 ByteOrder result = fixture.getByteOrder();
138 assertNotNull(result);
139 }
140
141 /**
142 * Run the long getMajor() method test.
143 */
144 @Test
145 public void testGetMajor() {
146 long result = fixture.getMajor();
147 assertEquals(1L, result);
148 }
149
150 /**
151 * Run the long getMinor() method test.
152 */
153 @Test
154 public void testGetMinor() {
155 long result = fixture.getMinor();
156 assertEquals(1L, result);
157 }
158
159 /**
160 * Run the StructDeclaration getPacketHeader() method test.
161 */
162 @Test
163 public void testGetPacketHeader() {
164 StructDeclaration result = fixture.getPacketHeader();
165 assertNotNull(result);
166 }
167
168 /**
169 * Run the String getPath() method test.
170 */
171 @Test
172 public void testGetPath() {
173 String result = fixture.getPath();
174 assertNotNull(result);
175 }
176
177 /**
178 * Run the Stream getStream(Long) method test.
179 */
180 @Test
181 public void testGetStream() {
182 Long id = new Long(0L);
183 Stream result = fixture.getStream(id);
184 assertNotNull(result);
185 }
186
187 /**
188 * Run the Map<Long, Stream> getStreams() method test.
189 */
190 @Test
191 public void testGetStreams() {
192 Map<Long, Stream> result = fixture.getStreams();
193 assertNotNull(result);
194 }
195
196 /**
197 * Run the File getTraceDirectory() method test.
198 */
199 @Test
200 public void testGetTraceDirectory() {
201 File result = fixture.getTraceDirectory();
202 assertNotNull(result);
203 }
204
205 /**
206 * Run the UUID getUUID() method test.
207 */
208 @Test
209 public void testGetUUID() {
210 UUID result = fixture.getUUID();
211 assertNotNull(result);
212 }
213
214 /**
215 * Run the Definition lookupDefinition(String) method test.
216 */
217 @Test
218 public void testLookupDefinition() {
219 String lookupPath = "trace.packet.header"; //$NON-NLS-1$
220 Definition result = fixture.lookupDefinition(lookupPath);
221 assertNotNull(result);
222 }
223
224 /**
225 * Run the boolean majortIsSet() method test.
226 */
227 @Test
228 public void testMajortIsSet() {
229 boolean result = fixture.majortIsSet();
230 assertTrue(result);
231 }
232
233 /**
234 * Run the boolean minorIsSet() method test.
235 */
236 @Test
237 public void testMinorIsSet() {
238 boolean result = fixture.minorIsSet();
239 assertTrue(result);
240 }
241
242 /**
243 * Run the boolean packetHeaderIsSet() method test with a valid header set.
244 */
245 @Test
246 public void testPacketHeaderIsSet_valid() {
247 boolean result = fixture.packetHeaderIsSet();
248 assertTrue(result);
249 }
250
251 /**
252 * Run the boolean packetHeaderIsSet() method test, without having a valid
253 * header set.
254 */
255 @Test
256 public void testPacketHeaderIsSet_invalid() {
257 CTFTrace fixture2 = CtfTestTraces.getTestTraceFromFile(TRACE_INDEX);
258 fixture2.setMinor(1L);
259 fixture2.setUUID(UUID.randomUUID());
260 fixture2.setPacketHeader((StructDeclaration) null); /* it's null here! */
261 fixture2.setMajor(1L);
262 fixture2.setByteOrder(ByteOrder.BIG_ENDIAN);
263
264 boolean result = fixture2.packetHeaderIsSet();
265 assertFalse(result);
266 }
267
268 /**
269 * Run the void setByteOrder(ByteOrder) method test.
270 */
271 @Test
272 public void testSetByteOrder() {
273 ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
274 fixture.setByteOrder(byteOrder);
275 }
276
277 /**
278 * Run the void setMajor(long) method test.
279 */
280 @Test
281 public void testSetMajor() {
282 long major = 1L;
283 fixture.setMajor(major);
284 }
285
286 /**
287 * Run the void setMinor(long) method test.
288 */
289 @Test
290 public void testSetMinor() {
291 long minor = 1L;
292 fixture.setMinor(minor);
293 }
294
295 /**
296 * Run the void setPacketHeader(StructDeclaration) method test.
297 */
298 @Test
299 public void testSetPacketHeader() {
300 StructDeclaration packetHeader = new StructDeclaration(1L);
301 fixture.setPacketHeader(packetHeader);
302 }
303
304 /**
305 * Run the void setUUID(UUID) method test.
306 */
307 @Test
308 public void testSetUUID() {
309 UUID uuid = UUID.randomUUID();
310 fixture.setUUID(uuid);
311 }
312
313 /**
314 * Run the CTFClock getClock() method test.
315 */
316 @Test
317 public void testGetClock_1() {
318 CTFClock result = fixture.getClock();
319 assertNotNull(result);
320 }
321
322 /**
323 * Run the CTFClock getClock() method test.
324 *
325 */
326 @Test
327 public void testGetClock_2() {
328 CTFClock result = fixture.getClock("Blabla"); //$NON-NLS-1$
329 assertNull(result);
330 }
331
332 /**
333 * Run the CTFClock getClock(String) method test.
334 */
335 @Test
336 public void testGetClock_3() {
337 String name = "invisibleClock"; //$NON-NLS-1$
338 CTFClock result = fixture.getClock(name);
339 assertNull(result);
340 }
341
342
343 /**
344 * Run the CTFClock getClock(String) method test.
345 */
346 @Test
347 public void testSetClock_1() {
348 String name = "clockyClock"; //$NON-NLS-1$
349 fixture.addClock(name, new CTFClock());
350 CTFClock result = fixture.getClock(name);
351
352 assertNotNull(result);
353 }
354
355 /**
356 * Run the CTFClock getClock(String) method test.
357 */
358 @Test
359 public void testSetClock_2() {
360 String name = ""; //$NON-NLS-1$
361 CTFClock ctfClock = new CTFClock();
362 ctfClock.addAttribute("name", "Bob"); //$NON-NLS-1$ //$NON-NLS-2$
363 ctfClock.addAttribute("pi", new Double(java.lang.Math.PI)); //$NON-NLS-1$
364 fixture.addClock(name, ctfClock);
365 CTFClock result = fixture.getClock(name);
366
367 assertNotNull(result);
368 assertTrue( (Double)ctfClock.getProperty("pi")> 3.0); //$NON-NLS-1$
369 assertTrue( ctfClock.getName().equals("Bob")); //$NON-NLS-1$
370 }
371
372 /**
373 * Run the String lookupEnvironment(String) method test.
374 */
375 @Test
376 public void testLookupEnvironment_1() {
377 String key = ""; //$NON-NLS-1$
378 String result = fixture.lookupEnvironment(key);
379 assertNull(result);
380 }
381
382 /**
383 * Run the String lookupEnvironment(String) method test.
384 */
385 @Test
386 public void testLookupEnvironment_2() {
387 String key = "otherTest"; //$NON-NLS-1$
388 String result = fixture.lookupEnvironment(key);
389 assertNull(result);
390 }
391
392 /**
393 * Run the String lookupEnvironment(String) method test.
394 */
395 @Test
396 public void testLookupEnvironment_3() {
397 String key = "test"; //$NON-NLS-1$
398 fixture.addEnvironmentVar(key, key);
399 String result = fixture.lookupEnvironment(key);
400 assertTrue(result.equals(key));
401 }
402
403 /**
404 * Run the String lookupEnvironment(String) method test.
405 */
406 @Test
407 public void testLookupEnvironment_4() {
408 String key = "test"; //$NON-NLS-1$
409 fixture.addEnvironmentVar(key, "bozo"); //$NON-NLS-1$
410 fixture.addEnvironmentVar(key, "the clown"); //$NON-NLS-1$
411 String result = fixture.lookupEnvironment(key);
412 assertNotNull(result);
413 }
414
415 }
This page took 0.044377 seconds and 6 git commands to generate.