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