[repacker] add test case for using max priority to resolve an overflow.

This commit is contained in:
Garret Rieger 2021-12-09 16:38:05 -08:00 committed by Behdad Esfahbod
parent be2c488e5d
commit 441877f56a
1 changed files with 73 additions and 0 deletions

View File

@ -136,6 +136,58 @@ populate_serializer_with_overflow (hb_serialize_context_t* c)
c->end_serialize(); c->end_serialize();
} }
static void
populate_serializer_with_priority_overflow (hb_serialize_context_t* c)
{
std::string large_string(50000, 'a');
c->start_serialize<char> ();
unsigned obj_e = add_object ("e", 1, c);
unsigned obj_d = add_object ("d", 1, c);
start_object (large_string.c_str (), 50000, c);
add_offset (obj_e, c);
unsigned obj_c = c->pop_pack (false);
start_object (large_string.c_str (), 20000, c);
add_offset (obj_d, c);
unsigned obj_b = c->pop_pack (false);
start_object ("a", 1, c);
add_offset (obj_b, c);
add_offset (obj_c, c);
c->pop_pack (false);
c->end_serialize();
}
static void
populate_serializer_with_priority_overflow_expected (hb_serialize_context_t* c)
{
std::string large_string(50000, 'a');
c->start_serialize<char> ();
unsigned obj_e = add_object ("e", 1, c);
start_object (large_string.c_str (), 50000, c);
add_offset (obj_e, c);
unsigned obj_c = c->pop_pack (false);
unsigned obj_d = add_object ("d", 1, c);
start_object (large_string.c_str (), 20000, c);
add_offset (obj_d, c);
unsigned obj_b = c->pop_pack (false);
start_object ("a", 1, c);
add_offset (obj_b, c);
add_offset (obj_c, c);
c->pop_pack (false);
c->end_serialize();
}
static void static void
populate_serializer_with_dedup_overflow (hb_serialize_context_t* c) populate_serializer_with_dedup_overflow (hb_serialize_context_t* c)
{ {
@ -1198,6 +1250,26 @@ static void test_resolve_overflows_via_splitting_spaces_2 ()
free (expected_buffer); free (expected_buffer);
} }
static void test_resolve_overflows_via_priority ()
{
size_t buffer_size = 160000;
void* buffer = malloc (buffer_size);
hb_serialize_context_t c (buffer, buffer_size);
populate_serializer_with_priority_overflow (&c);
void* expected_buffer = malloc (buffer_size);
hb_serialize_context_t e (expected_buffer, buffer_size);
populate_serializer_with_priority_overflow_expected (&e);
run_resolve_overflow_test ("test_resolve_overflows_via_priority",
c,
e,
3);
free (buffer);
free (expected_buffer);
}
static void test_virtual_link () static void test_virtual_link ()
{ {
size_t buffer_size = 100; size_t buffer_size = 100;
@ -1272,6 +1344,7 @@ main (int argc, char **argv)
test_will_overflow_3 (); test_will_overflow_3 ();
test_resolve_overflows_via_sort (); test_resolve_overflows_via_sort ();
test_resolve_overflows_via_duplication (); test_resolve_overflows_via_duplication ();
test_resolve_overflows_via_priority ();
test_resolve_overflows_via_space_assignment (); test_resolve_overflows_via_space_assignment ();
test_resolve_overflows_via_isolation (); test_resolve_overflows_via_isolation ();
test_resolve_overflows_via_isolation_with_recursive_duplication (); test_resolve_overflows_via_isolation_with_recursive_duplication ();