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 <SubsystemObject.h>
     34 #include <IntrospectionEntryPoint.h>
     35 #include "Test.hpp"
     36 #include <catch.hpp>
     37 #include <string>
     38 
     39 using std::string;
     40 
     41 namespace parameterFramework
     42 {
     43 
     44 struct BoolPF : public ParameterFramework
     45 {
     46     BoolPF() : ParameterFramework{createConfig()} {}
     47 
     48     /** Set the boolean parameter value within the "Conf" configuration,
     49      * which is always applicable. */
     50     void setParameterValue(bool value)
     51     {
     52         std::string valueStr = value ? "1" : "0";
     53         setConfigurationParameter("Domain", "Conf", "/test/test/param", valueStr);
     54     }
     55 
     56 private:
     57     static Config createConfig()
     58     {
     59         Config config;
     60         config.instances = R"(<BooleanParameter Name="param" Mapping="Object"/>)";
     61         config.plugins = {{"", {"introspection-subsystem"}}};
     62         config.subsystemType = "INTROSPECTION";
     63 
     64         config.domains = R"(<ConfigurableDomain Name="Domain">
     65                                 <Configurations>
     66                                     <Configuration Name="Conf">
     67                                         <CompoundRule Type="All"/>
     68                                     </Configuration>
     69                                 </Configurations>
     70 
     71                                 <ConfigurableElements>
     72                                     <ConfigurableElement Path="/test/test/param"/>
     73                                 </ConfigurableElements>
     74 
     75                                 <Settings>
     76                                     <Configuration Name="Conf">
     77                                         <ConfigurableElement Path="/test/test/param">
     78                                             <BooleanParameter Name="param">0</BooleanParameter>
     79                                         </ConfigurableElement>
     80                                     </Configuration>
     81                                 </Settings>
     82                             </ConfigurableDomain>)";
     83 
     84         return config;
     85     }
     86 };
     87 
     88 SCENARIO_METHOD(BoolPF, "Auto sync")
     89 {
     90     GIVEN ("A Pfw that starts") {
     91         REQUIRE_NOTHROW(start());
     92 
     93         THEN ("Parameter value is false according to the settings") {
     94             REQUIRE_FALSE(introspectionSubsystem::getParameterValue());
     95 
     96             AND_THEN ("Tuning is off") {
     97                 REQUIRE_FALSE(isTuningModeOn());
     98 
     99                 WHEN ("Turning autosync on") {
    100                     REQUIRE_NOTHROW(setAutoSync(true));
    101 
    102                     AND_WHEN ("A parameter is set") {
    103                         REQUIRE_NOTHROW(setParameterValue(true));
    104 
    105                         THEN ("Sync is done") {
    106                             CHECK(introspectionSubsystem::getParameterValue());
    107                         }
    108                     }
    109                 }
    110                 WHEN ("Turning autosync off") {
    111                     REQUIRE_NOTHROW(setAutoSync(false));
    112 
    113                     AND_WHEN ("A parameter is set") {
    114                         REQUIRE_NOTHROW(setParameterValue(true));
    115 
    116                         THEN ("Sync should not have occurred yet") {
    117                             REQUIRE_FALSE(introspectionSubsystem::getParameterValue());
    118 
    119                             WHEN ("Turning autosync on") {
    120                                 REQUIRE_NOTHROW(setAutoSync(true));
    121 
    122                                 THEN ("Sync is done") {
    123                                     CHECK(introspectionSubsystem::getParameterValue());
    124                                 }
    125                             }
    126                         }
    127                     }
    128                 }
    129             }
    130         }
    131     }
    132 }
    133 }
    134