Skip to content

Commit

Permalink
Fix and improve eof.read_valid_eof1_header test
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed May 30, 2023
1 parent eeb6b74 commit 8da7e5f
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions test/unittests/eof_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,27 @@ TEST(eof, read_valid_eof1_header)
{
std::string code;
uint16_t types_size;
uint16_t code_size;
std::vector<uint16_t> code_sizes;
uint16_t data_size;
};
const TestCase test_cases[] = {
{"EF00 01 010004 0200010001 030000 00 00000000 00", 4, 1, 0},
{"EF00 01 010004 0200010006 030000 00 00000400 600160005500", 4, 6, 0},
{"EF00 01 010004 0200010001 030001 00 00000000 00 00 AA", 4, 1, 1},
{"EF00 01 010004 0200010006 030004 00 00000000 600160005500 AABBCCDD", 4, 6, 4},
{"EF00 01 010004 0200010100 031000 00 00000000" + std::string(256, '0') +
std::string(4096, 'F'),
4, 256, 4096},
};
std::string nops_255;
for (int i = 0; i < 255; ++i)
nops_255 += "5B";

const TestCase test_cases[] = {{"EF00 01 010004 0200010001 030000 00 00000000 00", 4, {1}, 0},
{"EF00 01 010004 0200010006 030000 00 00000002 600160005500", 4, {6}, 0},
{"EF00 01 010004 0200010001 030001 00 00000000 00 AA", 4, {1}, 1},
{"EF00 01 010004 0200010006 030004 00 00000002 600160005500 AABBCCDD", 4, {6}, 4},
{"EF00 01 010004 0200010100 031000 00 00000000" + nops_255 + "00" + std::string(8192, 'F'),
4, {256}, 4096}};

for (const auto& test_case : test_cases)
{
const auto code = from_spaced_hex(test_case.code).value();
EXPECT_EQ(validate_eof(EVMC_CANCUN, code), EOFValidationError::success) << test_case.code;

const auto header = read_valid_eof1_header(code);
EXPECT_EQ(header.code_sizes[0], test_case.code_size) << test_case.code;
EXPECT_EQ(header.code_sizes, test_case.code_sizes) << test_case.code;
EXPECT_EQ(header.data_size, test_case.data_size) << test_case.code;
EXPECT_EQ(header.types.size() * 4, test_case.types_size) << test_case.code;
}
Expand Down

0 comments on commit 8da7e5f

Please sign in to comment.