2022-07-05 10:02:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
#include <mission/utility/GlobalConfigHandler.h>
|
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
#include "../testEnvironment.h"
|
|
|
|
#include <objects/systemObjectList.h>
|
|
|
|
|
|
|
|
TEST_CASE("Configfile Handler", "[ConfigHandler]") {
|
|
|
|
|
|
|
|
sif::debug<<"Testcase config file handler"<<std::endl;
|
2022-07-05 14:56:31 +02:00
|
|
|
testEnvironment::initialize();
|
2022-07-05 12:57:50 +02:00
|
|
|
//Init handler
|
|
|
|
GlobalConfigHandler confighandler= GlobalConfigHandler(objects::CONFIG_TEST,"JSON.config");
|
2022-07-05 10:02:43 +02:00
|
|
|
REQUIRE(confighandler.initialize() == HasReturnvaluesIF::RETURN_OK);
|
|
|
|
|
2022-07-05 12:57:50 +02:00
|
|
|
//Reset handler
|
2022-07-05 14:56:31 +02:00
|
|
|
REQUIRE(confighandler.ResetConfigFile() == HasReturnvaluesIF::RETURN_OK);
|
2022-07-05 12:57:50 +02:00
|
|
|
|
|
|
|
//Get and set double as well as int values
|
|
|
|
double doubleData=0.0;
|
|
|
|
REQUIRE(confighandler.getConfigFileValue(PARAM0, doubleData) == HasReturnvaluesIF::RETURN_OK);
|
|
|
|
REQUIRE(doubleData==5.0);
|
|
|
|
|
|
|
|
doubleData=55.9;
|
|
|
|
double doubleDataRead=0;
|
|
|
|
REQUIRE(confighandler.setConfigFileValue(PARAM0, doubleData) == HasReturnvaluesIF::RETURN_OK);
|
|
|
|
|
|
|
|
REQUIRE(confighandler.getConfigFileValue(PARAM0, doubleDataRead) == HasReturnvaluesIF::RETURN_OK);
|
|
|
|
REQUIRE(doubleDataRead==doubleData);
|
|
|
|
|
|
|
|
REQUIRE(confighandler.WriteConfigFile()==HasReturnvaluesIF::RETURN_OK);
|
|
|
|
|
|
|
|
int intData=0;
|
|
|
|
|
|
|
|
REQUIRE(confighandler.getConfigFileValue(PARAM1, intData) == HasReturnvaluesIF::RETURN_OK);
|
|
|
|
REQUIRE(intData==905);
|
|
|
|
|
|
|
|
intData=1337;
|
|
|
|
int intDataRead=0;
|
|
|
|
REQUIRE(confighandler.setConfigFileValue(PARAM1, intData) == HasReturnvaluesIF::RETURN_OK);
|
|
|
|
|
|
|
|
REQUIRE(confighandler.getConfigFileValue(PARAM1, intDataRead) == HasReturnvaluesIF::RETURN_OK);
|
|
|
|
REQUIRE(intDataRead==intData);
|
|
|
|
|
|
|
|
REQUIRE(confighandler.WriteConfigFile()==HasReturnvaluesIF::RETURN_OK);
|
|
|
|
|
|
|
|
//Check file name
|
|
|
|
REQUIRE(confighandler.getConfigFileName()=="JSON.config");
|
|
|
|
|
|
|
|
//Reset and check if it worked
|
2022-07-05 14:56:31 +02:00
|
|
|
REQUIRE(confighandler.ResetConfigFile() == HasReturnvaluesIF::RETURN_OK);
|
2022-07-05 12:57:50 +02:00
|
|
|
|
|
|
|
doubleData=0.0;
|
|
|
|
REQUIRE(confighandler.getConfigFileValue(PARAM0, doubleData) == HasReturnvaluesIF::RETURN_OK);
|
|
|
|
REQUIRE(doubleData==5.0);
|
|
|
|
|
2022-07-05 14:56:31 +02:00
|
|
|
//Test invalid Parameter
|
|
|
|
REQUIRE(confighandler.getConfigFileValue(PARAM2, doubleData) != HasReturnvaluesIF::RETURN_OK);//NVMParameterBase::KEY_NOT_EXISTS is private, why?
|
|
|
|
REQUIRE(confighandler.setConfigFileValue(PARAM2, doubleData) != HasReturnvaluesIF::RETURN_OK);
|
|
|
|
|
2022-07-05 10:02:43 +02:00
|
|
|
}
|