ffd3989c1cf98c47e7c06ed7329d3bc78198babb
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.ctf.core.tests / src / org / eclipse / tracecompass / ctf / core / tests / trace / CTFTraceTest.java
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
7 *
8 * Contributors:
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 *******************************************************************************/
13
14 package org.eclipse.tracecompass.ctf.core.tests.trace;
15
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;
22
23 import java.io.File;
24 import java.nio.ByteOrder;
25 import java.util.UUID;
26
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;
38
39 /**
40 * The class <code>CTFTraceTest</code> contains tests for the class
41 * <code>{@link CTFTrace}</code>.
42 *
43 * @author ematkho
44 */
45 public class CTFTraceTest {
46
47 private static final CtfTestTrace testTrace = CtfTestTrace.KERNEL;
48
49 private CTFTrace fixture;
50
51 /**
52 * Perform pre-test initialization.
53 */
54 @Before
55 public void setUp() {
56 try {
57 fixture = CtfTestTraceUtils.getTrace(testTrace);
58 } catch (CTFException e) {
59 /* If the assumeTrue() call passed, this should not happen. */
60 fail();
61 }
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
69 /**
70 * Run the CTFTrace(File) constructor test with a known existing trace.
71 */
72 @Test
73 public void testOpen_existing() {
74 try {
75 CTFTrace result = CtfTestTraceUtils.getTrace(testTrace);
76 assertNotNull(result.getUUID());
77 } catch (CTFException e) {
78 fail();
79 }
80 }
81
82 /**
83 * Run the CTFTrace(File) constructor test with an invalid path.
84 *
85 * @throws CTFException
86 * is expected
87 */
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);
93 }
94
95 /**
96 * Run the boolean UUIDIsSet() method test.
97 */
98 @Test
99 public void testUUIDIsSet() {
100 boolean result = fixture.uuidIsSet();
101 assertTrue(result);
102 }
103
104 /**
105 * Run the void addStream(Stream) method test.
106 */
107 @Test
108 public void testAddStream() {
109 // test number of streams
110 int nbStreams = fixture.nbStreams();
111 assertEquals(1, nbStreams);
112
113 // Add a stream
114 try {
115 CTFStream stream = new CTFStream(CtfTestTraceUtils.getTrace(testTrace));
116 stream.setId(1234);
117 fixture.addStream(stream);
118 } catch (CTFException e) {
119 fail();
120 } catch (ParseException e) {
121 fail();
122 }
123
124 // test number of streams
125 nbStreams = fixture.nbStreams();
126 assertEquals(2, nbStreams);
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);
189 CTFStream result = fixture.getStream(id);
190 assertNotNull(result);
191 }
192
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() {
216 String lookupPath = "trace.packet.header";
217 IDefinition result = fixture.lookupDefinition(lookupPath);
218 assertNotNull(result);
219 }
220
221 /**
222 * Run the boolean majorIsSet() method test.
223 */
224 @Test
225 public void testMajorIsSet() {
226 boolean result = fixture.majorIsSet();
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
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() {
254 try {
255 CTFTrace fixture2 = CtfTestTraceUtils.getTrace(testTrace);
256 fixture2.setMinor(1L);
257 fixture2.setUUID(UUID.randomUUID());
258 /*
259 * it's null here!
260 */
261 fixture2.setPacketHeader((StructDeclaration) null);
262 fixture2.setMajor(1L);
263 fixture2.setByteOrder(ByteOrder.BIG_ENDIAN);
264
265 boolean result = fixture2.packetHeaderIsSet();
266 assertFalse(result);
267 } catch (CTFException e) {
268 fail();
269 }
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 }
316
317 /**
318 * Run the CTFClock getClock/setClock method test.
319 */
320 @Test
321 public void testGetSetClock_1() {
322 String name = "clockyClock";
323 fixture.addClock(name, new CTFClock());
324 CTFClock result = fixture.getClock(name);
325
326 assertNotNull(result);
327 }
328
329 /**
330 * Run the CTFClock getClock/setClock method test.
331 */
332 @Test
333 public void testGetSetClock_2() {
334 String name = "";
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);
340
341 assertNotNull(result);
342 assertTrue((Double) ctfClock.getProperty("pi") > 3.0);
343 assertTrue(ctfClock.getName().equals("Bob"));
344 }
345
346 /**
347 * Run the String lookupEnvironment(String) method test.
348 */
349 @Test
350 public void testLookupEnvironment_1() {
351 String key = "";
352 String result = fixture.getEnvironment().get(key);
353 assertNull(result);
354 }
355
356 /**
357 * Run the String lookupEnvironment(String) method test.
358 */
359 @Test
360 public void testLookupEnvironment_2() {
361 String key = "otherTest";
362 String result = fixture.getEnvironment().get(key);
363 assertNull(result);
364 }
365
366 /**
367 * Run the String lookupEnvironment(String) method test.
368 */
369 @Test
370 public void testLookupEnvironment_3() {
371 String key = "test";
372 fixture.addEnvironmentVar(key, key);
373 String result = fixture.getEnvironment().get(key);
374 assertNotNull(result);
375 assertTrue(result.equals(key));
376 }
377
378 /**
379 * Run the String lookupEnvironment(String) method test.
380 */
381 @Test
382 public void testLookupEnvironment_4() {
383 String key = "test";
384 fixture.addEnvironmentVar(key, "bozo");
385 fixture.addEnvironmentVar(key, "the clown");
386 String result = fixture.getEnvironment().get(key);
387 assertNotNull(result);
388 }
389 }
This page took 0.04898 seconds and 5 git commands to generate.