Update Grammar and Add support for callsites
[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 Stream stream = new Stream(TestParams.createTrace());
108 stream.setId(1234);
109 fixture.addStream(stream);
110 }
111
112 /**
113 * Run the boolean byteOrderIsSet() method test.
114 */
115 @Test
116 public void testByteOrderIsSet() {
117 boolean result = fixture.byteOrderIsSet();
118 assertTrue(result);
119 }
120
121 /**
122 * Run the ByteOrder getByteOrder() method test.
123 */
124 @Test
125 public void testGetByteOrder_1() {
126 ByteOrder result = fixture.getByteOrder();
127 assertNotNull(result);
128 }
129
130 /**
131 * Run the long getMajor() method test.
132 */
133 @Test
134 public void testGetMajor() {
135 long result = fixture.getMajor();
136 assertEquals(1L, result);
137 }
138
139 /**
140 * Run the long getMinor() method test.
141 */
142 @Test
143 public void testGetMinor() {
144 long result = fixture.getMinor();
145 assertEquals(1L, result);
146 }
147
148 /**
149 * Run the StructDeclaration getPacketHeader() method test.
150 */
151 @Test
152 public void testGetPacketHeader() {
153 StructDeclaration result = fixture.getPacketHeader();
154 assertNotNull(result);
155 }
156
157 /**
158 * Run the String getPath() method test.
159 */
160 @Test
161 public void testGetPath() {
162 String result = fixture.getPath();
163 assertNotNull(result);
164 }
165
166 /**
167 * Run the Stream getStream(Long) method test.
168 */
169 @Test
170 public void testGetStream() {
171 Long id = new Long(0L);
172 Stream result = fixture.getStream(id);
173 assertNotNull(result);
174 }
175
176 /**
177 * Run the Map<Long, Stream> getStreams() method test.
178 */
179 @Test
180 public void testGetStreams() {
181 Map<Long, Stream> result = fixture.getStreams();
182 assertNotNull(result);
183 }
184
185 /**
186 * Run the File getTraceDirectory() method test.
187 */
188 @Test
189 public void testGetTraceDirectory() {
190 File result = fixture.getTraceDirectory();
191 assertNotNull(result);
192 }
193
194 /**
195 * Run the UUID getUUID() method test.
196 */
197 @Test
198 public void testGetUUID() {
199 UUID result = fixture.getUUID();
200 assertNotNull(result);
201 }
202
203 /**
204 * Run the Definition lookupDefinition(String) method test.
205 */
206 @Test
207 public void testLookupDefinition() {
208 String lookupPath = "trace.packet.header"; //$NON-NLS-1$
209 Definition result = fixture.lookupDefinition(lookupPath);
210 assertNotNull(result);
211 }
212
213 /**
214 * Run the boolean majortIsSet() method test.
215 */
216 @Test
217 public void testMajortIsSet() {
218 boolean result = fixture.majortIsSet();
219 assertTrue(result);
220 }
221
222 /**
223 * Run the boolean minorIsSet() method test.
224 */
225 @Test
226 public void testMinorIsSet() {
227 boolean result = fixture.minorIsSet();
228 assertTrue(result);
229 }
230
231 /**
232 * Run the int nbStreams() method test.
233 */
234 @Test
235 public void testNbStreams() {
236 int result = fixture.nbStreams();
237 assertEquals(2, result);
238 }
239
240 /**
241 * Run the boolean packetHeaderIsSet() method test with a valid header set.
242 */
243 @Test
244 public void testPacketHeaderIsSet_valid() {
245 boolean result = fixture.packetHeaderIsSet();
246 assertTrue(result);
247 }
248
249 /**
250 * Run the boolean packetHeaderIsSet() method test, without having a valid
251 * header set.
252 */
253 @Test
254 public void testPacketHeaderIsSet_invalid() {
255 CTFTrace fixture2 = TestParams.createTraceFromFile();
256 fixture2.setMinor(1L);
257 fixture2.setUUID(UUID.randomUUID());
258 fixture2.setPacketHeader((StructDeclaration) null); /* it's null here! */
259 fixture2.setMajor(1L);
260 fixture2.setByteOrder(ByteOrder.BIG_ENDIAN);
261
262 boolean result = fixture2.packetHeaderIsSet();
263 assertFalse(result);
264 }
265
266 /**
267 * Run the void setByteOrder(ByteOrder) method test.
268 */
269 @Test
270 public void testSetByteOrder() {
271 ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
272 fixture.setByteOrder(byteOrder);
273 }
274
275 /**
276 * Run the void setMajor(long) method test.
277 */
278 @Test
279 public void testSetMajor() {
280 long major = 1L;
281 fixture.setMajor(major);
282 }
283
284 /**
285 * Run the void setMinor(long) method test.
286 */
287 @Test
288 public void testSetMinor() {
289 long minor = 1L;
290 fixture.setMinor(minor);
291 }
292
293 /**
294 * Run the void setPacketHeader(StructDeclaration) method test.
295 */
296 @Test
297 public void testSetPacketHeader() {
298 StructDeclaration packetHeader = new StructDeclaration(1L);
299 fixture.setPacketHeader(packetHeader);
300 }
301
302 /**
303 * Run the void setUUID(UUID) method test.
304 */
305 @Test
306 public void testSetUUID() {
307 UUID uuid = UUID.randomUUID();
308 fixture.setUUID(uuid);
309 }
310
311 /**
312 * Run the CTFClock getClock() method test.
313 */
314 @Test
315 public void testGetClock_1() {
316 CTFClock result = fixture.getClock();
317 assertNotNull(result);
318 }
319
320 /**
321 * Run the CTFClock getClock() method test.
322 *
323 */
324 @Test
325 public void testGetClock_2() {
326 CTFClock result = fixture.getClock("Blabla"); //$NON-NLS-1$
327 assertNull(result);
328 }
329
330 /**
331 * Run the CTFClock getClock(String) method test.
332 */
333 @Test
334 public void testGetClock_3() {
335 String name = "invisibleClock"; //$NON-NLS-1$
336 CTFClock result = fixture.getClock(name);
337 assertNull(result);
338 }
339
340
341 /**
342 * Run the CTFClock getClock(String) method test.
343 */
344 @Test
345 public void testSetClock_1() {
346 String name = "clockyClock"; //$NON-NLS-1$
347 fixture.addClock(name, new CTFClock());
348 CTFClock result = fixture.getClock(name);
349
350 assertNotNull(result);
351 }
352
353 /**
354 * Run the CTFClock getClock(String) method test.
355 */
356 @Test
357 public void testSetClock_2() {
358 String name = ""; //$NON-NLS-1$
359 CTFClock ctfClock = new CTFClock();
360 ctfClock.addAttribute("name", "Bob"); //$NON-NLS-1$ //$NON-NLS-2$
361 ctfClock.addAttribute("pi", new Double(java.lang.Math.PI)); //$NON-NLS-1$
362 fixture.addClock(name, ctfClock);
363 CTFClock result = fixture.getClock(name);
364
365 assertNotNull(result);
366 assertTrue( (Double)ctfClock.getProperty("pi")> 3.0); //$NON-NLS-1$
367 assertTrue( ctfClock.getName().equals("Bob")); //$NON-NLS-1$
368 }
369
370 /**
371 * Run the String lookupEnvironment(String) method test.
372 */
373 @Test
374 public void testLookupEnvironment_1() {
375 String key = ""; //$NON-NLS-1$
376 String result = fixture.lookupEnvironment(key);
377 assertNull(result);
378 }
379
380 /**
381 * Run the String lookupEnvironment(String) method test.
382 */
383 @Test
384 public void testLookupEnvironment_2() {
385 String key = "otherTest"; //$NON-NLS-1$
386 String result = fixture.lookupEnvironment(key);
387 assertNull(result);
388 }
389
390 /**
391 * Run the String lookupEnvironment(String) method test.
392 */
393 @Test
394 public void testLookupEnvironment_3() {
395 String key = "test"; //$NON-NLS-1$
396 fixture.addEnvironmentVar(key, key);
397 String result = fixture.lookupEnvironment(key);
398 assertTrue(result.equals(key));
399 }
400
401 /**
402 * Run the String lookupEnvironment(String) method test.
403 */
404 @Test
405 public void testLookupEnvironment_4() {
406 String key = "test"; //$NON-NLS-1$
407 fixture.addEnvironmentVar(key, "bozo"); //$NON-NLS-1$
408 fixture.addEnvironmentVar(key, "the clown"); //$NON-NLS-1$
409 String result = fixture.lookupEnvironment(key);
410 assertNotNull(result);
411 }
412
413 }
This page took 0.045637 seconds and 6 git commands to generate.