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