From 00997204f7df5f4e2f75f8c1c2f72130f302e7c6 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 3 Jan 2013 03:51:10 -0600 Subject: Add test-pangocairo-threads.c Currently is not run automatically. But run it with args "10 100" and see it crash... --- tests/Makefile.am | 3 +- tests/test-pangocairo-threads.c | 74 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 tests/test-pangocairo-threads.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 8531f0ea..56a741ae 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -40,7 +40,7 @@ TESTS_ENVIRONMENT = \ srcdir=$(srcdir) \ PANGO_RC_FILE=./pangorc -check_PROGRAMS = testboundaries testboundaries_ucd testcolor testscript +check_PROGRAMS = testboundaries testboundaries_ucd testcolor testscript test-pangocairo-threads if HAVE_CAIRO check_PROGRAMS += testiter @@ -60,6 +60,7 @@ testcolor_LDADD = $(TEST_PANGO_LIBS) $(GLIB_LIBS) testiter_LDADD = $(TEST_PANGOCAIRO_LIBS) $(GLIB_LIBS) testscript_LDADD = $(TEST_PANGO_LIBS) $(GLIB_LIBS) test_ot_tags_LDADD = $(TEST_PANGOFT2_LIBS) $(GLIB_LIBS) +test_pangocairo_threads_LDADD = $(TEST_PANGOCAIRO_LIBS) $(CAIRO_LIBS) $(GLIB_LIBS) dump_boundaries_LDADD = $(TEST_PANGO_LIBS) $(GLIB_LIBS) if HAVE_CXX diff --git a/tests/test-pangocairo-threads.c b/tests/test-pangocairo-threads.c new file mode 100644 index 00000000..29c6aa57 --- /dev/null +++ b/tests/test-pangocairo-threads.c @@ -0,0 +1,74 @@ +#include +#include +#include + +const char *text = "The quick brown fox jumped over the lazy dog!"; +int num_iters = 100; + +static gpointer +thread_func (gpointer data) +{ + int num = GPOINTER_TO_INT (data); + int i; + char *filename; + + cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 500, 300); + cairo_t *cr = cairo_create (surface); + PangoLayout *layout = pango_cairo_create_layout (cr); + + cairo_set_source_rgb (cr, 1, 1, 1); + cairo_paint (cr); + cairo_set_source_rgb (cr, 0, 0, 0); + + pango_layout_set_text (layout, text, -1); + pango_layout_set_width (layout, 500 * PANGO_SCALE); + + for (i = 0; i < num_iters; i++) + { + /* force a relayout */ + PangoWrapMode wrap = pango_layout_get_wrap (layout); + wrap = wrap == PANGO_WRAP_WORD ? PANGO_WRAP_CHAR : PANGO_WRAP_WORD; + pango_layout_set_wrap (layout, wrap); + + pango_cairo_show_layout (cr, layout); + } + + filename = g_strdup_printf ("%d.png", num); + cairo_surface_write_to_png (surface, filename); + g_free (filename); + + return 0; +} + +static void +join_thread (gpointer thread, gpointer self) +{ + if (thread != self) + g_thread_join (thread); +} + + +int +main (int argc, char **argv) +{ + int num_threads = 2; + int i; + + if (argc > 1) + num_threads = atoi (argv[1]); + if (argc > 2) + num_iters = atoi (argv[2]); + + g_type_init (); + g_thread_init (NULL); + + /* force pango module initializations */ +/* thread_func (GINT_TO_POINTER (0)); */ + + for (i = 0; i < num_threads; i++) + g_thread_create (thread_func, GINT_TO_POINTER (i+1), TRUE, NULL); + + g_thread_foreach (join_thread, g_thread_self ()); + + return 0; +} -- cgit v1.2.1