ctf: Make events immutable
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / types / SequenceDeclarationTest.java
index f732ffd3bcc8a13c6bcddd3cb740b62b1ce520be..dbdf621cd703a2f0d5771e34a1b344274916c1e3 100644 (file)
@@ -14,19 +14,27 @@ package org.eclipse.linuxtools.ctf.core.tests.types;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
+import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
 
+import org.eclipse.jdt.annotation.NonNull;
+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.IDeclaration;
 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.StructDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
+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>SequenceDeclarationTest</code> contains tests for the class
  * <code>{@link SequenceDeclaration}</code>.
@@ -37,13 +45,17 @@ import org.junit.Test;
 @SuppressWarnings("javadoc")
 public class SequenceDeclarationTest {
 
-    private SequenceDeclaration fixture;
+    @NonNull private static final String FIELD_NAME = "LengthName";
 
-    static final String fieldName = "LengthName";
+    private SequenceDeclaration fixture;
+    @NonNull private BitBuffer input = new BitBuffer();
 
     @Before
     public void setUp() {
-        fixture = new SequenceDeclaration(fieldName, new StringDeclaration());
+        fixture = new SequenceDeclaration(FIELD_NAME, new StringDeclaration());
+        byte array[] = { 't', 'e', 's', 't', '\0', 't', 'h', 'i', 's', '\0' };
+        ByteBuffer byb = ByteBuffer.wrap(array);
+        input = new BitBuffer(byb);
     }
 
     /**
@@ -63,18 +75,30 @@ public class SequenceDeclarationTest {
     /**
      * Run the SequenceDefinition createDefinition(DefinitionScope,String)
      * method test.
+     *
+     * @throws CTFReaderException
+     *             an error in the bitbuffer
      */
     @Test
-    public void testCreateDefinition() {
-        IntegerDeclaration id = new IntegerDeclaration(8, false, 8,
-                ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null, 32);
-
+    public void testCreateDefinition() throws CTFReaderException {
+        long seqLen = 2;
+        IntegerDeclaration id = IntegerDeclaration.createDeclaration(8, false, 8,
+                ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, "", 32);
         StructDeclaration structDec = new StructDeclaration(0);
-        structDec.addField(fieldName, id);
-        StructDefinition structDef = new StructDefinition(structDec, null, "x");
-        long seqLen = 10;
-        structDef.lookupInteger(fieldName).setValue(seqLen);
-        SequenceDefinition result = this.fixture.createDefinition(structDef, fieldName);
+        structDec.addField(FIELD_NAME, id);
+        StructDefinition structDef = new StructDefinition(
+                structDec,
+                null,
+                "x",
+                ImmutableList.of(FIELD_NAME),
+                new Definition[] {
+                        new IntegerDefinition(
+                                id,
+                                null,
+                                FIELD_NAME,
+                                seqLen)
+                });
+        SequenceDefinition result = fixture.createDefinition(structDef, FIELD_NAME, input);
         assertNotNull(result);
     }
 
This page took 0.024407 seconds and 5 git commands to generate.