eive-obsw/unittest/controller/testConfigFileHandler.cpp
Robin Mueller fcef7e42a5
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good
some unittest fixes
2022-09-29 13:23:55 +02:00

66 lines
2.1 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;
// 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);
std::filesystem::remove("JSON.config");
}