File: basic.t

package info (click to toggle)
perl-tk 1%3A804.036-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 35,076 kB
  • sloc: ansic: 349,553; perl: 52,292; sh: 17,904; makefile: 5,699; asm: 3,565; ada: 1,681; pascal: 1,089; cpp: 1,006; yacc: 883; cs: 879
file content (67 lines) | stat: -rwxr-xr-x 1,463 bytes parent folder | download | duplicates (9)
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
#!perl

use strict;
use Tk;
use FindBin;

BEGIN {
    if (!eval q{
	use Test::More;
	1;
    }) {
	print "1..0 # skip: no Test::More module\n";
	exit;
    }
}

plan tests => 5;

use_ok('Tk::PNG');

my $file = (@ARGV) ? shift : "$FindBin::RealBin/../pngtest.png";

my $mw = MainWindow->new;
$mw->geometry('+10+10');

{
    my $image = $mw->Photo('-format' => "png", -file => $file);
    ok($image, "Loaded PNG image from $file");
    $mw->Label(-image => $image)->pack;
    $mw->update;
}

my $image_data = do {
    open my $fh, $file or die "Cannot load $file: $!";
    binmode $fh; 
    local $/;
    <$fh>;
};

SKIP: {
    skip("Needs MIME::Base64 for -data options", 1)
	if !eval { require MIME::Base64; 1 };

    my $image = $mw->Photo('-format' => 'png', -data => MIME::Base64::encode_base64($image_data));
    ok($image, "Loaded PNG image from base64 encoded data");
    $mw->Label(-image => $image)->pack;
    $mw->update;

    my $out_image_data = $image->data(-format => 'png');
    my $image2 = $mw->Photo('-format' => 'png', -data => $out_image_data);
    ok($image2, "Roundtrip image data");
    $mw->Label(-image => $image2)->pack;
    $mw->update;
}

SKIP: {
    skip("Loading PNG image from binary data NYI *TODO*", 1);

    my $image = $mw->Photo('-format' => 'png', -data => $image_data);
    ok($image, "Loaded PNG image from binary data");
    $mw->Label(-image => $image)->pack;
    $mw->update;
}

$mw->after(500,[destroy => $mw]);
MainLoop;