summaryrefslogtreecommitdiffhomepage
path: root/tests/test-config.cpp
blob: 816dfeaf31ef2d3b0a9d1f48ae5de887df66bd2c (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
#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);
}