tmf: Re-enable the unit tests depending on CTF traces
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / ctfadaptor / CtfTmfEventTest.java
index abe4256972ca42ec00ff5cf09efa362b2f182865..1e55fedaf1426eedd12b6fe0d6c138f1cbd401a8 100644 (file)
@@ -17,17 +17,21 @@ import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assume.assumeTrue;
 
 import java.util.Set;
 
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
+import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEventFactory;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEventType;
-import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
-import org.junit.After;
+import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTraces;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 /**
@@ -39,40 +43,31 @@ import org.junit.Test;
  */
 public class CtfTmfEventTest {
 
+    private static final int TRACE_INDEX = 0;
+
+    private static CtfTmfEvent nullEvent;
     private CtfTmfEvent fixture;
 
     /**
-     * Launch the test.
-     *
-     * @param args
-     *            the command line arguments
+     * Test class initialization
      */
-    public static void main(String[] args) {
-        new org.junit.runner.JUnitCore().run(CtfTmfEventTest.class);
+    @BeforeClass
+    public static void initialize() {
+        nullEvent = CtfTmfEventFactory.getNullEvent();
     }
 
     /**
      * Perform pre-test initialization.
-     *
-     * @throws TmfTraceException
-     *             If the test trace is not found
      */
     @Before
-    public void setUp() throws TmfTraceException {
-        CtfTmfTrace trace = TestParams.createTrace();
+    public void setUp() {
+        assumeTrue(CtfTmfTestTraces.tracesExist());
+        CtfTmfTrace trace = CtfTmfTestTraces.getTestTrace(TRACE_INDEX);
         CtfIterator tr = new CtfIterator(trace);
         tr.advance();
         fixture = tr.getCurrentEvent();
     }
 
-    /**
-     * Perform post-test clean-up.
-     */
-    @After
-    public void tearDown() {
-        // Add additional tear down code here
-    }
-
     /**
      * Run the CTFEvent(EventDefinition,StreamInputReader) constructor test.
      */
@@ -86,31 +81,16 @@ public class CtfTmfEventTest {
      */
     @Test
     public void testGetCPU() {
-        CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
         int result = nullEvent.getCPU();
-
         assertEquals(-1, result);
     }
 
-    /**
-     * Run the String getChannelName() method test.
-     */
-    @Test
-    public void testGetChannelName() {
-        CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
-        String result = nullEvent.getChannelName();
-
-        assertEquals("No stream", result); //$NON-NLS-1$
-    }
-
     /**
      * Run the String getEventName() method test.
      */
     @Test
     public void testGetEventName() {
-        CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
         String result = nullEvent.getEventName();
-
         assertEquals("Empty CTF event", result); //$NON-NLS-1$
     }
 
@@ -140,7 +120,6 @@ public class CtfTmfEventTest {
      */
     @Test
     public void testGetFields() {
-        CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
         ITmfEventField[] fields = nullEvent.getContent().getFields();
         ITmfEventField[] fields2 = new ITmfEventField[0];
         assertArrayEquals(fields2, fields);
@@ -151,66 +130,34 @@ public class CtfTmfEventTest {
      */
     @Test
     public void testGetID() {
-        CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
         long result = nullEvent.getID();
-
         assertEquals(-1L, result);
     }
 
-    /**
-     * Test the clone method
-     */
-    @Test
-    public void testClone() {
-        CtfTmfEvent other = CtfTmfEvent.getNullEvent().clone();
-        assertNotNull(other);
-    }
-
-    /**
-     * Run the CTFEvent getNullEvent() method test.
-     */
-    @Test
-    public void testGetNullEvent() {
-        CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
-
-        assertNotNull(nullEvent);
-        assertEquals(-1, nullEvent.getCPU());
-        assertEquals("Empty CTF event", nullEvent.getEventName()); //$NON-NLS-1$
-        assertEquals("No stream", nullEvent.getChannelName()); //$NON-NLS-1$
-        assertArrayEquals(new ITmfEventField[0], nullEvent.getContent().getFields());
-        assertEquals(-1L, nullEvent.getID());
-        assertEquals(-1L, nullEvent.getTimestamp().getValue());
-    }
-
     /**
      * Run the long getTimestamp() method test.
-     *
      */
     @Test
     public void testGetTimestamp() {
-        CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
         long result = nullEvent.getTimestamp().getValue();
-
         assertEquals(-1L, result);
     }
 
     /**
-     * Test the getters for the channel name, reference, source and type.
+     * Test the getters for the reference, source and type.
      */
     @Test
     public void testGetters() {
         long rank = fixture.getRank();
         CtfTmfTrace trace = fixture.getTrace();
-        String channelName = fixture.getChannelName();
         String reference = fixture.getReference();
         String source = fixture.getSource();
         ITmfEventType type = fixture.getType();
-        assertEquals(rank, 0);
-        assertEquals(trace.getName(), "test"); //$NON-NLS-1$
-        assertEquals(channelName, "channel0_1"); //$NON-NLS-1$
-        assertEquals(reference,"channel0_1"); //$NON-NLS-1$
-        assertEquals(source, "1"); //$NON-NLS-1$
-        assertEquals(type.toString(), "lttng_statedump_vm_map"); //$NON-NLS-1$
+        assertEquals(ITmfContext.UNKNOWN_RANK, rank);
+        assertEquals("test", trace.getName()); //$NON-NLS-1$
+        assertEquals("channel0_1", reference); //$NON-NLS-1$
+        assertEquals("1", source); //$NON-NLS-1$
+        assertEquals("lttng_statedump_vm_map", type.toString()); //$NON-NLS-1$
     }
 
     /**
@@ -234,4 +181,21 @@ public class CtfTmfEventTest {
         String s = fixture.getContent().toString();
         assertEquals("pid=1922, inode=917738, flags=0x8000075, end=0xb73ec000, start=0xb73ea000, pgoff=0", s); //$NON-NLS-1$
     }
+
+    /**
+     * Test the {@link CtfTmfEventFactory#getNullEvent()} method, and the
+     * nullEvent's values.
+     */
+    @Test
+    public void testNullEvent() {
+        CtfTmfEvent nullEvent2 = CtfTmfEventFactory.getNullEvent();
+        assertSame(nullEvent2, nullEvent);
+        assertNotNull(nullEvent);
+        assertEquals(-1, nullEvent.getCPU());
+        assertEquals("Empty CTF event", nullEvent.getEventName()); //$NON-NLS-1$
+        assertEquals("No stream", nullEvent.getReference()); //$NON-NLS-1$
+        assertArrayEquals(new ITmfEventField[0], nullEvent.getContent().getFields());
+        assertEquals(-1L, nullEvent.getID());
+        assertEquals(-1L, nullEvent.getTimestamp().getValue());
+    }
 }
This page took 0.026839 seconds and 5 git commands to generate.