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