summaryrefslogtreecommitdiffhomepage
path: root/tests/unittests.cpp
blob: 3b24f83676ac5f9c4b51ff5c18340b5fcab6ee9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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));
}