eive-obsw/unittest/rebootLogic/main.cpp

35 lines
909 B
C++
Raw Normal View History

2022-02-28 14:13:31 +01:00
#include "CoreController.h"
2022-02-28 16:05:32 +01:00
#include <catch2/catch_test_macros.hpp>
#include <iostream>
2022-02-28 16:47:36 +01:00
#include <fstream>
#include <filesystem>
static constexpr bool CAT_FILE_TO_CONSOLE = true;
const std::string CONF_PATH = "/tmp/conf";
const std::string REBOOT_FILE = CONF_PATH + "/reboot.txt";
void catFileToConsole();
2022-02-28 16:05:32 +01:00
TEST_CASE( "Core Controller Reboot File Handling", "[reboot-file]" ) {
2022-02-28 16:47:36 +01:00
if(not std::filesystem::exists(CONF_PATH)) {
std::filesystem::create_directory(CONF_PATH);
}
2022-02-28 14:13:31 +01:00
CoreController ctrl;
2022-02-28 16:47:36 +01:00
RebootFile rf;
ctrl.performRebootFileHandling(true);
2022-02-28 16:47:36 +01:00
catFileToConsole();
ctrl.parseRebootFile(REBOOT_FILE, rf);
REQUIRE(rf.enabled == 1);
REQUIRE(rf.enabled == 1);
std::filesystem::remove_all(CONF_PATH);
}
2022-02-28 16:47:36 +01:00
void catFileToConsole() {
if(CAT_FILE_TO_CONSOLE) {
std::ifstream file(REBOOT_FILE);
if (file.is_open()) {
std::cout << file.rdbuf();
}
}
}