summaryrefslogtreecommitdiffhomepage
path: root/tests/test-config.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test-config.cpp')
-rw-r--r--tests/test-config.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/test-config.cpp b/tests/test-config.cpp
new file mode 100644
index 0000000..816dfea
--- /dev/null
+++ b/tests/test-config.cpp
@@ -0,0 +1,63 @@
+#include <gtest/gtest.h>
+
+#include <filesystem>
+#include <string>
+#include <system_error>
+
+#include "libreichwein/file.h"
+
+#include "config.h"
+
+namespace fs = std::filesystem;
+using namespace Reichwein;
+
+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(), 0UL);
+ ASSERT_TRUE(!fs::exists(filename));
+ }
+
+ ASSERT_TRUE(!fs::exists(filename));
+}
+
+TEST_F(ConfigTest, testData)
+{
+ File::setFile(testConfigFilename, R"CONFIG(
+<config>
+ <datapath>/some/other/location</datapath>
+ <maxage>2592000</maxage>
+</config>
+)CONFIG");
+
+ {
+ Config config{testConfigFilename};
+ EXPECT_EQ(config.getDataPath(), "/some/other/location");
+ EXPECT_EQ(config.getMaxage(), 2592000UL);
+ }
+
+ std::error_code ec;
+ fs::remove(testConfigFilename, ec);
+}
+