ctf: Throw CTFReaderException in the BitBuffer API
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / ctfadaptor / CtfIteratorTest.java
index 96d4cb93a2dcf806038ba1ea3e0a5a102872f36c..c228d079f939c17ffa45b31de3e48da268015a29 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2012 Ericsson
+ * Copyright (c) 2012, 2013 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -17,13 +17,15 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
 
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocation;
-import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocationData;
+import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocationInfo;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
-import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTrace;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -37,31 +39,23 @@ import org.junit.Test;
  */
 public class CtfIteratorTest {
 
-    private CtfIterator fixture;
+    private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.KERNEL;
 
-    /**
-     * Launch the test.
-     *
-     * @param args
-     *            the command line arguments
-     */
-    public static void main(String[] args) {
-        new org.junit.runner.JUnitCore().run(CtfIteratorTest.class);
-    }
+    private CtfTmfTrace trace;
+    private CtfIterator iterator;
 
     /**
      * Perform pre-test initialization.
-     *
-     * @throws TmfTraceException
-     *             If the test trace is not found
+     * @throws CTFReaderException error
      */
     @Before
-    public void setUp() throws TmfTraceException {
-        fixture = new CtfIterator(createTrace());
-        CtfLocation ctfLocation = new CtfLocation(new CtfLocationData(1, 0));
-        ctfLocation.setLocation(new CtfLocationData(1, 0));
-        fixture.setLocation(ctfLocation);
-        fixture.increaseRank();
+    public void setUp() throws CTFReaderException {
+        assumeTrue(testTrace.exists());
+        trace = testTrace.getTrace();
+        iterator = new CtfIterator(trace);
+        CtfLocation ctfLocation = new CtfLocation(new CtfLocationInfo(1, 0));
+        iterator.setLocation(ctfLocation);
+        iterator.increaseRank();
     }
 
     /**
@@ -69,37 +63,28 @@ public class CtfIteratorTest {
      */
     @After
     public void tearDown() {
-        fixture.dispose();
-    }
-
-
-    private static CtfTmfTrace createTrace() throws TmfTraceException {
-        return TestParams.createTrace();
+        if (iterator != null) {
+            iterator.dispose();
+        }
     }
 
     /**
      * Run the CtfIterator(CtfTmfTrace) constructor on a non init'ed trace.
-     *
-     * @throws TmfTraceException
-     *             If the test trace is not found
+     * @throws CTFReaderException error
      */
     @Test
-    public void testCtfIterator_noinit() throws TmfTraceException {
-        CtfTmfTrace trace = createTrace();
+    public void testCtfIterator_noinit() throws CTFReaderException {
         CtfIterator result = new CtfIterator(trace);
         assertNotNull(result);
     }
 
     /**
      * Run the CtfIterator(CtfTmfTrace) constructor on an init'ed trace.
-     *
-     * @throws TmfTraceException
-     *             If the test trace is not found
+     * @throws CTFReaderException error
      */
     @Test
-    public void testCtfIterator_init() throws TmfTraceException {
-        CtfTmfTrace trace = createTrace();
-        trace.init("test"); //$NON-NLS-1$
+    public void testCtfIterator_init() throws CTFReaderException {
+        trace.init("test");
         CtfIterator result = new CtfIterator(trace);
 
         assertNotNull(result);
@@ -108,16 +93,13 @@ public class CtfIteratorTest {
     /**
      * Run the CtfIterator(CtfTmfTrace,long,long) constructor test, which
      * specifies an initial position for the iterator.
-     *
-     * @throws TmfTraceException
-     *             If the test trace is not found
+     * @throws CTFReaderException error
      */
     @Test
-    public void testCtfIterator_position() throws TmfTraceException {
-        CtfTmfTrace trace = createTrace();
+    public void testCtfIterator_position() throws CTFReaderException {
         long timestampValue = 1L;
         long rank = 1L;
-        CtfIterator result = new CtfIterator(trace, new CtfLocationData(timestampValue, 0), rank);
+        CtfIterator result = new CtfIterator(trace, new CtfLocationInfo(timestampValue, 0), rank);
 
         assertNotNull(result);
     }
@@ -128,7 +110,7 @@ public class CtfIteratorTest {
      */
     @Test
     public void testAdvance() {
-        boolean result = fixture.advance();
+        boolean result = iterator.advance();
         assertTrue(result);
     }
 
@@ -137,20 +119,18 @@ public class CtfIteratorTest {
      */
     @Test
     public void testClone() {
-        CtfIterator result = fixture.clone();
+        CtfIterator result = iterator.clone();
         assertNotNull(result);
     }
 
     /**
      * Run the int compareTo(CtfIterator) method test.
-     *
-     * @throws TmfTraceException
-     *             If the test trace is not found
+     * @throws CTFReaderException error
      */
     @Test
-    public void testCompareTo() throws TmfTraceException {
-        CtfIterator o = new CtfIterator(createTrace());
-        int result = fixture.compareTo(o);
+    public void testCompareTo() throws CTFReaderException {
+        CtfIterator o = new CtfIterator(trace);
+        int result = iterator.compareTo(o);
 
         assertEquals(1L, result);
     }
@@ -158,19 +138,16 @@ public class CtfIteratorTest {
     /**
      * Run the boolean equals(Object) method test. Compare with another iterator
      * on the same trace.
-     *
-     * @throws TmfTraceException
-     *             If the test trace is not found
+     * @throws CTFReaderException error
      */
     @Test
-    public void testEquals_other() throws TmfTraceException {
-        CtfIterator obj = new CtfIterator(createTrace());
-        CtfLocation ctfLocation1 = new CtfLocation(new CtfLocationData(1, 0));
-        ctfLocation1.setLocation(new CtfLocationData(1, 0));
+    public void testEquals_other() throws CTFReaderException {
+        CtfIterator obj = new CtfIterator(trace);
+        CtfLocation ctfLocation1 = new CtfLocation(new CtfLocationInfo(1, 0));
         obj.setLocation(ctfLocation1);
         obj.increaseRank();
 
-        boolean result = fixture.equals(obj);
+        boolean result = iterator.equals(obj);
         assertTrue(result);
     }
 
@@ -180,7 +157,7 @@ public class CtfIteratorTest {
     @Test
     public void testEquals_empty() {
         Object obj = new Object();
-        boolean result = fixture.equals(obj);
+        boolean result = iterator.equals(obj);
 
         assertFalse(result);
     }
@@ -190,7 +167,7 @@ public class CtfIteratorTest {
      */
     @Test
     public void testGetCtfTmfTrace() {
-        CtfTmfTrace result = fixture.getCtfTmfTrace();
+        CtfTmfTrace result = iterator.getCtfTmfTrace();
         assertNotNull(result);
     }
 
@@ -199,7 +176,7 @@ public class CtfIteratorTest {
      */
     @Test
     public void testGetCurrentEvent() {
-        CtfTmfEvent result = fixture.getCurrentEvent();
+        CtfTmfEvent result = iterator.getCurrentEvent();
         assertNotNull(result);
     }
 
@@ -208,7 +185,7 @@ public class CtfIteratorTest {
      */
     @Test
     public void testGetLocation() {
-        CtfLocation result = fixture.getLocation();
+        CtfLocation result = iterator.getLocation();
         assertNotNull(result);
     }
 
@@ -217,7 +194,7 @@ public class CtfIteratorTest {
      */
     @Test
     public void testGetRank() {
-        long result = fixture.getRank();
+        long result = iterator.getRank();
         assertEquals(1L, result);
     }
 
@@ -226,7 +203,7 @@ public class CtfIteratorTest {
      */
     @Test
     public void testHasValidRank() {
-        boolean result = fixture.hasValidRank();
+        boolean result = iterator.hasValidRank();
         assertTrue(result);
     }
 
@@ -235,8 +212,8 @@ public class CtfIteratorTest {
      */
     @Test
     public void testHashCode() {
-        int result = fixture.hashCode();
-        int result2 = fixture.hashCode();
+        int result = iterator.hashCode();
+        int result2 = iterator.hashCode();
         assertEquals(result, result2);
     }
 
@@ -245,7 +222,7 @@ public class CtfIteratorTest {
      */
     @Test
     public void testIncreaseRank() {
-        fixture.increaseRank();
+        iterator.increaseRank();
     }
 
     /**
@@ -254,7 +231,7 @@ public class CtfIteratorTest {
     @Test
     public void testSeek() {
         long timestamp = 1L;
-        boolean result = fixture.seek(timestamp);
+        boolean result = iterator.seek(timestamp);
         assertTrue(result);
     }
 
@@ -263,8 +240,7 @@ public class CtfIteratorTest {
      */
     @Test
     public void testSetLocation() {
-        CtfLocation location = new CtfLocation(new CtfLocationData(1, 0));
-        location.setLocation(new CtfLocationData(1, 0));
-        fixture.setLocation(location);
+        CtfLocation location = new CtfLocation(new CtfLocationInfo(1, 0));
+        iterator.setLocation(location);
     }
 }
This page took 0.03168 seconds and 5 git commands to generate.