From f6f4bbdf6234687984069d6b32a4219b33a6d6f1 Mon Sep 17 00:00:00 2001 From: Elizabeth Smith Date: Sun, 5 Jul 2009 04:26:42 +0000 Subject: [PATCH] Remainder of functional api tests for cairocontext --- cairo_context.c | 8 ++-- tests/CairoContext/cairo_clip.phpt | 18 +++++++- tests/CairoContext/cairo_clip_extents.phpt | 19 ++++++++- tests/CairoContext/cairo_clip_preserve.phpt | 19 ++++++++- .../cairo_clip_rectangle_list.phpt | 19 ++++++++- tests/CairoContext/cairo_copy_page.phpt | 2 + tests/CairoContext/cairo_fill.phpt | 22 +++++++++- tests/CairoContext/cairo_fill_extents.phpt | 22 +++++++++- tests/CairoContext/cairo_fill_preserve.phpt | 22 +++++++++- tests/CairoContext/cairo_get_antialias.phpt | 22 +++++++++- tests/CairoContext/cairo_set_antialias.phpt | 25 ++++++++++- tests/CairoContext/cairo_set_source.phpt | 19 +++++++++ tests/CairoContext/cairo_set_source_rgba.phpt | 41 ++++++++++++++++--- .../cairo_set_source_surface.phpt | 7 ++++ tests/CairoContext/cairo_show_page.phpt | 22 +++++++++- 15 files changed, 268 insertions(+), 19 deletions(-) diff --git a/cairo_context.c b/cairo_context.c index e7baa8c3..af49da17 100644 --- a/cairo_context.c +++ b/cairo_context.c @@ -571,9 +571,11 @@ PHP_FUNCTION(cairo_set_source_surface) cairo_set_source_surface(context_object->context, surface_object->surface, x, y); PHP_CAIRO_ERROR(cairo_status(context_object->context)); - /* we need to be able to get this zval out later, so ref and store - context_object->surface = surface_zval; - Z_ADDREF_P(surface_zval);*/ + /* If there's already a pattern, then we deref and remove it because we just overwrote it */ + if(context_object->pattern) { + Z_DELREF_P(context_object->pattern); + context_object->pattern = NULL; + } } /* }}} */ diff --git a/tests/CairoContext/cairo_clip.phpt b/tests/CairoContext/cairo_clip.phpt index cc8b8ef3..c838e6a4 100644 --- a/tests/CairoContext/cairo_clip.phpt +++ b/tests/CairoContext/cairo_clip.phpt @@ -14,7 +14,18 @@ var_dump($context); cairo_clip($context); +// bad type hint is an E_RECOVERABLE_ERROR, so let's hook a handler +function bad_class($errno, $errstr) { + echo 'CAUGHT ERROR: ' . $errstr, PHP_EOL; +} +set_error_handler('bad_class', E_RECOVERABLE_ERROR); + +// check number of args - should accept ONLY 1 cairo_clip(); +cairo_clip($context, 1); + +// check arg types, should be CairoContext +cairo_clip(1); ?> --EXPECTF-- object(CairoImageSurface)#%d (0) { @@ -22,4 +33,9 @@ object(CairoImageSurface)#%d (0) { object(CairoContext)#%d (0) { } -Warning: cairo_clip() expects exactly 1 parameter, 0 given in %s on line %d \ No newline at end of file +Warning: cairo_clip() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: cairo_clip() expects exactly 1 parameter, 2 given in %s on line %d +CAUGHT ERROR: Argument 1 passed to cairo_clip() must be an instance of CairoContext, integer given + +Warning: cairo_clip() expects parameter 1 to be CairoContext, integer given in %s on line %d \ No newline at end of file diff --git a/tests/CairoContext/cairo_clip_extents.phpt b/tests/CairoContext/cairo_clip_extents.phpt index 70ba3f6c..6a78ad74 100644 --- a/tests/CairoContext/cairo_clip_extents.phpt +++ b/tests/CairoContext/cairo_clip_extents.phpt @@ -13,7 +13,19 @@ $context = cairo_create($surface); var_dump($context); var_dump(cairo_clip_extents($context)); + +// bad type hint is an E_RECOVERABLE_ERROR, so let's hook a handler +function bad_class($errno, $errstr) { + echo 'CAUGHT ERROR: ' . $errstr, PHP_EOL; +} +set_error_handler('bad_class', E_RECOVERABLE_ERROR); + +// check number of args - should accept ONLY 1 cairo_clip_extents(); +cairo_clip_extents($context, 1); + +// check arg types, should be CairoContext +cairo_clip_extents(1); ?> --EXPECTF-- object(CairoImageSurface)#%d (0) { @@ -31,4 +43,9 @@ array(4) { float(50) } -Warning: cairo_clip_extents() expects exactly 1 parameter, 0 given in %s on line %d \ No newline at end of file +Warning: cairo_clip_extents() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: cairo_clip_extents() expects exactly 1 parameter, 2 given in %s on line %d +CAUGHT ERROR: Argument 1 passed to cairo_clip_extents() must be an instance of CairoContext, integer given + +Warning: cairo_clip_extents() expects parameter 1 to be CairoContext, integer given in %s on line %d \ No newline at end of file diff --git a/tests/CairoContext/cairo_clip_preserve.phpt b/tests/CairoContext/cairo_clip_preserve.phpt index 1ed59f76..9b31009a 100644 --- a/tests/CairoContext/cairo_clip_preserve.phpt +++ b/tests/CairoContext/cairo_clip_preserve.phpt @@ -13,7 +13,19 @@ $context = cairo_create($surface); var_dump($context); cairo_clip_preserve($context); + +// bad type hint is an E_RECOVERABLE_ERROR, so let's hook a handler +function bad_class($errno, $errstr) { + echo 'CAUGHT ERROR: ' . $errstr, PHP_EOL; +} +set_error_handler('bad_class', E_RECOVERABLE_ERROR); + +// check number of args - should accept ONLY 1 cairo_clip_preserve(); +cairo_clip_preserve($context, 1); + +// check arg types, should be CairoContext +cairo_clip_preserve(1); ?> --EXPECTF-- object(CairoImageSurface)#%d (0) { @@ -21,4 +33,9 @@ object(CairoImageSurface)#%d (0) { object(CairoContext)#%d (0) { } -Warning: cairo_clip_preserve() expects exactly 1 parameter, 0 given in %s on line %d \ No newline at end of file +Warning: cairo_clip_preserve() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: cairo_clip_preserve() expects exactly 1 parameter, 2 given in %s on line %d +CAUGHT ERROR: Argument 1 passed to cairo_clip_preserve() must be an instance of CairoContext, integer given + +Warning: cairo_clip_preserve() expects parameter 1 to be CairoContext, integer given in %s on line %d \ No newline at end of file diff --git a/tests/CairoContext/cairo_clip_rectangle_list.phpt b/tests/CairoContext/cairo_clip_rectangle_list.phpt index 304368e2..dd5e3af5 100644 --- a/tests/CairoContext/cairo_clip_rectangle_list.phpt +++ b/tests/CairoContext/cairo_clip_rectangle_list.phpt @@ -13,7 +13,19 @@ $context = cairo_create($surface); var_dump($context); var_dump(cairo_clip_rectangle_list($context)); + +// bad type hint is an E_RECOVERABLE_ERROR, so let's hook a handler +function bad_class($errno, $errstr) { + echo 'CAUGHT ERROR: ' . $errstr, PHP_EOL; +} +set_error_handler('bad_class', E_RECOVERABLE_ERROR); + +// check number of args - should accept ONLY 1 cairo_clip_rectangle_list(); +cairo_clip_rectangle_list($context, 1); + +// check arg types, should be CairoContext +cairo_clip_rectangle_list(1); ?> --EXPECTF-- object(CairoImageSurface)#%d (0) { @@ -34,4 +46,9 @@ array(1) { } } -Warning: cairo_clip_rectangle_list() expects exactly 1 parameter, 0 given in %s on line %d \ No newline at end of file +Warning: cairo_clip_rectangle_list() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: cairo_clip_rectangle_list() expects exactly 1 parameter, 2 given in %s on line %d +CAUGHT ERROR: Argument 1 passed to cairo_clip_rectangle_list() must be an instance of CairoContext, integer given + +Warning: cairo_clip_rectangle_list() expects parameter 1 to be CairoContext, integer given in %s on line %d \ No newline at end of file diff --git a/tests/CairoContext/cairo_copy_page.phpt b/tests/CairoContext/cairo_copy_page.phpt index fc79b71d..9cad8f9e 100644 --- a/tests/CairoContext/cairo_copy_page.phpt +++ b/tests/CairoContext/cairo_copy_page.phpt @@ -12,6 +12,8 @@ var_dump($surface); $context = cairo_create($surface); var_dump($context); +cairo_copy_page($context); + // bad type hint is an E_RECOVERABLE_ERROR, so let's hook a handler function bad_class($errno, $errstr) { echo 'CAUGHT ERROR: ' . $errstr, PHP_EOL; diff --git a/tests/CairoContext/cairo_fill.phpt b/tests/CairoContext/cairo_fill.phpt index 980da550..20a50ee3 100644 --- a/tests/CairoContext/cairo_fill.phpt +++ b/tests/CairoContext/cairo_fill.phpt @@ -13,9 +13,29 @@ $context = cairo_create($surface); var_dump($context); cairo_fill($context); + +// bad type hint is an E_RECOVERABLE_ERROR, so let's hook a handler +function bad_class($errno, $errstr) { + echo 'CAUGHT ERROR: ' . $errstr, PHP_EOL; +} +set_error_handler('bad_class', E_RECOVERABLE_ERROR); + +// check number of args - should accept ONLY 1 +cairo_fill(); +cairo_fill($context, 1); + +// check arg types, should be CairoContext +cairo_fill(1); ?> --EXPECTF-- object(CairoImageSurface)#%d (0) { } object(CairoContext)#%d (0) { -} \ No newline at end of file +} + +Warning: cairo_fill() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: cairo_fill() expects exactly 1 parameter, 2 given in %s on line %d +CAUGHT ERROR: Argument 1 passed to cairo_fill() must be an instance of CairoContext, integer given + +Warning: cairo_fill() expects parameter 1 to be CairoContext, integer given in %s on line %d \ No newline at end of file diff --git a/tests/CairoContext/cairo_fill_extents.phpt b/tests/CairoContext/cairo_fill_extents.phpt index 5154ba67..3ff03496 100644 --- a/tests/CairoContext/cairo_fill_extents.phpt +++ b/tests/CairoContext/cairo_fill_extents.phpt @@ -13,6 +13,19 @@ $context = cairo_create($surface); var_dump($context); var_dump(cairo_fill_extents($context)); + +// bad type hint is an E_RECOVERABLE_ERROR, so let's hook a handler +function bad_class($errno, $errstr) { + echo 'CAUGHT ERROR: ' . $errstr, PHP_EOL; +} +set_error_handler('bad_class', E_RECOVERABLE_ERROR); + +// check number of args - should accept ONLY 1 +cairo_fill_extents(); +cairo_fill_extents($context, 1); + +// check arg types, should be CairoContext +cairo_fill_extents(1); ?> --EXPECTF-- object(CairoImageSurface)#%d (0) { @@ -28,4 +41,11 @@ array(4) { float(0) [3]=> float(0) -} \ No newline at end of file +} + +Warning: cairo_fill_extents() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: cairo_fill_extents() expects exactly 1 parameter, 2 given in %s on line %d +CAUGHT ERROR: Argument 1 passed to cairo_fill_extents() must be an instance of CairoContext, integer given + +Warning: cairo_fill_extents() expects parameter 1 to be CairoContext, integer given in %s on line %d \ No newline at end of file diff --git a/tests/CairoContext/cairo_fill_preserve.phpt b/tests/CairoContext/cairo_fill_preserve.phpt index 9714efc9..03887824 100644 --- a/tests/CairoContext/cairo_fill_preserve.phpt +++ b/tests/CairoContext/cairo_fill_preserve.phpt @@ -13,9 +13,29 @@ $context = cairo_create($surface); var_dump($context); cairo_fill_preserve($context); + +// bad type hint is an E_RECOVERABLE_ERROR, so let's hook a handler +function bad_class($errno, $errstr) { + echo 'CAUGHT ERROR: ' . $errstr, PHP_EOL; +} +set_error_handler('bad_class', E_RECOVERABLE_ERROR); + +// check number of args - should accept ONLY 1 +cairo_fill_preserve(); +cairo_fill_preserve($context, 1); + +// check arg types, should be CairoContext +cairo_fill_preserve(1); ?> --EXPECTF-- object(CairoImageSurface)#%d (0) { } object(CairoContext)#%d (0) { -} \ No newline at end of file +} + +Warning: cairo_fill_preserve() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: cairo_fill_preserve() expects exactly 1 parameter, 2 given in %s on line %d +CAUGHT ERROR: Argument 1 passed to cairo_fill_preserve() must be an instance of CairoContext, integer given + +Warning: cairo_fill_preserve() expects parameter 1 to be CairoContext, integer given in %s on line %d \ No newline at end of file diff --git a/tests/CairoContext/cairo_get_antialias.phpt b/tests/CairoContext/cairo_get_antialias.phpt index a26a011f..fe4195f6 100644 --- a/tests/CairoContext/cairo_get_antialias.phpt +++ b/tests/CairoContext/cairo_get_antialias.phpt @@ -13,10 +13,30 @@ $context = cairo_create($surface); var_dump($context); var_dump(cairo_get_antialias($context)); + +// bad type hint is an E_RECOVERABLE_ERROR, so let's hook a handler +function bad_class($errno, $errstr) { + echo 'CAUGHT ERROR: ' . $errstr, PHP_EOL; +} +set_error_handler('bad_class', E_RECOVERABLE_ERROR); + +// check number of args - should accept ONLY 1 +cairo_get_antialias(); +cairo_get_antialias($context, 1); + +// check arg types, should be CairoSurface +cairo_get_antialias(1); ?> --EXPECTF-- object(CairoImageSurface)#%d (0) { } object(CairoContext)#%d (0) { } -int(0) \ No newline at end of file +int(0) + +Warning: cairo_get_antialias() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: cairo_get_antialias() expects exactly 1 parameter, 2 given in %s on line %d +CAUGHT ERROR: Argument 1 passed to cairo_get_antialias() must be an instance of CairoContext, integer given + +Warning: cairo_get_antialias() expects parameter 1 to be CairoContext, integer given in %s on line %d \ No newline at end of file diff --git a/tests/CairoContext/cairo_set_antialias.phpt b/tests/CairoContext/cairo_set_antialias.phpt index 5f8e4981..a17a92b6 100644 --- a/tests/CairoContext/cairo_set_antialias.phpt +++ b/tests/CairoContext/cairo_set_antialias.phpt @@ -14,10 +14,33 @@ var_dump($context); cairo_set_antialias($context, CAIRO_ANTIALIAS_GRAY); var_dump(cairo_get_antialias($context)); + +// bad type hint is an E_RECOVERABLE_ERROR, so let's hook a handler +function bad_class($errno, $errstr) { + echo 'CAUGHT ERROR: ' . $errstr, PHP_EOL; +} +set_error_handler('bad_class', E_RECOVERABLE_ERROR); + +// check number of args - should accept 1 or 2 +cairo_set_antialias(); +cairo_set_antialias($context, 1, 1); + +// check arg types, should be int +cairo_set_antialias(1, 1); +cairo_set_antialias($context, array()); ?> --EXPECTF-- object(CairoImageSurface)#%d (0) { } object(CairoContext)#%d (0) { } -int(2) \ No newline at end of file +int(2) + +Warning: cairo_set_antialias() expects at least 1 parameter, 0 given in %s on line %d + +Warning: cairo_set_antialias() expects at most 2 parameters, 3 given in %s on line %d +CAUGHT ERROR: Argument 1 passed to cairo_set_antialias() must be an instance of CairoContext, integer given + +Warning: cairo_set_antialias() expects parameter 1 to be CairoContext, integer given in %s on line %d + +Warning: cairo_set_antialias() expects parameter 2 to be long, array given in %s on line %d \ No newline at end of file diff --git a/tests/CairoContext/cairo_set_source.phpt b/tests/CairoContext/cairo_set_source.phpt index 5ccd2371..86db5d17 100644 --- a/tests/CairoContext/cairo_set_source.phpt +++ b/tests/CairoContext/cairo_set_source.phpt @@ -18,6 +18,13 @@ var_dump($pattern); cairo_set_source($context, $pattern); var_dump(cairo_pattern_get_rgba(cairo_get_source($context))); +$pattern = cairo_pattern_create_rgb(0.5, 0.5, 0.5); +var_dump($pattern); + +cairo_set_source($context, $pattern); + +var_dump(cairo_pattern_get_rgba(cairo_get_source($context))); + function bad_class($errno, $errstr) { echo 'CAUGHT ERROR: ' . $errstr, PHP_EOL; } @@ -50,6 +57,18 @@ array(4) { ["alpha"]=> float(1) } +object(CairoSolidPattern)#%d (0) { +} +array(4) { + ["red"]=> + float(0.5) + ["green"]=> + float(0.5) + ["blue"]=> + float(0.5) + ["alpha"]=> + float(1) +} Warning: cairo_set_source() expects exactly 2 parameters, 0 given in %s on line %d diff --git a/tests/CairoContext/cairo_set_source_rgba.phpt b/tests/CairoContext/cairo_set_source_rgba.phpt index 778d51da..9a52404b 100644 --- a/tests/CairoContext/cairo_set_source_rgba.phpt +++ b/tests/CairoContext/cairo_set_source_rgba.phpt @@ -13,8 +13,6 @@ $context = cairo_create($surface); var_dump($context); cairo_set_source_rgba($context, 0.1, 0.1, 0.1, 0.5); -cairo_set_source_rgba($context, "0.1", "0.1", "0.1", "0.5"); -cairo_set_source_rgba($context, "foo", "baz", "bar", "baz"); // bad type hint is an E_RECOVERABLE_ERROR, so let's hook a handler function bad_class($errno, $errstr) { @@ -22,7 +20,20 @@ function bad_class($errno, $errstr) { } set_error_handler('bad_class', E_RECOVERABLE_ERROR); -cairo_set_source_rgba(new stdClass, 0.1, 0.1, 0.1, 0.5); +// 5 args +cairo_set_source_rgba(); +cairo_set_source_rgba($context); +cairo_set_source_rgba($context, 1); +cairo_set_source_rgba($context, 1, 1); +cairo_set_source_rgba($context, 1, 1, 1); +cairo_set_source_rgba($context, 1, 1, 1, 1, 1); + +// types +cairo_set_source_rgba(array(), 1, 1, 1, 1); +cairo_set_source_rgba($context, array(), 1, 1, 1); +cairo_set_source_rgba($context, 1, array(), 1, 1); +cairo_set_source_rgba($context, 1, 1, array(), 1); +cairo_set_source_rgba($context, 1, 1, 1, array()); ?> --EXPECTF-- object(CairoImageSurface)#%d (0) { @@ -30,7 +41,25 @@ object(CairoImageSurface)#%d (0) { object(CairoContext)#%d (0) { } -Warning: cairo_set_source_rgba() expects parameter 2 to be double, string given in %s on line %d -CAUGHT ERROR: Argument 1 passed to cairo_set_source_rgba() must be an instance of CairoContext, instance of stdClass given +Warning: cairo_set_source_rgba() expects exactly 5 parameters, 0 given in %s on line %d + +Warning: cairo_set_source_rgba() expects exactly 5 parameters, 1 given in %s on line %d + +Warning: cairo_set_source_rgba() expects exactly 5 parameters, 2 given in %s on line %d + +Warning: cairo_set_source_rgba() expects exactly 5 parameters, 3 given in %s on line %d + +Warning: cairo_set_source_rgba() expects exactly 5 parameters, 4 given in %s on line %d + +Warning: cairo_set_source_rgba() expects exactly 5 parameters, 6 given in %s on line %d +CAUGHT ERROR: Argument 1 passed to cairo_set_source_rgba() must be an instance of CairoContext, array given + +Warning: cairo_set_source_rgba() expects parameter 1 to be CairoContext, array given in %s on line %d + +Warning: cairo_set_source_rgba() expects parameter 2 to be double, array given in %s on line %d + +Warning: cairo_set_source_rgba() expects parameter 3 to be double, array given in %s on line %d + +Warning: cairo_set_source_rgba() expects parameter 4 to be double, array given in %s on line %d -Warning: cairo_set_source_rgba() expects parameter 1 to be CairoContext, object given in %s on line %d +Warning: cairo_set_source_rgba() expects parameter 5 to be double, array given in %s on line %d \ No newline at end of file diff --git a/tests/CairoContext/cairo_set_source_surface.phpt b/tests/CairoContext/cairo_set_source_surface.phpt index ba01f82c..a129bd4e 100644 --- a/tests/CairoContext/cairo_set_source_surface.phpt +++ b/tests/CairoContext/cairo_set_source_surface.phpt @@ -15,6 +15,11 @@ var_dump($context); $surface2 = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 50, 50); var_dump($surface2); +$pattern = cairo_pattern_create_rgb(0.5, 0.5, 0.5); +var_dump($pattern); + +cairo_set_source($context, $pattern); + cairo_set_source_surface($context, $surface2, 5, 5); function bad_class($errno, $errstr) { @@ -42,6 +47,8 @@ object(CairoContext)#%d (0) { } object(CairoImageSurface)#%d (0) { } +object(CairoSolidPattern)#%d (0) { +} Warning: cairo_set_source_surface() expects at least 2 parameters, 0 given in %s on line %d diff --git a/tests/CairoContext/cairo_show_page.phpt b/tests/CairoContext/cairo_show_page.phpt index a28646d0..509d116c 100644 --- a/tests/CairoContext/cairo_show_page.phpt +++ b/tests/CairoContext/cairo_show_page.phpt @@ -13,9 +13,29 @@ $context = cairo_create($surface); var_dump($context); cairo_show_page($context); + +// bad type hint is an E_RECOVERABLE_ERROR, so let's hook a handler +function bad_class($errno, $errstr) { + echo 'CAUGHT ERROR: ' . $errstr, PHP_EOL; +} +set_error_handler('bad_class', E_RECOVERABLE_ERROR); + +/* wrong params */ +cairo_show_page(); +cairo_show_page($context, 1); + +/* wrong types */ +cairo_show_page(1); ?> --EXPECTF-- object(CairoImageSurface)#%d (0) { } object(CairoContext)#%d (0) { -} \ No newline at end of file +} + +Warning: cairo_show_page() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: cairo_show_page() expects exactly 1 parameter, 2 given in %s on line %d +CAUGHT ERROR: Argument 1 passed to cairo_show_page() must be an instance of CairoContext, integer given + +Warning: cairo_show_page() expects parameter 1 to be CairoContext, integer given in %s on line %d \ No newline at end of file