1 /*******************************************************************************
2 * Copyright (c) 2012 Ericsson
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
10 * Matthew Khouzam - Initial generation with CodePro tools
11 * Alexandre Montplaisir - Clean up, consolidate redundant tests
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.core
.tests
.ctfadaptor
;
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
;
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
;
42 * The class <code>CtfTmfTraceTest</code> contains tests for the class
43 * <code>{@link CtfTmfTrace}</code>.
48 public class CtfTmfTraceTest
{
50 private static final String PATH
= TestParams
.getPath();
52 private CtfTmfTrace fixture
;
58 * the command line arguments
60 public static void main(String
[] args
) {
61 new org
.junit
.runner
.JUnitCore().run(CtfTmfTraceTest
.class);
65 * Perform pre-test initialization.
67 * @throws TmfTraceException
68 * If the test trace is not found
71 public void setUp() throws TmfTraceException
{
72 fixture
= new CtfTmfTrace();
73 fixture
.initTrace((IResource
) null, PATH
, CtfTmfEvent
.class);
77 * Perform post-test clean-up.
80 public void tearDown() {
85 * Run the CtfTmfTrace() constructor test.
88 public void testCtfTmfTrace() {
89 CtfTmfTrace result
= new CtfTmfTrace();
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());
103 * Test the parseEvent() method
106 public void testParseEvent() {
107 ITmfContext ctx
= fixture
.seekEvent(0);
108 fixture
.getNext(ctx
);
109 CtfTmfEvent event
= fixture
.parseEvent(ctx
);
110 assertNotNull(event
);
114 * Run the void broadcast(TmfSignal) method test.
117 public void testBroadcast() {
118 TmfSignal signal
= new TmfEndSynchSignal(1);
119 fixture
.broadcast(signal
);
124 * Run the void dispose() method test.
127 public void testDispose() {
128 CtfTmfTrace emptyFixture
= new CtfTmfTrace();
129 emptyFixture
.dispose();
134 * Run the int getCacheSize() method test.
137 public void testGetCacheSize() {
138 CtfTmfTrace emptyFixture
= new CtfTmfTrace();
139 int result
= emptyFixture
.getCacheSize();
140 assertEquals(1000, result
);
144 * Run the ITmfLocation<Comparable> getCurrentLocation() method test.
147 public void testGetCurrentLocation() {
148 CtfLocation result
= (CtfLocation
) fixture
.getCurrentLocation();
153 * Test the seekEvent() method with a null location.
156 public void testSeekEventLoc_null() {
157 CtfLocation loc
= null;
158 fixture
.seekEvent(loc
);
159 assertNotNull(fixture
);
163 * Test the seekEvent() method with a location from a timestamp.
166 public void testSeekEventLoc_timetamp(){
167 CtfLocation loc
= new CtfLocation(new CtfTmfTimestamp(0L));
168 fixture
.seekEvent(loc
);
169 assertNotNull(fixture
);
174 * Run the ITmfTimestamp getEndTime() method test.
177 public void testGetEndTime() {
178 ITmfTimestamp result
= fixture
.getEndTime();
179 assertNotNull(result
);
183 * Run the String[] getEnvNames() method test.
186 public void testGetEnvNames() {
187 String
[] result
= fixture
.getEnvNames();
188 assertNotNull(result
);
192 * Run the String getEnvValue(String) method 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$
202 * Run the Class<CtfTmfEvent> getEventType() method test.
205 public void testGetEventType() {
206 Class
<ITmfEvent
> result
= fixture
.getEventType();
207 assertNotNull(result
);
211 * Run the double getLocationRatio(ITmfLocation<?>) method test.
214 public void testGetLocationRatio() {
215 final CtfLocationData location2
= new CtfLocationData(1, 0);
216 CtfLocation location
= new CtfLocation(location2
);
217 double result
= fixture
.getLocationRatio(location
);
219 assertEquals(Double
.NEGATIVE_INFINITY
, result
, 0.1);
223 * Run the String getName() method test.
226 public void testGetName() {
227 String result
= fixture
.getName();
228 assertNotNull(result
);
232 * Run the int getNbEnvVars() method test.
235 public void testGetNbEnvVars() {
236 int result
= fixture
.getNbEnvVars();
237 assertEquals(8, result
);
241 * Run the long getNbEvents() method test.
244 public void testGetNbEvents() {
245 long result
= fixture
.getNbEvents();
246 assertEquals(1L, result
);
250 * Run the CtfTmfEvent getNext(ITmfContext) method test.
253 public void testGetNext() {
254 ITmfContext context
= fixture
.seekEvent(0);
255 CtfTmfEvent result
= fixture
.getNext(context
);
256 assertNotNull(result
);
260 * Run the String getPath() method test.
263 public void testGetPath() {
264 String result
= fixture
.getPath();
265 assertNotNull(result
);
269 * Run the IResource getResource() method test.
272 public void testGetResource() {
273 IResource result
= fixture
.getResource();
278 * Run the ITmfTimestamp getStartTime() method test.
281 public void testGetStartTime() {
282 ITmfTimestamp result
= fixture
.getStartTime();
283 assertNotNull(result
);
287 * Run the IStateSystemQuerier getStateSystem() method test.
290 public void testGetStateSystem() {
291 IStateSystemQuerier result
= fixture
.getStateSystem();
296 * Run the long getStreamingInterval() method test.
299 public void testGetStreamingInterval() {
300 long result
= fixture
.getStreamingInterval();
301 assertEquals(0L, result
);
305 * Run the TmfTimeRange getTimeRange() method test.
308 public void testGetTimeRange() {
309 TmfTimeRange result
= fixture
.getTimeRange();
310 assertNotNull(result
);
314 * Run the CtfTmfEvent readNextEvent(ITmfContext) method test.
317 public void testReadNextEvent() {
318 ITmfContext context
= fixture
.seekEvent(0);
319 CtfTmfEvent result
= fixture
.getNext(context
);
320 assertNotNull(result
);
324 * Run the ITmfContext seekEvent(double) method test.
327 public void testSeekEvent_ratio() {
329 ITmfContext result
= fixture
.seekEvent(ratio
);
330 assertNotNull(result
);
334 * Run the ITmfContext seekEvent(long) method test.
337 public void testSeekEvent_rank() {
339 ITmfContext result
= fixture
.seekEvent(rank
);
340 assertNotNull(result
);
344 * Run the ITmfContext seekEvent(ITmfTimestamp) method test.
347 public void testSeekEvent_timestamp() {
348 ITmfTimestamp timestamp
= new TmfTimestamp();
349 ITmfContext result
= fixture
.seekEvent(timestamp
);
350 assertNotNull(result
);
354 * Run the ITmfContext seekEvent(ITmfLocation<?>) method test.
357 public void testSeekEvent_location() {
358 final CtfLocationData location2
= new CtfLocationData(1L, 0L);
359 CtfLocation ctfLocation
= new CtfLocation(location2
);
360 ITmfContext result
= fixture
.seekEvent(ctfLocation
);
361 assertNotNull(result
);
365 * Run the boolean validate(IProject,String) method test.
368 public void testValidate() {
369 IProject project
= null;
371 boolean result
= fixture
.validate(project
, path
);