Commit a1cd2e45 authored by Torsten Schönfeld's avatar Torsten Schönfeld
Browse files

Make t/CairoPath.t more robust

The end of a path that took a round trip into cairo and back might differ
for different versions of cairo.  Hence, compare only the beginning with
the expected path.
parent 21dd8a06
......@@ -11,17 +11,11 @@ use strict;
use warnings;
use Cairo;
use Test::More;
use Test::More tests => 18;
use constant IMG_WIDTH => 256;
use constant IMG_HEIGHT => 256;
if (Cairo::VERSION >= Cairo::VERSION_ENCODE (1, 4, 0)) {
plan tests => 6;
} else {
plan skip_all => 'path behavior not predictable on cairo < 1.4';
}
my $surf = Cairo::ImageSurface->create ('rgb24', IMG_WIDTH, IMG_HEIGHT);
my $cr = Cairo::Context->create ($surf);
......@@ -40,14 +34,7 @@ my $expected_path = [
];
my $path = $cr->copy_path;
is_deeply ($path, $expected_path);
sub paths_agree {
my ($cr, $path, $expected_path) = @_;
$cr->new_path;
$cr->append_path ($path);
is_deeply ($cr->copy_path, $expected_path);
}
paths_agree ($path, $expected_path);
# Modifying single point values.
foreach ($path, $expected_path) {
......@@ -57,21 +44,21 @@ foreach ($path, $expected_path) {
$_->[2]{points}[2][0] = 99;
$_->[2]{points}[2][1] = 1010;
}
paths_agree ($cr, $path, $expected_path);
path_round_trip_ok ($cr, $path, $expected_path);
# Modifying single points.
foreach ($path, $expected_path) {
$_->[1]{points}[0] = [333, 444];
$_->[2]{points}[2] = [77, 88];
}
paths_agree ($cr, $path, $expected_path);
path_round_trip_ok ($cr, $path, $expected_path);
# Replacing all points.
foreach ($path, $expected_path) {
$_->[1]{points} = [[3333, 4444]];
$_->[2]{points} = [[55, 66], [77, 88], [99, 1010]];
}
paths_agree ($cr, $path, $expected_path);
path_round_trip_ok ($cr, $path, $expected_path);
# Replacing and adding path segments.
my @cloned_path = @{$path};
......@@ -86,9 +73,24 @@ foreach (\@cloned_path, $expected_path) {
type => 'line-to',
points => [[23, 42]] };
}
paths_agree ($cr, \@cloned_path, $expected_path);
path_round_trip_ok ($cr, \@cloned_path, $expected_path);
# Passing bare arrays into Cairo.
$cr->new_path;
$cr->append_path ($expected_path);
is_deeply ($cr->copy_path, $expected_path);
paths_agree ($cr->copy_path, $expected_path);
sub path_round_trip_ok {
my ($cr, $path, $expected_path) = @_;
$cr->new_path;
$cr->append_path ($path);
paths_agree ($cr->copy_path, $expected_path);
}
sub paths_agree {
my ($path, $expected_path) = @_;
# Only the first three entries seem to be reliable across cairo versions.
for (0..2) {
is_deeply ($path->[$_], $expected_path->[$_]);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment