Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit e678467

Browse files
author
Sebastien Guiriec
authored
Merge pull request #402 from sguiriec/topic/coverage
Functional test: Add logarithmic format test
2 parents cf265b1 + 36497d5 commit e678467

File tree

9 files changed

+811
-0
lines changed

9 files changed

+811
-0
lines changed

parameter/BooleanParameterType.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ bool CBooleanParameterType::toBlackboard(uint32_t uiUserValue, uint32_t &uiValue
108108
if (uiUserValue > 1) {
109109

110110
parameterAccessContext.setError("Value out of range");
111+
return false;
111112
}
112113

113114
uiValue = uiUserValue;
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
/*
2+
* Copyright (c) 2017, 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+
36+
#include <catch.hpp>
37+
38+
#include <string>
39+
40+
using std::string;
41+
42+
namespace parameterFramework
43+
{
44+
45+
const auto validBitParameterInstances = Config{
46+
&Config::instances,
47+
// Default for integers is unsigned/32bits
48+
R"(<BitParameterBlock Name="nominal" Size="16"><BitParameter Pos="0" Size="1" Name="bool"/><BitParameter Pos="1" Size="2" Name="twobits"/><BitParameter Pos="3" Size="3" Max="6" Name="treebits"/></BitParameterBlock>)"};
49+
50+
const auto &invalidBitParameterParameters =
51+
Tests<string>{{"Too much bits", "<BitParameterBlock Name='toomuchbits' Size='8'><BitParameter "
52+
"Pos='1' Size='2' Name='twobits'/><BitParameter Pos='3' "
53+
"Size='7' Name='toobits'/></BitParameterBlock>"},
54+
{"Max too high", "<BitParameterBlock Name='maxtoohigh' Size='8'><BitParameter "
55+
"Pos='1' Size='2' Name='twobits'/><BitParameter Pos='3' "
56+
"Size='2' Max='5' Name='toohigh'/></BitParameterBlock>"}};
57+
58+
struct BitParameterPF : public ParameterFramework
59+
{
60+
BitParameterPF() : ParameterFramework{std::move(validBitParameterInstances)} {}
61+
};
62+
63+
SCENARIO_METHOD(LazyPF, "Invalid BitParameter types XML structure", "[BitParameter types]")
64+
{
65+
for (auto &vec : invalidBitParameterParameters) {
66+
GIVEN ("intentional error: " + vec.title) {
67+
create(Config{&Config::instances, vec.payload});
68+
THEN ("Start should fail") {
69+
CHECK_THROWS_AS(mPf->start(), Exception);
70+
}
71+
}
72+
}
73+
}
74+
75+
SCENARIO_METHOD(BitParameterPF, "BitParameter types", "[BitParameter types]")
76+
{
77+
GIVEN ("A valid XML structure file") {
78+
THEN ("Start should succeed") {
79+
CHECK_NOTHROW(start());
80+
REQUIRE_NOTHROW(setTuningMode(true));
81+
string path = "/test/test/nominal/treebits";
82+
83+
AND_THEN ("Set/Get a BitParameter type parameter in real value space") {
84+
85+
for (auto &vec : Tests<string>{
86+
{"(too high)", "7"}, {"(too low)", "-1"},
87+
}) {
88+
GIVEN ("Invalid value " + vec.title) {
89+
CHECK_THROWS_AS(setParameter(path, vec.payload), Exception);
90+
}
91+
}
92+
for (auto &vec : Tests<string>{
93+
{"(upper limit)", "6"}, {"(lower limit)", "0"},
94+
}) {
95+
GIVEN ("A valid value " + vec.title) {
96+
CHECK_NOTHROW(setParameter(path, vec.payload));
97+
string getValueBack;
98+
REQUIRE_NOTHROW(getParameter(path, getValueBack));
99+
CHECK(getValueBack == vec.payload);
100+
}
101+
}
102+
}
103+
104+
AND_THEN ("Set/Get a BitParameter type parameter in real value space") {
105+
ElementHandle handle{*this, path};
106+
REQUIRE_NOTHROW(setRawValueSpace(true));
107+
REQUIRE_NOTHROW(setHexOutputFormat(true));
108+
109+
for (auto &vec : Tests<string>{
110+
{"(too high)", "0x7"},
111+
}) {
112+
GIVEN ("Invalid value " + vec.title) {
113+
CHECK_THROWS_AS(setParameter(path, vec.payload), Exception);
114+
}
115+
}
116+
for (auto &vec : Tests<string>{
117+
{"(upper limit)", "0x6"}, {"(lower limit)", "0x0"},
118+
}) {
119+
GIVEN ("A valid value " + vec.title) {
120+
CHECK_NOTHROW(setParameter(path, vec.payload));
121+
string getValueBack;
122+
REQUIRE_NOTHROW(getParameter(path, getValueBack));
123+
CHECK(getValueBack == vec.payload);
124+
}
125+
}
126+
}
127+
128+
AND_THEN ("Set/Get a BitParameter type parameter in boolean") {
129+
ElementHandle handle{*this, path};
130+
/** @FIXME: 'set' operations on a ParameterHandle are silently
131+
* ignored in tuning mode. Does it make sense ? */
132+
REQUIRE_NOTHROW(setTuningMode(false));
133+
134+
for (auto &vec : Tests<bool>{
135+
{"(upper limit)", true}, {"(lower limit)", false},
136+
}) {
137+
GIVEN ("Invalid value " + vec.title) {
138+
CHECK_THROWS_AS(handle.setAsBoolean(vec.payload), Exception);
139+
}
140+
}
141+
}
142+
143+
AND_THEN ("Set/Get a BitParameter type parameter in boolean") {
144+
path = "/test/test/nominal/bool";
145+
ElementHandle handle{*this, path};
146+
/** @FIXME: 'set' operations on a ParameterHandle are silently
147+
* ignored in tuning mode. Does it make sense ? */
148+
REQUIRE_NOTHROW(setTuningMode(false));
149+
150+
for (auto &vec : Tests<bool>{
151+
{"(upper limit)", true}, {"(lower limit)", false},
152+
}) {
153+
GIVEN ("A valid value " + vec.title) {
154+
CHECK_NOTHROW(handle.setAsBoolean(vec.payload));
155+
bool getValueBack;
156+
REQUIRE_NOTHROW(handle.getAsBoolean(getValueBack));
157+
CHECK(getValueBack == vec.payload);
158+
}
159+
}
160+
}
161+
}
162+
}
163+
}
164+
}

test/functional-tests/Boolean.cpp

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
/*
2+
* Copyright (c) 2017, 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+
36+
#include <catch.hpp>
37+
38+
#include <string>
39+
40+
using std::string;
41+
42+
namespace parameterFramework
43+
{
44+
45+
const auto validBooleanInstances = Config{&Config::instances,
46+
// Default for integers is unsigned/32bits
47+
R"(<BooleanParameter Name="Empty"/>
48+
<BooleanParameter Name="nominal"/>)"};
49+
50+
struct BooleanPF : public ParameterFramework
51+
{
52+
BooleanPF() : ParameterFramework{std::move(validBooleanInstances)} {}
53+
};
54+
55+
SCENARIO_METHOD(BooleanPF, "Boolean types", "[Boolean types]")
56+
{
57+
GIVEN ("A valid XML structure file") {
58+
THEN ("Start should succeed") {
59+
CHECK_NOTHROW(start());
60+
REQUIRE_NOTHROW(setTuningMode(true));
61+
string path = "/test/test/nominal";
62+
63+
AND_THEN ("Set/Get a Boolean type parameter in real value space") {
64+
65+
for (auto &vec : Tests<string>{
66+
{"(too high)", "2"}, {"(too low)", "-1"}, {"(not a number)", "foobar"},
67+
}) {
68+
GIVEN ("Invalid value " + vec.title) {
69+
CHECK_THROWS_AS(setParameter(path, vec.payload), Exception);
70+
}
71+
}
72+
for (auto &vec : Tests<string>{
73+
{"(upper limit)", "1"}, {"(lower limit)", "0"},
74+
}) {
75+
GIVEN ("A valid value " + vec.title) {
76+
CHECK_NOTHROW(setParameter(path, vec.payload));
77+
string getValueBack;
78+
REQUIRE_NOTHROW(getParameter(path, getValueBack));
79+
CHECK(getValueBack == vec.payload);
80+
}
81+
}
82+
}
83+
84+
AND_THEN ("Set/Get boolean type parameter handle") {
85+
ElementHandle handle{*this, path};
86+
/** @FIXME: 'set' operations on a ParameterHandle are silently
87+
* ignored in tuning mode. Does it make sense ? */
88+
REQUIRE_NOTHROW(setTuningMode(false));
89+
90+
for (auto &vec : Tests<bool>{
91+
{"(upper limit)", true}, {"(lower limit)", false},
92+
}) {
93+
GIVEN ("A valid value " + vec.title) {
94+
CHECK_NOTHROW(handle.setAsBoolean(vec.payload));
95+
bool getValueBack;
96+
REQUIRE_NOTHROW(handle.getAsBoolean(getValueBack));
97+
CHECK(getValueBack == vec.payload);
98+
}
99+
}
100+
}
101+
102+
AND_THEN ("Set/Get integer type parameter handle") {
103+
ElementHandle handle{*this, path};
104+
/** @FIXME: 'set' operations on a ParameterHandle are silently
105+
* ignored in tuning mode. Does it make sense ? */
106+
REQUIRE_NOTHROW(setTuningMode(false));
107+
108+
for (auto &vec : Tests<uint32_t>{
109+
{"(upper limit)", 1}, {"(lower limit)", 0},
110+
}) {
111+
GIVEN ("A valid value " + vec.title) {
112+
CHECK_NOTHROW(handle.setAsInteger(vec.payload));
113+
uint32_t getValueBack;
114+
REQUIRE_NOTHROW(handle.getAsInteger(getValueBack));
115+
CHECK(getValueBack == vec.payload);
116+
}
117+
}
118+
for (auto &vec : Tests<uint32_t>{
119+
{"(too high)", 2},
120+
}) {
121+
GIVEN ("An invalid value " + vec.title) {
122+
CHECK_THROWS_AS(handle.setAsInteger(vec.payload), Exception);
123+
}
124+
}
125+
}
126+
127+
AND_THEN ("Set/Get a Boolean type parameter in real value space") {
128+
ElementHandle handle{*this, path};
129+
REQUIRE_NOTHROW(setRawValueSpace(true));
130+
131+
for (auto &vec : Tests<string>{
132+
{"(too high hexa)", "0x2"},
133+
{"(too high dec)", "2"},
134+
{"(too low hexa )", "0xFF"},
135+
{"(not a number)", "foobar"},
136+
}) {
137+
GIVEN ("Invalid value " + vec.title) {
138+
CHECK_THROWS_AS(setParameter(path, vec.payload), Exception);
139+
}
140+
}
141+
for (auto &vec : Tests<string>{
142+
{"(TRUE hexa)", "0x1"}, {"(TRUE dec)", "1"},
143+
}) {
144+
GIVEN ("A valid value " + vec.title) {
145+
CHECK_NOTHROW(setParameter(path, vec.payload));
146+
string getValueBack;
147+
REQUIRE_NOTHROW(getParameter(path, getValueBack));
148+
CHECK(getValueBack == "1");
149+
}
150+
}
151+
for (auto &vec : Tests<string>{
152+
{"(FALSE hexa)", "0x0"}, {"(FALSE dec)", "0"},
153+
}) {
154+
GIVEN ("A valid value " + vec.title) {
155+
CHECK_NOTHROW(setParameter(path, vec.payload));
156+
string getValueBack;
157+
REQUIRE_NOTHROW(getParameter(path, getValueBack));
158+
CHECK(getValueBack == "0");
159+
}
160+
}
161+
}
162+
}
163+
}
164+
}
165+
}

test/functional-tests/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,14 @@ if(BUILD_TESTING)
3535
# Add unit test
3636
add_executable(parameterFunctionalTest
3737
Basic.cpp
38+
Boolean.cpp
39+
BitParameter.cpp
40+
EnumParameter.cpp
3841
FloatingPoint.cpp
3942
FixedPoint.cpp
4043
Integer.cpp
44+
Linear.cpp
45+
Logarithmic.cpp
4146
Handle.cpp
4247
AutoSync.cpp)
4348

0 commit comments

Comments
 (0)