1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 Ericsson
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * Matthew Khouzam - Initial API and implementation
10 * Marc-Andre Laperle - Test in traces directory recursively
11 * Simon Delisle - Add test for getCallsite(eventName, ip)
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.ctf
.core
.tests
.trace
;
16 import static org
.junit
.Assert
.assertEquals
;
17 import static org
.junit
.Assert
.assertFalse
;
18 import static org
.junit
.Assert
.assertNotNull
;
19 import static org
.junit
.Assert
.assertNull
;
20 import static org
.junit
.Assert
.assertTrue
;
21 import static org
.junit
.Assert
.fail
;
24 import java
.nio
.ByteOrder
;
25 import java
.util
.UUID
;
27 import org
.eclipse
.tracecompass
.ctf
.core
.CTFException
;
28 import org
.eclipse
.tracecompass
.ctf
.core
.event
.CTFClock
;
29 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.IDefinition
;
30 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.StructDeclaration
;
31 import org
.eclipse
.tracecompass
.ctf
.core
.tests
.shared
.CtfTestTraceUtils
;
32 import org
.eclipse
.tracecompass
.ctf
.core
.trace
.CTFStream
;
33 import org
.eclipse
.tracecompass
.ctf
.core
.trace
.CTFTrace
;
34 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.exceptions
.ParseException
;
35 import org
.eclipse
.tracecompass
.testtraces
.ctf
.CtfTestTrace
;
36 import org
.junit
.Before
;
37 import org
.junit
.Test
;
40 * The class <code>CTFTraceTest</code> contains tests for the class
41 * <code>{@link CTFTrace}</code>.
45 public class CTFTraceTest
{
47 private static final CtfTestTrace testTrace
= CtfTestTrace
.KERNEL
;
49 private CTFTrace fixture
;
52 * Perform pre-test initialization.
57 fixture
= CtfTestTraceUtils
.getTrace(testTrace
);
58 } catch (CTFException e
) {
59 /* If the assumeTrue() call passed, this should not happen. */
63 fixture
.setUUID(UUID
.randomUUID());
64 fixture
.setPacketHeader(new StructDeclaration(1L));
66 fixture
.setByteOrder(ByteOrder
.BIG_ENDIAN
);
70 * Run the CTFTrace(File) constructor test with a known existing trace.
73 public void testOpen_existing() {
75 CTFTrace result
= CtfTestTraceUtils
.getTrace(testTrace
);
76 assertNotNull(result
.getUUID());
77 } catch (CTFException e
) {
83 * Run the CTFTrace(File) constructor test with an invalid path.
85 * @throws CTFException
88 @Test(expected
= org
.eclipse
.tracecompass
.ctf
.core
.CTFException
.class)
89 public void testOpen_invalid() throws CTFException
{
90 File path
= new File("");
91 CTFTrace result
= new CTFTrace(path
);
92 assertNotNull(result
);
96 * Run the boolean UUIDIsSet() method test.
99 public void testUUIDIsSet() {
100 boolean result
= fixture
.uuidIsSet();
105 * Run the void addStream(Stream) method test.
108 public void testAddStream() {
109 // test number of streams
110 int nbStreams
= fixture
.nbStreams();
111 assertEquals(1, nbStreams
);
115 CTFStream stream
= new CTFStream(CtfTestTraceUtils
.getTrace(testTrace
));
117 fixture
.addStream(stream
);
118 } catch (CTFException e
) {
120 } catch (ParseException e
) {
124 // test number of streams
125 nbStreams
= fixture
.nbStreams();
126 assertEquals(2, nbStreams
);
130 * Run the boolean byteOrderIsSet() method test.
133 public void testByteOrderIsSet() {
134 boolean result
= fixture
.byteOrderIsSet();
139 * Run the ByteOrder getByteOrder() method test.
142 public void testGetByteOrder_1() {
143 ByteOrder result
= fixture
.getByteOrder();
144 assertNotNull(result
);
148 * Run the long getMajor() method test.
151 public void testGetMajor() {
152 long result
= fixture
.getMajor();
153 assertEquals(1L, result
);
157 * Run the long getMinor() method test.
160 public void testGetMinor() {
161 long result
= fixture
.getMinor();
162 assertEquals(1L, result
);
166 * Run the StructDeclaration getPacketHeader() method test.
169 public void testGetPacketHeader() {
170 StructDeclaration result
= fixture
.getPacketHeader();
171 assertNotNull(result
);
175 * Run the String getPath() method test.
178 public void testGetPath() {
179 String result
= fixture
.getPath();
180 assertNotNull(result
);
184 * Run the Stream getStream(Long) method test.
187 public void testGetStream() {
188 Long id
= new Long(0L);
189 CTFStream result
= fixture
.getStream(id
);
190 assertNotNull(result
);
194 * Run the File getTraceDirectory() method test.
197 public void testGetTraceDirectory() {
198 File result
= fixture
.getTraceDirectory();
199 assertNotNull(result
);
203 * Run the UUID getUUID() method test.
206 public void testGetUUID() {
207 UUID result
= fixture
.getUUID();
208 assertNotNull(result
);
212 * Run the Definition lookupDefinition(String) method test.
215 public void testLookupDefinition() {
216 String lookupPath
= "trace.packet.header";
217 IDefinition result
= fixture
.lookupDefinition(lookupPath
);
218 assertNotNull(result
);
222 * Run the boolean majorIsSet() method test.
225 public void testMajorIsSet() {
226 boolean result
= fixture
.majorIsSet();
231 * Run the boolean minorIsSet() method test.
234 public void testMinorIsSet() {
235 boolean result
= fixture
.minorIsSet();
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() {
255 CTFTrace fixture2
= CtfTestTraceUtils
.getTrace(testTrace
);
256 fixture2
.setMinor(1L);
257 fixture2
.setUUID(UUID
.randomUUID());
261 fixture2
.setPacketHeader((StructDeclaration
) null);
262 fixture2
.setMajor(1L);
263 fixture2
.setByteOrder(ByteOrder
.BIG_ENDIAN
);
265 boolean result
= fixture2
.packetHeaderIsSet();
267 } catch (CTFException e
) {
273 * Run the void setByteOrder(ByteOrder) method test.
276 public void testSetByteOrder() {
277 ByteOrder byteOrder
= ByteOrder
.BIG_ENDIAN
;
278 fixture
.setByteOrder(byteOrder
);
282 * Run the void setMajor(long) method test.
285 public void testSetMajor() {
287 fixture
.setMajor(major
);
291 * Run the void setMinor(long) method test.
294 public void testSetMinor() {
296 fixture
.setMinor(minor
);
300 * Run the void setPacketHeader(StructDeclaration) method test.
303 public void testSetPacketHeader() {
304 StructDeclaration packetHeader
= new StructDeclaration(1L);
305 fixture
.setPacketHeader(packetHeader
);
309 * Run the void setUUID(UUID) method test.
312 public void testSetUUID() {
313 UUID uuid
= UUID
.randomUUID();
314 fixture
.setUUID(uuid
);
318 * Run the CTFClock getClock/setClock method test.
321 public void testGetSetClock_1() {
322 String name
= "clockyClock";
323 fixture
.addClock(name
, new CTFClock());
324 CTFClock result
= fixture
.getClock(name
);
326 assertNotNull(result
);
330 * Run the CTFClock getClock/setClock method test.
333 public void testGetSetClock_2() {
335 CTFClock ctfClock
= new CTFClock();
336 ctfClock
.addAttribute("name", "Bob");
337 ctfClock
.addAttribute("pi", new Double(java
.lang
.Math
.PI
));
338 fixture
.addClock(name
, ctfClock
);
339 CTFClock result
= fixture
.getClock(name
);
341 assertNotNull(result
);
342 assertTrue((Double
) ctfClock
.getProperty("pi") > 3.0);
343 assertTrue(ctfClock
.getName().equals("Bob"));
347 * Run the String lookupEnvironment(String) method test.
350 public void testLookupEnvironment_1() {
352 String result
= fixture
.getEnvironment().get(key
);
357 * Run the String lookupEnvironment(String) method test.
360 public void testLookupEnvironment_2() {
361 String key
= "otherTest";
362 String result
= fixture
.getEnvironment().get(key
);
367 * Run the String lookupEnvironment(String) method test.
370 public void testLookupEnvironment_3() {
372 fixture
.addEnvironmentVar(key
, key
);
373 String result
= fixture
.getEnvironment().get(key
);
374 assertNotNull(result
);
375 assertTrue(result
.equals(key
));
379 * Run the String lookupEnvironment(String) method test.
382 public void testLookupEnvironment_4() {
384 fixture
.addEnvironmentVar(key
, "bozo");
385 fixture
.addEnvironmentVar(key
, "the clown");
386 String result
= fixture
.getEnvironment().get(key
);
387 assertNotNull(result
);