Merge pull request #1290 from ebraminio/testopenfont

[test] Unify font file opening across the tests
This commit is contained in:
Ebrahim Byagowi 2018-10-21 11:36:41 +03:30 committed by GitHub
commit 4fa94a3e39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 78 additions and 113 deletions

View File

@ -47,27 +47,6 @@ typedef short bool;
HB_BEGIN_DECLS
static inline hb_face_t *
hb_subset_test_open_font (const char *font_path)
{
#if GLIB_CHECK_VERSION(2,37,2)
char *path = g_test_build_filename (G_TEST_DIST, font_path, NULL);
#else
char *path = g_strdup (font_path);
#endif
hb_blob_t *blob = hb_blob_create_from_file (path);
if (hb_blob_get_length (blob) == 0)
g_error ("Font not found.");
hb_face_t *face = hb_face_create (blob, 0);
hb_blob_destroy (blob);
g_free (path);
return face;
}
static inline hb_subset_input_t *
hb_subset_test_create_input(const hb_set_t *codepoints)
{

View File

@ -277,6 +277,27 @@ G_STMT_START { \
} G_STMT_END
static inline hb_face_t *
hb_test_open_font_file (const char *font_path)
{
#if GLIB_CHECK_VERSION(2,37,2)
char *path = g_test_build_filename (G_TEST_DIST, font_path, NULL);
#else
char *path = g_strdup (font_path);
#endif
hb_blob_t *blob = hb_blob_create_from_file (path);
if (hb_blob_get_length (blob) == 0)
g_error ("Font not found.");
hb_face_t *face = hb_face_create (blob, 0);
hb_blob_destroy (blob);
g_free (path);
return face;
}
HB_END_DECLS
#endif /* HB_TEST_H */

View File

@ -30,7 +30,7 @@
static void
test_collect_unicodes_format4 (void)
{
hb_face_t *face = hb_subset_test_open_font("fonts/Roboto-Regular.abc.format4.ttf");
hb_face_t *face = hb_test_open_font_file ("fonts/Roboto-Regular.abc.format4.ttf");
hb_set_t *codepoints = hb_set_create();
hb_codepoint_t cp;
@ -52,7 +52,7 @@ test_collect_unicodes_format4 (void)
static void
test_collect_unicodes_format12 (void)
{
hb_face_t *face = hb_subset_test_open_font("fonts/Roboto-Regular.abc.format12.ttf");
hb_face_t *face = hb_test_open_font_file ("fonts/Roboto-Regular.abc.format12.ttf");
hb_set_t *codepoints = hb_set_create();
hb_codepoint_t cp;
@ -74,7 +74,7 @@ test_collect_unicodes_format12 (void)
static void
test_collect_unicodes (void)
{
hb_face_t *face = hb_subset_test_open_font("fonts/Roboto-Regular.abc.ttf");
hb_face_t *face = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
hb_set_t *codepoints = hb_set_create();
hb_codepoint_t cp;

View File

@ -23,16 +23,13 @@
*
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <pthread.h>
#include <hb.h>
#include <hb-ft.h>
#include <hb-ot.h>
#include <glib.h>
#include "hb-test.h"
static const char *font_path = "fonts/Inconsolata-Regular.abc.ttf";
static const char *text = "abc";
@ -127,15 +124,9 @@ test_body (void)
int
main (int argc, char **argv)
{
g_test_init (&argc, &argv, NULL);
hb_test_init (&argc, &argv);
#if GLIB_CHECK_VERSION(2,37,2)
gchar *default_path = g_test_build_filename (G_TEST_DIST, font_path, NULL);
#else
gchar *default_path = g_strdup (font_path);
#endif
char *path = argc > 1 && *argv[1] ? argv[1] : (char *) default_path;
char *path = argc > 1 && *argv[1] ? argv[1] : (char *) font_path;
if (argc > 2)
num_threads = atoi (argv[2]);
if (argc > 3)
@ -147,11 +138,7 @@ main (int argc, char **argv)
* https://github.com/harfbuzz/harfbuzz/issues/1191 */
hb_language_get_default ();
hb_blob_t *blob = hb_blob_create_from_file (path);
if (hb_blob_get_length (blob) == 0)
g_error ("Font not found.");
hb_face_t *face = hb_face_create (blob, 0);
hb_face_t *face = hb_test_open_font_file (path);
font = hb_font_create (face);
/* Fill the reference */
@ -170,9 +157,6 @@ main (int argc, char **argv)
hb_font_destroy (font);
hb_face_destroy (face);
hb_blob_destroy (blob);
g_free (default_path);
return 0;
}

View File

@ -27,12 +27,10 @@
#include <hb-ot.h>
static const char *font_path = "fonts/cv01.otf";
static hb_face_t *face;
static void
test_ot_layout_feature_get_name_ids_and_characters (void)
{
hb_face_t *face = hb_test_open_font_file ("fonts/cv01.otf");
hb_tag_t cv01 = HB_TAG ('c','v','0','1');
unsigned int feature_index;
if (!hb_ot_layout_language_find_feature (face,
@ -70,6 +68,8 @@ test_ot_layout_feature_get_name_ids_and_characters (void)
g_assert_cmpint (char_count, ==, 2);
g_assert_cmpint (characters[0], ==, 10);
g_assert_cmpint (characters[1], ==, 24030);
hb_face_destroy (face);
}
int
@ -77,26 +77,7 @@ main (int argc, char **argv)
{
g_test_init (&argc, &argv, NULL);
#if GLIB_CHECK_VERSION(2,37,2)
gchar *default_path = g_test_build_filename (G_TEST_DIST, font_path, NULL);
#else
gchar *default_path = g_strdup (font_path);
#endif
hb_blob_t *blob;
char *path = argc > 1 && *argv[1] ? argv[1] : (char *) default_path;
blob = hb_blob_create_from_file (path);
if (hb_blob_get_length (blob) == 0)
g_error ("Font not found.");
face = hb_face_create (blob, 0);
hb_test_add (test_ot_layout_feature_get_name_ids_and_characters);
unsigned int result = hb_test_run ();
hb_face_destroy (face);
hb_blob_destroy (blob);
g_free (default_path);
return result;
return hb_test_run ();
}

View File

@ -32,8 +32,8 @@
static void
test_subset_cmap (void)
{
hb_face_t *face_abc = hb_subset_test_open_font ("fonts/Roboto-Regular.abc.ttf");
hb_face_t *face_ac = hb_subset_test_open_font ("fonts/Roboto-Regular.ac.ttf");
hb_face_t *face_abc = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
hb_face_t *face_ac = hb_test_open_font_file ("fonts/Roboto-Regular.ac.ttf");
hb_set_t *codepoints = hb_set_create ();
hb_face_t *face_abc_subset;
@ -52,7 +52,7 @@ test_subset_cmap (void)
static void
test_subset_cmap_non_consecutive_glyphs (void)
{
hb_face_t *face = hb_subset_test_open_font ("fonts/Roboto-Regular.D7,D8,D9,DA,DE.ttf");
hb_face_t *face = hb_test_open_font_file ("fonts/Roboto-Regular.D7,D8,D9,DA,DE.ttf");
hb_set_t *codepoints = hb_set_create ();
hb_face_t *face_subset;
@ -74,7 +74,7 @@ test_subset_cmap_non_consecutive_glyphs (void)
static void
test_subset_cmap_noop (void)
{
hb_face_t *face_abc = hb_subset_test_open_font("fonts/Roboto-Regular.abc.ttf");
hb_face_t *face_abc = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
hb_set_t *codepoints = hb_set_create();
hb_face_t *face_abc_subset;

View File

@ -60,8 +60,8 @@ static void check_maxp_num_glyphs (hb_face_t *face, uint16_t expected_num_glyphs
static void
test_subset_glyf (void)
{
hb_face_t *face_abc = hb_subset_test_open_font ("fonts/Roboto-Regular.abc.ttf");
hb_face_t *face_ac = hb_subset_test_open_font ("fonts/Roboto-Regular.ac.ttf");
hb_face_t *face_abc = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
hb_face_t *face_ac = hb_test_open_font_file ("fonts/Roboto-Regular.ac.ttf");
hb_set_t *codepoints = hb_set_create();
hb_face_t *face_abc_subset;
@ -82,8 +82,8 @@ test_subset_glyf (void)
static void
test_subset_glyf_with_components (void)
{
hb_face_t *face_components = hb_subset_test_open_font ("fonts/Roboto-Regular.components.ttf");
hb_face_t *face_subset = hb_subset_test_open_font ("fonts/Roboto-Regular.components.subset.ttf");
hb_face_t *face_components = hb_test_open_font_file ("fonts/Roboto-Regular.components.ttf");
hb_face_t *face_subset = hb_test_open_font_file ("fonts/Roboto-Regular.components.subset.ttf");
hb_set_t *codepoints = hb_set_create();
hb_face_t *face_generated_subset;
@ -103,8 +103,8 @@ test_subset_glyf_with_components (void)
static void
test_subset_glyf_with_gsub (void)
{
hb_face_t *face_fil = hb_subset_test_open_font ("fonts/Roboto-Regular.gsub.fil.ttf");
hb_face_t *face_fi = hb_subset_test_open_font ("fonts/Roboto-Regular.gsub.fi.ttf");
hb_face_t *face_fil = hb_test_open_font_file ("fonts/Roboto-Regular.gsub.fil.ttf");
hb_face_t *face_fi = hb_test_open_font_file ("fonts/Roboto-Regular.gsub.fi.ttf");
hb_subset_input_t *input;
hb_face_t *face_subset;
@ -130,8 +130,8 @@ test_subset_glyf_with_gsub (void)
static void
test_subset_glyf_without_gsub (void)
{
hb_face_t *face_fil = hb_subset_test_open_font ("fonts/Roboto-Regular.gsub.fil.ttf");
hb_face_t *face_fi = hb_subset_test_open_font ("fonts/Roboto-Regular.nogsub.fi.ttf");
hb_face_t *face_fil = hb_test_open_font_file ("fonts/Roboto-Regular.gsub.fil.ttf");
hb_face_t *face_fi = hb_test_open_font_file ("fonts/Roboto-Regular.nogsub.fi.ttf");
hb_subset_input_t *input;
hb_face_t *face_subset;
@ -157,7 +157,7 @@ test_subset_glyf_without_gsub (void)
static void
test_subset_glyf_noop (void)
{
hb_face_t *face_abc = hb_subset_test_open_font("fonts/Roboto-Regular.abc.ttf");
hb_face_t *face_abc = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
hb_set_t *codepoints = hb_set_create();
hb_face_t *face_abc_subset;
@ -178,8 +178,8 @@ test_subset_glyf_noop (void)
static void
test_subset_glyf_strip_hints_simple (void)
{
hb_face_t *face_abc = hb_subset_test_open_font ("fonts/Roboto-Regular.abc.ttf");
hb_face_t *face_ac = hb_subset_test_open_font ("fonts/Roboto-Regular.ac.nohints.ttf");
hb_face_t *face_abc = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
hb_face_t *face_ac = hb_test_open_font_file ("fonts/Roboto-Regular.ac.nohints.ttf");
hb_set_t *codepoints = hb_set_create();
hb_subset_input_t *input;
@ -203,8 +203,8 @@ test_subset_glyf_strip_hints_simple (void)
static void
test_subset_glyf_strip_hints_composite (void)
{
hb_face_t *face_components = hb_subset_test_open_font ("fonts/Roboto-Regular.components.ttf");
hb_face_t *face_subset = hb_subset_test_open_font ("fonts/Roboto-Regular.components.1fc.nohints.ttf");
hb_face_t *face_components = hb_test_open_font_file ("fonts/Roboto-Regular.components.ttf");
hb_face_t *face_subset = hb_test_open_font_file ("fonts/Roboto-Regular.components.1fc.nohints.ttf");
hb_set_t *codepoints = hb_set_create();
hb_subset_input_t *input;
@ -228,7 +228,7 @@ test_subset_glyf_strip_hints_composite (void)
static void
test_subset_glyf_strip_hints_invalid (void)
{
hb_face_t *face = hb_subset_test_open_font ("../fuzzing/fonts/oom-ccc61c92d589f895174cdef6ff2e3b20e9999a1a");
hb_face_t *face = hb_test_open_font_file ("../fuzzing/fonts/oom-ccc61c92d589f895174cdef6ff2e3b20e9999a1a");
hb_set_t *codepoints = hb_set_create();
const hb_codepoint_t text[] =

View File

@ -33,8 +33,8 @@
static void
test_subset_hdmx_simple_subset (void)
{
hb_face_t *face_abc = hb_subset_test_open_font ("fonts/Roboto-Regular.abc.ttf");
hb_face_t *face_ac = hb_subset_test_open_font ("fonts/Roboto-Regular.ac.ttf");
hb_face_t *face_abc = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
hb_face_t *face_ac = hb_test_open_font_file ("fonts/Roboto-Regular.ac.ttf");
hb_set_t *codepoints = hb_set_create ();
hb_face_t *face_abc_subset;
@ -53,8 +53,8 @@ test_subset_hdmx_simple_subset (void)
static void
test_subset_hdmx_multiple_device_records (void)
{
hb_face_t *face_abc = hb_subset_test_open_font ("fonts/Roboto-Regular.multihdmx.abc.ttf");
hb_face_t *face_a = hb_subset_test_open_font ("fonts/Roboto-Regular.multihdmx.a.ttf");
hb_face_t *face_abc = hb_test_open_font_file ("fonts/Roboto-Regular.multihdmx.abc.ttf");
hb_face_t *face_a = hb_test_open_font_file ("fonts/Roboto-Regular.multihdmx.a.ttf");
hb_set_t *codepoints = hb_set_create ();
hb_face_t *face_abc_subset;
@ -72,7 +72,7 @@ test_subset_hdmx_multiple_device_records (void)
static void
test_subset_hdmx_invalid (void)
{
hb_face_t *face = hb_subset_test_open_font("../fuzzing/fonts/crash-ccc61c92d589f895174cdef6ff2e3b20e9999a1a");
hb_face_t *face = hb_test_open_font_file ("../fuzzing/fonts/crash-ccc61c92d589f895174cdef6ff2e3b20e9999a1a");
hb_subset_input_t *input = hb_subset_input_create_or_fail ();
hb_set_t *codepoints = hb_subset_input_unicode_set (input);
@ -94,7 +94,7 @@ test_subset_hdmx_invalid (void)
static void
test_subset_hdmx_fails_sanitize (void)
{
hb_face_t *face = hb_subset_test_open_font("../fuzzing/fonts/clusterfuzz-testcase-minimized-hb-subset-fuzzer-5609911946838016");
hb_face_t *face = hb_test_open_font_file ("../fuzzing/fonts/clusterfuzz-testcase-minimized-hb-subset-fuzzer-5609911946838016");
hb_subset_input_t *input = hb_subset_input_create_or_fail ();
hb_set_t *codepoints = hb_subset_input_unicode_set (input);
@ -116,7 +116,7 @@ test_subset_hdmx_fails_sanitize (void)
static void
test_subset_hdmx_noop (void)
{
hb_face_t *face_abc = hb_subset_test_open_font("fonts/Roboto-Regular.abc.ttf");
hb_face_t *face_abc = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
hb_set_t *codepoints = hb_set_create();
hb_face_t *face_abc_subset;

View File

@ -47,8 +47,8 @@ static void check_num_hmetrics(hb_face_t *face, uint16_t expected_num_hmetrics)
static void
test_subset_hmtx_simple_subset (void)
{
hb_face_t *face_abc = hb_subset_test_open_font ("fonts/Roboto-Regular.abc.ttf");
hb_face_t *face_ac = hb_subset_test_open_font ("fonts/Roboto-Regular.ac.ttf");
hb_face_t *face_abc = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
hb_face_t *face_ac = hb_test_open_font_file ("fonts/Roboto-Regular.ac.ttf");
hb_set_t *codepoints = hb_set_create ();
hb_face_t *face_abc_subset;
@ -69,8 +69,8 @@ test_subset_hmtx_simple_subset (void)
static void
test_subset_hmtx_monospace (void)
{
hb_face_t *face_abc = hb_subset_test_open_font ("fonts/Inconsolata-Regular.abc.ttf");
hb_face_t *face_ac = hb_subset_test_open_font ("fonts/Inconsolata-Regular.ac.ttf");
hb_face_t *face_abc = hb_test_open_font_file ("fonts/Inconsolata-Regular.abc.ttf");
hb_face_t *face_ac = hb_test_open_font_file ("fonts/Inconsolata-Regular.ac.ttf");
hb_set_t *codepoints = hb_set_create ();
hb_face_t *face_abc_subset;
@ -91,8 +91,8 @@ test_subset_hmtx_monospace (void)
static void
test_subset_hmtx_keep_num_metrics (void)
{
hb_face_t *face_abc = hb_subset_test_open_font ("fonts/Inconsolata-Regular.abc.widerc.ttf");
hb_face_t *face_ac = hb_subset_test_open_font ("fonts/Inconsolata-Regular.ac.widerc.ttf");
hb_face_t *face_abc = hb_test_open_font_file ("fonts/Inconsolata-Regular.abc.widerc.ttf");
hb_face_t *face_ac = hb_test_open_font_file ("fonts/Inconsolata-Regular.ac.widerc.ttf");
hb_set_t *codepoints = hb_set_create ();
hb_face_t *face_abc_subset;
@ -112,8 +112,8 @@ test_subset_hmtx_keep_num_metrics (void)
static void
test_subset_hmtx_decrease_num_metrics (void)
{
hb_face_t *face_abc = hb_subset_test_open_font ("fonts/Inconsolata-Regular.abc.widerc.ttf");
hb_face_t *face_ab = hb_subset_test_open_font ("fonts/Inconsolata-Regular.ab.ttf");
hb_face_t *face_abc = hb_test_open_font_file ("fonts/Inconsolata-Regular.abc.widerc.ttf");
hb_face_t *face_ab = hb_test_open_font_file ("fonts/Inconsolata-Regular.ab.ttf");
hb_set_t *codepoints = hb_set_create ();
hb_face_t *face_abc_subset;
@ -133,7 +133,7 @@ test_subset_hmtx_decrease_num_metrics (void)
static void
test_subset_hmtx_noop (void)
{
hb_face_t *face_abc = hb_subset_test_open_font("fonts/Roboto-Regular.abc.ttf");
hb_face_t *face_abc = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
hb_set_t *codepoints = hb_set_create();
hb_face_t *face_abc_subset;
@ -153,7 +153,7 @@ test_subset_hmtx_noop (void)
static void
test_subset_invalid_hmtx (void)
{
hb_face_t *face = hb_subset_test_open_font("../fuzzing/fonts/crash-e4e0bb1458a91b692eba492c907ae1f94e635480");
hb_face_t *face = hb_test_open_font_file ("../fuzzing/fonts/crash-e4e0bb1458a91b692eba492c907ae1f94e635480");
hb_face_t *subset;
hb_subset_input_t *input = hb_subset_input_create_or_fail ();

View File

@ -31,8 +31,8 @@
static void
test_subset_os2 (void)
{
hb_face_t *face_abc = hb_subset_test_open_font("fonts/Roboto-Regular.abc.ttf");
hb_face_t *face_b = hb_subset_test_open_font("fonts/Roboto-Regular.b.ttf");
hb_face_t *face_abc = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
hb_face_t *face_b = hb_test_open_font_file ("fonts/Roboto-Regular.b.ttf");
hb_set_t *codepoints = hb_set_create();
hb_face_t *face_abc_subset;

View File

@ -32,8 +32,8 @@
static void
test_post_drops_glyph_names (void)
{
hb_face_t *face_full = hb_subset_test_open_font ("fonts/Mplus1p-Regular.660E,6975,73E0,5EA6,8F38,6E05.ttf");
hb_face_t *face_subset = hb_subset_test_open_font ("fonts/Mplus1p-Regular.660E.ttf");
hb_face_t *face_full = hb_test_open_font_file ("fonts/Mplus1p-Regular.660E,6975,73E0,5EA6,8F38,6E05.ttf");
hb_face_t *face_subset = hb_test_open_font_file ("fonts/Mplus1p-Regular.660E.ttf");
hb_face_t *face_full_subset;
hb_set_t *codepoints = hb_set_create ();

View File

@ -46,8 +46,8 @@ static void check_num_vmetrics(hb_face_t *face, uint16_t expected_num_vmetrics)
static void
test_subset_vmtx_simple_subset (void)
{
hb_face_t *face_full = hb_subset_test_open_font ("fonts/Mplus1p-Regular.660E,6975,73E0,5EA6,8F38,6E05.ttf");
hb_face_t *face_subset = hb_subset_test_open_font ("fonts/Mplus1p-Regular.660E.ttf");
hb_face_t *face_full = hb_test_open_font_file ("fonts/Mplus1p-Regular.660E,6975,73E0,5EA6,8F38,6E05.ttf");
hb_face_t *face_subset = hb_test_open_font_file ("fonts/Mplus1p-Regular.660E.ttf");
hb_face_t *face_full_subset;
hb_set_t *codepoints = hb_set_create ();
@ -67,7 +67,7 @@ test_subset_vmtx_simple_subset (void)
static void
test_subset_vmtx_noop (void)
{
hb_face_t *face_full = hb_subset_test_open_font ("fonts/Mplus1p-Regular.660E,6975,73E0,5EA6,8F38,6E05.ttf");
hb_face_t *face_full = hb_test_open_font_file ("fonts/Mplus1p-Regular.660E,6975,73E0,5EA6,8F38,6E05.ttf");
hb_face_t *face_full_subset;
hb_set_t *codepoints = hb_set_create();

View File

@ -32,7 +32,7 @@
static void
test_subset_32_tables (void)
{
hb_face_t *face = hb_subset_test_open_font("../fuzzing/fonts/oom-6ef8c96d3710262511bcc730dce9c00e722cb653");
hb_face_t *face = hb_test_open_font_file ("../fuzzing/fonts/oom-6ef8c96d3710262511bcc730dce9c00e722cb653");
hb_subset_input_t *input = hb_subset_input_create_or_fail ();
hb_set_t *codepoints = hb_subset_input_unicode_set (input);
@ -54,7 +54,7 @@ test_subset_32_tables (void)
static void
test_subset_no_inf_loop (void)
{
hb_face_t *face = hb_subset_test_open_font("../fuzzing/fonts/clusterfuzz-testcase-minimized-hb-subset-fuzzer-5521982557782016");
hb_face_t *face = hb_test_open_font_file ("../fuzzing/fonts/clusterfuzz-testcase-minimized-hb-subset-fuzzer-5521982557782016");
hb_subset_input_t *input = hb_subset_input_create_or_fail ();
hb_set_t *codepoints = hb_subset_input_unicode_set (input);
@ -76,7 +76,7 @@ test_subset_no_inf_loop (void)
static void
test_subset_crash (void)
{
hb_face_t *face = hb_subset_test_open_font("../fuzzing/fonts/crash-4b60576767ee4d9fe1cc10959d89baf73d4e8249");
hb_face_t *face = hb_test_open_font_file ("../fuzzing/fonts/crash-4b60576767ee4d9fe1cc10959d89baf73d4e8249");
hb_subset_input_t *input = hb_subset_input_create_or_fail ();
hb_set_t *codepoints = hb_subset_input_unicode_set (input);