Fix some null warnings
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.tmf.ctf.core.tests / src / org / eclipse / tracecompass / tmf / ctf / core / tests / trace / CtfTmfTraceTest.java
CommitLineData
95bf10e7 1/*******************************************************************************
da707390 2 * Copyright (c) 2012, 2015 Ericsson
95bf10e7
AM
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Matthew Khouzam - Initial generation with CodePro tools
11 * Alexandre Montplaisir - Clean up, consolidate redundant tests
4a1f6c41 12 * Patrick Tasse - Fix location ratio
95bf10e7
AM
13 *******************************************************************************/
14
9722e5d7 15package org.eclipse.tracecompass.tmf.ctf.core.tests.trace;
81c8e6f7
MK
16
17import static org.junit.Assert.assertEquals;
3480bf12 18import static org.junit.Assert.assertFalse;
81c8e6f7
MK
19import static org.junit.Assert.assertNotNull;
20import static org.junit.Assert.assertNull;
21import static org.junit.Assert.assertTrue;
22
409bea20
GB
23import java.util.Arrays;
24import java.util.HashSet;
25import java.util.Set;
26
81c8e6f7
MK
27import org.eclipse.core.resources.IProject;
28import org.eclipse.core.resources.IResource;
a94410d9 29import org.eclipse.core.runtime.IStatus;
c4d57ac1
AM
30import org.eclipse.jdt.annotation.NonNull;
31import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
2bdf0193 32import org.eclipse.tracecompass.tmf.core.event.ITmfEventType;
2bdf0193
AM
33import org.eclipse.tracecompass.tmf.core.signal.TmfEndSynchSignal;
34import org.eclipse.tracecompass.tmf.core.signal.TmfSignal;
35import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
da707390 36import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp;
2bdf0193
AM
37import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
38import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
39import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
40import org.eclipse.tracecompass.tmf.core.trace.TmfEventTypeCollectionHelper;
9722e5d7
AM
41import org.eclipse.tracecompass.tmf.ctf.core.context.CtfLocation;
42import org.eclipse.tracecompass.tmf.ctf.core.context.CtfLocationInfo;
43import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
c4d57ac1 44import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
9722e5d7 45import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
81c8e6f7
MK
46import org.junit.After;
47import org.junit.Before;
48import org.junit.Test;
49
50/**
95bf10e7
AM
51 * The class <code>CtfTmfTraceTest</code> contains tests for the class
52 * <code>{@link CtfTmfTrace}</code>.
81c8e6f7 53 *
81c8e6f7 54 * @author ematkho
95bf10e7 55 * @version 1.0
81c8e6f7
MK
56 */
57public class CtfTmfTraceTest {
95bf10e7 58
c4d57ac1 59 private static final @NonNull CtfTestTrace testTrace = CtfTestTrace.KERNEL;
81c8e6f7 60
95bf10e7
AM
61 private CtfTmfTrace fixture;
62
95bf10e7
AM
63 /**
64 * Perform pre-test initialization.
81c8e6f7 65 */
95bf10e7 66 @Before
c4d57ac1
AM
67 public void setUp() {
68 fixture = CtfTmfTestTraceUtils.getTrace(testTrace);
95bf10e7 69 }
81c8e6f7 70
95bf10e7
AM
71 /**
72 * Perform post-test clean-up.
73 */
74 @After
75 public void tearDown() {
5dd1fa65
AM
76 if (fixture != null) {
77 fixture.dispose();
78 }
95bf10e7
AM
79 }
80
81 /**
82 * Run the CtfTmfTrace() constructor test.
83 */
84 @Test
85 public void testCtfTmfTrace() {
0ff9e595
AM
86 CtfTmfTrace result = new CtfTmfTrace();
87
88 assertNotNull(result);
89 assertEquals(1000, result.getCacheSize());
90 assertEquals(0L, result.getNbEvents());
91 assertEquals(0L, result.getStreamingInterval());
92 assertNull(result.getResource());
ea652979 93 assertNull(result.getEventType());
0ff9e595
AM
94
95 result.dispose();
81c8e6f7
MK
96 }
97
95bf10e7
AM
98 /**
99 * Test the parseEvent() method
100 */
788ddcbc 101 @Test
95bf10e7 102 public void testParseEvent() {
788ddcbc
MK
103 ITmfContext ctx = fixture.seekEvent(0);
104 fixture.getNext(ctx);
105 CtfTmfEvent event = fixture.parseEvent(ctx);
106 assertNotNull(event);
4a1f6c41 107 ctx.dispose();
788ddcbc
MK
108 }
109
81c8e6f7
MK
110 /**
111 * Run the void broadcast(TmfSignal) method test.
81c8e6f7
MK
112 */
113 @Test
95bf10e7 114 public void testBroadcast() {
81c8e6f7 115 TmfSignal signal = new TmfEndSynchSignal(1);
81c8e6f7 116 fixture.broadcast(signal);
81c8e6f7
MK
117 }
118
409bea20
GB
119 /**
120 * Run the void dispose() method test.
121 */
122 @Test
0ff9e595
AM
123 public void testDispose() {
124 CtfTmfTrace emptyFixture = new CtfTmfTrace();
125 emptyFixture.dispose();
409bea20
GB
126 }
127
81c8e6f7
MK
128 /**
129 * Run the int getCacheSize() method test.
81c8e6f7
MK
130 */
131 @Test
95bf10e7 132 public void testGetCacheSize() {
0ff9e595
AM
133 CtfTmfTrace emptyFixture = new CtfTmfTrace();
134 int result = emptyFixture.getCacheSize();
135 assertEquals(1000, result);
136
137 emptyFixture.dispose();
81c8e6f7
MK
138 }
139
140 /**
141 * Run the ITmfLocation<Comparable> getCurrentLocation() method test.
81c8e6f7
MK
142 */
143 @Test
95bf10e7 144 public void testGetCurrentLocation() {
81c8e6f7 145 CtfLocation result = (CtfLocation) fixture.getCurrentLocation();
f474d36b 146 assertNull(result);
81c8e6f7
MK
147 }
148
95bf10e7
AM
149 /**
150 * Test the seekEvent() method with a null location.
151 */
81c8e6f7 152 @Test
95bf10e7 153 public void testSeekEventLoc_null() {
81c8e6f7
MK
154 CtfLocation loc = null;
155 fixture.seekEvent(loc);
156 assertNotNull(fixture);
157 }
158
95bf10e7
AM
159 /**
160 * Test the seekEvent() method with a location from a timestamp.
161 */
81c8e6f7 162 @Test
409bea20 163 public void testSeekEventLoc_timetamp() {
da707390 164 CtfLocation loc = new CtfLocation(new TmfNanoTimestamp(0L));
81c8e6f7
MK
165 fixture.seekEvent(loc);
166 assertNotNull(fixture);
167 }
168
81c8e6f7
MK
169 /**
170 * Run the ITmfTimestamp getEndTime() method test.
81c8e6f7
MK
171 */
172 @Test
95bf10e7 173 public void testGetEndTime() {
81c8e6f7
MK
174 ITmfTimestamp result = fixture.getEndTime();
175 assertNotNull(result);
176 }
177
178 /**
299e494e 179 * Run the String getEnvironment method test.
81c8e6f7
MK
180 */
181 @Test
95bf10e7 182 public void testGetEnvValue() {
cad06250 183 String key = "tracer_name";
22307af3 184 String result = fixture.getTraceProperties().get(key);
409bea20 185 assertEquals("\"lttng-modules\"", result);
81c8e6f7
MK
186 }
187
188 /**
409bea20 189 * Test the {@link CtfTmfTrace#getEventType()} method.
81c8e6f7
MK
190 */
191 @Test
95bf10e7 192 public void testGetEventType() {
409bea20
GB
193 Class<?> result = fixture.getEventType();
194 assertNotNull(result);
195 assertEquals(CtfTmfEvent.class, result);
196 }
197
198 /**
199 * Run the Class<CtfTmfEvent> getContainedEventTypes() method test.
200 */
201 @Test
202 public void testGetContainedEventTypes() {
e600c338 203 Set<? extends ITmfEventType> result = fixture.getContainedEventTypes();
bfe038ff 204 assertNotNull(result);
409bea20 205 assertFalse(result.isEmpty());
81c8e6f7
MK
206 }
207
208 /**
209 * Run the double getLocationRatio(ITmfLocation<?>) method test.
81c8e6f7
MK
210 */
211 @Test
95bf10e7 212 public void testGetLocationRatio() {
4a1f6c41
PT
213 ITmfContext context = fixture.seekEvent(0);
214 long t1 = ((CtfLocationInfo) context.getLocation().getLocationInfo()).getTimestamp();
215 fixture.getNext(context);
216 long t2 = ((CtfLocationInfo) context.getLocation().getLocationInfo()).getTimestamp();
217 fixture.getNext(context);
218 long t3 = ((CtfLocationInfo) context.getLocation().getLocationInfo()).getTimestamp();
219 fixture.getNext(context);
220 context.dispose();
221 double ratio1 = fixture.getLocationRatio(new CtfLocation(t1, 0));
222 assertEquals(0.0, ratio1, 0.01);
223 double ratio2 = fixture.getLocationRatio(new CtfLocation(t2, 0));
224 assertEquals((double) (t2 - t1) / (t3 - t1), ratio2, 0.01);
225 double ratio3 = fixture.getLocationRatio(new CtfLocation(t3, 0));
226 assertEquals(1.0, ratio3, 0.01);
81c8e6f7
MK
227 }
228
229 /**
230 * Run the String getName() method test.
81c8e6f7
MK
231 */
232 @Test
95bf10e7 233 public void testGetName() {
81c8e6f7 234 String result = fixture.getName();
81c8e6f7
MK
235 assertNotNull(result);
236 }
237
238 /**
2db2b43a 239 * Run the getTraceProperties() method test.
81c8e6f7
MK
240 */
241 @Test
2db2b43a 242 public void testGetTraceProperties() {
22307af3 243 int result = fixture.getTraceProperties().size();
2db2b43a 244 assertEquals(9, result);
81c8e6f7
MK
245 }
246
247 /**
248 * Run the long getNbEvents() method test.
81c8e6f7
MK
249 */
250 @Test
95bf10e7 251 public void testGetNbEvents() {
81c8e6f7 252 long result = fixture.getNbEvents();
132a02b0 253 assertEquals(1L, result);
81c8e6f7
MK
254 }
255
256 /**
257 * Run the CtfTmfEvent getNext(ITmfContext) method test.
81c8e6f7
MK
258 */
259 @Test
95bf10e7 260 public void testGetNext() {
f474d36b 261 ITmfContext context = fixture.seekEvent(0);
81c8e6f7 262 CtfTmfEvent result = fixture.getNext(context);
81c8e6f7 263 assertNotNull(result);
4a1f6c41 264 context.dispose();
81c8e6f7
MK
265 }
266
267 /**
268 * Run the String getPath() method test.
81c8e6f7
MK
269 */
270 @Test
95bf10e7 271 public void testGetPath() {
81c8e6f7 272 String result = fixture.getPath();
81c8e6f7
MK
273 assertNotNull(result);
274 }
275
276 /**
277 * Run the IResource getResource() method test.
81c8e6f7
MK
278 */
279 @Test
95bf10e7 280 public void testGetResource() {
81c8e6f7 281 IResource result = fixture.getResource();
81c8e6f7
MK
282 assertNull(result);
283 }
284
285 /**
286 * Run the ITmfTimestamp getStartTime() method test.
81c8e6f7
MK
287 */
288 @Test
95bf10e7 289 public void testGetStartTime() {
81c8e6f7 290 ITmfTimestamp result = fixture.getStartTime();
81c8e6f7
MK
291 assertNotNull(result);
292 }
293
81c8e6f7
MK
294 /**
295 * Run the long getStreamingInterval() method test.
81c8e6f7
MK
296 */
297 @Test
95bf10e7 298 public void testGetStreamingInterval() {
81c8e6f7 299 long result = fixture.getStreamingInterval();
81c8e6f7
MK
300 assertEquals(0L, result);
301 }
302
303 /**
304 * Run the TmfTimeRange getTimeRange() method test.
81c8e6f7
MK
305 */
306 @Test
95bf10e7 307 public void testGetTimeRange() {
81c8e6f7 308 TmfTimeRange result = fixture.getTimeRange();
81c8e6f7
MK
309 assertNotNull(result);
310 }
311
81c8e6f7
MK
312 /**
313 * Run the CtfTmfEvent readNextEvent(ITmfContext) method test.
81c8e6f7
MK
314 */
315 @Test
95bf10e7 316 public void testReadNextEvent() {
f474d36b 317 ITmfContext context = fixture.seekEvent(0);
c32744d6 318 CtfTmfEvent result = fixture.getNext(context);
81c8e6f7 319 assertNotNull(result);
4a1f6c41 320 context.dispose();
81c8e6f7
MK
321 }
322
323 /**
324 * Run the ITmfContext seekEvent(double) method test.
81c8e6f7
MK
325 */
326 @Test
95bf10e7 327 public void testSeekEvent_ratio() {
4a1f6c41
PT
328 ITmfContext context = fixture.seekEvent(0);
329 long t1 = ((CtfLocationInfo) context.getLocation().getLocationInfo()).getTimestamp();
330 fixture.getNext(context);
331 long t2 = ((CtfLocationInfo) context.getLocation().getLocationInfo()).getTimestamp();
332 fixture.getNext(context);
333 long t3 = ((CtfLocationInfo) context.getLocation().getLocationInfo()).getTimestamp();
334 fixture.getNext(context);
335 context.dispose();
336 context = fixture.seekEvent(0.0);
337 assertEquals(t1, ((CtfLocationInfo) context.getLocation().getLocationInfo()).getTimestamp());
338 context.dispose();
339 context = fixture.seekEvent(0.5);
340 assertEquals(t2, ((CtfLocationInfo) context.getLocation().getLocationInfo()).getTimestamp());
341 context.dispose();
342 context = fixture.seekEvent(1.0);
343 assertEquals(t3, ((CtfLocationInfo) context.getLocation().getLocationInfo()).getTimestamp());
344 context.dispose();
81c8e6f7
MK
345 }
346
347 /**
348 * Run the ITmfContext seekEvent(long) method test.
81c8e6f7
MK
349 */
350 @Test
95bf10e7 351 public void testSeekEvent_rank() {
81c8e6f7 352 long rank = 1L;
81c8e6f7 353 ITmfContext result = fixture.seekEvent(rank);
81c8e6f7 354 assertNotNull(result);
4a1f6c41 355 result.dispose();
81c8e6f7
MK
356 }
357
358 /**
359 * Run the ITmfContext seekEvent(ITmfTimestamp) method test.
81c8e6f7
MK
360 */
361 @Test
95bf10e7 362 public void testSeekEvent_timestamp() {
81c8e6f7 363 ITmfTimestamp timestamp = new TmfTimestamp();
81c8e6f7 364 ITmfContext result = fixture.seekEvent(timestamp);
81c8e6f7 365 assertNotNull(result);
4a1f6c41 366 result.dispose();
81c8e6f7
MK
367 }
368
81c8e6f7 369 /**
95bf10e7 370 * Run the ITmfContext seekEvent(ITmfLocation<?>) method test.
81c8e6f7
MK
371 */
372 @Test
95bf10e7 373 public void testSeekEvent_location() {
f5df94f8 374 final CtfLocationInfo location2 = new CtfLocationInfo(1L, 0L);
132a02b0 375 CtfLocation ctfLocation = new CtfLocation(location2);
95bf10e7
AM
376 ITmfContext result = fixture.seekEvent(ctfLocation);
377 assertNotNull(result);
4a1f6c41 378 result.dispose();
81c8e6f7
MK
379 }
380
21924e03
MAL
381 /**
382 * Run the ITmfContext seekEvent(ITmfLocation<?>) method test with invalid location.
383 */
384 @Test
385 public void testSeekEventInvalidLocation() {
386 CtfLocation ctfLocation = new CtfLocation(CtfLocation.INVALID_LOCATION);
387 ITmfContext result = fixture.seekEvent(ctfLocation);
388 assertNull(fixture.getNext(result));
389 assertEquals(CtfLocation.INVALID_LOCATION, result.getLocation().getLocationInfo());
390 result.dispose();
391
392 // Not using CtfLocation.INVALID_LOCATION directly on purpose, to make sure CtfLocationInfo.equals is properly used
393 CtfLocationInfo invalidLocation = new CtfLocationInfo(CtfLocation.INVALID_LOCATION.getTimestamp(), CtfLocation.INVALID_LOCATION.getIndex());
394 ctfLocation = new CtfLocation(invalidLocation);
395 result = fixture.seekEvent(ctfLocation);
396 assertNull(fixture.getNext(result));
397 assertEquals(CtfLocation.INVALID_LOCATION, result.getLocation().getLocationInfo());
398 result.dispose();
399 }
400
81c8e6f7
MK
401 /**
402 * Run the boolean validate(IProject,String) method test.
81c8e6f7
MK
403 */
404 @Test
95bf10e7 405 public void testValidate() {
81c8e6f7 406 IProject project = null;
c4d57ac1 407 IStatus result = fixture.validate(project, fixture.getPath());
a94410d9 408 assertTrue(result.isOK());
81c8e6f7 409 }
3480bf12
GB
410
411 /**
412 * Run the boolean hasEvent(final String) method test
413 */
414 @Test
415 public void testEventLookup() {
aa353506 416 Set<@NonNull ? extends ITmfEventType> eventTypes = fixture.getContainedEventTypes();
409bea20
GB
417 Set<String> eventNames = TmfEventTypeCollectionHelper.getEventNames(eventTypes);
418 assertTrue(eventNames.contains("sched_switch"));
419 assertFalse(eventNames.contains("Sched_switch"));
3480bf12 420 String[] events = { "sched_switch", "sched_wakeup", "timer_init" };
409bea20
GB
421 assertTrue(eventNames.containsAll(Arrays.asList(events)));
422 Set<String> copy = new HashSet<>(eventNames);
423 copy.retainAll(Arrays.asList(events));
424 assertFalse(copy.isEmpty());
3480bf12 425 String[] names = { "inexistent", "sched_switch", "SomeThing" };
409bea20
GB
426 copy = new HashSet<>(eventNames);
427 copy.retainAll(Arrays.asList(names));
428 assertTrue(!copy.isEmpty());
429 assertFalse(eventNames.containsAll(Arrays.asList(names)));
3480bf12 430 }
bb52f9bc
GB
431
432 /**
433 * Run the String getHostId() method test
434 */
435 @Test
436 public void testCtfHostId() {
437 String a = fixture.getHostId();
438 assertEquals("\"84db105b-b3f4-4821-b662-efc51455106a\"", a);
439 }
440
2d223a34 441}
This page took 0.10558 seconds and 5 git commands to generate.