eive-obsw/unittest/controller/testConfigFileHandler.cpp
Robin Mueller 3ca11b5894
Some checks failed
EIVE/eive-obsw/pipeline/pr-develop There was a failure building this commit
run auto-formatter
2022-07-14 17:35:49 +02:00

66 lines
2.3 KiB
C++

#include <mission/utility/GlobalConfigHandler.h>
#include <objects/systemObjectList.h>
#include <catch2/catch_test_macros.hpp>
#include <fstream>
#include <iostream>
#include <stdexcept>
#include "../testEnvironment.h"
TEST_CASE("Configfile Handler", "[ConfigHandler]") {
sif::debug << "Testcase config file handler" << std::endl;
testEnvironment::initialize();
// Init handler
GlobalConfigHandler confighandler = GlobalConfigHandler(objects::CONFIG_TEST, "JSON.config");
REQUIRE(confighandler.initialize() == HasReturnvaluesIF::RETURN_OK);
// Reset handler
REQUIRE(confighandler.ResetConfigFile() == HasReturnvaluesIF::RETURN_OK);
// 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
REQUIRE(confighandler.ResetConfigFile() == HasReturnvaluesIF::RETURN_OK);
doubleData = 0.0;
REQUIRE(confighandler.getConfigFileValue(PARAM0, doubleData) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(doubleData == 5.0);
// 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);
}