Fix warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / trace / CTFTraceTest.java
1 package org.eclipse.linuxtools.ctf.core.tests.trace;
2
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;
8
9 import java.io.File;
10 import java.nio.ByteOrder;
11 import java.util.Map;
12 import java.util.UUID;
13
14 import org.eclipse.linuxtools.ctf.core.event.CTFClock;
15 import org.eclipse.linuxtools.ctf.core.event.metadata.exceptions.ParseException;
16 import org.eclipse.linuxtools.ctf.core.event.types.Definition;
17 import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
18 import org.eclipse.linuxtools.ctf.core.tests.TestParams;
19 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
20 import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
21 import org.eclipse.linuxtools.ctf.core.trace.Stream;
22 import org.junit.After;
23 import org.junit.Before;
24 import org.junit.Test;
25
26 /**
27 * The class <code>CTFTraceTest</code> contains tests for the class
28 * <code>{@link CTFTrace}</code>.
29 *
30 * @author ematkho
31 * @version $Revision: 1.0 $
32 */
33 public class CTFTraceTest {
34
35 private CTFTrace fixture;
36
37 /**
38 * Launch the test.
39 *
40 * @param args
41 * the command line arguments
42 */
43 public static void main(String[] args) {
44 new org.junit.runner.JUnitCore().run(CTFTraceTest.class);
45 }
46
47 /**
48 * Perform pre-test initialization.
49 */
50 @Before
51 public void setUp() {
52 fixture = TestParams.createTraceFromFile();
53 fixture.setMinor(1L);
54 fixture.setUUID(UUID.randomUUID());
55 fixture.setPacketHeader(new StructDeclaration(1L));
56 fixture.setMajor(1L);
57 fixture.setByteOrder(ByteOrder.BIG_ENDIAN);
58 }
59
60 /**
61 * Perform post-test clean-up.
62 */
63 @After
64 public void tearDown() {
65 // Add additional tear down code here
66 }
67
68 /**
69 * Run the CTFTrace(File) constructor test with a known existing trace.
70 */
71 @Test
72 public void testOpen_existing() {
73 CTFTrace result = TestParams.createTraceFromFile();
74 assertNotNull(result.getUUID());
75 }
76
77 /**
78 * Run the CTFTrace(File) constructor test with an invalid path.
79 *
80 * @throws CTFReaderException
81 */
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);
87 }
88
89 /**
90 * Run the boolean UUIDIsSet() method test.
91 */
92 @Test
93 public void testUUIDIsSet() {
94 boolean result = fixture.UUIDIsSet();
95 assertTrue(result);
96 }
97
98 /**
99 * Run the void addStream(Stream) method test.
100 *
101 * @throws ParseException
102 * @throws CTFReaderException
103 */
104 @Test
105 public void testAddStream() throws ParseException, CTFReaderException {
106 Stream stream = new Stream(TestParams.createTrace());
107 stream.setId(1L);
108 fixture.addStream(stream);
109 }
110
111 /**
112 * Run the boolean byteOrderIsSet() method test.
113 */
114 @Test
115 public void testByteOrderIsSet() {
116 boolean result = fixture.byteOrderIsSet();
117 assertTrue(result);
118 }
119
120 /**
121 * Run the ByteOrder getByteOrder() method test.
122 */
123 @Test
124 public void testGetByteOrder_1() {
125 ByteOrder result = fixture.getByteOrder();
126 assertNotNull(result);
127 }
128
129 /**
130 * Run the long getMajor() method test.
131 */
132 @Test
133 public void testGetMajor() {
134 long result = fixture.getMajor();
135 assertEquals(1L, result);
136 }
137
138 /**
139 * Run the long getMinor() method test.
140 */
141 @Test
142 public void testGetMinor() {
143 long result = fixture.getMinor();
144 assertEquals(1L, result);
145 }
146
147 /**
148 * Run the StructDeclaration getPacketHeader() method test.
149 */
150 @Test
151 public void testGetPacketHeader() {
152 StructDeclaration result = fixture.getPacketHeader();
153 assertNotNull(result);
154 }
155
156 /**
157 * Run the String getPath() method test.
158 */
159 @Test
160 public void testGetPath() {
161 String result = fixture.getPath();
162 assertNotNull(result);
163 }
164
165 /**
166 * Run the Stream getStream(Long) method test.
167 */
168 @Test
169 public void testGetStream() {
170 Long id = new Long(0L);
171 Stream result = fixture.getStream(id);
172 assertNotNull(result);
173 }
174
175 /**
176 * Run the Map<Long, Stream> getStreams() method test.
177 */
178 @Test
179 public void testGetStreams() {
180 Map<Long, Stream> result = fixture.getStreams();
181 assertNotNull(result);
182 }
183
184 /**
185 * Run the File getTraceDirectory() method test.
186 */
187 @Test
188 public void testGetTraceDirectory() {
189 File result = fixture.getTraceDirectory();
190 assertNotNull(result);
191 }
192
193 /**
194 * Run the UUID getUUID() method test.
195 */
196 @Test
197 public void testGetUUID() {
198 UUID result = fixture.getUUID();
199 assertNotNull(result);
200 }
201
202 /**
203 * Run the Definition lookupDefinition(String) method test.
204 */
205 @Test
206 public void testLookupDefinition() {
207 String lookupPath = "trace.packet.header"; //$NON-NLS-1$
208 Definition result = fixture.lookupDefinition(lookupPath);
209 assertNotNull(result);
210 }
211
212 /**
213 * Run the boolean majortIsSet() method test.
214 */
215 @Test
216 public void testMajortIsSet() {
217 boolean result = fixture.majortIsSet();
218 assertTrue(result);
219 }
220
221 /**
222 * Run the boolean minorIsSet() method test.
223 */
224 @Test
225 public void testMinorIsSet() {
226 boolean result = fixture.minorIsSet();
227 assertTrue(result);
228 }
229
230 /**
231 * Run the int nbStreams() method test.
232 */
233 @Test
234 public void testNbStreams() {
235 int result = fixture.nbStreams();
236 assertEquals(2, 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 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);
260
261 boolean result = fixture2.packetHeaderIsSet();
262 assertFalse(result);
263 }
264
265 /**
266 * Run the void setByteOrder(ByteOrder) method test.
267 */
268 @Test
269 public void testSetByteOrder() {
270 ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
271 fixture.setByteOrder(byteOrder);
272 }
273
274 /**
275 * Run the void setMajor(long) method test.
276 */
277 @Test
278 public void testSetMajor() {
279 long major = 1L;
280 fixture.setMajor(major);
281 }
282
283 /**
284 * Run the void setMinor(long) method test.
285 */
286 @Test
287 public void testSetMinor() {
288 long minor = 1L;
289 fixture.setMinor(minor);
290 }
291
292 /**
293 * Run the void setPacketHeader(StructDeclaration) method test.
294 */
295 @Test
296 public void testSetPacketHeader() {
297 StructDeclaration packetHeader = new StructDeclaration(1L);
298 fixture.setPacketHeader(packetHeader);
299 }
300
301 /**
302 * Run the void setUUID(UUID) method test.
303 */
304 @Test
305 public void testSetUUID() {
306 UUID uuid = UUID.randomUUID();
307 fixture.setUUID(uuid);
308 }
309
310 /**
311 * Run the CTFClock getClock() method test.
312 */
313 @Test
314 public void testGetClock_1() {
315 CTFClock result = fixture.getClock();
316 assertNull(result);
317 }
318
319 /**
320 * Run the CTFClock getClock() method test.
321 *
322 */
323 @Test
324 public void testGetClock_2() {
325 CTFClock result = fixture.getClock("Blabla"); //$NON-NLS-1$
326 assertNull(result);
327 }
328
329 /**
330 * Run the CTFClock getClock(String) method test.
331 */
332 @Test
333 public void testGetClock_3() {
334 String name = ""; //$NON-NLS-1$
335 CTFClock result = fixture.getClock(name);
336 assertNull(result);
337 }
338
339
340 /**
341 * Run the CTFClock getClock(String) method test.
342 */
343 @Test
344 public void testSetClock_1() {
345 String name = ""; //$NON-NLS-1$
346 fixture.addClock(name, new CTFClock());
347 CTFClock result = fixture.getClock(name);
348
349 assertNotNull(result);
350 }
351
352 /**
353 * Run the CTFClock getClock(String) method test.
354 */
355 @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);
363
364 assertNotNull(result);
365 assertTrue( (Double)ctfClock.getProperty("pi")> 3.0); //$NON-NLS-1$
366 assertTrue( ctfClock.getName().equals("Bob")); //$NON-NLS-1$
367 }
368
369 /**
370 * Run the String lookupEnvironment(String) method test.
371 */
372 @Test
373 public void testLookupEnvironment_1() {
374 String key = ""; //$NON-NLS-1$
375 String result = fixture.lookupEnvironment(key);
376 assertNull(result);
377 }
378
379 /**
380 * Run the String lookupEnvironment(String) method test.
381 */
382 @Test
383 public void testLookupEnvironment_2() {
384 String key = "test"; //$NON-NLS-1$
385 String result = fixture.lookupEnvironment(key);
386 assertNull(result);
387 }
388
389 /**
390 * Run the String lookupEnvironment(String) method test.
391 */
392 @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));
398 }
399
400 /**
401 * Run the String lookupEnvironment(String) method test.
402 */
403 @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);
410 }
411
412 }
This page took 0.042428 seconds and 6 git commands to generate.