#include #include #include #include #include #include #include "../testEnvironment.h" TEST_CASE("Configfile Handler", "[ConfigHandler]") { sif::debug << "Testcase config file handler" << std::endl; testEnvironment::initialize(); // Init handler GlobalConfigHandler confighandler = GlobalConfigHandler(objects::GLOBAL_JSON_CFG, "JSON.config"); REQUIRE(confighandler.initialize() == returnvalue::OK); // Reset handler REQUIRE(confighandler.ResetConfigFile() == returnvalue::OK); // Get and set double as well as int values double doubleData = 0.0; REQUIRE(confighandler.getConfigFileValue(PARAM0, doubleData) == returnvalue::OK); REQUIRE(doubleData == 5.0); doubleData = 55.9; double doubleDataRead = 0; REQUIRE(confighandler.setConfigFileValue(PARAM0, doubleData) == returnvalue::OK); REQUIRE(confighandler.getConfigFileValue(PARAM0, doubleDataRead) == returnvalue::OK); REQUIRE(doubleDataRead == doubleData); REQUIRE(confighandler.WriteConfigFile() == returnvalue::OK); int intData = 0; REQUIRE(confighandler.getConfigFileValue(PARAM1, intData) == returnvalue::OK); REQUIRE(intData == 905); intData = 1337; int intDataRead = 0; REQUIRE(confighandler.setConfigFileValue(PARAM1, intData) == returnvalue::OK); REQUIRE(confighandler.getConfigFileValue(PARAM1, intDataRead) == returnvalue::OK); REQUIRE(intDataRead == intData); REQUIRE(confighandler.WriteConfigFile() == returnvalue::OK); // Check file name REQUIRE(confighandler.getConfigFileName() == "JSON.config"); // Reset and check if it worked REQUIRE(confighandler.ResetConfigFile() == returnvalue::OK); doubleData = 0.0; REQUIRE(confighandler.getConfigFileValue(PARAM0, doubleData) == returnvalue::OK); REQUIRE(doubleData == 5.0); // Test invalid Parameter REQUIRE(confighandler.getConfigFileValue(PARAM2, doubleData) != returnvalue::OK); // NVMParameterBase::KEY_NOT_EXISTS is private, why? REQUIRE(confighandler.setConfigFileValue(PARAM2, doubleData) != returnvalue::OK); }