Merge commit 'e1de8d2d152352eded708615a967021db7800709' into lttng-luna
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / ctfadaptor / CtfTmfEventFieldTest.java
index 300a27c68dc1358fd2e6d3d5ab98a5669b3e0c85..d3cdf07b6c4c99b75b954cb59d15f32688589ae7 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2012 Ericsson
+ * Copyright (c) 2012, 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
 package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertArrayEquals;
 
 import java.nio.ByteOrder;
 
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
 import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration;
 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.FloatDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.FloatDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
@@ -28,9 +30,8 @@ import org.eclipse.linuxtools.ctf.core.event.types.SequenceDeclaration;
 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.internal.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEventField;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -43,27 +44,20 @@ import org.junit.Test;
  */
 public class CtfTmfEventFieldTest {
 
-    private static final String ROOT = "root"; //$NON-NLS-1$
-    private static final String SEQ = "seq"; //$NON-NLS-1$
-    private static final String ARRAY = "array"; //$NON-NLS-1$
-    private static final String STR = "str"; //$NON-NLS-1$
-    private static final String FLOAT = "float"; //$NON-NLS-1$
-    private static final String LEN = "len"; //$NON-NLS-1$
-    private static final String INT = "int"; //$NON-NLS-1$
-    private static final String NAME = "test"; //$NON-NLS-1$
+    private static final String ROOT = "root";
+    private static final String SEQ = "seq";
+    private static final String ARRAY = "array";
+    private static final String STR = "str";
+    private static final String FLOAT = "float";
+    private static final String LEN = "len";
+    private static final String INT = "int";
+    private static final String NAME = "test";
+    private static final String STRUCT = "struct";
+    private static final String VARIANT = "variant";
+    private static final String ENUM = "enum";
 
     private StructDefinition fixture;
 
-    /**
-     * Launch the test.
-     *
-     * @param args
-     *            the command line arguments
-     */
-    public static void main(String[] args) {
-        new org.junit.runner.JUnitCore().run(CtfTmfEventFieldTest.class);
-    }
-
     /**
      * Perform pre-test initialization.
      */
@@ -77,42 +71,49 @@ public class CtfTmfEventFieldTest {
                 ByteOrder.BIG_ENDIAN, 8);
         ArrayDeclaration arrDec = new ArrayDeclaration(2, intDec);
         SequenceDeclaration seqDec = new SequenceDeclaration(LEN, intDec);
+        StructDeclaration structDec = new StructDeclaration(32);
+        EnumDeclaration enumDec = new EnumDeclaration(intDec);
+        VariantDeclaration varDec = new VariantDeclaration();
         sDec.addField(INT, intDec);
         sDec.addField(LEN, intDec);
         sDec.addField(FLOAT, flDec);
         sDec.addField(STR, strDec);
         sDec.addField(ARRAY, arrDec);
         sDec.addField(SEQ, seqDec);
+        structDec.addField(STR, strDec);
+        structDec.addField(INT, intDec);
+        sDec.addField(STRUCT, structDec);
+        enumDec.add(0, 1, LEN);
+        enumDec.add(2, 3, FLOAT);
+        sDec.addField(ENUM, enumDec);
+        varDec.addField(LEN, intDec);
+        varDec.addField(FLOAT, flDec);
+        varDec.setTag(ENUM);
+        sDec.addField(VARIANT, varDec);
         fixture = sDec.createDefinition(fixture, ROOT);
-        int capacity = 1024;
+        int capacity = 2048;
         java.nio.ByteBuffer bb = java.nio.ByteBuffer.allocateDirect(capacity);
         for (int i = 0; i < capacity; i++) {
             bb.put((byte) 2);
         }
         bb.position(20);
         bb.put((byte) 0);
+        bb.position(40);
+        bb.put((byte) 0);
+        bb.position(60);
+        bb.put((byte) 0);
         bb.position(0);
         fixture.read(new BitBuffer(bb));
     }
 
-    /**
-     * Perform post-test clean-up.
-     */
-    @After
-    public void tearDown() {
-        // Add additional tear down code here
-    }
-
     /**
      * Run the CtfTmfEventField parseField(Definition,String) method test.
      */
     @Test
     public void testParseField_float() {
-        FloatDefinition fieldDef;
-        fieldDef = (FloatDefinition) fixture.lookupDefinition(FLOAT);
-        CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, "_"+NAME); //$NON-NLS-1$
-        String result2 = CtfTmfEventField.copyFrom(result).toString();
-        assertEquals( result2, "test=9.551467814359616E-38"); //$NON-NLS-1$
+        FloatDefinition fieldDef = (FloatDefinition) fixture.lookupDefinition(FLOAT);
+        CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, "_" + NAME);
+        assertEquals("test=9.551467814359616E-38", result.toString());
     }
 
     /**
@@ -120,10 +121,9 @@ public class CtfTmfEventFieldTest {
      */
     @Test
     public void testParseField_array() {
-        CtfTmfEventField result;
-        result = CtfTmfEventField.parseField(fixture.lookupArray(ARRAY), NAME);
-        String result2 = CtfTmfEventField.copyFrom(result).toString();
-        assertEquals( result2, "test={ 2, 2}"); //$NON-NLS-1$
+        Definition fieldDef = fixture.lookupArray(ARRAY);
+        CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
+        assertEquals("test=[02, 02]", result.toString());
     }
 
     /**
@@ -133,8 +133,7 @@ public class CtfTmfEventFieldTest {
     public void testParseField_int() {
         Definition fieldDef = fixture.lookupDefinition(INT);
         CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
-        String result2 =CtfTmfEventField.copyFrom(result).toString();
-        assertEquals( result2, "test=02"); //$NON-NLS-1$
+        assertEquals("test=02", result.toString());
     }
 
     /**
@@ -144,8 +143,19 @@ public class CtfTmfEventFieldTest {
     public void testParseField_sequence() {
         Definition fieldDef = fixture.lookupDefinition(SEQ);
         CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
-        String result2 =CtfTmfEventField.copyFrom(result).toString();
-        assertEquals( result2, "test={ 2, 2}"); //$NON-NLS-1$
+        assertEquals("test=[02, 02]", result.toString());
+    }
+
+    /**
+     * Run the CtfTmfEventField parseField(Definition,String) method test.
+     */
+    @Test
+    public void testParseField_sequence_value() {
+        Definition fieldDef = fixture.lookupDefinition(SEQ);
+        CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
+        long[] values = (long[]) result.getValue();
+        long[] expected = new long[] { 2, 2 };
+        assertArrayEquals(expected, values);
     }
 
     /**
@@ -155,17 +165,36 @@ public class CtfTmfEventFieldTest {
     public void testParseField_string() {
         Definition fieldDef = fixture.lookupDefinition(STR);
         CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
-        String result2 =CtfTmfEventField.copyFrom(result).toString();
-        assertEquals( result2, "test=\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2"); //$NON-NLS-1$
+        assertEquals("test=\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2", result.toString());
     }
 
     /**
-     * Test the clone() method.
+     * Run the CtfTmfEventField parseField(Definition,String) method test.
      */
     @Test
-    public void testClone() {
-        Definition fieldDef = fixture.lookupDefinition(STR);
+    public void testParseField_struct() {
+        Definition fieldDef = fixture.lookupDefinition(STRUCT);
+        CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
+        assertEquals("test=[str=\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2, int=02]", result.toString());
+    }
+
+    /**
+     * Run the CtfTmfEventField parseField(Definition,String) method test.
+     */
+    @Test
+    public void testParseField_enum() {
+        Definition fieldDef = fixture.lookupDefinition(ENUM);
+        CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
+        assertEquals("test=float", result.toString());
+    }
+
+    /**
+     * Run the CtfTmfEventField parseField(Definition,String) method test.
+     */
+    @Test
+    public void testParseField_variant() {
+        Definition fieldDef = fixture.lookupDefinition(VARIANT);
         CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
-        assertNotNull(result.clone());
+        assertEquals("test=float=9.551467814359616E-38", result.toString());
     }
 }
This page took 0.026778 seconds and 5 git commands to generate.