Merge branch 'master' into lttng-luna
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / ctfadaptor / CtfTmfTraceTest.java
CommitLineData
95bf10e7 1/*******************************************************************************
61759503 2 * Copyright (c) 2012, 2013 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
12 *******************************************************************************/
13
81c8e6f7
MK
14package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor;
15
16import static org.junit.Assert.assertEquals;
3480bf12 17import static org.junit.Assert.assertFalse;
81c8e6f7
MK
18import static org.junit.Assert.assertNotNull;
19import static org.junit.Assert.assertNull;
20import static org.junit.Assert.assertTrue;
5dd1fa65 21import static org.junit.Assume.assumeTrue;
81c8e6f7
MK
22
23import org.eclipse.core.resources.IProject;
24import org.eclipse.core.resources.IResource;
a94410d9 25import org.eclipse.core.runtime.IStatus;
81c8e6f7 26import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocation;
f5df94f8 27import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocationInfo;
81c8e6f7
MK
28import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
29import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTimestamp;
30import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
6256d8ad 31import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
81c8e6f7 32import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
81c8e6f7
MK
33import org.eclipse.linuxtools.tmf.core.signal.TmfEndSynchSignal;
34import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;
5dd1fa65 35import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTraces;
3bd46eef
AM
36import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
37import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
38import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
81c8e6f7 39import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
81c8e6f7
MK
40import org.junit.After;
41import org.junit.Before;
42import org.junit.Test;
43
44/**
95bf10e7
AM
45 * The class <code>CtfTmfTraceTest</code> contains tests for the class
46 * <code>{@link CtfTmfTrace}</code>.
81c8e6f7 47 *
81c8e6f7 48 * @author ematkho
95bf10e7 49 * @version 1.0
81c8e6f7
MK
50 */
51public class CtfTmfTraceTest {
95bf10e7 52
5dd1fa65
AM
53 private static final int TRACE_INDEX = 0;
54 private static final String PATH = CtfTmfTestTraces.getTestTracePath(TRACE_INDEX);
81c8e6f7 55
95bf10e7
AM
56 private CtfTmfTrace fixture;
57
95bf10e7
AM
58 /**
59 * Perform pre-test initialization.
81c8e6f7 60 *
95bf10e7
AM
61 * @throws TmfTraceException
62 * If the test trace is not found
81c8e6f7 63 */
95bf10e7
AM
64 @Before
65 public void setUp() throws TmfTraceException {
5dd1fa65 66 assumeTrue(CtfTmfTestTraces.tracesExist());
95bf10e7
AM
67 fixture = new CtfTmfTrace();
68 fixture.initTrace((IResource) null, PATH, CtfTmfEvent.class);
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() {
81c8e6f7
MK
86 CtfTmfTrace result = new CtfTmfTrace();
87
81c8e6f7 88 assertNotNull(result);
95bf10e7 89 assertNull(result.getEventType());
bfe038ff 90 assertEquals(1000, result.getCacheSize());
81c8e6f7
MK
91 assertEquals(0L, result.getNbEvents());
92 assertEquals(0L, result.getStreamingInterval());
95bf10e7 93 assertNull(result.getResource());
81c8e6f7 94 assertEquals(1000, result.getQueueSize());
95bf10e7 95 assertNull(result.getType());
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);
107 }
108
81c8e6f7
MK
109 /**
110 * Run the void broadcast(TmfSignal) method test.
81c8e6f7
MK
111 */
112 @Test
95bf10e7 113 public void testBroadcast() {
81c8e6f7 114 TmfSignal signal = new TmfEndSynchSignal(1);
81c8e6f7 115 fixture.broadcast(signal);
81c8e6f7
MK
116 }
117
118
119 /**
120 * Run the void dispose() method test.
81c8e6f7
MK
121 */
122 @Test
95bf10e7
AM
123 public void testDispose() {
124 CtfTmfTrace emptyFixture = new CtfTmfTrace();
125 emptyFixture.dispose();
81c8e6f7
MK
126
127 }
128
129 /**
130 * Run the int getCacheSize() method test.
81c8e6f7
MK
131 */
132 @Test
95bf10e7
AM
133 public void testGetCacheSize() {
134 CtfTmfTrace emptyFixture = new CtfTmfTrace();
135 int result = emptyFixture.getCacheSize();
bfe038ff 136 assertEquals(1000, result);
81c8e6f7
MK
137 }
138
139 /**
140 * Run the ITmfLocation<Comparable> getCurrentLocation() method test.
81c8e6f7
MK
141 */
142 @Test
95bf10e7 143 public void testGetCurrentLocation() {
81c8e6f7 144 CtfLocation result = (CtfLocation) fixture.getCurrentLocation();
f474d36b 145 assertNull(result);
81c8e6f7
MK
146 }
147
95bf10e7
AM
148 /**
149 * Test the seekEvent() method with a null location.
150 */
81c8e6f7 151 @Test
95bf10e7 152 public void testSeekEventLoc_null() {
81c8e6f7
MK
153 CtfLocation loc = null;
154 fixture.seekEvent(loc);
155 assertNotNull(fixture);
156 }
157
95bf10e7
AM
158 /**
159 * Test the seekEvent() method with a location from a timestamp.
160 */
81c8e6f7 161 @Test
95bf10e7 162 public void testSeekEventLoc_timetamp(){
81c8e6f7
MK
163 CtfLocation loc = new CtfLocation(new CtfTmfTimestamp(0L));
164 fixture.seekEvent(loc);
165 assertNotNull(fixture);
166 }
167
168
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);
cad06250 185 assertEquals("\"lttng-modules\"",result);
81c8e6f7
MK
186 }
187
188 /**
189 * Run the Class<CtfTmfEvent> getEventType() method test.
81c8e6f7
MK
190 */
191 @Test
95bf10e7 192 public void testGetEventType() {
6256d8ad 193 Class<ITmfEvent> result = fixture.getEventType();
bfe038ff 194 assertNotNull(result);
81c8e6f7
MK
195 }
196
197 /**
198 * Run the double getLocationRatio(ITmfLocation<?>) method test.
81c8e6f7
MK
199 */
200 @Test
95bf10e7 201 public void testGetLocationRatio() {
f5df94f8 202 final CtfLocationInfo location2 = new CtfLocationInfo(1, 0);
132a02b0 203 CtfLocation location = new CtfLocation(location2);
81c8e6f7
MK
204 double result = fixture.getLocationRatio(location);
205
788ddcbc 206 assertEquals(Double.NEGATIVE_INFINITY, result, 0.1);
81c8e6f7
MK
207 }
208
209 /**
210 * Run the String getName() method test.
81c8e6f7
MK
211 */
212 @Test
95bf10e7 213 public void testGetName() {
81c8e6f7 214 String result = fixture.getName();
81c8e6f7
MK
215 assertNotNull(result);
216 }
217
218 /**
219 * Run the int getNbEnvVars() method test.
81c8e6f7
MK
220 */
221 @Test
95bf10e7 222 public void testGetNbEnvVars() {
22307af3 223 int result = fixture.getTraceProperties().size();
81c8e6f7
MK
224 assertEquals(8, result);
225 }
226
227 /**
228 * Run the long getNbEvents() method test.
81c8e6f7
MK
229 */
230 @Test
95bf10e7 231 public void testGetNbEvents() {
81c8e6f7 232 long result = fixture.getNbEvents();
132a02b0 233 assertEquals(1L, result);
81c8e6f7
MK
234 }
235
236 /**
237 * Run the CtfTmfEvent getNext(ITmfContext) method test.
81c8e6f7
MK
238 */
239 @Test
95bf10e7 240 public void testGetNext() {
f474d36b 241 ITmfContext context = fixture.seekEvent(0);
81c8e6f7 242 CtfTmfEvent result = fixture.getNext(context);
81c8e6f7
MK
243 assertNotNull(result);
244 }
245
246 /**
247 * Run the String getPath() method test.
81c8e6f7
MK
248 */
249 @Test
95bf10e7 250 public void testGetPath() {
81c8e6f7 251 String result = fixture.getPath();
81c8e6f7
MK
252 assertNotNull(result);
253 }
254
255 /**
256 * Run the IResource getResource() method test.
81c8e6f7
MK
257 */
258 @Test
95bf10e7 259 public void testGetResource() {
81c8e6f7 260 IResource result = fixture.getResource();
81c8e6f7
MK
261 assertNull(result);
262 }
263
264 /**
265 * Run the ITmfTimestamp getStartTime() method test.
81c8e6f7
MK
266 */
267 @Test
95bf10e7 268 public void testGetStartTime() {
81c8e6f7 269 ITmfTimestamp result = fixture.getStartTime();
81c8e6f7
MK
270 assertNotNull(result);
271 }
272
81c8e6f7
MK
273 /**
274 * Run the long getStreamingInterval() method test.
81c8e6f7
MK
275 */
276 @Test
95bf10e7 277 public void testGetStreamingInterval() {
81c8e6f7 278 long result = fixture.getStreamingInterval();
81c8e6f7
MK
279 assertEquals(0L, result);
280 }
281
282 /**
283 * Run the TmfTimeRange getTimeRange() method test.
81c8e6f7
MK
284 */
285 @Test
95bf10e7 286 public void testGetTimeRange() {
81c8e6f7 287 TmfTimeRange result = fixture.getTimeRange();
81c8e6f7
MK
288 assertNotNull(result);
289 }
290
81c8e6f7
MK
291 /**
292 * Run the CtfTmfEvent readNextEvent(ITmfContext) method test.
81c8e6f7
MK
293 */
294 @Test
95bf10e7 295 public void testReadNextEvent() {
f474d36b 296 ITmfContext context = fixture.seekEvent(0);
c32744d6 297 CtfTmfEvent result = fixture.getNext(context);
81c8e6f7
MK
298 assertNotNull(result);
299 }
300
301 /**
302 * Run the ITmfContext seekEvent(double) method test.
81c8e6f7
MK
303 */
304 @Test
95bf10e7 305 public void testSeekEvent_ratio() {
788ddcbc 306 double ratio = 0.99;
81c8e6f7 307 ITmfContext result = fixture.seekEvent(ratio);
81c8e6f7
MK
308 assertNotNull(result);
309 }
310
311 /**
312 * Run the ITmfContext seekEvent(long) method test.
81c8e6f7
MK
313 */
314 @Test
95bf10e7 315 public void testSeekEvent_rank() {
81c8e6f7 316 long rank = 1L;
81c8e6f7 317 ITmfContext result = fixture.seekEvent(rank);
81c8e6f7
MK
318 assertNotNull(result);
319 }
320
321 /**
322 * Run the ITmfContext seekEvent(ITmfTimestamp) method test.
81c8e6f7
MK
323 */
324 @Test
95bf10e7 325 public void testSeekEvent_timestamp() {
81c8e6f7 326 ITmfTimestamp timestamp = new TmfTimestamp();
81c8e6f7 327 ITmfContext result = fixture.seekEvent(timestamp);
81c8e6f7
MK
328 assertNotNull(result);
329 }
330
81c8e6f7 331 /**
95bf10e7 332 * Run the ITmfContext seekEvent(ITmfLocation<?>) method test.
81c8e6f7
MK
333 */
334 @Test
95bf10e7 335 public void testSeekEvent_location() {
f5df94f8 336 final CtfLocationInfo location2 = new CtfLocationInfo(1L, 0L);
132a02b0 337 CtfLocation ctfLocation = new CtfLocation(location2);
95bf10e7
AM
338 ITmfContext result = fixture.seekEvent(ctfLocation);
339 assertNotNull(result);
81c8e6f7
MK
340 }
341
342 /**
343 * Run the boolean validate(IProject,String) method test.
81c8e6f7
MK
344 */
345 @Test
95bf10e7 346 public void testValidate() {
81c8e6f7
MK
347 IProject project = null;
348 String path = PATH;
a94410d9
MK
349 IStatus result = fixture.validate(project, path);
350 assertTrue(result.isOK());
81c8e6f7 351 }
3480bf12
GB
352
353 /**
354 * Run the boolean hasEvent(final String) method test
355 */
356 @Test
357 public void testEventLookup() {
358 assertTrue(fixture.hasEvent("sched_switch"));
359 assertFalse(fixture.hasEvent("Sched_switch"));
360 String[] events = { "sched_switch", "sched_wakeup", "timer_init" };
361 assertTrue(fixture.hasAllEvents(events));
362 assertTrue(fixture.hasAtLeastOneOfEvents(events));
363 String[] names = { "inexistent", "sched_switch", "SomeThing" };
364 assertTrue(fixture.hasAtLeastOneOfEvents(names));
365 assertFalse(fixture.hasAllEvents(names));
366 }
bb52f9bc
GB
367
368 /**
369 * Run the String getHostId() method test
370 */
371 @Test
372 public void testCtfHostId() {
373 String a = fixture.getHostId();
374 assertEquals("\"84db105b-b3f4-4821-b662-efc51455106a\"", a);
375 }
376
2d223a34 377}
This page took 0.052577 seconds and 5 git commands to generate.