change rom test inputs to hex for consistency

This commit is contained in:
Justin Scofield
2022-08-08 08:12:32 -04:00
parent 465b3fc49b
commit 3339a420f2

View File

@@ -52,7 +52,7 @@ TEST(ROMTest, NewDecompressionPieceOk) {
char command = 1;
int length = 1;
char args[] = "aaa";
int argument_length = 2;
int argument_length = 0x02;
CompressionPiece old_piece;
old_piece.command = command;
old_piece.length = length;
@@ -60,7 +60,7 @@ TEST(ROMTest, NewDecompressionPieceOk) {
old_piece.argument_length = argument_length;
old_piece.next = nullptr;
auto new_piece = ExpectNewCompressionPieceOk(1, 1, "aaa", 2);
auto new_piece = ExpectNewCompressionPieceOk(0x01, 0x01, "aaa", 0x02);
EXPECT_EQ(old_piece.command, new_piece->command);
EXPECT_EQ(old_piece.length, new_piece->length);
@@ -72,24 +72,25 @@ TEST(ROMTest, NewDecompressionPieceOk) {
TEST(ROMTest, DecompressionValidCommand) {
ROM rom;
std::array<uchar, 4> simple_copy_input = {BUILD_HEADER(0, 2), 42, 69, 0xFF};
uchar simple_copy_output[2] = {42, 69};
std::array<uchar, 4> simple_copy_input = {BUILD_HEADER(0x00, 0x02), 0x2A,
0x45, 0xFF};
uchar simple_copy_output[2] = {0x2A, 0x45};
auto decomp_result = ExpectDecompressOk(rom, simple_copy_input.data(), 4);
EXPECT_THAT(simple_copy_output, ElementsAreArray(decomp_result.data(), 2));
}
TEST(ROMTest, DecompressionMixingCommand) {
ROM rom;
uchar random1_i[11] = {BUILD_HEADER(1, 3),
42,
BUILD_HEADER(0, 4),
1,
2,
3,
4,
BUILD_HEADER(2, 2),
11,
22,
uchar random1_i[11] = {BUILD_HEADER(0x01, 0x03),
0x2A,
BUILD_HEADER(0x00, 0x04),
0x01,
0x02,
0x03,
0x04,
BUILD_HEADER(0x02, 0x02),
0x0B,
0x16,
0xFF};
uchar random1_o[9] = {42, 42, 42, 1, 2, 3, 4, 11, 22};
auto decomp_result = ExpectDecompressOk(rom, random1_i, 11);
@@ -99,10 +100,10 @@ TEST(ROMTest, DecompressionMixingCommand) {
/* Extended Header Command is currently unimplemented
TEST(ROMTest, ExtendedHeaderDecompress) {
ROM rom;
uchar extendedcmd_i[4] = {0b11100100, 0x8F, 42, 0xFF};
uchar extendedcmd_i[4] = {0b11100100, 0x8F, 0x2A, 0xFF};
uchar extendedcmd_o[50];
for (int i = 0; i < 50; ++i) {
extendedcmd_o[i] = 42;
extendedcmd_o[i] = 0x2A;
}
auto decomp_result = ExpectDecompressOk(rom, extendedcmd_i, 4);
@@ -111,10 +112,10 @@ TEST(ROMTest, ExtendedHeaderDecompress) {
TEST(ROMTest, ExtendedHeaderDecompress2) {
ROM rom;
uchar extendedcmd_i[4] = {0b11100101, 0x8F, 42, 0xFF};
uchar extendedcmd_i[4] = {0b11100101, 0x8F, 0x2A, 0xFF};
uchar extendedcmd_o[50];
for (int i = 0; i < 50; i++) {
extendedcmd_o[i] = 42;
extendedcmd_o[i] = 0x2A;
}
auto data = ExpectDecompressOk(rom, extendedcmd_i, 4);
@@ -126,8 +127,8 @@ TEST(ROMTest, ExtendedHeaderDecompress2) {
TEST(ROMTest, CompressionSingleSet) {
ROM rom;
uchar single_set[5] = {42, 42, 42, 42, 42};
uchar single_set_expected[3] = {BUILD_HEADER(1, 5), 42, 0xFF};
uchar single_set[5] = {0x2A, 0x2A, 0x2A, 0x2A, 0x2A};
uchar single_set_expected[3] = {BUILD_HEADER(1, 5), 0x2A, 0xFF};
auto comp_result = ExpectCompressOk(rom, single_set, 5);
EXPECT_THAT(single_set_expected, ElementsAreArray(comp_result.data(), 3));
@@ -135,8 +136,8 @@ TEST(ROMTest, CompressionSingleSet) {
TEST(ROMTest, CompressionSingleWord) {
ROM rom;
uchar single_word[6] = {42, 1, 42, 1, 42, 1};
uchar single_word_expected[4] = {BUILD_HEADER(2, 6), 42, 1, 0xFF};
uchar single_word[6] = {0x2A, 0x01, 0x2A, 0x01, 0x2A, 0x01};
uchar single_word_expected[4] = {BUILD_HEADER(0x02, 0x06), 0x2A, 0x01, 0xFF};
auto comp_result = ExpectCompressOk(rom, single_word, 6);
EXPECT_THAT(single_word_expected, ElementsAreArray(comp_result.data(), 4));
@@ -144,71 +145,73 @@ TEST(ROMTest, CompressionSingleWord) {
TEST(ROMTest, CompressionSingleIncrement) {
ROM rom;
uchar single_inc[3] = {1, 2, 3};
uchar single_inc_expected[3] = {BUILD_HEADER(3, 3), 1, 0xFF};
uchar single_inc[3] = {0x01, 0x02, 0x03};
uchar single_inc_expected[3] = {BUILD_HEADER(0x03, 0x03), 0x01, 0xFF};
auto comp_result = ExpectCompressOk(rom, single_inc, 3);
EXPECT_THAT(single_inc_expected, ElementsAreArray(comp_result.data(), 3));
}
TEST(ROMTest, CompressionSingleCopy) {
ROM rom;
uchar single_copy[4] = {3, 10, 7, 20};
uchar single_copy_expected[6] = {BUILD_HEADER(0, 4), 3, 10, 7, 20, 0xFF};
uchar single_copy[4] = {0x03, 0x0A, 0x07, 0x14};
uchar single_copy_expected[6] = {
BUILD_HEADER(0x00, 0x04), 0x03, 0x0A, 0x07, 0x14, 0xFF};
auto comp_result = ExpectCompressOk(rom, single_copy, 4);
EXPECT_THAT(single_copy_expected, ElementsAreArray(comp_result.data(), 6));
}
/*
Hiding tests until I figure out a better PR to address the bug.
/* Hiding tests until I figure out a better PR to address the bug
TEST(ROMTest, CompressionSingleCopyRepeat) {
ROM rom;
uchar single_copy_repeat[8] = {3, 10, 7, 20, 3, 10, 7, 20};
uchar single_copy_repeat_expected[9] = {BUILD_HEADER(0, 4), 3, 10, 7, 20,
BUILD_HEADER(4, 4), 0, 0, 0xFF};
uchar single_copy_repeat[8] = {0x03, 0x0A, 0x07, 0x14, 0x03, 10, 0x07, 0x14};
uchar single_copy_repeat_expected[9] = {
BUILD_HEADER(0x00, 0x04), 0x03, 0x0A, 0x07, 0x14,
BUILD_HEADER(0x04, 0x04), 0x00, 0x00, 0xFF};
auto comp_result = ExpectCompressOk(rom, single_copy_repeat, 8);
EXPECT_THAT(single_copy_repeat_expected,
ElementsAreArray(comp_result.data(), 8));
}
TEST(ROMTest, CompressionSingleOverflowIncrement) {
ROM rom;
uchar overflow_inc[4] = {0xFE, 0xFF, 0, 1};
uchar overflow_inc_expected[3] = {BUILD_HEADER(3, 4), 0xFE, 0xFF};
uchar overflow_inc[4] = {0xFE, 0xFF, 0x00, 0x01};
uchar overflow_inc_expected[3] = {BUILD_HEADER(0x03, 0x04), 0xFE, 0xFF};
auto comp_result = ExpectCompressOk(rom, overflow_inc, 4);
EXPECT_THAT(overflow_inc_expected, ElementsAreArray(comp_result.data(), 3));
}
TEST(ROMTest, CompressionMixedRepeatIncrement) {
ROM rom;
uchar to_compress_string[28] = {5, 5, 5, 5, 6, 7, 8, 9, 10, 11, 5, 2, 5, 2,
5, 2, 10, 11, 5, 2, 5, 2, 5, 2, 8, 10, 0, 5};
uchar repeat_and_inc_copy_expected[7] = {BUILD_HEADER(1, 4),
5,
BUILD_HEADER(3, 6),
6,
BUILD_HEADER(0, 1),
5,
0xFF};
uchar to_compress_string[28] = {0x05, 0x05, 0x05, 0x05, 0x06, 0x07, 0x08,
0x09, 0x0A, 0x0B, 0x05, 0x02, 0x05, 0x02,
0x05, 0x02, 0x0A, 0x0B, 0x05, 0x02, 0x05,
0x02, 0x05, 0x02, 0x08, 0x0A, 0x00, 0x05};
uchar repeat_and_inc_copy_expected[7] = {BUILD_HEADER(0x01, 0x04),
0x05,
BUILD_HEADER(0x03, 0x06),
0x06,
BUILD_HEADER(0x00, 0x01),
0x05,
0xFF};
// Mixing, repeat, inc, trailing copy
auto comp_result = ExpectCompressOk(rom, to_compress_string, 28);
EXPECT_THAT(repeat_and_inc_copy_expected,
ElementsAreArray(comp_result.data(), 7));
}
TEST(ROMTest, SimpleMixCompression) {
ROM rom;
uchar to_compress_string[] = {5, 5, 5, 5, 6, 7, 8, 9, 10, 11, 5, 2, 5, 2,
5, 2, 10, 11, 5, 2, 5, 2, 5, 2, 8, 10, 0, 5};
uchar repeat_and_inc_copy_expected[] = {BUILD_HEADER(1, 4),
5,
BUILD_HEADER(3, 6),
6,
BUILD_HEADER(0, 1),
5,
uchar to_compress_string[] = {0x05, 0x05, 0x05, 0x05, 0x06, 0x07, 0x08,
0x09, 0x0A, 0x0B, 0x05, 0x02, 0x05, 0x02,
0x05, 0x02, 0x0A, 0x0B, 0x05, 0x02, 0x05,
0x02, 0x05, 0x02, 0x08, 0x0A, 0x00, 0x05};
uchar repeat_and_inc_copy_expected[] = {BUILD_HEADER(0x01, 0x04),
0x05,
BUILD_HEADER(0x03, 0x06),
0x06,
BUILD_HEADER(0x00, 0x01),
0x05,
0xFF};
// Mixing, repeat, inc, trailing copy
auto data = ExpectCompressOk(rom, to_compress_string, 7);
@@ -216,93 +219,78 @@ TEST(ROMTest, SimpleMixCompression) {
EXPECT_EQ(repeat_and_inc_copy_expected[i], data[i]);
}
// char inc_word_intra_copy_expected[] = {BUILD_HEADER(3, 7),
// 5,
// BUILD_HEADER(2, 6),
// 5,
// 2,
// BUILD_HEADER(4, 8),
// 5,
// 0,
// 0xFF};
uchar inc_word_intra_copy_expected[] = {BUILD_HEADER(0x03, 0x07),
0x05,
BUILD_HEADER(0x02, 0x06),
0x05,
0x02,
BUILD_HEADER(0x04, 0x08),
0x05,
0x00,
0xFF};
// CuAssertDataEquals_Msg(
// tc, "Mixing, inc, alternate, intra copy", inc_word_intra_copy_expected,
// 9, alttp_compress_gfx(to_compress_string, 3, 21, &compress_size));
// char all_expected[] = {BUILD_HEADER(1, 4),
// 5,
// BUILD_HEADER(3, 6),
// 6,
// BUILD_HEADER(2, 6),
// 5,
// 2,
// BUILD_HEADER(4, 8),
// 8,
// 0,
// BUILD_HEADER(0, 4),
// 8,
// 10,
// 0,
// 5,
// 0xFF};
uchar all_expected[] = {BUILD_HEADER(0x01, 0x04),
0x05,
BUILD_HEADER(0x03, 0x06),
0x06,
BUILD_HEADER(0x02, 0x06),
0x05,
0x02,
BUILD_HEADER(0x04, 0x08),
0x08,
0x00,
BUILD_HEADER(0x00, 0x04),
0x08,
0x0A,
0x00,
0x05,
0xFF};
// CuAssertDataEquals_Msg(
// tc, "Mixing, inc, alternate, intra copy", all_expected, 16,
// alttp_compress_gfx(to_compress_string, 0, 28, &compress_size));
}
*/
TEST(ROMTest, LengthBorderCompression) {
char buffer[3000];
unsigned int compress_size;
for (unsigned int i = 0; i < 3000; i++) buffer[i] = 5;
char extended_lenght_expected_42[] = {0b11100100, 41, 5, 0xFF};
char extended_lenght_expected_400[] = {0b11100101, 0x8F, 5, 0xFF};
char extended_lenght_expected_1050[] = {0b11100111, 0xFF, 5,
BUILD_HEADER(1, 26), 5, 0xFF};
char extended_lenght_expected_2050[] = {
0b11100111, 0xFF, 5, 0b11100111, 0xFF, 5, BUILD_HEADER(1, 2), 5, 0xFF};
CuAssertDataEquals_Msg(tc, "Extended lenght, 42 repeat of 5",
extended_lenght_expected_42, 4,
alttp_compress_gfx(buffer, 0, 42, &compress_size));
CuAssertDataEquals_Msg(tc, "Extended lenght, 400 repeat of 5",
extended_lenght_expected_400, 4,
alttp_compress_gfx(buffer, 0, 400, &compress_size));
CuAssertDataEquals_Msg(tc, "Extended lenght, 1050 repeat of 5",
extended_lenght_expected_1050, 6,
alttp_compress_gfx(buffer, 0, 1050,
&compress_size));
CuAssertDataEquals_Msg(tc, "Extended lenght, 2050 repeat of 5",
extended_lenght_expected_2050, 9,
alttp_compress_gfx(buffer, 0, 2050,
&compress_size));
for (unsigned int i = 0; i < 3000; i++) buffer[i] = 0x05;
uchar extended_lenght_expected_42[] = {0b11100100, 0x29, 0x05, 0xFF};
uchar extended_lenght_expected_400[] = {0b11100101, 0x8F, 0x05, 0xFF};
uchar extended_lenght_expected_1050[] = {
0b11100111, 0xFF, 0x05, BUILD_HEADER(0x01, 0x1A), 0x05, 0xFF};
uchar extended_lenght_expected_2050[] = {
0b11100111, 0xFF, 0x05, 0b11100111, 0xFF, 0x05, BUILD_HEADER(0x01, 0x02),
0x05, 0xFF};
// CuAssertDataEquals_Msg(tc, "Extended lenght, 42 repeat of 5",
// extended_lenght_expected_42, 4,
// alttp_compress_gfx(buffer, 0, 42, &compress_size));
// CuAssertDataEquals_Msg(tc, "Extended lenght, 400 repeat of 5",
// extended_lenght_expected_400, 4,
// alttp_compress_gfx(buffer, 0, 400, &compress_size));
// CuAssertDataEquals_Msg(tc, "Extended lenght, 1050 repeat of 5",
// extended_lenght_expected_1050, 6,
// alttp_compress_gfx(buffer, 0, 1050,
// &compress_size));
// CuAssertDataEquals_Msg(tc, "Extended lenght, 2050 repeat of 5",
// extended_lenght_expected_2050, 9,
// alttp_compress_gfx(buffer, 0, 2050,
// &compress_size));
for (unsigned int i = 0; i < 3000; i += 2) {
buffer[i] = 5;
buffer[i + 1] = 6;
buffer[i] = 0x05;
buffer[i + 1] = 0x06;
}
char hightlenght_word_1050[] = {0b11101011, 0xFF, 5, 6,
BUILD_HEADER(2, 26), 5, 6, 0xFF};
CuAssertDataEquals_Msg(tc, "Extended word copy", hightlenght_word_1050, 8,
alttp_compress_gfx(buffer, 0, 1050,
&compress_size));
uchar hightlenght_word_1050[] = {
0b11101011, 0xFF, 0x05, 0x06, BUILD_HEADER(0x02, 0x1A), 0x05, 0x06, 0xFF};
// CuAssertDataEquals_Msg(tc, "Extended word copy", hightlenght_word_1050, 8,
// alttp_compress_gfx(buffer, 0, 1050,
// &compress_size));
}
TEST(ROMTest, CompressDecompress) {
char buffer[32];
unsigned int compress_size;
int fd = open("testsnestilebpp4.tl", O_RDONLY);
if (fd == -1) {
fprintf(stderr, "Can't open testsnestilebpp4.tl : %s\n",
strerror(errno)); return;
}
read(fd, buffer, 32);
char* comdata = alttp_compress_gfx(buffer, 0, 32, &compress_size);
CuAssertDataEquals_Msg(
tc, "Compressing/Uncompress testtilebpp4.tl", buffer, 32,
alttp_decompress_gfx(comdata, 0, 0, &compress_size, &c_size));
}
*/
} // namespace rom_test
} // namespace yaze_test