|
| 1 | +/* |
| 2 | + * Copyright (c) 2016, Intel Corporation |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * Redistribution and use in source and binary forms, with or without modification, |
| 6 | + * are permitted provided that the following conditions are met: |
| 7 | + * |
| 8 | + * 1. Redistributions of source code must retain the above copyright notice, this |
| 9 | + * list of conditions and the following disclaimer. |
| 10 | + * |
| 11 | + * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 12 | + * this list of conditions and the following disclaimer in the documentation and/or |
| 13 | + * other materials provided with the distribution. |
| 14 | + * |
| 15 | + * 3. Neither the name of the copyright holder nor the names of its contributors |
| 16 | + * may be used to endorse or promote products derived from this software without |
| 17 | + * specific prior written permission. |
| 18 | + * |
| 19 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 20 | + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 21 | + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 22 | + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
| 23 | + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 24 | + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 25 | + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
| 26 | + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 28 | + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | + */ |
| 30 | + |
| 31 | +#include "Config.hpp" |
| 32 | +#include "ParameterFramework.hpp" |
| 33 | +#include "ElementHandle.hpp" |
| 34 | +#include "Test.hpp" |
| 35 | +#include "BinaryCopy.hpp" |
| 36 | + |
| 37 | +#include <catch.hpp> |
| 38 | + |
| 39 | +#include <string> |
| 40 | + |
| 41 | +using std::string; |
| 42 | + |
| 43 | +namespace parameterFramework |
| 44 | +{ |
| 45 | + |
| 46 | +const auto validIntegerInstances = Config{&Config::instances, |
| 47 | + // Default for integers is unsigned/32bits |
| 48 | + R"(<IntegerParameter Name="Empty"/> |
| 49 | + <IntegerParameter Name="trivial" Size="8" Signed="true"/> |
| 50 | + <IntegerParameter Name="nominal" Size="8" Signed="true" Min="-50" Max="12"/> |
| 51 | + <IntegerParameter Name="negMinMaxS8" Size="8" Signed="true" Min="-120" Max="-110"/> |
| 52 | + <IntegerParameter Name="posMinMaxS8" Size="8" Signed="true" Min="90" Max="100"/> |
| 53 | + <IntegerParameter Name="defaultMinS8" Size="8" Signed="true" Min="-128"/> |
| 54 | + <IntegerParameter Name="defaultMaxS8" Size="8" Signed="true" Max="127"/> |
| 55 | + <IntegerParameter Name="defaultMinU8" Size="8" Signed="false" Min="0"/> |
| 56 | + <IntegerParameter Name="defaultMaxU8" Size="8" Signed="false" Max="255"/> |
| 57 | + <IntegerParameter Name="defaultMinS16" Size="16" Signed="true" Min="-32768"/> |
| 58 | + <IntegerParameter Name="defaultMaxS16" Size="16" Signed="true" Max="32767"/> |
| 59 | + <IntegerParameter Name="defaultMinU16" Size="16" Signed="false" Min="0"/> |
| 60 | + <IntegerParameter Name="defaultMaxU16" Size="16" Signed="false" Max="65535"/> |
| 61 | + <IntegerParameter Name="defaultMinS32" Size="32" Signed="true" Min="-2147483648"/> |
| 62 | + <IntegerParameter Name="defaultMaxS32" Size="32" Signed="true" Max="2147483647"/> |
| 63 | + <IntegerParameter Name="defaultMinU32" Size="32" Signed="false" Min="0"/> |
| 64 | + <IntegerParameter Name="defaultMaxU32" Size="32" Signed="false" Max="4294967295"/>)"}; |
| 65 | +const auto &invalidIntegerParameters = Tests<string>{ |
| 66 | + {"invalid Size(64)", "<IntegerParameter Name='error' Size='64'/>"}, |
| 67 | + {"minimum > maximum", "<IntegerParameter Name='error' Min='1' Max='0'/>"}, |
| 68 | + {"S8 minimum > MaxRange", "<IntegerParameter Name='error' Size='8' Signed='true' Min='128'/>"}, |
| 69 | + {"S8 minimum < MinRange", "<IntegerParameter Name='error' Size='8' Signed='true' Min='-129'/>"}, |
| 70 | + {"S8 maximum > MaxRange", "<IntegerParameter Name='error' Size='8' Signed='true' Max='128'/>"}, |
| 71 | + {"S8 maximum < MinRange", "<IntegerParameter Name='error' Size='8' Signed='true' Max='-129'/>"}, |
| 72 | + {"U8 minimum > MaxRange", "<IntegerParameter Name='error' Size='8' Signed='false' Min='256'/>"}, |
| 73 | + {"U8 maximum > MaxRange", "<IntegerParameter Name='error' Size='8' Signed='false' Max='256'/>"}, |
| 74 | + {"S16 minimum > MaxRange", |
| 75 | + "<IntegerParameter Name='error' Size='16' Signed='true' Min='32768'/>"}, |
| 76 | + {"S16 minimum < MinRange", |
| 77 | + "<IntegerParameter Name='error' Size='16' Signed='true' Min='-32769'/>"}, |
| 78 | + {"S16 maximum > MaxRange", |
| 79 | + "<IntegerParameter Name='error' Size='16' Signed='true' Max='32768'/>"}, |
| 80 | + {"S16 maximum < MinRange", |
| 81 | + "<IntegerParameter Name='error' Size='16' Signed='true' Max='-32769'/>"}, |
| 82 | + {"U16 minimum > MaxRange", |
| 83 | + "<IntegerParameter Name='error' Size='16' Signed='false' Min='65536'/>"}, |
| 84 | + {"U16 maximum > MaxRange", |
| 85 | + "<IntegerParameter Name='error' Size='16' Signed='false' Max='65536'/>"}}; |
| 86 | + |
| 87 | +struct IntegerPF : public ParameterFramework |
| 88 | +{ |
| 89 | + IntegerPF() : ParameterFramework{std::move(validIntegerInstances)} {} |
| 90 | +}; |
| 91 | + |
| 92 | +SCENARIO_METHOD(LazyPF, "Invalid Integer types XML structure", "[Integer types]") |
| 93 | +{ |
| 94 | + for (auto &vec : invalidIntegerParameters) { |
| 95 | + GIVEN ("intentional error: " + vec.title) { |
| 96 | + create(Config{&Config::instances, vec.payload}); |
| 97 | + THEN ("Start should fail") { |
| 98 | + CHECK_THROWS_AS(mPf->start(), Exception); |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | +} |
| 103 | + |
| 104 | +SCENARIO_METHOD(IntegerPF, "Integer types", "[Integer types]") |
| 105 | +{ |
| 106 | + GIVEN ("A valid XML structure file") { |
| 107 | + THEN ("Start should succeed") { |
| 108 | + CHECK_NOTHROW(start()); |
| 109 | + REQUIRE_NOTHROW(setTuningMode(true)); |
| 110 | + string path = "/test/test/nominal"; |
| 111 | + |
| 112 | + AND_THEN ("Set/Get a integer type parameter in real value space") { |
| 113 | + |
| 114 | + for (auto &vec : Tests<string>{ |
| 115 | + {"(too high)", "13"}, {"(too low)", "-51"}, {"(not a number)", "foobar"}, |
| 116 | + }) { |
| 117 | + GIVEN ("Invalid value " + vec.title) { |
| 118 | + CHECK_THROWS_AS(setParameter(path, vec.payload), Exception); |
| 119 | + } |
| 120 | + } |
| 121 | + for (auto &vec : Tests<string>{ |
| 122 | + {"(upper limit)", "12"}, {"(lower limit)", "-50"}, {"(inside range)", "0"}, |
| 123 | + }) { |
| 124 | + GIVEN ("A valid value " + vec.title) { |
| 125 | + CHECK_NOTHROW(setParameter(path, vec.payload)); |
| 126 | + string getValueBack; |
| 127 | + REQUIRE_NOTHROW(getParameter(path, getValueBack)); |
| 128 | + CHECK(getValueBack == vec.payload); |
| 129 | + } |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + AND_THEN ("Set/Get integer type parameter handle") { |
| 134 | + ElementHandle handle{*this, path}; |
| 135 | + /** @FIXME: 'set' operations on a ParameterHandle are silently |
| 136 | + * ignored in tuning mode. Does it make sense ? */ |
| 137 | + REQUIRE_NOTHROW(setTuningMode(false)); |
| 138 | + |
| 139 | + for (auto &vec : Tests<int32_t>{ |
| 140 | + {"(upper limit)", 12}, {"(lower limit)", -50}, {"(inside range)", 0}, |
| 141 | + }) { |
| 142 | + GIVEN ("A valid value " + vec.title) { |
| 143 | + CHECK_NOTHROW(handle.setAsSignedInteger(vec.payload)); |
| 144 | + int32_t getValueBack; |
| 145 | + REQUIRE_NOTHROW(handle.getAsSignedInteger(getValueBack)); |
| 146 | + CHECK(getValueBack == vec.payload); |
| 147 | + } |
| 148 | + } |
| 149 | + for (auto &vec : Tests<int32_t>{ |
| 150 | + {"(too high)", 13}, {"(too low)", -51}, |
| 151 | + }) { |
| 152 | + GIVEN ("An invalid value " + vec.title) { |
| 153 | + CHECK_THROWS_AS(handle.setAsSignedInteger(vec.payload), Exception); |
| 154 | + } |
| 155 | + } |
| 156 | + } |
| 157 | + } |
| 158 | + } |
| 159 | +} |
| 160 | +} |
0 commit comments