Crusader_Decomp/rebuild/remorse/tests/file_system_tests.cpp
Maddo 202679f857 Add comprehensive tests for collision detection, entity dispatch, file system, isometric controls, map rendering, and sorting
- Implemented collision tests to verify overlap and movement logic for collision bodies.
- Enhanced entity dispatch entry tests to cover initialization, group ID management, and process handling.
- Expanded file system tests to include crash diagnostics and ensure proper game data root detection.
- Created isometric controls tests to validate movement requests and screen projection calculations.
- Added map renderer tests to check fixed map loading and rendering functionality.
- Introduced map sorter tests to confirm correct rendering order for various items.
2026-09-25 21:41:20 +02:00

112 lines
3.8 KiB
C++

#include "remorse/file_system.h"
#include "remorse/runtime.h"
#include <cassert>
#include <cstdio>
#include <cstring>
#include <exception>
#include <filesystem>
#include <stdexcept>
#include <string>
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#ifdef _DEBUG
#include <crtdbg.h>
#endif
#endif
int main(int argc, char** argv)
{
#ifdef _WIN32
if (argc == 2 && std::strcmp(argv[1], "--crash-probe") == 0) {
remorse::installCrashDiagnostics();
try {
throw std::runtime_error("diagnostic probe");
} catch (...) {
std::terminate();
}
}
#ifdef _DEBUG
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_WNDW);
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_WNDW);
#endif
remorse::installCrashDiagnostics();
assert((GetErrorMode() & SEM_NOGPFAULTERRORBOX) != 0);
#ifdef _DEBUG
assert((_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_REPORT_MODE) & _CRTDBG_MODE_WNDW) == 0);
assert((_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_REPORT_MODE) & _CRTDBG_MODE_DEBUG) != 0);
assert((_CrtSetReportMode(_CRT_ERROR, _CRTDBG_REPORT_MODE) & _CRTDBG_MODE_WNDW) == 0);
#endif
wchar_t executable[MAX_PATH]{};
if (GetModuleFileNameW(nullptr, executable, MAX_PATH) == 0) {
return 1;
}
std::wstring commandLine = L"\"" + std::wstring(executable) + L"\" --crash-probe";
SECURITY_ATTRIBUTES pipeSecurity{sizeof(SECURITY_ATTRIBUTES), nullptr, TRUE};
HANDLE readPipe = nullptr;
HANDLE writePipe = nullptr;
if (!CreatePipe(&readPipe, &writePipe, &pipeSecurity, 0)) {
return 1;
}
if (!SetHandleInformation(readPipe, HANDLE_FLAG_INHERIT, 0)) {
CloseHandle(readPipe);
CloseHandle(writePipe);
return 1;
}
STARTUPINFOW startup{};
startup.cb = sizeof(startup);
startup.dwFlags = STARTF_USESTDHANDLES;
startup.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
startup.hStdOutput = writePipe;
startup.hStdError = writePipe;
PROCESS_INFORMATION child{};
if (!CreateProcessW(nullptr, commandLine.data(), nullptr, nullptr, TRUE, CREATE_NO_WINDOW,
nullptr, nullptr, &startup, &child)) {
CloseHandle(readPipe);
CloseHandle(writePipe);
return 1;
}
CloseHandle(writePipe);
const DWORD waitResult = WaitForSingleObject(child.hProcess, 5000);
if (waitResult == WAIT_TIMEOUT) {
TerminateProcess(child.hProcess, 2);
WaitForSingleObject(child.hProcess, INFINITE);
}
char buffer[512];
DWORD count = 0;
std::string crashOutput;
while (ReadFile(readPipe, buffer, sizeof(buffer), &count, nullptr) && count != 0) {
crashOutput.append(buffer, count);
}
DWORD exitCode = 0;
const BOOL gotExitCode = GetExitCodeProcess(child.hProcess, &exitCode);
CloseHandle(readPipe);
CloseHandle(child.hThread);
CloseHandle(child.hProcess);
if (!gotExitCode || waitResult != WAIT_OBJECT_0 || exitCode != 1 ||
crashOutput.find("Unhandled C++ exception: diagnostic probe") == std::string::npos) {
std::fprintf(stderr, "Crash probe wait=%lu exit=0x%08lX output=%s\n",
waitResult, exitCode, crashOutput.c_str());
return 1;
}
#endif
const auto root = remorse::findGameDataRoot(std::filesystem::current_path());
assert(root.has_value());
assert(root->hasExecutable);
assert(root->hasStaticData);
assert(root->hasUsecode);
const auto palettePath = remorse::resolveGameDataPath(*root, std::filesystem::path("static") / "gamepal.pal");
assert(palettePath.has_value());
const auto paletteBytes = remorse::readBinaryFile(*palettePath);
assert(paletteBytes.has_value());
assert(!paletteBytes->empty());
const auto blockedParent = remorse::resolveGameDataPath(*root, std::filesystem::path("..") / "CRUSADER.EXE");
assert(!blockedParent.has_value());
return 0;
}