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
.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
;
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 static final int TRACE_INDEX
= 0;
39 private CTFTrace fixture
;
45 * the command line arguments
47 public static void main(String
[] args
) {
48 new org
.junit
.runner
.JUnitCore().run(CTFTraceTest
.class);
52 * Perform pre-test initialization.
56 assumeTrue(CtfTestTraces
.tracesExist());
57 fixture
= CtfTestTraces
.getTestTraceFromFile(TRACE_INDEX
);
59 fixture
.setUUID(UUID
.randomUUID());
60 fixture
.setPacketHeader(new StructDeclaration(1L));
62 fixture
.setByteOrder(ByteOrder
.BIG_ENDIAN
);
66 * Perform post-test clean-up.
69 public void tearDown() {
70 // Add additional tear down code here
74 * Run the CTFTrace(File) constructor test with a known existing trace.
77 public void testOpen_existing() {
78 CTFTrace result
= CtfTestTraces
.getTestTraceFromFile(TRACE_INDEX
);
79 assertNotNull(result
.getUUID());
83 * Run the CTFTrace(File) constructor test with an invalid path.
85 * @throws CTFReaderException
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
);
95 * Run the boolean UUIDIsSet() method test.
98 public void testUUIDIsSet() {
99 boolean result
= fixture
.UUIDIsSet();
104 * Run the void addStream(Stream) method test.
106 * @throws ParseException
107 * @throws CTFReaderException
110 public void testAddStream() throws ParseException
, CTFReaderException
{
111 // test number of streams
112 int nbStreams
= fixture
.nbStreams();
113 assertEquals(1, nbStreams
);
115 Stream stream
= new Stream(CtfTestTraces
.getTestTrace(TRACE_INDEX
));
117 fixture
.addStream(stream
);
118 // test number of streams
119 nbStreams
= fixture
.nbStreams();
120 assertEquals(2, nbStreams
);
124 * Run the boolean byteOrderIsSet() method test.
127 public void testByteOrderIsSet() {
128 boolean result
= fixture
.byteOrderIsSet();
133 * Run the ByteOrder getByteOrder() method test.
136 public void testGetByteOrder_1() {
137 ByteOrder result
= fixture
.getByteOrder();
138 assertNotNull(result
);
142 * Run the long getMajor() method test.
145 public void testGetMajor() {
146 long result
= fixture
.getMajor();
147 assertEquals(1L, result
);
151 * Run the long getMinor() method test.
154 public void testGetMinor() {
155 long result
= fixture
.getMinor();
156 assertEquals(1L, result
);
160 * Run the StructDeclaration getPacketHeader() method test.
163 public void testGetPacketHeader() {
164 StructDeclaration result
= fixture
.getPacketHeader();
165 assertNotNull(result
);
169 * Run the String getPath() method test.
172 public void testGetPath() {
173 String result
= fixture
.getPath();
174 assertNotNull(result
);
178 * Run the Stream getStream(Long) method test.
181 public void testGetStream() {
182 Long id
= new Long(0L);
183 Stream result
= fixture
.getStream(id
);
184 assertNotNull(result
);
188 * Run the Map<Long, Stream> getStreams() method test.
191 public void testGetStreams() {
192 Map
<Long
, Stream
> result
= fixture
.getStreams();
193 assertNotNull(result
);
197 * Run the File getTraceDirectory() method test.
200 public void testGetTraceDirectory() {
201 File result
= fixture
.getTraceDirectory();
202 assertNotNull(result
);
206 * Run the UUID getUUID() method test.
209 public void testGetUUID() {
210 UUID result
= fixture
.getUUID();
211 assertNotNull(result
);
215 * Run the Definition lookupDefinition(String) method test.
218 public void testLookupDefinition() {
219 String lookupPath
= "trace.packet.header"; //$NON-NLS-1$
220 Definition result
= fixture
.lookupDefinition(lookupPath
);
221 assertNotNull(result
);
225 * Run the boolean majortIsSet() method test.
228 public void testMajortIsSet() {
229 boolean result
= fixture
.majortIsSet();
234 * Run the boolean minorIsSet() method test.
237 public void testMinorIsSet() {
238 boolean result
= fixture
.minorIsSet();
243 * Run the boolean packetHeaderIsSet() method test with a valid header set.
246 public void testPacketHeaderIsSet_valid() {
247 boolean result
= fixture
.packetHeaderIsSet();
252 * Run the boolean packetHeaderIsSet() method test, without having a valid
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
);
264 boolean result
= fixture2
.packetHeaderIsSet();
269 * Run the void setByteOrder(ByteOrder) method test.
272 public void testSetByteOrder() {
273 ByteOrder byteOrder
= ByteOrder
.BIG_ENDIAN
;
274 fixture
.setByteOrder(byteOrder
);
278 * Run the void setMajor(long) method test.
281 public void testSetMajor() {
283 fixture
.setMajor(major
);
287 * Run the void setMinor(long) method test.
290 public void testSetMinor() {
292 fixture
.setMinor(minor
);
296 * Run the void setPacketHeader(StructDeclaration) method test.
299 public void testSetPacketHeader() {
300 StructDeclaration packetHeader
= new StructDeclaration(1L);
301 fixture
.setPacketHeader(packetHeader
);
305 * Run the void setUUID(UUID) method test.
308 public void testSetUUID() {
309 UUID uuid
= UUID
.randomUUID();
310 fixture
.setUUID(uuid
);
314 * Run the CTFClock getClock() method test.
317 public void testGetClock_1() {
318 CTFClock result
= fixture
.getClock();
319 assertNotNull(result
);
323 * Run the CTFClock getClock() method test.
327 public void testGetClock_2() {
328 CTFClock result
= fixture
.getClock("Blabla"); //$NON-NLS-1$
333 * Run the CTFClock getClock(String) method test.
336 public void testGetClock_3() {
337 String name
= "invisibleClock"; //$NON-NLS-1$
338 CTFClock result
= fixture
.getClock(name
);
344 * Run the CTFClock getClock(String) method 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
);
352 assertNotNull(result
);
356 * Run the CTFClock getClock(String) method 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
);
367 assertNotNull(result
);
368 assertTrue( (Double
)ctfClock
.getProperty("pi")> 3.0); //$NON-NLS-1$
369 assertTrue( ctfClock
.getName().equals("Bob")); //$NON-NLS-1$
373 * Run the String lookupEnvironment(String) method test.
376 public void testLookupEnvironment_1() {
377 String key
= ""; //$NON-NLS-1$
378 String result
= fixture
.lookupEnvironment(key
);
383 * Run the String lookupEnvironment(String) method test.
386 public void testLookupEnvironment_2() {
387 String key
= "otherTest"; //$NON-NLS-1$
388 String result
= fixture
.lookupEnvironment(key
);
393 * Run the String lookupEnvironment(String) method 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
));
404 * Run the String lookupEnvironment(String) method 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
);