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 "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 validLogarithmicInstances = Config{
     47     &Config::instances,
     48     // Size is fixed at 32 and as such is optional */
     49     R"(<IntegerParameter Name="trivial" Signed="true"> <LogarithmicAdaptation SlopeNumerator="200" LogarithmBase="10"/> </IntegerParameter>
     50     <IntegerParameter Name="nominal" Size="32" Signed="true" Min="-144" Max="30"> <LogarithmicAdaptation SlopeNumerator="1" LogarithmBase="10"/> </IntegerParameter>)"};
     51 const auto &invalidLogarithmicParameters = Tests<string>{
     52     {"invalid Size(64)", "<IntegerParameter Name='nominal' Size='64' Signed='true' Min='-144' "
     53                          "Max='30'> <LogarithmicAdaptation SlopeNumerator='1' LogarithmBase='10'/> "
     54                          "</IntegerParameter>"},
     55     {"minimum > maximum", "<IntegerParameter Name='nominal' Size='32' Signed='true' Min='30' "
     56                           "Max='-144'> <LogarithmicAdaptation SlopeNumerator='1' "
     57                           "LogarithmBase='10'/> </IntegerParameter>"},
     58     {"logBase =1", "<IntegerParameter Name='nominal' Size='32' Signed='true' Min='-144' Max='30'> "
     59                    "<LogarithmicAdaptation SlopeNumerator='1' LogarithmBase='1'/> "
     60                    "</IntegerParameter>"},
     61     {"logBase negative", "<IntegerParameter Name='nominal' Size='32' Signed='true' Min='-144' "
     62                          "Max='30'> <LogarithmicAdaptation SlopeNumerator='1' "
     63                          "LogarithmBase='-10'/> </IntegerParameter>"}};
     64 
     65 struct LogarithmicsPF : public ParameterFramework
     66 {
     67     LogarithmicsPF() : ParameterFramework{std::move(validLogarithmicInstances)} {}
     68 };
     69 
     70 SCENARIO_METHOD(LazyPF, "Invalid Logarithmic points XML structure", "[Logarithmic Type]")
     71 {
     72     for (auto &vec : invalidLogarithmicParameters) {
     73         GIVEN ("intentional error: " + vec.title) {
     74             create(Config{&Config::instances, vec.payload});
     75             THEN ("Start should fail") {
     76                 CHECK_THROWS_AS(mPf->start(), Exception);
     77             }
     78         }
     79     }
     80 }
     81 
     82 SCENARIO_METHOD(LogarithmicsPF, "Logarithmic points", "[Logarithmic Type]")
     83 {
     84     GIVEN ("A valid XML structure file") {
     85         THEN ("Start should succeed") {
     86             CHECK_NOTHROW(start());
     87             REQUIRE_NOTHROW(setTuningMode(true));
     88             string path = "/test/test/nominal";
     89             AND_THEN ("Set/Get a Loagaritmic point parameter in real value space") {
     90 
     91                 for (auto &vec : Tests<string>{
     92                          {"(too high)", "31"}, {"(too low)", "-145"}, {"(not a number)", "foobar"},
     93                      }) {
     94                     GIVEN ("Invalid value " + vec.title) {
     95                         CHECK_THROWS_AS(setParameter(path, vec.payload), Exception);
     96                     }
     97                 }
     98                 for (auto &vec : Tests<string>{
     99                          {"(upper limit)", "30"},
    100                          {"(lower limit)", "-144"},
    101                          {"(inside range)", "0"},
    102                      }) {
    103                     GIVEN ("A valid value " + vec.title) {
    104                         CHECK_NOTHROW(setParameter(path, vec.payload));
    105                         string getValueBack;
    106                         REQUIRE_NOTHROW(getParameter(path, getValueBack));
    107                         CHECK(getValueBack == vec.payload);
    108                     }
    109                 }
    110             }
    111         }
    112     }
    113 }
    114 } // namespace parameterFramework
    115