2018-12-12 18:51:04 +01:00
|
|
|
#include <RWConfig.hpp>
|
2017-02-17 01:17:50 +01:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
#include <boost/test/unit_test.hpp>
|
2017-02-17 01:17:50 +01:00
|
|
|
|
2017-02-20 20:57:36 +01:00
|
|
|
#include <boost/property_tree/ini_parser.hpp>
|
|
|
|
#include <boost/property_tree/ptree.hpp>
|
|
|
|
|
2016-05-20 03:09:22 +02:00
|
|
|
#include <fstream>
|
2017-02-17 01:17:50 +01:00
|
|
|
#include <map>
|
|
|
|
|
2018-06-21 16:49:05 +02:00
|
|
|
#include <rw/debug.hpp>
|
2017-10-29 23:50:59 +01:00
|
|
|
#include <rw/filesystem.hpp>
|
2017-02-20 20:57:36 +01:00
|
|
|
|
|
|
|
namespace pt = boost::property_tree;
|
2017-02-17 01:17:50 +01:00
|
|
|
|
2017-02-20 20:57:36 +01:00
|
|
|
typedef std::map<std::string, std::map<std::string, std::string>>
|
|
|
|
simpleConfig_t;
|
|
|
|
|
2017-11-02 03:36:13 +01:00
|
|
|
simpleConfig_t readConfig(const rwfs::path &path) {
|
2017-02-20 20:57:36 +01:00
|
|
|
simpleConfig_t cfg;
|
|
|
|
pt::ptree tree;
|
2017-11-02 03:36:13 +01:00
|
|
|
pt::read_ini(path.string(), tree);
|
2017-02-20 20:57:36 +01:00
|
|
|
|
|
|
|
for (const auto §ion : tree) {
|
|
|
|
for (const auto &subKey : section.second) {
|
|
|
|
cfg[section.first][subKey.first] = subKey.second.data();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cfg;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string stripWhitespace(const std::string &in) {
|
|
|
|
static const std::string whitespace = " \n\r\t";
|
|
|
|
auto start = in.find_first_not_of(whitespace);
|
|
|
|
auto end = in.find_last_not_of(whitespace) + 1;
|
|
|
|
return std::string(in, start, end - start);
|
|
|
|
}
|
2017-02-17 01:17:50 +01:00
|
|
|
|
2017-02-17 01:58:49 +01:00
|
|
|
simpleConfig_t getValidConfig() {
|
|
|
|
simpleConfig_t result;
|
2017-02-18 02:35:28 +01:00
|
|
|
// Some values and subkeys are surrounded by whitespace
|
|
|
|
// to test the robustness of the INI parser.
|
2017-02-17 01:58:49 +01:00
|
|
|
// Don't change game.path and input.invert_y keys. Tests depend on them.
|
|
|
|
result["game"]["path"] = "\t/dev/test \t \r\n";
|
2017-02-20 20:57:36 +01:00
|
|
|
result["game"]["\tlanguage\t "] =
|
|
|
|
" american ;american english french german italian spanish.";
|
|
|
|
result["input"]["invert_y"] =
|
|
|
|
"1 #values != 0 enable input inversion. Optional.";
|
2018-10-29 14:52:18 +01:00
|
|
|
result["game"]["hud_scale"] = "2.0\t;HUD scale";
|
2017-02-17 01:17:50 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-02-17 14:00:02 +01:00
|
|
|
std::ostream &operator<<(std::ostream &os, const simpleConfig_t &config) {
|
2017-02-17 01:17:50 +01:00
|
|
|
for (auto §ion : config) {
|
2017-02-20 20:57:36 +01:00
|
|
|
os << "[" << section.first << "]"
|
|
|
|
<< "\n";
|
2017-02-17 01:17:50 +01:00
|
|
|
for (auto &keyValue : section.second) {
|
|
|
|
os << keyValue.first << "=" << keyValue.second << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2017-04-22 03:13:32 +02:00
|
|
|
class Temp {
|
|
|
|
// An object of type Temp file will be removed on destruction
|
2017-02-17 14:00:02 +01:00
|
|
|
public:
|
2017-04-22 03:13:32 +02:00
|
|
|
virtual ~Temp() {
|
2017-02-17 14:00:02 +01:00
|
|
|
}
|
2017-04-22 03:13:32 +02:00
|
|
|
bool exists() const {
|
2017-11-02 03:36:13 +01:00
|
|
|
return rwfs::exists(this->m_path);
|
2017-02-17 14:00:02 +01:00
|
|
|
}
|
2017-11-02 03:36:13 +01:00
|
|
|
const rwfs::path &path() const {
|
|
|
|
return this->m_path;
|
2017-02-17 14:00:02 +01:00
|
|
|
}
|
2017-04-22 03:13:32 +02:00
|
|
|
std::string filename() const {
|
2017-02-17 14:00:02 +01:00
|
|
|
return this->m_path.filename().string();
|
|
|
|
}
|
2017-04-22 03:13:32 +02:00
|
|
|
std::string dirname() const {
|
2017-02-17 14:00:02 +01:00
|
|
|
return this->m_path.parent_path().string();
|
|
|
|
}
|
2017-08-30 23:57:57 +02:00
|
|
|
virtual void change_perms_normal() const = 0;
|
2017-04-22 03:13:32 +02:00
|
|
|
virtual void change_perms_readonly() const = 0;
|
|
|
|
virtual void remove() const = 0;
|
|
|
|
virtual void touch() const = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Temp(const Temp &) = delete;
|
|
|
|
Temp() : m_path(getRandomFilePath()) {
|
|
|
|
}
|
2017-11-02 03:36:13 +01:00
|
|
|
Temp(const rwfs::path &dirname) : m_path(getRandomFilePath(dirname)) {
|
2017-04-22 03:13:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2017-11-02 03:36:13 +01:00
|
|
|
static rwfs::path getRandomFilePath(const rwfs::path &dirname) {
|
|
|
|
return rwfs::unique_path(dirname / "openrw_test_%%%%%%%%%%%%%%%%");
|
2017-04-22 03:13:32 +02:00
|
|
|
}
|
2017-11-02 03:36:13 +01:00
|
|
|
static rwfs::path getRandomFilePath() {
|
|
|
|
return getRandomFilePath(rwfs::temp_directory_path());
|
2017-04-22 03:13:32 +02:00
|
|
|
}
|
2017-11-02 03:36:13 +01:00
|
|
|
rwfs::path m_path;
|
2017-04-22 03:13:32 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class TempFile;
|
|
|
|
|
|
|
|
class TempDir : public Temp {
|
|
|
|
public:
|
|
|
|
TempDir() : Temp() {
|
|
|
|
}
|
2017-11-02 03:36:13 +01:00
|
|
|
TempDir(const TempDir &dirname) : Temp(dirname.path()) {
|
2017-04-22 03:13:32 +02:00
|
|
|
}
|
|
|
|
virtual ~TempDir() {
|
|
|
|
this->remove();
|
|
|
|
}
|
2017-08-30 23:57:57 +02:00
|
|
|
virtual void change_perms_normal() const override {
|
|
|
|
rwfs::permissions(this->path(),
|
|
|
|
rwfs::perms::owner_read | rwfs::perms::owner_write | rwfs::perms::owner_exe |
|
|
|
|
rwfs::perms::group_read | rwfs::perms::group_exe |
|
|
|
|
rwfs::perms::others_read | rwfs::perms::others_exe);
|
|
|
|
}
|
2017-04-22 03:13:32 +02:00
|
|
|
virtual void change_perms_readonly() const override {
|
2017-11-02 03:36:13 +01:00
|
|
|
rwfs::permissions(this->path(),
|
|
|
|
rwfs::perms::owner_read | rwfs::perms::owner_exe |
|
|
|
|
rwfs::perms::group_read | rwfs::perms::group_exe |
|
|
|
|
rwfs::perms::others_read | rwfs::perms::others_exe);
|
2017-04-22 03:13:32 +02:00
|
|
|
}
|
|
|
|
virtual void remove() const override {
|
2017-08-30 23:57:57 +02:00
|
|
|
// Remove may fail if this directory contains a read-only entry. Ignore.
|
|
|
|
rwfs::error_code ec;
|
|
|
|
rwfs::remove_all(this->path(), ec);
|
2017-04-22 03:13:32 +02:00
|
|
|
}
|
|
|
|
void touch() const override {
|
2017-11-02 03:36:13 +01:00
|
|
|
rwfs::create_directories(this->path());
|
2017-04-22 03:13:32 +02:00
|
|
|
}
|
|
|
|
friend class TempFile;
|
|
|
|
};
|
|
|
|
|
|
|
|
class TempFile : public Temp {
|
|
|
|
public:
|
|
|
|
TempFile() : Temp() {
|
|
|
|
}
|
2017-11-02 03:36:13 +01:00
|
|
|
TempFile(const TempDir &dirname) : Temp(dirname.path()) {
|
2017-04-22 03:13:32 +02:00
|
|
|
}
|
|
|
|
virtual ~TempFile() {
|
|
|
|
this->remove();
|
|
|
|
}
|
2017-08-30 23:57:57 +02:00
|
|
|
virtual void change_perms_normal() const override {
|
|
|
|
rwfs::permissions(this->path(),
|
|
|
|
rwfs::perms::owner_read | rwfs::perms::owner_write |
|
|
|
|
rwfs::perms::group_read |
|
|
|
|
rwfs::perms::others_read);
|
|
|
|
}
|
2017-04-22 03:13:32 +02:00
|
|
|
virtual void change_perms_readonly() const override {
|
2017-11-02 03:36:13 +01:00
|
|
|
rwfs::permissions(this->path(), rwfs::perms::owner_read |
|
|
|
|
rwfs::perms::group_read |
|
|
|
|
rwfs::perms::others_read);
|
2017-04-22 03:13:32 +02:00
|
|
|
}
|
|
|
|
virtual void remove() const override {
|
2017-08-30 23:57:57 +02:00
|
|
|
rwfs::error_code ec;
|
|
|
|
rwfs::remove_all(this->path(), ec);
|
2017-04-22 03:13:32 +02:00
|
|
|
}
|
|
|
|
virtual void touch() const override {
|
2017-11-02 03:36:13 +01:00
|
|
|
std::ofstream ofs(this->path().string(), std::ios::out | std::ios::app);
|
2017-04-22 03:13:32 +02:00
|
|
|
ofs.close();
|
2017-02-18 07:33:53 +01:00
|
|
|
}
|
2017-02-20 20:57:36 +01:00
|
|
|
template <typename T>
|
2017-04-22 03:13:32 +02:00
|
|
|
bool append(T t) const {
|
2017-02-18 02:35:28 +01:00
|
|
|
// Append argument at the end of the file.
|
|
|
|
// File is open/closes repeatedly. Not optimal.
|
2017-11-02 03:36:13 +01:00
|
|
|
std::ofstream ofs(this->path().string(), std::ios::out | std::ios::app);
|
2017-02-17 14:00:02 +01:00
|
|
|
ofs << t;
|
|
|
|
ofs.close();
|
2017-02-18 07:33:53 +01:00
|
|
|
return ofs.good();
|
|
|
|
}
|
2017-02-20 20:57:36 +01:00
|
|
|
template <typename T>
|
2017-04-22 03:13:32 +02:00
|
|
|
bool write(T t) const {
|
2017-02-18 07:33:53 +01:00
|
|
|
// Write the argument to the file, discarding all contents.
|
|
|
|
// File is open/closes repeatedly. Not optimal.
|
2017-11-02 03:36:13 +01:00
|
|
|
std::ofstream ofs(this->path().string(), std::ios::out | std::ios::trunc);
|
2017-02-18 07:33:53 +01:00
|
|
|
ofs << t;
|
|
|
|
ofs.close();
|
|
|
|
return ofs.good();
|
2017-02-17 14:00:02 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-20 03:09:22 +02:00
|
|
|
BOOST_AUTO_TEST_SUITE(ConfigTests)
|
|
|
|
|
2017-02-20 20:57:36 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(test_stripWhitespace) {
|
|
|
|
std::map<std::string, std::string> map;
|
|
|
|
map["abc"] = "abc";
|
|
|
|
map["\tabc"] = "abc";
|
|
|
|
map["abc\t"] = "abc";
|
|
|
|
map[" abc"] = "abc";
|
|
|
|
map["abc "] = "abc";
|
|
|
|
map[" abc "] = "abc";
|
|
|
|
map[" abc "] = "abc";
|
|
|
|
for (const auto &keyValue : map) {
|
|
|
|
BOOST_CHECK_EQUAL(keyValue.second, stripWhitespace(keyValue.first));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-22 03:13:32 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(test_TempDir) {
|
|
|
|
// Check the behavior of TempFile
|
|
|
|
TempDir tempDir;
|
2017-11-02 03:36:13 +01:00
|
|
|
BOOST_CHECK(!tempDir.exists());
|
2017-04-22 03:13:32 +02:00
|
|
|
tempDir.touch();
|
2017-11-02 03:36:13 +01:00
|
|
|
BOOST_CHECK(tempDir.exists());
|
2017-04-22 03:13:32 +02:00
|
|
|
tempDir.remove();
|
2017-11-02 03:36:13 +01:00
|
|
|
BOOST_CHECK(!tempDir.exists());
|
2017-04-22 03:13:32 +02:00
|
|
|
|
|
|
|
tempDir.touch();
|
2017-11-02 03:36:13 +01:00
|
|
|
BOOST_CHECK(tempDir.exists());
|
2017-04-22 03:13:32 +02:00
|
|
|
|
|
|
|
TempDir tempChildDir(tempDir);
|
2017-11-02 03:36:13 +01:00
|
|
|
BOOST_CHECK(!tempChildDir.exists());
|
2017-04-22 03:13:32 +02:00
|
|
|
|
|
|
|
tempChildDir.touch();
|
2017-11-02 03:36:13 +01:00
|
|
|
BOOST_CHECK(tempChildDir.exists());
|
2017-04-22 03:13:32 +02:00
|
|
|
|
|
|
|
tempDir.remove();
|
2017-11-02 03:36:13 +01:00
|
|
|
BOOST_CHECK(!tempChildDir.exists());
|
|
|
|
BOOST_CHECK(!tempDir.exists());
|
2017-04-22 03:13:32 +02:00
|
|
|
|
|
|
|
tempChildDir.touch();
|
2017-11-02 03:36:13 +01:00
|
|
|
BOOST_CHECK(tempChildDir.exists());
|
2017-04-22 03:13:32 +02:00
|
|
|
|
2017-11-02 03:36:13 +01:00
|
|
|
rwfs::path path;
|
2017-04-22 03:13:32 +02:00
|
|
|
{
|
|
|
|
TempDir tempLocal;
|
|
|
|
tempLocal.touch();
|
2017-11-02 03:36:13 +01:00
|
|
|
BOOST_CHECK(tempLocal.exists());
|
2017-04-22 03:13:32 +02:00
|
|
|
path = tempLocal.path();
|
|
|
|
}
|
2017-11-02 03:36:13 +01:00
|
|
|
BOOST_CHECK(!rwfs::exists(path));
|
2017-04-22 03:13:32 +02:00
|
|
|
}
|
|
|
|
|
2017-02-18 02:35:28 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(test_TempFile) {
|
|
|
|
// Check the behavior of TempFile
|
|
|
|
TempFile tempFile;
|
2017-11-02 03:36:13 +01:00
|
|
|
BOOST_CHECK(!tempFile.exists());
|
2017-02-18 02:35:28 +01:00
|
|
|
tempFile.touch();
|
2017-11-02 03:36:13 +01:00
|
|
|
BOOST_CHECK(tempFile.exists());
|
2017-02-18 02:35:28 +01:00
|
|
|
tempFile.remove();
|
2017-11-02 03:36:13 +01:00
|
|
|
BOOST_CHECK(!tempFile.exists());
|
2017-02-18 02:35:28 +01:00
|
|
|
|
|
|
|
tempFile.touch();
|
2017-11-02 03:36:13 +01:00
|
|
|
BOOST_CHECK(tempFile.exists());
|
2017-02-18 02:35:28 +01:00
|
|
|
tempFile.remove();
|
|
|
|
|
2017-11-02 03:36:13 +01:00
|
|
|
BOOST_CHECK(tempFile.append("abc"));
|
|
|
|
BOOST_CHECK(tempFile.append("def"));
|
|
|
|
BOOST_CHECK(tempFile.exists());
|
2017-02-18 02:35:28 +01:00
|
|
|
tempFile.touch();
|
2017-11-02 03:36:13 +01:00
|
|
|
std::ifstream ifs(tempFile.path().string());
|
2017-02-18 02:35:28 +01:00
|
|
|
std::string line;
|
|
|
|
std::getline(ifs, line);
|
|
|
|
BOOST_CHECK_EQUAL(line, "abcdef");
|
2017-02-18 07:33:53 +01:00
|
|
|
|
|
|
|
tempFile.change_perms_readonly();
|
2017-11-02 03:36:13 +01:00
|
|
|
BOOST_CHECK(!tempFile.write("abc"));
|
|
|
|
BOOST_CHECK(!tempFile.append("def"));
|
2017-04-22 03:13:32 +02:00
|
|
|
|
2017-11-02 03:36:13 +01:00
|
|
|
rwfs::path path;
|
2017-04-22 03:13:32 +02:00
|
|
|
{
|
|
|
|
TempFile tempLocal;
|
|
|
|
tempLocal.touch();
|
2017-11-02 03:36:13 +01:00
|
|
|
BOOST_CHECK(tempLocal.exists());
|
2017-04-22 03:13:32 +02:00
|
|
|
path = tempLocal.path();
|
|
|
|
}
|
2017-11-02 03:36:13 +01:00
|
|
|
BOOST_CHECK(!rwfs::exists(path));
|
|
|
|
}
|
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(test_configParser_initial) {
|
2017-11-02 03:36:13 +01:00
|
|
|
// Test an initial config
|
2018-12-12 18:51:04 +01:00
|
|
|
[[maybe_unused]] RWConfigParser cfgParser;
|
2017-02-18 02:35:28 +01:00
|
|
|
}
|
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(test_configParser_valid) {
|
2017-02-17 01:58:49 +01:00
|
|
|
// Test reading a valid configuration file
|
2017-02-17 01:17:50 +01:00
|
|
|
auto cfg = getValidConfig();
|
2017-01-15 03:16:46 +01:00
|
|
|
|
2017-02-17 14:00:02 +01:00
|
|
|
TempFile tempFile;
|
2017-02-18 07:33:53 +01:00
|
|
|
tempFile.append(cfg);
|
2016-05-20 03:09:22 +02:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
RWConfigParser cfgParser;
|
|
|
|
auto [cfgLayer, parseResult] = cfgParser.loadFile(tempFile.path());
|
2016-05-20 03:09:22 +02:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_CHECK(parseResult.isValid());
|
|
|
|
BOOST_CHECK_EQUAL(parseResult.type(),
|
|
|
|
RWConfigParser::ParseResult::GOOD);
|
|
|
|
BOOST_CHECK_EQUAL(parseResult.getKeysInvalidData().size(), 0);
|
|
|
|
|
|
|
|
BOOST_REQUIRE(cfgLayer.gamedataPath.has_value());
|
|
|
|
BOOST_REQUIRE(cfgLayer.gameLanguage.has_value());
|
|
|
|
BOOST_REQUIRE(cfgLayer.invertY.has_value());
|
|
|
|
BOOST_REQUIRE(cfgLayer.hudScale.has_value());
|
2016-05-20 03:09:22 +02:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_CHECK_EQUAL(*cfgLayer.gamedataPath, "/dev/test");
|
|
|
|
BOOST_CHECK_EQUAL(*cfgLayer.gameLanguage, "american");
|
|
|
|
BOOST_CHECK(*cfgLayer.invertY);
|
|
|
|
BOOST_CHECK_EQUAL(*cfgLayer.hudScale, 2.f);
|
2017-02-17 01:17:50 +01:00
|
|
|
}
|
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(test_configParser_valid_modified) {
|
2017-02-17 01:58:49 +01:00
|
|
|
// Test reading a valid modified configuration file
|
2017-02-17 01:17:50 +01:00
|
|
|
auto cfg = getValidConfig();
|
2017-02-17 01:58:49 +01:00
|
|
|
cfg["game"]["path"] = "Liberty City";
|
2017-02-17 01:17:50 +01:00
|
|
|
cfg["input"]["invert_y"] = "0";
|
|
|
|
|
2017-02-17 14:00:02 +01:00
|
|
|
TempFile tempFile;
|
2017-02-18 07:33:53 +01:00
|
|
|
tempFile.append(cfg);
|
2017-02-17 01:17:50 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
RWConfigParser cfgParser;
|
|
|
|
auto [cfgLayer, parseResult] = cfgParser.loadFile(tempFile.path());
|
2017-02-17 01:17:50 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_CHECK(parseResult.isValid());
|
|
|
|
BOOST_CHECK_EQUAL(parseResult.type(),
|
|
|
|
RWConfigParser::ParseResult::GOOD);
|
|
|
|
BOOST_CHECK_EQUAL(parseResult.getKeysInvalidData().size(), 0);
|
2017-02-17 01:17:50 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_REQUIRE(cfgLayer.invertY.has_value());
|
|
|
|
BOOST_REQUIRE(cfgLayer.gamedataPath.has_value());
|
|
|
|
BOOST_CHECK(!*cfgLayer.invertY);
|
|
|
|
BOOST_CHECK_EQUAL(*cfgLayer.gamedataPath, "Liberty City");
|
2017-02-17 01:58:49 +01:00
|
|
|
}
|
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(test_configParser_save) {
|
2017-02-17 01:58:49 +01:00
|
|
|
// Test saving a configuration file
|
|
|
|
auto cfg = getValidConfig();
|
|
|
|
cfg["game"]["path"] = "Liberty City";
|
|
|
|
|
2017-02-17 14:00:02 +01:00
|
|
|
TempFile tempFile;
|
2017-02-18 07:33:53 +01:00
|
|
|
tempFile.append(cfg);
|
2017-02-17 01:58:49 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
{
|
|
|
|
RWConfigLayer cfgLayer;
|
|
|
|
{
|
|
|
|
RWConfigParser cfgParser;
|
|
|
|
RWConfigParser::ParseResult parseResult;
|
|
|
|
std::tie(cfgLayer, parseResult) = cfgParser.loadFile(tempFile.path());
|
|
|
|
BOOST_CHECK(parseResult.isValid());
|
|
|
|
BOOST_REQUIRE(cfgLayer.gamedataPath.has_value());
|
|
|
|
}
|
2017-02-17 01:58:49 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
tempFile.remove();
|
|
|
|
BOOST_CHECK(!tempFile.exists());
|
2017-02-18 07:33:53 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
{
|
|
|
|
RWConfigParser cfgParser;
|
|
|
|
auto parseResult = cfgParser.saveFile(tempFile.path(), cfgLayer);
|
|
|
|
BOOST_CHECK(parseResult.isValid());
|
|
|
|
BOOST_CHECK(tempFile.exists());
|
|
|
|
}
|
|
|
|
}
|
2017-02-17 14:00:02 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
{
|
|
|
|
RWConfigParser cfgParser;
|
|
|
|
auto [cfgLayer, parseResult] = cfgParser.loadFile(tempFile.path());
|
|
|
|
BOOST_CHECK(parseResult.isValid());
|
2017-02-17 14:00:02 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_REQUIRE(cfgLayer.gamedataPath.has_value());
|
|
|
|
BOOST_CHECK_EQUAL(*cfgLayer.gamedataPath, "Liberty City");
|
|
|
|
}
|
2017-02-20 20:57:36 +01:00
|
|
|
|
|
|
|
simpleConfig_t cfg2 = readConfig(tempFile.path());
|
|
|
|
BOOST_CHECK_EQUAL(cfg2["game"]["path"], "Liberty City");
|
|
|
|
}
|
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(test_configParser_valid_unknown_keys) {
|
2017-02-20 20:57:36 +01:00
|
|
|
// Test reading a valid modified configuration file with unknown data
|
|
|
|
auto cfg = getValidConfig();
|
|
|
|
cfg["game"]["unknownkey"] = "descartes";
|
|
|
|
cfg["dontknow"]["dontcare"] = "\t$%!$8847 %%$ ";
|
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
std::map<std::string, std::string> globalUnknownData;
|
|
|
|
|
2017-02-20 20:57:36 +01:00
|
|
|
TempFile tempFile;
|
|
|
|
tempFile.append(cfg);
|
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
{
|
|
|
|
RWConfigParser cfgParser;
|
|
|
|
RWConfigLayer cfgLayer;
|
|
|
|
{
|
|
|
|
RWConfigParser::ParseResult parseResult;
|
|
|
|
std::tie(cfgLayer, parseResult) = cfgParser.loadFile(tempFile.path());
|
2017-02-20 20:57:36 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_CHECK(parseResult.isValid());
|
2017-02-20 20:57:36 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
const auto &unknownData = parseResult.getUnknownData();
|
2017-02-20 20:57:36 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_CHECK_EQUAL(unknownData.size(), 2);
|
2017-02-20 20:57:36 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_CHECK_EQUAL(unknownData.count("game.unknownkey"), 1);
|
|
|
|
BOOST_CHECK_EQUAL(unknownData.at("game.unknownkey"),
|
|
|
|
stripWhitespace(cfg["game"]["unknownkey"]));
|
2017-02-20 20:57:36 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_CHECK_EQUAL(unknownData.count("dontknow.dontcare"), 1);
|
|
|
|
BOOST_CHECK_EQUAL(unknownData.at("dontknow.dontcare"),
|
|
|
|
stripWhitespace(cfg["dontknow"]["dontcare"]));
|
2017-02-20 20:57:36 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_CHECK_EQUAL(unknownData.count("game.path"), 0);
|
|
|
|
globalUnknownData = unknownData;
|
|
|
|
}
|
2017-02-20 20:57:36 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
tempFile.remove();
|
2017-02-20 20:57:36 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
{
|
|
|
|
auto parseResult = cfgParser.saveFile(tempFile.path(), cfgLayer, globalUnknownData);
|
|
|
|
BOOST_CHECK(parseResult.isValid());
|
|
|
|
}
|
|
|
|
}
|
2017-02-20 20:57:36 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
{
|
|
|
|
RWConfigParser cfgParser;
|
|
|
|
auto [cfgLayer, parseResult] = cfgParser.loadFile(tempFile.path());
|
|
|
|
BOOST_CHECK(parseResult.isValid());
|
|
|
|
const auto &unknownData = parseResult.getUnknownData();
|
2017-02-20 20:57:36 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_REQUIRE_EQUAL(unknownData.size(), 2);
|
2017-02-20 20:57:36 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_CHECK_EQUAL(unknownData.count("game.unknownkey"), 1);
|
|
|
|
BOOST_CHECK_EQUAL(unknownData.at("game.unknownkey"),
|
|
|
|
stripWhitespace(cfg["game"]["unknownkey"]));
|
2017-02-20 20:57:36 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_CHECK_EQUAL(unknownData.count("dontknow.dontcare"), 1);
|
|
|
|
BOOST_CHECK_EQUAL(unknownData.at("dontknow.dontcare"),
|
|
|
|
stripWhitespace(cfg["dontknow"]["dontcare"]));
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(unknownData.count("game.path"), 0);
|
|
|
|
}
|
2016-05-20 03:09:22 +02:00
|
|
|
}
|
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(test_configParser_valid_empty_file) {
|
|
|
|
// An empty config file is valid
|
|
|
|
TempFile tempFile;
|
|
|
|
tempFile.touch();
|
|
|
|
|
|
|
|
RWConfigParser cfgParser;
|
|
|
|
auto [cfgLayer, parseResult] = cfgParser.loadFile(tempFile.path());
|
|
|
|
BOOST_CHECK(parseResult.isValid());
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(test_configParser_save_readonly) {
|
2017-02-18 07:33:53 +01:00
|
|
|
// Test whether saving to a readonly INI file fails
|
|
|
|
auto cfg = getValidConfig();
|
|
|
|
|
|
|
|
TempFile tempFile;
|
|
|
|
tempFile.append(cfg);
|
|
|
|
tempFile.change_perms_readonly();
|
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
RWConfigParser cfgParser;
|
|
|
|
RWConfigLayer cfgLayer;
|
|
|
|
{
|
|
|
|
RWConfigParser::ParseResult parseResult;
|
|
|
|
std::tie(cfgLayer, parseResult) = cfgParser.loadFile(tempFile.path());
|
|
|
|
BOOST_CHECK(parseResult.isValid());
|
|
|
|
}
|
2017-02-18 07:33:53 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
{
|
|
|
|
auto parseResult = cfgParser.saveFile(tempFile.path(), cfgLayer);
|
|
|
|
BOOST_CHECK(!parseResult.isValid());
|
|
|
|
BOOST_CHECK_EQUAL(parseResult.type(),
|
|
|
|
RWConfigParser::ParseResult::INVALIDOUTPUTFILE);
|
|
|
|
}
|
2017-02-18 07:33:53 +01:00
|
|
|
}
|
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(test_configParser_valid_default) {
|
2017-02-17 14:00:02 +01:00
|
|
|
// Test whether the default INI string is valid
|
|
|
|
TempFile tempFile;
|
|
|
|
BOOST_CHECK(!tempFile.exists());
|
2017-02-18 07:33:53 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
RWConfigParser cfgParser;
|
|
|
|
{
|
|
|
|
auto [cfgLayer, parseResult] = cfgParser.loadFile(tempFile.path());
|
|
|
|
BOOST_CHECK(!parseResult.isValid());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
auto defaultLayer = buildDefaultConfigLayer();
|
|
|
|
auto parseResult = cfgParser.saveFile(tempFile.path(), defaultLayer);
|
|
|
|
BOOST_CHECK(parseResult.isValid());
|
|
|
|
}
|
2017-02-17 14:00:02 +01:00
|
|
|
|
2017-11-02 03:36:13 +01:00
|
|
|
BOOST_CHECK(tempFile.exists());
|
2017-02-17 14:00:02 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
{
|
|
|
|
auto [cfgLayer, parseResult] = cfgParser.loadFile(tempFile.path());
|
|
|
|
BOOST_CHECK(parseResult.isValid());
|
|
|
|
}
|
2017-02-17 14:00:02 +01:00
|
|
|
}
|
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(test_configParser_invalid_emptykey) {
|
2017-02-20 20:57:36 +01:00
|
|
|
// Test duplicate keys in invalid configuration file
|
|
|
|
auto cfg = getValidConfig();
|
|
|
|
cfg["game"][""] = "0";
|
|
|
|
|
|
|
|
TempFile tempFile;
|
|
|
|
tempFile.append(cfg);
|
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
RWConfigParser cfgParser;
|
|
|
|
auto [cfgLayer, parseResult] = cfgParser.loadFile(tempFile.path());
|
2017-02-20 20:57:36 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_CHECK(!parseResult.isValid());
|
2017-02-20 20:57:36 +01:00
|
|
|
BOOST_CHECK_EQUAL(parseResult.type(),
|
2018-12-12 18:51:04 +01:00
|
|
|
RWConfigParser::ParseResult::INVALIDINPUTFILE);
|
2017-02-20 20:57:36 +01:00
|
|
|
}
|
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(test_configParser_invalid_duplicate) {
|
2017-02-17 01:58:49 +01:00
|
|
|
// Test duplicate keys in invalid configuration file
|
2017-02-17 01:17:50 +01:00
|
|
|
auto cfg = getValidConfig();
|
|
|
|
cfg["input"]["invert_y "] = "0";
|
|
|
|
|
2017-02-17 14:00:02 +01:00
|
|
|
TempFile tempFile;
|
2017-02-18 07:33:53 +01:00
|
|
|
tempFile.append(cfg);
|
2017-02-17 01:17:50 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
RWConfigParser cfgParser;
|
|
|
|
auto [cfgLayer, parseResult] = cfgParser.loadFile(tempFile.path());
|
2017-02-17 01:17:50 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_CHECK(!parseResult.isValid());
|
2017-02-20 20:57:36 +01:00
|
|
|
BOOST_CHECK_EQUAL(parseResult.type(),
|
2018-12-12 18:51:04 +01:00
|
|
|
RWConfigParser::ParseResult::INVALIDINPUTFILE);
|
2017-02-17 01:17:50 +01:00
|
|
|
}
|
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(test_configParser_invalid_wrong_type) {
|
|
|
|
// Test wrong data type
|
2017-02-17 01:58:49 +01:00
|
|
|
auto cfg = getValidConfig();
|
2018-12-12 18:51:04 +01:00
|
|
|
cfg["input"]["invert_y"] = "d";
|
2017-02-17 01:58:49 +01:00
|
|
|
|
2017-02-17 14:00:02 +01:00
|
|
|
TempFile tempFile;
|
2017-02-18 07:33:53 +01:00
|
|
|
tempFile.append(cfg);
|
2017-02-17 01:58:49 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
RWConfigParser cfgParser;
|
|
|
|
auto [cfgLayer, parseResult] = cfgParser.loadFile(tempFile.path());
|
2017-02-17 01:58:49 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_CHECK(!parseResult.isValid());
|
2017-02-18 07:33:53 +01:00
|
|
|
|
2017-02-20 20:57:36 +01:00
|
|
|
BOOST_CHECK_EQUAL(parseResult.type(),
|
2018-12-12 18:51:04 +01:00
|
|
|
RWConfigParser::ParseResult::INVALIDCONTENT);
|
2017-02-18 07:33:53 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_REQUIRE_EQUAL(parseResult.getKeysInvalidData().size(), 1);
|
2017-02-18 07:33:53 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_CHECK_EQUAL(parseResult.getKeysInvalidData()[0], "input.invert_y");
|
2017-02-17 01:58:49 +01:00
|
|
|
}
|
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(test_configParser_invalid_nodir) {
|
|
|
|
// Test reading non-existing configuration file in non-existing directory
|
|
|
|
TempDir tempDir;
|
|
|
|
TempFile tempFile(tempDir);
|
|
|
|
|
|
|
|
BOOST_CHECK(!tempDir.exists());
|
|
|
|
BOOST_CHECK(!tempFile.exists());
|
|
|
|
|
|
|
|
RWConfigParser cfgParser;
|
|
|
|
auto [cfgLayer, parseResult] = cfgParser.loadFile(tempFile.path());
|
|
|
|
|
|
|
|
BOOST_CHECK(!parseResult.isValid());
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(parseResult.type(),
|
|
|
|
RWConfigParser::ParseResult::INVALIDINPUTFILE);
|
|
|
|
}
|
2017-02-17 19:19:02 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(test_configParser_invalid_nonexisting) {
|
|
|
|
// Test reading non-existing configuration file
|
2017-02-17 19:19:02 +01:00
|
|
|
TempFile tempFile;
|
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_CHECK(!tempFile.exists());
|
|
|
|
RWConfigParser cfgParser;
|
|
|
|
auto [cfgLayer, parseResult] = cfgParser.loadFile(tempFile.path());
|
2017-02-17 19:19:02 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_CHECK(!parseResult.isValid());
|
2017-02-18 07:33:53 +01:00
|
|
|
|
2017-02-20 20:57:36 +01:00
|
|
|
BOOST_CHECK_EQUAL(parseResult.type(),
|
2018-12-12 18:51:04 +01:00
|
|
|
RWConfigParser::ParseResult::INVALIDINPUTFILE);
|
|
|
|
}
|
2017-02-18 07:33:53 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(test_argParser_nullptr) {
|
|
|
|
RWArgumentParser argParser;
|
|
|
|
argParser.parseArguments(0, nullptr);
|
|
|
|
}
|
2017-02-18 07:33:53 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(test_argParser_one) {
|
|
|
|
RWArgumentParser argParser;
|
|
|
|
const char *args[] = {""};
|
|
|
|
argParser.parseArguments(1, args);
|
2017-02-17 19:19:02 +01:00
|
|
|
}
|
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(test_argParser_optional_nonexisting) {
|
|
|
|
RWArgumentParser argParser;
|
|
|
|
const char *args[] = {"", "--nonexistingoptional"};
|
|
|
|
auto optLayer = argParser.parseArguments(2, args);
|
|
|
|
BOOST_CHECK(!optLayer.has_value());
|
|
|
|
}
|
2017-02-17 01:17:50 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(test_argParser_positional_nonexisting) {
|
|
|
|
RWArgumentParser argParser;
|
|
|
|
const char *args[] = {"", "nonexistingpositional"};
|
|
|
|
auto optLayer = argParser.parseArguments(2, args);
|
|
|
|
BOOST_CHECK(!optLayer.has_value());
|
|
|
|
}
|
2017-02-17 01:17:50 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(test_argParser_bool) {
|
|
|
|
RWArgumentParser argParser;
|
|
|
|
const char *args[] = {"", "--help"};
|
|
|
|
auto optLayer = argParser.parseArguments(2, args);
|
|
|
|
BOOST_REQUIRE(optLayer.has_value());
|
|
|
|
BOOST_CHECK(optLayer->help);
|
|
|
|
}
|
2017-02-18 07:33:53 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(test_argParser_string) {
|
|
|
|
RWArgumentParser argParser;
|
|
|
|
{
|
|
|
|
const auto path = "/some/path";
|
|
|
|
const char *args[] = {"", "-c", path};
|
|
|
|
auto optLayer = argParser.parseArguments(3, args);
|
|
|
|
BOOST_REQUIRE(optLayer.has_value());
|
|
|
|
BOOST_REQUIRE(optLayer->configPath.has_value());
|
|
|
|
BOOST_CHECK_EQUAL(*optLayer->configPath, path);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
const auto path = "/some/path";
|
|
|
|
const char *args[] = {"", "-b", path};
|
|
|
|
auto optLayer = argParser.parseArguments(3, args);
|
|
|
|
BOOST_REQUIRE(optLayer.has_value());
|
|
|
|
BOOST_REQUIRE(optLayer->benchmarkPath.has_value());
|
|
|
|
BOOST_CHECK_EQUAL(*optLayer->benchmarkPath, path);
|
|
|
|
}
|
2017-02-17 01:17:50 +01:00
|
|
|
}
|
2017-01-06 22:45:25 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(test_argParser_int) {
|
|
|
|
RWArgumentParser argParser;
|
2017-04-22 03:13:32 +02:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
const int width = 1920;
|
|
|
|
const auto widthStr = std::to_string(width);
|
|
|
|
const char *args[] = {"", "-w", widthStr.c_str()};
|
|
|
|
auto optLayer = argParser.parseArguments(3, args);
|
2017-11-02 03:36:13 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_REQUIRE(optLayer.has_value());
|
|
|
|
BOOST_REQUIRE(optLayer->width.has_value());
|
|
|
|
BOOST_CHECK_EQUAL(*optLayer->width, width);
|
|
|
|
}
|
2017-04-22 03:13:32 +02:00
|
|
|
|
2019-01-03 04:27:27 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(test_argParser_incomplete_optional) {
|
|
|
|
RWArgumentParser argParser;
|
|
|
|
const char *args[] = {"", "--hel"};
|
|
|
|
auto optLayer = argParser.parseArguments(2, args);
|
|
|
|
BOOST_CHECK(!optLayer.has_value());
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(test_argParser_case_sensitive) {
|
|
|
|
RWArgumentParser argParser;
|
|
|
|
const char *args[] = {"", "--HELP"};
|
|
|
|
auto optLayer = argParser.parseArguments(2, args);
|
|
|
|
BOOST_CHECK(!optLayer.has_value());
|
|
|
|
}
|
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(test_argParser_int_invalid) {
|
|
|
|
RWArgumentParser argParser;
|
2017-04-22 03:13:32 +02:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
const auto widthStr = "1920d";
|
|
|
|
const char *args[] = {"", "-w", widthStr};
|
|
|
|
auto optLayer = argParser.parseArguments(3, args);
|
|
|
|
|
|
|
|
BOOST_CHECK(!optLayer.has_value());
|
2017-04-22 03:13:32 +02:00
|
|
|
}
|
|
|
|
|
2019-01-03 04:27:27 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(test_argParser_bool_newgame) {
|
|
|
|
RWArgumentParser argParser;
|
|
|
|
{
|
|
|
|
const char *args[] = {""};
|
|
|
|
auto optLayer = argParser.parseArguments(1, args);
|
|
|
|
|
|
|
|
BOOST_REQUIRE(optLayer.has_value());
|
|
|
|
BOOST_CHECK(!optLayer->newGame);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
const char *args[] = {"", "-n"};
|
|
|
|
auto optLayer = argParser.parseArguments(2, args);
|
|
|
|
|
|
|
|
BOOST_REQUIRE(optLayer.has_value());
|
|
|
|
BOOST_CHECK(optLayer->newGame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(test_argParser_bool_invert_y) {
|
|
|
|
RWArgumentParser argParser;
|
|
|
|
{
|
|
|
|
const char *args[] = {""};
|
|
|
|
auto optLayer = argParser.parseArguments(1, args);
|
|
|
|
|
|
|
|
BOOST_REQUIRE(optLayer.has_value());
|
|
|
|
BOOST_CHECK(!optLayer->invertY.has_value());
|
|
|
|
}
|
|
|
|
{
|
|
|
|
const char *args[] = {"", "--invert_y"};
|
|
|
|
auto optLayer = argParser.parseArguments(2, args);
|
|
|
|
|
|
|
|
BOOST_REQUIRE(optLayer.has_value());
|
|
|
|
BOOST_REQUIRE(optLayer->invertY.has_value());
|
|
|
|
BOOST_CHECK(*optLayer->invertY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(test_rwconfig_initial) {
|
|
|
|
RWConfig config;
|
|
|
|
auto missingKeys = config.missingKeys();
|
|
|
|
BOOST_CHECK_NE(missingKeys.size(), 0u);
|
|
|
|
}
|
2017-02-17 01:58:49 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(test_rwconfig_defaultLayer) {
|
|
|
|
auto defaultLayer = buildDefaultConfigLayer();
|
|
|
|
RWConfig config;
|
2017-02-17 01:58:49 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
config.setLayer(RWConfig::LAYER_DEFAULT, defaultLayer);
|
|
|
|
BOOST_CHECK_NE(config.missingKeys().size(), 0u);
|
|
|
|
BOOST_CHECK_EQUAL(config.missingKeys().size(), 1u);
|
2017-02-18 07:33:53 +01:00
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
defaultLayer.gamedataPath = "/path/to/gamedata";
|
|
|
|
config.setLayer(RWConfig::LAYER_DEFAULT, defaultLayer);
|
|
|
|
|
|
|
|
BOOST_REQUIRE(config.layers[RWConfig::LAYER_DEFAULT].gamedataPath.has_value());
|
|
|
|
BOOST_CHECK_EQUAL(*config.layers[RWConfig::LAYER_DEFAULT].gamedataPath, "/path/to/gamedata");
|
|
|
|
BOOST_CHECK_EQUAL(config.gamedataPath(), "/path/to/gamedata");
|
|
|
|
BOOST_CHECK_EQUAL(config.missingKeys().size(), 0u);
|
|
|
|
|
|
|
|
config.layers[RWConfig::LAYER_USER].gamedataPath = "/some/other/path/to/gamedata";
|
|
|
|
BOOST_REQUIRE(config.layers[RWConfig::LAYER_DEFAULT].gamedataPath.has_value());
|
|
|
|
BOOST_CHECK_EQUAL(*config.layers[RWConfig::LAYER_DEFAULT].gamedataPath, "/path/to/gamedata");
|
|
|
|
BOOST_REQUIRE(config.layers[RWConfig::LAYER_USER].gamedataPath.has_value());
|
|
|
|
BOOST_CHECK_EQUAL(*config.layers[RWConfig::LAYER_USER].gamedataPath, "/some/other/path/to/gamedata");
|
|
|
|
BOOST_CHECK_EQUAL(config.gamedataPath(), "/some/other/path/to/gamedata");
|
2017-02-17 01:58:49 +01:00
|
|
|
}
|
|
|
|
|
2016-05-20 03:09:22 +02:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|