[repacker] add a couple more complex isolation tests.
This commit is contained in:
parent
62c502cd9d
commit
d0daa7a59b
|
@ -865,7 +865,8 @@ static bool _process_overflows (const hb_vector_t<graph_t::overflow_record_t>& o
|
|||
inline void
|
||||
hb_resolve_overflows (const hb_vector_t<hb_serialize_context_t::object_t *>& packed,
|
||||
hb_tag_t table_tag,
|
||||
hb_serialize_context_t* c) {
|
||||
hb_serialize_context_t* c,
|
||||
unsigned max_rounds = 10) {
|
||||
// Kahn sort is ~twice as fast as shortest distance sort and works for many fonts
|
||||
// so try it first to save time.
|
||||
graph_t sorted_graph (packed);
|
||||
|
@ -894,7 +895,7 @@ hb_resolve_overflows (const hb_vector_t<hb_serialize_context_t::object_t *>& pac
|
|||
// TODO(garretrieger): select a good limit for max rounds.
|
||||
while (!sorted_graph.in_error ()
|
||||
&& sorted_graph.will_overflow (&overflows)
|
||||
&& round++ < 10) {
|
||||
&& round++ < max_rounds) {
|
||||
DEBUG_MSG (SUBSET_REPACK, nullptr, "=== Overflow resolution round %d ===", round);
|
||||
sorted_graph.print_overflows (overflows);
|
||||
|
||||
|
|
|
@ -143,6 +143,70 @@ populate_serializer_with_isolation_overflow (hb_serialize_context_t* c)
|
|||
c->end_serialize();
|
||||
}
|
||||
|
||||
static void
|
||||
populate_serializer_with_isolation_overflow_complex (hb_serialize_context_t* c)
|
||||
{
|
||||
std::string large_string(70000, 'a');
|
||||
c->start_serialize<char> ();
|
||||
|
||||
unsigned obj_f = add_object ("f", 1, c);
|
||||
|
||||
start_object ("e", 1, c);
|
||||
add_offset (obj_f, c);
|
||||
unsigned obj_e = c->pop_pack ();
|
||||
|
||||
start_object ("c", 1, c);
|
||||
add_offset (obj_e, c);
|
||||
unsigned obj_c = c->pop_pack ();
|
||||
|
||||
start_object ("d", 1, c);
|
||||
add_offset (obj_e, c);
|
||||
unsigned obj_d = c->pop_pack ();
|
||||
|
||||
start_object (large_string.c_str(), 60000, c);
|
||||
add_offset (obj_c, c);
|
||||
add_offset (obj_d, c);
|
||||
unsigned obj_b = c->pop_pack ();
|
||||
|
||||
start_object (large_string.c_str(), 10000, c);
|
||||
add_offset (obj_d, c);
|
||||
unsigned obj_g = c->pop_pack ();
|
||||
|
||||
start_object ("a", 1, c);
|
||||
add_wide_offset (obj_b, c);
|
||||
add_offset (obj_g, c);
|
||||
c->pop_pack ();
|
||||
|
||||
c->end_serialize();
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
populate_serializer_with_isolation_overflow_spaces (hb_serialize_context_t* c)
|
||||
{
|
||||
std::string large_string(70000, 'a');
|
||||
c->start_serialize<char> ();
|
||||
|
||||
unsigned obj_d = add_object ("f", 1, c);
|
||||
unsigned obj_e = add_object ("f", 1, c);
|
||||
|
||||
start_object (large_string.c_str(), 60000, c);
|
||||
add_offset (obj_d, c);
|
||||
unsigned obj_b = c->pop_pack ();
|
||||
|
||||
start_object (large_string.c_str(), 60000, c);
|
||||
add_offset (obj_e, c);
|
||||
unsigned obj_c = c->pop_pack ();
|
||||
|
||||
|
||||
start_object ("a", 1, c);
|
||||
add_wide_offset (obj_b, c);
|
||||
add_wide_offset (obj_c, c);
|
||||
c->pop_pack ();
|
||||
|
||||
c->end_serialize();
|
||||
}
|
||||
|
||||
static void
|
||||
populate_serializer_complex_1 (hb_serialize_context_t* c)
|
||||
{
|
||||
|
@ -509,7 +573,7 @@ static void test_resolve_overflows_via_isolation ()
|
|||
hb_serialize_context_t out (out_buffer, buffer_size);
|
||||
|
||||
assert (c.offset_overflow ());
|
||||
hb_resolve_overflows (c.object_graph (), HB_TAG ('G', 'S', 'U', 'B'), &out);
|
||||
hb_resolve_overflows (c.object_graph (), HB_TAG ('G', 'S', 'U', 'B'), &out, 0);
|
||||
assert (!out.offset_overflow ());
|
||||
hb_bytes_t result = out.copy_bytes ();
|
||||
assert (result.length == (1 + 10000 + 60000 + 1 + 1
|
||||
|
@ -520,11 +584,57 @@ static void test_resolve_overflows_via_isolation ()
|
|||
free (out_buffer);
|
||||
}
|
||||
|
||||
// TODO(grieger): test for recursively duplicated nodes during isolation.
|
||||
// TODO(grieger): test that isolated subgraphs are packed tightly within the subgraph.
|
||||
static void test_resolve_overflows_via_isolation_with_recursive_duplication ()
|
||||
{
|
||||
size_t buffer_size = 160000;
|
||||
void* buffer = malloc (buffer_size);
|
||||
hb_serialize_context_t c (buffer, buffer_size);
|
||||
populate_serializer_with_isolation_overflow_complex (&c);
|
||||
graph_t graph (c.object_graph ());
|
||||
|
||||
void* out_buffer = malloc (buffer_size);
|
||||
hb_serialize_context_t out (out_buffer, buffer_size);
|
||||
|
||||
assert (c.offset_overflow ());
|
||||
hb_resolve_overflows (c.object_graph (), HB_TAG ('G', 'S', 'U', 'B'), &out, 0);
|
||||
assert (!out.offset_overflow ());
|
||||
hb_bytes_t result = out.copy_bytes ();
|
||||
|
||||
unsigned expected_length = 8 + 10000 + 60000; // objects
|
||||
expected_length += 4 + 2 * 9; // links
|
||||
assert (result.length == expected_length);
|
||||
|
||||
result.fini ();
|
||||
free (buffer);
|
||||
free (out_buffer);
|
||||
}
|
||||
|
||||
static void test_resolve_overflows_via_isolation_spaces ()
|
||||
{
|
||||
size_t buffer_size = 160000;
|
||||
void* buffer = malloc (buffer_size);
|
||||
hb_serialize_context_t c (buffer, buffer_size);
|
||||
populate_serializer_with_isolation_overflow_spaces (&c);
|
||||
graph_t graph (c.object_graph ());
|
||||
|
||||
void* out_buffer = malloc (buffer_size);
|
||||
hb_serialize_context_t out (out_buffer, buffer_size);
|
||||
|
||||
assert (c.offset_overflow ());
|
||||
hb_resolve_overflows (c.object_graph (), HB_TAG ('G', 'S', 'U', 'B'), &out, 0);
|
||||
assert (!out.offset_overflow ());
|
||||
hb_bytes_t result = out.copy_bytes ();
|
||||
|
||||
unsigned expected_length = 3 + 2 * 60000; // objects
|
||||
expected_length += 2 * 4 + 2 * 2; // links
|
||||
assert (result.length == expected_length);
|
||||
|
||||
result.fini ();
|
||||
free (buffer);
|
||||
free (out_buffer);
|
||||
}
|
||||
|
||||
// TODO(garretrieger): update will_overflow tests to check the overflows array.
|
||||
// TODO(garretrieger): add a test(s) using a real font.
|
||||
// TODO(garretrieger): add tests for priority raising.
|
||||
|
||||
int
|
||||
|
@ -540,6 +650,8 @@ main (int argc, char **argv)
|
|||
test_resolve_overflows_via_sort ();
|
||||
test_resolve_overflows_via_duplication ();
|
||||
test_resolve_overflows_via_isolation ();
|
||||
test_resolve_overflows_via_isolation_with_recursive_duplication ();
|
||||
test_resolve_overflows_via_isolation_spaces ();
|
||||
test_duplicate_leaf ();
|
||||
test_duplicate_interior ();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue