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 public class CTFTraceTest
{
35 private CTFTrace fixture
;
41 * the command line arguments
43 public static void main(String
[] args
) {
44 new org
.junit
.runner
.JUnitCore().run(CTFTraceTest
.class);
48 * Perform pre-test initialization.
52 fixture
= TestParams
.createTraceFromFile();
54 fixture
.setUUID(UUID
.randomUUID());
55 fixture
.setPacketHeader(new StructDeclaration(1L));
57 fixture
.setByteOrder(ByteOrder
.BIG_ENDIAN
);
61 * Perform post-test clean-up.
64 public void tearDown() {
65 // Add additional tear down code here
69 * Run the CTFTrace(File) constructor test with a known existing trace.
72 public void testOpen_existing() {
73 CTFTrace result
= TestParams
.createTraceFromFile();
74 assertNotNull(result
.getUUID());
78 * Run the CTFTrace(File) constructor test with an invalid path.
80 * @throws CTFReaderException
82 @Test(expected
= org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
.class)
83 public void testOpen_invalid() throws CTFReaderException
{
84 File path
= new File(""); //$NON-NLS-1$
85 CTFTrace result
= new CTFTrace(path
);
86 assertNotNull(result
);
90 * Run the boolean UUIDIsSet() method test.
93 public void testUUIDIsSet() {
94 boolean result
= fixture
.UUIDIsSet();
99 * Run the void addStream(Stream) method test.
101 * @throws ParseException
102 * @throws CTFReaderException
105 public void testAddStream() throws ParseException
, CTFReaderException
{
106 Stream stream
= new Stream(TestParams
.createTrace());
108 fixture
.addStream(stream
);
112 * Run the boolean byteOrderIsSet() method test.
115 public void testByteOrderIsSet() {
116 boolean result
= fixture
.byteOrderIsSet();
121 * Run the ByteOrder getByteOrder() method test.
124 public void testGetByteOrder_1() {
125 ByteOrder result
= fixture
.getByteOrder();
126 assertNotNull(result
);
130 * Run the long getMajor() method test.
133 public void testGetMajor() {
134 long result
= fixture
.getMajor();
135 assertEquals(1L, result
);
139 * Run the long getMinor() method test.
142 public void testGetMinor() {
143 long result
= fixture
.getMinor();
144 assertEquals(1L, result
);
148 * Run the StructDeclaration getPacketHeader() method test.
151 public void testGetPacketHeader() {
152 StructDeclaration result
= fixture
.getPacketHeader();
153 assertNotNull(result
);
157 * Run the String getPath() method test.
160 public void testGetPath() {
161 String result
= fixture
.getPath();
162 assertNotNull(result
);
166 * Run the Stream getStream(Long) method test.
169 public void testGetStream() {
170 Long id
= new Long(0L);
171 Stream result
= fixture
.getStream(id
);
172 assertNotNull(result
);
176 * Run the Map<Long, Stream> getStreams() method test.
179 public void testGetStreams() {
180 Map
<Long
, Stream
> result
= fixture
.getStreams();
181 assertNotNull(result
);
185 * Run the File getTraceDirectory() method test.
188 public void testGetTraceDirectory() {
189 File result
= fixture
.getTraceDirectory();
190 assertNotNull(result
);
194 * Run the UUID getUUID() method test.
197 public void testGetUUID() {
198 UUID result
= fixture
.getUUID();
199 assertNotNull(result
);
203 * Run the Definition lookupDefinition(String) method test.
206 public void testLookupDefinition() {
207 String lookupPath
= "trace.packet.header"; //$NON-NLS-1$
208 Definition result
= fixture
.lookupDefinition(lookupPath
);
209 assertNotNull(result
);
213 * Run the boolean majortIsSet() method test.
216 public void testMajortIsSet() {
217 boolean result
= fixture
.majortIsSet();
222 * Run the boolean minorIsSet() method test.
225 public void testMinorIsSet() {
226 boolean result
= fixture
.minorIsSet();
231 * Run the int nbStreams() method test.
234 public void testNbStreams() {
235 int result
= fixture
.nbStreams();
236 assertEquals(2, result
);
240 * Run the boolean packetHeaderIsSet() method test with a valid header set.
243 public void testPacketHeaderIsSet_valid() {
244 boolean result
= fixture
.packetHeaderIsSet();
249 * Run the boolean packetHeaderIsSet() method test, without having a valid
253 public void testPacketHeaderIsSet_invalid() {
254 CTFTrace fixture2
= TestParams
.createTraceFromFile();
255 fixture2
.setMinor(1L);
256 fixture2
.setUUID(UUID
.randomUUID());
257 fixture2
.setPacketHeader((StructDeclaration
) null); /* it's null here! */
258 fixture2
.setMajor(1L);
259 fixture2
.setByteOrder(ByteOrder
.BIG_ENDIAN
);
261 boolean result
= fixture2
.packetHeaderIsSet();
266 * Run the void setByteOrder(ByteOrder) method test.
269 public void testSetByteOrder() {
270 ByteOrder byteOrder
= ByteOrder
.BIG_ENDIAN
;
271 fixture
.setByteOrder(byteOrder
);
275 * Run the void setMajor(long) method test.
278 public void testSetMajor() {
280 fixture
.setMajor(major
);
284 * Run the void setMinor(long) method test.
287 public void testSetMinor() {
289 fixture
.setMinor(minor
);
293 * Run the void setPacketHeader(StructDeclaration) method test.
296 public void testSetPacketHeader() {
297 StructDeclaration packetHeader
= new StructDeclaration(1L);
298 fixture
.setPacketHeader(packetHeader
);
302 * Run the void setUUID(UUID) method test.
305 public void testSetUUID() {
306 UUID uuid
= UUID
.randomUUID();
307 fixture
.setUUID(uuid
);
311 * Run the CTFClock getClock() method test.
314 public void testGetClock_1() {
315 CTFClock result
= fixture
.getClock();
316 assertNotNull(result
);
320 * Run the CTFClock getClock() method test.
324 public void testGetClock_2() {
325 CTFClock result
= fixture
.getClock("Blabla"); //$NON-NLS-1$
330 * Run the CTFClock getClock(String) method test.
333 public void testGetClock_3() {
334 String name
= ""; //$NON-NLS-1$
335 CTFClock result
= fixture
.getClock(name
);
341 * Run the CTFClock getClock(String) method test.
344 public void testSetClock_1() {
345 String name
= ""; //$NON-NLS-1$
346 fixture
.addClock(name
, new CTFClock());
347 CTFClock result
= fixture
.getClock(name
);
349 assertNotNull(result
);
353 * Run the CTFClock getClock(String) method test.
356 public void testSetClock_2() {
357 String name
= ""; //$NON-NLS-1$
358 CTFClock ctfClock
= new CTFClock();
359 ctfClock
.addAttribute("name", "Bob"); //$NON-NLS-1$ //$NON-NLS-2$
360 ctfClock
.addAttribute("pi", new Double(java
.lang
.Math
.PI
)); //$NON-NLS-1$
361 fixture
.addClock(name
, ctfClock
);
362 CTFClock result
= fixture
.getClock(name
);
364 assertNotNull(result
);
365 assertTrue( (Double
)ctfClock
.getProperty("pi")> 3.0); //$NON-NLS-1$
366 assertTrue( ctfClock
.getName().equals("Bob")); //$NON-NLS-1$
370 * Run the String lookupEnvironment(String) method test.
373 public void testLookupEnvironment_1() {
374 String key
= ""; //$NON-NLS-1$
375 String result
= fixture
.lookupEnvironment(key
);
380 * Run the String lookupEnvironment(String) method test.
383 public void testLookupEnvironment_2() {
384 String key
= "test"; //$NON-NLS-1$
385 String result
= fixture
.lookupEnvironment(key
);
390 * Run the String lookupEnvironment(String) method test.
393 public void testLookupEnvironment_3() {
394 String key
= "test"; //$NON-NLS-1$
395 fixture
.addEnvironmentVar(key
, key
);
396 String result
= fixture
.lookupEnvironment(key
);
397 assertTrue(result
.equals(key
));
401 * Run the String lookupEnvironment(String) method test.
404 public void testLookupEnvironment_4() {
405 String key
= "test"; //$NON-NLS-1$
406 fixture
.addEnvironmentVar(key
, "bozo"); //$NON-NLS-1$
407 fixture
.addEnvironmentVar(key
, "the clown"); //$NON-NLS-1$
408 String result
= fixture
.lookupEnvironment(key
);
409 assertNotNull(result
);