mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-22 02:12:45 +01:00
config: fix TempFile.touch() + TempFile test + extra doc of getValidConfig
This commit is contained in:
parent
90001b11ac
commit
e0813e4378
@ -105,7 +105,7 @@ struct IntTranslator {
|
||||
return res;
|
||||
}
|
||||
boost::optional<internal_type> put_value(const external_type &i) {
|
||||
return boost::optional<internal_type>(std::to_string(i));
|
||||
return std::to_string(i);
|
||||
}
|
||||
};
|
||||
|
||||
@ -190,7 +190,7 @@ bool GameConfig::parseConfig(
|
||||
success = false;
|
||||
break;
|
||||
case ParseType::CONFIG:
|
||||
//Don't care if success == false
|
||||
// Don't care if success == false
|
||||
target = sourceValue;
|
||||
break;
|
||||
case ParseType::FILE:
|
||||
@ -229,4 +229,3 @@ bool GameConfig::parseConfig(
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,8 @@ typedef std::map<std::string, std::map<std::string, std::string>> simpleConfig_t
|
||||
|
||||
simpleConfig_t getValidConfig() {
|
||||
simpleConfig_t result;
|
||||
// Some values and subkeys are surrounded by whitespace
|
||||
// to test the robustness of the INI parser.
|
||||
// Don't change game.path and input.invert_y keys. Tests depend on them.
|
||||
result["game"]["path"] = "\t/dev/test \t \r\n";
|
||||
result["game"]["\tlanguage\t "] = " american ;american english french german italian spanish.";
|
||||
@ -41,7 +43,7 @@ public:
|
||||
fs::remove(this->m_path);
|
||||
}
|
||||
void touch() {
|
||||
std::ofstream ofs(this->path());
|
||||
std::ofstream ofs(this->path(), std::ios::out | std::ios::app);
|
||||
ofs.close();
|
||||
}
|
||||
bool exists() {
|
||||
@ -58,7 +60,9 @@ public:
|
||||
}
|
||||
template<typename T>
|
||||
void write(T t) {
|
||||
std::ofstream ofs(this->path());
|
||||
// Append argument at the end of the file.
|
||||
// File is open/closes repeatedly. Not optimal.
|
||||
std::ofstream ofs(this->path(), std::ios::out | std::ios::app);
|
||||
ofs << t;
|
||||
ofs.close();
|
||||
}
|
||||
@ -71,6 +75,29 @@ private:
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(ConfigTests)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_TempFile) {
|
||||
// Check the behavior of TempFile
|
||||
TempFile tempFile;
|
||||
BOOST_CHECK_EQUAL(tempFile.exists(), false);
|
||||
tempFile.touch();
|
||||
BOOST_CHECK_EQUAL(tempFile.exists(), true);
|
||||
tempFile.remove();
|
||||
BOOST_CHECK_EQUAL(tempFile.exists(), false);
|
||||
|
||||
tempFile.touch();
|
||||
BOOST_CHECK_EQUAL(tempFile.exists(), true);
|
||||
tempFile.remove();
|
||||
|
||||
tempFile.write("abc");
|
||||
tempFile.write("def");
|
||||
BOOST_CHECK_EQUAL(tempFile.exists(), true);
|
||||
tempFile.touch();
|
||||
std::ifstream ifs(tempFile.path());
|
||||
std::string line;
|
||||
std::getline(ifs, line);
|
||||
BOOST_CHECK_EQUAL(line, "abcdef");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_config_valid) {
|
||||
// Test reading a valid configuration file
|
||||
auto cfg = getValidConfig();
|
||||
|
Loading…
Reference in New Issue
Block a user