Add comprehensive tests for entity dispatch, file system, fixed map, flex archive, isometric controls, and crash setup
- Enhance `entity_dispatch_entry_tests.cpp` with additional assertions for event type checks, group ID increments, and error handling. - Refactor `file_system_tests.cpp` to streamline probe execution and enhance output validation. - Extend `fixed_map_tests.cpp` to cover retail map loading, item classification, and process creation scenarios. - Introduce new checks in `flex_archive_tests.cpp` for usecode loading and event handling, ensuring robust validation of game data. - Add tests in `isometric_controls_tests.cpp` for controller direction mapping based on scan codes. - Implement `test_crash_setup.cpp` to initialize crash diagnostics for improved error handling during tests.
This commit is contained in:
parent
202679f857
commit
c346b0e1a7
17 changed files with 1207 additions and 92 deletions
|
|
@ -29,6 +29,10 @@ int main(int argc, char** argv)
|
|||
}
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
if (argc == 2 && std::strcmp(argv[1], "--assert-probe") == 0) {
|
||||
assert(false && "diagnostic assert probe");
|
||||
return 0;
|
||||
}
|
||||
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_WNDW);
|
||||
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_WNDW);
|
||||
#endif
|
||||
|
|
@ -44,52 +48,63 @@ int main(int argc, char** argv)
|
|||
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);
|
||||
auto runProbe = [&](const wchar_t* option, const char* expectedOutput, bool expectExitOne) {
|
||||
std::wstring commandLine = L"\"" + std::wstring(executable) + L"\" " + option;
|
||||
SECURITY_ATTRIBUTES pipeSecurity{sizeof(SECURITY_ATTRIBUTES), nullptr, TRUE};
|
||||
HANDLE readPipe = nullptr;
|
||||
HANDLE writePipe = nullptr;
|
||||
if (!CreatePipe(&readPipe, &writePipe, &pipeSecurity, 0)) {
|
||||
return false;
|
||||
}
|
||||
if (!SetHandleInformation(readPipe, HANDLE_FLAG_INHERIT, 0)) {
|
||||
CloseHandle(readPipe);
|
||||
CloseHandle(writePipe);
|
||||
return false;
|
||||
}
|
||||
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 false;
|
||||
}
|
||||
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)) {
|
||||
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(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());
|
||||
CloseHandle(child.hThread);
|
||||
CloseHandle(child.hProcess);
|
||||
const bool passed = gotExitCode && waitResult == WAIT_OBJECT_0 &&
|
||||
(expectExitOne ? exitCode == 1 : exitCode != 0) &&
|
||||
crashOutput.find(expectedOutput) != std::string::npos;
|
||||
if (!passed) {
|
||||
std::fprintf(stderr, "Probe %ls wait=%lu exit=0x%08lX output=%s\n",
|
||||
option, waitResult, exitCode, crashOutput.c_str());
|
||||
}
|
||||
return passed;
|
||||
};
|
||||
if (!runProbe(L"--crash-probe", "Unhandled C++ exception: diagnostic probe", true)
|
||||
#ifdef _DEBUG
|
||||
|| !runProbe(L"--assert-probe", "diagnostic assert probe", false)
|
||||
#endif
|
||||
) {
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue