diff --git a/parameter/BooleanParameterType.cpp b/parameter/BooleanParameterType.cpp index 66556d304..c6a5be41f 100644 --- a/parameter/BooleanParameterType.cpp +++ b/parameter/BooleanParameterType.cpp @@ -108,6 +108,7 @@ bool CBooleanParameterType::toBlackboard(uint32_t uiUserValue, uint32_t &uiValue if (uiUserValue > 1) { parameterAccessContext.setError("Value out of range"); + return false; } uiValue = uiUserValue; diff --git a/test/functional-tests/BitParameter.cpp b/test/functional-tests/BitParameter.cpp new file mode 100644 index 000000000..0a0fb9508 --- /dev/null +++ b/test/functional-tests/BitParameter.cpp @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2017, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "Config.hpp" +#include "ParameterFramework.hpp" +#include "ElementHandle.hpp" +#include "Test.hpp" + +#include + +#include + +using std::string; + +namespace parameterFramework +{ + +const auto validBitParameterInstances = Config{ + &Config::instances, + // Default for integers is unsigned/32bits + R"()"}; + +const auto &invalidBitParameterParameters = + Tests{{"Too much bits", ""}, + {"Max too high", ""}}; + +struct BitParameterPF : public ParameterFramework +{ + BitParameterPF() : ParameterFramework{std::move(validBitParameterInstances)} {} +}; + +SCENARIO_METHOD(LazyPF, "Invalid BitParameter types XML structure", "[BitParameter types]") +{ + for (auto &vec : invalidBitParameterParameters) { + GIVEN ("intentional error: " + vec.title) { + create(Config{&Config::instances, vec.payload}); + THEN ("Start should fail") { + CHECK_THROWS_AS(mPf->start(), Exception); + } + } + } +} + +SCENARIO_METHOD(BitParameterPF, "BitParameter types", "[BitParameter types]") +{ + GIVEN ("A valid XML structure file") { + THEN ("Start should succeed") { + CHECK_NOTHROW(start()); + REQUIRE_NOTHROW(setTuningMode(true)); + string path = "/test/test/nominal/treebits"; + + AND_THEN ("Set/Get a BitParameter type parameter in real value space") { + + for (auto &vec : Tests{ + {"(too high)", "7"}, {"(too low)", "-1"}, + }) { + GIVEN ("Invalid value " + vec.title) { + CHECK_THROWS_AS(setParameter(path, vec.payload), Exception); + } + } + for (auto &vec : Tests{ + {"(upper limit)", "6"}, {"(lower limit)", "0"}, + }) { + GIVEN ("A valid value " + vec.title) { + CHECK_NOTHROW(setParameter(path, vec.payload)); + string getValueBack; + REQUIRE_NOTHROW(getParameter(path, getValueBack)); + CHECK(getValueBack == vec.payload); + } + } + } + + AND_THEN ("Set/Get a BitParameter type parameter in real value space") { + ElementHandle handle{*this, path}; + REQUIRE_NOTHROW(setRawValueSpace(true)); + REQUIRE_NOTHROW(setHexOutputFormat(true)); + + for (auto &vec : Tests{ + {"(too high)", "0x7"}, + }) { + GIVEN ("Invalid value " + vec.title) { + CHECK_THROWS_AS(setParameter(path, vec.payload), Exception); + } + } + for (auto &vec : Tests{ + {"(upper limit)", "0x6"}, {"(lower limit)", "0x0"}, + }) { + GIVEN ("A valid value " + vec.title) { + CHECK_NOTHROW(setParameter(path, vec.payload)); + string getValueBack; + REQUIRE_NOTHROW(getParameter(path, getValueBack)); + CHECK(getValueBack == vec.payload); + } + } + } + + AND_THEN ("Set/Get a BitParameter type parameter in boolean") { + ElementHandle handle{*this, path}; + /** @FIXME: 'set' operations on a ParameterHandle are silently + * ignored in tuning mode. Does it make sense ? */ + REQUIRE_NOTHROW(setTuningMode(false)); + + for (auto &vec : Tests{ + {"(upper limit)", true}, {"(lower limit)", false}, + }) { + GIVEN ("Invalid value " + vec.title) { + CHECK_THROWS_AS(handle.setAsBoolean(vec.payload), Exception); + } + } + } + + AND_THEN ("Set/Get a BitParameter type parameter in boolean") { + path = "/test/test/nominal/bool"; + ElementHandle handle{*this, path}; + /** @FIXME: 'set' operations on a ParameterHandle are silently + * ignored in tuning mode. Does it make sense ? */ + REQUIRE_NOTHROW(setTuningMode(false)); + + for (auto &vec : Tests{ + {"(upper limit)", true}, {"(lower limit)", false}, + }) { + GIVEN ("A valid value " + vec.title) { + CHECK_NOTHROW(handle.setAsBoolean(vec.payload)); + bool getValueBack; + REQUIRE_NOTHROW(handle.getAsBoolean(getValueBack)); + CHECK(getValueBack == vec.payload); + } + } + } + } + } +} +} diff --git a/test/functional-tests/Boolean.cpp b/test/functional-tests/Boolean.cpp new file mode 100644 index 000000000..c485abad7 --- /dev/null +++ b/test/functional-tests/Boolean.cpp @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2017, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "Config.hpp" +#include "ParameterFramework.hpp" +#include "ElementHandle.hpp" +#include "Test.hpp" + +#include + +#include + +using std::string; + +namespace parameterFramework +{ + +const auto validBooleanInstances = Config{&Config::instances, + // Default for integers is unsigned/32bits + R"( + )"}; + +struct BooleanPF : public ParameterFramework +{ + BooleanPF() : ParameterFramework{std::move(validBooleanInstances)} {} +}; + +SCENARIO_METHOD(BooleanPF, "Boolean types", "[Boolean types]") +{ + GIVEN ("A valid XML structure file") { + THEN ("Start should succeed") { + CHECK_NOTHROW(start()); + REQUIRE_NOTHROW(setTuningMode(true)); + string path = "/test/test/nominal"; + + AND_THEN ("Set/Get a Boolean type parameter in real value space") { + + for (auto &vec : Tests{ + {"(too high)", "2"}, {"(too low)", "-1"}, {"(not a number)", "foobar"}, + }) { + GIVEN ("Invalid value " + vec.title) { + CHECK_THROWS_AS(setParameter(path, vec.payload), Exception); + } + } + for (auto &vec : Tests{ + {"(upper limit)", "1"}, {"(lower limit)", "0"}, + }) { + GIVEN ("A valid value " + vec.title) { + CHECK_NOTHROW(setParameter(path, vec.payload)); + string getValueBack; + REQUIRE_NOTHROW(getParameter(path, getValueBack)); + CHECK(getValueBack == vec.payload); + } + } + } + + AND_THEN ("Set/Get boolean type parameter handle") { + ElementHandle handle{*this, path}; + /** @FIXME: 'set' operations on a ParameterHandle are silently + * ignored in tuning mode. Does it make sense ? */ + REQUIRE_NOTHROW(setTuningMode(false)); + + for (auto &vec : Tests{ + {"(upper limit)", true}, {"(lower limit)", false}, + }) { + GIVEN ("A valid value " + vec.title) { + CHECK_NOTHROW(handle.setAsBoolean(vec.payload)); + bool getValueBack; + REQUIRE_NOTHROW(handle.getAsBoolean(getValueBack)); + CHECK(getValueBack == vec.payload); + } + } + } + + AND_THEN ("Set/Get integer type parameter handle") { + ElementHandle handle{*this, path}; + /** @FIXME: 'set' operations on a ParameterHandle are silently + * ignored in tuning mode. Does it make sense ? */ + REQUIRE_NOTHROW(setTuningMode(false)); + + for (auto &vec : Tests{ + {"(upper limit)", 1}, {"(lower limit)", 0}, + }) { + GIVEN ("A valid value " + vec.title) { + CHECK_NOTHROW(handle.setAsInteger(vec.payload)); + uint32_t getValueBack; + REQUIRE_NOTHROW(handle.getAsInteger(getValueBack)); + CHECK(getValueBack == vec.payload); + } + } + for (auto &vec : Tests{ + {"(too high)", 2}, + }) { + GIVEN ("An invalid value " + vec.title) { + CHECK_THROWS_AS(handle.setAsInteger(vec.payload), Exception); + } + } + } + + AND_THEN ("Set/Get a Boolean type parameter in real value space") { + ElementHandle handle{*this, path}; + REQUIRE_NOTHROW(setRawValueSpace(true)); + + for (auto &vec : Tests{ + {"(too high hexa)", "0x2"}, + {"(too high dec)", "2"}, + {"(too low hexa )", "0xFF"}, + {"(not a number)", "foobar"}, + }) { + GIVEN ("Invalid value " + vec.title) { + CHECK_THROWS_AS(setParameter(path, vec.payload), Exception); + } + } + for (auto &vec : Tests{ + {"(TRUE hexa)", "0x1"}, {"(TRUE dec)", "1"}, + }) { + GIVEN ("A valid value " + vec.title) { + CHECK_NOTHROW(setParameter(path, vec.payload)); + string getValueBack; + REQUIRE_NOTHROW(getParameter(path, getValueBack)); + CHECK(getValueBack == "1"); + } + } + for (auto &vec : Tests{ + {"(FALSE hexa)", "0x0"}, {"(FALSE dec)", "0"}, + }) { + GIVEN ("A valid value " + vec.title) { + CHECK_NOTHROW(setParameter(path, vec.payload)); + string getValueBack; + REQUIRE_NOTHROW(getParameter(path, getValueBack)); + CHECK(getValueBack == "0"); + } + } + } + } + } +} +} diff --git a/test/functional-tests/CMakeLists.txt b/test/functional-tests/CMakeLists.txt index f0c4d6460..c3d02d0ef 100644 --- a/test/functional-tests/CMakeLists.txt +++ b/test/functional-tests/CMakeLists.txt @@ -35,9 +35,14 @@ if(BUILD_TESTING) # Add unit test add_executable(parameterFunctionalTest Basic.cpp + Boolean.cpp + BitParameter.cpp + EnumParameter.cpp FloatingPoint.cpp FixedPoint.cpp Integer.cpp + Linear.cpp + Logarithmic.cpp Handle.cpp AutoSync.cpp) diff --git a/test/functional-tests/EnumParameter.cpp b/test/functional-tests/EnumParameter.cpp new file mode 100644 index 000000000..5d1783703 --- /dev/null +++ b/test/functional-tests/EnumParameter.cpp @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2017, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "Config.hpp" +#include "ParameterFramework.hpp" +#include "ElementHandle.hpp" +#include "Test.hpp" + +#include + +#include + +using std::string; + +namespace parameterFramework +{ + +const auto validEnumParameterInstances = Config{ + &Config::instances, + // Default for integers is unsigned/32bits + R"()"}; + +const auto &invalidEnumParameterParameters = Tests{ + {"No Size", ""}}; + +struct EnumParameterPF : public ParameterFramework +{ + EnumParameterPF() : ParameterFramework{std::move(validEnumParameterInstances)} {} +}; + +SCENARIO_METHOD(LazyPF, "Invalid EnumParameter types XML structure", "[EnumParameter types]") +{ + for (auto &vec : invalidEnumParameterParameters) { + GIVEN ("intentional error: " + vec.title) { + create(Config{&Config::instances, vec.payload}); + THEN ("Start should fail") { + CHECK_THROWS_AS(mPf->start(), Exception); + } + } + } +} + +SCENARIO_METHOD(EnumParameterPF, "EnumParameter types", "[EnumParameter types]") +{ + GIVEN ("A valid XML structure file") { + THEN ("Start should succeed") { + CHECK_NOTHROW(start()); + REQUIRE_NOTHROW(setTuningMode(true)); + string path = "/test/test/nominal"; + + AND_THEN ("Set/Get a EnumParameter type parameter in real value space") { + + for (auto &vec : Tests{ + {"(not a number)", "foobar"}, + }) { + GIVEN ("Invalid value " + vec.title) { + CHECK_THROWS_AS(setParameter(path, vec.payload), Exception); + } + } + for (auto &vec : Tests{ + {"(upper limit)", "on"}, {"(lower limit)", "off"}, + }) { + GIVEN ("A valid value " + vec.title) { + CHECK_NOTHROW(setParameter(path, vec.payload)); + string getValueBack; + REQUIRE_NOTHROW(getParameter(path, getValueBack)); + CHECK(getValueBack == vec.payload); + } + } + } + + AND_THEN ("Set/Get a EnumParameter type parameter in raw value space") { + ElementHandle handle{*this, path}; + REQUIRE_NOTHROW(setRawValueSpace(true)); + + for (auto &vec : Tests{{"(too high)", "7"}, {"(too low)", "-1"}}) { + GIVEN ("Invalid value " + vec.title) { + CHECK_THROWS_AS(setParameter(path, vec.payload), Exception); + } + } + for (auto &vec : Tests{ + {"(upper limit)", "3"}, {"(lower limit)", "0"}, + }) { + GIVEN ("A valid value " + vec.title) { + CHECK_NOTHROW(setParameter(path, vec.payload)); + string getValueBack; + REQUIRE_NOTHROW(getParameter(path, getValueBack)); + CHECK(getValueBack == vec.payload); + } + } + + REQUIRE_NOTHROW(setHexOutputFormat(true)); + + for (auto &vec : Tests{{"(too high)", "0x7"}, {"(too low)", "0xFF"}}) { + GIVEN ("Invalid value " + vec.title) { + CHECK_THROWS_AS(setParameter(path, vec.payload), Exception); + } + } + for (auto &vec : Tests{ + {"(upper limit)", "0x03"}, {"(lower limit)", "0x00"}, + }) { + GIVEN ("A valid value " + vec.title) { + CHECK_NOTHROW(setParameter(path, vec.payload)); + string getValueBack; + REQUIRE_NOTHROW(getParameter(path, getValueBack)); + CHECK(getValueBack == vec.payload); + } + } + } + + AND_THEN ("Set/Get a EnumParameter type parameter in Integer value space") { + ElementHandle handle{*this, path}; + /** @FIXME: 'set' operations on a ParameterHandle are silently + * ignored in tuning mode. Does it make sense ? */ + REQUIRE_NOTHROW(setTuningMode(false)); + + for (auto &vec : Tests{ + {"(upper limit)", 3}, {"(lower limit)", 0}, + }) { + GIVEN ("A valid value " + vec.title) { + CHECK_NOTHROW(handle.setAsSignedInteger(vec.payload)); + int32_t getValueBack; + REQUIRE_NOTHROW(handle.getAsSignedInteger(getValueBack)); + CHECK(getValueBack == vec.payload); + } + } + for (auto &vec : Tests{ + {"(too high)", 13}, {"(too low)", -51}, + }) { + GIVEN ("An invalid value " + vec.title) { + CHECK_THROWS_AS(handle.setAsSignedInteger(vec.payload), Exception); + } + } + } + } + } +} +} diff --git a/test/functional-tests/Integer.cpp b/test/functional-tests/Integer.cpp index db39f8428..1a44ca3bc 100644 --- a/test/functional-tests/Integer.cpp +++ b/test/functional-tests/Integer.cpp @@ -130,6 +130,31 @@ SCENARIO_METHOD(IntegerPF, "Integer types", "[Integer types]") } } + AND_THEN ("Set/Get a integer type parameter in raw value space") { + REQUIRE_NOTHROW(setRawValueSpace(true)); + REQUIRE_NOTHROW(setHexOutputFormat(true)); + + for (auto &vec : Tests{ + {"(too high)", "0x0D"}, {"(too low)", "0xCD"}, + }) { + GIVEN ("Invalid value " + vec.title) { + CHECK_THROWS_AS(setParameter(path, vec.payload), Exception); + } + } + for (auto &vec : Tests{ + {"(upper limit)", "0x0C"}, + {"(lower limit)", "0xCE"}, + {"(inside range)", "0x00"}, + }) { + GIVEN ("A valid value " + vec.title) { + CHECK_NOTHROW(setParameter(path, vec.payload)); + string getValueBack; + REQUIRE_NOTHROW(getParameter(path, getValueBack)); + CHECK(getValueBack == vec.payload); + } + } + } + AND_THEN ("Set/Get integer type parameter handle") { ElementHandle handle{*this, path}; /** @FIXME: 'set' operations on a ParameterHandle are silently @@ -154,6 +179,30 @@ SCENARIO_METHOD(IntegerPF, "Integer types", "[Integer types]") } } } + + AND_THEN ("Set/Get double type parameter handle") { + ElementHandle handle{*this, path}; + /** @FIXME: 'set' operations on a ParameterHandle are silently + * ignored in tuning mode. Does it make sense ? */ + REQUIRE_NOTHROW(setTuningMode(false)); + + for (auto &vec : Tests{ + {"(upper limit)", 12.0f}, + {"(lower limit)", -50.0f}, + {"(inside range)", 0.0f}, + }) { + GIVEN ("A valid value (rejected not supported)" + vec.title) { + CHECK_THROWS_AS(handle.setAsDouble(vec.payload), Exception); + } + } + for (auto &vec : Tests{ + {"(too high)", 12.01f}, {"(too low)", -50.01f}, + }) { + GIVEN ("An invalid value " + vec.title) { + CHECK_THROWS_AS(handle.setAsDouble(vec.payload), Exception); + } + } + } } } } diff --git a/test/functional-tests/Linear.cpp b/test/functional-tests/Linear.cpp new file mode 100644 index 000000000..363567c06 --- /dev/null +++ b/test/functional-tests/Linear.cpp @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2017, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "Config.hpp" +#include "ParameterFramework.hpp" +#include "ElementHandle.hpp" +#include "Test.hpp" +#include "BinaryCopy.hpp" + +#include + +#include + +using std::string; + +namespace parameterFramework +{ + +const auto validLinearInstances = Config{ + &Config::instances, + // Size is fixed at 32 and as such is optional */ + R"( + )"}; +const auto &invalidLinearParameters = Tests{ + {"invalid Size(64)", " " + ""}, + {"minimum > maximum", " "}, + {"SlopeDenominator=0", + " " + " " + ""}}; + +struct LinearsPF : public ParameterFramework +{ + LinearsPF() : ParameterFramework{std::move(validLinearInstances)} {} +}; + +SCENARIO_METHOD(LazyPF, "Invalid Linear points XML structure", "[Linear Type]") +{ + for (auto &vec : invalidLinearParameters) { + GIVEN ("intentional error: " + vec.title) { + create(Config{&Config::instances, vec.payload}); + THEN ("Start should fail") { + CHECK_THROWS_AS(mPf->start(), Exception); + } + } + } +} + +SCENARIO_METHOD(LinearsPF, "Linear points", "[Linear Type]") +{ + GIVEN ("A valid XML structure file") { + THEN ("Start should succeed") { + CHECK_NOTHROW(start()); + REQUIRE_NOTHROW(setTuningMode(true)); + string path = "/test/test/nominal"; + AND_THEN ("Set/Get a Loagaritmic point parameter in real value space") { + + for (auto &vec : Tests{ + {"(too high)", "301"}, + {"(too low)", "-1441"}, + {"(not a number)", "foobar"}, + }) { + GIVEN ("Invalid value " + vec.title) { + CHECK_THROWS_AS(setParameter(path, vec.payload), Exception); + } + } + for (auto &vec : Tests{ + {"(upper limit)", "300"}, + {"(lower limit)", "-1440"}, + {"(inside range)", "0"}, + }) { + GIVEN ("A valid value " + vec.title) { + CHECK_NOTHROW(setParameter(path, vec.payload)); + string getValueBack = "-11"; + REQUIRE_NOTHROW(getParameter(path, getValueBack)); + CHECK(getValueBack == vec.payload); + } + } + } + + AND_THEN ("Set/Get double type parameter handle") { + ElementHandle handle{*this, path}; + /** @FIXME: 'set' operations on a ParameterHandle are silently + * ignored in tuning mode. Does it make sense ? */ + REQUIRE_NOTHROW(setTuningMode(false)); + REQUIRE_NOTHROW(setRawValueSpace(true)); + + /* nominal is defined as a Num=10,Denum=100 (division by 10). So limits should be 10 + * above Mina dn Max Integer value in order to get exception. */ + for (auto &vec : Tests{ + {"(upper limit)", 3000.0f}, + {"(lower limit)", -14400.0f}, + {"(inside range)", 0.0f}, + }) { + GIVEN ("A valid value " + vec.title) { + CHECK_NOTHROW(handle.setAsDouble(vec.payload)); + double getValueBack = 1.0f; + REQUIRE_NOTHROW(handle.getAsDouble(getValueBack)); + CHECK(getValueBack == vec.payload); + } + } + for (auto &vec : Tests{ + {"(too high)", 3010.0f}, {"(too low)", -14410.00f}, + }) { + GIVEN ("An invalid value " + vec.title) { + CHECK_THROWS_AS(handle.setAsDouble(vec.payload), Exception); + } + } + } + } + } +} +} // namespace parameterFramework diff --git a/test/functional-tests/Logarithmic.cpp b/test/functional-tests/Logarithmic.cpp new file mode 100644 index 000000000..137338e47 --- /dev/null +++ b/test/functional-tests/Logarithmic.cpp @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2015, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "Config.hpp" +#include "ParameterFramework.hpp" +#include "ElementHandle.hpp" +#include "Test.hpp" +#include "BinaryCopy.hpp" + +#include + +#include + +using std::string; + +namespace parameterFramework +{ + +const auto validLogarithmicInstances = Config{ + &Config::instances, + // Size is fixed at 32 and as such is optional */ + R"( + )"}; +const auto &invalidLogarithmicParameters = Tests{ + {"invalid Size(64)", " " + ""}, + {"minimum > maximum", " "}, + {"logBase =1", " " + " " + ""}, + {"logBase negative", " "}}; + +struct LogarithmicsPF : public ParameterFramework +{ + LogarithmicsPF() : ParameterFramework{std::move(validLogarithmicInstances)} {} +}; + +SCENARIO_METHOD(LazyPF, "Invalid Logarithmic points XML structure", "[Logarithmic Type]") +{ + for (auto &vec : invalidLogarithmicParameters) { + GIVEN ("intentional error: " + vec.title) { + create(Config{&Config::instances, vec.payload}); + THEN ("Start should fail") { + CHECK_THROWS_AS(mPf->start(), Exception); + } + } + } +} + +SCENARIO_METHOD(LogarithmicsPF, "Logarithmic points", "[Logarithmic Type]") +{ + GIVEN ("A valid XML structure file") { + THEN ("Start should succeed") { + CHECK_NOTHROW(start()); + REQUIRE_NOTHROW(setTuningMode(true)); + string path = "/test/test/nominal"; + AND_THEN ("Set/Get a Loagaritmic point parameter in real value space") { + + for (auto &vec : Tests{ + {"(too high)", "31"}, {"(too low)", "-145"}, {"(not a number)", "foobar"}, + }) { + GIVEN ("Invalid value " + vec.title) { + CHECK_THROWS_AS(setParameter(path, vec.payload), Exception); + } + } + for (auto &vec : Tests{ + {"(upper limit)", "30"}, + {"(lower limit)", "-144"}, + {"(inside range)", "0"}, + }) { + GIVEN ("A valid value " + vec.title) { + CHECK_NOTHROW(setParameter(path, vec.payload)); + string getValueBack; + REQUIRE_NOTHROW(getParameter(path, getValueBack)); + CHECK(getValueBack == vec.payload); + } + } + } + } + } +} +} // namespace parameterFramework diff --git a/test/functional-tests/include/ElementHandle.hpp b/test/functional-tests/include/ElementHandle.hpp index a2f547540..335ac6781 100644 --- a/test/functional-tests/include/ElementHandle.hpp +++ b/test/functional-tests/include/ElementHandle.hpp @@ -76,6 +76,9 @@ class ElementHandle : private FailureWrapper<::ElementHandle> /** Wrap EH::getAsDouble to throw an exception on failure. */ void getAsDouble(double &value) const { mayFailCall(&EH::getAsDouble, value); } + void setAsBoolean(bool value) { mayFailCall(&EH::setAsBoolean, value); } + void getAsBoolean(bool &value) const { mayFailCall(&EH::getAsBoolean, value); } + void setAsInteger(uint32_t value) { mayFailCall(&EH::setAsInteger, value); } void getAsInteger(uint32_t &value) const { mayFailCall(&EH::getAsInteger, value); } void setAsIntegerArray(const std::vector &value)