mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-01 23:35:41 +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 "${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_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g")
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -fno-builtin")
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -fno-builtin")
|
||||||
|
option(SANITIZE "Turns on thread and UB sanitizers" OFF)
|
||||||
if (SANITIZE)
|
if (SANITIZE)
|
||||||
message(STATUS "sanitize is ON")
|
message(STATUS "sanitize is ON")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined,thread")
|
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;
|
std::unordered_map<std::string, fs::file_time_type> mFileTimes;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TLuaEngine : IThreaded {
|
class TLuaEngine : IThreaded, public std::enable_shared_from_this<TLuaEngine> {
|
||||||
public:
|
public:
|
||||||
enum CallStrategy : int {
|
enum CallStrategy : int {
|
||||||
BestEffort,
|
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;
|
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) {
|
static inline std::string TrimString(std::string S) {
|
||||||
S.erase(S.begin(), std::find_if(S.begin(), S.end(), [](unsigned char ch) {
|
S.erase(S.begin(), std::find_if(S.begin(), S.end(), [](unsigned char ch) {
|
||||||
return !std::isspace(ch);
|
return !std::isspace(ch);
|
||||||
@ -25,6 +36,21 @@ static inline std::string TrimString(std::string S) {
|
|||||||
return 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::string GetDate() {
|
||||||
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
|
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
|
||||||
time_t tt = std::chrono::system_clock::to_time_t(now);
|
time_t tt = std::chrono::system_clock::to_time_t(now);
|
||||||
|
@ -38,6 +38,12 @@ TLuaEngine::TLuaEngine()
|
|||||||
Start();
|
Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("TLuaEngine ctor & dtor") {
|
||||||
|
Application::Settings.Resource = "beammp_server_test_resources";
|
||||||
|
TLuaEngine engine;
|
||||||
|
Application::GracefullyShutdown();
|
||||||
|
}
|
||||||
|
|
||||||
void TLuaEngine::operator()() {
|
void TLuaEngine::operator()() {
|
||||||
RegisterThread("LuaEngine");
|
RegisterThread("LuaEngine");
|
||||||
Application::SetSubsystemStatus("LuaEngine", Application::Status::Good);
|
Application::SetSubsystemStatus("LuaEngine", Application::Status::Good);
|
||||||
@ -269,6 +275,7 @@ std::shared_ptr<TLuaResult> TLuaEngine::EnqueueFunctionCall(TLuaStateId StateID,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TLuaEngine::CollectAndInitPlugins() {
|
void TLuaEngine::CollectAndInitPlugins() {
|
||||||
|
fs::create_directories(mResourceServerPath);
|
||||||
for (const auto& Dir : fs::directory_iterator(mResourceServerPath)) {
|
for (const auto& Dir : fs::directory_iterator(mResourceServerPath)) {
|
||||||
auto Path = Dir.path();
|
auto Path = Dir.path();
|
||||||
Path = fs::relative(Path);
|
Path = fs::relative(Path);
|
||||||
|
@ -133,9 +133,9 @@ int BeamMPServerMain(MainArguments Arguments) {
|
|||||||
|
|
||||||
TServer Server(Arguments.List);
|
TServer Server(Arguments.List);
|
||||||
TConfig Config(ConfigPath);
|
TConfig Config(ConfigPath);
|
||||||
TLuaEngine LuaEngine;
|
auto LuaEngine = std::make_shared<TLuaEngine>();
|
||||||
LuaEngine.SetServer(&Server);
|
LuaEngine->SetServer(&Server);
|
||||||
Application::Console().InitializeLuaConsole(LuaEngine);
|
Application::Console().InitializeLuaConsole(*LuaEngine);
|
||||||
|
|
||||||
if (Config.Failed()) {
|
if (Config.Failed()) {
|
||||||
beammp_info("Closing in 10 seconds");
|
beammp_info("Closing in 10 seconds");
|
||||||
@ -155,7 +155,7 @@ int BeamMPServerMain(MainArguments Arguments) {
|
|||||||
TPPSMonitor PPSMonitor(Server);
|
TPPSMonitor PPSMonitor(Server);
|
||||||
THeartbeatThread Heartbeat(ResourceManager, Server);
|
THeartbeatThread Heartbeat(ResourceManager, Server);
|
||||||
TNetwork Network(Server, PPSMonitor, ResourceManager);
|
TNetwork Network(Server, PPSMonitor, ResourceManager);
|
||||||
LuaEngine.SetNetwork(&Network);
|
LuaEngine->SetNetwork(&Network);
|
||||||
PPSMonitor.SetNetwork(Network);
|
PPSMonitor.SetNetwork(Network);
|
||||||
Application::CheckForUpdates();
|
Application::CheckForUpdates();
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
doctest::Context context;
|
doctest::Context context;
|
||||||
|
|
||||||
Application::InitializeConsole();
|
// Application::InitializeConsole();
|
||||||
|
|
||||||
context.applyCommandLine(argc, argv);
|
context.applyCommandLine(argc, argv);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user