| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Test::Image::GD; |
|
3
|
|
|
|
|
|
|
|
|
4
|
5
|
|
|
5
|
|
162363
|
use strict; |
|
|
5
|
|
|
|
|
12
|
|
|
|
5
|
|
|
|
|
192
|
|
|
5
|
5
|
|
|
5
|
|
27
|
use warnings; |
|
|
5
|
|
|
|
|
8
|
|
|
|
5
|
|
|
|
|
136
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
5
|
|
|
5
|
|
25
|
use Test::Builder (); |
|
|
5
|
|
|
|
|
13
|
|
|
|
5
|
|
|
|
|
92
|
|
|
8
|
5
|
|
|
5
|
|
28
|
use Scalar::Util 'blessed'; |
|
|
5
|
|
|
|
|
16
|
|
|
|
5
|
|
|
|
|
628
|
|
|
9
|
5
|
|
|
5
|
|
2186
|
use GD ':cmp'; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
require Exporter; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
|
14
|
|
|
|
|
|
|
our @ISA = ('Exporter'); |
|
15
|
|
|
|
|
|
|
our @EXPORT = qw( |
|
16
|
|
|
|
|
|
|
cmp_image |
|
17
|
|
|
|
|
|
|
size_ok |
|
18
|
|
|
|
|
|
|
height_ok |
|
19
|
|
|
|
|
|
|
width_ok |
|
20
|
|
|
|
|
|
|
); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $Test = Test::Builder->new; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub cmp_image ($$;$) { |
|
25
|
|
|
|
|
|
|
my ($got, $expected, $message) = @_; |
|
26
|
|
|
|
|
|
|
_coerce_image($got); |
|
27
|
|
|
|
|
|
|
_coerce_image($expected); |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
if ($got->compare($expected) & GD_CMP_IMAGE) { |
|
30
|
|
|
|
|
|
|
$Test->ok(0, $message); |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
else { |
|
33
|
|
|
|
|
|
|
$Test->ok(1, $message); |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub size_ok ($$;$) { |
|
38
|
|
|
|
|
|
|
my ($got, $expected, $message) = @_; |
|
39
|
|
|
|
|
|
|
_coerce_image($got); |
|
40
|
|
|
|
|
|
|
(ref($expected) && ref($expected) eq 'ARRAY') |
|
41
|
|
|
|
|
|
|
|| die "expected must be an ARRAY ref"; |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
if ($got->width == $expected->[0] && |
|
44
|
|
|
|
|
|
|
$got->height == $expected->[1] ){ |
|
45
|
|
|
|
|
|
|
$Test->ok(1, $message); |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
else { |
|
48
|
|
|
|
|
|
|
$Test->diag("... (image => (width, height))\n" . |
|
49
|
|
|
|
|
|
|
" w: (" . $got->width . " => " . $expected->[0] . ")\n" . |
|
50
|
|
|
|
|
|
|
" h: (" . $got->height . " => " . $expected->[1] . ")"); |
|
51
|
|
|
|
|
|
|
$Test->ok(0, $message); |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub height_ok ($$;$) { |
|
56
|
|
|
|
|
|
|
my ($got, $expected, $message) = @_; |
|
57
|
|
|
|
|
|
|
_coerce_image($got); |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
if ($got->height == $expected){ |
|
60
|
|
|
|
|
|
|
$Test->ok(1, $message); |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
else { |
|
63
|
|
|
|
|
|
|
$Test->diag("... (image => (height))\n" . |
|
64
|
|
|
|
|
|
|
" h: (" . $got->height . " => " . $expected . ")"); |
|
65
|
|
|
|
|
|
|
$Test->ok(0, $message); |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub width_ok ($$;$) { |
|
70
|
|
|
|
|
|
|
my ($got, $expected, $message) = @_; |
|
71
|
|
|
|
|
|
|
_coerce_image($got); |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
if ($got->width == $expected){ |
|
74
|
|
|
|
|
|
|
$Test->ok(1, $message); |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
else { |
|
77
|
|
|
|
|
|
|
$Test->diag("... (image => (width))\n" . |
|
78
|
|
|
|
|
|
|
" w: (" . $got->width . " => " . $expected . ")"); |
|
79
|
|
|
|
|
|
|
$Test->ok(0, $message); |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
## Utility Methods |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _coerce_image { |
|
86
|
|
|
|
|
|
|
unless (blessed($_[0]) && $_[0]->isa('GD::Image')) { |
|
87
|
|
|
|
|
|
|
$_[0] = GD::Image->new($_[0]) |
|
88
|
|
|
|
|
|
|
|| die "Could not create GD::Image instance with : " . $_[0]; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__END__ |