Files
.idea
.run
archive
arduino
automation
bsp_egse
bsp_hosted
bsp_linux_board
bsp_q7s
bsp_te0720_1cfa
cmake
common
doc
dummies
fsfw
generators
hooks
linux
misc
mission
scripts
test
thirdparty
tmtc
unittest
controller
CMakeLists.txt
testAcsController.cpp
testConfigFileHandler.cpp
testThermalController.cpp
mocks
rebootLogic
CMakeLists.txt
hdlcEncodingRw.cpp
main.cpp
meineTestDaten.txt
printChar.cpp
printChar.h
testEnvironment.cpp
testEnvironment.h
testGenericFilesystem.cpp
watchdog
.clang-format
.dockerignore
.gitignore
.gitmodules
CHANGELOG.md
CMakeLists.txt
Justfile
LICENSE
NOTICE
README.md
clone-submodules-no-privlibs.sh
docker-compose.yml
q7s-env-em.sh
q7s-env.sh
release-checklist.md
eive-obsw/unittest/controller/testConfigFileHandler.cpp
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");
}