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
;
54 * Perform pre-test initialization.
56 * @throws TmfTraceException
57 * If the test trace is not found
60 public void setUp() throws TmfTraceException
{
61 fixture
= new CtfTmfTrace();
62 fixture
.initTrace((IResource
) null, PATH
, CtfTmfEvent
.class);
66 * Perform post-test clean-up.
69 public void tearDown() {
74 * Run the CtfTmfTrace() constructor test.
77 public void testCtfTmfTrace() {
78 CtfTmfTrace result
= new CtfTmfTrace();
80 assertNotNull(result
);
81 assertNull(result
.getEventType());
82 assertEquals(1000, result
.getCacheSize());
83 assertEquals(0L, result
.getNbEvents());
84 assertEquals(0L, result
.getStreamingInterval());
85 assertNull(result
.getResource());
86 assertEquals(1000, result
.getQueueSize());
87 assertNull(result
.getType());
91 * Test the parseEvent() method
94 public void testParseEvent() {
95 ITmfContext ctx
= fixture
.seekEvent(0);
97 CtfTmfEvent event
= fixture
.parseEvent(ctx
);
102 * Run the void broadcast(TmfSignal) method test.
105 public void testBroadcast() {
106 TmfSignal signal
= new TmfEndSynchSignal(1);
107 fixture
.broadcast(signal
);
112 * Run the void dispose() method test.
115 public void testDispose() {
116 CtfTmfTrace emptyFixture
= new CtfTmfTrace();
117 emptyFixture
.dispose();
122 * Run the int getCacheSize() method test.
125 public void testGetCacheSize() {
126 CtfTmfTrace emptyFixture
= new CtfTmfTrace();
127 int result
= emptyFixture
.getCacheSize();
128 assertEquals(1000, result
);
132 * Run the ITmfLocation<Comparable> getCurrentLocation() method test.
135 public void testGetCurrentLocation() {
136 CtfLocation result
= (CtfLocation
) fixture
.getCurrentLocation();
141 * Test the seekEvent() method with a null location.
144 public void testSeekEventLoc_null() {
145 CtfLocation loc
= null;
146 fixture
.seekEvent(loc
);
147 assertNotNull(fixture
);
151 * Test the seekEvent() method with a location from a timestamp.
154 public void testSeekEventLoc_timetamp(){
155 CtfLocation loc
= new CtfLocation(new CtfTmfTimestamp(0L));
156 fixture
.seekEvent(loc
);
157 assertNotNull(fixture
);
162 * Run the ITmfTimestamp getEndTime() method test.
165 public void testGetEndTime() {
166 ITmfTimestamp result
= fixture
.getEndTime();
167 assertNotNull(result
);
171 * Run the String[] getEnvNames() method test.
174 public void testGetEnvNames() {
175 String
[] result
= fixture
.getEnvNames();
176 assertNotNull(result
);
180 * Run the String getEnvValue(String) method test.
183 public void testGetEnvValue() {
184 String key
= "tracer_name"; //$NON-NLS-1$
185 String result
= fixture
.getEnvValue(key
);
186 assertEquals("\"lttng-modules\"",result
); //$NON-NLS-1$
190 * Run the Class<CtfTmfEvent> getEventType() method test.
193 public void testGetEventType() {
194 Class
<ITmfEvent
> result
= fixture
.getEventType();
195 assertNotNull(result
);
199 * Run the double getLocationRatio(ITmfLocation<?>) method test.
202 public void testGetLocationRatio() {
203 final CtfLocationData location2
= new CtfLocationData(1, 0);
204 CtfLocation location
= new CtfLocation(location2
);
205 double result
= fixture
.getLocationRatio(location
);
207 assertEquals(Double
.NEGATIVE_INFINITY
, result
, 0.1);
211 * Run the String getName() method test.
214 public void testGetName() {
215 String result
= fixture
.getName();
216 assertNotNull(result
);
220 * Run the int getNbEnvVars() method test.
223 public void testGetNbEnvVars() {
224 int result
= fixture
.getNbEnvVars();
225 assertEquals(8, result
);
229 * Run the long getNbEvents() method test.
232 public void testGetNbEvents() {
233 long result
= fixture
.getNbEvents();
234 assertEquals(1L, result
);
238 * Run the CtfTmfEvent getNext(ITmfContext) method test.
241 public void testGetNext() {
242 ITmfContext context
= fixture
.seekEvent(0);
243 CtfTmfEvent result
= fixture
.getNext(context
);
244 assertNotNull(result
);
248 * Run the String getPath() method test.
251 public void testGetPath() {
252 String result
= fixture
.getPath();
253 assertNotNull(result
);
257 * Run the IResource getResource() method test.
260 public void testGetResource() {
261 IResource result
= fixture
.getResource();
266 * Run the ITmfTimestamp getStartTime() method test.
269 public void testGetStartTime() {
270 ITmfTimestamp result
= fixture
.getStartTime();
271 assertNotNull(result
);
275 * Run the long getStreamingInterval() method test.
278 public void testGetStreamingInterval() {
279 long result
= fixture
.getStreamingInterval();
280 assertEquals(0L, result
);
284 * Run the TmfTimeRange getTimeRange() method test.
287 public void testGetTimeRange() {
288 TmfTimeRange result
= fixture
.getTimeRange();
289 assertNotNull(result
);
293 * Run the CtfTmfEvent readNextEvent(ITmfContext) method test.
296 public void testReadNextEvent() {
297 ITmfContext context
= fixture
.seekEvent(0);
298 CtfTmfEvent result
= fixture
.getNext(context
);
299 assertNotNull(result
);
303 * Run the ITmfContext seekEvent(double) method test.
306 public void testSeekEvent_ratio() {
308 ITmfContext result
= fixture
.seekEvent(ratio
);
309 assertNotNull(result
);
313 * Run the ITmfContext seekEvent(long) method test.
316 public void testSeekEvent_rank() {
318 ITmfContext result
= fixture
.seekEvent(rank
);
319 assertNotNull(result
);
323 * Run the ITmfContext seekEvent(ITmfTimestamp) method test.
326 public void testSeekEvent_timestamp() {
327 ITmfTimestamp timestamp
= new TmfTimestamp();
328 ITmfContext result
= fixture
.seekEvent(timestamp
);
329 assertNotNull(result
);
333 * Run the ITmfContext seekEvent(ITmfLocation<?>) method test.
336 public void testSeekEvent_location() {
337 final CtfLocationData location2
= new CtfLocationData(1L, 0L);
338 CtfLocation ctfLocation
= new CtfLocation(location2
);
339 ITmfContext result
= fixture
.seekEvent(ctfLocation
);
340 assertNotNull(result
);
344 * Run the boolean validate(IProject,String) method test.
347 public void testValidate() {
348 IProject project
= null;
350 boolean result
= fixture
.validate(project
, path
);