1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 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
.core
.runtime
.IStatus
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfLocation
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfLocationInfo
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfEvent
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfTimestamp
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfTrace
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
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
.tests
.shared
.CtfTmfTestTraces
;
35 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
36 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimeRange
;
37 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimestamp
;
38 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
39 import org
.junit
.After
;
40 import org
.junit
.Before
;
41 import org
.junit
.Test
;
44 * The class <code>CtfTmfTraceTest</code> contains tests for the class
45 * <code>{@link CtfTmfTrace}</code>.
50 public class CtfTmfTraceTest
{
52 private static final int TRACE_INDEX
= 0;
53 private static final String PATH
= CtfTmfTestTraces
.getTestTracePath(TRACE_INDEX
);
55 private CtfTmfTrace fixture
;
58 * Perform pre-test initialization.
60 * @throws TmfTraceException
61 * If the test trace is not found
64 public void setUp() throws TmfTraceException
{
65 assumeTrue(CtfTmfTestTraces
.tracesExist());
66 fixture
= new CtfTmfTrace();
67 fixture
.initTrace((IResource
) null, PATH
, CtfTmfEvent
.class);
71 * Perform post-test clean-up.
74 public void tearDown() {
75 if (fixture
!= null) {
81 * Run the CtfTmfTrace() constructor test.
84 public void testCtfTmfTrace() {
85 CtfTmfTrace result
= new CtfTmfTrace();
87 assertNotNull(result
);
88 assertNull(result
.getEventType());
89 assertEquals(1000, result
.getCacheSize());
90 assertEquals(0L, result
.getNbEvents());
91 assertEquals(0L, result
.getStreamingInterval());
92 assertNull(result
.getResource());
93 assertEquals(1000, result
.getQueueSize());
94 assertNull(result
.getType());
98 * Test the parseEvent() method
101 public void testParseEvent() {
102 ITmfContext ctx
= fixture
.seekEvent(0);
103 fixture
.getNext(ctx
);
104 CtfTmfEvent event
= fixture
.parseEvent(ctx
);
105 assertNotNull(event
);
109 * Run the void broadcast(TmfSignal) method test.
112 public void testBroadcast() {
113 TmfSignal signal
= new TmfEndSynchSignal(1);
114 fixture
.broadcast(signal
);
119 * Run the void dispose() method test.
122 public void testDispose() {
123 CtfTmfTrace emptyFixture
= new CtfTmfTrace();
124 emptyFixture
.dispose();
129 * Run the int getCacheSize() method test.
132 public void testGetCacheSize() {
133 CtfTmfTrace emptyFixture
= new CtfTmfTrace();
134 int result
= emptyFixture
.getCacheSize();
135 assertEquals(1000, result
);
139 * Run the ITmfLocation<Comparable> getCurrentLocation() method test.
142 public void testGetCurrentLocation() {
143 CtfLocation result
= (CtfLocation
) fixture
.getCurrentLocation();
148 * Test the seekEvent() method with a null location.
151 public void testSeekEventLoc_null() {
152 CtfLocation loc
= null;
153 fixture
.seekEvent(loc
);
154 assertNotNull(fixture
);
158 * Test the seekEvent() method with a location from a timestamp.
161 public void testSeekEventLoc_timetamp(){
162 CtfLocation loc
= new CtfLocation(new CtfTmfTimestamp(0L));
163 fixture
.seekEvent(loc
);
164 assertNotNull(fixture
);
169 * Run the ITmfTimestamp getEndTime() method test.
172 public void testGetEndTime() {
173 ITmfTimestamp result
= fixture
.getEndTime();
174 assertNotNull(result
);
178 * Run the String[] getEnvNames() method test.
181 public void testGetEnvNames() {
182 String
[] result
= fixture
.getEnvNames();
183 assertNotNull(result
);
187 * Run the String getEnvValue(String) method test.
190 public void testGetEnvValue() {
191 String key
= "tracer_name";
192 String result
= fixture
.getEnvValue(key
);
193 assertEquals("\"lttng-modules\"",result
);
197 * Run the Class<CtfTmfEvent> getEventType() method test.
200 public void testGetEventType() {
201 Class
<ITmfEvent
> result
= fixture
.getEventType();
202 assertNotNull(result
);
206 * Run the double getLocationRatio(ITmfLocation<?>) method test.
209 public void testGetLocationRatio() {
210 final CtfLocationInfo location2
= new CtfLocationInfo(1, 0);
211 CtfLocation location
= new CtfLocation(location2
);
212 double result
= fixture
.getLocationRatio(location
);
214 assertEquals(Double
.NEGATIVE_INFINITY
, result
, 0.1);
218 * Run the String getName() method test.
221 public void testGetName() {
222 String result
= fixture
.getName();
223 assertNotNull(result
);
227 * Run the int getNbEnvVars() method test.
230 public void testGetNbEnvVars() {
231 int result
= fixture
.getNbEnvVars();
232 assertEquals(8, result
);
236 * Run the long getNbEvents() method test.
239 public void testGetNbEvents() {
240 long result
= fixture
.getNbEvents();
241 assertEquals(1L, result
);
245 * Run the CtfTmfEvent getNext(ITmfContext) method test.
248 public void testGetNext() {
249 ITmfContext context
= fixture
.seekEvent(0);
250 CtfTmfEvent result
= fixture
.getNext(context
);
251 assertNotNull(result
);
255 * Run the String getPath() method test.
258 public void testGetPath() {
259 String result
= fixture
.getPath();
260 assertNotNull(result
);
264 * Run the IResource getResource() method test.
267 public void testGetResource() {
268 IResource result
= fixture
.getResource();
273 * Run the ITmfTimestamp getStartTime() method test.
276 public void testGetStartTime() {
277 ITmfTimestamp result
= fixture
.getStartTime();
278 assertNotNull(result
);
282 * Run the long getStreamingInterval() method test.
285 public void testGetStreamingInterval() {
286 long result
= fixture
.getStreamingInterval();
287 assertEquals(0L, result
);
291 * Run the TmfTimeRange getTimeRange() method test.
294 public void testGetTimeRange() {
295 TmfTimeRange result
= fixture
.getTimeRange();
296 assertNotNull(result
);
300 * Run the CtfTmfEvent readNextEvent(ITmfContext) method test.
303 public void testReadNextEvent() {
304 ITmfContext context
= fixture
.seekEvent(0);
305 CtfTmfEvent result
= fixture
.getNext(context
);
306 assertNotNull(result
);
310 * Run the ITmfContext seekEvent(double) method test.
313 public void testSeekEvent_ratio() {
315 ITmfContext result
= fixture
.seekEvent(ratio
);
316 assertNotNull(result
);
320 * Run the ITmfContext seekEvent(long) method test.
323 public void testSeekEvent_rank() {
325 ITmfContext result
= fixture
.seekEvent(rank
);
326 assertNotNull(result
);
330 * Run the ITmfContext seekEvent(ITmfTimestamp) method test.
333 public void testSeekEvent_timestamp() {
334 ITmfTimestamp timestamp
= new TmfTimestamp();
335 ITmfContext result
= fixture
.seekEvent(timestamp
);
336 assertNotNull(result
);
340 * Run the ITmfContext seekEvent(ITmfLocation<?>) method test.
343 public void testSeekEvent_location() {
344 final CtfLocationInfo location2
= new CtfLocationInfo(1L, 0L);
345 CtfLocation ctfLocation
= new CtfLocation(location2
);
346 ITmfContext result
= fixture
.seekEvent(ctfLocation
);
347 assertNotNull(result
);
351 * Run the boolean validate(IProject,String) method test.
352 * @throws TmfValidationException
355 public void testValidate() {
356 IProject project
= null;
358 IStatus result
= fixture
.validate(project
, path
);
359 assertTrue(result
.isOK());