From 4146c00caa29e53ee9a29def151f12792ac76596 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Wed, 3 Oct 2018 21:26:58 +0330 Subject: [PATCH] [test] Use an in-repo font for test-multithread (#1218) As Khaled's suggestion, hard-coded font paths was only for my own testing. --- test/api/hb-subset-test.h | 13 ++++++++---- test/api/test-multithread.c | 41 +++++++++++++++++++++++-------------- test/fuzzing/main.cc | 6 ++++++ 3 files changed, 41 insertions(+), 19 deletions(-) diff --git a/test/api/hb-subset-test.h b/test/api/hb-subset-test.h index 0318fa7bb..8f32d3dba 100644 --- a/test/api/hb-subset-test.h +++ b/test/api/hb-subset-test.h @@ -51,13 +51,18 @@ 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); + char *path = g_test_build_filename (G_TEST_DIST, font_path, NULL); #else - char* path = g_strdup (font_path); + char *path = g_strdup (font_path); #endif - hb_blob_t* blob = hb_blob_create_from_file (path); - hb_face_t* face = hb_face_create (blob, 0); + hb_blob_t *blob = hb_blob_create_from_file (path); + if (hb_blob_get_length (blob) == 0) + { + printf ("The test font is not found."); + exit (1); + } + hb_face_t *face = hb_face_create (blob, 0); hb_blob_destroy (blob); g_free (path); diff --git a/test/api/test-multithread.c b/test/api/test-multithread.c index 508dd3965..72a1a178c 100644 --- a/test/api/test-multithread.c +++ b/test/api/test-multithread.c @@ -32,18 +32,10 @@ #include #include #include +#include -static const char *text = "طرح‌نَما"; -static const char *path = -#if defined(__linux__) - "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"; -#elif defined(__FreeBSD__) - "/usr/local/share/fonts/dejavu/DejaVuSans.ttf"; -#elif defined(_WIN32) || defined(_WIN64) - "C:\\Windows\\Fonts\\tahoma.ttf"; -#elif __APPLE__ - "/Library/Fonts/Tahoma.ttf"; -#endif +static char *font_path = "fonts/Inconsolata-Regular.abc.ttf"; +static char *text = "abc"; static int num_threads = 30; static int num_iters = 200; @@ -56,7 +48,7 @@ static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static void fill_the_buffer (hb_buffer_t *buffer) { - hb_buffer_add_utf8 (buffer, text, sizeof (text), 0, sizeof (text)); + hb_buffer_add_utf8 (buffer, text, -1, 0, -1); hb_buffer_guess_segment_properties (buffer); hb_shape (font, buffer, NULL, 0); } @@ -135,16 +127,33 @@ test_body (void) int main (int argc, char **argv) { - if (argc > 1) - num_threads = atoi (argv[1]); + 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 + + char *path = argc > 1 ? argv[1] : (char *) default_path; if (argc > 2) - num_iters = atoi (argv[2]); + num_threads = atoi (argv[2]); + if (argc > 3) + num_iters = atoi (argv[3]); + if (argc > 4) + text = argv[4]; // Dummy call to alleviate _guess_segment_properties thread safety-ness // 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) + { + printf ("The test font is not found."); + return 1; + } + hb_face_t *face = hb_face_create (blob, 0); font = hb_font_create (face); @@ -167,5 +176,7 @@ main (int argc, char **argv) hb_face_destroy (face); hb_blob_destroy (blob); + g_free (default_path); + return 0; } diff --git a/test/fuzzing/main.cc b/test/fuzzing/main.cc index 3ff8803ee..b42d60c13 100644 --- a/test/fuzzing/main.cc +++ b/test/fuzzing/main.cc @@ -1,12 +1,18 @@ #include "hb-fuzzer.hh" #include +#include #include int main(int argc, char **argv) { hb_blob_t *blob = hb_blob_create_from_file (argv[1]); unsigned int len; const char *font_data = hb_blob_get_data (blob, &len); + if (len == 0) + { + printf ("The test font is not found."); + exit (1); + } for (int i = 1; i < argc; i++) { printf ("%s\n", argv[i]);