mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-01 15:26:59 +00:00
add moar tests!!!
This commit is contained in:
parent
46b92b4992
commit
f06f31c2a0
@ -62,6 +62,7 @@ elseif (UNIX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -static-libstdc++ -static-libgcc")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -fno-builtin")
|
||||
option(SANITIZE "Turns on thread and UB sanitizers" OFF)
|
||||
if (SANITIZE)
|
||||
message(STATUS "sanitize is ON")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined,thread")
|
||||
|
@ -73,7 +73,7 @@ private:
|
||||
std::unordered_map<std::string, fs::file_time_type> mFileTimes;
|
||||
};
|
||||
|
||||
class TLuaEngine : IThreaded {
|
||||
class TLuaEngine : IThreaded, public std::enable_shared_from_this<TLuaEngine> {
|
||||
public:
|
||||
enum CallStrategy : int {
|
||||
BestEffort,
|
||||
|
@ -14,6 +14,17 @@ static inline bool StringStartsWith(const std::string& What, const std::string&
|
||||
return What.size() >= StartsWith.size() && What.substr(0, StartsWith.size()) == StartsWith;
|
||||
}
|
||||
|
||||
TEST_CASE("StringStartsWith") {
|
||||
CHECK(StringStartsWith("Hello, World", "Hello"));
|
||||
CHECK(StringStartsWith("Hello, World", "H"));
|
||||
CHECK(StringStartsWith("Hello, World", ""));
|
||||
CHECK(!StringStartsWith("Hello, World", "ello"));
|
||||
CHECK(!StringStartsWith("Hello, World", "World"));
|
||||
CHECK(StringStartsWith("", ""));
|
||||
CHECK(!StringStartsWith("", "hello"));
|
||||
}
|
||||
|
||||
// Trims leading and trailing spaces, newlines, tabs, etc.
|
||||
static inline std::string TrimString(std::string S) {
|
||||
S.erase(S.begin(), std::find_if(S.begin(), S.end(), [](unsigned char ch) {
|
||||
return !std::isspace(ch);
|
||||
@ -25,6 +36,21 @@ static inline std::string TrimString(std::string S) {
|
||||
return S;
|
||||
}
|
||||
|
||||
TEST_CASE("TrimString") {
|
||||
CHECK(TrimString("hel lo") == "hel lo");
|
||||
CHECK(TrimString(" hel lo") == "hel lo");
|
||||
CHECK(TrimString(" hel lo ") == "hel lo");
|
||||
CHECK(TrimString("hel lo ") == "hel lo");
|
||||
CHECK(TrimString(" hel lo") == "hel lo");
|
||||
CHECK(TrimString("hel lo ") == "hel lo");
|
||||
CHECK(TrimString(" hel lo ") == "hel lo");
|
||||
CHECK(TrimString("\t\thel\nlo\n\n") == "hel\nlo");
|
||||
CHECK(TrimString("\n\thel\tlo\n\t") == "hel\tlo");
|
||||
CHECK(TrimString(" ") == "");
|
||||
CHECK(TrimString(" \t\n\r ") == "");
|
||||
CHECK(TrimString("") == "");
|
||||
}
|
||||
|
||||
std::string GetDate() {
|
||||
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
|
||||
time_t tt = std::chrono::system_clock::to_time_t(now);
|
||||
|
@ -38,6 +38,12 @@ TLuaEngine::TLuaEngine()
|
||||
Start();
|
||||
}
|
||||
|
||||
TEST_CASE("TLuaEngine ctor & dtor") {
|
||||
Application::Settings.Resource = "beammp_server_test_resources";
|
||||
TLuaEngine engine;
|
||||
Application::GracefullyShutdown();
|
||||
}
|
||||
|
||||
void TLuaEngine::operator()() {
|
||||
RegisterThread("LuaEngine");
|
||||
Application::SetSubsystemStatus("LuaEngine", Application::Status::Good);
|
||||
@ -269,6 +275,7 @@ std::shared_ptr<TLuaResult> TLuaEngine::EnqueueFunctionCall(TLuaStateId StateID,
|
||||
}
|
||||
|
||||
void TLuaEngine::CollectAndInitPlugins() {
|
||||
fs::create_directories(mResourceServerPath);
|
||||
for (const auto& Dir : fs::directory_iterator(mResourceServerPath)) {
|
||||
auto Path = Dir.path();
|
||||
Path = fs::relative(Path);
|
||||
|
@ -133,9 +133,9 @@ int BeamMPServerMain(MainArguments Arguments) {
|
||||
|
||||
TServer Server(Arguments.List);
|
||||
TConfig Config(ConfigPath);
|
||||
TLuaEngine LuaEngine;
|
||||
LuaEngine.SetServer(&Server);
|
||||
Application::Console().InitializeLuaConsole(LuaEngine);
|
||||
auto LuaEngine = std::make_shared<TLuaEngine>();
|
||||
LuaEngine->SetServer(&Server);
|
||||
Application::Console().InitializeLuaConsole(*LuaEngine);
|
||||
|
||||
if (Config.Failed()) {
|
||||
beammp_info("Closing in 10 seconds");
|
||||
@ -155,7 +155,7 @@ int BeamMPServerMain(MainArguments Arguments) {
|
||||
TPPSMonitor PPSMonitor(Server);
|
||||
THeartbeatThread Heartbeat(ResourceManager, Server);
|
||||
TNetwork Network(Server, PPSMonitor, ResourceManager);
|
||||
LuaEngine.SetNetwork(&Network);
|
||||
LuaEngine->SetNetwork(&Network);
|
||||
PPSMonitor.SetNetwork(Network);
|
||||
Application::CheckForUpdates();
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
int main(int argc, char** argv) {
|
||||
doctest::Context context;
|
||||
|
||||
Application::InitializeConsole();
|
||||
// Application::InitializeConsole();
|
||||
|
||||
context.applyCommandLine(argc, argv);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user