• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2015, 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 "DynamicLibrary.hpp"
34 #include <SubsystemObject.h>
35 #include <IntrospectionEntryPoint.h>
36 #include "Test.hpp"
37 #include <catch.hpp>
38 #include <string>
39 #include <iostream>
40 #include "Memory.hpp"
41 
42 using std::string;
43 
44 namespace parameterFramework
45 {
46 
47 struct BoolPF : public ParameterFramework
48 {
BoolPFparameterFramework::BoolPF49     BoolPF() : ParameterFramework{createConfig()}
50     {
51 
52         mDynamicLibrary = ::utility::make_unique<DynamicLibrary>(mSubsystemPath);
53         REQUIRE(mDynamicLibrary != nullptr);
54         mGetParamFunc = mDynamicLibrary->getSymbol<GetParamFunc>("getParameterValue");
55         REQUIRE(mGetParamFunc != nullptr);
56     }
57 
58     /** Set the boolean parameter value within the "Conf" configuration,
59      * which is always applicable. */
setParameterValueparameterFramework::BoolPF60     void setParameterValue(bool value)
61     {
62         std::string valueStr = value ? "1" : "0";
63         setConfigurationParameter("Domain", "Conf", "/test/test/param", valueStr);
64     }
65 
getParameterValueparameterFramework::BoolPF66     bool getParameterValue() { return mGetParamFunc(); }
67 
68 private:
createConfigparameterFramework::BoolPF69     static Config createConfig()
70     {
71         Config config;
72         config.instances = R"(<BooleanParameter Name="param" Mapping="Object"/>)";
73         config.plugins = {{PLUGIN_PATH, {PLUGIN_NAME}}};
74         config.subsystemType = "INTROSPECTION";
75         config.domains = R"(<ConfigurableDomain Name="Domain">
76                                 <Configurations>
77                                     <Configuration Name="Conf">
78                                         <CompoundRule Type="All"/>
79                                     </Configuration>
80                                 </Configurations>
81 
82                                 <ConfigurableElements>
83                                     <ConfigurableElement Path="/test/test/param"/>
84                                 </ConfigurableElements>
85 
86                                 <Settings>
87                                     <Configuration Name="Conf">
88                                         <ConfigurableElement Path="/test/test/param">
89                                             <BooleanParameter Name="param">0</BooleanParameter>
90                                         </ConfigurableElement>
91                                     </Configuration>
92                                 </Settings>
93                             </ConfigurableDomain>)";
94 
95         return config;
96     }
97 
98     using GetParamFunc = bool (*)();
99     std::string mSubsystemPath = std::string(PLUGIN_PATH) + (*PLUGIN_PATH ? "/" : "") + PLUGIN_NAME;
100     std::unique_ptr<DynamicLibrary> mDynamicLibrary;
101     bool (*mGetParamFunc)();
102 };
103 
104 SCENARIO_METHOD(BoolPF, "Auto sync")
105 {
106     GIVEN ("A Pfw that starts") {
107         REQUIRE_NOTHROW(start());
108 
109         THEN ("Parameter value is false according to the settings") {
110             REQUIRE_FALSE(getParameterValue());
111 
112             AND_THEN ("Tuning is off") {
113                 REQUIRE_FALSE(isTuningModeOn());
114 
115                 WHEN ("Turning autosync on") {
116                     REQUIRE_NOTHROW(setAutoSync(true));
117 
118                     AND_WHEN ("A parameter is set") {
119                         REQUIRE_NOTHROW(setParameterValue(true));
120 
121                         THEN ("Sync is done") {
122                             CHECK(getParameterValue());
123                         }
124                     }
125                 }
126                 WHEN ("Turning autosync off") {
127                     REQUIRE_NOTHROW(setAutoSync(false));
128 
129                     AND_WHEN ("A parameter is set") {
130                         REQUIRE_NOTHROW(setParameterValue(true));
131 
132                         THEN ("Sync should not have occurred yet") {
133                             REQUIRE_FALSE(getParameterValue());
134 
135                             WHEN ("Turning autosync on") {
136                                 REQUIRE_NOTHROW(setAutoSync(true));
137 
138                                 THEN ("Sync is done") {
139                                     CHECK(getParameterValue());
140                                 }
141                             }
142                         }
143                     }
144                 }
145             }
146         }
147     }
148 }
149 } // namespace parameterFramework
150