From 9465fd744cc2117190bafc1a3e2da9f10ca29bf9 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 31 Dec 2022 22:00:11 +0100 Subject: Storage via SQLite, Added tests (WIP) --- tests/test-config.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tests/test-config.cpp (limited to 'tests/test-config.cpp') diff --git a/tests/test-config.cpp b/tests/test-config.cpp new file mode 100644 index 0000000..065dedf --- /dev/null +++ b/tests/test-config.cpp @@ -0,0 +1,61 @@ +#include + +#include +#include +#include + +#include "config.h" +#include "file.h" + +namespace fs = std::filesystem; + +namespace { + const std::string testConfigFilename{"./test.conf"}; + const std::string testDbFilename{"./whiteboard.db3"}; +} + +class ConfigTest: public ::testing::Test +{ +protected: + ConfigTest(){ + } + + ~ConfigTest(){ + } +}; + +TEST_F(ConfigTest, defaultData) +{ + std::string filename{testConfigFilename + "doesntexist"}; + std::error_code ec; + fs::remove(filename, ec); + ASSERT_TRUE(!fs::exists(filename)); + { + Config config{filename}; + EXPECT_EQ(config.getDataPath(), "/var/lib/whiteboard"); + EXPECT_EQ(config.getMaxage(), 0); + ASSERT_TRUE(!fs::exists(filename)); + } + + ASSERT_TRUE(!fs::exists(filename)); +} + +TEST_F(ConfigTest, testData) +{ + File::setFile(testConfigFilename, R"CONFIG( + + /some/other/location + 2592000 + +)CONFIG"); + + { + Config config{testConfigFilename}; + EXPECT_EQ(config.getDataPath(), "/some/other/location"); + EXPECT_EQ(config.getMaxage(), 2592000); + } + + std::error_code ec; + fs::remove(testConfigFilename, ec); +} + -- cgit v1.2.3