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
.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
.getResource());
96 assertEquals(1000, result
.getQueueSize());
97 assertNull(result
.getType());
101 * Test the parseEvent() method
104 public void testParseEvent() {
105 ITmfContext ctx
= fixture
.seekEvent(0);
106 fixture
.getNext(ctx
);
107 CtfTmfEvent event
= fixture
.parseEvent(ctx
);
108 assertNotNull(event
);
112 * Run the void broadcast(TmfSignal) method test.
115 public void testBroadcast() {
116 TmfSignal signal
= new TmfEndSynchSignal(1);
117 fixture
.broadcast(signal
);
122 * Run the void dispose() method test.
125 public void testDispose() {
126 CtfTmfTrace emptyFixture
= new CtfTmfTrace();
127 emptyFixture
.dispose();
132 * Run the int getCacheSize() method test.
135 public void testGetCacheSize() {
136 CtfTmfTrace emptyFixture
= new CtfTmfTrace();
137 int result
= emptyFixture
.getCacheSize();
138 assertEquals(1000, result
);
142 * Run the ITmfLocation<Comparable> getCurrentLocation() method test.
145 public void testGetCurrentLocation() {
146 CtfLocation result
= (CtfLocation
) fixture
.getCurrentLocation();
151 * Test the seekEvent() method with a null location.
154 public void testSeekEventLoc_null() {
155 CtfLocation loc
= null;
156 fixture
.seekEvent(loc
);
157 assertNotNull(fixture
);
161 * Test the seekEvent() method with a location from a timestamp.
164 public void testSeekEventLoc_timetamp(){
165 CtfLocation loc
= new CtfLocation(new CtfTmfTimestamp(0L));
166 fixture
.seekEvent(loc
);
167 assertNotNull(fixture
);
172 * Run the ITmfTimestamp getEndTime() method test.
175 public void testGetEndTime() {
176 ITmfTimestamp result
= fixture
.getEndTime();
177 assertNotNull(result
);
181 * Run the String[] getEnvNames() method test.
184 public void testGetEnvNames() {
185 String
[] result
= fixture
.getEnvNames();
186 assertNotNull(result
);
190 * Run the String getEnvValue(String) method test.
193 public void testGetEnvValue() {
194 String key
= "tracer_name"; //$NON-NLS-1$
195 String result
= fixture
.getEnvValue(key
);
196 assertEquals("\"lttng-modules\"",result
); //$NON-NLS-1$
200 * Run the Class<CtfTmfEvent> getEventType() method test.
203 public void testGetEventType() {
204 Class
<ITmfEvent
> result
= fixture
.getEventType();
205 assertNotNull(result
);
209 * Run the double getLocationRatio(ITmfLocation<?>) method test.
212 public void testGetLocationRatio() {
213 final CtfLocationData location2
= new CtfLocationData(1, 0);
214 CtfLocation location
= new CtfLocation(location2
);
215 double result
= fixture
.getLocationRatio(location
);
217 assertEquals(Double
.NEGATIVE_INFINITY
, result
, 0.1);
221 * Run the String getName() method test.
224 public void testGetName() {
225 String result
= fixture
.getName();
226 assertNotNull(result
);
230 * Run the int getNbEnvVars() method test.
233 public void testGetNbEnvVars() {
234 int result
= fixture
.getNbEnvVars();
235 assertEquals(8, result
);
239 * Run the long getNbEvents() method test.
242 public void testGetNbEvents() {
243 long result
= fixture
.getNbEvents();
244 assertEquals(1L, result
);
248 * Run the CtfTmfEvent getNext(ITmfContext) method test.
251 public void testGetNext() {
252 ITmfContext context
= fixture
.seekEvent(0);
253 CtfTmfEvent result
= fixture
.getNext(context
);
254 assertNotNull(result
);
258 * Run the String getPath() method test.
261 public void testGetPath() {
262 String result
= fixture
.getPath();
263 assertNotNull(result
);
267 * Run the IResource getResource() method test.
270 public void testGetResource() {
271 IResource result
= fixture
.getResource();
276 * Run the ITmfTimestamp getStartTime() method test.
279 public void testGetStartTime() {
280 ITmfTimestamp result
= fixture
.getStartTime();
281 assertNotNull(result
);
285 * Run the long getStreamingInterval() method test.
288 public void testGetStreamingInterval() {
289 long result
= fixture
.getStreamingInterval();
290 assertEquals(0L, result
);
294 * Run the TmfTimeRange getTimeRange() method test.
297 public void testGetTimeRange() {
298 TmfTimeRange result
= fixture
.getTimeRange();
299 assertNotNull(result
);
303 * Run the CtfTmfEvent readNextEvent(ITmfContext) method test.
306 public void testReadNextEvent() {
307 ITmfContext context
= fixture
.seekEvent(0);
308 CtfTmfEvent result
= fixture
.getNext(context
);
309 assertNotNull(result
);
313 * Run the ITmfContext seekEvent(double) method test.
316 public void testSeekEvent_ratio() {
318 ITmfContext result
= fixture
.seekEvent(ratio
);
319 assertNotNull(result
);
323 * Run the ITmfContext seekEvent(long) method test.
326 public void testSeekEvent_rank() {
328 ITmfContext result
= fixture
.seekEvent(rank
);
329 assertNotNull(result
);
333 * Run the ITmfContext seekEvent(ITmfTimestamp) method test.
336 public void testSeekEvent_timestamp() {
337 ITmfTimestamp timestamp
= new TmfTimestamp();
338 ITmfContext result
= fixture
.seekEvent(timestamp
);
339 assertNotNull(result
);
343 * Run the ITmfContext seekEvent(ITmfLocation<?>) method test.
346 public void testSeekEvent_location() {
347 final CtfLocationData location2
= new CtfLocationData(1L, 0L);
348 CtfLocation ctfLocation
= new CtfLocation(location2
);
349 ITmfContext result
= fixture
.seekEvent(ctfLocation
);
350 assertNotNull(result
);
354 * Run the boolean validate(IProject,String) method test.
357 public void testValidate() {
358 IProject project
= null;
360 boolean result
= fixture
.validate(project
, path
);