add more tests to LuaAPI::FS, minor fixes to LuaAPI::FS

test config file creation, too
This commit is contained in:
Lion Kortlepel 2022-05-26 13:49:13 +02:00
parent 811ace1999
commit 22b63220c7
No known key found for this signature in database
GPG Key ID: 4322FF2B4C71259B
2 changed files with 53 additions and 0 deletions

View File

@ -434,22 +434,50 @@ std::string LuaAPI::FS::GetFilename(const std::string& Path) {
return fs::path(Path).filename().string();
}
TEST_CASE("LuaAPI::FS::GetFilename") {
CHECK(LuaAPI::FS::GetFilename("test.txt") == "test.txt");
CHECK(LuaAPI::FS::GetFilename("/test.txt") == "test.txt");
CHECK(LuaAPI::FS::GetFilename("place/test.txt") == "test.txt");
CHECK(LuaAPI::FS::GetFilename("/some/../place/test.txt") == "test.txt");
}
std::string LuaAPI::FS::GetExtension(const std::string& Path) {
return fs::path(Path).extension().string();
}
TEST_CASE("LuaAPI::FS::GetExtension") {
CHECK(LuaAPI::FS::GetExtension("test.txt") == ".txt");
CHECK(LuaAPI::FS::GetExtension("/test.txt") == ".txt");
CHECK(LuaAPI::FS::GetExtension("place/test.txt") == ".txt");
CHECK(LuaAPI::FS::GetExtension("/some/../place/test.txt") == ".txt");
CHECK(LuaAPI::FS::GetExtension("/some/../place/test") == "");
CHECK(LuaAPI::FS::GetExtension("/some/../place/test.a.b.c") == ".c");
CHECK(LuaAPI::FS::GetExtension("/some/../place/test.") == ".");
CHECK(LuaAPI::FS::GetExtension("/some/../place/test.a.b.") == ".");
}
std::string LuaAPI::FS::GetParentFolder(const std::string& Path) {
return fs::path(Path).parent_path().string();
}
TEST_CASE("LuaAPI::FS::GetParentFolder") {
CHECK(LuaAPI::FS::GetParentFolder("test.txt") == "");
CHECK(LuaAPI::FS::GetParentFolder("/test.txt") == "/");
CHECK(LuaAPI::FS::GetParentFolder("place/test.txt") == "place");
CHECK(LuaAPI::FS::GetParentFolder("/some/../place/test.txt") == "/some/../place");
}
// TODO: add tests
bool LuaAPI::FS::IsDirectory(const std::string& Path) {
return fs::is_directory(Path);
}
// TODO: add tests
bool LuaAPI::FS::IsFile(const std::string& Path) {
return fs::is_regular_file(Path);
}
// TODO: add tests
std::string LuaAPI::FS::ConcatPaths(sol::variadic_args Args) {
fs::path Path;
for (size_t i = 0; i < Args.size(); ++i) {

View File

@ -32,6 +32,31 @@ static constexpr std::string_view StrSSLCertPath = "SSLCertPath";
static constexpr std::string_view StrHTTPServerPort = "HTTPServerPort";
static constexpr std::string_view StrHTTPServerIP = "HTTPServerIP";
TEST_CASE("TConfig::TConfig") {
const std::string CfgFile = "beammp_server_testconfig.toml";
fs::remove(CfgFile);
TConfig Cfg(CfgFile);
CHECK(fs::file_size(CfgFile) != 0);
std::string buf;
{
buf.resize(fs::file_size(CfgFile));
auto fp = std::fopen(CfgFile.c_str(), "r");
std::fread(buf.data(), 1, buf.size(), fp);
std::fclose(fp);
}
INFO("file contents are:", buf);
const auto table = toml::parse(CfgFile);
CHECK(table.at("General").is_table());
CHECK(table.at("Misc").is_table());
CHECK(table.at("HTTP").is_table());
fs::remove(CfgFile);
}
TConfig::TConfig(const std::string& ConfigFileName)
: mConfigFileName(ConfigFileName) {
Application::SetSubsystemStatus("Config", Application::Status::Starting);