[cairo-commit] cairo-perl/t CairoSurface.t,1.5,1.6

Torsten Schoenfeld commit at pdx.freedesktop.org
Sun May 14 06:43:12 PDT 2006


Committed by: tsch

Update of /cvs/cairo/cairo-perl/t
In directory kemper:/tmp/cvs-serv17130/t

Modified Files:
	CairoSurface.t 
Log Message:
	* t/CairoSurface.t, CairoSurface.xs: Remove
	Cairo::Surface::finish; it's memory management related and not
	needed, as far as I can tell.  Scream if you used it.

	* t/CairoSurface.t, CairoSurface.xs: Bind and test
	cairo_surface_write_to_png_stream,
	cairo_image_surface_create_from_png_stream,
	cairo_pdf_surface_create_for_stream, and
	cairo_ps_surface_create_for_stream.

	* CairoSurface.xs: Don't leak cairo_surface_create_similar's
	return value.

	* cairo-perl-private.h: Remove CAIRO_PERL_UNUSED.

	* cairo-perl-private.h, Cairo.xs, CairoFont.xs, CairoMatrix.xs,
	CairoPattern.xs: Rename pcairo_copy_matrix to
	cairo_perl_copy_matrix.

	* TODO: Update.


Index: CairoSurface.t
===================================================================
RCS file: /cvs/cairo/cairo-perl/t/CairoSurface.t,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- CairoSurface.t	7 May 2006 14:17:39 -0000	1.5
+++ CairoSurface.t	14 May 2006 13:43:10 -0000	1.6
@@ -9,7 +9,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 21;
+use Test::More tests => 42;
 
 use constant {
 	IMG_WIDTH => 256,
@@ -37,8 +37,6 @@
 is ($surf->status, 'success');
 is ($surf->get_type, 'image');
 
-$surf->finish;
-
 isa_ok ($surf->get_font_options, 'Cairo::FontOptions');
 
 $surf->mark_dirty;
@@ -46,21 +44,60 @@
 $surf->flush;
 
 SKIP: {
-	skip 'png surface', 3
+	skip 'png surface', 16
 		unless Cairo::HAS_PNG_FUNCTIONS;
 
 	$surf = Cairo::ImageSurface->create ('rgb24', IMG_WIDTH, IMG_HEIGHT);
 	is ($surf->write_to_png ('tmp.png'), 'success');
+	
+	is ($surf->write_to_png_stream (sub {
+		my ($closure, $data) = @_;
+		is ($closure, 'blub');
+		like ($data, qr/PNG/);
+		die 'write-error';
+	}, 'blub'), 'no-memory');
+	
+	is ($surf->write_to_png_stream (sub {
+		my ($closure, $data) = @_;
+		is ($closure, undef);
+		like ($data, qr/PNG/);
+		die 'write-error';
+	}), 'no-memory');
 
 	$surf = Cairo::ImageSurface->create_from_png ('tmp.png');
 	isa_ok ($surf, 'Cairo::ImageSurface');
 	isa_ok ($surf, 'Cairo::Surface');
 
+	open my $fh, 'tmp.png';
+	$surf = Cairo::ImageSurface->create_from_png_stream (sub {
+		my ($closure, $length) = @_;
+		my $buffer;
+
+		if ($length != sysread($fh, $buffer, $length)) {
+			die 'no-memory';
+		}
+
+		return $buffer;
+	});
+	isa_ok ($surf, 'Cairo::ImageSurface');
+	isa_ok ($surf, 'Cairo::Surface');
+	is ($surf->status, 'success');
+	close $fh;
+
+	$surf = Cairo::ImageSurface->create_from_png_stream (sub {
+		my ($closure, $length) = @_;
+		is ($closure, 'blub');
+		die 'read-error';
+	}, 'blub');
+	isa_ok ($surf, 'Cairo::ImageSurface');
+	isa_ok ($surf, 'Cairo::Surface');
+	is ($surf->status, 'read-error');
+
 	unlink 'tmp.png';
 }
 
 SKIP: {
-	skip 'pdf surface', 4
+	skip 'pdf surface', 8
 		unless Cairo::HAS_PDF_SURFACE;
 
 	$surf = Cairo::PdfSurface->create ('tmp.pdf', IMG_WIDTH, IMG_HEIGHT);
@@ -76,10 +113,19 @@
 	isa_ok ($surf, 'Cairo::Surface');
 
 	unlink 'tmp.pdf';
+
+	$surf = Cairo::PdfSurface->create_for_stream (sub {
+		my ($closure, $data) = @_;
+		is ($closure, 'blub');
+		like ($data, qr/PDF/);
+		die 'write-error';
+	}, 'blub', IMG_WIDTH, IMG_HEIGHT);
+	isa_ok ($surf, 'Cairo::PdfSurface');
+	isa_ok ($surf, 'Cairo::Surface');
 }
 
 SKIP: {
-	skip 'ps surface', 4
+	skip 'ps surface', 8
 		unless Cairo::HAS_PS_SURFACE;
 
 	$surf = Cairo::PsSurface->create ('tmp.ps', IMG_WIDTH, IMG_HEIGHT);
@@ -99,4 +145,13 @@
 	isa_ok ($surf, 'Cairo::Surface');
 
 	unlink 'tmp.ps';
+
+	$surf = Cairo::PsSurface->create_for_stream (sub {
+		my ($closure, $data) = @_;
+		is ($closure, 'blub');
+		like ($data, qr/PS/);
+		die 'write-error';
+	}, 'blub', IMG_WIDTH, IMG_HEIGHT);
+	isa_ok ($surf, 'Cairo::PsSurface');
+	isa_ok ($surf, 'Cairo::Surface');
 }



More information about the cairo-commit mailing list