diff options
Diffstat (limited to 'runtime/test/loader_test.cpp')
| -rw-r--r-- | runtime/test/loader_test.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/runtime/test/loader_test.cpp b/runtime/test/loader_test.cpp index a925fa021..d985ba423 100644 --- a/runtime/test/loader_test.cpp +++ b/runtime/test/loader_test.cpp | |||
| @@ -1408,13 +1408,33 @@ void test_compat_modules() { | |||
| 1408 | std::filesystem::path bad = g_dir / "compat_bad"; | 1408 | std::filesystem::path bad = g_dir / "compat_bad"; |
| 1409 | std::filesystem::create_directories(bad); | 1409 | std::filesystem::create_directories(bad); |
| 1410 | write_image_as(std::vector<uint8_t>(64, 0x5A), "compat_bad/testcompat.dll"); | 1410 | write_image_as(std::vector<uint8_t>(64, 0x5A), "compat_bad/testcompat.dll"); |
| 1411 | // The loader has to keep Windows from raising its "Bad Image" box for this file (the load would wait | ||
| 1412 | // on a click), and has to leave the thread's error mode as it found it. The mode here is one without | ||
| 1413 | // SEM_FAILCRITICALERRORS, so a loader that suppresses nothing shows the box, and one that does not | ||
| 1414 | // restore the mode is caught below. | ||
| 1415 | const DWORD mode_before = GetThreadErrorMode() & ~static_cast<DWORD>(SEM_FAILCRITICALERRORS); | ||
| 1416 | DWORD mode_at_entry = 0; | ||
| 1417 | SetThreadErrorMode(mode_before, &mode_at_entry); | ||
| 1418 | const ULONGLONG started = GetTickCount64(); | ||
| 1411 | try { | 1419 | try { |
| 1412 | bind_with_compat(bad, "testcompat.dll", "Answer", bound); | 1420 | bind_with_compat(bad, "testcompat.dll", "Answer", bound); |
| 1413 | failed(what, "the load succeeded"); | 1421 | failed(what, "the load succeeded"); |
| 1414 | } catch (const std::exception& e) { | 1422 | } catch (const std::exception& e) { |
| 1415 | if (std::string(e.what()).find("LEONIDA_COMPAT_DIR") == std::string::npos) failed(what, e.what()); | 1423 | if (std::string(e.what()).find("LEONIDA_COMPAT_DIR") == std::string::npos) failed(what, e.what()); |
| 1424 | else if (std::string(e.what()).find("(error 0)") != std::string::npos) | ||
| 1425 | failed(what, "the message lost the Windows error code"); | ||
| 1416 | else pass(what); | 1426 | else pass(what); |
| 1417 | } | 1427 | } |
| 1428 | const ULONGLONG waited_ms = GetTickCount64() - started; | ||
| 1429 | const DWORD mode_after = GetThreadErrorMode(); | ||
| 1430 | SetThreadErrorMode(mode_at_entry, nullptr); | ||
| 1431 | if (mode_after != mode_before) | ||
| 1432 | failed("a compat file Windows cannot load: the thread error mode is put back", "the mode changed"); | ||
| 1433 | else pass("a compat file Windows cannot load: the thread error mode is put back"); | ||
| 1434 | // A refused load takes milliseconds; with the box up, the load returns only after someone clicks it. | ||
| 1435 | if (waited_ms > 5000) | ||
| 1436 | failed("a compat file Windows cannot load is refused without an error box", "the load took over 5 s"); | ||
| 1437 | else pass("a compat file Windows cannot load is refused without an error box"); | ||
| 1418 | } | 1438 | } |
| 1419 | } catch (const std::exception& e) { | 1439 | } catch (const std::exception& e) { |
| 1420 | failed("LEONIDA_COMPAT_DIR", e.what()); | 1440 | failed("LEONIDA_COMPAT_DIR", e.what()); |