ss: Add unit tests for state values
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Mon, 7 Mar 2016 14:47:45 +0000 (09:47 -0500)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Wed, 23 Mar 2016 01:11:06 +0000 (21:11 -0400)
Change-Id: Ibc7da569fcb3cd2920170a1d28bb48dc6497fe7f
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Signed-off-by: Alexandre Montplaisir <alexmonthy@efficios.com>
Reviewed-on: https://git.eclipse.org/r/67908
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-by: Hudson CI
statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/DoubleStateValueTest.java [new file with mode: 0644]
statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/IntStateValueTest.java [new file with mode: 0644]
statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/LongStateValueTest.java [new file with mode: 0644]
statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/NullStateValueTest.java [new file with mode: 0644]
statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/StateValueCompareToTest.java
statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/StateValueTestBase.java [new file with mode: 0644]
statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/StringStateValueTest.java [new file with mode: 0644]
statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/package-info.java [new file with mode: 0644]

diff --git a/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/DoubleStateValueTest.java b/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/DoubleStateValueTest.java
new file mode 100644 (file)
index 0000000..a8b8362
--- /dev/null
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2016 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.statesystem.core.tests.statevalue;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
+import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue.Type;
+import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
+import org.junit.Test;
+
+/**
+ * Test the double state value class
+ *
+ * @author Geneviève Bastien
+ */
+public class DoubleStateValueTest extends StateValueTestBase {
+
+    private static final double UNBOXED_VALUE = 34.3534;
+    private static final TmfStateValue STATE_VALUE = TmfStateValue.newValueDouble(UNBOXED_VALUE);
+
+
+    @Override
+    protected ITmfStateValue getStateValueFixture() {
+        return STATE_VALUE;
+    }
+
+    @Override
+    protected Type getStateValueType() {
+        return ITmfStateValue.Type.DOUBLE;
+    }
+
+    @Override
+    @Test
+    public void testUnboxDouble() {
+        double value = STATE_VALUE.unboxDouble();
+        assertEquals(UNBOXED_VALUE, value, 0.0001);
+    }
+}
diff --git a/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/IntStateValueTest.java b/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/IntStateValueTest.java
new file mode 100644 (file)
index 0000000..584e022
--- /dev/null
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2016 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.statesystem.core.tests.statevalue;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
+import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue.Type;
+import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
+import org.junit.Test;
+
+/**
+ * Test the integer state value class
+ *
+ * @author Geneviève Bastien
+ */
+public class IntStateValueTest extends StateValueTestBase {
+
+    private static final int UNBOXED_VALUE = 34;
+    private static final TmfStateValue STATE_VALUE = TmfStateValue.newValueInt(UNBOXED_VALUE);
+
+
+    @Override
+    protected ITmfStateValue getStateValueFixture() {
+        return STATE_VALUE;
+    }
+
+    @Override
+    protected Type getStateValueType() {
+        return ITmfStateValue.Type.INTEGER;
+    }
+
+    @Override
+    @Test
+    public void testUnboxInt() {
+        int unboxed = STATE_VALUE.unboxInt();
+        assertEquals(UNBOXED_VALUE, unboxed);
+    }
+
+    @Override
+    @Test
+    public void testUnboxLong() {
+        long unboxed = STATE_VALUE.unboxLong();
+        assertEquals(UNBOXED_VALUE, unboxed);
+    }
+
+}
diff --git a/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/LongStateValueTest.java b/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/LongStateValueTest.java
new file mode 100644 (file)
index 0000000..6cae822
--- /dev/null
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2016 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.statesystem.core.tests.statevalue;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
+import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue.Type;
+import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
+import org.junit.Test;
+
+/**
+ * Test the long state value class
+ *
+ * @author Geneviève Bastien
+ */
+public class LongStateValueTest extends StateValueTestBase {
+
+    private static final long UNBOXED_VALUE = 34L;
+    private static final TmfStateValue STATE_VALUE = TmfStateValue.newValueLong(UNBOXED_VALUE);
+
+    @Override
+    protected ITmfStateValue getStateValueFixture() {
+        return STATE_VALUE;
+    }
+
+    @Override
+    protected Type getStateValueType() {
+        return ITmfStateValue.Type.LONG;
+    }
+
+    @Override
+    @Test
+    public void testUnboxLong() {
+        long unboxed = STATE_VALUE.unboxLong();
+        assertEquals(UNBOXED_VALUE, unboxed);
+    }
+}
diff --git a/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/NullStateValueTest.java b/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/NullStateValueTest.java
new file mode 100644 (file)
index 0000000..68c304e
--- /dev/null
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2016 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.statesystem.core.tests.statevalue;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue.Type;
+import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
+import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
+import org.junit.Test;
+
+/**
+ * Test the string state value class
+ *
+ * @author Geneviève Bastien
+ */
+public class NullStateValueTest extends StateValueTestBase {
+
+    private static final TmfStateValue STATE_VALUE = TmfStateValue.nullValue();
+
+    @Override
+    protected ITmfStateValue getStateValueFixture() {
+        return STATE_VALUE;
+    }
+
+    @Override
+    protected Type getStateValueType() {
+        return ITmfStateValue.Type.NULL;
+    }
+
+    @Override
+    @Test
+    public void testUnboxInt() {
+        int unboxed = STATE_VALUE.unboxInt();
+        assertEquals(-1, unboxed);
+    }
+
+    @Override
+    @Test
+    public void testUnboxLong() {
+        long unboxed = STATE_VALUE.unboxLong();
+        assertEquals(-1, unboxed);
+    }
+
+    @Override
+    @Test
+    public void testUnboxDouble() {
+        double unboxed = STATE_VALUE.unboxDouble();
+        assertEquals(Double.NaN, unboxed, 0.00001);
+    }
+
+    @Override
+    @Test
+    public void testUnboxStr() {
+        String unboxed = STATE_VALUE.unboxStr();
+        assertEquals("nullValue", unboxed);
+    }
+
+    @Override
+    @Test
+    public void testIsNull() {
+        assertTrue(STATE_VALUE.isNull());
+    }
+}
index 73951589b829065e1388905565379679dc6bb559..f65b18df7ae1e1422aa93cf398b21d05e88065cd 100644 (file)
@@ -14,7 +14,6 @@ package org.eclipse.tracecompass.statesystem.core.tests.statevalue;
 
 import static org.junit.Assert.assertTrue;
 
-import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
 import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
 import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
@@ -25,7 +24,6 @@ import org.junit.Test;
  *
  * @author Naser Ezzati
  */
-@NonNullByDefault
 public class StateValueCompareToTest {
 
     // ------------------------------------------------------------------------
diff --git a/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/StateValueTestBase.java b/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/StateValueTestBase.java
new file mode 100644 (file)
index 0000000..841ecc8
--- /dev/null
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2016 EfficiOS Inc., Alexandre Montplaisir
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.statesystem.core.tests.statevalue;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
+import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
+import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
+import org.junit.Test;
+
+/**
+ * Base class for state value tests.
+ *
+ * By default, it is assumed the state value is *not* null, and throws an
+ * exception for every unbox*() method. Subclasses should override the
+ * appropriate tests to represent their actual behaviour.
+ *
+ * @author Alexandre Montplaisir
+ */
+public abstract class StateValueTestBase {
+
+    /**
+     * @return The state value fixture
+     */
+    protected abstract ITmfStateValue getStateValueFixture();
+
+    /**
+     * @return The expected type of the state value
+     */
+    protected abstract ITmfStateValue.Type getStateValueType();
+
+    /**
+     * Test the {@link TmfStateValue#getType()} method
+     */
+    @Test
+    public final void testGetType() {
+        assertEquals(getStateValueType(), getStateValueFixture().getType());
+    }
+
+    /**
+     * Test the {@link TmfStateValue#unboxInt()} method
+     */
+    @Test(expected=StateValueTypeException.class)
+    public void testUnboxInt() {
+        getStateValueFixture().unboxInt();
+    }
+
+    /**
+     * Test the {@link TmfStateValue#unboxLong()} method
+     */
+    @Test(expected=StateValueTypeException.class)
+    public void testUnboxLong() {
+        getStateValueFixture().unboxLong();
+    }
+
+    /**
+     * Test the {@link TmfStateValue#unboxDouble()} method
+     */
+    @Test(expected=StateValueTypeException.class)
+    public void testUnboxDouble() {
+        getStateValueFixture().unboxDouble();
+    }
+
+    /**
+     * Test the {@link TmfStateValue#unboxStr()} method
+     */
+    @Test(expected=StateValueTypeException.class)
+    public void testUnboxStr() {
+        getStateValueFixture().unboxStr();
+    }
+
+    /**
+     * Test the {@link TmfStateValue#isNull()} method
+     */
+    @Test
+    public void testIsNull() {
+        assertFalse(getStateValueFixture().isNull());
+    }
+}
diff --git a/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/StringStateValueTest.java b/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/StringStateValueTest.java
new file mode 100644 (file)
index 0000000..4a857dc
--- /dev/null
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2016 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.statesystem.core.tests.statevalue;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
+import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue.Type;
+import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
+import org.junit.Test;
+
+/**
+ * Test the string state value class
+ *
+ * @author Geneviève Bastien
+ */
+public class StringStateValueTest extends StateValueTestBase {
+
+    private static final String UNBOXED_VALUE = "MyString";
+    private static final TmfStateValue STATE_VALUE = TmfStateValue.newValueString(UNBOXED_VALUE);
+
+    @Override
+    protected ITmfStateValue getStateValueFixture() {
+        return STATE_VALUE;
+    }
+
+    @Override
+    protected Type getStateValueType() {
+        return ITmfStateValue.Type.STRING;
+    }
+
+    @Override
+    @Test
+    public void testUnboxStr() {
+        String unboxed = STATE_VALUE.unboxStr();
+        assertEquals(UNBOXED_VALUE, unboxed);
+    }
+}
diff --git a/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/package-info.java b/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/package-info.java
new file mode 100644 (file)
index 0000000..36dcf83
--- /dev/null
@@ -0,0 +1,11 @@
+/*******************************************************************************
+ * Copyright (c) 2016 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+@org.eclipse.jdt.annotation.NonNullByDefault
+package org.eclipse.tracecompass.statesystem.core.tests.statevalue;
This page took 0.032201 seconds and 5 git commands to generate.