xref: /aosp_15_r20/external/parameter-framework/upstream/bindings/c/Test.cpp (revision c33452fb792a5495ec310a9626f2638b053af5dd)
1*c33452fbSAndroid Build Coastguard Worker /*
2*c33452fbSAndroid Build Coastguard Worker  * Copyright (c) 2015, Intel Corporation
3*c33452fbSAndroid Build Coastguard Worker  * All rights reserved.
4*c33452fbSAndroid Build Coastguard Worker  *
5*c33452fbSAndroid Build Coastguard Worker  * Redistribution and use in source and binary forms, with or without modification,
6*c33452fbSAndroid Build Coastguard Worker  * are permitted provided that the following conditions are met:
7*c33452fbSAndroid Build Coastguard Worker  *
8*c33452fbSAndroid Build Coastguard Worker  * 1. Redistributions of source code must retain the above copyright notice, this
9*c33452fbSAndroid Build Coastguard Worker  * list of conditions and the following disclaimer.
10*c33452fbSAndroid Build Coastguard Worker  *
11*c33452fbSAndroid Build Coastguard Worker  * 2. Redistributions in binary form must reproduce the above copyright notice,
12*c33452fbSAndroid Build Coastguard Worker  * this list of conditions and the following disclaimer in the documentation and/or
13*c33452fbSAndroid Build Coastguard Worker  * other materials provided with the distribution.
14*c33452fbSAndroid Build Coastguard Worker  *
15*c33452fbSAndroid Build Coastguard Worker  * 3. Neither the name of the copyright holder nor the names of its contributors
16*c33452fbSAndroid Build Coastguard Worker  * may be used to endorse or promote products derived from this software without
17*c33452fbSAndroid Build Coastguard Worker  * specific prior written permission.
18*c33452fbSAndroid Build Coastguard Worker  *
19*c33452fbSAndroid Build Coastguard Worker  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20*c33452fbSAndroid Build Coastguard Worker  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21*c33452fbSAndroid Build Coastguard Worker  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22*c33452fbSAndroid Build Coastguard Worker  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23*c33452fbSAndroid Build Coastguard Worker  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24*c33452fbSAndroid Build Coastguard Worker  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25*c33452fbSAndroid Build Coastguard Worker  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26*c33452fbSAndroid Build Coastguard Worker  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27*c33452fbSAndroid Build Coastguard Worker  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28*c33452fbSAndroid Build Coastguard Worker  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29*c33452fbSAndroid Build Coastguard Worker  */
30*c33452fbSAndroid Build Coastguard Worker 
31*c33452fbSAndroid Build Coastguard Worker #include "ParameterFramework.h"
32*c33452fbSAndroid Build Coastguard Worker 
33*c33452fbSAndroid Build Coastguard Worker #include "TmpFile.hpp"
34*c33452fbSAndroid Build Coastguard Worker 
35*c33452fbSAndroid Build Coastguard Worker #define CATCH_CONFIG_MAIN // This tells Catch to provide a main()
36*c33452fbSAndroid Build Coastguard Worker #include <catch.hpp>
37*c33452fbSAndroid Build Coastguard Worker 
38*c33452fbSAndroid Build Coastguard Worker #include <string>
39*c33452fbSAndroid Build Coastguard Worker #include <memory>
40*c33452fbSAndroid Build Coastguard Worker #include <vector>
41*c33452fbSAndroid Build Coastguard Worker #include <array>
42*c33452fbSAndroid Build Coastguard Worker 
43*c33452fbSAndroid Build Coastguard Worker #include <cstring>
44*c33452fbSAndroid Build Coastguard Worker #include <cerrno>
45*c33452fbSAndroid Build Coastguard Worker #include <climits>
46*c33452fbSAndroid Build Coastguard Worker 
47*c33452fbSAndroid Build Coastguard Worker struct Test
48*c33452fbSAndroid Build Coastguard Worker {
49*c33452fbSAndroid Build Coastguard Worker     /** @return true if str is empty. */
emptyTest50*c33452fbSAndroid Build Coastguard Worker     bool empty(const char *str)
51*c33452fbSAndroid Build Coastguard Worker     {
52*c33452fbSAndroid Build Coastguard Worker         REQUIRE(str != NULL);
53*c33452fbSAndroid Build Coastguard Worker         return *str == '\0';
54*c33452fbSAndroid Build Coastguard Worker     }
55*c33452fbSAndroid Build Coastguard Worker 
REQUIRE_FAILURETest56*c33452fbSAndroid Build Coastguard Worker     void REQUIRE_FAILURE(bool success)
57*c33452fbSAndroid Build Coastguard Worker     {
58*c33452fbSAndroid Build Coastguard Worker         THEN ("It should be an error") {
59*c33452fbSAndroid Build Coastguard Worker             INFO("Previous pfw log: \n" + logLines);
60*c33452fbSAndroid Build Coastguard Worker             CAPTURE(pfwGetLastError(pfw));
61*c33452fbSAndroid Build Coastguard Worker             CHECK(not success);
62*c33452fbSAndroid Build Coastguard Worker             CHECK(not empty(pfwGetLastError(pfw)));
63*c33452fbSAndroid Build Coastguard Worker         }
64*c33452fbSAndroid Build Coastguard Worker     }
65*c33452fbSAndroid Build Coastguard Worker 
REQUIRE_SUCCESSTest66*c33452fbSAndroid Build Coastguard Worker     void REQUIRE_SUCCESS(bool success)
67*c33452fbSAndroid Build Coastguard Worker     {
68*c33452fbSAndroid Build Coastguard Worker         THEN ("It should be a success") {
69*c33452fbSAndroid Build Coastguard Worker             INFO("Previous pfw log: \n" + logLines);
70*c33452fbSAndroid Build Coastguard Worker             CAPTURE(pfwGetLastError(pfw));
71*c33452fbSAndroid Build Coastguard Worker             CHECK(success);
72*c33452fbSAndroid Build Coastguard Worker             CHECK(empty(pfwGetLastError(pfw)));
73*c33452fbSAndroid Build Coastguard Worker         }
74*c33452fbSAndroid Build Coastguard Worker     }
75*c33452fbSAndroid Build Coastguard Worker 
76*c33452fbSAndroid Build Coastguard Worker     /** Wrap utility::TmpFile to add an implicit convertion to the temporary file.
77*c33452fbSAndroid Build Coastguard Worker      *
78*c33452fbSAndroid Build Coastguard Worker      * This avoids dozens of .getPath() in the following tests. */
79*c33452fbSAndroid Build Coastguard Worker     class TmpFile : private parameterFramework::utility::TmpFile
80*c33452fbSAndroid Build Coastguard Worker     {
81*c33452fbSAndroid Build Coastguard Worker     private:
82*c33452fbSAndroid Build Coastguard Worker         using Base = parameterFramework::utility::TmpFile;
83*c33452fbSAndroid Build Coastguard Worker 
84*c33452fbSAndroid Build Coastguard Worker     public:
85*c33452fbSAndroid Build Coastguard Worker         using Base::TmpFile;
86*c33452fbSAndroid Build Coastguard Worker 
87*c33452fbSAndroid Build Coastguard Worker         using Base::getPath;
88*c33452fbSAndroid Build Coastguard Worker         /** Implicitly convert to the path of the temporary file. */
operator const char*() const89*c33452fbSAndroid Build Coastguard Worker         operator const char *() const { return getPath().c_str(); }
90*c33452fbSAndroid Build Coastguard Worker     };
91*c33452fbSAndroid Build Coastguard Worker 
92*c33452fbSAndroid Build Coastguard Worker     /** Log in logLines. */
logCbTest93*c33452fbSAndroid Build Coastguard Worker     static void logCb(void *voidLogLines, PfwLogLevel level, const char *logLine)
94*c33452fbSAndroid Build Coastguard Worker     {
95*c33452fbSAndroid Build Coastguard Worker         std::string &logLines = *reinterpret_cast<std::string *>(voidLogLines);
96*c33452fbSAndroid Build Coastguard Worker         switch (level) {
97*c33452fbSAndroid Build Coastguard Worker         case pfwLogWarning:
98*c33452fbSAndroid Build Coastguard Worker             logLines += "Warning: ";
99*c33452fbSAndroid Build Coastguard Worker             break;
100*c33452fbSAndroid Build Coastguard Worker         case pfwLogInfo:
101*c33452fbSAndroid Build Coastguard Worker             logLines += "Info: ";
102*c33452fbSAndroid Build Coastguard Worker         }
103*c33452fbSAndroid Build Coastguard Worker         logLines += logLine;
104*c33452fbSAndroid Build Coastguard Worker         logLines += '\n';
105*c33452fbSAndroid Build Coastguard Worker     }
106*c33452fbSAndroid Build Coastguard Worker 
107*c33452fbSAndroid Build Coastguard Worker     /** Log buffer, will only be display in case of failure */
108*c33452fbSAndroid Build Coastguard Worker     std::string logLines;
109*c33452fbSAndroid Build Coastguard Worker 
110*c33452fbSAndroid Build Coastguard Worker     /** Pfw handler used in the tests. */
111*c33452fbSAndroid Build Coastguard Worker     PfwHandler *pfw;
112*c33452fbSAndroid Build Coastguard Worker };
113*c33452fbSAndroid Build Coastguard Worker 
114*c33452fbSAndroid Build Coastguard Worker TEST_CASE_METHOD(Test, "Parameter-framework c api use")
115*c33452fbSAndroid Build Coastguard Worker {
116*c33452fbSAndroid Build Coastguard Worker     // Create criteria
117*c33452fbSAndroid Build Coastguard Worker     const char *letterList[] = {"a", "b", "c", nullptr};
118*c33452fbSAndroid Build Coastguard Worker     const char *numberList[] = {"1", "2", "3", nullptr};
119*c33452fbSAndroid Build Coastguard Worker     const PfwCriterion criteria[] = {
120*c33452fbSAndroid Build Coastguard Worker         {"inclusiveCrit", true, letterList}, {"exclusiveCrit", false, numberList},
121*c33452fbSAndroid Build Coastguard Worker     };
122*c33452fbSAndroid Build Coastguard Worker     size_t criterionNb = sizeof(criteria) / sizeof(criteria[0]);
123*c33452fbSAndroid Build Coastguard Worker     PfwLogger logger = {&logLines, logCb};
124*c33452fbSAndroid Build Coastguard Worker 
125*c33452fbSAndroid Build Coastguard Worker     // Create valid pfw config file
126*c33452fbSAndroid Build Coastguard Worker     const char *intParameterPath = "/test/system/integer";
127*c33452fbSAndroid Build Coastguard Worker     const char *stringParameterPath = "/test/system/string";
128*c33452fbSAndroid Build Coastguard Worker     TmpFile system("<?xml version='1.0' encoding='UTF-8'?>\
129*c33452fbSAndroid Build Coastguard Worker         <Subsystem Name='system' Type='Virtual'>\
130*c33452fbSAndroid Build Coastguard Worker             <ComponentLibrary/>\
131*c33452fbSAndroid Build Coastguard Worker             <InstanceDefinition>\
132*c33452fbSAndroid Build Coastguard Worker                 <IntegerParameter Name='integer' Size='32' Signed='true' Max='100'/>\
133*c33452fbSAndroid Build Coastguard Worker                 <StringParameter Name='string' MaxLength='9'/>\
134*c33452fbSAndroid Build Coastguard Worker             </InstanceDefinition>\
135*c33452fbSAndroid Build Coastguard Worker         </Subsystem>");
136*c33452fbSAndroid Build Coastguard Worker     TmpFile libraries("<?xml version='1.0' encoding='UTF-8'?>\
137*c33452fbSAndroid Build Coastguard Worker         <SystemClass Name='test'>\
138*c33452fbSAndroid Build Coastguard Worker             <SubsystemInclude Path='" +
139*c33452fbSAndroid Build Coastguard Worker                       system.getPath() + "'/>\
140*c33452fbSAndroid Build Coastguard Worker         </SystemClass>");
141*c33452fbSAndroid Build Coastguard Worker     TmpFile config("<?xml version='1.0' encoding='UTF-8'?>\
142*c33452fbSAndroid Build Coastguard Worker         <ParameterFrameworkConfiguration\
143*c33452fbSAndroid Build Coastguard Worker             SystemClassName='test' TuningAllowed='false'>\
144*c33452fbSAndroid Build Coastguard Worker             <SubsystemPlugins/>\
145*c33452fbSAndroid Build Coastguard Worker             <StructureDescriptionFileLocation Path='" +
146*c33452fbSAndroid Build Coastguard Worker                    libraries.getPath() + "'/>\
147*c33452fbSAndroid Build Coastguard Worker         </ParameterFrameworkConfiguration>");
148*c33452fbSAndroid Build Coastguard Worker 
149*c33452fbSAndroid Build Coastguard Worker     GIVEN ("A created parameter framework") {
150*c33452fbSAndroid Build Coastguard Worker         pfw = pfwCreate();
151*c33452fbSAndroid Build Coastguard Worker         REQUIRE(pfw != NULL);
152*c33452fbSAndroid Build Coastguard Worker 
153*c33452fbSAndroid Build Coastguard Worker         THEN ("Error message should be empty") {
154*c33452fbSAndroid Build Coastguard Worker             CHECK(empty(pfwGetLastError(pfw)));
155*c33452fbSAndroid Build Coastguard Worker         }
156*c33452fbSAndroid Build Coastguard Worker 
157*c33452fbSAndroid Build Coastguard Worker         WHEN ("The pfw is started without an existent file") {
158*c33452fbSAndroid Build Coastguard Worker             REQUIRE_FAILURE(pfwStart(pfw, "/doNotExist", criteria, criterionNb, &logger));
159*c33452fbSAndroid Build Coastguard Worker         }
160*c33452fbSAndroid Build Coastguard Worker 
161*c33452fbSAndroid Build Coastguard Worker         WHEN ("The pfw is started with duplicated criterion value") {
162*c33452fbSAndroid Build Coastguard Worker             const PfwCriterion duplicatedCriteria[] = {
163*c33452fbSAndroid Build Coastguard Worker                 {"duplicated name", true, letterList}, {"duplicated name", false, numberList},
164*c33452fbSAndroid Build Coastguard Worker             };
165*c33452fbSAndroid Build Coastguard Worker             REQUIRE_FAILURE(pfwStart(pfw, config, duplicatedCriteria, 2, &logger));
166*c33452fbSAndroid Build Coastguard Worker         }
167*c33452fbSAndroid Build Coastguard Worker         WHEN ("The pfw is started with duplicated criterion value state") {
168*c33452fbSAndroid Build Coastguard Worker             const char *values[] = {"a", "a", nullptr};
169*c33452fbSAndroid Build Coastguard Worker             const PfwCriterion duplicatedCriteria[] = {{"name", true, values}};
170*c33452fbSAndroid Build Coastguard Worker 
171*c33452fbSAndroid Build Coastguard Worker             WHEN ("Using test logger") {
172*c33452fbSAndroid Build Coastguard Worker                 REQUIRE_FAILURE(pfwStart(pfw, config, duplicatedCriteria, 1, &logger));
173*c33452fbSAndroid Build Coastguard Worker             }
174*c33452fbSAndroid Build Coastguard Worker             WHEN ("Using default logger") {
175*c33452fbSAndroid Build Coastguard Worker                 // Test coverage of default logger warning
176*c33452fbSAndroid Build Coastguard Worker                 REQUIRE_FAILURE(pfwStart(pfw, config, duplicatedCriteria, 1, nullptr));
177*c33452fbSAndroid Build Coastguard Worker             }
178*c33452fbSAndroid Build Coastguard Worker         }
179*c33452fbSAndroid Build Coastguard Worker         WHEN ("The pfw is started with NULL name criterion") {
180*c33452fbSAndroid Build Coastguard Worker             const PfwCriterion duplicatedCriteria[] = {{nullptr, true, letterList}};
181*c33452fbSAndroid Build Coastguard Worker             REQUIRE_FAILURE(pfwStart(pfw, config, duplicatedCriteria, 1, &logger));
182*c33452fbSAndroid Build Coastguard Worker         }
183*c33452fbSAndroid Build Coastguard Worker         WHEN ("The pfw is started with NULL criterion state list") {
184*c33452fbSAndroid Build Coastguard Worker             const PfwCriterion duplicatedCriteria[] = {{"name", true, nullptr}};
185*c33452fbSAndroid Build Coastguard Worker             REQUIRE_FAILURE(pfwStart(pfw, config, duplicatedCriteria, 1, &logger));
186*c33452fbSAndroid Build Coastguard Worker         }
187*c33452fbSAndroid Build Coastguard Worker         GIVEN ("A criteria with lots of values") {
188*c33452fbSAndroid Build Coastguard Worker             // Build a criterion with as many value as there is bits in int.
189*c33452fbSAndroid Build Coastguard Worker             std::vector<char> names(sizeof(int) * CHAR_BIT + 1, 'a');
190*c33452fbSAndroid Build Coastguard Worker             names.back() = '\0';
191*c33452fbSAndroid Build Coastguard Worker             std::vector<const char *> values(names.size());
192*c33452fbSAndroid Build Coastguard Worker             for (size_t i = 0; i < values.size(); ++i) {
193*c33452fbSAndroid Build Coastguard Worker                 values[i] = &names[i];
194*c33452fbSAndroid Build Coastguard Worker             }
195*c33452fbSAndroid Build Coastguard Worker             values.back() = nullptr;
196*c33452fbSAndroid Build Coastguard Worker             /* The pfw c api requires criterion values to be a NULL terminated
197*c33452fbSAndroid Build Coastguard Worker              * array of string. Each string is a pointer to a NULL terminated
198*c33452fbSAndroid Build Coastguard Worker              * array of char. The pfw requires each string to be different
199*c33452fbSAndroid Build Coastguard Worker              * from all others, ie strcmp(values[i], values[j]) != 0 for any
200*c33452fbSAndroid Build Coastguard Worker              * i j.
201*c33452fbSAndroid Build Coastguard Worker              *
202*c33452fbSAndroid Build Coastguard Worker              * In order to generate easily an array of different strings,
203*c33452fbSAndroid Build Coastguard Worker              * instantiate one string (names) big enough
204*c33452fbSAndroid Build Coastguard Worker              * (@see PfwCriterion::values).
205*c33452fbSAndroid Build Coastguard Worker              * Then instantiate an array of pointer (values),
206*c33452fbSAndroid Build Coastguard Worker              * each pointing to a different position in the previously
207*c33452fbSAndroid Build Coastguard Worker              * created string.
208*c33452fbSAndroid Build Coastguard Worker              *
209*c33452fbSAndroid Build Coastguard Worker              * Representation of the names and values vectors.
210*c33452fbSAndroid Build Coastguard Worker              *
211*c33452fbSAndroid Build Coastguard Worker              * n = number of bit in an int
212*c33452fbSAndroid Build Coastguard Worker              *            <--- n+1 elements --->
213*c33452fbSAndroid Build Coastguard Worker              * names    = |a|a|a|a|...|a|a|a|\0|
214*c33452fbSAndroid Build Coastguard Worker              *             ^ ^             ^
215*c33452fbSAndroid Build Coastguard Worker              * values[0] = ´ |             |
216*c33452fbSAndroid Build Coastguard Worker              * values[1] = --´             |
217*c33452fbSAndroid Build Coastguard Worker              * ...                         |
218*c33452fbSAndroid Build Coastguard Worker              * values[n - 1] =  -----------´
219*c33452fbSAndroid Build Coastguard Worker              * values[n] = NULL
220*c33452fbSAndroid Build Coastguard Worker              *
221*c33452fbSAndroid Build Coastguard Worker              */
222*c33452fbSAndroid Build Coastguard Worker             const PfwCriterion duplicatedCriteria[] = {{"name", true, &values[0]}};
223*c33452fbSAndroid Build Coastguard Worker 
224*c33452fbSAndroid Build Coastguard Worker             WHEN ("The pfw is started with a too long criterion state list") {
225*c33452fbSAndroid Build Coastguard Worker                 REQUIRE_FAILURE(pfwStart(pfw, config, duplicatedCriteria, 1, &logger));
226*c33452fbSAndroid Build Coastguard Worker             }
227*c33452fbSAndroid Build Coastguard Worker             WHEN ("The pfw is started with max length criterion state list") {
228*c33452fbSAndroid Build Coastguard Worker                 values[values.size() - 2] = nullptr; // Hide last value
229*c33452fbSAndroid Build Coastguard Worker                 REQUIRE_SUCCESS(pfwStart(pfw, config, duplicatedCriteria, 1, &logger));
230*c33452fbSAndroid Build Coastguard Worker             }
231*c33452fbSAndroid Build Coastguard Worker         }
232*c33452fbSAndroid Build Coastguard Worker 
233*c33452fbSAndroid Build Coastguard Worker         WHEN ("The pfw is started with zero criteria") {
234*c33452fbSAndroid Build Coastguard Worker             REQUIRE_SUCCESS(pfwStart(pfw, config, criteria, 0, &logger));
235*c33452fbSAndroid Build Coastguard Worker         }
236*c33452fbSAndroid Build Coastguard Worker 
237*c33452fbSAndroid Build Coastguard Worker         WHEN ("The pfw is started twice a pfw") {
238*c33452fbSAndroid Build Coastguard Worker             REQUIRE_SUCCESS(pfwStart(pfw, config, criteria, criterionNb, &logger));
239*c33452fbSAndroid Build Coastguard Worker             REQUIRE_FAILURE(pfwStart(pfw, config, criteria, criterionNb, &logger));
240*c33452fbSAndroid Build Coastguard Worker         }
241*c33452fbSAndroid Build Coastguard Worker 
242*c33452fbSAndroid Build Coastguard Worker         WHEN ("The pfw is started without a logger callback") {
243*c33452fbSAndroid Build Coastguard Worker             PfwLogger noLog = {nullptr, nullptr};
244*c33452fbSAndroid Build Coastguard Worker             REQUIRE_SUCCESS(pfwStart(pfw, config, criteria, criterionNb, &noLog));
245*c33452fbSAndroid Build Coastguard Worker         }
246*c33452fbSAndroid Build Coastguard Worker         WHEN ("The pfw is started with default logger") {
247*c33452fbSAndroid Build Coastguard Worker             REQUIRE_SUCCESS(pfwStart(pfw, config, criteria, criterionNb, nullptr));
248*c33452fbSAndroid Build Coastguard Worker         }
249*c33452fbSAndroid Build Coastguard Worker 
250*c33452fbSAndroid Build Coastguard Worker         WHEN ("Get criterion of a stopped pfw") {
251*c33452fbSAndroid Build Coastguard Worker             int value;
252*c33452fbSAndroid Build Coastguard Worker             REQUIRE_FAILURE(pfwGetCriterion(pfw, criteria[0].name, &value));
253*c33452fbSAndroid Build Coastguard Worker         }
254*c33452fbSAndroid Build Coastguard Worker         WHEN ("Set criterion of a stopped pfw") {
255*c33452fbSAndroid Build Coastguard Worker             REQUIRE_FAILURE(pfwSetCriterion(pfw, criteria[0].name, 1));
256*c33452fbSAndroid Build Coastguard Worker         }
257*c33452fbSAndroid Build Coastguard Worker         WHEN ("Commit criteria of a stopped pfw") {
258*c33452fbSAndroid Build Coastguard Worker             REQUIRE_FAILURE(pfwApplyConfigurations(pfw));
259*c33452fbSAndroid Build Coastguard Worker         }
260*c33452fbSAndroid Build Coastguard Worker 
261*c33452fbSAndroid Build Coastguard Worker         WHEN ("Bind parameter with a stopped pfw") {
262*c33452fbSAndroid Build Coastguard Worker             REQUIRE(pfwBindParameter(pfw, intParameterPath) == NULL);
263*c33452fbSAndroid Build Coastguard Worker         }
264*c33452fbSAndroid Build Coastguard Worker 
265*c33452fbSAndroid Build Coastguard Worker         WHEN ("The pfw is started correctly") {
266*c33452fbSAndroid Build Coastguard Worker             REQUIRE_SUCCESS(pfwStart(pfw, config, criteria, criterionNb, &logger));
267*c33452fbSAndroid Build Coastguard Worker             int value;
268*c33452fbSAndroid Build Coastguard Worker 
269*c33452fbSAndroid Build Coastguard Worker             WHEN ("Get not existing criterion") {
270*c33452fbSAndroid Build Coastguard Worker                 REQUIRE_FAILURE(pfwGetCriterion(pfw, "Do not exist", &value));
271*c33452fbSAndroid Build Coastguard Worker             }
272*c33452fbSAndroid Build Coastguard Worker             THEN ("All criterion should value 0") {
273*c33452fbSAndroid Build Coastguard Worker                 for (size_t i = 0; i < criterionNb; ++i) {
274*c33452fbSAndroid Build Coastguard Worker                     const char *criterionName = criteria[i].name;
275*c33452fbSAndroid Build Coastguard Worker                     CAPTURE(criterionName);
276*c33452fbSAndroid Build Coastguard Worker                     REQUIRE_SUCCESS(pfwGetCriterion(pfw, criterionName, &value));
277*c33452fbSAndroid Build Coastguard Worker                     REQUIRE(value == 0);
278*c33452fbSAndroid Build Coastguard Worker                 }
279*c33452fbSAndroid Build Coastguard Worker             }
280*c33452fbSAndroid Build Coastguard Worker 
281*c33452fbSAndroid Build Coastguard Worker             WHEN ("Set not existing criterion") {
282*c33452fbSAndroid Build Coastguard Worker                 REQUIRE_FAILURE(pfwSetCriterion(pfw, "Do not exist", 3));
283*c33452fbSAndroid Build Coastguard Worker             }
284*c33452fbSAndroid Build Coastguard Worker             WHEN ("Set criterion value") {
285*c33452fbSAndroid Build Coastguard Worker                 for (size_t i = 0; i < criterionNb; ++i) {
286*c33452fbSAndroid Build Coastguard Worker                     const char *criterionName = criteria[i].name;
287*c33452fbSAndroid Build Coastguard Worker                     CAPTURE(criterionName);
288*c33452fbSAndroid Build Coastguard Worker                     REQUIRE_SUCCESS(pfwSetCriterion(pfw, criterionName, 3));
289*c33452fbSAndroid Build Coastguard Worker                 }
290*c33452fbSAndroid Build Coastguard Worker                 THEN ("Get criterion value should return what was set") {
291*c33452fbSAndroid Build Coastguard Worker                     for (size_t i = 0; i < criterionNb; ++i) {
292*c33452fbSAndroid Build Coastguard Worker                         const char *criterionName = criteria[i].name;
293*c33452fbSAndroid Build Coastguard Worker                         CAPTURE(criterionName);
294*c33452fbSAndroid Build Coastguard Worker                         REQUIRE_SUCCESS(pfwGetCriterion(pfw, criterionName, &value));
295*c33452fbSAndroid Build Coastguard Worker                         REQUIRE(value == 3);
296*c33452fbSAndroid Build Coastguard Worker                     }
297*c33452fbSAndroid Build Coastguard Worker                 }
298*c33452fbSAndroid Build Coastguard Worker                 WHEN ("Set a new value to a criterion without committing first") {
299*c33452fbSAndroid Build Coastguard Worker                     const char *criterionName = criteria[0].name;
300*c33452fbSAndroid Build Coastguard Worker                     REQUIRE_SUCCESS(pfwSetCriterion(pfw, criterionName, 0));
301*c33452fbSAndroid Build Coastguard Worker                     THEN ("A warning message should have been displayed") {
302*c33452fbSAndroid Build Coastguard Worker                         INFO("Previous pfw log: \n" + logLines);
303*c33452fbSAndroid Build Coastguard Worker                         size_t logPos = logLines.find("Warning: Selection criterion "
304*c33452fbSAndroid Build Coastguard Worker                                                       "'inclusiveCrit' has been modified 1 time(s)"
305*c33452fbSAndroid Build Coastguard Worker                                                       " without any configuration application");
306*c33452fbSAndroid Build Coastguard Worker                         CHECK(logPos != std::string::npos);
307*c33452fbSAndroid Build Coastguard Worker                     }
308*c33452fbSAndroid Build Coastguard Worker                 }
309*c33452fbSAndroid Build Coastguard Worker             }
310*c33452fbSAndroid Build Coastguard Worker             WHEN ("Commit criteria of a started pfw") {
311*c33452fbSAndroid Build Coastguard Worker                 REQUIRE_SUCCESS(pfwApplyConfigurations(pfw));
312*c33452fbSAndroid Build Coastguard Worker             }
313*c33452fbSAndroid Build Coastguard Worker             WHEN ("Bind a non existing parameter") {
314*c33452fbSAndroid Build Coastguard Worker                 REQUIRE_FAILURE(pfwBindParameter(pfw, "do/not/exist") != nullptr);
315*c33452fbSAndroid Build Coastguard Worker             }
316*c33452fbSAndroid Build Coastguard Worker 
317*c33452fbSAndroid Build Coastguard Worker             GIVEN ("An integer parameter handle") {
318*c33452fbSAndroid Build Coastguard Worker                 PfwParameterHandler *param = pfwBindParameter(pfw, intParameterPath);
319*c33452fbSAndroid Build Coastguard Worker                 REQUIRE_SUCCESS(param != nullptr);
320*c33452fbSAndroid Build Coastguard Worker 
321*c33452fbSAndroid Build Coastguard Worker                 WHEN ("Set parameter out of range") {
322*c33452fbSAndroid Build Coastguard Worker                     REQUIRE_FAILURE(pfwSetIntParameter(param, 101));
323*c33452fbSAndroid Build Coastguard Worker                 }
324*c33452fbSAndroid Build Coastguard Worker 
325*c33452fbSAndroid Build Coastguard Worker                 WHEN ("Set parameter") {
326*c33452fbSAndroid Build Coastguard Worker                     REQUIRE_SUCCESS(pfwSetIntParameter(param, 11));
327*c33452fbSAndroid Build Coastguard Worker                     THEN ("Get parameter should return what was set") {
328*c33452fbSAndroid Build Coastguard Worker                         REQUIRE_SUCCESS(pfwGetIntParameter(param, &value));
329*c33452fbSAndroid Build Coastguard Worker                         REQUIRE(value == 11);
330*c33452fbSAndroid Build Coastguard Worker                     }
331*c33452fbSAndroid Build Coastguard Worker                 }
332*c33452fbSAndroid Build Coastguard Worker 
333*c33452fbSAndroid Build Coastguard Worker                 pfwUnbindParameter(param);
334*c33452fbSAndroid Build Coastguard Worker             }
335*c33452fbSAndroid Build Coastguard Worker 
336*c33452fbSAndroid Build Coastguard Worker             GIVEN ("An string parameter handle") {
337*c33452fbSAndroid Build Coastguard Worker                 PfwParameterHandler *param = pfwBindParameter(pfw, stringParameterPath);
338*c33452fbSAndroid Build Coastguard Worker                 REQUIRE_SUCCESS(param != nullptr);
339*c33452fbSAndroid Build Coastguard Worker 
340*c33452fbSAndroid Build Coastguard Worker                 WHEN ("Set parameter out of range") {
341*c33452fbSAndroid Build Coastguard Worker                     REQUIRE_FAILURE(pfwSetStringParameter(param, "ko_1234567"));
342*c33452fbSAndroid Build Coastguard Worker                 }
343*c33452fbSAndroid Build Coastguard Worker 
344*c33452fbSAndroid Build Coastguard Worker                 WHEN ("Set parameter") {
345*c33452fbSAndroid Build Coastguard Worker                     char *value;
346*c33452fbSAndroid Build Coastguard Worker                     REQUIRE_SUCCESS(pfwSetStringParameter(param, "ok"));
347*c33452fbSAndroid Build Coastguard Worker                     THEN ("Get parameter should return what was set") {
348*c33452fbSAndroid Build Coastguard Worker                         REQUIRE_SUCCESS(pfwGetStringParameter(param, &value));
349*c33452fbSAndroid Build Coastguard Worker                         REQUIRE(value == std::string("ok"));
350*c33452fbSAndroid Build Coastguard Worker                         pfwFree(value);
351*c33452fbSAndroid Build Coastguard Worker                     }
352*c33452fbSAndroid Build Coastguard Worker                 }
353*c33452fbSAndroid Build Coastguard Worker 
354*c33452fbSAndroid Build Coastguard Worker                 pfwUnbindParameter(param);
355*c33452fbSAndroid Build Coastguard Worker             }
356*c33452fbSAndroid Build Coastguard Worker         }
357*c33452fbSAndroid Build Coastguard Worker 
358*c33452fbSAndroid Build Coastguard Worker         pfwDestroy(pfw);
359*c33452fbSAndroid Build Coastguard Worker     }
360*c33452fbSAndroid Build Coastguard Worker }
361