ctf: Make events immutable
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / types / SequenceDefinitionTest.java
index 073e5d4a6d80fa9c51c91ab433417ef49d25942a..4a5e5adfc6f18025c4936363d44d4aba1fd275ad 100644 (file)
@@ -21,6 +21,7 @@ import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
 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.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.StructDeclaration;
@@ -29,6 +30,8 @@ import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 import org.junit.Before;
 import org.junit.Test;
 
+import com.google.common.collect.ImmutableList;
+
 /**
  * The class <code>SequenceDefinitionTest</code> contains tests for the class
  * <code>{@link SequenceDefinition}</code>.
@@ -42,8 +45,13 @@ public class SequenceDefinitionTest {
     private SequenceDefinition fixture;
     private final static int seqLen = 15;
 
+    private static ImmutableList<String> wrap(String s) {
+        return ImmutableList.<String> builder().add(s).build();
+    }
+
     /**
      * Perform pre-test initialization.
+     *
      * @throws CTFReaderException
      */
     @Before
@@ -51,22 +59,23 @@ public class SequenceDefinitionTest {
         StructDeclaration structDec;
         StructDefinition structDef;
 
-        IntegerDeclaration id = new IntegerDeclaration(8, false, 8,
-                ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null, 8);
+        IntegerDeclaration id = IntegerDeclaration.createDeclaration(8, false, 8,
+                ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, "", 8);
         String lengthName = "LengthName";
         structDec = new StructDeclaration(0);
         structDec.addField(lengthName, id);
-        structDef = new StructDefinition(structDec, null, "x");
+        structDef = new StructDefinition(structDec, null, "x",
+                wrap(lengthName),
+                new Definition[] { new IntegerDefinition(id, null, lengthName, seqLen) });
 
-        structDef.lookupInteger(lengthName).setValue(seqLen);
         SequenceDeclaration sd = new SequenceDeclaration(lengthName, id);
-        fixture = new SequenceDefinition(sd, structDef, "TestX");
         BitBuffer input = new BitBuffer(
                 java.nio.ByteBuffer.allocateDirect(seqLen * 8));
         for (int i = 0; i < seqLen; i++) {
             input.putInt(i);
         }
-        fixture.read(input);
+
+        fixture = sd.createDefinition(structDef, "TestX", input);
         assert (fixture != null);
     }
 
@@ -75,22 +84,22 @@ public class SequenceDefinitionTest {
         StructDefinition structDef;
 
         int len = 32;
-        IntegerDeclaration id = new IntegerDeclaration(len, false, len,
-                ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null,8);
+        IntegerDeclaration id = IntegerDeclaration.createDeclaration(len, false, len,
+                ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, "", 8);
         String lengthName = "LengthName";
         structDec = new StructDeclaration(0);
         structDec.addField(lengthName, id);
-        structDef = new StructDefinition(structDec, null, "x");
 
-        structDef.lookupInteger(lengthName).setValue(seqLen);
+        structDef = new StructDefinition(structDec, null, "x", wrap(lengthName), new Definition[] { new IntegerDefinition(id, null, lengthName, seqLen) });
+
         SequenceDeclaration sd = new SequenceDeclaration(lengthName, id);
-        SequenceDefinition ret = new SequenceDefinition(sd, structDef, "TestX");
         BitBuffer input = new BitBuffer(
                 java.nio.ByteBuffer.allocateDirect(seqLen * len));
         for (int i = 0; i < seqLen; i++) {
             input.putInt(i);
         }
-        ret.read(input);
+
+        SequenceDefinition ret = sd.createDefinition(structDef, "TestX", input);
         assertNotNull(ret);
         return ret;
     }
@@ -138,20 +147,10 @@ public class SequenceDefinitionTest {
      */
     @Test
     public void testIsString() {
-        boolean result = fixture.isString();
+        boolean result = fixture.getDeclaration().isString();
         assertTrue(result);
     }
 
-    /**
-     * Run the void read(BitBuffer) method test.
-     * @throws CTFReaderException error
-     */
-    @Test
-    public void testRead() throws CTFReaderException {
-        BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
-        fixture.read(input);
-    }
-
     /**
      * Run the String toString() method test.
      */
This page took 0.024919 seconds and 5 git commands to generate.