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