File: 20_cmp_image.t

package info (click to toggle)
libtest-image-gd-perl 0.03-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 96 kB
  • sloc: perl: 270; makefile: 2
file content (72 lines) | stat: -rw-r--r-- 2,528 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/perl

use strict;
use warnings;

use Test::Builder::Tester tests => 2;
use Test::More;
use File::Spec::Functions;

BEGIN { 
    use_ok('Test::Image::GD');
}

my $path_to_cpan_gif  = catdir('t', 'cpan.gif');
my $path_to_cpan2_gif = catdir('t', 'cpan2.gif');
my $path_to_perl_gif  = catdir('t', 'download_perl.gif');

{
    my $cpan = GD::Image->new(200, 100);
    $cpan->colorAllocate(255, 255, 255);
    $cpan->string(GD::gdSmallFont(), (10 * $_), (10 * $_), "CPAN Rules", $cpan->colorAllocate(0, 0, 0))
        foreach 1 .. 5;
    open GIF1, ">", $path_to_cpan_gif || die "Could not create test GIF file";
    print GIF1 $cpan->gif;
    close GIF1;
}
{
    my $cpan2 = GD::Image->new(200, 100);
    $cpan2->colorAllocate(255, 255, 255);
    $cpan2->string(GD::gdSmallFont(), (10 * $_), (10 * $_), "CPAN Rules", $cpan2->colorAllocate(0, 0, 0))
        foreach 1 .. 5;
    open GIF2, ">", $path_to_cpan2_gif || die "Could not create test GIF file";
    print GIF2 $cpan2->gif;
    close GIF2;
}
{
    my $perl = GD::Image->new(200, 100);
    $perl->colorAllocate(255, 255, 255);
    $perl->string(GD::gdSmallFont(), (10 * $_), (10 * $_), "Perl Rules", $perl->colorAllocate(0, 0, 0))
        foreach 1 .. 5;
    open GIF3, ">", $path_to_perl_gif || die "Could not create test GIF file";
    print GIF3 $perl->gif;
    close GIF3;
}

test_out("ok 1 - ... these are the exact same images");
test_out("ok 2 - ... these are the same images visually");
test_out("not ok 3 - ... these are not the same images");
test_err("#     Failed test (t/20_cmp_image.t at line 58)");
test_out("ok 4 - ... these are the exact same images");
test_out("ok 5 - ... these are the same images visually");
test_out("not ok 6 - ... these are not the same images");
test_err("#     Failed test (t/20_cmp_image.t at line 66)");

cmp_image($path_to_cpan_gif, $path_to_cpan_gif, '... these are the exact same images');
cmp_image($path_to_cpan_gif, $path_to_cpan2_gif, '... these are the same images visually');

cmp_image($path_to_cpan_gif, $path_to_perl_gif, '... these are not the same images');

my $cpan  = GD::Image->new($path_to_cpan_gif);
my $cpan2 = GD::Image->new($path_to_cpan2_gif);
my $perl  = GD::Image->new($path_to_perl_gif);

cmp_image($cpan, $cpan2, '... these are the exact same images');
cmp_image($cpan, $cpan2, '... these are the same images visually');
cmp_image($cpan, $perl, '... these are not the same images');

test_test("cmp_image works");

unlink $path_to_cpan_gif;
unlink $path_to_cpan2_gif;
unlink $path_to_perl_gif;