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
;
20 import static org
.junit
.Assume
.assumeTrue
;
22 import org
.eclipse
.core
.resources
.IProject
;
23 import org
.eclipse
.core
.resources
.IResource
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfLocation
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfLocationInfo
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfEvent
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfTimestamp
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfTrace
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfEndSynchSignal
;
32 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignal
;
33 import org
.eclipse
.linuxtools
.tmf
.core
.tests
.shared
.CtfTmfTestTraces
;
34 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
35 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimeRange
;
36 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimestamp
;
37 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
38 import org
.junit
.After
;
39 import org
.junit
.Before
;
40 import org
.junit
.Test
;
43 * The class <code>CtfTmfTraceTest</code> contains tests for the class
44 * <code>{@link CtfTmfTrace}</code>.
49 public class CtfTmfTraceTest
{
51 private static final int TRACE_INDEX
= 0;
52 private static final String PATH
= CtfTmfTestTraces
.getTestTracePath(TRACE_INDEX
);
54 private CtfTmfTrace fixture
;
57 * Perform pre-test initialization.
59 * @throws TmfTraceException
60 * If the test trace is not found
63 public void setUp() throws TmfTraceException
{
64 assumeTrue(CtfTmfTestTraces
.tracesExist());
65 fixture
= new CtfTmfTrace();
66 fixture
.initTrace((IResource
) null, PATH
, CtfTmfEvent
.class);
70 * Perform post-test clean-up.
73 public void tearDown() {
74 if (fixture
!= null) {
80 * Run the CtfTmfTrace() constructor test.
83 public void testCtfTmfTrace() {
84 CtfTmfTrace result
= new CtfTmfTrace();
86 assertNotNull(result
);
87 assertNull(result
.getEventType());
88 assertEquals(1000, result
.getCacheSize());
89 assertEquals(0L, result
.getNbEvents());
90 assertEquals(0L, result
.getStreamingInterval());
91 assertNull(result
.getResource());
92 assertEquals(1000, result
.getQueueSize());
93 assertNull(result
.getType());
97 * Test the parseEvent() method
100 public void testParseEvent() {
101 ITmfContext ctx
= fixture
.seekEvent(0);
102 fixture
.getNext(ctx
);
103 CtfTmfEvent event
= fixture
.parseEvent(ctx
);
104 assertNotNull(event
);
108 * Run the void broadcast(TmfSignal) method test.
111 public void testBroadcast() {
112 TmfSignal signal
= new TmfEndSynchSignal(1);
113 fixture
.broadcast(signal
);
118 * Run the void dispose() method test.
121 public void testDispose() {
122 CtfTmfTrace emptyFixture
= new CtfTmfTrace();
123 emptyFixture
.dispose();
128 * Run the int getCacheSize() method test.
131 public void testGetCacheSize() {
132 CtfTmfTrace emptyFixture
= new CtfTmfTrace();
133 int result
= emptyFixture
.getCacheSize();
134 assertEquals(1000, result
);
138 * Run the ITmfLocation<Comparable> getCurrentLocation() method test.
141 public void testGetCurrentLocation() {
142 CtfLocation result
= (CtfLocation
) fixture
.getCurrentLocation();
147 * Test the seekEvent() method with a null location.
150 public void testSeekEventLoc_null() {
151 CtfLocation loc
= null;
152 fixture
.seekEvent(loc
);
153 assertNotNull(fixture
);
157 * Test the seekEvent() method with a location from a timestamp.
160 public void testSeekEventLoc_timetamp(){
161 CtfLocation loc
= new CtfLocation(new CtfTmfTimestamp(0L));
162 fixture
.seekEvent(loc
);
163 assertNotNull(fixture
);
168 * Run the ITmfTimestamp getEndTime() method test.
171 public void testGetEndTime() {
172 ITmfTimestamp result
= fixture
.getEndTime();
173 assertNotNull(result
);
177 * Run the String[] getEnvNames() method test.
180 public void testGetEnvNames() {
181 String
[] result
= fixture
.getEnvNames();
182 assertNotNull(result
);
186 * Run the String getEnvValue(String) method test.
189 public void testGetEnvValue() {
190 String key
= "tracer_name"; //$NON-NLS-1$
191 String result
= fixture
.getEnvValue(key
);
192 assertEquals("\"lttng-modules\"",result
); //$NON-NLS-1$
196 * Run the Class<CtfTmfEvent> getEventType() method test.
199 public void testGetEventType() {
200 Class
<ITmfEvent
> result
= fixture
.getEventType();
201 assertNotNull(result
);
205 * Run the double getLocationRatio(ITmfLocation<?>) method test.
208 public void testGetLocationRatio() {
209 final CtfLocationInfo location2
= new CtfLocationInfo(1, 0);
210 CtfLocation location
= new CtfLocation(location2
);
211 double result
= fixture
.getLocationRatio(location
);
213 assertEquals(Double
.NEGATIVE_INFINITY
, result
, 0.1);
217 * Run the String getName() method test.
220 public void testGetName() {
221 String result
= fixture
.getName();
222 assertNotNull(result
);
226 * Run the int getNbEnvVars() method test.
229 public void testGetNbEnvVars() {
230 int result
= fixture
.getNbEnvVars();
231 assertEquals(8, result
);
235 * Run the long getNbEvents() method test.
238 public void testGetNbEvents() {
239 long result
= fixture
.getNbEvents();
240 assertEquals(1L, result
);
244 * Run the CtfTmfEvent getNext(ITmfContext) method test.
247 public void testGetNext() {
248 ITmfContext context
= fixture
.seekEvent(0);
249 CtfTmfEvent result
= fixture
.getNext(context
);
250 assertNotNull(result
);
254 * Run the String getPath() method test.
257 public void testGetPath() {
258 String result
= fixture
.getPath();
259 assertNotNull(result
);
263 * Run the IResource getResource() method test.
266 public void testGetResource() {
267 IResource result
= fixture
.getResource();
272 * Run the ITmfTimestamp getStartTime() method test.
275 public void testGetStartTime() {
276 ITmfTimestamp result
= fixture
.getStartTime();
277 assertNotNull(result
);
281 * Run the long getStreamingInterval() method test.
284 public void testGetStreamingInterval() {
285 long result
= fixture
.getStreamingInterval();
286 assertEquals(0L, result
);
290 * Run the TmfTimeRange getTimeRange() method test.
293 public void testGetTimeRange() {
294 TmfTimeRange result
= fixture
.getTimeRange();
295 assertNotNull(result
);
299 * Run the CtfTmfEvent readNextEvent(ITmfContext) method test.
302 public void testReadNextEvent() {
303 ITmfContext context
= fixture
.seekEvent(0);
304 CtfTmfEvent result
= fixture
.getNext(context
);
305 assertNotNull(result
);
309 * Run the ITmfContext seekEvent(double) method test.
312 public void testSeekEvent_ratio() {
314 ITmfContext result
= fixture
.seekEvent(ratio
);
315 assertNotNull(result
);
319 * Run the ITmfContext seekEvent(long) method test.
322 public void testSeekEvent_rank() {
324 ITmfContext result
= fixture
.seekEvent(rank
);
325 assertNotNull(result
);
329 * Run the ITmfContext seekEvent(ITmfTimestamp) method test.
332 public void testSeekEvent_timestamp() {
333 ITmfTimestamp timestamp
= new TmfTimestamp();
334 ITmfContext result
= fixture
.seekEvent(timestamp
);
335 assertNotNull(result
);
339 * Run the ITmfContext seekEvent(ITmfLocation<?>) method test.
342 public void testSeekEvent_location() {
343 final CtfLocationInfo location2
= new CtfLocationInfo(1L, 0L);
344 CtfLocation ctfLocation
= new CtfLocation(location2
);
345 ITmfContext result
= fixture
.seekEvent(ctfLocation
);
346 assertNotNull(result
);
350 * Run the boolean validate(IProject,String) method test.
353 public void testValidate() {
354 IProject project
= null;
356 boolean result
= fixture
.validate(project
, path
);