From cff7c719c389c4a5b556059324d653841e0f817a Mon Sep 17 00:00:00 2001 From: roblabla Date: Sun, 14 Apr 2024 15:23:48 +0200 Subject: [PATCH 1/2] Unstub Supervisor::OnUpdate/OnDraw --- config/stubbed.csv | 2 -- 1 file changed, 2 deletions(-) diff --git a/config/stubbed.csv b/config/stubbed.csv index 7d66d3c1..210d46c6 100644 --- a/config/stubbed.csv +++ b/config/stubbed.csv @@ -24,8 +24,6 @@ SoundPlayer::InitSoundBuffers SoundPlayer::PlaySoundByIdx SoundPlayer::Release SoundPlayer::PlaySounds -Supervisor::OnUpdate -Supervisor::OnDraw Supervisor::DeletedCallback Supervisor::CreateBackBuffer Supervisor::SetupDInput From 3a7895703fe392224f6d70c8a2fe3cf5cba0b06b Mon Sep 17 00:00:00 2001 From: roblabla Date: Sun, 14 Apr 2024 15:25:22 +0200 Subject: [PATCH 2/2] Slight improvement to the pbg3 tests --- tests/test_Pbg3Archive.cpp | 109 +++++++++++++++++++++++++------------ 1 file changed, 73 insertions(+), 36 deletions(-) diff --git a/tests/test_Pbg3Archive.cpp b/tests/test_Pbg3Archive.cpp index a2a36de4..22a2ac6d 100644 --- a/tests/test_Pbg3Archive.cpp +++ b/tests/test_Pbg3Archive.cpp @@ -1,9 +1,18 @@ +#include #include +#include #include #include "pbg3/Pbg3Archive.hpp" #include +static char *file_name_params[] = {"ascii.png", "th06logo.jpg", "text.anm", NULL}; + +static MunitParameterEnum test_params[] = { + {"file_name", file_name_params}, + {NULL, NULL}, +}; + static MunitResult test_read_raw(const MunitParameter params[], void *user_data) { Pbg3Archive archive; @@ -23,63 +32,91 @@ static MunitResult test_read_raw(const MunitParameter params[], void *user_data) static MunitResult test_read_decompress(const MunitParameter params[], void *user_data) { - Pbg3Archive archive; - munit_assert_int(archive.Load("resources/KOUMAKYO_IN.dat"), !=, 0); - - // Read from PBG3 - i32 entryIdx = archive.FindEntry("th06logo.jpg"); - munit_assert_int(entryIdx, !=, -1); - u8 *entry = archive.ReadDecompressEntry(entryIdx, "th06logo.jpg"); - munit_assert_not_null(entry); - u32 entrySize = archive.GetEntrySize(entryIdx); - munit_assert_int(entrySize, !=, 0); - - // Write decompressed file to disk. - std::ofstream outfile("resources/th06logo2.jpg.expected", std::ios::out | std::ios::binary); - outfile.write((char *)entry, entrySize); - - // Read file on disk - std::ifstream infile("resources/th06logo.jpg", std::ios::binary); - std::vector buffer(std::istreambuf_iterator(infile), std::istreambuf_iterator()); - u8 *reference = (u8 *)&buffer[0]; - u32 referenceSize = buffer.size(); + char *archiveNameRelative = "resources/KOUMAKYO_IN.dat"; + char *fileName = params[0].value; + char archiveName[MAX_PATH] = {0}; - munit_assert_int(entrySize, ==, referenceSize); - munit_assert_memory_equal(entrySize, entry, reference); - return MUNIT_OK; -} + if (_fullpath(archiveName, archiveNameRelative, MAX_PATH) == NULL) + { + munit_errorf_ex(__FILE__, __LINE__, "Failed to canonicalize %s", archiveNameRelative); + return MUNIT_FAIL; + } -static MunitResult test_read_decompress_anm(const MunitParameter params[], void *user_data) -{ Pbg3Archive archive; - munit_assert_int(archive.Load("resources/KOUMAKYO_IN.dat"), !=, 0); + munit_assert_int(archive.Load(archiveName), !=, 0); - // Read from PBG3 - i32 entryIdx = archive.FindEntry("text.anm"); + // Read from PBG3. + i32 entryIdx = archive.FindEntry(fileName); munit_assert_int(entryIdx, !=, -1); - u8 *entry = archive.ReadDecompressEntry(entryIdx, "text.anm"); + u8 *entry = archive.ReadDecompressEntry(entryIdx, fileName); munit_assert_not_null(entry); u32 entrySize = archive.GetEntrySize(entryIdx); munit_assert_int(entrySize, !=, 0); - // Write decompressed file to disk. - std::ofstream outfile("resources/text.anm.expected", std::ios::out | std::ios::binary); + // Create a temporary directory to work from. + char tmpNameStr[MAX_PATH] = {0}; + tmpnam(tmpNameStr); + // Remove trailing dot. + for (int i = 0; i < MAX_PATH; i++) + { + if (i == 0) + { + if (tmpNameStr[i - 1] == '.') + { + tmpNameStr[i - 1] = '\0'; + } + break; + } + } + + char tmpPathCStr[MAX_PATH] = {0}; + DWORD tmpPathSize = GetTempPathA(MAX_PATH, tmpPathCStr); + munit_assert_int(tmpPathSize, !=, 0); + std::string tmpPath(tmpPathCStr, tmpPathSize); + if (tmpNameStr[0] != '\\') + { + tmpPath += "\\"; + } + tmpPath += tmpNameStr; + _mkdir(tmpPath.c_str()); + + munit_logf_ex(MUNIT_LOG_INFO, __FILE__, __LINE__, "Temporary path: %s", tmpPath.c_str()); + + // Write decompressed file to disk. Useful for debugging. + std::string actualPath(tmpPath); + actualPath += "/"; + actualPath += fileName; + actualPath += ".actual"; + std::ofstream outfile(actualPath.c_str(), std::ios::out | std::ios::binary); outfile.write((char *)entry, entrySize); - // Read file on disk - std::ifstream infile("resources/text.anm", std::ios::binary); + // Extract using reference implementation. + std::string cmd("cd /d "); + cmd += tmpPath; + cmd += " && thdat -x 6 "; + cmd += archiveName; + cmd += " "; + cmd += params[0].value; + munit_logf_ex(MUNIT_LOG_INFO, __FILE__, __LINE__, "Running %s", cmd.c_str()); + munit_assert_int(system(cmd.c_str()), !=, -1); + + // Read reference extraction + std::string referencePath(tmpPath); + referencePath += "/"; + referencePath += params[0].value; + std::ifstream infile(referencePath.c_str(), std::ios::binary); std::vector buffer(std::istreambuf_iterator(infile), std::istreambuf_iterator()); u8 *reference = (u8 *)&buffer[0]; u32 referenceSize = buffer.size(); + // Ensure they are equal. munit_assert_int(entrySize, ==, referenceSize); munit_assert_memory_equal(entrySize, entry, reference); return MUNIT_OK; } static MunitTest pbg3archives_test_suite_tests[] = { - {"/read_decompress_anm", test_read_decompress_anm, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL}, - {"/read_decompress", test_read_decompress, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL}, + {"/read_decompress", test_read_decompress, NULL, NULL, MUNIT_TEST_OPTION_NONE, test_params}, {"/read_raw", test_read_raw, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL}, /* Mark the end of the array with an entry where the test * function is NULL */