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;
9ac63b5b 35import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTrace;
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
9ac63b5b 53 private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.KERNEL;
81c8e6f7 54
95bf10e7
AM
55 private CtfTmfTrace fixture;
56
95bf10e7
AM
57 /**
58 * Perform pre-test initialization.
81c8e6f7 59 *
95bf10e7
AM
60 * @throws TmfTraceException
61 * If the test trace is not found
81c8e6f7 62 */
95bf10e7
AM
63 @Before
64 public void setUp() throws TmfTraceException {
9ac63b5b 65 assumeTrue(testTrace.exists());
95bf10e7 66 fixture = new CtfTmfTrace();
9ac63b5b 67 fixture.initTrace((IResource) null, testTrace.getPath(), CtfTmfEvent.class);
95bf10e7 68 }
81c8e6f7 69
95bf10e7
AM
70 /**
71 * Perform post-test clean-up.
72 */
73 @After
74 public void tearDown() {
5dd1fa65
AM
75 if (fixture != null) {
76 fixture.dispose();
77 }
95bf10e7
AM
78 }
79
80 /**
81 * Run the CtfTmfTrace() constructor test.
82 */
83 @Test
84 public void testCtfTmfTrace() {
81c8e6f7
MK
85 CtfTmfTrace result = new CtfTmfTrace();
86
81c8e6f7 87 assertNotNull(result);
95bf10e7 88 assertNull(result.getEventType());
bfe038ff 89 assertEquals(1000, result.getCacheSize());
81c8e6f7
MK
90 assertEquals(0L, result.getNbEvents());
91 assertEquals(0L, result.getStreamingInterval());
95bf10e7 92 assertNull(result.getResource());
81c8e6f7 93 assertEquals(1000, result.getQueueSize());
95bf10e7 94 assertNull(result.getType());
81c8e6f7
MK
95 }
96
95bf10e7
AM
97 /**
98 * Test the parseEvent() method
99 */
788ddcbc 100 @Test
95bf10e7 101 public void testParseEvent() {
788ddcbc
MK
102 ITmfContext ctx = fixture.seekEvent(0);
103 fixture.getNext(ctx);
104 CtfTmfEvent event = fixture.parseEvent(ctx);
105 assertNotNull(event);
106 }
107
81c8e6f7
MK
108 /**
109 * Run the void broadcast(TmfSignal) method test.
81c8e6f7
MK
110 */
111 @Test
95bf10e7 112 public void testBroadcast() {
81c8e6f7 113 TmfSignal signal = new TmfEndSynchSignal(1);
81c8e6f7 114 fixture.broadcast(signal);
81c8e6f7
MK
115 }
116
117
118 /**
119 * Run the void dispose() method test.
81c8e6f7
MK
120 */
121 @Test
95bf10e7
AM
122 public void testDispose() {
123 CtfTmfTrace emptyFixture = new CtfTmfTrace();
124 emptyFixture.dispose();
81c8e6f7
MK
125
126 }
127
128 /**
129 * Run the int getCacheSize() method test.
81c8e6f7
MK
130 */
131 @Test
95bf10e7
AM
132 public void testGetCacheSize() {
133 CtfTmfTrace emptyFixture = new CtfTmfTrace();
134 int result = emptyFixture.getCacheSize();
bfe038ff 135 assertEquals(1000, result);
81c8e6f7
MK
136 }
137
138 /**
139 * Run the ITmfLocation<Comparable> getCurrentLocation() method test.
81c8e6f7
MK
140 */
141 @Test
95bf10e7 142 public void testGetCurrentLocation() {
81c8e6f7 143 CtfLocation result = (CtfLocation) fixture.getCurrentLocation();
f474d36b 144 assertNull(result);
81c8e6f7
MK
145 }
146
95bf10e7
AM
147 /**
148 * Test the seekEvent() method with a null location.
149 */
81c8e6f7 150 @Test
95bf10e7 151 public void testSeekEventLoc_null() {
81c8e6f7
MK
152 CtfLocation loc = null;
153 fixture.seekEvent(loc);
154 assertNotNull(fixture);
155 }
156
95bf10e7
AM
157 /**
158 * Test the seekEvent() method with a location from a timestamp.
159 */
81c8e6f7 160 @Test
95bf10e7 161 public void testSeekEventLoc_timetamp(){
81c8e6f7
MK
162 CtfLocation loc = new CtfLocation(new CtfTmfTimestamp(0L));
163 fixture.seekEvent(loc);
164 assertNotNull(fixture);
165 }
166
167
168 /**
169 * Run the ITmfTimestamp getEndTime() method test.
81c8e6f7
MK
170 */
171 @Test
95bf10e7 172 public void testGetEndTime() {
81c8e6f7
MK
173 ITmfTimestamp result = fixture.getEndTime();
174 assertNotNull(result);
175 }
176
177 /**
299e494e 178 * Run the String getEnvironment method test.
81c8e6f7
MK
179 */
180 @Test
95bf10e7 181 public void testGetEnvValue() {
cad06250 182 String key = "tracer_name";
22307af3 183 String result = fixture.getTraceProperties().get(key);
cad06250 184 assertEquals("\"lttng-modules\"",result);
81c8e6f7
MK
185 }
186
187 /**
188 * Run the Class<CtfTmfEvent> getEventType() method test.
81c8e6f7
MK
189 */
190 @Test
95bf10e7 191 public void testGetEventType() {
6256d8ad 192 Class<ITmfEvent> result = fixture.getEventType();
bfe038ff 193 assertNotNull(result);
81c8e6f7
MK
194 }
195
196 /**
197 * Run the double getLocationRatio(ITmfLocation<?>) method test.
81c8e6f7
MK
198 */
199 @Test
95bf10e7 200 public void testGetLocationRatio() {
f5df94f8 201 final CtfLocationInfo location2 = new CtfLocationInfo(1, 0);
132a02b0 202 CtfLocation location = new CtfLocation(location2);
81c8e6f7
MK
203 double result = fixture.getLocationRatio(location);
204
788ddcbc 205 assertEquals(Double.NEGATIVE_INFINITY, result, 0.1);
81c8e6f7
MK
206 }
207
208 /**
209 * Run the String getName() method test.
81c8e6f7
MK
210 */
211 @Test
95bf10e7 212 public void testGetName() {
81c8e6f7 213 String result = fixture.getName();
81c8e6f7
MK
214 assertNotNull(result);
215 }
216
217 /**
218 * Run the int getNbEnvVars() method test.
81c8e6f7
MK
219 */
220 @Test
95bf10e7 221 public void testGetNbEnvVars() {
22307af3 222 int result = fixture.getTraceProperties().size();
81c8e6f7
MK
223 assertEquals(8, result);
224 }
225
226 /**
227 * Run the long getNbEvents() method test.
81c8e6f7
MK
228 */
229 @Test
95bf10e7 230 public void testGetNbEvents() {
81c8e6f7 231 long result = fixture.getNbEvents();
132a02b0 232 assertEquals(1L, result);
81c8e6f7
MK
233 }
234
235 /**
236 * Run the CtfTmfEvent getNext(ITmfContext) method test.
81c8e6f7
MK
237 */
238 @Test
95bf10e7 239 public void testGetNext() {
f474d36b 240 ITmfContext context = fixture.seekEvent(0);
81c8e6f7 241 CtfTmfEvent result = fixture.getNext(context);
81c8e6f7
MK
242 assertNotNull(result);
243 }
244
245 /**
246 * Run the String getPath() method test.
81c8e6f7
MK
247 */
248 @Test
95bf10e7 249 public void testGetPath() {
81c8e6f7 250 String result = fixture.getPath();
81c8e6f7
MK
251 assertNotNull(result);
252 }
253
254 /**
255 * Run the IResource getResource() method test.
81c8e6f7
MK
256 */
257 @Test
95bf10e7 258 public void testGetResource() {
81c8e6f7 259 IResource result = fixture.getResource();
81c8e6f7
MK
260 assertNull(result);
261 }
262
263 /**
264 * Run the ITmfTimestamp getStartTime() method test.
81c8e6f7
MK
265 */
266 @Test
95bf10e7 267 public void testGetStartTime() {
81c8e6f7 268 ITmfTimestamp result = fixture.getStartTime();
81c8e6f7
MK
269 assertNotNull(result);
270 }
271
81c8e6f7
MK
272 /**
273 * Run the long getStreamingInterval() method test.
81c8e6f7
MK
274 */
275 @Test
95bf10e7 276 public void testGetStreamingInterval() {
81c8e6f7 277 long result = fixture.getStreamingInterval();
81c8e6f7
MK
278 assertEquals(0L, result);
279 }
280
281 /**
282 * Run the TmfTimeRange getTimeRange() method test.
81c8e6f7
MK
283 */
284 @Test
95bf10e7 285 public void testGetTimeRange() {
81c8e6f7 286 TmfTimeRange result = fixture.getTimeRange();
81c8e6f7
MK
287 assertNotNull(result);
288 }
289
81c8e6f7
MK
290 /**
291 * Run the CtfTmfEvent readNextEvent(ITmfContext) method test.
81c8e6f7
MK
292 */
293 @Test
95bf10e7 294 public void testReadNextEvent() {
f474d36b 295 ITmfContext context = fixture.seekEvent(0);
c32744d6 296 CtfTmfEvent result = fixture.getNext(context);
81c8e6f7
MK
297 assertNotNull(result);
298 }
299
300 /**
301 * Run the ITmfContext seekEvent(double) method test.
81c8e6f7
MK
302 */
303 @Test
95bf10e7 304 public void testSeekEvent_ratio() {
788ddcbc 305 double ratio = 0.99;
81c8e6f7 306 ITmfContext result = fixture.seekEvent(ratio);
81c8e6f7
MK
307 assertNotNull(result);
308 }
309
310 /**
311 * Run the ITmfContext seekEvent(long) method test.
81c8e6f7
MK
312 */
313 @Test
95bf10e7 314 public void testSeekEvent_rank() {
81c8e6f7 315 long rank = 1L;
81c8e6f7 316 ITmfContext result = fixture.seekEvent(rank);
81c8e6f7
MK
317 assertNotNull(result);
318 }
319
320 /**
321 * Run the ITmfContext seekEvent(ITmfTimestamp) method test.
81c8e6f7
MK
322 */
323 @Test
95bf10e7 324 public void testSeekEvent_timestamp() {
81c8e6f7 325 ITmfTimestamp timestamp = new TmfTimestamp();
81c8e6f7 326 ITmfContext result = fixture.seekEvent(timestamp);
81c8e6f7
MK
327 assertNotNull(result);
328 }
329
81c8e6f7 330 /**
95bf10e7 331 * Run the ITmfContext seekEvent(ITmfLocation<?>) method test.
81c8e6f7
MK
332 */
333 @Test
95bf10e7 334 public void testSeekEvent_location() {
f5df94f8 335 final CtfLocationInfo location2 = new CtfLocationInfo(1L, 0L);
132a02b0 336 CtfLocation ctfLocation = new CtfLocation(location2);
95bf10e7
AM
337 ITmfContext result = fixture.seekEvent(ctfLocation);
338 assertNotNull(result);
81c8e6f7
MK
339 }
340
341 /**
342 * Run the boolean validate(IProject,String) method test.
81c8e6f7
MK
343 */
344 @Test
95bf10e7 345 public void testValidate() {
81c8e6f7 346 IProject project = null;
9ac63b5b 347 IStatus result = fixture.validate(project, testTrace.getPath());
a94410d9 348 assertTrue(result.isOK());
81c8e6f7 349 }
3480bf12
GB
350
351 /**
352 * Run the boolean hasEvent(final String) method test
353 */
354 @Test
355 public void testEventLookup() {
356 assertTrue(fixture.hasEvent("sched_switch"));
357 assertFalse(fixture.hasEvent("Sched_switch"));
358 String[] events = { "sched_switch", "sched_wakeup", "timer_init" };
359 assertTrue(fixture.hasAllEvents(events));
360 assertTrue(fixture.hasAtLeastOneOfEvents(events));
361 String[] names = { "inexistent", "sched_switch", "SomeThing" };
362 assertTrue(fixture.hasAtLeastOneOfEvents(names));
363 assertFalse(fixture.hasAllEvents(names));
364 }
bb52f9bc
GB
365
366 /**
367 * Run the String getHostId() method test
368 */
369 @Test
370 public void testCtfHostId() {
371 String a = fixture.getHostId();
372 assertEquals("\"84db105b-b3f4-4821-b662-efc51455106a\"", a);
373 }
374
2d223a34 375}
This page took 0.080499 seconds and 5 git commands to generate.