TYPE3
[iec.git] / src / type3_AndroidCloud / anbox-master / external / xdg / xdg_test.cpp
1 // Copyright (C) 2015 Thomas Voß <thomas.voss.bochum@gmail.com>
2 //
3 // This library is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU Lesser General Public License as published
5 // by the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public License
14 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16 #include <xdg.h>
17
18 #include <boost/test/unit_test.hpp>
19
20 #include <cstdlib>
21 #include <iostream>
22
23 BOOST_AUTO_TEST_CASE(XdgDataHomeThrowsForRelativeDirectoryFromEnv)
24 {
25     ::setenv("XDG_DATA_HOME", "tmp", 1);
26     BOOST_CHECK_THROW(xdg::BaseDirSpecification::create()->data().home(), std::runtime_error);
27     BOOST_CHECK_THROW(xdg::data().home(), std::runtime_error);
28 }
29
30 BOOST_AUTO_TEST_CASE(XdgDataHomeReturnsDefaultValueForEmptyEnv)
31 {
32     ::setenv("HOME", "/tmp", 1);
33     ::setenv("XDG_DATA_HOME", "", 1);
34     BOOST_CHECK_EQUAL("/tmp/.local/share", xdg::BaseDirSpecification::create()->data().home());
35     BOOST_CHECK_EQUAL("/tmp/.local/share", xdg::data().home());
36 }
37
38 BOOST_AUTO_TEST_CASE(XdgDataDirsCorrectlyTokenizesEnv)
39 {
40     ::setenv("XDG_DATA_DIRS", "/tmp:/tmp", 1);
41     BOOST_CHECK(2 == xdg::BaseDirSpecification::create()->data().dirs().size());
42     BOOST_CHECK(2 == xdg::data().dirs().size());
43 }
44
45 BOOST_AUTO_TEST_CASE(XdgDataDirsThrowsForRelativeDirectoryFromEnv)
46 {
47     ::setenv("XDG_DATA_DIRS", "/tmp:tmp", 1);
48     BOOST_CHECK_THROW(xdg::BaseDirSpecification::create()->data().dirs(), std::runtime_error);
49     BOOST_CHECK_THROW(xdg::data().dirs(), std::runtime_error);
50 }
51
52 BOOST_AUTO_TEST_CASE(XdgDataDirsReturnsDefaultValueForEmptyEnv)
53 {
54     ::setenv("XDG_DATA_DIRS", "", 1);
55     auto dirs = xdg::data().dirs();
56     BOOST_CHECK_EQUAL("/usr/local/share", dirs[0]);
57     BOOST_CHECK_EQUAL("/usr/share", dirs[1]);
58
59     dirs = xdg::BaseDirSpecification::create()->data().dirs();
60     BOOST_CHECK_EQUAL("/usr/local/share", dirs[0]);
61     BOOST_CHECK_EQUAL("/usr/share", dirs[1]);
62 }
63
64 BOOST_AUTO_TEST_CASE(XdgConfigHomeThrowsForRelativeDirectoryFromEnv)
65 {
66     ::setenv("XDG_CONFIG_HOME", "tmp", 1);
67     BOOST_CHECK_THROW(xdg::BaseDirSpecification::create()->config().home(), std::runtime_error);
68     BOOST_CHECK_THROW(xdg::config().home(), std::runtime_error);
69 }
70
71 BOOST_AUTO_TEST_CASE(XdgConfigHomeReturnsDefaultValueForEmptyEnv)
72 {
73     ::setenv("HOME", "/tmp", 1);
74     ::setenv("XDG_CONFIG_HOME", "", 1);
75     BOOST_CHECK_EQUAL("/tmp/.config", xdg::BaseDirSpecification::create()->config().home());
76     BOOST_CHECK_EQUAL("/tmp/.config", xdg::config().home());
77 }
78
79 BOOST_AUTO_TEST_CASE(XdgConfigDirsCorrectlyTokenizesEnv)
80 {
81     ::setenv("XDG_CONFIG_DIRS", "/tmp:/tmp", 1);
82     BOOST_CHECK(2 == xdg::BaseDirSpecification::create()->config().dirs().size());
83     BOOST_CHECK(2 == xdg::config().dirs().size());
84 }
85
86 BOOST_AUTO_TEST_CASE(XdgConfigDirsThrowsForRelativeDirectoryFromEnv)
87 {
88     ::setenv("XDG_CONFIG_DIRS", "/tmp:tmp", 1);
89     BOOST_CHECK_THROW(xdg::BaseDirSpecification::create()->config().dirs(), std::runtime_error);
90     BOOST_CHECK_THROW(xdg::config().dirs(), std::runtime_error);
91 }
92
93 BOOST_AUTO_TEST_CASE(XdgConfigDirsReturnsDefaultValueForEmptyEnv)
94 {
95     ::setenv("XDG_CONFIG_DIRS", "", 1);
96     auto dirs = xdg::config().dirs();
97     BOOST_CHECK_EQUAL("/etc/xdg", dirs[0]);
98     dirs = xdg::BaseDirSpecification::create()->config().dirs();
99     BOOST_CHECK_EQUAL("/etc/xdg", dirs[0]);
100 }
101
102 BOOST_AUTO_TEST_CASE(XdgCacheHomeThrowsForRelativeDirectoryFromEnv)
103 {
104     ::setenv("XDG_CACHE_HOME", "tmp", 1);
105     BOOST_CHECK_THROW(xdg::BaseDirSpecification::create()->cache().home(), std::runtime_error);
106     BOOST_CHECK_THROW(xdg::cache().home(), std::runtime_error);
107 }
108
109 BOOST_AUTO_TEST_CASE(XdgCacheHomeReturnsDefaultValueForEmptyEnv)
110 {
111     ::setenv("HOME", "/tmp", 1);
112     ::setenv("XDG_CACHE_HOME", "", 1);
113     BOOST_CHECK_EQUAL("/tmp/.cache", xdg::BaseDirSpecification::create()->cache().home());
114     BOOST_CHECK_EQUAL("/tmp/.cache", xdg::cache().home());
115 }
116
117 BOOST_AUTO_TEST_CASE(XdgRuntimeDirThrowsForRelativeDirectoryFromEnv)
118 {
119     ::setenv("XDG_RUNTIME_DIR", "tmp", 1);
120     BOOST_CHECK_THROW(xdg::BaseDirSpecification::create()->runtime().dir(), std::runtime_error);
121     BOOST_CHECK_THROW(xdg::runtime().dir(), std::runtime_error);
122 }
123
124 BOOST_AUTO_TEST_CASE(XdgRuntimeDirThrowsForEmptyEnv)
125 {
126     ::setenv("XDG_RUNTIME_DIR", "", 1);
127     BOOST_CHECK_THROW(xdg::BaseDirSpecification::create()->runtime().dir(), std::runtime_error);
128     BOOST_CHECK_THROW(xdg::runtime().dir(), std::runtime_error);
129 }
130