1 package org
.eclipse
.linuxtools
.ctf
.core
.tests
.trace
;
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
;
10 import java
.nio
.ByteOrder
;
12 import java
.util
.UUID
;
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
;
27 * The class <code>CTFTraceTest</code> contains tests for the class
28 * <code>{@link CTFTrace}</code>.
31 * @version $Revision: 1.0 $
33 @SuppressWarnings("javadoc")
34 public class CTFTraceTest
{
36 private CTFTrace fixture
;
42 * the command line arguments
44 public static void main(String
[] args
) {
45 new org
.junit
.runner
.JUnitCore().run(CTFTraceTest
.class);
49 * Perform pre-test initialization.
53 fixture
= TestParams
.createTraceFromFile();
55 fixture
.setUUID(UUID
.randomUUID());
56 fixture
.setPacketHeader(new StructDeclaration(1L));
58 fixture
.setByteOrder(ByteOrder
.BIG_ENDIAN
);
62 * Perform post-test clean-up.
65 public void tearDown() {
66 // Add additional tear down code here
70 * Run the CTFTrace(File) constructor test with a known existing trace.
73 public void testOpen_existing() {
74 CTFTrace result
= TestParams
.createTraceFromFile();
75 assertNotNull(result
.getUUID());
79 * Run the CTFTrace(File) constructor test with an invalid path.
81 * @throws CTFReaderException
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
);
91 * Run the boolean UUIDIsSet() method test.
94 public void testUUIDIsSet() {
95 boolean result
= fixture
.UUIDIsSet();
100 * Run the void addStream(Stream) method test.
102 * @throws ParseException
103 * @throws CTFReaderException
106 public void testAddStream() throws ParseException
, CTFReaderException
{
107 // test number of streams
108 int nbStreams
= fixture
.nbStreams();
109 assertEquals(1, nbStreams
);
111 Stream stream
= new Stream(TestParams
.createTrace());
113 fixture
.addStream(stream
);
114 // test number of streams
115 nbStreams
= fixture
.nbStreams();
116 assertEquals(2, nbStreams
);
120 * Run the boolean byteOrderIsSet() method test.
123 public void testByteOrderIsSet() {
124 boolean result
= fixture
.byteOrderIsSet();
129 * Run the ByteOrder getByteOrder() method test.
132 public void testGetByteOrder_1() {
133 ByteOrder result
= fixture
.getByteOrder();
134 assertNotNull(result
);
138 * Run the long getMajor() method test.
141 public void testGetMajor() {
142 long result
= fixture
.getMajor();
143 assertEquals(1L, result
);
147 * Run the long getMinor() method test.
150 public void testGetMinor() {
151 long result
= fixture
.getMinor();
152 assertEquals(1L, result
);
156 * Run the StructDeclaration getPacketHeader() method test.
159 public void testGetPacketHeader() {
160 StructDeclaration result
= fixture
.getPacketHeader();
161 assertNotNull(result
);
165 * Run the String getPath() method test.
168 public void testGetPath() {
169 String result
= fixture
.getPath();
170 assertNotNull(result
);
174 * Run the Stream getStream(Long) method test.
177 public void testGetStream() {
178 Long id
= new Long(0L);
179 Stream result
= fixture
.getStream(id
);
180 assertNotNull(result
);
184 * Run the Map<Long, Stream> getStreams() method test.
187 public void testGetStreams() {
188 Map
<Long
, Stream
> result
= fixture
.getStreams();
189 assertNotNull(result
);
193 * Run the File getTraceDirectory() method test.
196 public void testGetTraceDirectory() {
197 File result
= fixture
.getTraceDirectory();
198 assertNotNull(result
);
202 * Run the UUID getUUID() method test.
205 public void testGetUUID() {
206 UUID result
= fixture
.getUUID();
207 assertNotNull(result
);
211 * Run the Definition lookupDefinition(String) method test.
214 public void testLookupDefinition() {
215 String lookupPath
= "trace.packet.header"; //$NON-NLS-1$
216 Definition result
= fixture
.lookupDefinition(lookupPath
);
217 assertNotNull(result
);
221 * Run the boolean majortIsSet() method test.
224 public void testMajortIsSet() {
225 boolean result
= fixture
.majortIsSet();
230 * Run the boolean minorIsSet() method test.
233 public void testMinorIsSet() {
234 boolean result
= fixture
.minorIsSet();
239 * Run the boolean packetHeaderIsSet() method test with a valid header set.
242 public void testPacketHeaderIsSet_valid() {
243 boolean result
= fixture
.packetHeaderIsSet();
248 * Run the boolean packetHeaderIsSet() method test, without having a valid
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
);
260 boolean result
= fixture2
.packetHeaderIsSet();
265 * Run the void setByteOrder(ByteOrder) method test.
268 public void testSetByteOrder() {
269 ByteOrder byteOrder
= ByteOrder
.BIG_ENDIAN
;
270 fixture
.setByteOrder(byteOrder
);
274 * Run the void setMajor(long) method test.
277 public void testSetMajor() {
279 fixture
.setMajor(major
);
283 * Run the void setMinor(long) method test.
286 public void testSetMinor() {
288 fixture
.setMinor(minor
);
292 * Run the void setPacketHeader(StructDeclaration) method test.
295 public void testSetPacketHeader() {
296 StructDeclaration packetHeader
= new StructDeclaration(1L);
297 fixture
.setPacketHeader(packetHeader
);
301 * Run the void setUUID(UUID) method test.
304 public void testSetUUID() {
305 UUID uuid
= UUID
.randomUUID();
306 fixture
.setUUID(uuid
);
310 * Run the CTFClock getClock() method test.
313 public void testGetClock_1() {
314 CTFClock result
= fixture
.getClock();
315 assertNotNull(result
);
319 * Run the CTFClock getClock() method test.
323 public void testGetClock_2() {
324 CTFClock result
= fixture
.getClock("Blabla"); //$NON-NLS-1$
329 * Run the CTFClock getClock(String) method test.
332 public void testGetClock_3() {
333 String name
= "invisibleClock"; //$NON-NLS-1$
334 CTFClock result
= fixture
.getClock(name
);
340 * Run the CTFClock getClock(String) method 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
);
348 assertNotNull(result
);
352 * Run the CTFClock getClock(String) method 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
);
363 assertNotNull(result
);
364 assertTrue( (Double
)ctfClock
.getProperty("pi")> 3.0); //$NON-NLS-1$
365 assertTrue( ctfClock
.getName().equals("Bob")); //$NON-NLS-1$
369 * Run the String lookupEnvironment(String) method test.
372 public void testLookupEnvironment_1() {
373 String key
= ""; //$NON-NLS-1$
374 String result
= fixture
.lookupEnvironment(key
);
379 * Run the String lookupEnvironment(String) method test.
382 public void testLookupEnvironment_2() {
383 String key
= "otherTest"; //$NON-NLS-1$
384 String result
= fixture
.lookupEnvironment(key
);
389 * Run the String lookupEnvironment(String) method 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
));
400 * Run the String lookupEnvironment(String) method 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
);