ctf: Depend on the tracecompass-test-traces project
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.ctf.core.tests / src / org / eclipse / tracecompass / ctf / core / tests / trace / CTFTraceTest.java
CommitLineData
4bd7f2db 1/*******************************************************************************
60ae41e1 2 * Copyright (c) 2013, 2014 Ericsson
4bd7f2db
AM
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
7 *
8 * Contributors:
9 * Matthew Khouzam - Initial API and implementation
4311ac8b 10 * Marc-Andre Laperle - Test in traces directory recursively
890f9136 11 * Simon Delisle - Add test for getCallsite(eventName, ip)
4bd7f2db
AM
12 *******************************************************************************/
13
f357bcd4 14package org.eclipse.tracecompass.ctf.core.tests.trace;
866e5b51
FC
15
16import static org.junit.Assert.assertEquals;
17import static org.junit.Assert.assertFalse;
18import static org.junit.Assert.assertNotNull;
e291b8c8 19import static org.junit.Assert.assertNull;
866e5b51 20import static org.junit.Assert.assertTrue;
30753cb3 21import static org.junit.Assert.fail;
866e5b51
FC
22
23import java.io.File;
24import java.nio.ByteOrder;
866e5b51
FC
25import java.util.UUID;
26
680f9173 27import org.eclipse.tracecompass.ctf.core.CTFException;
f357bcd4
AM
28import org.eclipse.tracecompass.ctf.core.event.CTFClock;
29import org.eclipse.tracecompass.ctf.core.event.types.IDefinition;
30import org.eclipse.tracecompass.ctf.core.event.types.StructDeclaration;
c4d57ac1 31import org.eclipse.tracecompass.ctf.core.tests.shared.CtfTestTraceUtils;
f357bcd4
AM
32import org.eclipse.tracecompass.ctf.core.trace.CTFStream;
33import org.eclipse.tracecompass.ctf.core.trace.CTFTrace;
34import org.eclipse.tracecompass.internal.ctf.core.event.metadata.exceptions.ParseException;
c4d57ac1 35import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
866e5b51
FC
36import org.junit.Before;
37import org.junit.Test;
38
39/**
40 * The class <code>CTFTraceTest</code> contains tests for the class
41 * <code>{@link CTFTrace}</code>.
e291b8c8 42 *
866e5b51 43 * @author ematkho
866e5b51
FC
44 */
45public class CTFTraceTest {
46
9ac63b5b 47 private static final CtfTestTrace testTrace = CtfTestTrace.KERNEL;
32bf80d2 48
866e5b51
FC
49 private CTFTrace fixture;
50
866e5b51
FC
51 /**
52 * Perform pre-test initialization.
53 */
54 @Before
55 public void setUp() {
9ac63b5b 56 try {
c4d57ac1 57 fixture = CtfTestTraceUtils.getTrace(testTrace);
680f9173 58 } catch (CTFException e) {
9ac63b5b
AM
59 /* If the assumeTrue() call passed, this should not happen. */
60 fail();
61 }
866e5b51
FC
62 fixture.setMinor(1L);
63 fixture.setUUID(UUID.randomUUID());
64 fixture.setPacketHeader(new StructDeclaration(1L));
65 fixture.setMajor(1L);
66 fixture.setByteOrder(ByteOrder.BIG_ENDIAN);
67 }
68
866e5b51
FC
69 /**
70 * Run the CTFTrace(File) constructor test with a known existing trace.
71 */
72 @Test
73 public void testOpen_existing() {
b562a24f 74 try {
c4d57ac1 75 CTFTrace result = CtfTestTraceUtils.getTrace(testTrace);
9ac63b5b 76 assertNotNull(result.getUUID());
680f9173 77 } catch (CTFException e) {
9ac63b5b
AM
78 fail();
79 }
866e5b51
FC
80 }
81
82 /**
83 * Run the CTFTrace(File) constructor test with an invalid path.
e291b8c8 84 *
680f9173 85 * @throws CTFException
30753cb3 86 * is expected
866e5b51 87 */
680f9173
MK
88 @Test(expected = org.eclipse.tracecompass.ctf.core.CTFException.class)
89 public void testOpen_invalid() throws CTFException {
30753cb3 90 File path = new File("");
b562a24f
MK
91 CTFTrace result = new CTFTrace(path);
92 assertNotNull(result);
866e5b51
FC
93 }
94
95 /**
96 * Run the boolean UUIDIsSet() method test.
97 */
98 @Test
99 public void testUUIDIsSet() {
0594c61c 100 boolean result = fixture.uuidIsSet();
866e5b51
FC
101 assertTrue(result);
102 }
103
104 /**
105 * Run the void addStream(Stream) method test.
866e5b51
FC
106 */
107 @Test
30753cb3 108 public void testAddStream() {
b26a2c52
BH
109 // test number of streams
110 int nbStreams = fixture.nbStreams();
111 assertEquals(1, nbStreams);
30753cb3 112
b26a2c52 113 // Add a stream
30753cb3 114 try {
c4d57ac1 115 CTFStream stream = new CTFStream(CtfTestTraceUtils.getTrace(testTrace));
30753cb3
AM
116 stream.setId(1234);
117 fixture.addStream(stream);
680f9173 118 } catch (CTFException e) {
30753cb3
AM
119 fail();
120 } catch (ParseException e) {
121 fail();
122 }
123
b26a2c52
BH
124 // test number of streams
125 nbStreams = fixture.nbStreams();
126 assertEquals(2, nbStreams);
866e5b51
FC
127 }
128
129 /**
130 * Run the boolean byteOrderIsSet() method test.
131 */
132 @Test
133 public void testByteOrderIsSet() {
134 boolean result = fixture.byteOrderIsSet();
135 assertTrue(result);
136 }
137
138 /**
139 * Run the ByteOrder getByteOrder() method test.
140 */
141 @Test
142 public void testGetByteOrder_1() {
143 ByteOrder result = fixture.getByteOrder();
144 assertNotNull(result);
145 }
146
147 /**
148 * Run the long getMajor() method test.
149 */
150 @Test
151 public void testGetMajor() {
152 long result = fixture.getMajor();
153 assertEquals(1L, result);
154 }
155
156 /**
157 * Run the long getMinor() method test.
158 */
159 @Test
160 public void testGetMinor() {
161 long result = fixture.getMinor();
162 assertEquals(1L, result);
163 }
164
165 /**
166 * Run the StructDeclaration getPacketHeader() method test.
167 */
168 @Test
169 public void testGetPacketHeader() {
170 StructDeclaration result = fixture.getPacketHeader();
171 assertNotNull(result);
172 }
173
174 /**
175 * Run the String getPath() method test.
176 */
177 @Test
178 public void testGetPath() {
179 String result = fixture.getPath();
180 assertNotNull(result);
181 }
182
183 /**
184 * Run the Stream getStream(Long) method test.
185 */
186 @Test
187 public void testGetStream() {
188 Long id = new Long(0L);
d84419e1 189 CTFStream result = fixture.getStream(id);
866e5b51
FC
190 assertNotNull(result);
191 }
192
866e5b51
FC
193 /**
194 * Run the File getTraceDirectory() method test.
195 */
196 @Test
197 public void testGetTraceDirectory() {
198 File result = fixture.getTraceDirectory();
199 assertNotNull(result);
200 }
201
202 /**
203 * Run the UUID getUUID() method test.
204 */
205 @Test
206 public void testGetUUID() {
207 UUID result = fixture.getUUID();
208 assertNotNull(result);
209 }
210
211 /**
212 * Run the Definition lookupDefinition(String) method test.
213 */
214 @Test
215 public void testLookupDefinition() {
30753cb3 216 String lookupPath = "trace.packet.header";
cc98c947 217 IDefinition result = fixture.lookupDefinition(lookupPath);
866e5b51
FC
218 assertNotNull(result);
219 }
220
221 /**
07804639 222 * Run the boolean majorIsSet() method test.
866e5b51
FC
223 */
224 @Test
07804639
EB
225 public void testMajorIsSet() {
226 boolean result = fixture.majorIsSet();
866e5b51
FC
227 assertTrue(result);
228 }
229
230 /**
231 * Run the boolean minorIsSet() method test.
232 */
233 @Test
234 public void testMinorIsSet() {
235 boolean result = fixture.minorIsSet();
236 assertTrue(result);
237 }
238
866e5b51
FC
239 /**
240 * Run the boolean packetHeaderIsSet() method test with a valid header set.
241 */
242 @Test
243 public void testPacketHeaderIsSet_valid() {
244 boolean result = fixture.packetHeaderIsSet();
245 assertTrue(result);
246 }
247
248 /**
249 * Run the boolean packetHeaderIsSet() method test, without having a valid
250 * header set.
251 */
252 @Test
253 public void testPacketHeaderIsSet_invalid() {
b562a24f 254 try {
c4d57ac1 255 CTFTrace fixture2 = CtfTestTraceUtils.getTrace(testTrace);
9ac63b5b
AM
256 fixture2.setMinor(1L);
257 fixture2.setUUID(UUID.randomUUID());
b562a24f
MK
258 /*
259 * it's null here!
260 */
261 fixture2.setPacketHeader((StructDeclaration) null);
9ac63b5b
AM
262 fixture2.setMajor(1L);
263 fixture2.setByteOrder(ByteOrder.BIG_ENDIAN);
264
265 boolean result = fixture2.packetHeaderIsSet();
266 assertFalse(result);
680f9173 267 } catch (CTFException e) {
9ac63b5b
AM
268 fail();
269 }
866e5b51
FC
270 }
271
272 /**
273 * Run the void setByteOrder(ByteOrder) method test.
274 */
275 @Test
276 public void testSetByteOrder() {
277 ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
278 fixture.setByteOrder(byteOrder);
279 }
280
281 /**
282 * Run the void setMajor(long) method test.
283 */
284 @Test
285 public void testSetMajor() {
286 long major = 1L;
287 fixture.setMajor(major);
288 }
289
290 /**
291 * Run the void setMinor(long) method test.
292 */
293 @Test
294 public void testSetMinor() {
295 long minor = 1L;
296 fixture.setMinor(minor);
297 }
298
299 /**
300 * Run the void setPacketHeader(StructDeclaration) method test.
301 */
302 @Test
303 public void testSetPacketHeader() {
304 StructDeclaration packetHeader = new StructDeclaration(1L);
305 fixture.setPacketHeader(packetHeader);
306 }
307
308 /**
309 * Run the void setUUID(UUID) method test.
310 */
311 @Test
312 public void testSetUUID() {
313 UUID uuid = UUID.randomUUID();
314 fixture.setUUID(uuid);
315 }
e291b8c8
MK
316
317 /**
30753cb3 318 * Run the CTFClock getClock/setClock method test.
e291b8c8
MK
319 */
320 @Test
30753cb3
AM
321 public void testGetSetClock_1() {
322 String name = "clockyClock";
e291b8c8
MK
323 fixture.addClock(name, new CTFClock());
324 CTFClock result = fixture.getClock(name);
325
326 assertNotNull(result);
327 }
328
329 /**
30753cb3 330 * Run the CTFClock getClock/setClock method test.
e291b8c8
MK
331 */
332 @Test
30753cb3
AM
333 public void testGetSetClock_2() {
334 String name = "";
e291b8c8 335 CTFClock ctfClock = new CTFClock();
30753cb3
AM
336 ctfClock.addAttribute("name", "Bob");
337 ctfClock.addAttribute("pi", new Double(java.lang.Math.PI));
e291b8c8
MK
338 fixture.addClock(name, ctfClock);
339 CTFClock result = fixture.getClock(name);
340
341 assertNotNull(result);
30753cb3
AM
342 assertTrue((Double) ctfClock.getProperty("pi") > 3.0);
343 assertTrue(ctfClock.getName().equals("Bob"));
e291b8c8
MK
344 }
345
346 /**
347 * Run the String lookupEnvironment(String) method test.
348 */
349 @Test
350 public void testLookupEnvironment_1() {
30753cb3 351 String key = "";
a95fddf5 352 String result = fixture.getEnvironment().get(key);
e291b8c8
MK
353 assertNull(result);
354 }
355
356 /**
357 * Run the String lookupEnvironment(String) method test.
358 */
359 @Test
360 public void testLookupEnvironment_2() {
30753cb3 361 String key = "otherTest";
a95fddf5 362 String result = fixture.getEnvironment().get(key);
e291b8c8
MK
363 assertNull(result);
364 }
365
366 /**
367 * Run the String lookupEnvironment(String) method test.
368 */
369 @Test
370 public void testLookupEnvironment_3() {
30753cb3 371 String key = "test";
e291b8c8 372 fixture.addEnvironmentVar(key, key);
a95fddf5 373 String result = fixture.getEnvironment().get(key);
202956f1 374 assertNotNull(result);
e291b8c8
MK
375 assertTrue(result.equals(key));
376 }
377
378 /**
379 * Run the String lookupEnvironment(String) method test.
380 */
381 @Test
382 public void testLookupEnvironment_4() {
30753cb3
AM
383 String key = "test";
384 fixture.addEnvironmentVar(key, "bozo");
385 fixture.addEnvironmentVar(key, "the clown");
a95fddf5 386 String result = fixture.getEnvironment().get(key);
e291b8c8
MK
387 assertNotNull(result);
388 }
866e5b51 389}
This page took 0.317376 seconds and 5 git commands to generate.