Update submodules and include some unit testing code.

This commit is contained in:
momo5502 2016-02-04 21:58:49 +01:00
parent dcd46633ca
commit ad1e25bd56
13 changed files with 130 additions and 21 deletions

2
deps/json11 vendored

@ -1 +1 @@
Subproject commit a6a661e9240e0018b6be0f67a9e9ca2a6be2626f
Subproject commit afcc8d0d82b1ce2df587a7a0637d05ba493bf5e6

2
deps/libtomcrypt vendored

@ -1 +1 @@
Subproject commit 912eff4949f46c0b426d2180429a6fa4c1144f1d
Subproject commit bd7933cc2b43ebe7c4349614c6cf1271251ebee4

2
deps/libtommath vendored

@ -1 +1 @@
Subproject commit afb4224186662b585ffa456aadb91c6a1a916733
Subproject commit 1bd1320b198655ad8edd3dd791805d6a4a89437d

View File

@ -205,7 +205,7 @@ workspace "iw4x"
-- libtomcrypt
project "libtomcrypt"
language "C"
defines { "_LIB", "LTC_SOURCE", "LTC_NO_RSA_BLINDING", "LTM_DESC" }
defines { "_LIB", "LTC_SOURCE", "LTC_NO_RSA_BLINDING", "LTM_DESC", "USE_LTM" }
links { "libtommath" }
includedirs { "./deps/libtomcrypt/src/headers" }
@ -213,8 +213,19 @@ workspace "iw4x"
files { "./deps/libtomcrypt/src/**.c" }
-- remove ocb3 code
removefiles { "./deps/libtomcrypt/src/encauth/ocb3/**.c" }
-- remove incorrect files
-- for some reason, they lack the necessary header files
-- i might have to open a pull request which includes them
removefiles
{
"./deps/libtomcrypt/src/prngs/sober128tab.c",
"./deps/libtomcrypt/src/pk/dh/dh_sys.c",
"./deps/libtomcrypt/src/ciphers/aes/aes_tab.c",
"./deps/libtomcrypt/src/hashes/sha2/sha224.c",
"./deps/libtomcrypt/src/hashes/sha2/sha384.c",
"./deps/libtomcrypt/src/hashes/whirl/whirltab.c",
"./deps/libtomcrypt/src/encauth/ocb3/**.c",
}
-- not our code, ignore POSIX usage warnings for now
warnings "Off"

View File

@ -61,6 +61,36 @@ namespace Components
Loader::Components.clear();
}
bool Loader::PerformUnitTests()
{
bool result = true;
Logger::Print("Performing unit tests for components:\n");
for (auto component : Loader::Components)
{
Logger::Print("Testing '%s'...\n", component->GetName());
auto startTime = std::chrono::high_resolution_clock::now();
bool testRes = component->UnitTest();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - startTime).count();
Logger::Print("Test done (%llims): %s\n\n", duration, (testRes ? "Success" : "Error"));//
result &= testRes;
}
return result;
}
bool Loader::PerformingUnitTests()
{
#if DEBUG
return Flags::HasFlag("tests");
#else
return false;
#endif
}
void Loader::Register(Component* component)
{
if (component)

View File

@ -6,6 +6,7 @@ namespace Components
Component() {};
virtual ~Component() {};
virtual const char* GetName() { return "Unknown"; };
virtual bool UnitTest() { return true; }; // Unit testing entry
};
class Loader
@ -13,6 +14,8 @@ namespace Components
public:
static void Initialize();
static void Uninitialize();
static bool PerformUnitTests();
static bool PerformingUnitTests();
static void Register(Component* component);
private:

View File

@ -368,13 +368,26 @@ namespace Components
Console::Console()
{
// Console '%s: %s> ' string
Utils::Hook::Set<char*>(0x5A44B4, "IW4x: r" REVISION_STR "> ");
// Internal console
Utils::Hook(0x4F690C, Console::ToggleConsole, HOOK_CALL).Install()->Quick();
Utils::Hook(0x4F65A5, Console::ToggleConsole, HOOK_JUMP).Install()->Quick();
// Check for bad food ;)
Utils::Hook(0x4CB9F4, Console::GetAutoCompleteFileList, HOOK_CALL).Install()->Quick();
// Code below is not necessary, when performing unit tests!
if (Loader::PerformingUnitTests()) return;
// External console
if (Flags::HasFlag("console") || ZoneBuilder::IsEnabled()) // ZoneBuilder uses the game's console, until the native one is adapted.
{
FreeConsole();
Utils::Hook::Nop(0x60BB58, 11);
}
else if(Dedicated::IsDedicated()/* || ZoneBuilder::IsEnabled()*/)
else if (Dedicated::IsDedicated()/* || ZoneBuilder::IsEnabled()*/)
{
Utils::Hook::Nop(0x60BB58, 11);
@ -388,15 +401,5 @@ namespace Components
{
FreeConsole();
}
// Console '%s: %s> ' string
Utils::Hook::Set<char*>(0x5A44B4, "IW4x: r" REVISION_STR "> ");
// Internal console
Utils::Hook(0x4F690C, Console::ToggleConsole, HOOK_CALL).Install()->Quick();
Utils::Hook(0x4F65A5, Console::ToggleConsole, HOOK_JUMP).Install()->Quick();
// Check for bad food ;)
Utils::Hook(0x4CB9F4, Console::GetAutoCompleteFileList, HOOK_CALL).Install()->Quick();
}
}

View File

@ -1,5 +1,7 @@
#include "STDInclude.hpp"
using namespace std::literals;
namespace Components
{
Pipe* IPCPipe::ServerPipe = 0;
@ -61,9 +63,14 @@ namespace Components
this->hPipe = CreateNamedPipe(this->PipeFile, PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, sizeof(this->mPacket), sizeof(this->mPacket), NMPWAIT_USE_DEFAULT_WAIT, NULL);
if (INVALID_HANDLE_VALUE != this->hPipe)
{
// Only create the thread, when not performing unit tests!
if (!Loader::PerformingUnitTests())
{
this->mThreadAttached = true;
this->mThread = new std::thread(Pipe::ReceiveThread, this);
}
Logger::Print("Pipe successfully created\n");
return true;
}

View File

@ -32,6 +32,7 @@ namespace Components
}
else
{
printf("%s", buffer);
OutputDebugStringA(buffer);
}
}

View File

@ -1,13 +1,52 @@
#include "STDInclude.hpp"
#define NEWS_MOTD_DEFUALT "Welcome to ReactIW4x Multiplayer!"
namespace Components
{
std::thread* News::Thread = 0;
std::thread* News::Thread = nullptr;
bool News::UnitTest()
{
bool result = true;
if (News::Thread)
{
Logger::Print("Awaiting thread termination...\n");
News::Thread->join();
delete News::Thread;
News::Thread = nullptr;
if (!strlen(Localization::Get("MPUI_CHANGELOG_TEXT")))
{
Logger::Print("Failed to fetch changelog!\n");
result = false;
}
else
{
Logger::Print("Successfully fetched changelog.\n");
}
if (!strcmp(Localization::Get("MPUI_MOTD_TEXT"), NEWS_MOTD_DEFUALT))
{
Logger::Print("Failed to fetch motd!\n");
result = false;
}
else
{
Logger::Print("Successfully fetched motd.\n");
}
}
return result;
}
News::News()
{
Localization::Set("MPUI_CHANGELOG_TEXT", "");
Localization::Set("MPUI_MOTD_TEXT", "Welcome to ReactIW4x Multiplayer!");
Localization::Set("MPUI_MOTD_TEXT", NEWS_MOTD_DEFUALT);
News::Thread = new std::thread([] ()
{
@ -30,6 +69,8 @@ namespace Components
{
News::Thread->join();
delete News::Thread;
News::Thread = nullptr;
}
}
}

View File

@ -6,6 +6,7 @@ namespace Components
News();
~News();
const char* GetName() { return "News"; };
bool UnitTest();
private:
static std::thread* Thread;

View File

@ -8,6 +8,17 @@ namespace Main
{
Main::EntryPointHook.Uninstall();
Components::Loader::Initialize();
#ifdef DEBUG
if (Components::Loader::PerformingUnitTests())
{
DWORD result = (Components::Loader::PerformUnitTests() ? 0 : -1);
Components::Loader::Uninitialize();
ExitProcess(result);
}
#else
Logger::Print("Unit tests are disabled outside the debug environment!\n");
#endif
}
void Uninitialize()

View File

@ -46,6 +46,7 @@
#define ZLIB_CONST
#define USE_LTM
#define LTM_DESC
#define LTC_NO_FAST
#define LTC_NO_PROTOTYPES