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