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

Commit 3477290

Browse files
author
Sebastien Guiriec
committed
Functional test: Add Boolean type parameter tests.
This pathc is improving Boolean parameter Ynit test for setting in the different possible formats. Signed-off-by: Sebastien Guiriec <[email protected]>
1 parent 73a8db8 commit 3477290

File tree

2 files changed

+149
-0
lines changed

2 files changed

+149
-0
lines changed

test/functional-tests/Boolean.cpp

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

test/functional-tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ if(BUILD_TESTING)
3535
# Add unit test
3636
add_executable(parameterFunctionalTest
3737
Basic.cpp
38+
Boolean.cpp
3839
FloatingPoint.cpp
3940
FixedPoint.cpp
4041
Integer.cpp

0 commit comments

Comments
 (0)