Improve test cases, speed and accuracy.
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Wed, 2 May 2012 19:58:20 +0000 (15:58 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Wed, 2 May 2012 20:32:35 +0000 (16:32 -0400)
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/TestParams.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceReaderTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinitionTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EventDeclarationTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/IntegerDefinitionTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDefinitionTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StringDefinitionTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StructDefinitionTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/VariantDefinitionTest.java

index 5f2f9c6760264ef504a4b0c792917dbdc743679a..ede840ab360d93cb800de45002046b445b107ee4 100644 (file)
@@ -20,6 +20,7 @@ public abstract class TestParams {
     private static final String testTracePath1 = "traces/kernel"; //$NON-NLS-1$
     private static CTFTrace testTrace1 = null;
     private static CTFTrace testTraceFromFile1 = null;
+    private static final File testTraceFile1 = new File(testTracePath1);
 
     private static final File emptyFile = new File(""); //$NON-NLS-1$
     private static CTFTrace emptyTrace = null;
@@ -28,6 +29,9 @@ public abstract class TestParams {
         return emptyFile;
     }
 
+    public static File getTraceFile(){
+        return testTraceFile1;
+    }
     public static CTFTrace getEmptyTrace() {
         if (emptyTrace == null) {
             try {
index 1e7f7b6b490a12fe3190279cdd40f03dc78ee2e1..81a3af5edbb4cbf1550d557be504ba5ba1b03e0d 100644 (file)
@@ -303,13 +303,25 @@ public class CTFTraceReaderTest {
             fixture.advance();
         }
         boolean result= fixture.seekIndex(0);
+
         third = getTimestamp();
         boolean result2 = fixture.seekIndex(rank);
         fourth = getTimestamp();
-        assertTrue(result);
-        assertTrue(result2);
-        assertEquals( first , third);
-        assertEquals( second , fourth);
+        /*
+         * in blocks to see where code coverage fails
+         */
+        {
+            assertTrue(result);
+        }
+        {
+            assertTrue(result2);
+        }
+        {
+            assertEquals( first , third);
+        }
+        {
+            assertEquals( second , fourth);
+        }
     }
 
     /**
index 906f1b571fefefd3382ee368b8573c4e0b4aa7a3..6f85b9af8854377e8d5ab35a7a0cb58e29642acc 100644 (file)
@@ -17,7 +17,6 @@ import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
-import org.eclipse.linuxtools.ctf.core.tests.TestParams;
 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
 import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer;
@@ -59,8 +58,6 @@ public class ArrayDefinitionTest {
      */
     @Before
     public void setUp() throws CTFReaderException {
-        this.trace = TestParams.createTrace();
-
         charArrayFixture = createCharArray();
         stringArrayFixture = createStringArray();
         longArrayFixture = createLongArray();
index 2c796beca2b1655883511e3b4664ce8014e4892f..af3cd0a7dc93611dbe2e27f993aaff203b3f6521 100644 (file)
@@ -25,7 +25,7 @@ import org.junit.Test;
 /**
  * The class <code>EventDeclarationTest</code> contains tests for the class
  * <code>{@link EventDeclaration}</code>.
- * 
+ *
  * @author ematkho
  * @version $Revision: 1.0 $
  */
@@ -35,7 +35,7 @@ public class EventDeclarationTest {
 
     /**
      * Launch the test.
-     * 
+     *
      * @param args
      *            the command line arguments
      */
@@ -45,8 +45,8 @@ public class EventDeclarationTest {
 
     /**
      * Perform pre-test initialization.
-     * 
-     * @throws CTFReaderException 
+     *
+     * @throws CTFReaderException
      */
     @Before
     public void setUp() throws CTFReaderException {
@@ -97,14 +97,14 @@ public class EventDeclarationTest {
 
     /**
      * Run the EventDefinition createDefinition(StreamInputReader) method test.
-     * 
-     * @throws CTFReaderException 
+     *
+     * @throws CTFReaderException
      */
     @Test
     public void testCreateDefinition() throws CTFReaderException {
         StreamInputReader streamInputReader = new StreamInputReader(
                 new StreamInput(new Stream(TestParams.createTrace()),
-                        (FileChannel) null, TestParams.getEmptyFile()));
+                        (FileChannel) null, TestParams.getTraceFile()));
 
         EventDefinition result = fixture.createDefinition(streamInputReader);
         assertNotNull(result);
@@ -112,8 +112,8 @@ public class EventDeclarationTest {
 
     /**
      * Run the boolean equals(Object) method test.
-     * 
-     * @throws CTFReaderException 
+     *
+     * @throws CTFReaderException
      */
     @Test
     public void testEquals() throws CTFReaderException {
@@ -333,8 +333,8 @@ public class EventDeclarationTest {
 
     /**
      * Test for the EventDefinition class
-     * 
-     * @throws CTFReaderException 
+     *
+     * @throws CTFReaderException
      */
     @Test
     public void testEventDefinition() throws CTFReaderException {
index 2915e2755e18f319d1936f4269094bb39e432d85..64d328d5bfdd0157cbcb239e9c78f9a70810bd8f 100644 (file)
@@ -5,17 +5,12 @@ import static org.junit.Assert.assertNotNull;
 
 import java.nio.ByteOrder;
 
-import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.Definition;
 import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
 import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope;
 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
-import org.eclipse.linuxtools.ctf.core.tests.TestParams;
 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.internal.ctf.core.event.io.BitBuffer;
 import org.junit.After;
 import org.junit.Before;
@@ -31,7 +26,8 @@ import org.junit.Test;
 public class IntegerDefinitionTest {
 
     private IntegerDefinition fixture;
-
+    String name = "testInt"; //$NON-NLS-1$
+    String clockName = "clock"; //$NON-NLS-1$
     /**
      * Launch the test.
      *
@@ -50,27 +46,11 @@ public class IntegerDefinitionTest {
      */
     @Before
     public void setUp() throws CTFReaderException {
-        CTFTrace trace = TestParams.createTrace();
-        CTFTraceReader tr = new CTFTraceReader(trace);
-        String name = ""; //$NON-NLS-1$
+
         StructDefinition structDef = null;
         boolean found = false;
-
-        while (tr.hasMoreEvents() && !found) {
-            tr.advance();
-            EventDefinition ed = tr.getCurrentEventDef();
-            for (String key : ed.fields.getDefinitions().keySet()) {
-                structDef = ed.fields;
-                Definition d = structDef.lookupDefinition(key);
-                if (d instanceof IntegerDefinition) {
-                    found = true;
-                    name = key;
-                    break;
-                }
-            }
-        }
-        assert (structDef != null);
-        fixture = structDef.lookupInteger(name);
+        IntegerDeclaration id = new IntegerDeclaration( 1, true, 1, ByteOrder.BIG_ENDIAN, Encoding.NONE, clockName, 8);
+        fixture = id.createDefinition(null, name);
     }
 
     /**
index 5cf9b92887da3c149cae9f226345df628c342a67..14b8f950dcef483667a618ec7ad8d4d4afe05c9f 100644 (file)
@@ -172,8 +172,8 @@ public class SequenceDefinitionTest {
      */
     @Test
     public void testToString_nonString() throws Exception {
-        SequenceDefinition nonStringFixture = initNonString();
-        String result = nonStringFixture.toString();
+        fixture = initNonString();
+        String result = fixture.toString();
         assertNotNull(result);
     }
 }
index fbfd03b3e15f598c84f6eb7b788f9ce3b67db310..3ef00b8c5438e2269d198808f8294270ae018ba3 100644 (file)
@@ -2,18 +2,11 @@ package org.eclipse.linuxtools.ctf.core.tests.types;
 
 import static org.junit.Assert.assertNotNull;
 
-import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.Definition;
 import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope;
 import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
-import org.eclipse.linuxtools.ctf.core.tests.TestParams;
 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.internal.ctf.core.event.io.BitBuffer;
-
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -21,7 +14,7 @@ import org.junit.Test;
 /**
  * The class <code>StringDefinitionTest</code> contains tests for the class
  * <code>{@link StringDefinition}</code>.
- * 
+ *
  * @author ematkho
  * @version $Revision: 1.0 $
  */
@@ -31,7 +24,7 @@ public class StringDefinitionTest {
 
     /**
      * Launch the test.
-     * 
+     *
      * @param args
      *            the command line arguments
      */
@@ -41,31 +34,14 @@ public class StringDefinitionTest {
 
     /**
      * Perform pre-test initialization.
-     * 
-     * @throws CTFReaderException 
+     *
+     * @throws CTFReaderException
      */
     @Before
     public void setUp() throws CTFReaderException {
-        CTFTrace trace = TestParams.createTrace();
-        CTFTraceReader tr = new CTFTraceReader(trace);
-        String name = ""; //$NON-NLS-1$
-        StructDefinition structDef = null;
-        boolean found = false;
-
-        while (tr.hasMoreEvents() && !found) {
-            tr.advance();
-            EventDefinition ed = tr.getCurrentEventDef();
-            for (String key : ed.fields.getDefinitions().keySet()) {
-                structDef = ed.fields;
-                Definition d = structDef.lookupDefinition(key);
-                if (d instanceof StringDefinition) {
-                    found = true;
-                    name = key;
-                    break;
-                }
-            }
-        }
-        fixture = structDef.lookupString(name);
+        String name = "testString"; //$NON-NLS-1$
+        StringDeclaration stringDec = new StringDeclaration();
+        fixture = stringDec.createDefinition(null, name);
     }
 
     /**
index 2ab82a028558e89732d83bc2b72c8925c93b7949..b2a412411c2aeb3828e1846dd32596aa5ad290f8 100644 (file)
@@ -4,22 +4,25 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 
 import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
 import java.util.HashMap;
 
-import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.Definition;
+import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
+import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.EnumDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.SequenceDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.SequenceDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.VariantDefinition;
-import org.eclipse.linuxtools.ctf.core.tests.TestParams;
 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.internal.ctf.core.event.io.BitBuffer;
 import org.junit.After;
 import org.junit.Before;
@@ -34,6 +37,24 @@ import org.junit.Test;
  */
 public class StructDefinitionTest {
 
+    private static final String TEST_STRUCT_ID = "testStruct"; //$NON-NLS-1$
+
+    private static final String ENUM_2 = "y"; //$NON-NLS-1$
+
+    private static final String ENUM_1 = "x"; //$NON-NLS-1$
+
+    private static final String TAG_ID = "Tag"; //$NON-NLS-1$
+
+    private static final String INT_ID = "_id"; //$NON-NLS-1$
+
+    private static final String STRING_ID = "_args"; //$NON-NLS-1$
+
+    private static final String ENUM_ID = "_enumArgs"; //$NON-NLS-1$
+
+    private static final String SEQUENCE_ID = "_seq"; //$NON-NLS-1$
+
+    private static final String LENGTH_SEQ = "_len"; //$NON-NLS-1$
+
     private StructDefinition fixture;
 
     private static final String VAR_FIELD_NAME = "SomeVariant"; //$NON-NLS-1$
@@ -55,10 +76,31 @@ public class StructDefinitionTest {
      */
     @Before
     public void setUp() throws CTFReaderException {
-        CTFTrace c = TestParams.createTrace();
-        CTFTraceReader tr = new CTFTraceReader(c);
-        EventDefinition ed = tr.getCurrentEventDef();
-        fixture = ed.fields;
+        StructDeclaration sDec = new StructDeclaration(12);
+        IntegerDeclaration id = new IntegerDeclaration(32, false, 32, ByteOrder.BIG_ENDIAN, Encoding.NONE, null, 8);
+        IntegerDeclaration lenDec = new IntegerDeclaration(8, false, 8, ByteOrder.BIG_ENDIAN, Encoding.NONE, null, 8);
+        StringDeclaration sd = new StringDeclaration();
+        EnumDeclaration ed = new EnumDeclaration(id);
+        SequenceDeclaration seqDec = new SequenceDeclaration(LENGTH_SEQ, id);
+        VariantDeclaration varDec = new VariantDeclaration();
+        EnumDeclaration tagDec = new EnumDeclaration(id);
+        tagDec.add(0, 1, ENUM_1);
+        tagDec.add(2, 3, ENUM_2);
+        varDec.addField(ENUM_2, id);
+        varDec.addField(ENUM_1, sd);
+        varDec.setTag(TAG_ID);
+        sDec.addField(INT_ID, id);
+        sDec.addField(STRING_ID, sd);
+        sDec.addField(ENUM_ID, ed);
+        sDec.addField(TAG_ID, tagDec);
+        sDec.addField(LENGTH_SEQ, lenDec);
+        sDec.addField(SEQUENCE_ID, seqDec);
+        sDec.addField(VAR_FIELD_NAME, varDec);
+        fixture = sDec.createDefinition(null, TEST_STRUCT_ID);
+        EnumDefinition eDef = tagDec.createDefinition(fixture, TAG_ID);
+        VariantDefinition vd = varDec.createDefinition(fixture,VAR_FIELD_NAME );
+        vd.setTagDefinition(eDef);
+
     }
 
     /**
@@ -92,7 +134,7 @@ public class StructDefinitionTest {
      */
     @Test
     public void testLookupArray() {
-        String name = "id"; //$NON-NLS-1$
+        String name = INT_ID;
         ArrayDefinition result = fixture.lookupArray(name);
 
         assertNull(result);
@@ -114,11 +156,9 @@ public class StructDefinitionTest {
      */
     @Test
     public void testLookupEnum() {
-        String name = ""; //$NON-NLS-1$
+        String name = ENUM_ID;
         EnumDefinition result = fixture.lookupEnum(name);
-
-        /* There are no enums in the test trace */
-        assertNull(result);
+        assertNotNull(result);
     }
 
     /**
@@ -126,9 +166,8 @@ public class StructDefinitionTest {
      */
     @Test
     public void testLookupInteger_1() {
-        String name = "_args"; //$NON-NLS-1$
+        String name = "_id"; //$NON-NLS-1$
         IntegerDefinition result = fixture.lookupInteger(name);
-
         assertNotNull(result);
     }
 
@@ -139,7 +178,6 @@ public class StructDefinitionTest {
     public void testLookupInteger_2() {
         String name = VAR_FIELD_NAME;
         IntegerDefinition result = fixture.lookupInteger(name);
-
         assertNull(result);
     }
 
@@ -148,10 +186,9 @@ public class StructDefinitionTest {
      */
     @Test
     public void testLookupSequence() {
-        String name = VAR_FIELD_NAME;
+        String name = SEQUENCE_ID;
         SequenceDefinition result = fixture.lookupSequence(name);
-
-        assertNull(result);
+        assertNotNull(result);
     }
 
     /**
@@ -184,7 +221,7 @@ public class StructDefinitionTest {
         String name = VAR_FIELD_NAME;
         VariantDefinition result = fixture.lookupVariant(name);
 
-        assertNull(result);
+        assertNotNull(result);
     }
 
     /**
index cf2eb5d9c613d95a19de9fc199894efe409857c5..1b8a11c90552c5e4c13b7f7648ac5020b76a34be 100644 (file)
@@ -6,21 +6,23 @@ import static org.junit.Assert.assertNull;
 import java.nio.ByteOrder;
 import java.util.HashMap;
 
+import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.Definition;
 import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
 import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.EnumDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.FloatDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope;
 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.SequenceDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.VariantDefinition;
-import org.eclipse.linuxtools.ctf.core.tests.TestParams;
 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 import org.junit.After;
 import org.junit.Before;
@@ -46,7 +48,30 @@ public class VariantDefinitionTest {
     public static void main(String[] args) {
         new org.junit.runner.JUnitCore().run(VariantDefinitionTest.class);
     }
+    StructDefinition structDefinition;
+    private static final String TEST_STRUCT_ID = "testStruct"; //$NON-NLS-1$
 
+    private static final String ENUM_7 = "g"; //$NON-NLS-1$
+    private static final String ENUM_6 = "f"; //$NON-NLS-1$
+    private static final String ENUM_5 = "e"; //$NON-NLS-1$
+    private static final String ENUM_4 = "d"; //$NON-NLS-1$
+    private static final String ENUM_3 = "c"; //$NON-NLS-1$
+    private static final String ENUM_2 = "b"; //$NON-NLS-1$
+    private static final String ENUM_1 = "a"; //$NON-NLS-1$
+
+    private static final String TAG_ID = "a"; //$NON-NLS-1$
+
+    private static final String INT_ID = "_id"; //$NON-NLS-1$
+
+    private static final String STRING_ID = "_args"; //$NON-NLS-1$
+
+    private static final String ENUM_ID = "_enumArgs"; //$NON-NLS-1$
+
+    private static final String SEQUENCE_ID = "_seq"; //$NON-NLS-1$
+
+    private static final String LENGTH_SEQ = "_len"; //$NON-NLS-1$
+    private static final String VAR_FIELD_NAME = "var";
+    private static final String ENUM_8 = null;
     /**
      * Perform pre-test initialization.
      *
@@ -55,32 +80,47 @@ public class VariantDefinitionTest {
      * @throws CTFReaderException
      */
     @Before
-    public void setUp() throws CTFReaderException {
-        VariantDeclaration vDecl1, vDecl2, vDecl3;
-        VariantDefinition vDef1, vDef2;
-        StructDefinition sDef1, sDef2;
-        EnumDefinition eDef;
-        String fName = ""; //$NON-NLS-1$
-
-        vDecl1 = new VariantDeclaration();
-        vDecl2 = new VariantDeclaration();
-        vDecl3 = new VariantDeclaration();
-        vDecl1.setTag(fName);
-        vDecl2.setTag(fName);
-        vDecl3.setTag(fName);
-
-        vDef1 = new VariantDefinition(vDecl2, TestParams.createTrace(), fName);
-        vDef2 = new VariantDefinition(vDecl3, TestParams.createTrace(), fName);
-
-        sDef1 = new StructDefinition(new StructDeclaration(1L), vDef1, fName);
-        sDef2 = new StructDefinition(new StructDeclaration(1L), vDef2, fName);
-
-        eDef = new EnumDefinition(new EnumDeclaration(new IntegerDeclaration(1,
-                true, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, fName, 8)), sDef2, fName);
-
-        fixture = new VariantDefinition(vDecl1, sDef1, fName);
+    public void setUp() {
+        StructDeclaration sDec = new StructDeclaration(12);
+        StructDeclaration smallStruct = new StructDeclaration(8);
+        IntegerDeclaration iDec = new IntegerDeclaration(32, false, 32, ByteOrder.BIG_ENDIAN, Encoding.NONE, null, 8);
+        IntegerDeclaration lenDec = new IntegerDeclaration(8, false, 8, ByteOrder.BIG_ENDIAN, Encoding.NONE, null, 8);
+        StringDeclaration strDec = new StringDeclaration();
+        EnumDeclaration enDec = new EnumDeclaration(iDec);
+//        SequenceDeclaration seqDec = new SequenceDeclaration(LENGTH_SEQ, iDec);
+        VariantDeclaration varDec = new VariantDeclaration();
+        EnumDeclaration tagDec = new EnumDeclaration(iDec);
+        ArrayDeclaration arrDec = new ArrayDeclaration(2, iDec);
+        FloatDeclaration fDec = new FloatDeclaration(8, 24, ByteOrder.BIG_ENDIAN, Encoding.NONE, 8);
+        tagDec.add(0, 1, ENUM_1);
+        tagDec.add(2, 3, ENUM_2);
+        tagDec.add(4, 5, ENUM_3);
+        //tagDec.add(6, 7, ENUM_4); // this should not work
+        tagDec.add(8, 9, ENUM_5);
+        tagDec.add(10, 11, ENUM_6);
+        tagDec.add(12, 13, ENUM_7);
+        varDec.addField(ENUM_4, lenDec);
+        varDec.addField(ENUM_7, fDec);
+        varDec.addField(ENUM_6, smallStruct);
+        varDec.addField(ENUM_5, enDec);
+        //varDec.addField(ENUM_4, seqDec);// this should not work
+        varDec.addField(ENUM_3, arrDec);
+        varDec.addField(ENUM_2, iDec);
+        varDec.addField(ENUM_1, strDec);
+
+        sDec.addField(TAG_ID, tagDec);
+        sDec.addField(LENGTH_SEQ, lenDec);
+//        sDec.addField(SEQUENCE_ID, seqDec);
+
+        sDec.addField(VAR_FIELD_NAME, varDec);
+        varDec.setTag(TAG_ID);
+
+        structDefinition = sDec.createDefinition(null, TEST_STRUCT_ID);
+
+        EnumDefinition eDef = tagDec.createDefinition(structDefinition, TAG_ID);
+        fixture = varDec.createDefinition(structDefinition,VAR_FIELD_NAME );
         fixture.setTagDefinition(eDef);
-        fixture.setCurrentField(fName);
+
     }
 
     /**
@@ -97,13 +137,13 @@ public class VariantDefinitionTest {
      * @throws CTFReaderException
      */
     @Test
-    public void testVariantDefinition() throws CTFReaderException {
+    public void testVariantDefinition() {
         VariantDeclaration declaration = new VariantDeclaration();
         declaration.setTag(""); //$NON-NLS-1$
         VariantDeclaration variantDeclaration = new VariantDeclaration();
         variantDeclaration.setTag(""); //$NON-NLS-1$
         VariantDefinition variantDefinition = new VariantDefinition(
-                variantDeclaration, TestParams.createTrace(), ""); //$NON-NLS-1$
+                variantDeclaration, structDefinition, ""); //$NON-NLS-1$
         IDefinitionScope definitionScope = new StructDefinition(
                 new StructDeclaration(1L), variantDefinition, ""); //$NON-NLS-1$
         String fieldName = ""; //$NON-NLS-1$
@@ -120,6 +160,9 @@ public class VariantDefinitionTest {
     public void testGetCurrentField() {
         Definition result = fixture.getCurrentField();
         assertNull(result);
+        fixture.setCurrentField(ENUM_1);
+        result = fixture.getCurrentField();
+        assertNotNull(result);
     }
 
     /**
@@ -127,6 +170,7 @@ public class VariantDefinitionTest {
      */
     @Test
     public void testGetCurrentFieldName() {
+        fixture.setCurrentField(ENUM_1);
         String result = fixture.getCurrentFieldName();
         assertNotNull(result);
     }
@@ -172,9 +216,8 @@ public class VariantDefinitionTest {
      */
     @Test
     public void testLookupArray() {
-        String name = ""; //$NON-NLS-1$
-        ArrayDefinition result = fixture.lookupArray(name);
-        assertNull(result);
+        ArrayDefinition result = fixture.lookupArray(ENUM_3);
+        assertNotNull(result);
     }
 
     /**
@@ -182,9 +225,8 @@ public class VariantDefinitionTest {
      */
     @Test
     public void testLookupDefinition() {
-        String lookupPath = ""; //$NON-NLS-1$
-        Definition result = fixture.lookupDefinition(lookupPath);
-        assertNull(result);
+        Definition result = fixture.lookupDefinition(ENUM_1);
+        assertNotNull(result);
     }
 
     /**
@@ -192,9 +234,8 @@ public class VariantDefinitionTest {
      */
     @Test
     public void testLookupEnum() {
-        String name = ""; //$NON-NLS-1$
-        EnumDefinition result = fixture.lookupEnum(name);
-        assertNull(result);
+        EnumDefinition result = fixture.lookupEnum(ENUM_5);
+        assertNotNull(result);
     }
 
     /**
@@ -202,9 +243,8 @@ public class VariantDefinitionTest {
      */
     @Test
     public void testLookupInteger() {
-        String name = ""; //$NON-NLS-1$
-        IntegerDefinition result = fixture.lookupInteger(name);
-        assertNull(result);
+        IntegerDefinition result = fixture.lookupInteger(ENUM_2);
+        assertNotNull(result);
     }
 
     /**
@@ -212,8 +252,7 @@ public class VariantDefinitionTest {
      */
     @Test
     public void testLookupSequence_1() {
-        String name = ""; //$NON-NLS-1$
-        SequenceDefinition result = fixture.lookupSequence(name);
+        SequenceDefinition result = fixture.lookupSequence(ENUM_4);
         assertNull(result);
     }
 
@@ -222,9 +261,8 @@ public class VariantDefinitionTest {
      */
     @Test
     public void testLookupString() {
-        String name = ""; //$NON-NLS-1$
-        StringDefinition result = fixture.lookupString(name);
-        assertNull(result);
+        StringDefinition result = fixture.lookupString(ENUM_1);
+        assertNotNull(result);
     }
 
     /**
@@ -232,9 +270,8 @@ public class VariantDefinitionTest {
      */
     @Test
     public void testLookupStruct() {
-        String name = ""; //$NON-NLS-1$
-        StructDefinition result = fixture.lookupStruct(name);
-        assertNull(result);
+        StructDefinition result = fixture.lookupStruct(ENUM_6);
+        assertNotNull(result);
     }
 
     /**
@@ -242,8 +279,7 @@ public class VariantDefinitionTest {
      */
     @Test
     public void testLookupVariant() {
-        String name = ""; //$NON-NLS-1$
-        VariantDefinition result = fixture.lookupVariant(name);
+        VariantDefinition result = fixture.lookupVariant(ENUM_8);
         assertNull(result);
     }
 
@@ -252,8 +288,7 @@ public class VariantDefinitionTest {
      */
     @Test
     public void testSetCurrentField() {
-        String currentField = ""; //$NON-NLS-1$
-        fixture.setCurrentField(currentField);
+        fixture.setCurrentField(ENUM_1);
     }
 
     /**
@@ -280,7 +315,7 @@ public class VariantDefinitionTest {
      * @throws CTFReaderException
      */
     @Test
-    public void testSetTagDefinition() throws CTFReaderException {
+    public void testSetTagDefinition(){
         VariantDeclaration vDecl;
         VariantDefinition vDef;
         StructDefinition structDef;
@@ -289,7 +324,7 @@ public class VariantDefinitionTest {
 
         vDecl = new VariantDeclaration();
         vDecl.setTag(fName);
-        vDef = new VariantDefinition(vDecl, TestParams.createTrace(), fName);
+        vDef = new VariantDefinition(vDecl, structDefinition, fName);
         structDef = new StructDefinition(new StructDeclaration(1L), vDef, fName);
         tagDefinition = new EnumDefinition(new EnumDeclaration(
                 new IntegerDeclaration(1, true, 1, ByteOrder.BIG_ENDIAN,
This page took 0.039898 seconds and 5 git commands to generate.