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
.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
;
41 * The class <code>CtfTmfTraceTest</code> contains tests for the class
42 * <code>{@link CtfTmfTrace}</code>.
47 public class CtfTmfTraceTest
{
49 private static final String PATH
= TestParams
.getPath();
51 private CtfTmfTrace fixture
;
57 * the command line arguments
59 public static void main(String
[] args
) {
60 new org
.junit
.runner
.JUnitCore().run(CtfTmfTraceTest
.class);
64 * Perform pre-test initialization.
66 * @throws TmfTraceException
67 * If the test trace is not found
70 public void setUp() throws TmfTraceException
{
71 fixture
= new CtfTmfTrace();
72 fixture
.initTrace((IResource
) null, PATH
, CtfTmfEvent
.class);
76 * Perform post-test clean-up.
79 public void tearDown() {
84 * Run the CtfTmfTrace() constructor test.
87 public void testCtfTmfTrace() {
88 CtfTmfTrace result
= new CtfTmfTrace();
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());
102 * Test the parseEvent() method
105 public void testParseEvent() {
106 ITmfContext ctx
= fixture
.seekEvent(0);
107 fixture
.getNext(ctx
);
108 CtfTmfEvent event
= fixture
.parseEvent(ctx
);
109 assertNotNull(event
);
113 * Run the void broadcast(TmfSignal) method test.
116 public void testBroadcast() {
117 TmfSignal signal
= new TmfEndSynchSignal(1);
118 fixture
.broadcast(signal
);
123 * Run the void dispose() method test.
126 public void testDispose() {
127 CtfTmfTrace emptyFixture
= new CtfTmfTrace();
128 emptyFixture
.dispose();
133 * Run the int getCacheSize() method test.
136 public void testGetCacheSize() {
137 CtfTmfTrace emptyFixture
= new CtfTmfTrace();
138 int result
= emptyFixture
.getCacheSize();
139 assertEquals(1000, result
);
143 * Run the ITmfLocation<Comparable> getCurrentLocation() method test.
146 public void testGetCurrentLocation() {
147 CtfLocation result
= (CtfLocation
) fixture
.getCurrentLocation();
152 * Test the seekEvent() method with a null location.
155 public void testSeekEventLoc_null() {
156 CtfLocation loc
= null;
157 fixture
.seekEvent(loc
);
158 assertNotNull(fixture
);
162 * Test the seekEvent() method with a location from a timestamp.
165 public void testSeekEventLoc_timetamp(){
166 CtfLocation loc
= new CtfLocation(new CtfTmfTimestamp(0L));
167 fixture
.seekEvent(loc
);
168 assertNotNull(fixture
);
173 * Run the ITmfTimestamp getEndTime() method test.
176 public void testGetEndTime() {
177 ITmfTimestamp result
= fixture
.getEndTime();
178 assertNotNull(result
);
182 * Run the String[] getEnvNames() method test.
185 public void testGetEnvNames() {
186 String
[] result
= fixture
.getEnvNames();
187 assertNotNull(result
);
191 * Run the String getEnvValue(String) method 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$
201 * Run the Class<CtfTmfEvent> getEventType() method test.
204 public void testGetEventType() {
205 Class
<ITmfEvent
> result
= fixture
.getEventType();
206 assertNotNull(result
);
210 * Run the double getLocationRatio(ITmfLocation<?>) method 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
);
218 assertEquals(Double
.NEGATIVE_INFINITY
, result
, 0.1);
222 * Run the String getName() method test.
225 public void testGetName() {
226 String result
= fixture
.getName();
227 assertNotNull(result
);
231 * Run the int getNbEnvVars() method test.
234 public void testGetNbEnvVars() {
235 int result
= fixture
.getNbEnvVars();
236 assertEquals(8, result
);
240 * Run the long getNbEvents() method test.
243 public void testGetNbEvents() {
244 long result
= fixture
.getNbEvents();
245 assertEquals(0L, result
);
249 * Run the CtfTmfEvent getNext(ITmfContext) method test.
252 public void testGetNext() {
253 ITmfContext context
= fixture
.seekEvent(0);
254 CtfTmfEvent result
= fixture
.getNext(context
);
255 assertNotNull(result
);
259 * Run the String getPath() method test.
262 public void testGetPath() {
263 String result
= fixture
.getPath();
264 assertNotNull(result
);
268 * Run the IResource getResource() method test.
271 public void testGetResource() {
272 IResource result
= fixture
.getResource();
277 * Run the ITmfTimestamp getStartTime() method test.
280 public void testGetStartTime() {
281 ITmfTimestamp result
= fixture
.getStartTime();
282 assertNotNull(result
);
286 * Run the IStateSystemQuerier getStateSystem() method test.
289 public void testGetStateSystem() {
290 IStateSystemQuerier result
= fixture
.getStateSystem();
295 * Run the long getStreamingInterval() method test.
298 public void testGetStreamingInterval() {
299 long result
= fixture
.getStreamingInterval();
300 assertEquals(0L, result
);
304 * Run the TmfTimeRange getTimeRange() method test.
307 public void testGetTimeRange() {
308 TmfTimeRange result
= fixture
.getTimeRange();
309 assertNotNull(result
);
313 * Run the CtfTmfEvent readNextEvent(ITmfContext) method test.
316 public void testReadNextEvent() {
317 ITmfContext context
= fixture
.seekEvent(0);
318 CtfTmfEvent result
= fixture
.getNext(context
);
319 assertNotNull(result
);
323 * Run the ITmfContext seekEvent(double) method test.
326 public void testSeekEvent_ratio() {
328 ITmfContext result
= fixture
.seekEvent(ratio
);
329 assertNotNull(result
);
333 * Run the ITmfContext seekEvent(long) method test.
336 public void testSeekEvent_rank() {
338 ITmfContext result
= fixture
.seekEvent(rank
);
339 assertNotNull(result
);
343 * Run the ITmfContext seekEvent(ITmfTimestamp) method test.
346 public void testSeekEvent_timestamp() {
347 ITmfTimestamp timestamp
= new TmfTimestamp();
348 ITmfContext result
= fixture
.seekEvent(timestamp
);
349 assertNotNull(result
);
353 * Run the ITmfContext seekEvent(ITmfLocation<?>) method test.
356 public void testSeekEvent_location() {
357 CtfLocation ctfLocation
= new CtfLocation(new Long(1L));
358 ITmfContext result
= fixture
.seekEvent(ctfLocation
);
359 assertNotNull(result
);
363 * Run the boolean validate(IProject,String) method test.
366 public void testValidate() {
367 IProject project
= null;
369 boolean result
= fixture
.validate(project
, path
);