summaryrefslogtreecommitdiff
path: root/test/invalid-matrix.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2008-02-11 17:00:30 +0000
committerChris Wilson <chris@chris-wilson.co.uk>2008-02-15 13:50:43 +0000
commit92970ec83687435e75e60110cb7434670515ae57 (patch)
treecb914aea109a58e95bbf9fa475c22cef5666d952 /test/invalid-matrix.c
parent012f68e043d3594fa6cb5235eafb1ca1bfe2d099 (diff)
downloadcairo-92970ec83687435e75e60110cb7434670515ae57.tar.gz
[test/invalid-matrix] Test detection of infinities.
Feed infinities into the API and check that we correctly return INVALID_MATRIX.
Diffstat (limited to 'test/invalid-matrix.c')
-rw-r--r--test/invalid-matrix.c123
1 files changed, 122 insertions, 1 deletions
diff --git a/test/invalid-matrix.c b/test/invalid-matrix.c
index 08a81fef7..5d3bcbc98 100644
--- a/test/invalid-matrix.c
+++ b/test/invalid-matrix.c
@@ -26,6 +26,10 @@
#include "cairo-test.h"
+#if _XOPEN_SOURCE >= 600 || _ISOC99_SOURCE
+#define HAVE_INFINITY 1
+#endif
+
static cairo_test_draw_function_t draw;
cairo_test_t test = {
@@ -45,7 +49,7 @@ draw (cairo_t *cr, int width, int height)
cairo_scaled_font_t *scaled_font;
cairo_pattern_t *pattern;
cairo_t *cr2;
- cairo_matrix_t identity, bogus, invalid = {
+ cairo_matrix_t identity, bogus, inf, invalid = {
4.0, 4.0,
4.0, 4.0,
4.0, 4.0
@@ -71,6 +75,13 @@ if ((status) == CAIRO_STATUS_SUCCESS) { \
status = cairo_matrix_invert (&bogus);
CHECK_STATUS (status, "cairo_matrix_invert(NaN)");
+#if HAVE_INFINITY
+ inf.x0 = inf.xy = inf.xx = INFINITY;
+ inf.y0 = inf.yx = inf.yy = inf.xx;
+ status = cairo_matrix_invert (&inf);
+ CHECK_STATUS (status, "cairo_matrix_invert(infinity)");
+#endif
+
/* test cairo_matrix_invert with invalid matrix */
status = cairo_matrix_invert (&invalid);
CHECK_STATUS (status, "cairo_matrix_invert(invalid)");
@@ -96,6 +107,16 @@ if ((status) == CAIRO_STATUS_SUCCESS) { \
cairo_destroy (cr2);
CHECK_STATUS (status, "cairo_transform(NaN)");
+#if HAVE_INFINITY
+ /* test cairo_transform with ∞ matrix */
+ cr2 = cairo_create (target);
+ cairo_transform (cr2, &inf);
+
+ status = cairo_status (cr2);
+ cairo_destroy (cr2);
+ CHECK_STATUS (status, "cairo_transform(infinity)");
+#endif
+
/* test cairo_set_matrix with invalid matrix */
cr2 = cairo_create (target);
@@ -113,6 +134,16 @@ if ((status) == CAIRO_STATUS_SUCCESS) { \
cairo_destroy (cr2);
CHECK_STATUS (status, "cairo_set_matrix(NaN)");
+#if HAVE_INFINITY
+ /* test cairo_set_matrix with ∞ matrix */
+ cr2 = cairo_create (target);
+ cairo_set_matrix (cr2, &inf);
+
+ status = cairo_status (cr2);
+ cairo_destroy (cr2);
+ CHECK_STATUS (status, "cairo_set_matrix(infinity)");
+#endif
+
/* test cairo_set_font_matrix with invalid matrix */
cr2 = cairo_create (target);
@@ -136,6 +167,19 @@ if ((status) == CAIRO_STATUS_SUCCESS) { \
cairo_destroy (cr2);
CHECK_STATUS (status, "cairo_set_font_matrix(NaN)");
+#if HAVE_INFINITY
+ /* test cairo_set_font_matrix with ∞ matrix */
+ cr2 = cairo_create (target);
+ cairo_set_font_matrix (cr2, &inf);
+
+ /* draw some text to force the font to be resolved */
+ cairo_show_text (cr2, "hello");
+
+ status = cairo_status (cr2);
+ cairo_destroy (cr2);
+ CHECK_STATUS (status, "cairo_set_font_matrix(infinity)");
+#endif
+
/* test cairo_scaled_font_create with invalid matrix */
cr2 = cairo_create (target);
@@ -187,6 +231,33 @@ if ((status) == CAIRO_STATUS_SUCCESS) { \
cairo_font_options_destroy (font_options);
cairo_destroy (cr2);
+#if HAVE_INFINITY
+ /* test cairo_scaled_font_create with ∞ matrix */
+ cr2 = cairo_create (target);
+ font_face = cairo_get_font_face (cr2);
+ font_options = cairo_font_options_create ();
+ cairo_get_font_options (cr, font_options);
+ scaled_font = cairo_scaled_font_create (font_face,
+ &inf,
+ &identity,
+ font_options);
+ status = cairo_scaled_font_status (scaled_font);
+ CHECK_STATUS (status, "cairo_scaled_font_create(infinity)");
+
+ cairo_scaled_font_destroy (scaled_font);
+
+ scaled_font = cairo_scaled_font_create (font_face,
+ &identity,
+ &inf,
+ font_options);
+ status = cairo_scaled_font_status (scaled_font);
+ CHECK_STATUS (status, "cairo_scaled_font_create(infinity)");
+
+ cairo_scaled_font_destroy (scaled_font);
+ cairo_font_options_destroy (font_options);
+ cairo_destroy (cr2);
+#endif
+
/* test cairo_pattern_set_matrix with invalid matrix */
pattern = cairo_pattern_create_rgb (1.0, 1.0, 1.0);
@@ -202,6 +273,15 @@ if ((status) == CAIRO_STATUS_SUCCESS) { \
CHECK_STATUS (status, "cairo_pattern_set_matrix(NaN)");
cairo_pattern_destroy (pattern);
+#if HAVE_INFINITY
+ /* test cairo_pattern_set_matrix with ∞ matrix */
+ pattern = cairo_pattern_create_rgb (1.0, 1.0, 1.0);
+ cairo_pattern_set_matrix (pattern, &inf);
+ status = cairo_pattern_status (pattern);
+ CHECK_STATUS (status, "cairo_pattern_set_matrix(infinity)");
+ cairo_pattern_destroy (pattern);
+#endif
+
/* test invalid transformations */
cr2 = cairo_create (target);
@@ -219,6 +299,23 @@ if ((status) == CAIRO_STATUS_SUCCESS) { \
CHECK_STATUS (status, "cairo_translate(NaN, 0)");
cairo_destroy (cr2);
+#if HAVE_INFINITY
+ cr2 = cairo_create (target);
+ cairo_translate (cr2, inf.xx, inf.yy);
+ CHECK_STATUS (status, "cairo_translate(∞, ∞)");
+ cairo_destroy (cr2);
+
+ cr2 = cairo_create (target);
+ cairo_translate (cr2, 0, inf.yy);
+ CHECK_STATUS (status, "cairo_translate(0, ∞)");
+ cairo_destroy (cr2);
+
+ cr2 = cairo_create (target);
+ cairo_translate (cr2, inf.xx, 0);
+ CHECK_STATUS (status, "cairo_translate(∞, 0)");
+ cairo_destroy (cr2);
+#endif
+
cr2 = cairo_create (target);
cairo_scale (cr2, bogus.xx, bogus.yy);
@@ -235,6 +332,23 @@ if ((status) == CAIRO_STATUS_SUCCESS) { \
CHECK_STATUS (status, "cairo_scale(NaN, 1)");
cairo_destroy (cr2);
+#if HAVE_INFINITY
+ cr2 = cairo_create (target);
+ cairo_scale (cr2, inf.xx, inf.yy);
+ CHECK_STATUS (status, "cairo_scale(∞, ∞)");
+ cairo_destroy (cr2);
+
+ cr2 = cairo_create (target);
+ cairo_scale (cr2, 1, inf.yy);
+ CHECK_STATUS (status, "cairo_scale(1, ∞)");
+ cairo_destroy (cr2);
+
+ cr2 = cairo_create (target);
+ cairo_scale (cr2, inf.xx, 1);
+ CHECK_STATUS (status, "cairo_scale(∞, 1)");
+ cairo_destroy (cr2);
+#endif
+
cr2 = cairo_create (target);
cairo_scale (cr2, bogus.xx, bogus.yy);
CHECK_STATUS (status, "cairo_scale(0, 0)");
@@ -256,6 +370,13 @@ if ((status) == CAIRO_STATUS_SUCCESS) { \
CHECK_STATUS (status, "cairo_rotate(NaN)");
cairo_destroy (cr2);
+#if HAVE_INFINITY
+ cr2 = cairo_create (target);
+ cairo_rotate (cr2, inf.xx);
+ CHECK_STATUS (status, "cairo_rotate(∞)");
+ cairo_destroy (cr2);
+#endif
+
return CAIRO_TEST_SUCCESS;
}