summaryrefslogtreecommitdiffhomepage
path: root/tests/unittests.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2022-12-30 15:07:39 +0100
committerRoland Reichwein <mail@reichwein.it>2022-12-30 15:07:39 +0100
commitaf1c4ee4d74ff7afc997372802d851d11daad418 (patch)
tree745761113c41ccbe6ea37119b51b609a219882c9 /tests/unittests.cpp
parent3f3d579c6a6f9a1a31278221f85b3194e3b6c5f4 (diff)
Added tests, added sqlite-backed storage (WIP!)
Diffstat (limited to 'tests/unittests.cpp')
-rw-r--r--tests/unittests.cpp94
1 files changed, 94 insertions, 0 deletions
diff --git a/tests/unittests.cpp b/tests/unittests.cpp
new file mode 100644
index 0000000..3b24f83
--- /dev/null
+++ b/tests/unittests.cpp
@@ -0,0 +1,94 @@
+#include <gtest/gtest.h>
+
+#include <filesystem>
+#include <string>
+#include <system_error>
+
+#include "config.h"
+#include "file.h"
+#include "storage.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");
+ 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");
+ }
+
+ std::error_code ec;
+ fs::remove(testConfigFilename, ec);
+}
+
+class StorageTest: public ::testing::Test
+{
+protected:
+ StorageTest(){
+ File::setFile(testConfigFilename, R"CONFIG(
+<config>
+ <datapath>.</datapath>
+ <maxage>2592000</maxage>
+</config>
+)CONFIG");
+ std::error_code ec;
+ fs::remove(testDbFilename, ec);
+ }
+
+ ~StorageTest(){
+ std::error_code ec;
+ fs::remove(testDbFilename, ec);
+ fs::remove(testConfigFilename, ec);
+ }
+};
+
+TEST_F(StorageTest, create)
+{
+ ASSERT_TRUE(!fs::exists(testDbFilename));
+
+ {
+ Config config(testConfigFilename);
+ ASSERT_EQ(config.getDataPath(), ".");
+ Storage storage(config);
+ }
+
+ ASSERT_TRUE(fs::exists(testDbFilename));
+}
+