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 cbee082c995d1544d00a9da6ae50d8153b8f385e..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,62 +16,47 @@ 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 java.nio.channels.FileChannel;
-
-import org.eclipse.linuxtools.ctf.core.event.EventDeclaration;
 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.StreamInput;
-import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
-import org.junit.After;
+import org.eclipse.linuxtools.ctf.core.trace.CTFStream;
+import org.eclipse.linuxtools.internal.ctf.core.event.EventDeclaration;
 import org.junit.Before;
 import org.junit.Test;
 
 /**
  * The class <code>EventDeclarationTest</code> contains tests for the class
  * <code>{@link EventDeclaration}</code>.
- * 
+ *
  * @author ematkho
  * @version $Revision: 1.0 $
  */
+@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.
+     *
+     * @throws CTFReaderException
      */
     @Before
-    public void setUp() {
+    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("");
     }
 
     /**
@@ -92,30 +88,19 @@ public class EventDeclarationTest {
         assertFalse(result);
     }
 
-    /**
-     * Run the EventDefinition createDefinition(StreamInputReader) method test.
-     */
-    @Test
-    public void testCreateDefinition() {
-        StreamInputReader streamInputReader = new StreamInputReader(
-                new StreamInput(new Stream(TestParams.createTrace()),
-                        (FileChannel) null, TestParams.getEmptyFile()));
-
-        EventDefinition result = fixture.createDefinition(streamInputReader);
-        assertNotNull(result);
-    }
-
     /**
      * Run the boolean equals(Object) method test.
+     *
+     * @throws CTFReaderException
      */
     @Test
-    public void testEquals() {
+    public void testEquals() throws CTFReaderException {
         EventDeclaration obj = new EventDeclaration();
         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);
@@ -192,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);
@@ -232,8 +217,7 @@ public class EventDeclarationTest {
      */
     @Test
     public void testGetId() {
-        Long result = fixture.getId();
-        assertNotNull(result);
+        assertEquals(1,fixture.id());
     }
 
     /**
@@ -250,7 +234,7 @@ public class EventDeclarationTest {
      */
     @Test
     public void testGetStream() {
-        Stream result = fixture.getStream();
+        CTFStream result = fixture.getStream();
         assertNotNull(result);
     }
 
@@ -268,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();
@@ -318,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);
@@ -326,29 +310,66 @@ public class EventDeclarationTest {
 
     /**
      * Test for the EventDefinition class
+     *
+     * @throws CTFReaderException
      */
     @Test
-    public void testEventDefinition() {
-        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.context = ed.getFields();
-        assertNotNull(ed.toString());
+    public void testEventDefinition() throws CTFReaderException {
+        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;
+    EventDeclaration e2;
 
+
+    @Test
+    public void testEquals1(){
+        e1 = new EventDeclaration();
+        assertFalse(e1.equals(null));
+    }
+
+    @Test
+    public void testEquals2(){
+        e1 = EventDeclaration.getLostEventDeclaration();
+        assertFalse(e1.equals(new Long(23L)));
+    }
+
+    @Test
+    public void testEquals3(){
+        e1 = EventDeclaration.getLostEventDeclaration();
+        assertEquals(e1,e1);
+    }
+
+    @Test
+    public void testEquals4(){
+        e1 = EventDeclaration.getLostEventDeclaration();
+        e2 = EventDeclaration.getLostEventDeclaration();
+        assertEquals(e1,e2);
+    }
+
+    @Test
+    public void testEquals5(){
+        e1 = EventDeclaration.getLostEventDeclaration();
+        e2 = new EventDeclaration();
+        assertFalse(e1.equals(e2));
     }
 }
This page took 0.029446 seconds and 5 git commands to generate.