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