diff --git a/src/graph/graph.hh b/src/graph/graph.hh index 3479e002c..347a2b012 100644 --- a/src/graph/graph.hh +++ b/src/graph/graph.hh @@ -49,17 +49,27 @@ struct graph_t unsigned end = 0; unsigned priority = 0; - bool equals (vertex_t& other, graph_t& graph) + void normalize () { - if (as_bytes () != other.as_bytes ()) + obj.real_links.qsort (); + for (auto& l : obj.real_links) + { + for (unsigned i = 0; i < l.width; i++) + { + obj.head[l.position + i] = 0; + } + } + } + + bool equals (const vertex_t& other, const graph_t& graph) const + { + if (!(as_bytes () == other.as_bytes ())) return false; - obj.real_links.qsort (); - other.obj.real_links.qsort (); return links_equal (graph, obj.real_links, other.obj.real_links); } - hb_bytes_t as_bytes () + hb_bytes_t as_bytes () const { return hb_bytes_t (obj.head, table_size ()); } @@ -184,7 +194,7 @@ struct graph_t } private: - bool links_equal (graph_t& graph, + bool links_equal (const graph_t& graph, const hb_vector_t& this_links, const hb_vector_t& other_links) const { @@ -281,9 +291,16 @@ struct graph_t hb_free (b); } - bool operator== (graph_t& other) + bool operator== (const graph_t& other) const { - return vertices_[root_idx ()].equals (other.vertices_[other.root_idx ()], *this); + return root ().equals (other.root (), *this); + } + + // Sorts links of all objects in a consistent manner and zeroes all offsets. + void normalize () + { + for (auto& v : vertices_.writer ()) + v.normalize (); } bool in_error () const diff --git a/src/test-repacker.cc b/src/test-repacker.cc index e6ac36e7a..0afd6f2b1 100644 --- a/src/test-repacker.cc +++ b/src/test-repacker.cc @@ -309,44 +309,28 @@ static void run_resolve_overflow_test (const char* name, name); graph_t graph (overflowing.object_graph ()); + graph_t expected_graph (expected.object_graph ()); + // Check that overflow resolution succeeds assert (overflowing.offset_overflow ()); - hb_blob_t* out = hb_resolve_overflows (overflowing.object_graph (), - tag, - num_iterations, - recalculate_extensions); + assert (hb_resolve_graph_overflows (tag, + num_iterations, + recalculate_extensions, + graph)); + + // Check the graphs can be serialized. + hb_blob_t* out = graph::serialize (graph); assert (out); - - hb_bytes_t result = out->as_bytes (); - - assert (!expected.offset_overflow ()); - hb_bytes_t expected_result = expected.copy_bytes (); - - if (result.length != expected_result.length) - { - printf("result.length (%u) != expected.length (%u).\n", - result.length, - expected_result.length); - } - assert (result.length == expected_result.length); - - bool equal = true; - for (unsigned i = 0; i < expected_result.length; i++) - { - if (result[i] != expected_result[i]) - { - equal = false; - uint8_t a = result[i]; - uint8_t b = expected_result[i]; - printf("%08u: %x != %x\n", i, a, b); - } - } - - assert (equal); - - expected_result.fini (); hb_blob_destroy (out); + out = graph::serialize (expected_graph); + assert (out); + hb_blob_destroy (out); + + // Check the graphs are equivalent + graph.normalize (); + expected_graph.normalize (); + assert (graph == expected_graph); } static void add_virtual_offset (unsigned id,