mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-03 08:15:35 +00:00
add more tests to LuaAPI::FS, minor fixes to LuaAPI::FS
test config file creation, too
This commit is contained in:
parent
811ace1999
commit
22b63220c7
@ -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) {
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user