eive-obsw/unittest/controller/testConfigFileHandler.cpp

66 lines
2.1 KiB
C++
Raw Normal View History

#include <mission/utility/GlobalConfigHandler.h>
2022-07-14 17:35:49 +02:00
#include <objects/systemObjectList.h>
#include <catch2/catch_test_macros.hpp>
#include <fstream>
#include <iostream>
#include <stdexcept>
#include "../testEnvironment.h"
TEST_CASE("Configfile Handler", "[ConfigHandler]") {
2022-07-14 17:35:49 +02:00
sif::debug << "Testcase config file handler" << std::endl;
// Init handler
2022-09-29 13:20:05 +02:00
GlobalConfigHandler confighandler = GlobalConfigHandler(objects::GLOBAL_JSON_CFG, "JSON.config");
REQUIRE(confighandler.initialize() == returnvalue::OK);
2022-07-14 17:35:49 +02:00
// Reset handler
2022-09-29 13:20:05 +02:00
REQUIRE(confighandler.ResetConfigFile() == returnvalue::OK);
2022-07-14 17:35:49 +02:00
// Get and set double as well as int values
double doubleData = 0.0;
2022-09-29 13:20:05 +02:00
REQUIRE(confighandler.getConfigFileValue(PARAM0, doubleData) == returnvalue::OK);
2022-07-14 17:35:49 +02:00
REQUIRE(doubleData == 5.0);
2022-07-14 17:35:49 +02:00
doubleData = 55.9;
double doubleDataRead = 0;
2022-09-29 13:20:05 +02:00
REQUIRE(confighandler.setConfigFileValue(PARAM0, doubleData) == returnvalue::OK);
2022-09-29 13:20:05 +02:00
REQUIRE(confighandler.getConfigFileValue(PARAM0, doubleDataRead) == returnvalue::OK);
2022-07-14 17:35:49 +02:00
REQUIRE(doubleDataRead == doubleData);
2022-09-29 13:20:05 +02:00
REQUIRE(confighandler.WriteConfigFile() == returnvalue::OK);
2022-07-14 17:35:49 +02:00
int intData = 0;
2022-09-29 13:20:05 +02:00
REQUIRE(confighandler.getConfigFileValue(PARAM1, intData) == returnvalue::OK);
2022-07-14 17:35:49 +02:00
REQUIRE(intData == 905);
2022-07-14 17:35:49 +02:00
intData = 1337;
int intDataRead = 0;
2022-09-29 13:20:05 +02:00
REQUIRE(confighandler.setConfigFileValue(PARAM1, intData) == returnvalue::OK);
2022-09-29 13:20:05 +02:00
REQUIRE(confighandler.getConfigFileValue(PARAM1, intDataRead) == returnvalue::OK);
2022-07-14 17:35:49 +02:00
REQUIRE(intDataRead == intData);
2022-09-29 13:20:05 +02:00
REQUIRE(confighandler.WriteConfigFile() == returnvalue::OK);
2022-07-14 17:35:49 +02:00
// Check file name
REQUIRE(confighandler.getConfigFileName() == "JSON.config");
2022-07-14 17:35:49 +02:00
// Reset and check if it worked
2022-09-29 13:20:05 +02:00
REQUIRE(confighandler.ResetConfigFile() == returnvalue::OK);
2022-07-14 17:35:49 +02:00
doubleData = 0.0;
2022-09-29 13:20:05 +02:00
REQUIRE(confighandler.getConfigFileValue(PARAM0, doubleData) == returnvalue::OK);
2022-07-14 17:35:49 +02:00
REQUIRE(doubleData == 5.0);
2022-07-14 17:35:49 +02:00
// Test invalid Parameter
REQUIRE(confighandler.getConfigFileValue(PARAM2, doubleData) !=
2022-09-29 13:20:05 +02:00
returnvalue::OK); // NVMParameterBase::KEY_NOT_EXISTS is private, why?
REQUIRE(confighandler.setConfigFileValue(PARAM2, doubleData) != returnvalue::OK);
2022-09-29 13:23:55 +02:00
std::filesystem::remove("JSON.config");
}