/* * Copyright (c) 2016, 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 validIntegerInstances = Config{&Config::instances, // Default for integers is unsigned/32bits R"( )"}; const auto &invalidIntegerParameters = Tests{ {"invalid Size(64)", ""}, {"minimum > maximum", ""}, {"S8 minimum > MaxRange", ""}, {"S8 minimum < MinRange", ""}, {"S8 maximum > MaxRange", ""}, {"S8 maximum < MinRange", ""}, {"U8 minimum > MaxRange", ""}, {"U8 maximum > MaxRange", ""}, {"S16 minimum > MaxRange", ""}, {"S16 minimum < MinRange", ""}, {"S16 maximum > MaxRange", ""}, {"S16 maximum < MinRange", ""}, {"U16 minimum > MaxRange", ""}, {"U16 maximum > MaxRange", ""}}; struct IntegerPF : public ParameterFramework { IntegerPF() : ParameterFramework{std::move(validIntegerInstances)} {} }; SCENARIO_METHOD(LazyPF, "Invalid Integer types XML structure", "[Integer types]") { for (auto &vec : invalidIntegerParameters) { GIVEN ("intentional error: " + vec.title) { create(Config{&Config::instances, vec.payload}); THEN ("Start should fail") { CHECK_THROWS_AS(mPf->start(), Exception); } } } } SCENARIO_METHOD(IntegerPF, "Integer types", "[Integer 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 integer type parameter in real value space") { for (auto &vec : Tests{ {"(too high)", "13"}, {"(too low)", "-51"}, {"(not a number)", "foobar"}, }) { GIVEN ("Invalid value " + vec.title) { CHECK_THROWS_AS(setParameter(path, vec.payload), Exception); } } for (auto &vec : Tests{ {"(upper limit)", "12"}, {"(lower limit)", "-50"}, {"(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); } } } 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 * ignored in tuning mode. Does it make sense ? */ REQUIRE_NOTHROW(setTuningMode(false)); for (auto &vec : Tests{ {"(upper limit)", 12}, {"(lower limit)", -50}, {"(inside range)", 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); } } } 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); } } } } } } }