Add test cases for float definitions.
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Tue, 1 May 2012 13:43:39 +0000 (09:43 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Tue, 1 May 2012 13:47:45 +0000 (09:47 -0400)
Fix build error caused by rebase.

Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/FloatDeclarationTest.java [new file with mode: 0644]
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/FloatDefinitionTest.java [new file with mode: 0644]
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/TestAll.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java

diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/FloatDeclarationTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/FloatDeclarationTest.java
new file mode 100644 (file)
index 0000000..4cb0a95
--- /dev/null
@@ -0,0 +1,41 @@
+package org.eclipse.linuxtools.ctf.core.tests.types;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.nio.ByteOrder;
+
+import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
+import org.eclipse.linuxtools.ctf.core.event.types.FloatDeclaration;
+import org.junit.Test;
+
+
+public class FloatDeclarationTest {
+    private FloatDeclaration fixture;
+
+
+    @Test
+    public void ctorTest() {
+        for( int i = 1; i < 20; i++) {
+            fixture = new FloatDeclaration(i, 32-i, ByteOrder.nativeOrder(), Encoding.NONE, 0);
+            assertNotNull(fixture);
+        }
+    }
+
+    @Test
+    public void getterTest() {
+        fixture = new FloatDeclaration(8, 24, ByteOrder.nativeOrder(), Encoding.NONE, 0);
+        assertEquals( fixture.getAlignment(), 0);
+        assertEquals( fixture.getByteOrder(), ByteOrder.nativeOrder());
+        assertEquals( fixture.getEncoding(), Encoding.NONE);
+        assertEquals( fixture.getExponent(), 8);
+        assertEquals( fixture.getMantissa(), 24);
+    }
+
+    @Test
+    public void toStringTest() {
+        fixture = new FloatDeclaration(8, 24, ByteOrder.nativeOrder(), Encoding.NONE, 0);
+        assertTrue(fixture.toString().contains("float")); //$NON-NLS-1$
+    }
+}
diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/FloatDefinitionTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/FloatDefinitionTest.java
new file mode 100644 (file)
index 0000000..d6c22d6
--- /dev/null
@@ -0,0 +1,158 @@
+package org.eclipse.linuxtools.ctf.core.tests.types;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.nio.ByteOrder;
+
+import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
+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.IntegerDefinition;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+
+
+/**
+ * The class <code>IntegerDefinitionTest</code> contains tests for the class
+ * <code>{@link IntegerDefinition}</code>.
+ *
+ * @author ematkho
+ * @version $Revision: 1.0 $
+ */
+
+public class FloatDefinitionTest {
+    private FloatDefinition fixture;
+    private FloatDefinition singleFixture;
+    private FloatDefinition doubleFixture; //all the way.
+    private FloatDeclaration parent;
+    private static final String fieldName = "float"; //$NON-NLS-1$
+    /**
+     * Launch the test.
+     *
+     * @param args
+     *            the command line arguments
+     */
+    public static void main(String[] args) {
+        new org.junit.runner.JUnitCore().run(IntegerDefinitionTest.class);
+    }
+
+    /**
+     * Perform pre-test initialization. We know the structDef won't be null (or
+     * else the tests will fail), so we can safely suppress the warning.
+     *
+     * @throws CTFReaderException
+     */
+    @Before
+    public void setUp(){
+        testFloat248();
+        testFloat5311();
+    }
+
+    /**
+     * Perform post-test clean-up.
+     */
+    @After
+    public void tearDown() {
+        // Add additional tear down code here
+    }
+
+    @Test
+    public void testFloat248() {
+        parent = new FloatDeclaration(8, 24, ByteOrder.nativeOrder(), Encoding.NONE, 0);
+        singleFixture = (FloatDefinition) parent.createDefinition(null, fieldName);
+        assertNotNull(singleFixture);
+    }
+
+
+
+    @Test
+    public void testFloat5311() {
+        parent = new FloatDeclaration(11, 53, ByteOrder.nativeOrder(), Encoding.NONE, 0);
+        doubleFixture = (FloatDefinition) parent.createDefinition(null, fieldName);
+        assertNotNull(doubleFixture);
+    }
+
+    @Test
+    public void testFloat32Bit(){
+        for(int i = 1; i < 31 ; i++)
+        {
+            parent = new FloatDeclaration(i, 32-i, ByteOrder.nativeOrder(), Encoding.NONE, 0);
+            fixture = (FloatDefinition) parent.createDefinition(null, fieldName);
+            assertNotNull(fixture);
+            fixture.setValue(2.0);
+            assertTrue(fixture.toString().contains("2")); //$NON-NLS-1$
+        }
+    }
+
+    @Test
+    public void testFloat64Bit(){
+        for(int i = 1; i < 63 ; i++)
+        {
+            parent = new FloatDeclaration(i, 64-i, ByteOrder.nativeOrder(), Encoding.NONE, 0);
+            fixture = (FloatDefinition) parent.createDefinition(null, fieldName);
+            assertNotNull(fixture);
+            BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
+            fixture.read(input);
+            fixture.setValue(2.0);
+            assertTrue(fixture.toString().contains("2")); //$NON-NLS-1$
+        }
+    }
+
+    @Test
+    public void testFloat48Bit(){
+        parent = new FloatDeclaration(12, 32, ByteOrder.nativeOrder(), Encoding.NONE, 0);
+        fixture = (FloatDefinition) parent.createDefinition(null, fieldName);
+        assertNotNull(fixture);
+        BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
+        fixture.read(input);
+
+        assertEquals(Double.NaN ,fixture.getValue(),0.1);
+    }
+    /**
+     * Run the IntegerDeclaration getDeclaration() method test.
+     */
+    @Test
+    public void testGetDeclaration() {
+        singleFixture.setValue(2.0);
+        FloatDeclaration result = singleFixture.getDeclaration();
+        assertNotNull(result);
+    }
+
+    /**
+     * Run the long getValue() method test.
+     */
+    @SuppressWarnings("deprecation")
+    @Test
+    public void testGetValue() {
+        singleFixture.setValue(2.0);
+        double result = singleFixture.getValue();
+        assertEquals(2.0, result,0.1);
+    }
+
+    /**
+     * Run the void read(BitBuffer) method test.
+     */
+    @Test
+    public void testRead() {
+        singleFixture.setValue(2.0);
+        BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
+        singleFixture.read(input);
+
+    }
+
+    /**
+     * Run the String toString() method test.
+     */
+    @Test
+    public void testToString() {
+        singleFixture.setValue(222.22);
+        String result = singleFixture.toString();
+        assertNotNull(result);
+    }
+}
index 5e6cba8fe467c3406959c134c951ff9c27c83777..10ddccfd35a37e72a53ff448a03395090fe971ec 100644 (file)
@@ -8,7 +8,7 @@ import org.junit.runners.Suite;
  * The class <code>TestAll</code> builds a suite that can be used to run all of
  * the tests within its package as well as within any subpackages of its
  * package.
- * 
+ *
  * @author ematkho
  * @version $Revision: 1.0 $
  */
@@ -19,13 +19,14 @@ import org.junit.runners.Suite;
         IntegerDefinitionTest.class, SequenceDefinitionTest.class,
         ArrayDefinitionTest.class, EnumDeclarationTest.class,
         StringDeclarationTest.class, ArrayDeclarationTest.class,
+        FloatDefinitionTest.class, FloatDeclarationTest.class,
         VariantDefinitionTest.class, VariantDeclarationTest.class,
         StringDefinitionTest.class, EventDeclarationTest.class, })
 public class TestAll {
 
     /**
      * Launch the test.
-     * 
+     *
      * @param args
      *            the command line arguments
      */
index f0039dfac9b621b679784abe271c86e3215fb300..294663e2f570b28ab0893b82fff37a06378311ce 100644 (file)
@@ -104,7 +104,7 @@ public class CTFTraceReader {
         if (hasMoreEvents()) {
             this.startTime = prio.peek().getCurrentEvent().timestamp;
             this.endTime = this.startTime;
-            this.index = 0;
+            this.fIndex = 0;
         }
         startIndex = new HashMap<Integer, Long>();
     }
@@ -258,8 +258,8 @@ public class CTFTraceReader {
                     startIndex.put(n, 0L);
                 }
                 currentPacket.setIndexBegin(startIndex.get(n));
-                currentPacket.setIndexEnd(index);
-                startIndex.put(n, index + 1);
+                currentPacket.setIndexEnd(fIndex);
+                startIndex.put(n, fIndex + 1);
             }
         }
         /*
This page took 0.028125 seconds and 5 git commands to generate.