Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Jun 4, 2024
1 parent 2414fd6 commit 3d9a3bf
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions test/unittests/eof_validation_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,51 +608,51 @@ TEST_F(eof_validation, EOF1_rjumpv_invalid_destination)

TEST_F(eof_validation, EOF1_section_order)
{
// 01 02 03
// 01 02 04
add_test_case("EF0001 010004 0200010006 040002 00 00800001 6000E0000000 AABB",
EOFValidationError::success);

// 01 03 02
// 01 04 02
add_test_case("EF0001 010004 040002 0200010006 00 00800000 AABB 6000E0000000",
EOFValidationError::code_section_missing);

// 02 01 03
// 02 01 04
add_test_case("EF0001 0200010006 010004 040002 00 6000E0000000 00800000 AABB",
EOFValidationError::type_section_missing);

// 02 03 01
// 02 04 01
add_test_case("EF0001 0200010006 040002 010004 00 6000E0000000 AABB 00800000",
EOFValidationError::type_section_missing);

// 03 01 02
// 04 01 02
add_test_case("EF0001 040002 010004 0200010006 00 AABB 00800000 6000E0000000",
EOFValidationError::type_section_missing);

// 03 02 01
// 04 02 01
add_test_case("EF0001 040002 0200010006 010004 00 AABB 6000E0000000 00800000",
EOFValidationError::type_section_missing);

// 01 02 03 04
add_test_case(
"EF0001 010004 0200010006 0300010014 040002 00 00800001 6000E0000000 "
"EF0001 010004 0200010007 0300010014 040002 00 00800004 5F5F5F5FEC0000 "
"EF000101000402000100010400000000800000FE AABB",
EOFValidationError::success);

// 03 01 02 04
add_test_case(
"EF0001 0300010014 010004 0200010006 040002 00 EF000101000402000100010400000000800000FE "
"00800001 6000E0000000 AABB",
"EF0001 0300010014 010004 0200010007 040002 00 EF000101000402000100010400000000800000FE "
"00800004 5F5F5F5FEC0000 AABB",
EOFValidationError::type_section_missing);

// 01 03 02 04
add_test_case(
"EF0001 010004 0300010014 0200010006 040002 00 00800001 "
"EF000101000402000100010400000000800000FE 6000E0000000 AABB",
"EF0001 010004 0300010014 0200010007 040002 00 00800004 "
"EF000101000402000100010400000000800000FE 5F5F5F5FEC0000 AABB",
EOFValidationError::code_section_missing);

// 01 02 04 03
add_test_case(
"EF0001 010004 0200010006 040002 0300010014 00 00800001 6000E0000000 AABB "
"EF0001 010004 0200010007 040002 0300010014 00 00800004 5F5F5F5FEC0000 AABB "
"EF000101000402000100010400000000800000FE",
EOFValidationError::header_terminator_missing);
}
Expand Down Expand Up @@ -1012,40 +1012,44 @@ TEST_F(eof_validation, EOF1_embedded_container)
{
// no data section
add_test_case(
"EF0001 010004 0200010006 0300010014 040000 00 00800001 6000E0000000 "
"EF0001 010004 0200010007 0300010014 040000 00 00800004 5F5F5F5FEC0000 "
"EF000101000402000100010400000000800000FE",
EOFValidationError::success);

// no data section in container, but anticipated aux_data
add_test_case(
"EF0001 010004 0200010006 0300010014 040002 00 00800001 6000E0000000 "
"EF0001 010004 0200010007 0300010014 040002 00 00800004 5F5F5F5FEC0000 "
"EF000101000402000100010400000000800000FE",
EOFValidationError::success);

// with data section
add_test_case(
"EF0001 010004 0200010006 0300010014 040002 00 00800001 6000E0000000 "
"EF0001 010004 0200010007 0300010014 040002 00 00800004 5F5F5F5FEC0000 "
"EF000101000402000100010400000000800000FE AABB",
EOFValidationError::success);

// garbage in container section - not allowed
add_test_case(
"EF0001 010004 0200010006 0300010006 040000 00 00800001 6000E0000000 aabbccddeeff",
"EF0001 010004 0200010007 0300010006 040000 00 00800004 5F5F5F5FEC0000 aabbccddeeff",
EOFValidationError::invalid_prefix);

// multiple container sections
add_test_case(
"EF0001 010004 0200010006 03000200140016 040000 00 00800001 6000E0000000 "
"EF0001 010004 020001000E 03000200140016 040000 00 00800004 5F5F5F5FEC00505F5F5F5FEC0100 "
"EF000101000402000100010400000000800000FE "
"EF0001010004020001000304000000008000025F5FF3",
"EF0001010004020001000304000000008000025F5FFD",
EOFValidationError::success);

// Max number (256) of container sections
const auto containers_header = bytecode{"030100"} + 256 * bytecode{"0014"};
const auto containers_body = 256 * bytecode{"EF000101000402000100010400000000800000FE"};
add_test_case("EF0001 010004 0200010006" + containers_header +
"040000 00 00800001 6000E0000000" + containers_body,
EOFValidationError::success);
bytecode code;
for (auto i = 0; i < 256; ++i)
code += eofcreate().container(static_cast<uint8_t>(i)) + OP_POP;
code += bytecode{OP_STOP};
auto container = eof_bytecode(code, 4);
const auto subcontainer = eof_bytecode(OP_INVALID);
for (auto i = 0; i < 256; ++i)
container.container(subcontainer);
add_test_case(container, EOFValidationError::success);

Check warning on line 1052 in test/unittests/eof_validation_test.cpp

View check run for this annotation

Codecov / codecov/patch

test/unittests/eof_validation_test.cpp#L1044-L1052

Added lines #L1044 - L1052 were not covered by tests
}

TEST_F(eof_validation, EOF1_embedded_container_invalid)
Expand Down Expand Up @@ -1091,8 +1095,10 @@ TEST_F(eof_validation, EOF1_eofcreate_valid)

// initcontainer_index = 1
add_test_case(
eof_bytecode(
eofcreate().container(1).input(0, OP_CALLDATASIZE).salt(0xff) + OP_POP + OP_STOP, 4)
eof_bytecode(eofcreate().container(0).input(0, OP_CALLDATASIZE).salt(0xff) + OP_POP +
eofcreate().container(1).input(0, OP_CALLDATASIZE).salt(0xfe) + OP_POP +

Check warning on line 1099 in test/unittests/eof_validation_test.cpp

View check run for this annotation

Codecov / codecov/patch

test/unittests/eof_validation_test.cpp#L1098-L1099

Added lines #L1098 - L1099 were not covered by tests
OP_STOP,
4)
.container(embedded)
.container(embedded),
EOFValidationError::success);
Expand Down

0 comments on commit 3d9a3bf

Please sign in to comment.