Debian Codegraph @

PNG/t/basic.t

raw
1 #!perl
2
3 use strict;
4 use Tk;
5 use FindBin;
6
7 BEGIN {
8 if (!eval q{
9 use Test::More;
10 1;
11 }) {
12 print "1..0 # skip: no Test::More module\n";
13 exit;
14 }
15 }
16
17 plan tests => 5;
18
19 use_ok('Tk::PNG');
20
21 my $file = (@ARGV) ? shift : "$FindBin::RealBin/../pngtest.png";
22
23 my $mw = MainWindow->new;
24 $mw->geometry('+10+10');
25
26 {
27 my $image = $mw->Photo('-format' => "png", -file => $file);
28 ok($image, "Loaded PNG image from $file");
29 $mw->Label(-image => $image)->pack;
30 $mw->update;
31 }
32
33 my $image_data = do {
34 open my $fh, $file or die "Cannot load $file: $!";
35 binmode $fh;
36 local $/;
37 <$fh>;
38 };
39
40 SKIP: {
41 skip("Needs MIME::Base64 for -data options", 1)
42 if !eval { require MIME::Base64; 1 };
43
44 my $image = $mw->Photo('-format' => 'png', -data => MIME::Base64::encode_base64($image_data));
45 ok($image, "Loaded PNG image from base64 encoded data");
46 $mw->Label(-image => $image)->pack;
47 $mw->update;
48
49 my $out_image_data = $image->data(-format => 'png');
50 my $image2 = $mw->Photo('-format' => 'png', -data => $out_image_data);
51 ok($image2, "Roundtrip image data");
52 $mw->Label(-image => $image2)->pack;
53 $mw->update;
54 }
55
56 SKIP: {
57 skip("Loading PNG image from binary data NYI *TODO*", 1);
58
59 my $image = $mw->Photo('-format' => 'png', -data => $image_data);
60 ok($image, "Loaded PNG image from binary data");
61 $mw->Label(-image => $image)->pack;
62 $mw->update;
63 }
64
65 $mw->after(500,[destroy => $mw]);
66 MainLoop;
67