[cairo-commit] cairo-perl/t Cairo.t, 1.3, 1.4 CairoFont.t, NONE, 1.1 CairoMatrix.t, 1.1, 1.2 CairoPath.t, NONE, 1.1 CairoPattern.t, 1.1, 1.2 CairoSurface.t, 1.1, 1.2

Torsten Schoenfeld commit at pdx.freedesktop.org
Tue Jul 12 13:29:51 PDT 2005


Committed by: tsch

Update of /cvs/cairo/cairo-perl/t
In directory gabe:/tmp/cvs-serv30085/t

Modified Files:
	Cairo.t CairoMatrix.t CairoPattern.t CairoSurface.t 
Added Files:
	CairoFont.t CairoPath.t 
Log Message:
	* Cairo.pm, Cairo.xs, t/Cairo.t: Replace the %backends hash with
	Cairo::HAS_PS_SURFACE, HAS_PDF_SURFACE, HAS_XLIB_SURFACE,
	HAS_FT_FONT and HAS_PNG_FUNCTIONS.

	* Cairo.pm, CairoPattern.xs, CairoSurface.xs, Makefile.PL:
	Implement the pattern and surface hierarchy suggested by the
	language bindings guidelines.

	* Cairo.xs: Use Cairo::Context for the namespace of cairo_t,
	instead of just Cairo, as suggested by the guidelines.

	* Cairo.xs, CairoFont.xs, CairoMatrix.xs, CairoPattern.xs,
	CairoSurface.xs, cairo-perl.h: Add new, remove old API.  Shuffle
	some things around.

	* Cairo.xs: Convert font and text extents and glyphs to and from
	native Perl data structures.

	* Cairo.xs, cairo-perl.h, cairo-perl.typemap: Remove everything
	that cannot be used from Perl, like the XLib and Glitz stuff.

	* CairoPath.xs, t/CairoPath.t: Add support for cairo_path_t,
	including a nice tied interface that lets you iterate over paths
	as if they were normal array references.

	* MakeHelper.pm: Extend the typemap generator to support "const"
	and "_noinc" types.  Change the enum handling to use the Glib
	convention, i.e. lowercase and hyphen instead of underscore.

	* Makefile.PL, README: Use ExtUtils::Depends.

	* examples/simple.pl, examples/png/caps_join.pl,
	examples/png/hering.pl, examples/png/outline.pl,
	examples/png/spiral.pl, examples/png/splines_tolerance.pl,
	examples/png/stars.pl: Update the examples to make them work again
	after all those API changes.

	* t/Cairo.t, t/CairoFont.t, CairoMatrix.t, CairoPattern.t,
	CairoSurface.t: Redo and/or expand the whole test suite.


Index: Cairo.t
===================================================================
RCS file: /cvs/cairo/cairo-perl/t/Cairo.t,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- Cairo.t	12 Nov 2004 03:26:34 -0000	1.3
+++ Cairo.t	12 Jul 2005 20:29:49 -0000	1.4
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2004 by the cairo  perl team (see the file README)
+# Copyright (c) 2004-2005 by the cairo perl team (see the file README)
 #
 # Licensed under the LGPL, see LICENSE file for more information.
 #
@@ -8,293 +8,163 @@
 
 use strict;
 use warnings;
-use Data::Dumper;
 
-use Test::More tests => 47;
+use Test::More tests => 48;
 
 use constant {
 	IMG_WIDTH => 256,
 	IMG_HEIGHT => 256,
 };
 
-BEGIN
-{
+BEGIN {
 	use_ok ('Cairo');
 }
 
-# make sure there's something in there
-ok (%Cairo::backends, '%Cairo::backends');
-
-isa_ok (my $cr = Cairo->create, 'Cairo', 'create');
-{
-	isa_ok (my $copy = $cr->copy, 'Cairo', 'copy');
-}
-
-eval
-{
-	$cr->save;
-	$cr->restore;
-};
-is ($@, '', '$cr->save|restore');
+my $surf = Cairo::ImageSurface->create ('rgb24', IMG_WIDTH, IMG_HEIGHT);
+isa_ok ($surf, 'Cairo::Surface');
 
-{
-	my $surf = Cairo::Surface->image_create ('RGB24', IMG_WIDTH, IMG_HEIGHT);
-	isa_ok ($surf, 'Cairo::Surface', 'support');
+my $cr = Cairo::Context->create ($surf);
+isa_ok ($cr, 'Cairo::Context');
 
-	$cr->set_target_surface ($surf);
-	isa_ok ($cr->current_target_surface, 'Cairo::Surface',
-		'$cr->set_target_surface');
-	
-	my $ptn = Cairo::Pattern->create_for_surface ($surf);
-	$cr->set_pattern ($ptn);
-	isa_ok ($cr->current_pattern, 'Cairo::Pattern',
-		'$cr->set|current_pattern');
-}
+$cr->save;
+$cr->restore;
 
-# TODO: $cr->set_target_image
+$cr->set_operator ('clear');
+is ($cr->get_operator, 'clear');
 
-$cr->set_operator ('CLEAR');
-is ($cr->current_operator, 'CLEAR', '$cr->set|current_operator');
+$cr->set_source_rgb (0.5, 0.6, 0.7);
+$cr->set_source_rgba (0.5, 0.6, 0.7, 0.8);
 
-$cr->set_rgb_color (0.5, 0.6, 0.7);
-is_deeply ([$cr->current_rgb_color], [0.5, 0.6, 0.7],
-	  '$cr->set|current_rgb_color');
+my $pat = Cairo::SurfacePattern->create ($surf);
 
-$cr->set_alpha (0.25);
-is ($cr->current_alpha, 0.25, '$cr->set|current_alpha');
+$cr->set_source ($pat);
+$cr->set_source_surface ($surf, 23, 42);
 
 $cr->set_tolerance (0.75);
-is ($cr->current_tolerance, 0.75, '$cr->set|current_tolerance');
+is ($cr->get_tolerance, 0.75);
 
-$cr->set_fill_rule ('WINDING');
-is ($cr->current_fill_rule, 'WINDING', '$cr->set|current_fill_rule');
+$cr->set_fill_rule ('winding');
+is ($cr->get_fill_rule, 'winding');
 
 $cr->set_line_width (3);
-is ($cr->current_line_width, 3, '$cr->set|current_line_width');
+is ($cr->get_line_width, 3);
 
-$cr->set_line_cap ('BUTT');
-is ($cr->current_line_cap, 'BUTT', '$cr->set|current_line_cap');
+$cr->set_line_cap ('butt');
+is ($cr->get_line_cap, 'butt');
 
-$cr->set_line_join ('MITER');
-is ($cr->current_line_join, 'MITER', '$cr->set|current_line_join');
+$cr->set_line_join ('miter');
+is ($cr->get_line_join, 'miter');
 
-eval
-{
-	$cr->set_dash (0, 2, 4, 6, 4, 2);
-};
-is ($@, '', '$cr->set_dash');
+$cr->set_dash (0, 2, 4, 6, 4, 2);
 
 $cr->set_miter_limit (2.2);
-is ($cr->current_miter_limit, 2.2, '$cr->set|current_miter_limit');
-
-eval
-{
-	$cr->translate (2.2, 3.3);
-};
-is ($@, '', '$cr->translate');
-
-eval
-{
-	$cr->scale (2.2, 3.3);
-};
-is ($@, '', '$cr->scale');
-
-eval
-{
-	$cr->rotate (2.2);
-};
-is ($@, '', '$cr->rotate');
-
-eval
-{
-	$cr->default_matrix;
-};
-is ($@, '', '$cr->default_matrix');
-
-eval
-{
-	$cr->identity_matrix;
-};
-is ($@, '', '$cr->identity_matrix');
+is ($cr->get_miter_limit, 2.2);
 
-{
-	my $matrix = Cairo::Matrix->create;
+$cr->translate (2.2, 3.3);
+$cr->scale (2.2, 3.3);
+$cr->rotate (2.2);
 
-	$matrix->set_affine (1.1, 2.2, 3.3, 4.4, 23, 34);
+my $mat = Cairo::Matrix->init_identity;
+isa_ok ($mat, 'Cairo::Matrix');
 
-	$cr->set_matrix ($matrix);
-	is_deeply ([$cr->current_matrix->get_affine], 
-		   [ 1.1, 2.2, 3.3, 4.4, 23, 34 ], '$cr->current_matrix');
+$cr->set_matrix ($mat);
+isa_ok ($cr->get_matrix, 'Cairo::Matrix');
 
-	eval
-	{
-		$cr->concat_matrix ($matrix);
-	};
-	is ($@, '', '$cr->concat_matrix');
-}
+$cr->transform ($mat);
+$cr->identity_matrix;
 
-{
-	my ($x, $y) = (1.1, 2.2);
-	is_deeply ([$cr->transform_point ($x, $y)], [209.747, 306.074],
-		   '$cr->transform_point');
-	
-	is_deeply ([$cr->transform_distance ($x, $y)], [49.247, 71.874],
-		   '$cr->transform_distance');
-	
-	my ($tx, $ty) = $cr->inverse_transform_point ($x, $y);
-	$tx = int ($tx);
-	$ty = int ($ty);
-	is_deeply ([$tx, $ty], [-5, -6], '$cr->inverse_transform_point');
-	
-	($tx, $ty) = $cr->inverse_transform_distance ($x, $y);
-	$tx = int ($tx);
-	$ty = int ($ty);
-	is_deeply ([$tx, $ty], [-1, 0], '$cr->inverse_transform_distance');
-}
+is_deeply ([$cr->user_to_device (23, 42)], [23, 42]);
+is_deeply ([$cr->user_to_device_distance (1, 2)], [1, 2]);
+is_deeply ([$cr->device_to_user (23, 42)], [23, 42]);
+is_deeply ([$cr->device_to_user_distance (1, 2)], [1, 2]);
 
-# img isn't going to be very interesting
-my $outtmp = 't/out.tmp';
-open OUT, '>'.$outtmp
-	or die "failed to create output tmp file ($outtmp)";
-ok (*OUT, 'OUT support');
+$cr->new_path;
+$cr->move_to (1.1, 2.2);
+$cr->line_to (2.2, 3.3);
+$cr->curve_to (3.3, 4.4, 5.5, 6.6, 7.7, 8.8);
+$cr->arc (4.4, 5.5, 6.6, 7.7, 8.8);
+$cr->arc_negative (5.5, 6.6, 7.7, 8.8, 9.9);
+$cr->rel_move_to (6.6, 7.7);
+$cr->rel_line_to (8.8, 9.9);
+$cr->rel_curve_to (9.9, 0.0, 1.1, 2.2, 3.3, 4.4);
+$cr->rectangle (0.0, 1.1, 2.2, 3.3);
+$cr->close_path;
 
-SKIP:
-{
-	skip "png backend not supported in bound cairo", 1
-		unless ($Cairo::backends{png});
-	eval
-	{
-		$cr->set_target_png (*OUT, 'ARGB32', IMG_WIDTH, IMG_HEIGHT);
-	};
-	is ($@, '', '$cr->set_target_png');
-}
+$cr->paint;
+$cr->paint_with_alpha (0.5);
+$cr->mask ($pat);
+$cr->mask_surface ($surf, 23, 42);
+$cr->stroke;
+$cr->stroke_preserve;
+$cr->fill;
+$cr->fill_preserve;
+$cr->copy_page;
+$cr->show_page;
 
-# XXX: we have to set a backend ^ before doing the stuff below or we get
-# segfaults
-eval
-{
-	$cr->new_path;
-	$cr->move_to (1.1, 2.2);
-	$cr->line_to (2.2, 3.3);
-	$cr->curve_to (3.3, 4.4, 5.5, 6.6, 7.7, 8.8);
-	$cr->arc (4.4, 5.5, 6.6, 7.7, 8.8);
-	$cr->arc (5.5, 6.6, 7.7, 8.8, 9.9);
-	$cr->rel_move_to (6.6, 7.7);
-	$cr->rel_line_to (8.8, 9.9);
-	$cr->rel_curve_to (9.9, 0.0, 1.1, 2.2, 3.3, 4.4);
-	$cr->rectangle (0.0, 1.1, 2.2, 3.3);
+ok (!$cr->in_stroke (23, 42));
+ok (!$cr->in_fill (23, 42));
 
-	$cr->close_path;
+my @ext = $cr->stroke_extents;
+is (@ext, 4);
 
-	my ($ex, $ey) = $cr->stroke_extents;
-	$ex = int ($ex);
-	$ey = int ($ey);
-	is_deeply ([$ex, $ey], [-1, 0], '$cr->stroke_extents');
-	
-	($ex, $ey) = $cr->fill_extents;
-	$ex = int ($ex);
-	$ey = int ($ey);
-	is_deeply ([$ex, $ey], [0, 1], '$cr->fill_extents');
-	
-	$cr->stroke;
-	$cr->fill;
+ at ext = $cr->fill_extents;
+is (@ext, 4);
 
-	$cr->copy_page;
-	$cr->show_page;
+$cr->clip;
+$cr->clip_preserve;
+$cr->reset_clip;
+$cr->select_font_face ('Sans', 'normal', 'normal');
+$cr->set_font_size (12);
 
-	ok (! $cr->in_stroke (1.1, 2.2), '$cr->in_stroke');
-	ok (! $cr->in_fill (2.2, 3.3), '$cr->in_fill');
-};
-is ($@, '', 'path/drawing funcs');
+$cr->set_font_matrix ($mat);
+isa_ok ($cr->get_font_matrix, 'Cairo::Matrix');
 
-eval
-{
-#	$cr->init_clip;
-#	$cr->clip;
-};
-is ($@, '', 'clip funcs');
+my @glyphs = ({ index => 1, x => 2, y => 3 },
+              { index => 2, x => 3, y => 4 },
+              { index => 3, x => 4, y => 5 });
 
-eval
-{
-	$cr->select_font ('courier', 'NORMAL', 'NORMAL');
-	$cr->scale_font (2);
-	$cr->transform_font ($cr->current_matrix);
-# XXX: if i call show text things abort
-#	$cr->show_text ('Hello World');
+$cr->show_text ('Urgs?');
+$cr->show_glyphs (@glyphs);
 
-	my $font = $cr->current_font;
-	isa_ok ($font, 'Cairo::Font', '$cr->current_font');
-	$cr->set_font ($font);
+my $face = $cr->get_font_face;
+isa_ok ($face, 'Cairo::FontFace');
+$cr->set_font_face ($face);
 
-# XXX: lines 225 - 256 should be tested here
-#	isa_ok ($cr->current_font_extents, 'Cairo::Font::Extents',
-#		'$cr->current_font_extents');
-};
-is ($@, '', 'fonts');
+my $ext = $cr->font_extents;
+isa_ok ($ext, 'HASH');
+ok (exists $ext->{'ascent'});
+ok (exists $ext->{'descent'});
+ok (exists $ext->{'height'});
+ok (exists $ext->{'max_x_advance'});
+ok (exists $ext->{'max_y_advance'});
 
-{
-	my $surf = Cairo::Surface->image_create ('RGB24', IMG_WIDTH, IMG_HEIGHT);
-	eval
-	{
-		$cr->show_surface ($surf, IMG_WIDTH, IMG_HEIGHT);
-	};
-	is ($@, '', '$cr->show_surface');
+foreach $ext ($cr->text_extents ('Urgs?'),
+              $cr->glyph_extents (@glyphs)) {
+	isa_ok ($ext, 'HASH');
+	ok (exists $ext->{'x_bearing'});
+	ok (exists $ext->{'y_bearing'});
+	ok (exists $ext->{'width'});
+	ok (exists $ext->{'height'});
+	ok (exists $ext->{'x_advance'});
+	ok (exists $ext->{'y_advance'});
 }
 
-is ($cr->status, 'SUCCESS', '$cr->status');
-
-is ($cr->status_string, 'success', '$cr->status_string');
-
-SKIP:
-{
-	# XXX:
-	skip "ps backend currently hangs", 1;
+$cr->text_path ('Urgs?');
+$cr->glyph_path (@glyphs);
 
-	skip "ps backend not supported in bound cairo", 1
-		unless ($Cairo::backends{ps});
-	eval
-	{
-		$cr->set_target_ps (*OUT, IMG_WIDTH, IMG_HEIGHT, 72, 72);
-	};
-	is ($@, '', '$cr->set_target_ps');
-}
+isa_ok ($cr->get_source, 'Cairo::Pattern');
 
-SKIP:
-{
-	# XXX:
-	skip "xlib backend no way to get display and drawable", 1;
+my @pnt = $cr->get_current_point;
+is (@pnt, 2);
 
-	skip "xlib backend not supported in bound cairo", 1
-		unless ($Cairo::backends{xlib});
-	eval
-	{
-		$cr->set_target_drawable ();
-	};
-	is ($@, '', '$cr->set_target_xlib');
-}
+isa_ok ($cr->get_target, 'Cairo::Surface');
 
-SKIP:
-{
-	skip "xcb backend not supported in bound cairo", 1
-		unless ($Cairo::backends{xcb});
-	eval
-	{
-		$cr->set_target_xcb ();
-	};
-	is ($@, '', '$cr->set_target_xcb');
-}
+my $path = $cr->copy_path;
+isa_ok ($path, 'ARRAY');
 
-SKIP:
-{
-	skip "glitz backend not supported in bound cairo", 1
-		unless ($Cairo::backends{glitz});
-	eval
-	{
-		$cr->set_target_glitz ();
-	};
-	is ($@, '', '$cr->set_target_glitz');
-}
+$path = $cr->copy_path_flat;
+isa_ok ($path, 'ARRAY');
 
-close OUT;
+$cr->append_path ($path);
 
-ok (unlink ($outtmp), 'rm tmpout');
+is ($cr->status, 'success');

--- NEW FILE: CairoFont.t ---
#
# Copyright (c) 2004-2005 by the cairo perl team (see the file README)
#
# Licensed under the LGPL, see LICENSE file for more information.
#
# $Header: /cvs/cairo/cairo-perl/t/CairoFont.t,v 1.1 2005/07/12 20:29:49 tsch Exp $
#

use strict;
use warnings;

use Test::More tests => 3;

use constant {
	IMG_WIDTH => 256,
	IMG_HEIGHT => 256,
};

use Cairo;

my $surf = Cairo::ImageSurface->create ('rgb24', IMG_WIDTH, IMG_HEIGHT);
my $cr = Cairo::Context->create ($surf);
my $face = $cr->get_font_face;

my $matrix = Cairo::Matrix->init_identity;
my $ctm = Cairo::Matrix->init_identity;

my $font = Cairo::ScaledFont->create ($face, $matrix, $ctm);
isa_ok ($font, 'Cairo::ScaledFont');
isa_ok ($font->extents, 'HASH');
isa_ok ($font->glyph_extents ({ index => 1, x => 2, y => 3 }), 'HASH');

Index: CairoMatrix.t
===================================================================
RCS file: /cvs/cairo/cairo-perl/t/CairoMatrix.t,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- CairoMatrix.t	12 Nov 2004 03:32:05 -0000	1.1
+++ CairoMatrix.t	12 Jul 2005 20:29:49 -0000	1.2
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2004 by the cairo  perl team (see the file README)
+# Copyright (c) 2004-2005 by the cairo perl team (see the file README)
 #
 # Licensed under the LGPL, see LICENSE file for more information.
 #
@@ -8,35 +8,42 @@
 
 use strict;
 use warnings;
-use Data::Dumper;
 
-use Test::More tests => 6;
+use Test::More tests => 10;
 
 use Cairo;
 
-isa_ok (my $matrix = Cairo::Matrix->create, 'Cairo::Matrix');
+my $matrix = Cairo::Matrix->init (1, 2, 3, 4, 5, 6);
+isa_ok ($matrix, 'Cairo::Matrix');
 
-{
-	isa_ok ($matrix->copy, 'Cairo::Matrix', '$matrix->copy');
-}
+$matrix = Cairo::Matrix->init_identity;
+isa_ok ($matrix, 'Cairo::Matrix');
+
+$matrix = Cairo::Matrix->init_translate (1, 2);
+isa_ok ($matrix, 'Cairo::Matrix');
+
+$matrix = Cairo::Matrix->init_scale (3, 4);
+isa_ok ($matrix, 'Cairo::Matrix');
+
+$matrix = Cairo::Matrix->init_rotate (3.1415);
+isa_ok ($matrix, 'Cairo::Matrix');
 
 eval
 {
-	$matrix->set_identity;
-	$matrix->translate (2, 3);
+	$matrix->translate (1, 2);
 	$matrix->scale (3, 4);
-	$matrix->rotate (3.14);
-	$matrix->invert;
+	$matrix->rotate (3.1415);
 };
-is ($@, '', 'set_identity, translate, scale, rotate, invert');
+is ($@, '', 'set_identity, translate, scale, rotate');
 
-$matrix->set_affine (1, 2, 3, 4, 5, 6);
-is_deeply ([$matrix->get_affine], [1, 2, 3, 4, 5, 6],
-	   '$matrix->set|get_affine');
+is ($matrix->invert, 'success');
 
-is_deeply ([$matrix->transform_distance (1, 2)], [7, 10],
-	   '$matrix->transform_distance');
+my $id = Cairo::Matrix->init_identity;
 
-is_deeply ([$matrix->transform_point (2, 3)], [16, 22],
-	   '$matrix->transform_point');
+isa_ok ($matrix->multiply ($id), 'Cairo::Matrix');
 
+is_deeply ([$id->transform_distance (1, 1)], [1, 1],
+	   '$id->transform_distance');
+
+is_deeply ([$id->transform_point (1, 1)], [1, 1],
+	   '$id->transform_point');

--- NEW FILE: CairoPath.t ---
#
# Copyright (c) 2004-2005 by the cairo perl team (see the file README)
#
# Licensed under the LGPL, see LICENSE file for more information.
#
# $Header: /cvs/cairo/cairo-perl/t/CairoPath.t,v 1.1 2005/07/12 20:29:49 tsch Exp $
#

use strict;
use warnings;
use Cairo;

use Test::More tests => 4;

use constant {
	IMG_WIDTH => 256,
	IMG_HEIGHT => 256,
};

my $surf = Cairo::ImageSurface->create ('rgb24', IMG_WIDTH, IMG_HEIGHT);
my $cr = Cairo::Context->create ($surf);

$cr->new_path;
$cr->move_to (1, 2);
$cr->line_to (3, 4);
$cr->curve_to (5, 6, 7, 8, 9, 10);
$cr->close_path;

my $path = $cr->copy_path;

is_deeply ($path->[0], { type => "move-to", points => [[1, 2]] });
is_deeply ($path->[1], { type => "line-to", points => [[3, 4]] });
is_deeply ($path->[2], { type => "curve-to", points => [[5, 6], [7, 8], [9, 10]] });
is_deeply ($path->[3], { type => "close-path", points => [] });

Index: CairoPattern.t
===================================================================
RCS file: /cvs/cairo/cairo-perl/t/CairoPattern.t,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- CairoPattern.t	12 Nov 2004 03:32:05 -0000	1.1
+++ CairoPattern.t	12 Jul 2005 20:29:49 -0000	1.2
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2004 by the cairo  perl team (see the file README)
+# Copyright (c) 2004-2005 by the cairo perl team (see the file README)
 #
 # Licensed under the LGPL, see LICENSE file for more information.
 #
@@ -8,9 +8,8 @@
 
 use strict;
 use warnings;
-use Data::Dumper;
 
-use Test::More tests => 6;
+use Test::More tests => 12;
 
 use constant {
 	IMG_WIDTH => 256,
@@ -19,30 +18,33 @@
 
 use Cairo;
 
-{
-	my $surf = Cairo::Surface->image_create ('RGB24', IMG_WIDTH,
-						 IMG_HEIGHT);
-	isa_ok (Cairo::Pattern->create_for_surface ($surf), 'Cairo::Pattern',
-		'Cairo::Pattern->create_for_surface');
-}
+my $surf = Cairo::ImageSurface->create ('rgb24', IMG_WIDTH, IMG_HEIGHT);
 
+my $pat = Cairo::SurfacePattern->create ($surf);
+isa_ok ($pat, 'Cairo::SurfacePattern');
+isa_ok ($pat, 'Cairo::Pattern');
 
-isa_ok (Cairo::Pattern->create_linear (1, 2, 3, 4), 'Cairo::Pattern',
-	'Cairo::Pattern->create_linear');
+$pat->set_extend ('none');
+is ($pat->get_extend, 'none', '$pat->set|get_extend');
 
-isa_ok (my $pat = Cairo::Pattern->create_radial (1, 2, 3, 4, 5, 6),
-	'Cairo::Pattern', 'Cairo::Pattern->create_radial');
+$pat->set_filter ('fast');
+is ($pat->get_filter, 'fast', '$pat->set|get_filter');
 
-$pat->add_color_stop (1, 0.5, 0.6, 0.7, 0.8);
+$pat = Cairo::LinearGradient->create (1, 2, 3, 4);
+isa_ok ($pat, 'Cairo::LinearGradient');
+isa_ok ($pat, 'Cairo::Gradient');
+isa_ok ($pat, 'Cairo::Pattern');
 
-{
-	my $matrix = Cairo::Matrix->create;
-	$pat->set_matrix ($matrix);
-	isa_ok ($pat->get_matrix, 'Cairo::Matrix', '$pat->get_matrix');
-}
+$pat = Cairo::RadialGradient->create (1, 2, 3, 4, 5, 6);
+isa_ok ($pat, 'Cairo::RadialGradient');
+isa_ok ($pat, 'Cairo::Gradient');
+isa_ok ($pat, 'Cairo::Pattern');
 
-$pat->set_extend ('NONE');
-is ($pat->get_extend, 'NONE', '$pat->set|get_extend');
+$pat->add_color_stop_rgb (1, 0.5, 0.6, 0.7);
+$pat->add_color_stop_rgba (1, 0.5, 0.6, 0.7, 0.8);
 
-$pat->set_filter ('FAST');
-is ($pat->get_filter, 'FAST', '$pat->set|get_filter');
+my $matrix = Cairo::Matrix->init_identity;
+$pat->set_matrix ($matrix);
+isa_ok ($pat->get_matrix, 'Cairo::Matrix');
+
+is ($pat->status, 'success');

Index: CairoSurface.t
===================================================================
RCS file: /cvs/cairo/cairo-perl/t/CairoSurface.t,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- CairoSurface.t	12 Nov 2004 03:32:05 -0000	1.1
+++ CairoSurface.t	12 Jul 2005 20:29:49 -0000	1.2
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2004 by the cairo  perl team (see the file README)
+# Copyright (c) 2004-2005 by the cairo perl team (see the file README)
 #
 # Licensed under the LGPL, see LICENSE file for more information.
 #
@@ -8,9 +8,8 @@
 
 use strict;
 use warnings;
-use Data::Dumper;
 
-use Test::More tests => 12;
+use Test::More tests => 18;
 
 use constant {
 	IMG_WIDTH => 256,
@@ -19,79 +18,67 @@
 
 use Cairo;
 
-isa_ok (my $surf = Cairo::Surface->image_create ('RGB24', IMG_WIDTH,
-						 IMG_HEIGHT),
-	'Cairo::Surface');
+my $surf = Cairo::ImageSurface->create ('rgb24', IMG_WIDTH, IMG_HEIGHT);
+isa_ok ($surf, 'Cairo::ImageSurface');
+isa_ok ($surf, 'Cairo::Surface');
 
-{
-	isa_ok ($surf->create_similar ('RGB24', IMG_WIDTH, IMG_HEIGHT),
-		'Cairo::Surface', '$surf->create_similar');
-}
+$surf = Cairo::ImageSurface->create_for_data ('Urgs!', 'rgb24',
+                                              IMG_WIDTH, IMG_HEIGHT, 23);
+isa_ok ($surf, 'Cairo::ImageSurface');
+isa_ok ($surf, 'Cairo::Surface');
 
-eval
-{
-	$surf->set_repeat (1);
-};
-is ($@, '', '$sufr->set_repeate');
+$surf = $surf->create_similar ('color', IMG_WIDTH, IMG_HEIGHT);
+isa_ok ($surf, 'Cairo::ImageSurface');
+isa_ok ($surf, 'Cairo::Surface');
 
-{
-	my $matrix = Cairo::Matrix->create;
-	$surf->set_matrix ($matrix);
-	isa_ok ($surf->get_matrix, 'Cairo::Matrix', '$surf->set|get_matrix');
-}
+$surf->set_device_offset (23, 42);
 
-$surf->set_filter ('FAST');
-is ($surf->get_filter, 'FAST', '$surf->set|get_filter');
+is ($surf->finish, 'success');
 
-# img isn't going to be very interesting
-my $outtmp = 't/out.tmp';
-open OUT, '>'.$outtmp
-	or die "failed to create output tmp file ($outtmp)";
-ok (*OUT, 'OUT support');
+SKIP: {
+	skip 'png surface', 3
+		unless Cairo::HAS_PNG_FUNCTIONS;
 
-SKIP:
-{
-	skip "png backend not supported in bound cairo", 1
-		unless ($Cairo::backends{png});
-	isa_ok (Cairo::Surface->png_create (*OUT, 'ARGB32', IMG_WIDTH, 
-					    IMG_HEIGHT), 'Cairo::Surface');
-}
+	$surf = Cairo::ImageSurface->create ('rgb24', IMG_WIDTH, IMG_HEIGHT);
+	is ($surf->write_to_png ('tmp.png'), 'success');
 
-SKIP:
-{
-	# XXX:
-	skip "ps backend currently hangs", 1;
+	$surf = Cairo::ImageSurface->create_from_png ('tmp.png');
+	isa_ok ($surf, 'Cairo::ImageSurface');
+	isa_ok ($surf, 'Cairo::Surface');
 
-	skip "ps backend not supported in bound cairo", 1
-		unless ($Cairo::backends{ps});
-	isa_ok (Cairo::Surface->ps_create (*OUT, IMG_WIDTH, IMG_HEIGHT,
-					   72, 72), 'Cairo::Surface');
+	unlink 'tmp.png';
 }
 
-SKIP:
-{
-	# XXX:
-	skip "xlib backend no way to get display and drawable", 1;
+SKIP: {
+	skip 'pdf surface', 4
+		unless Cairo::HAS_PDF_SURFACE;
 
-	skip "xlib backend not supported in bound cairo", 1
-		unless ($Cairo::backends{xlib});
-	isa_ok (Cairo::Surface->xlib_create (), 'Cairo::Surface');
-}
+	$surf = Cairo::PdfSurface->create ('tmp.pdf', IMG_WIDTH, IMG_HEIGHT);
+	isa_ok ($surf, 'Cairo::PdfSurface');
+	isa_ok ($surf, 'Cairo::Surface');
 
-SKIP:
-{
-	skip "xcb backend not supported in bound cairo", 1
-		unless ($Cairo::backends{xcb});
-	isa_ok (Cairo::Surface->xcb_create (), 'Cairo::Surface');
-}
+	$surf = $surf->create_similar ('alpha', IMG_WIDTH, IMG_HEIGHT);
+	isa_ok ($surf, 'Cairo::PdfSurface');
+	isa_ok ($surf, 'Cairo::Surface');
 
-SKIP:
-{
-	skip "glitz backend not supported in bound cairo", 1
-		unless ($Cairo::backends{glitz});
-	isa_ok (Cairo::Surface->glitz_create (), 'Cairo::Surface');
+	$surf->set_dpi (72, 72);
+
+	unlink 'tmp.pdf';
 }
 
-close OUT;
+SKIP: {
+	skip 'ps surface', 4
+		unless Cairo::HAS_PS_SURFACE;
 
-ok (unlink ($outtmp), 'rm tmpout');
+	$surf = Cairo::PsSurface->create ('tmp.ps', IMG_WIDTH, IMG_HEIGHT);
+	isa_ok ($surf, 'Cairo::PsSurface');
+	isa_ok ($surf, 'Cairo::Surface');
+
+	$surf = $surf->create_similar ('alpha', IMG_WIDTH, IMG_HEIGHT);
+	isa_ok ($surf, 'Cairo::PsSurface');
+	isa_ok ($surf, 'Cairo::Surface');
+
+	# $surf->set_dpi (72, 72);
+
+	unlink 'tmp.ps';
+}




More information about the cairo-commit mailing list