This is an example of how to use the TempDir and TemEnv classes.
#include <algorithm>
#include <string>
#include <vector>
#include <boost/filesystem/fstream.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/test/unit_test.hpp>
using boost::filesystem::exists;
using boost::filesystem::is_regular;
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-%%%%%%%"} {
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");
boost::filesystem::create_directory(p);
});
m_item_list.emplace_back(m_top_dir.path() / "test4");
m_target_item_list = m_item_list;
m_real_item_list.resize(m_item_list.size());
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());
auto it2 =
copy_if(m_target_item_list.begin(), m_target_item_list.end(), m_target_real_item_list.begin(),
return exists(p);
});
m_target_real_item_list.erase(it2, m_target_real_item_list.end());
}
~Configuration_Fixture() {}
};
BOOST_AUTO_TEST_SUITE(Configuration_test)
BOOST_AUTO_TEST_CASE(ConfigurationException_test) {
}
BOOST_AUTO_TEST_CASE(ConfigurationVariableName_test) {
}
BOOST_FIXTURE_TEST_CASE(getFromLocations_test, Configuration_Fixture) {
env[
"ELEMENTS_CONF_PATH"] =
Path::join(m_item_list);
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) {
env[
"ELEMENTS_CONF_PATH"] =
Path::join(m_real_item_list);
BOOST_CHECK_EQUAL_COLLECTIONS(locations.begin(), locations.end(), m_target_real_item_list.begin(),
m_target_real_item_list.end());
}
BOOST_AUTO_TEST_SUITE_END()
}