[repacker] begin adding tests for PairPosFormat1 splitting.

This commit is contained in:
Garret Rieger 2022-07-28 22:56:47 +00:00
parent f1bfb6585f
commit 4e7360f78d
1 changed files with 175 additions and 39 deletions

View File

@ -79,11 +79,115 @@ static void add_wide_offset (unsigned id,
c->add_link (*offset, id);
}
static void add_gsubgpos_header (unsigned lookup_list,
hb_serialize_context_t* c)
{
char header[] = {
0, 1, // major
0, 0, // minor
0, 0, // script list
0, 0, // feature list
};
start_object (header, 8, c);
add_offset (lookup_list, c);
c->pop_pack (false);
}
static unsigned add_lookup_list (const unsigned* lookups,
char count,
hb_serialize_context_t* c)
{
char lookup_count[] = {0, count};
start_object ((char *) &lookup_count, 2, c);
for (int i = 0; i < count; i++)
add_offset (lookups[i], c);
return c->pop_pack (false);
}
static void start_lookup (int8_t type,
int8_t num_subtables,
hb_serialize_context_t* c)
{
char lookup[] = {
0, type, // type
0, 0, // flag
0, num_subtables, // num subtables
};
start_object (lookup, 6, c);
}
static unsigned finish_lookup (hb_serialize_context_t* c)
{
char filter[] = {0, 0};
extend (filter, 2, c);
return c->pop_pack (false);
}
static unsigned add_extension (unsigned child,
uint8_t type,
hb_serialize_context_t* c)
{
char ext[] = {
0, 1,
0, (char) type,
};
start_object (ext, 4, c);
add_wide_offset (child, c);
return c->pop_pack (false);
}
static unsigned add_coverage (char start, char end,
hb_serialize_context_t* c)
{
char header[] = {
0, 2, // format
0, 1, // range count
0, start, // start
0, end, // end
0, 0,
};
return add_object (header, 10, c);
}
static unsigned add_pair_pos_1 (unsigned* pair_sets,
char count,
unsigned coverage,
hb_serialize_context_t* c)
{
char format[] = {
0, 1
};
start_object (format, 2, c);
add_offset (coverage, c);
char value_format[] = {
0, 0,
0, 0,
0, count,
};
extend (value_format, 6, c);
for (char i = 0; i < count; i++)
add_offset (pair_sets[(unsigned) i], c);
return c->pop_pack (false);
}
static void run_resolve_overflow_test (const char* name,
hb_serialize_context_t& overflowing,
hb_serialize_context_t& expected,
unsigned num_iterations = 0,
bool recalculate_extensions = false)
bool recalculate_extensions = false,
hb_tag_t tag = HB_TAG ('G', 'S', 'U', 'B'))
{
printf (">>> Testing overflowing resolution for %s\n",
name);
@ -93,7 +197,7 @@ static void run_resolve_overflow_test (const char* name,
assert (overflowing.offset_overflow ());
hb_blob_t* out = hb_resolve_overflows (overflowing.object_graph (),
HB_TAG ('G', 'S', 'U', 'B'),
tag,
num_iterations,
recalculate_extensions);
assert (out);
@ -884,7 +988,6 @@ populate_serializer_with_24_and_32_bit_offsets (hb_serialize_context_t* c)
c->end_serialize();
}
static void
populate_serializer_with_extension_promotion (hb_serialize_context_t* c,
int num_extensions = 0)
@ -906,31 +1009,19 @@ populate_serializer_with_extension_promotion (hb_serialize_context_t* c,
i >= (num_lookups - num_extensions) * 2;
i--)
{
char ext[] = {
0, 1,
0, 5
};
unsigned ext_index = i - (num_lookups - num_extensions) * 2; // 5
unsigned subtable_index = num_subtables - ext_index - 1; // 10 - 5 - 1 = 4
start_object (ext, 4, c);
add_wide_offset (subtables[subtable_index], c);
extensions[i] = c->pop_pack (false);
unsigned ext_index = i - (num_lookups - num_extensions) * 2;
unsigned subtable_index = num_subtables - ext_index - 1;
extensions[i] = add_extension (subtables[subtable_index], 5, c);
}
for (int i = num_lookups - 1; i >= 0; i--)
{
bool is_ext = (i >= (num_lookups - num_extensions));
char lookup[] = {
0, is_ext ? (char) 7 : (char) 5, // type
0, 0, // flag
0, 2, // num subtables
};
start_lookup (is_ext ? (char) 7 : (char) 5,
2,
c);
start_object (lookup, 6, c);
if (is_ext) {
add_offset (extensions[i * 2], c);
add_offset (extensions[i * 2 + 1], c);
@ -939,30 +1030,42 @@ populate_serializer_with_extension_promotion (hb_serialize_context_t* c,
add_offset (subtables[i * 2 + 1], c);
}
char filter[] = {0, 0};
extend (filter, 2, c);
lookups[i] = c->pop_pack (false);
lookups[i] = finish_lookup (c);
}
char lookup_count[] = {0, num_lookups};
start_object ((char *) &lookup_count, 2, c);
unsigned lookup_list = add_lookup_list (lookups, num_lookups, c);
for (int i = 0; i < num_lookups; i++)
add_offset (lookups[i], c);
add_gsubgpos_header (lookup_list, c);
unsigned lookup_list = c->pop_pack (false);
c->end_serialize();
}
char gsub_header[] = {
0, 1, // major
0, 0, // minor
0, 0, // script list
0, 0, // feature list
};
static void
populate_serializer_with_large_pair_pos_1 (hb_serialize_context_t* c)
{
std::string large_string(60000, 'a');
c->start_serialize<char> ();
start_object (gsub_header, 8, c);
add_offset (lookup_list, c);
c->pop_pack (false);
unsigned pair_set[4];
for (int i = 3; i >= 0; i--)
pair_set[i] = add_object (large_string.c_str (), 30000, c);
unsigned coverage = add_coverage (0, 3, c);
unsigned pair_pos_2 = add_object (large_string.c_str(), 200, c);
unsigned pair_pos_1 = add_pair_pos_1 (pair_set, 4, coverage, c);
start_lookup (2, 2, c);
add_offset (pair_pos_1, c);
add_offset (pair_pos_2, c);
unsigned lookup = finish_lookup (c);
unsigned lookup_list = add_lookup_list (&lookup, 1, c);
add_gsubgpos_header (lookup_list, c);
c->end_serialize();
}
@ -1336,6 +1439,30 @@ static void test_resolve_with_extension_promotion ()
free (expected_buffer);
}
static void test_resolve_with_basic_pair_pos_1_split ()
{
size_t buffer_size = 200000;
void* buffer = malloc (buffer_size);
assert (buffer);
hb_serialize_context_t c (buffer, buffer_size);
populate_serializer_with_large_pair_pos_1 (&c);
void* expected_buffer = malloc (buffer_size);
assert (expected_buffer);
hb_serialize_context_t e (expected_buffer, buffer_size);
populate_serializer_with_large_pair_pos_1 (&e);
run_resolve_overflow_test ("test_resolve_with_basic_pair_pos_1_split",
c,
e,
20,
true,
HB_TAG('G', 'P', 'O', 'S'));
free (buffer);
free (expected_buffer);
}
static void test_resolve_overflows_via_splitting_spaces ()
{
size_t buffer_size = 160000;
@ -1461,6 +1588,7 @@ test_shared_node_with_virtual_links ()
int
main (int argc, char **argv)
{
if (1) {
test_serialize ();
test_sort_shortest ();
test_will_overflow_1 ();
@ -1483,6 +1611,14 @@ main (int argc, char **argv)
test_virtual_link ();
test_shared_node_with_virtual_links ();
test_resolve_with_extension_promotion ();
}
test_resolve_with_basic_pair_pos_1_split ();
// TODO:
// - basic splitting case.
// - splitting with extensions.
// TODO(grieger): test with extensions already mixed in as well.
// TODO(grieger): test two layer ext promotion setup.
// TODO(grieger): test sorting by subtables per byte in ext. promotion.