ctf: replace HashMaps with ArrayLists for EventDeclaration storage
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / types / EventDeclarationTest.java
index 3b680003842759a7dfdadcfe393f6296a0d2e4d1..ddb000ded041ef9ebb9cc208cc89eff044a10194 100644 (file)
@@ -1,3 +1,14 @@
+/*******************************************************************************
+ * Copyright (c) 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 accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
 package org.eclipse.linuxtools.ctf.core.tests.types;
 
 import static org.junit.Assert.assertEquals;
@@ -5,16 +16,16 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
 
 import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
-import org.eclipse.linuxtools.ctf.core.tests.TestParams;
+import org.eclipse.linuxtools.ctf.core.tests.shared.CtfTestTrace;
 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
 import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader;
-import org.eclipse.linuxtools.ctf.core.trace.Stream;
+import org.eclipse.linuxtools.ctf.core.trace.CTFStream;
 import org.eclipse.linuxtools.internal.ctf.core.event.EventDeclaration;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -28,17 +39,9 @@ import org.junit.Test;
 @SuppressWarnings("javadoc")
 public class EventDeclarationTest {
 
-    private EventDeclaration fixture;
+    private static final CtfTestTrace testTrace = CtfTestTrace.KERNEL;
 
-    /**
-     * Launch the test.
-     *
-     * @param args
-     *            the command line arguments
-     */
-    public static void main(String[] args) {
-        new org.junit.runner.JUnitCore().run(EventDeclarationTest.class);
-    }
+    private EventDeclaration fixture;
 
     /**
      * Perform pre-test initialization.
@@ -47,20 +50,13 @@ public class EventDeclarationTest {
      */
     @Before
     public void setUp() throws CTFReaderException {
+        assumeTrue(testTrace.exists());
         fixture = new EventDeclaration();
         fixture.setContext(new StructDeclaration(1L));
         fixture.setId(1L);
         fixture.setFields(new StructDeclaration(1L));
-        fixture.setStream(new Stream(TestParams.createTrace()));
-        fixture.setName(""); //$NON-NLS-1$
-    }
-
-    /**
-     * Perform post-test clean-up.
-     */
-    @After
-    public void tearDown() {
-        // Add additional tear down code here
+        fixture.setStream(new CTFStream(testTrace.getTrace()));
+        fixture.setName("");
     }
 
     /**
@@ -103,8 +99,8 @@ public class EventDeclarationTest {
         obj.setContext(new StructDeclaration(1L));
         obj.setId(1L);
         obj.setFields(new StructDeclaration(1L));
-        obj.setStream(new Stream(TestParams.createTrace()));
-        obj.setName(""); //$NON-NLS-1$
+        obj.setStream(new CTFStream(testTrace.getTrace()));
+        obj.setName("");
 
         assertTrue(fixture.equals(fixture));
         boolean result = fixture.equals(obj);
@@ -181,7 +177,7 @@ public class EventDeclarationTest {
         obj.setContext(new StructDeclaration(1L));
         obj.setId(1L);
         obj.setFields(new StructDeclaration(1L));
-        obj.setName(""); //$NON-NLS-1$
+        obj.setName("");
 
         boolean result = fixture.equals(obj);
         assertFalse(result);
@@ -221,8 +217,7 @@ public class EventDeclarationTest {
      */
     @Test
     public void testGetId() {
-        Long result = fixture.getId();
-        assertNotNull(result);
+        assertEquals(1,fixture.id());
     }
 
     /**
@@ -239,7 +234,7 @@ public class EventDeclarationTest {
      */
     @Test
     public void testGetStream() {
-        Stream result = fixture.getStream();
+        CTFStream result = fixture.getStream();
         assertNotNull(result);
     }
 
@@ -257,7 +252,7 @@ public class EventDeclarationTest {
      */
     @Test
     public void testHashCode_null() {
-        fixture.setStream((Stream) null);
+        fixture.setStream((CTFStream) null);
         fixture.setName((String) null);
 
         int result = fixture.hashCode();
@@ -307,7 +302,7 @@ public class EventDeclarationTest {
      */
     @Test
     public void testStreamIsSet_null() {
-        fixture.setStream((Stream) null);
+        fixture.setStream((CTFStream) null);
 
         boolean result = fixture.streamIsSet();
         assertEquals(false, result);
@@ -320,26 +315,26 @@ public class EventDeclarationTest {
      */
     @Test
     public void testEventDefinition() throws CTFReaderException {
-        CTFTrace trace = TestParams.createTrace();
-        CTFTraceReader tr = new CTFTraceReader(trace);
-        tr.advance();
-        EventDefinition ed = new EventDefinition(null, null);
-        ed = tr.getCurrentEventDef();
-        assertNotNull(ed);
-        assertNotNull(ed.getPath());
-        assertNotNull(ed.getDeclaration());
-        assertNotNull(ed.getFields());
-        assertNull(ed.getContext());
-        assertNotNull(ed.getPacketContext());
-        assertNotNull(ed.getCPU());
-        assertNotNull(ed.getPacketContext());
-        assertNotNull(ed.getStreamInputReader());
-        assertNull(ed.lookupDefinition("context")); //$NON-NLS-1$
-        assertNotNull(ed.lookupDefinition("fields")); //$NON-NLS-1$
-        assertNull(ed.lookupDefinition("other")); //$NON-NLS-1$
-        assertNotNull(ed.toString());
-        ed.setContext( ed.getFields());
-        assertNotNull(ed.toString());
+        try (CTFTrace trace = testTrace.getTrace();) {
+            EventDefinition ed = null;
+            try (CTFTraceReader tr = new CTFTraceReader(trace);) {
+                tr.advance();
+                ed = tr.getCurrentEventDef();
+            }
+
+            assertNotNull(ed);
+            assertNotNull(ed.getScopePath());
+            assertNotNull(ed.getDeclaration());
+            assertNotNull(ed.getFields());
+            assertNull(ed.getContext());
+            assertNotNull(ed.getPacketContext());
+            assertNotNull(ed.getCPU());
+            assertNotNull(ed.getStreamInputReader());
+            assertNull(ed.lookupDefinition("context"));
+            assertNotNull(ed.lookupDefinition("fields"));
+            assertNull(ed.lookupDefinition("other"));
+            assertNotNull(ed.toString());
+        }
     }
 
     EventDeclaration e1;
This page took 0.026254 seconds and 5 git commands to generate.