Commit | Line | Data |
---|---|---|
95bf10e7 AM |
1 | /******************************************************************************* |
2 | * Copyright (c) 2012 Ericsson | |
3 | * | |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Matthew Khouzam - Initial generation with CodePro tools | |
11 | * Alexandre Montplaisir - Clean up, consolidate redundant tests | |
12 | *******************************************************************************/ | |
13 | ||
81c8e6f7 MK |
14 | package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor; |
15 | ||
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 | ||
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; | |
81c8e6f7 MK |
27 | import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; |
28 | import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; | |
29 | import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; | |
30 | import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; | |
81c8e6f7 MK |
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.statesystem.IStateSystemQuerier; | |
34 | import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; | |
81c8e6f7 MK |
35 | import org.junit.After; |
36 | import org.junit.Before; | |
37 | import org.junit.Test; | |
38 | ||
39 | /** | |
95bf10e7 AM |
40 | * The class <code>CtfTmfTraceTest</code> contains tests for the class |
41 | * <code>{@link CtfTmfTrace}</code>. | |
81c8e6f7 | 42 | * |
81c8e6f7 | 43 | * @author ematkho |
95bf10e7 | 44 | * @version 1.0 |
81c8e6f7 MK |
45 | */ |
46 | public class CtfTmfTraceTest { | |
95bf10e7 | 47 | |
81c8e6f7 MK |
48 | private static final String PATH = TestParams.getPath(); |
49 | ||
95bf10e7 AM |
50 | private CtfTmfTrace fixture; |
51 | ||
81c8e6f7 | 52 | /** |
95bf10e7 | 53 | * Launch the test. |
81c8e6f7 | 54 | * |
95bf10e7 AM |
55 | * @param args |
56 | * the command line arguments | |
57 | */ | |
58 | public static void main(String[] args) { | |
59 | new org.junit.runner.JUnitCore().run(CtfTmfTraceTest.class); | |
60 | } | |
61 | ||
62 | /** | |
63 | * Perform pre-test initialization. | |
81c8e6f7 | 64 | * |
95bf10e7 AM |
65 | * @throws TmfTraceException |
66 | * If the test trace is not found | |
81c8e6f7 | 67 | */ |
95bf10e7 AM |
68 | @Before |
69 | public void setUp() throws TmfTraceException { | |
70 | fixture = new CtfTmfTrace(); | |
71 | fixture.initTrace((IResource) null, PATH, CtfTmfEvent.class); | |
72 | } | |
81c8e6f7 | 73 | |
95bf10e7 AM |
74 | /** |
75 | * Perform post-test clean-up. | |
76 | */ | |
77 | @After | |
78 | public void tearDown() { | |
79 | fixture.dispose(); | |
80 | } | |
81 | ||
82 | /** | |
83 | * Run the CtfTmfTrace() constructor test. | |
84 | */ | |
85 | @Test | |
86 | public void testCtfTmfTrace() { | |
81c8e6f7 MK |
87 | CtfTmfTrace result = new CtfTmfTrace(); |
88 | ||
81c8e6f7 | 89 | assertNotNull(result); |
95bf10e7 | 90 | assertNull(result.getEventType()); |
bfe038ff | 91 | assertEquals(1000, result.getCacheSize()); |
81c8e6f7 MK |
92 | assertEquals(0L, result.getNbEvents()); |
93 | assertEquals(0L, result.getStreamingInterval()); | |
95bf10e7 AM |
94 | assertNull(result.getStateSystem()); |
95 | assertNull(result.getResource()); | |
81c8e6f7 | 96 | assertEquals(1000, result.getQueueSize()); |
95bf10e7 | 97 | assertNull(result.getType()); |
81c8e6f7 MK |
98 | } |
99 | ||
95bf10e7 AM |
100 | /** |
101 | * Test the parseEvent() method | |
102 | */ | |
788ddcbc | 103 | @Test |
95bf10e7 | 104 | public void testParseEvent() { |
788ddcbc MK |
105 | ITmfContext ctx = fixture.seekEvent(0); |
106 | fixture.getNext(ctx); | |
107 | CtfTmfEvent event = fixture.parseEvent(ctx); | |
108 | assertNotNull(event); | |
109 | } | |
110 | ||
81c8e6f7 MK |
111 | /** |
112 | * Run the void broadcast(TmfSignal) method test. | |
81c8e6f7 MK |
113 | */ |
114 | @Test | |
95bf10e7 | 115 | public void testBroadcast() { |
81c8e6f7 | 116 | TmfSignal signal = new TmfEndSynchSignal(1); |
81c8e6f7 | 117 | fixture.broadcast(signal); |
81c8e6f7 MK |
118 | } |
119 | ||
120 | ||
121 | /** | |
122 | * Run the void dispose() method test. | |
81c8e6f7 MK |
123 | */ |
124 | @Test | |
95bf10e7 AM |
125 | public void testDispose() { |
126 | CtfTmfTrace emptyFixture = new CtfTmfTrace(); | |
127 | emptyFixture.dispose(); | |
81c8e6f7 MK |
128 | |
129 | } | |
130 | ||
131 | /** | |
132 | * Run the int getCacheSize() method test. | |
81c8e6f7 MK |
133 | */ |
134 | @Test | |
95bf10e7 AM |
135 | public void testGetCacheSize() { |
136 | CtfTmfTrace emptyFixture = new CtfTmfTrace(); | |
137 | int result = emptyFixture.getCacheSize(); | |
bfe038ff | 138 | assertEquals(1000, result); |
81c8e6f7 MK |
139 | } |
140 | ||
141 | /** | |
142 | * Run the ITmfLocation<Comparable> getCurrentLocation() method test. | |
81c8e6f7 MK |
143 | */ |
144 | @Test | |
95bf10e7 | 145 | public void testGetCurrentLocation() { |
81c8e6f7 | 146 | CtfLocation result = (CtfLocation) fixture.getCurrentLocation(); |
f474d36b | 147 | assertNull(result); |
81c8e6f7 MK |
148 | } |
149 | ||
95bf10e7 AM |
150 | /** |
151 | * Test the seekEvent() method with a null location. | |
152 | */ | |
81c8e6f7 | 153 | @Test |
95bf10e7 | 154 | public void testSeekEventLoc_null() { |
81c8e6f7 MK |
155 | CtfLocation loc = null; |
156 | fixture.seekEvent(loc); | |
157 | assertNotNull(fixture); | |
158 | } | |
159 | ||
95bf10e7 AM |
160 | /** |
161 | * Test the seekEvent() method with a location from a timestamp. | |
162 | */ | |
81c8e6f7 | 163 | @Test |
95bf10e7 | 164 | public void testSeekEventLoc_timetamp(){ |
81c8e6f7 MK |
165 | CtfLocation loc = new CtfLocation(new CtfTmfTimestamp(0L)); |
166 | fixture.seekEvent(loc); | |
167 | assertNotNull(fixture); | |
168 | } | |
169 | ||
170 | ||
171 | /** | |
172 | * Run the ITmfTimestamp getEndTime() method test. | |
81c8e6f7 MK |
173 | */ |
174 | @Test | |
95bf10e7 | 175 | public void testGetEndTime() { |
81c8e6f7 MK |
176 | ITmfTimestamp result = fixture.getEndTime(); |
177 | assertNotNull(result); | |
178 | } | |
179 | ||
180 | /** | |
181 | * Run the String[] getEnvNames() method test. | |
81c8e6f7 MK |
182 | */ |
183 | @Test | |
95bf10e7 | 184 | public void testGetEnvNames() { |
81c8e6f7 | 185 | String[] result = fixture.getEnvNames(); |
81c8e6f7 MK |
186 | assertNotNull(result); |
187 | } | |
188 | ||
189 | /** | |
190 | * Run the String getEnvValue(String) method test. | |
81c8e6f7 MK |
191 | */ |
192 | @Test | |
95bf10e7 | 193 | public void testGetEnvValue() { |
81c8e6f7 | 194 | String key = "tracer_name"; //$NON-NLS-1$ |
81c8e6f7 | 195 | String result = fixture.getEnvValue(key); |
81c8e6f7 MK |
196 | assertEquals("\"lttng-modules\"",result); //$NON-NLS-1$ |
197 | } | |
198 | ||
199 | /** | |
200 | * Run the Class<CtfTmfEvent> getEventType() method test. | |
81c8e6f7 MK |
201 | */ |
202 | @Test | |
95bf10e7 | 203 | public void testGetEventType() { |
81c8e6f7 | 204 | Class<CtfTmfEvent> result = fixture.getEventType(); |
bfe038ff | 205 | assertNotNull(result); |
81c8e6f7 MK |
206 | } |
207 | ||
208 | /** | |
209 | * Run the double getLocationRatio(ITmfLocation<?>) method test. | |
81c8e6f7 MK |
210 | */ |
211 | @Test | |
95bf10e7 | 212 | public void testGetLocationRatio() { |
0879b6b9 FC |
213 | CtfLocation location = new CtfLocation(Long.valueOf(1)); |
214 | location.setLocation(Long.valueOf(1)); | |
81c8e6f7 MK |
215 | double result = fixture.getLocationRatio(location); |
216 | ||
788ddcbc | 217 | assertEquals(Double.NEGATIVE_INFINITY, result, 0.1); |
81c8e6f7 MK |
218 | } |
219 | ||
220 | /** | |
221 | * Run the String getName() method test. | |
81c8e6f7 MK |
222 | */ |
223 | @Test | |
95bf10e7 | 224 | public void testGetName() { |
81c8e6f7 | 225 | String result = fixture.getName(); |
81c8e6f7 MK |
226 | assertNotNull(result); |
227 | } | |
228 | ||
229 | /** | |
230 | * Run the int getNbEnvVars() method test. | |
81c8e6f7 MK |
231 | */ |
232 | @Test | |
95bf10e7 | 233 | public void testGetNbEnvVars() { |
81c8e6f7 | 234 | int result = fixture.getNbEnvVars(); |
81c8e6f7 MK |
235 | assertEquals(8, result); |
236 | } | |
237 | ||
238 | /** | |
239 | * Run the long getNbEvents() method test. | |
81c8e6f7 MK |
240 | */ |
241 | @Test | |
95bf10e7 | 242 | public void testGetNbEvents() { |
81c8e6f7 | 243 | long result = fixture.getNbEvents(); |
81c8e6f7 MK |
244 | assertEquals(0L, result); |
245 | } | |
246 | ||
247 | /** | |
248 | * Run the CtfTmfEvent getNext(ITmfContext) method test. | |
81c8e6f7 MK |
249 | */ |
250 | @Test | |
95bf10e7 | 251 | public void testGetNext() { |
f474d36b | 252 | ITmfContext context = fixture.seekEvent(0); |
81c8e6f7 | 253 | CtfTmfEvent result = fixture.getNext(context); |
81c8e6f7 MK |
254 | assertNotNull(result); |
255 | } | |
256 | ||
257 | /** | |
258 | * Run the String getPath() method test. | |
81c8e6f7 MK |
259 | */ |
260 | @Test | |
95bf10e7 | 261 | public void testGetPath() { |
81c8e6f7 | 262 | String result = fixture.getPath(); |
81c8e6f7 MK |
263 | assertNotNull(result); |
264 | } | |
265 | ||
266 | /** | |
267 | * Run the IResource getResource() method test. | |
81c8e6f7 MK |
268 | */ |
269 | @Test | |
95bf10e7 | 270 | public void testGetResource() { |
81c8e6f7 | 271 | IResource result = fixture.getResource(); |
81c8e6f7 MK |
272 | assertNull(result); |
273 | } | |
274 | ||
275 | /** | |
276 | * Run the ITmfTimestamp getStartTime() method test. | |
81c8e6f7 MK |
277 | */ |
278 | @Test | |
95bf10e7 | 279 | public void testGetStartTime() { |
81c8e6f7 | 280 | ITmfTimestamp result = fixture.getStartTime(); |
81c8e6f7 MK |
281 | assertNotNull(result); |
282 | } | |
283 | ||
284 | /** | |
285 | * Run the IStateSystemQuerier getStateSystem() method test. | |
81c8e6f7 MK |
286 | */ |
287 | @Test | |
95bf10e7 | 288 | public void testGetStateSystem() { |
81c8e6f7 | 289 | IStateSystemQuerier result = fixture.getStateSystem(); |
81c8e6f7 MK |
290 | assertNull(result); |
291 | } | |
292 | ||
293 | /** | |
294 | * Run the long getStreamingInterval() method test. | |
81c8e6f7 MK |
295 | */ |
296 | @Test | |
95bf10e7 | 297 | public void testGetStreamingInterval() { |
81c8e6f7 | 298 | long result = fixture.getStreamingInterval(); |
81c8e6f7 MK |
299 | assertEquals(0L, result); |
300 | } | |
301 | ||
302 | /** | |
303 | * Run the TmfTimeRange getTimeRange() method test. | |
81c8e6f7 MK |
304 | */ |
305 | @Test | |
95bf10e7 | 306 | public void testGetTimeRange() { |
81c8e6f7 | 307 | TmfTimeRange result = fixture.getTimeRange(); |
81c8e6f7 MK |
308 | assertNotNull(result); |
309 | } | |
310 | ||
81c8e6f7 MK |
311 | /** |
312 | * Run the CtfTmfEvent readNextEvent(ITmfContext) method test. | |
81c8e6f7 MK |
313 | */ |
314 | @Test | |
95bf10e7 | 315 | public void testReadNextEvent() { |
f474d36b | 316 | ITmfContext context = fixture.seekEvent(0); |
c32744d6 | 317 | CtfTmfEvent result = fixture.getNext(context); |
81c8e6f7 MK |
318 | assertNotNull(result); |
319 | } | |
320 | ||
321 | /** | |
322 | * Run the ITmfContext seekEvent(double) method test. | |
81c8e6f7 MK |
323 | */ |
324 | @Test | |
95bf10e7 | 325 | public void testSeekEvent_ratio() { |
788ddcbc | 326 | double ratio = 0.99; |
81c8e6f7 | 327 | ITmfContext result = fixture.seekEvent(ratio); |
81c8e6f7 MK |
328 | assertNotNull(result); |
329 | } | |
330 | ||
331 | /** | |
332 | * Run the ITmfContext seekEvent(long) method test. | |
81c8e6f7 MK |
333 | */ |
334 | @Test | |
95bf10e7 | 335 | public void testSeekEvent_rank() { |
81c8e6f7 | 336 | long rank = 1L; |
81c8e6f7 | 337 | ITmfContext result = fixture.seekEvent(rank); |
81c8e6f7 MK |
338 | assertNotNull(result); |
339 | } | |
340 | ||
341 | /** | |
342 | * Run the ITmfContext seekEvent(ITmfTimestamp) method test. | |
81c8e6f7 MK |
343 | */ |
344 | @Test | |
95bf10e7 | 345 | public void testSeekEvent_timestamp() { |
81c8e6f7 | 346 | ITmfTimestamp timestamp = new TmfTimestamp(); |
81c8e6f7 | 347 | ITmfContext result = fixture.seekEvent(timestamp); |
81c8e6f7 MK |
348 | assertNotNull(result); |
349 | } | |
350 | ||
81c8e6f7 | 351 | /** |
95bf10e7 | 352 | * Run the ITmfContext seekEvent(ITmfLocation<?>) method test. |
81c8e6f7 MK |
353 | */ |
354 | @Test | |
95bf10e7 AM |
355 | public void testSeekEvent_location() { |
356 | CtfLocation ctfLocation = new CtfLocation(new Long(1L)); | |
357 | ITmfContext result = fixture.seekEvent(ctfLocation); | |
358 | assertNotNull(result); | |
81c8e6f7 MK |
359 | } |
360 | ||
361 | /** | |
362 | * Run the boolean validate(IProject,String) method test. | |
81c8e6f7 MK |
363 | */ |
364 | @Test | |
95bf10e7 | 365 | public void testValidate() { |
81c8e6f7 MK |
366 | IProject project = null; |
367 | String path = PATH; | |
81c8e6f7 | 368 | boolean result = fixture.validate(project, path); |
81c8e6f7 MK |
369 | assertTrue(result); |
370 | } | |
2d223a34 | 371 | } |