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
;
8 import static org
.junit
.Assume
.assumeTrue
;
11 import java
.nio
.ByteOrder
;
13 import java
.util
.UUID
;
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
.TestParams
;
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
;
28 * The class <code>CTFTraceTest</code> contains tests for the class
29 * <code>{@link CTFTrace}</code>.
32 * @version $Revision: 1.0 $
34 @SuppressWarnings("javadoc")
35 public class CTFTraceTest
{
37 private CTFTrace fixture
;
43 * the command line arguments
45 public static void main(String
[] args
) {
46 new org
.junit
.runner
.JUnitCore().run(CTFTraceTest
.class);
50 * Perform pre-test initialization.
54 assumeTrue(TestParams
.tracesExist());
55 fixture
= TestParams
.createTraceFromFile();
57 fixture
.setUUID(UUID
.randomUUID());
58 fixture
.setPacketHeader(new StructDeclaration(1L));
60 fixture
.setByteOrder(ByteOrder
.BIG_ENDIAN
);
64 * Perform post-test clean-up.
67 public void tearDown() {
68 // Add additional tear down code here
72 * Run the CTFTrace(File) constructor test with a known existing trace.
75 public void testOpen_existing() {
76 CTFTrace result
= TestParams
.createTraceFromFile();
77 assertNotNull(result
.getUUID());
81 * Run the CTFTrace(File) constructor test with an invalid path.
83 * @throws CTFReaderException
85 @Test(expected
= org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
.class)
86 public void testOpen_invalid() throws CTFReaderException
{
87 File path
= new File(""); //$NON-NLS-1$
88 CTFTrace result
= new CTFTrace(path
);
89 assertNotNull(result
);
93 * Run the boolean UUIDIsSet() method test.
96 public void testUUIDIsSet() {
97 boolean result
= fixture
.UUIDIsSet();
102 * Run the void addStream(Stream) method test.
104 * @throws ParseException
105 * @throws CTFReaderException
108 public void testAddStream() throws ParseException
, CTFReaderException
{
109 // test number of streams
110 int nbStreams
= fixture
.nbStreams();
111 assertEquals(1, nbStreams
);
113 Stream stream
= new Stream(TestParams
.createTrace());
115 fixture
.addStream(stream
);
116 // test number of streams
117 nbStreams
= fixture
.nbStreams();
118 assertEquals(2, nbStreams
);
122 * Run the boolean byteOrderIsSet() method test.
125 public void testByteOrderIsSet() {
126 boolean result
= fixture
.byteOrderIsSet();
131 * Run the ByteOrder getByteOrder() method test.
134 public void testGetByteOrder_1() {
135 ByteOrder result
= fixture
.getByteOrder();
136 assertNotNull(result
);
140 * Run the long getMajor() method test.
143 public void testGetMajor() {
144 long result
= fixture
.getMajor();
145 assertEquals(1L, result
);
149 * Run the long getMinor() method test.
152 public void testGetMinor() {
153 long result
= fixture
.getMinor();
154 assertEquals(1L, result
);
158 * Run the StructDeclaration getPacketHeader() method test.
161 public void testGetPacketHeader() {
162 StructDeclaration result
= fixture
.getPacketHeader();
163 assertNotNull(result
);
167 * Run the String getPath() method test.
170 public void testGetPath() {
171 String result
= fixture
.getPath();
172 assertNotNull(result
);
176 * Run the Stream getStream(Long) method test.
179 public void testGetStream() {
180 Long id
= new Long(0L);
181 Stream result
= fixture
.getStream(id
);
182 assertNotNull(result
);
186 * Run the Map<Long, Stream> getStreams() method test.
189 public void testGetStreams() {
190 Map
<Long
, Stream
> result
= fixture
.getStreams();
191 assertNotNull(result
);
195 * Run the File getTraceDirectory() method test.
198 public void testGetTraceDirectory() {
199 File result
= fixture
.getTraceDirectory();
200 assertNotNull(result
);
204 * Run the UUID getUUID() method test.
207 public void testGetUUID() {
208 UUID result
= fixture
.getUUID();
209 assertNotNull(result
);
213 * Run the Definition lookupDefinition(String) method test.
216 public void testLookupDefinition() {
217 String lookupPath
= "trace.packet.header"; //$NON-NLS-1$
218 Definition result
= fixture
.lookupDefinition(lookupPath
);
219 assertNotNull(result
);
223 * Run the boolean majortIsSet() method test.
226 public void testMajortIsSet() {
227 boolean result
= fixture
.majortIsSet();
232 * Run the boolean minorIsSet() method test.
235 public void testMinorIsSet() {
236 boolean result
= fixture
.minorIsSet();
241 * Run the boolean packetHeaderIsSet() method test with a valid header set.
244 public void testPacketHeaderIsSet_valid() {
245 boolean result
= fixture
.packetHeaderIsSet();
250 * Run the boolean packetHeaderIsSet() method test, without having a valid
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
);
262 boolean result
= fixture2
.packetHeaderIsSet();
267 * Run the void setByteOrder(ByteOrder) method test.
270 public void testSetByteOrder() {
271 ByteOrder byteOrder
= ByteOrder
.BIG_ENDIAN
;
272 fixture
.setByteOrder(byteOrder
);
276 * Run the void setMajor(long) method test.
279 public void testSetMajor() {
281 fixture
.setMajor(major
);
285 * Run the void setMinor(long) method test.
288 public void testSetMinor() {
290 fixture
.setMinor(minor
);
294 * Run the void setPacketHeader(StructDeclaration) method test.
297 public void testSetPacketHeader() {
298 StructDeclaration packetHeader
= new StructDeclaration(1L);
299 fixture
.setPacketHeader(packetHeader
);
303 * Run the void setUUID(UUID) method test.
306 public void testSetUUID() {
307 UUID uuid
= UUID
.randomUUID();
308 fixture
.setUUID(uuid
);
312 * Run the CTFClock getClock() method test.
315 public void testGetClock_1() {
316 CTFClock result
= fixture
.getClock();
317 assertNotNull(result
);
321 * Run the CTFClock getClock() method test.
325 public void testGetClock_2() {
326 CTFClock result
= fixture
.getClock("Blabla"); //$NON-NLS-1$
331 * Run the CTFClock getClock(String) method test.
334 public void testGetClock_3() {
335 String name
= "invisibleClock"; //$NON-NLS-1$
336 CTFClock result
= fixture
.getClock(name
);
342 * Run the CTFClock getClock(String) method 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
);
350 assertNotNull(result
);
354 * Run the CTFClock getClock(String) method 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
);
365 assertNotNull(result
);
366 assertTrue( (Double
)ctfClock
.getProperty("pi")> 3.0); //$NON-NLS-1$
367 assertTrue( ctfClock
.getName().equals("Bob")); //$NON-NLS-1$
371 * Run the String lookupEnvironment(String) method test.
374 public void testLookupEnvironment_1() {
375 String key
= ""; //$NON-NLS-1$
376 String result
= fixture
.lookupEnvironment(key
);
381 * Run the String lookupEnvironment(String) method test.
384 public void testLookupEnvironment_2() {
385 String key
= "otherTest"; //$NON-NLS-1$
386 String result
= fixture
.lookupEnvironment(key
);
391 * Run the String lookupEnvironment(String) method 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
));
402 * Run the String lookupEnvironment(String) method 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
);