From fef07c8b7d740ed07ee855ceae7c391481ce73c2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Genevi=C3=A8ve=20Bastien?= Date: Mon, 7 Mar 2016 09:47:45 -0500 Subject: [PATCH] ss: Add unit tests for state values MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: Ibc7da569fcb3cd2920170a1d28bb48dc6497fe7f Signed-off-by: Geneviève Bastien Signed-off-by: Alexandre Montplaisir Reviewed-on: https://git.eclipse.org/r/67908 Reviewed-by: Matthew Khouzam Reviewed-by: Hudson CI --- .../statevalue/DoubleStateValueTest.java | 46 ++++++++++ .../tests/statevalue/IntStateValueTest.java | 54 ++++++++++++ .../tests/statevalue/LongStateValueTest.java | 45 ++++++++++ .../tests/statevalue/NullStateValueTest.java | 72 +++++++++++++++ .../statevalue/StateValueCompareToTest.java | 2 - .../tests/statevalue/StateValueTestBase.java | 88 +++++++++++++++++++ .../statevalue/StringStateValueTest.java | 45 ++++++++++ .../core/tests/statevalue/package-info.java | 11 +++ 8 files changed, 361 insertions(+), 2 deletions(-) create mode 100644 statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/DoubleStateValueTest.java create mode 100644 statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/IntStateValueTest.java create mode 100644 statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/LongStateValueTest.java create mode 100644 statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/NullStateValueTest.java create mode 100644 statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/StateValueTestBase.java create mode 100644 statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/StringStateValueTest.java create mode 100644 statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/package-info.java 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 index 0000000000..a8b83625b0 --- /dev/null +++ b/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/DoubleStateValueTest.java @@ -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 index 0000000000..584e022909 --- /dev/null +++ b/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/IntStateValueTest.java @@ -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 index 0000000000..6cae822de9 --- /dev/null +++ b/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/LongStateValueTest.java @@ -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 index 0000000000..68c304e747 --- /dev/null +++ b/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/NullStateValueTest.java @@ -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()); + } +} diff --git a/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/StateValueCompareToTest.java b/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/StateValueCompareToTest.java index 73951589b8..f65b18df7a 100644 --- a/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/StateValueCompareToTest.java +++ b/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/StateValueCompareToTest.java @@ -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 index 0000000000..841ecc8589 --- /dev/null +++ b/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/StateValueTestBase.java @@ -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 index 0000000000..4a857dc3a1 --- /dev/null +++ b/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/StringStateValueTest.java @@ -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 index 0000000000..36dcf836eb --- /dev/null +++ b/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/statevalue/package-info.java @@ -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; -- 2.34.1