summaryrefslogtreecommitdiff
path: root/test/pthread-show-text.c
diff options
context:
space:
mode:
authorCarl Worth <cworth@cworth.org>2005-09-13 12:11:32 +0000
committerCarl Worth <cworth@cworth.org>2005-09-13 12:11:32 +0000
commit258f6f4903eb91187384c2df7591413d9041f184 (patch)
treec53d17a13c2d363752e8f158cc2dc5a1fa69209a /test/pthread-show-text.c
parent999c2a8a2b27412ac2fb59041837c780e6d7eec3 (diff)
downloadcairo-258f6f4903eb91187384c2df7591413d9041f184.tar.gz
Add documentation for cairo_test functions.
Abstract log fie creation into cairo_test_init for use by tests that don't use cairo_test(). Add new test for bug #4299 as reported by Alexey Shabalin.
Diffstat (limited to 'test/pthread-show-text.c')
-rw-r--r--test/pthread-show-text.c110
1 files changed, 110 insertions, 0 deletions
diff --git a/test/pthread-show-text.c b/test/pthread-show-text.c
new file mode 100644
index 000000000..b0e37ff71
--- /dev/null
+++ b/test/pthread-show-text.c
@@ -0,0 +1,110 @@
+/*
+ * Copyright © 2005 Red Hat, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Red Hat, Inc. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Red Hat, Inc. makes no representations about the
+ * suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+ * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Carl D. Worth <cworth@cworth.org>
+ */
+
+/* Test case for bug #4299:
+
+ Assertion fails in "cairo-font.c" when using multithreads
+ https://bugs.freedesktop.org/show_bug.cgi?id=4299
+*/
+
+#include "cairo-test.h"
+#include "xmalloc.h"
+
+#include <string.h>
+#include <stdlib.h>
+#include <pthread.h>
+#if HAVE_FCFINI
+#include <fontconfig/fontconfig.h>
+#endif
+
+static void *
+start (void *closure)
+{
+ cairo_surface_t *surface;
+ cairo_t *cr;
+ int i;
+
+ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 100, 100);
+ cr = cairo_create (surface);
+
+ cairo_save (cr);
+ {
+ cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
+ cairo_paint (cr);
+ }
+ cairo_restore (cr);
+
+ cairo_move_to (cr, 10, 10);
+
+ for (i=0; i < 3; i++) {
+ cairo_set_font_size (cr, 8 + i % 3);
+ cairo_show_text (cr, "Hello world.\n");
+ }
+
+ cairo_destroy (cr);
+ cairo_surface_destroy (surface);
+
+ return NULL;
+}
+
+int
+main (int argc, char *argv[0])
+{
+ int err;
+ int i, num_threads;
+ pthread_t *pthread;
+
+ if (argc > 1) {
+ num_threads = atoi (argv[1]);
+ } else {
+ num_threads = 10;
+ }
+
+ cairo_test_init ("pthread-show-text");
+
+ cairo_test_log ("Running with %d threads.\n", num_threads);
+
+ pthread = xmalloc (num_threads * sizeof (pthread_t));
+
+ for (i = 0; i < num_threads; i++) {
+ err = pthread_create (&pthread[i], NULL, start, NULL);
+ if (err) {
+ cairo_test_log ("pthread_create failed: %s\n", strerror(err));
+ return CAIRO_TEST_FAILURE;
+ }
+ }
+
+ for (i = 0; i < num_threads; i++)
+ pthread_join (pthread[i], NULL);
+
+ free (pthread);
+
+ cairo_debug_reset_static_data ();
+#if HAVE_FCFINI
+ FcFini ();
+#endif
+
+ return CAIRO_TEST_SUCCESS;
+}