Permalink
Browse files

More cairocontext tests, some fixes for cairo font face

Thanks to  Mark (the amazing) Skilbeck for help writing tests
  • Loading branch information...
1 parent 8bc6532 commit 86d484ae4fbeea8d2b15e45f95ff9078272f2989 @auroraeosrose auroraeosrose committed Jul 2, 2009
Showing with 1,020 additions and 15 deletions.
  1. +50 −1 cairo_context.c
  2. +1 −0 cairo_font_face.c
  3. +128 −0 tests/CairoContext/Paths/arc.phpt
  4. +71 −0 tests/CairoContext/Paths/cairo_arc.phpt
  5. +1 −1 tests/CairoContext/Paths/closePath.phpt
  6. +18 −3 tests/CairoContext/cairo_copy_page.phpt
  7. +22 −1 tests/CairoContext/cairo_get_group_target.phpt
  8. +22 −2 tests/CairoContext/cairo_pop_group.phpt
  9. +22 −1 tests/CairoContext/cairo_pop_group_to_source.phpt
  10. +28 −1 tests/CairoContext/cairo_set_source.phpt
  11. +64 −0 tests/CairoContext/cairo_set_source_rgba function.phpt
  12. +36 −2 tests/CairoContext/cairo_set_source_surface.phpt
  13. +42 −0 tests/CairoContext/get_dash_count.phpt
  14. +2 −2 tests/CairoContext/setDash.phpt
  15. +63 −1 tests/CairoContext/setSourceRGB.phpt
  16. +62 −0 tests/CairoFontFace/CairoToyFontFace/__construct.phpt
  17. +54 −0 tests/CairoFontFace/CairoToyFontFace/cairo_toy_font_face_create.phpt
  18. +36 −0 tests/CairoFontFace/CairoToyFontFace/cairo_toy_font_face_get_family.phpt
  19. +38 −0 tests/CairoFontFace/CairoToyFontFace/cairo_toy_font_face_get_slant.phpt
  20. +38 −0 tests/CairoFontFace/CairoToyFontFace/cairo_toy_font_face_get_weight.phpt
  21. +15 −0 tests/CairoFontFace/CairoToyFontFace/getFamily.phpt
  22. +19 −0 tests/CairoFontFace/CairoToyFontFace/getSlant.phpt
  23. +19 −0 tests/CairoFontFace/CairoToyFontFace/getWeight.phpt
  24. +27 −0 tests/CairoFontFace/__construct.phpt
  25. +36 −0 tests/CairoFontFace/cairo_font_face_get_type.phpt
  26. +41 −0 tests/CairoFontFace/cairo_font_face_status.phpt
  27. +10 −0 tests/CairoFontFace/create_toyfont.inc
  28. +25 −0 tests/CairoFontFace/getType.phpt
  29. +30 −0 tests/CairoFontFace/status.phpt
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -81,6 +81,7 @@ PHP_FUNCTION(cairo_font_face_get_type)
/* {{{ cairo_font_face_methods[] */
const zend_function_entry cairo_font_face_methods[] = {
+ PHP_ME(CairoFontFace, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME_MAPPING(status, cairo_font_face_status, NULL, ZEND_ACC_PUBLIC)
PHP_ME_MAPPING(getType, cairo_font_face_get_type, NULL, ZEND_ACC_PUBLIC)
{NULL, NULL, NULL}
@@ -0,0 +1,128 @@
+--TEST--
+CairoContext->arc() method
+--SKIPIF--
+<?php
+if(!extension_loaded('cairo')) die('skip - Cairo extension not available');
+?>
+--FILE--
+<?php
+$surface = new CairoImageSurface(CairoFormat::ARGB32, 50, 50);
+var_dump($surface);
+
+$context = new CairoContext($surface);
+var_dump($context);
+
+function trig_err()
+{
+ trigger_error('CairoContext::arc() expects 5 parameters!');
+}
+
+$context->arc(0, 0, 1, 0, 2 * M_PI);
+
+/* wrong params */
+try {
+ $context->arc();
+ trig_err();
+}
+catch (CairoException $ex) {
+ echo $ex->getMessage(), PHP_EOL;
+}
+
+try {
+ $context->arc(1);
+ trig_err();
+}
+catch (CairoException $ex) {
+ echo $ex->getMessage(), PHP_EOL;
+}
+
+try {
+ $context->arc(1,1);
+ trig_err();
+}
+catch (CairoException $ex) {
+ echo $ex->getMessage(), PHP_EOL;
+}
+
+try {
+ $context->arc(1,1,1);
+ trig_err();
+}
+catch (CairoException $ex) {
+ echo $ex->getMessage(), PHP_EOL;
+}
+
+try {
+ $context->arc(1,1,1,1);
+ trig_err();
+}
+catch (CairoException $ex) {
+ echo $ex->getMessage(), PHP_EOL;
+}
+
+try {
+ $context->arc(1,1,1,1,1,1);
+ trig_err();
+}
+catch (CairoException $ex) {
+ echo $ex->getMessage(), PHP_EOL;
+}
+
+/* wrong types */
+try {
+ $context->arc(array(),1,1,1,1);
+ trig_err();
+}
+catch (CairoException $ex) {
+ echo $ex->getMessage(), PHP_EOL;
+}
+
+try {
+ $context->arc(1,array(),1,1,1);
+ trig_err();
+}
+catch (CairoException $ex) {
+ echo $ex->getMessage(), PHP_EOL;
+}
+
+try {
+ $context->arc(1,1,array(),1,1);
+ trig_err();
+}
+catch (CairoException $ex) {
+ echo $ex->getMessage(), PHP_EOL;
+}
+
+try {
+ $context->arc(1,1,1,array(),1);
+ trig_err();
+}
+catch (CairoException $ex) {
+ echo $ex->getMessage(), PHP_EOL;
+}
+
+try {
+ $context->arc(1,1,1,1,array());
+ trig_err();
+}
+catch (CairoException $ex) {
+ echo $ex->getMessage(), PHP_EOL;
+}
+
+?>
+--EXPECTF--
+object(CairoImageSurface)#%d (0) {
+}
+object(CairoContext)#%d (0) {
+}
+CairoContext::arc() expects exactly 5 parameters, 0 given
+CairoContext::arc() expects exactly 5 parameters, 1 given
+CairoContext::arc() expects exactly 5 parameters, 2 given
+CairoContext::arc() expects exactly 5 parameters, 3 given
+CairoContext::arc() expects exactly 5 parameters, 4 given
+CairoContext::arc() expects exactly 5 parameters, 6 given
+CairoContext::arc() expects parameter 1 to be double, array given
+CairoContext::arc() expects parameter 2 to be double, array given
+CairoContext::arc() expects parameter 3 to be double, array given
+CairoContext::arc() expects parameter 4 to be double, array given
+CairoContext::arc() expects parameter 5 to be double, array given
@@ -0,0 +1,71 @@
+--TEST--
+cairo_arc() function
+--SKIPIF--
+<?php
+if(!extension_loaded('cairo')) die('skip - Cairo extension not available');
+?>
+--FILE--
+<?php
+$surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 50, 50);
+var_dump($surface);
+
+$context = cairo_create($surface);
+var_dump($context);
+
+cairo_arc($context, 0, 0, 1, 0, 2 * M_PI);
+
+// 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_arc();
+cairo_arc($context);
+cairo_arc($context, 1);
+cairo_arc($context, 1, 1);
+cairo_arc($context, 1, 1, 1);
+cairo_arc($context, 1, 1, 1, 1);
+cairo_arc($context, 1, 1, 1, 1, 1, 1);
+
+/* wrong types */
+cairo_arc(1, 1, 1, 1, 1, 1);
+cairo_arc($context, array(), 1, 1, 1, 1);
+cairo_arc($context, 1, array(), 1, 1, 1);
+cairo_arc($context, 1, 1, array(), 1, 1);
+cairo_arc($context, 1, 1, 1, array(), 1);
+cairo_arc($context, 1, 1, 1, 1, array());
+?>
+--EXPECTF--
+object(CairoImageSurface)#%d (0) {
+}
+object(CairoContext)#%d (0) {
+}
+
+Warning: cairo_arc() expects exactly 6 parameters, 0 given in %s on line %d
+
+Warning: cairo_arc() expects exactly 6 parameters, 1 given in %s on line %d
+
+Warning: cairo_arc() expects exactly 6 parameters, 2 given in %s on line %d
+
+Warning: cairo_arc() expects exactly 6 parameters, 3 given in %s on line %d
+
+Warning: cairo_arc() expects exactly 6 parameters, 4 given in %s on line %d
+
+Warning: cairo_arc() expects exactly 6 parameters, 5 given in %s on line %d
+
+Warning: cairo_arc() expects exactly 6 parameters, 7 given in %s on line %d
+CAUGHT ERROR: Argument 1 passed to cairo_arc() must be an instance of CairoContext, integer given
+
+Warning: cairo_arc() expects parameter 1 to be CairoContext, integer given in %s on line %d
+
+Warning: cairo_arc() expects parameter 2 to be double, array given in %s on line %d
+
+Warning: cairo_arc() expects parameter 3 to be double, array given in %s on line %d
+
+Warning: cairo_arc() expects parameter 4 to be double, array given in %s on line %d
+
+Warning: cairo_arc() expects parameter 5 to be double, array given in %s on line %d
+
+Warning: cairo_arc() expects parameter 6 to be double, array given in %s on line %d
@@ -1,5 +1,5 @@
--TEST--
-CairoContext->newSubPath() method
+CairoContext->closePath() method
--SKIPIF--
<?php
if(!extension_loaded('cairo')) die('skip - Cairo extension not available');
@@ -1,5 +1,5 @@
--TEST--
-cairo_copy_page function
+cairo_copy_page() function
--SKIPIF--
<?php
if(!extension_loaded('cairo')) die('skip - Cairo extension not available');
@@ -12,13 +12,28 @@ 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;
+}
+set_error_handler('bad_class', E_RECOVERABLE_ERROR);
+
+/* wrong params */
cairo_copy_page();
+cairo_copy_page($context, 1);
+
+/* wrong types */
+cairo_copy_page(1);
?>
--EXPECTF--
object(CairoImageSurface)#%d (0) {
}
object(CairoContext)#%d (0) {
}
-Warning: cairo_copy_page() expects exactly 1 parameter, 0 given in %s on line %d
+Warning: cairo_copy_page() expects exactly 1 parameter, 0 given in %s on line %d
+
+Warning: cairo_copy_page() expects exactly 1 parameter, 2 given in %s on line %d
+CAUGHT ERROR: Argument 1 passed to cairo_copy_page() must be an instance of CairoContext, integer given
+
+Warning: cairo_copy_page() expects parameter 1 to be CairoContext, integer given in %s on line %d
@@ -15,6 +15,20 @@ var_dump($context);
$surface2 = cairo_get_group_target($context);
var_dump($surface2);
var_dump($surface2 == $surface);
+
+// 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 parameters */
+cairo_get_group_target();
+cairo_get_group_target($context, 1);
+
+/* wrong type */
+cairo_get_group_target(1);
+
?>
--EXPECTF--
object(CairoImageSurface)#%d (0) {
@@ -23,4 +37,11 @@ object(CairoContext)#%d (0) {
}
object(CairoImageSurface)#%d (0) {
}
-bool(true)
+bool(true)
+
+Warning: cairo_get_group_target() expects exactly 1 parameter, 0 given in %s on line %d
+
+Warning: cairo_get_group_target() expects exactly 1 parameter, 2 given in %s on line %d
+CAUGHT ERROR: Argument 1 passed to cairo_get_group_target() must be an instance of CairoContext, integer given
+
+Warning: cairo_get_group_target() expects parameter 1 to be CairoContext, integer given in %s on line %d
@@ -1,5 +1,5 @@
--TEST--
-cairo_pop_group function
+cairo_pop_group() function
--SKIPIF--
<?php
if(!extension_loaded('cairo')) die('skip - Cairo extension not available');
@@ -15,11 +15,31 @@ var_dump($context);
cairo_push_group($context);
$pattern = cairo_pop_group($context);
var_dump($pattern);
+
+// 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 only accept ONE
+cairo_pop_group();
+cairo_pop_group($context, 1);
+
+// Accept correct type!
+cairo_pop_group(1);
?>
--EXPECTF--
object(CairoImageSurface)#%d (0) {
}
object(CairoContext)#%d (0) {
}
object(CairoSurfacePattern)#%d (0) {
-}
+}
+
+Warning: cairo_pop_group() expects exactly 1 parameter, 0 given in %s on line %d
+
+Warning: cairo_pop_group() expects exactly 1 parameter, 2 given in %s on line %d
+CAUGHT ERROR: Argument 1 passed to cairo_pop_group() must be an instance of CairoContext, integer given
+
+Warning: cairo_pop_group() expects parameter 1 to be CairoContext, integer given in %s on line %d
@@ -16,11 +16,32 @@ cairo_push_group($context);
cairo_pop_group_to_source($context);
var_dump(cairo_get_source($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 parameters */
+cairo_pop_group_to_source();
+cairo_pop_group_to_source($context, 1);
+
+/* wrong type */
+cairo_pop_group_to_source(1);
+
?>
--EXPECTF--
object(CairoImageSurface)#%d (0) {
}
object(CairoContext)#%d (0) {
}
object(CairoSurfacePattern)#%d (0) {
-}
+}
+
+Warning: cairo_pop_group_to_source() expects exactly 1 parameter, 0 given in %s on line %d
+
+Warning: cairo_pop_group_to_source() expects exactly 1 parameter, 2 given in %s on line %d
+CAUGHT ERROR: Argument 1 passed to cairo_pop_group_to_source() must be an instance of CairoContext, integer given
+
+Warning: cairo_pop_group_to_source() expects parameter 1 to be CairoContext, integer given in %s on line %d
Oops, something went wrong.

0 comments on commit 86d484a

Please sign in to comment.