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