diff options
author | Benjamin Otte <otte@redhat.com> | 2015-02-21 00:03:49 +0100 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2015-02-25 01:55:28 +0100 |
commit | 40f2af665d59f2732ac587734b4958682d5f7c7d (patch) | |
tree | 592f1e3801906df01f8db9c0cac71329fc64fcbf /testsuite | |
parent | 0ab48fcc4227ab112835f8fc1b922cfb21a7927f (diff) | |
download | gtk+-40f2af665d59f2732ac587734b4958682d5f7c7d.tar.gz |
gdkcairo: Bail if surface is in error
Don't try to paint onto an error surface. This happens for example when
gdk_cairo_set_source_pixbuf() is called with a pixbuf that is too big
for Cairo to handle.
Spotted by Christian Boxdörfer
Diffstat (limited to 'testsuite')
-rw-r--r-- | testsuite/gdk/Makefile.am | 5 | ||||
-rw-r--r-- | testsuite/gdk/cairo.c | 40 |
2 files changed, 43 insertions, 2 deletions
diff --git a/testsuite/gdk/Makefile.am b/testsuite/gdk/Makefile.am index 5b0d30f086..32b018a0c3 100644 --- a/testsuite/gdk/Makefile.am +++ b/testsuite/gdk/Makefile.am @@ -18,10 +18,11 @@ LDADD = \ #TEST_PROGS += check-gdk-cairo TEST_PROGS += \ - rgba \ - encoding \ + cairo \ display \ + encoding \ keysyms \ + rgba \ $(NULL) CLEANFILES = \ diff --git a/testsuite/gdk/cairo.c b/testsuite/gdk/cairo.c new file mode 100644 index 0000000000..77be879c97 --- /dev/null +++ b/testsuite/gdk/cairo.c @@ -0,0 +1,40 @@ +#include <gdk/gdk.h> + +static void +test_set_source_big_pixbuf (void) +{ + cairo_surface_t *surface; + GdkPixbuf *pixbuf; + cairo_t *cr; + +#define WAY_TOO_BIG 65540 + + /* Check that too big really is to big. + * If this check fails, somebody improved Cairo and this test is useless. + */ + surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, WAY_TOO_BIG, 1); + g_assert_cmpint (cairo_surface_status (surface), !=, CAIRO_STATUS_SUCCESS); + cairo_surface_destroy (surface); + + surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 10, 10); + cr = cairo_create (surface); + pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, WAY_TOO_BIG, 1); + + gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0); + g_assert_cmpint (cairo_status (cr), !=, CAIRO_STATUS_SUCCESS); + + g_object_unref (pixbuf); + cairo_destroy (cr); + cairo_surface_destroy (surface); +} + +int +main (int argc, char *argv[]) +{ + g_test_init (&argc, &argv, NULL); + gdk_init (&argc, &argv); + + g_test_add_func ("/drawing/set-source-big-pixbuf", test_set_source_big_pixbuf); + + return g_test_run (); +} |