forked from degauden/Elements
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathConfiguration_test.cpp
More file actions
159 lines (113 loc) · 5.22 KB
/
Copy pathConfiguration_test.cpp
File metadata and controls
159 lines (113 loc) · 5.22 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/**
* @file Configuration_test.cpp
*
* Created on: Dec 4, 2013
* Author: Pierre Dubath
*
* @copyright 2012-2020 Euclid Science Ground Segment
*
* 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.0 of the License, or (at your option)
* any later version.
*
* This library 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 Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include "ElementsKernel/Configuration.h" // header to test
#include <boost/test/unit_test.hpp>
#include <algorithm> // for copy_if, for_each
#include <filesystem> // for create_directory, operator/, exists
#include <string> // for allocator, string
#include <vector> // for vector
#include "ElementsKernel/Exception.h" // for Exception
#include "ElementsKernel/Path.h" // for Item, join
#include "ElementsKernel/System.h" // for DEFAULT_INSTALL_PREFIX
#include "ElementsKernel/Temporary.h" // for TempDir, TempEnv
using std::string;
using std::vector;
using std::filesystem::exists;
namespace Elements {
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//
// Begin of the Boost tests
//
//-----------------------------------------------------------------------------
struct Configuration_Fixture {
TempDir m_top_dir;
vector<Path::Item> m_item_list;
vector<Path::Item> m_target_item_list;
vector<Path::Item> m_real_item_list;
vector<Path::Item> m_target_real_item_list;
Configuration_Fixture() : m_top_dir{"Configuration_test-%%%%%%%"} {
using std::copy_if;
using std::for_each;
m_item_list.emplace_back(m_top_dir.path() / "test1");
m_item_list.emplace_back(m_top_dir.path() / "test1" / "foo");
m_item_list.emplace_back(m_top_dir.path() / "test2");
m_item_list.emplace_back(m_top_dir.path() / "test3");
for_each(m_item_list.cbegin(), m_item_list.cend(), [](const Path::Item& p) {
create_directory(p);
});
m_item_list.emplace_back(m_top_dir.path() / "test4");
m_target_item_list = m_item_list;
m_target_item_list.emplace_back(Path::Item(System::DEFAULT_INSTALL_PREFIX) / "share" / "conf");
m_real_item_list.resize(m_item_list.size());
const auto it = copy_if(m_item_list.begin(), m_item_list.end(), m_real_item_list.begin(), [](const Path::Item& p) {
return exists(p);
});
m_real_item_list.erase(it, m_real_item_list.end());
m_target_real_item_list.resize(m_target_item_list.size());
const auto it2 = copy_if(m_target_item_list.begin(), m_target_item_list.end(), m_target_real_item_list.begin(),
[](const Path::Item& p) {
return exists(p);
});
m_target_real_item_list.erase(it2, m_target_real_item_list.end());
}
~Configuration_Fixture() = default;
};
BOOST_AUTO_TEST_SUITE(Configuration_test)
//-----------------------------------------------------------------------------
BOOST_AUTO_TEST_CASE(ConfigurationException_test) {
BOOST_CHECK_THROW(getConfigurationPath("NonExistingFile.conf"), Exception);
}
BOOST_AUTO_TEST_CASE(ConfigurationVariableName_test) {
BOOST_CHECK_EQUAL(getConfigurationVariableName(), "ELEMENTS_CONF_PATH");
}
BOOST_FIXTURE_TEST_CASE(getFromLocations_test, Configuration_Fixture) {
auto env = TempEnv();
env["ELEMENTS_CONF_PATH"] = Path::join(m_item_list);
auto locations = getConfigurationLocations();
BOOST_CHECK_EQUAL_COLLECTIONS(locations.begin(), locations.end(), m_target_item_list.begin(),
m_target_item_list.end());
}
BOOST_FIXTURE_TEST_CASE(getFromLocationsExist_test, Configuration_Fixture) {
auto env = TempEnv();
env["ELEMENTS_CONF_PATH"] = Path::join(m_real_item_list);
auto locations = getConfigurationLocations(true);
BOOST_CHECK_EQUAL_COLLECTIONS(locations.begin(), locations.end(), m_target_real_item_list.begin(),
m_target_real_item_list.end());
}
BOOST_FIXTURE_TEST_CASE(NamespaceAlias_test, Configuration_Fixture) {
{
auto env = TempEnv();
env["ELEMENTS_CONF_PATH"] = Path::join(m_real_item_list);
auto locations = Configuration::getLocations(true);
BOOST_CHECK_EQUAL_COLLECTIONS(locations.begin(), locations.end(), m_target_real_item_list.begin(),
m_target_real_item_list.end());
}
BOOST_CHECK_EQUAL(Configuration::getVariableName(), "ELEMENTS_CONF_PATH");
BOOST_CHECK_THROW(Configuration::getPath("NonExistingFile.conf"), Exception);
}
BOOST_AUTO_TEST_SUITE_END()
//-----------------------------------------------------------------------------
//
// End of the Boost tests
//
//-----------------------------------------------------------------------------
} // namespace Elements