summaryrefslogtreecommitdiff
path: root/test/font-options.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2008-02-11 14:58:21 +0000
committerChris Wilson <chris@chris-wilson.co.uk>2008-02-15 13:50:42 +0000
commitad265cc9f26a20f2336747d69b28bc6ca0d91f4b (patch)
tree879b767e5d236214405704c56760acea25c5fa5d /test/font-options.c
parent790eaef71cbd30e1994c9499ab553f2ef5e5d620 (diff)
downloadcairo-ad265cc9f26a20f2336747d69b28bc6ca0d91f4b.tar.gz
[cairo-font-options] Disallow use of NULL font-options.
Partial revert of commit 0086db893cba90dc73824d77c661d2965ad48112. This is a follow to the earlier commit that allowed creation of scaled fonts using a NULL font options (by interpreting the NULL as meaning use the default options) to reflect the comments made by Behdad (http://lists.cairographics.org/archives/cairo/2008-January/012714.html). The intent is that the public font options getter/setter API has similar defensive behaviour to that of the core objects - i.e. do not overwrite the nil object and if the object is in error then return the default value. For the indirect use of a NULL/nil font options (e.g. creation of scaled fonts), then an error should be returned rather than crashing.
Diffstat (limited to 'test/font-options.c')
-rw-r--r--test/font-options.c51
1 files changed, 29 insertions, 22 deletions
diff --git a/test/font-options.c b/test/font-options.c
index aab4045ef..50c1fb812 100644
--- a/test/font-options.c
+++ b/test/font-options.c
@@ -38,48 +38,53 @@
int
main (void)
{
- cairo_font_options_t *options1;
- cairo_font_options_t *options2;
+ cairo_font_options_t *default_options;
+ cairo_font_options_t *nil_options;
cairo_surface_t *surface;
cairo_matrix_t identity;
cairo_t *cr;
cairo_scaled_font_t *scaled_font;
/* first check NULL handling of cairo_font_options_t */
- options1 = cairo_font_options_create ();
- options2 = cairo_font_options_copy (NULL);
-
- assert (cairo_font_options_equal (options1, options2));
- assert (cairo_font_options_equal (NULL, options2));
- assert (cairo_font_options_equal (options1, NULL));
-
- assert (cairo_font_options_hash (options1) == cairo_font_options_hash (options2));
- assert (cairo_font_options_hash (NULL) == cairo_font_options_hash (options2));
- assert (cairo_font_options_hash (options1) == cairo_font_options_hash (NULL));
+ default_options = cairo_font_options_create ();
+ assert (cairo_font_options_status (default_options) == CAIRO_STATUS_SUCCESS);
+ nil_options = cairo_font_options_copy (NULL);
+ assert (cairo_font_options_status (nil_options) == CAIRO_STATUS_NO_MEMORY);
+
+ assert (cairo_font_options_equal (default_options, default_options));
+ assert (! cairo_font_options_equal (default_options, nil_options));
+ assert (! cairo_font_options_equal (NULL, nil_options));
+ assert (! cairo_font_options_equal (nil_options, nil_options));
+ assert (! cairo_font_options_equal (default_options, NULL));
+ assert (! cairo_font_options_equal (NULL, default_options));
+
+ assert (cairo_font_options_hash (default_options) == cairo_font_options_hash (nil_options));
+ assert (cairo_font_options_hash (NULL) == cairo_font_options_hash (nil_options));
+ assert (cairo_font_options_hash (default_options) == cairo_font_options_hash (NULL));
cairo_font_options_merge (NULL, NULL);
- cairo_font_options_merge (options1, NULL);
- cairo_font_options_merge (options1, options2);
+ cairo_font_options_merge (default_options, NULL);
+ cairo_font_options_merge (default_options, nil_options);
cairo_font_options_set_antialias (NULL, CAIRO_ANTIALIAS_DEFAULT);
cairo_font_options_get_antialias (NULL);
- assert (cairo_font_options_get_antialias (options1) == CAIRO_ANTIALIAS_DEFAULT);
+ assert (cairo_font_options_get_antialias (default_options) == CAIRO_ANTIALIAS_DEFAULT);
cairo_font_options_set_subpixel_order (NULL, CAIRO_SUBPIXEL_ORDER_DEFAULT);
cairo_font_options_get_subpixel_order (NULL);
- assert (cairo_font_options_get_subpixel_order (options1) == CAIRO_SUBPIXEL_ORDER_DEFAULT);
+ assert (cairo_font_options_get_subpixel_order (default_options) == CAIRO_SUBPIXEL_ORDER_DEFAULT);
cairo_font_options_set_hint_style (NULL, CAIRO_HINT_STYLE_DEFAULT);
cairo_font_options_get_hint_style (NULL);
- assert (cairo_font_options_get_hint_style (options1) == CAIRO_HINT_STYLE_DEFAULT);
+ assert (cairo_font_options_get_hint_style (default_options) == CAIRO_HINT_STYLE_DEFAULT);
cairo_font_options_set_hint_metrics (NULL, CAIRO_HINT_METRICS_DEFAULT);
cairo_font_options_get_hint_metrics (NULL);
- assert (cairo_font_options_get_hint_metrics (options1) == CAIRO_HINT_METRICS_DEFAULT);
+ assert (cairo_font_options_get_hint_metrics (default_options) == CAIRO_HINT_METRICS_DEFAULT);
cairo_font_options_destroy (NULL);
- cairo_font_options_destroy (options1);
- cairo_font_options_destroy (options2);
+ cairo_font_options_destroy (default_options);
+ cairo_font_options_destroy (nil_options);
/* Now try creating fonts with NULLs */
@@ -91,12 +96,14 @@ main (void)
scaled_font = cairo_scaled_font_create (cairo_get_font_face (cr),
&identity, &identity,
NULL);
- assert (cairo_scaled_font_status (scaled_font) == CAIRO_STATUS_SUCCESS);
+ assert (cairo_scaled_font_status (scaled_font) == CAIRO_STATUS_NO_MEMORY); /* XXX */
cairo_scaled_font_get_font_options (scaled_font, NULL);
cairo_scaled_font_destroy (scaled_font);
- cairo_set_font_options (cr, NULL);
+ assert (cairo_status (cr) == CAIRO_STATUS_SUCCESS);
cairo_get_font_options (cr, NULL);
+ cairo_set_font_options (cr, NULL);
+ assert (cairo_status (cr) == CAIRO_STATUS_NULL_POINTER);
cairo_destroy (cr);