[test] Use an in-repo font for test-multithread (#1218)
As Khaled's suggestion, hard-coded font paths was only for my own testing.
This commit is contained in:
parent
fde9b8852d
commit
4146c00caa
|
@ -51,13 +51,18 @@ static inline hb_face_t *
|
||||||
hb_subset_test_open_font (const char *font_path)
|
hb_subset_test_open_font (const char *font_path)
|
||||||
{
|
{
|
||||||
#if GLIB_CHECK_VERSION(2,37,2)
|
#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
|
#else
|
||||||
char* path = g_strdup (font_path);
|
char *path = g_strdup (font_path);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
hb_blob_t* blob = hb_blob_create_from_file (path);
|
hb_blob_t *blob = hb_blob_create_from_file (path);
|
||||||
hb_face_t* face = hb_face_create (blob, 0);
|
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);
|
hb_blob_destroy (blob);
|
||||||
|
|
||||||
g_free (path);
|
g_free (path);
|
||||||
|
|
|
@ -32,18 +32,10 @@
|
||||||
#include <hb.h>
|
#include <hb.h>
|
||||||
#include <hb-ft.h>
|
#include <hb-ft.h>
|
||||||
#include <hb-ot.h>
|
#include <hb-ot.h>
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
static const char *text = "طرحنَما";
|
static char *font_path = "fonts/Inconsolata-Regular.abc.ttf";
|
||||||
static const char *path =
|
static char *text = "abc";
|
||||||
#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 int num_threads = 30;
|
static int num_threads = 30;
|
||||||
static int num_iters = 200;
|
static int num_iters = 200;
|
||||||
|
@ -56,7 +48,7 @@ static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
static void
|
static void
|
||||||
fill_the_buffer (hb_buffer_t *buffer)
|
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_buffer_guess_segment_properties (buffer);
|
||||||
hb_shape (font, buffer, NULL, 0);
|
hb_shape (font, buffer, NULL, 0);
|
||||||
}
|
}
|
||||||
|
@ -135,16 +127,33 @@ test_body (void)
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
if (argc > 1)
|
g_test_init (&argc, &argv, NULL);
|
||||||
num_threads = atoi (argv[1]);
|
|
||||||
|
#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)
|
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
|
// Dummy call to alleviate _guess_segment_properties thread safety-ness
|
||||||
// https://github.com/harfbuzz/harfbuzz/issues/1191
|
// https://github.com/harfbuzz/harfbuzz/issues/1191
|
||||||
hb_language_get_default ();
|
hb_language_get_default ();
|
||||||
|
|
||||||
hb_blob_t *blob = hb_blob_create_from_file (path);
|
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);
|
hb_face_t *face = hb_face_create (blob, 0);
|
||||||
font = hb_font_create (face);
|
font = hb_font_create (face);
|
||||||
|
|
||||||
|
@ -167,5 +176,7 @@ main (int argc, char **argv)
|
||||||
hb_face_destroy (face);
|
hb_face_destroy (face);
|
||||||
hb_blob_destroy (blob);
|
hb_blob_destroy (blob);
|
||||||
|
|
||||||
|
g_free (default_path);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,18 @@
|
||||||
#include "hb-fuzzer.hh"
|
#include "hb-fuzzer.hh"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
hb_blob_t *blob = hb_blob_create_from_file (argv[1]);
|
hb_blob_t *blob = hb_blob_create_from_file (argv[1]);
|
||||||
unsigned int len;
|
unsigned int len;
|
||||||
const char *font_data = hb_blob_get_data (blob, &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++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
printf ("%s\n", argv[i]);
|
printf ("%s\n", argv[i]);
|
||||||
|
|
Loading…
Reference in New Issue