-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
181 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[submodule "3rdparty/munit"] | ||
path = 3rdparty/munit | ||
url = https://github.com/roblabla/munit | ||
branch = msvc2002 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from pathlib import Path | ||
|
||
from build import BuildType, build | ||
from winhelpers import run_windows_program | ||
|
||
SCRIPTS_DIR = Path(__file__).parent | ||
|
||
|
||
def main(): | ||
# Run the build for tests | ||
build(BuildType.TESTS) | ||
|
||
# Then, run the tests | ||
run_windows_program( | ||
[SCRIPTS_DIR.parent / "build" / "th06e-tests.exe"], | ||
cwd=str(SCRIPTS_DIR.parent), | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#include <fstream> | ||
#include <vector> | ||
|
||
#include "munit.h" | ||
#include <Pbg3Archive.hpp> | ||
|
||
static MunitResult test_read_raw(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); | ||
|
||
u32 size; | ||
u32 expectedCsum; | ||
u8 *entry = archive.ReadEntryRaw(&size, &expectedCsum, entryIdx); | ||
munit_assert_not_null(entry); | ||
|
||
return MUNIT_OK; | ||
} | ||
|
||
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<char> buffer(std::istreambuf_iterator<char>(infile), std::istreambuf_iterator<char>()); | ||
u8 *reference = (u8 *)&buffer[0]; | ||
u32 referenceSize = buffer.size(); | ||
|
||
munit_assert_int(entrySize, ==, referenceSize); | ||
munit_assert_memory_equal(entrySize, entry, reference); | ||
return MUNIT_OK; | ||
} | ||
|
||
static MunitResult test_read_decompress_anm(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("text.anm"); | ||
munit_assert_int(entryIdx, !=, -1); | ||
u8 *entry = archive.ReadDecompressEntry(entryIdx, "text.anm"); | ||
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); | ||
outfile.write((char *)entry, entrySize); | ||
|
||
// Read file on disk | ||
std::ifstream infile("resources/text.anm", std::ios::binary); | ||
std::vector<char> buffer(std::istreambuf_iterator<char>(infile), std::istreambuf_iterator<char>()); | ||
u8 *reference = (u8 *)&buffer[0]; | ||
u32 referenceSize = buffer.size(); | ||
|
||
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_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 */ | ||
{NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL}}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include "munit.h" | ||
|
||
#include "test_Pbg3Archive.cpp" | ||
|
||
static MunitSuite root_test_suites[] = { | ||
{"/Pbg3Archives", pbg3archives_test_suite_tests, NULL, 1, MUNIT_SUITE_OPTION_NONE}, | ||
{NULL, NULL, NULL, 0, MUNIT_SUITE_OPTION_NONE}}; | ||
static const MunitSuite test_suite = {"", NULL, root_test_suites, 1, MUNIT_SUITE_OPTION_NONE}; | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
/* Finally, we'll actually run our test suite! That second argument | ||
* is the user_data parameter which will be passed either to the | ||
* test or (if provided) the fixture setup function. */ | ||
return munit_suite_main(&test_suite, NULL, argc, argv); | ||
} |