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
1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 Ericsson
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
14 package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor;
15
16 import static org.junit.Assert.assertEquals;
17 import static org.junit.Assert.assertFalse;
18 import static org.junit.Assert.assertNotNull;
19 import static org.junit.Assert.assertNull;
20 import static org.junit.Assert.assertTrue;
21 import static org.junit.Assume.assumeTrue;
22
23 import org.eclipse.core.resources.IProject;
24 import org.eclipse.core.resources.IResource;
25 import org.eclipse.core.runtime.IStatus;
26 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocation;
27 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocationInfo;
28 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
29 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTimestamp;
30 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
31 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
32 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
33 import org.eclipse.linuxtools.tmf.core.signal.TmfEndSynchSignal;
34 import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;
35 import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTrace;
36 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
37 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
38 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
39 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
40 import org.junit.After;
41 import org.junit.Before;
42 import org.junit.Test;
43
44 /**
45 * The class <code>CtfTmfTraceTest</code> contains tests for the class
46 * <code>{@link CtfTmfTrace}</code>.
47 *
48 * @author ematkho
49 * @version 1.0
50 */
51 public class CtfTmfTraceTest {
52
53 private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.KERNEL;
54
55 private CtfTmfTrace fixture;
56
57 /**
58 * Perform pre-test initialization.
59 *
60 * @throws TmfTraceException
61 * If the test trace is not found
62 */
63 @Before
64 public void setUp() throws TmfTraceException {
65 assumeTrue(testTrace.exists());
66 fixture = new CtfTmfTrace();
67 fixture.initTrace((IResource) null, testTrace.getPath(), CtfTmfEvent.class);
68 }
69
70 /**
71 * Perform post-test clean-up.
72 */
73 @After
74 public void tearDown() {
75 if (fixture != null) {
76 fixture.dispose();
77 }
78 }
79
80 /**
81 * Run the CtfTmfTrace() constructor test.
82 */
83 @Test
84 public void testCtfTmfTrace() {
85 CtfTmfTrace result = new CtfTmfTrace();
86
87 assertNotNull(result);
88 assertNull(result.getEventType());
89 assertEquals(1000, result.getCacheSize());
90 assertEquals(0L, result.getNbEvents());
91 assertEquals(0L, result.getStreamingInterval());
92 assertNull(result.getResource());
93 assertEquals(1000, result.getQueueSize());
94 assertNull(result.getType());
95 }
96
97 /**
98 * Test the parseEvent() method
99 */
100 @Test
101 public void testParseEvent() {
102 ITmfContext ctx = fixture.seekEvent(0);
103 fixture.getNext(ctx);
104 CtfTmfEvent event = fixture.parseEvent(ctx);
105 assertNotNull(event);
106 }
107
108 /**
109 * Run the void broadcast(TmfSignal) method test.
110 */
111 @Test
112 public void testBroadcast() {
113 TmfSignal signal = new TmfEndSynchSignal(1);
114 fixture.broadcast(signal);
115 }
116
117
118 /**
119 * Run the void dispose() method test.
120 */
121 @Test
122 public void testDispose() {
123 CtfTmfTrace emptyFixture = new CtfTmfTrace();
124 emptyFixture.dispose();
125
126 }
127
128 /**
129 * Run the int getCacheSize() method test.
130 */
131 @Test
132 public void testGetCacheSize() {
133 CtfTmfTrace emptyFixture = new CtfTmfTrace();
134 int result = emptyFixture.getCacheSize();
135 assertEquals(1000, result);
136 }
137
138 /**
139 * Run the ITmfLocation<Comparable> getCurrentLocation() method test.
140 */
141 @Test
142 public void testGetCurrentLocation() {
143 CtfLocation result = (CtfLocation) fixture.getCurrentLocation();
144 assertNull(result);
145 }
146
147 /**
148 * Test the seekEvent() method with a null location.
149 */
150 @Test
151 public void testSeekEventLoc_null() {
152 CtfLocation loc = null;
153 fixture.seekEvent(loc);
154 assertNotNull(fixture);
155 }
156
157 /**
158 * Test the seekEvent() method with a location from a timestamp.
159 */
160 @Test
161 public void testSeekEventLoc_timetamp(){
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.
170 */
171 @Test
172 public void testGetEndTime() {
173 ITmfTimestamp result = fixture.getEndTime();
174 assertNotNull(result);
175 }
176
177 /**
178 * Run the String getEnvironment method test.
179 */
180 @Test
181 public void testGetEnvValue() {
182 String key = "tracer_name";
183 String result = fixture.getTraceProperties().get(key);
184 assertEquals("\"lttng-modules\"",result);
185 }
186
187 /**
188 * Run the Class<CtfTmfEvent> getEventType() method test.
189 */
190 @Test
191 public void testGetEventType() {
192 Class<ITmfEvent> result = fixture.getEventType();
193 assertNotNull(result);
194 }
195
196 /**
197 * Run the double getLocationRatio(ITmfLocation<?>) method test.
198 */
199 @Test
200 public void testGetLocationRatio() {
201 final CtfLocationInfo location2 = new CtfLocationInfo(1, 0);
202 CtfLocation location = new CtfLocation(location2);
203 double result = fixture.getLocationRatio(location);
204
205 assertEquals(Double.NEGATIVE_INFINITY, result, 0.1);
206 }
207
208 /**
209 * Run the String getName() method test.
210 */
211 @Test
212 public void testGetName() {
213 String result = fixture.getName();
214 assertNotNull(result);
215 }
216
217 /**
218 * Run the int getNbEnvVars() method test.
219 */
220 @Test
221 public void testGetNbEnvVars() {
222 int result = fixture.getTraceProperties().size();
223 assertEquals(8, result);
224 }
225
226 /**
227 * Run the long getNbEvents() method test.
228 */
229 @Test
230 public void testGetNbEvents() {
231 long result = fixture.getNbEvents();
232 assertEquals(1L, result);
233 }
234
235 /**
236 * Run the CtfTmfEvent getNext(ITmfContext) method test.
237 */
238 @Test
239 public void testGetNext() {
240 ITmfContext context = fixture.seekEvent(0);
241 CtfTmfEvent result = fixture.getNext(context);
242 assertNotNull(result);
243 }
244
245 /**
246 * Run the String getPath() method test.
247 */
248 @Test
249 public void testGetPath() {
250 String result = fixture.getPath();
251 assertNotNull(result);
252 }
253
254 /**
255 * Run the IResource getResource() method test.
256 */
257 @Test
258 public void testGetResource() {
259 IResource result = fixture.getResource();
260 assertNull(result);
261 }
262
263 /**
264 * Run the ITmfTimestamp getStartTime() method test.
265 */
266 @Test
267 public void testGetStartTime() {
268 ITmfTimestamp result = fixture.getStartTime();
269 assertNotNull(result);
270 }
271
272 /**
273 * Run the long getStreamingInterval() method test.
274 */
275 @Test
276 public void testGetStreamingInterval() {
277 long result = fixture.getStreamingInterval();
278 assertEquals(0L, result);
279 }
280
281 /**
282 * Run the TmfTimeRange getTimeRange() method test.
283 */
284 @Test
285 public void testGetTimeRange() {
286 TmfTimeRange result = fixture.getTimeRange();
287 assertNotNull(result);
288 }
289
290 /**
291 * Run the CtfTmfEvent readNextEvent(ITmfContext) method test.
292 */
293 @Test
294 public void testReadNextEvent() {
295 ITmfContext context = fixture.seekEvent(0);
296 CtfTmfEvent result = fixture.getNext(context);
297 assertNotNull(result);
298 }
299
300 /**
301 * Run the ITmfContext seekEvent(double) method test.
302 */
303 @Test
304 public void testSeekEvent_ratio() {
305 double ratio = 0.99;
306 ITmfContext result = fixture.seekEvent(ratio);
307 assertNotNull(result);
308 }
309
310 /**
311 * Run the ITmfContext seekEvent(long) method test.
312 */
313 @Test
314 public void testSeekEvent_rank() {
315 long rank = 1L;
316 ITmfContext result = fixture.seekEvent(rank);
317 assertNotNull(result);
318 }
319
320 /**
321 * Run the ITmfContext seekEvent(ITmfTimestamp) method test.
322 */
323 @Test
324 public void testSeekEvent_timestamp() {
325 ITmfTimestamp timestamp = new TmfTimestamp();
326 ITmfContext result = fixture.seekEvent(timestamp);
327 assertNotNull(result);
328 }
329
330 /**
331 * Run the ITmfContext seekEvent(ITmfLocation<?>) method test.
332 */
333 @Test
334 public void testSeekEvent_location() {
335 final CtfLocationInfo location2 = new CtfLocationInfo(1L, 0L);
336 CtfLocation ctfLocation = new CtfLocation(location2);
337 ITmfContext result = fixture.seekEvent(ctfLocation);
338 assertNotNull(result);
339 }
340
341 /**
342 * Run the boolean validate(IProject,String) method test.
343 */
344 @Test
345 public void testValidate() {
346 IProject project = null;
347 IStatus result = fixture.validate(project, testTrace.getPath());
348 assertTrue(result.isOK());
349 }
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 }
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
375 }
This page took 0.053281 seconds and 6 git commands to generate.