Fix for bug #3915:

Add new NULL_POINTER nil pattern.
Check for surface == NULL and return a nil pattern.
Verify that the above fix works.
This commit is contained in:
Carl Worth 2005-08-19 07:39:47 +00:00
parent 435fb3c65f
commit b626dff5b9
3 changed files with 64 additions and 2 deletions

View file

@ -1,3 +1,15 @@
2005-08-19 Carl Worth <cworth@cworth.org>
Fix for bug #3915:
* src/cairo-pattern.c: (_cairo_pattern_nil_for_status): Add new
NULL_POINTER nil pattern.
* src/cairo-pattern.c: (cairo_pattern_create_for_surface): Check
for surface == NULL and return a nil pattern.
* test/nil-surface.c: (draw): Verify that the above fix works.
2005-08-18 Carl Worth <cworth@cworth.org>
Fix for bug #4088:

View file

@ -59,6 +59,15 @@ const cairo_solid_pattern_t cairo_pattern_nil = {
CAIRO_EXTEND_DEFAULT }, /* extend */
};
const cairo_solid_pattern_t cairo_pattern_nil_null_pointer = {
{ CAIRO_PATTERN_SOLID, /* type */
(unsigned int)-1, /* ref_count */
CAIRO_STATUS_NULL_POINTER,/* status */
{ 1., 0., 0., 1., 0., 0., }, /* matrix */
CAIRO_FILTER_DEFAULT, /* filter */
CAIRO_EXTEND_DEFAULT }, /* extend */
};
const cairo_solid_pattern_t cairo_pattern_nil_file_not_found = {
{ CAIRO_PATTERN_SOLID, /* type */
(unsigned int)-1, /* ref_count */
@ -81,6 +90,8 @@ static const cairo_pattern_t *
_cairo_pattern_nil_for_status (cairo_status_t status)
{
switch (status) {
case CAIRO_STATUS_NULL_POINTER:
return &cairo_pattern_nil_null_pointer.base;
case CAIRO_STATUS_FILE_NOT_FOUND:
return &cairo_pattern_nil_file_not_found.base;
case CAIRO_STATUS_READ_ERROR:
@ -394,6 +405,9 @@ cairo_pattern_create_for_surface (cairo_surface_t *surface)
{
cairo_surface_pattern_t *pattern;
if (surface == NULL)
return (cairo_pattern_t*) _cairo_pattern_nil_for_status (CAIRO_STATUS_NULL_POINTER);
if (surface->status)
return (cairo_pattern_t*) _cairo_pattern_nil_for_status (surface->status);

View file

@ -26,7 +26,11 @@
#include "cairo-test.h"
#include <cairo-ft.h>
/* Test case for: https://bugs.freedesktop.org/show_bug.cgi?id=4088 */
/* Test to verify fixes for the following similar bugs:
*
* https://bugs.freedesktop.org/show_bug.cgi?id=4088
* https://bugs.freedesktop.org/show_bug.cgi?id=3915
*/
cairo_test_t test = {
"nil-surface",
@ -41,6 +45,10 @@ draw (cairo_t *cr, int width, int height)
cairo_pattern_t *pattern;
cairo_t *cr2;
/*
* 1. Test file-not-found from surface->pattern->cairo_t
*/
/* Make a custom context to not interfere with the one passed in. */
cr2 = cairo_create (cairo_get_target (cr));
@ -58,8 +66,36 @@ draw (cairo_t *cr, int width, int height)
cairo_surface_destroy (surface);
/* Check that the error made it all that way. */
if (cairo_status (cr2) != CAIRO_STATUS_FILE_NOT_FOUND)
if (cairo_status (cr2) != CAIRO_STATUS_FILE_NOT_FOUND) {
cairo_test_log ("Error: Received status of \"%s\" rather than expected \"%s\"\n",
cairo_status_to_string (cairo_status (cr2)),
cairo_status_to_string (CAIRO_STATUS_FILE_NOT_FOUND));
return CAIRO_TEST_FAILURE;
}
cairo_destroy (cr2);
/*
* 2. Test NULL pointer pattern->cairo_t
*/
cr2 = cairo_create (cairo_get_target (cr));
/* First, trigger the NULL pointer status. */
pattern = cairo_pattern_create_for_surface (NULL);
/* Then let it propagate into the cairo_t. */
cairo_set_source (cr2, pattern);
cairo_paint (cr2);
cairo_pattern_destroy (pattern);
/* Check that the error made it all that way. */
if (cairo_status (cr2) != CAIRO_STATUS_NULL_POINTER) {
cairo_test_log ("Error: Received status of \"%s\" rather than expected \"%s\"\n",
cairo_status_to_string (cairo_status (cr2)),
cairo_status_to_string (CAIRO_STATUS_NULL_POINTER));
return CAIRO_TEST_FAILURE;
}
cairo_destroy (cr2);