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