-
Notifications
You must be signed in to change notification settings - Fork 2
/
xdg_test.cpp
130 lines (111 loc) · 4.71 KB
/
xdg_test.cpp
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Copyright (C) 2015 Thomas Voß <[email protected]>
//
// This library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <xdg.h>
#include <boost/test/unit_test.hpp>
#include <cstdlib>
#include <iostream>
BOOST_AUTO_TEST_CASE(XdgDataHomeThrowsForRelativeDirectoryFromEnv)
{
::setenv("XDG_DATA_HOME", "tmp", 1);
BOOST_CHECK_THROW(xdg::BaseDirSpecification::create()->data().home(), std::runtime_error);
BOOST_CHECK_THROW(xdg::data().home(), std::runtime_error);
}
BOOST_AUTO_TEST_CASE(XdgDataHomeReturnsDefaultValueForEmptyEnv)
{
::setenv("HOME", "/tmp", 1);
::setenv("XDG_DATA_HOME", "", 1);
BOOST_CHECK_EQUAL("/tmp/.local/share", xdg::BaseDirSpecification::create()->data().home());
BOOST_CHECK_EQUAL("/tmp/.local/share", xdg::data().home());
}
BOOST_AUTO_TEST_CASE(XdgDataDirsCorrectlyTokenizesEnv)
{
::setenv("XDG_DATA_DIRS", "/tmp:/tmp", 1);
BOOST_CHECK(2 == xdg::BaseDirSpecification::create()->data().dirs().size());
BOOST_CHECK(2 == xdg::data().dirs().size());
}
BOOST_AUTO_TEST_CASE(XdgDataDirsThrowsForRelativeDirectoryFromEnv)
{
::setenv("XDG_DATA_DIRS", "/tmp:tmp", 1);
BOOST_CHECK_THROW(xdg::BaseDirSpecification::create()->data().dirs(), std::runtime_error);
BOOST_CHECK_THROW(xdg::data().dirs(), std::runtime_error);
}
BOOST_AUTO_TEST_CASE(XdgDataDirsReturnsDefaultValueForEmptyEnv)
{
::setenv("XDG_DATA_DIRS", "", 1);
auto dirs = xdg::data().dirs();
BOOST_CHECK_EQUAL("/usr/local/share", dirs[0]);
BOOST_CHECK_EQUAL("/usr/share", dirs[1]);
dirs = xdg::BaseDirSpecification::create()->data().dirs();
BOOST_CHECK_EQUAL("/usr/local/share", dirs[0]);
BOOST_CHECK_EQUAL("/usr/share", dirs[1]);
}
BOOST_AUTO_TEST_CASE(XdgConfigHomeThrowsForRelativeDirectoryFromEnv)
{
::setenv("XDG_CONFIG_HOME", "tmp", 1);
BOOST_CHECK_THROW(xdg::BaseDirSpecification::create()->config().home(), std::runtime_error);
BOOST_CHECK_THROW(xdg::config().home(), std::runtime_error);
}
BOOST_AUTO_TEST_CASE(XdgConfigHomeReturnsDefaultValueForEmptyEnv)
{
::setenv("HOME", "/tmp", 1);
::setenv("XDG_CONFIG_HOME", "", 1);
BOOST_CHECK_EQUAL("/tmp/.config", xdg::BaseDirSpecification::create()->config().home());
BOOST_CHECK_EQUAL("/tmp/.config", xdg::config().home());
}
BOOST_AUTO_TEST_CASE(XdgConfigDirsCorrectlyTokenizesEnv)
{
::setenv("XDG_CONFIG_DIRS", "/tmp:/tmp", 1);
BOOST_CHECK(2 == xdg::BaseDirSpecification::create()->config().dirs().size());
BOOST_CHECK(2 == xdg::config().dirs().size());
}
BOOST_AUTO_TEST_CASE(XdgConfigDirsThrowsForRelativeDirectoryFromEnv)
{
::setenv("XDG_CONFIG_DIRS", "/tmp:tmp", 1);
BOOST_CHECK_THROW(xdg::BaseDirSpecification::create()->config().dirs(), std::runtime_error);
BOOST_CHECK_THROW(xdg::config().dirs(), std::runtime_error);
}
BOOST_AUTO_TEST_CASE(XdgConfigDirsReturnsDefaultValueForEmptyEnv)
{
::setenv("XDG_CONFIG_DIRS", "", 1);
auto dirs = xdg::config().dirs();
BOOST_CHECK_EQUAL("/etc/xdg", dirs[0]);
dirs = xdg::BaseDirSpecification::create()->config().dirs();
BOOST_CHECK_EQUAL("/etc/xdg", dirs[0]);
}
BOOST_AUTO_TEST_CASE(XdgCacheHomeThrowsForRelativeDirectoryFromEnv)
{
::setenv("XDG_CACHE_HOME", "tmp", 1);
BOOST_CHECK_THROW(xdg::BaseDirSpecification::create()->cache().home(), std::runtime_error);
BOOST_CHECK_THROW(xdg::cache().home(), std::runtime_error);
}
BOOST_AUTO_TEST_CASE(XdgCacheHomeReturnsDefaultValueForEmptyEnv)
{
::setenv("HOME", "/tmp", 1);
::setenv("XDG_CACHE_HOME", "", 1);
BOOST_CHECK_EQUAL("/tmp/.cache", xdg::BaseDirSpecification::create()->cache().home());
BOOST_CHECK_EQUAL("/tmp/.cache", xdg::cache().home());
}
BOOST_AUTO_TEST_CASE(XdgRuntimeDirThrowsForRelativeDirectoryFromEnv)
{
::setenv("XDG_RUNTIME_DIR", "tmp", 1);
BOOST_CHECK_THROW(xdg::BaseDirSpecification::create()->runtime().dir(), std::runtime_error);
BOOST_CHECK_THROW(xdg::runtime().dir(), std::runtime_error);
}
BOOST_AUTO_TEST_CASE(XdgRuntimeDirThrowsForEmptyEnv)
{
::setenv("XDG_RUNTIME_DIR", "", 1);
BOOST_CHECK_THROW(xdg::BaseDirSpecification::create()->runtime().dir(), std::runtime_error);
BOOST_CHECK_THROW(xdg::runtime().dir(), std::runtime_error);
}