File: unicode.t

package info (click to toggle)
perl-tk 1%3A804.036%2Bdfsg1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 35,284 kB
  • sloc: ansic: 349,560; perl: 52,292; sh: 12,678; makefile: 5,700; asm: 3,565; ada: 1,681; pascal: 1,082; cpp: 1,006; yacc: 883; cs: 879
file content (189 lines) | stat: -rwxr-xr-x 4,685 bytes parent folder | download | duplicates (5)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/usr/bin/perl -w
# -*- perl -*-

#
# Author: Slaven Rezic
#

use strict;
use FindBin;
use lib $FindBin::RealBin;

use Encode qw(encode);
use File::Copy qw(cp);
use File::Spec::Functions qw(catfile);
use File::Temp qw(tempdir);

use Tk;
use Tk::FBox;

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

use TkTest qw(catch_grabs);

if (!defined $ENV{BATCH}) { $ENV{BATCH} = 1 }

my $dir = tempdir(CLEANUP => 1);
die "Cannot create temporary directory" if !$dir;

my $encoding = "iso-8859-1";
if ($^O eq 'darwin') {
    $encoding = 'utf-8';
}

# Preparations. May fail on some systems, see
# https://rt.cpan.org/Ticket/Display.html?id=75347
my($umlautdir, $umlautgif, $umlautxpm, $umlautxbm, $eurogif);
eval {
    $umlautdir = catfile $dir, encode($encoding, "");
    mkdir $umlautdir
	or die "Cannot create $umlautdir: $!";

    $umlautgif = catfile $umlautdir, encode($encoding, ".gif");
    cp(Tk->findINC("Xcamel.gif"), $umlautgif)
	or die "Can't copy Xcamel.gif to $umlautgif: $!";

    $umlautxpm = catfile $umlautdir, encode($encoding, ".xpm");
    cp(Tk->findINC("Camel.xpm"), $umlautxpm)
	or die "Can't copy Camel.xpm to $umlautxpm: $!";
    utf8::upgrade($umlautxpm); # upgrade to utf8 it before Perl/Tk...

    $umlautxbm = catfile $umlautdir, encode($encoding, ".xbm");
    cp(Tk->findINC("Tk.xbm"), $umlautxbm)
	or die "Can't copy Tk.xbm to $umlautxbm: $!";

    $eurogif = catfile $umlautdir, "\xe2\x82\xac.gif"; # the utf8-representation of \x{20ac} (Euro sign)
    cp(Tk->findINC("Xcamel.gif"), $eurogif)
	or die "Can't copy Xcamel.gif to $eurogif: $!";
};
if ($@) {
    plan skip_all => $@;
    exit 0;
}

plan tests => 13;

my $mw = tkinit;
$mw->geometry("+10+10");

######################################################################
# Various image formats
{
    my $p = eval { $mw->Photo(-file => $umlautgif) };
    is($@, "", "Create a photo with non-ascii chars in filename");
    $p->delete if $p;
}

{
    my $p = eval { $mw->Pixmap(-file => $umlautxpm) };
    is($@, "", "Create a pixmap with non-ascii chars in filename");
    $p->delete if $p;
}

{
    my $p = eval { $mw->Bitmap(-file => $umlautxbm) };
    is($@, "", "Create a bitmap with non-ascii chars in filename");
    $p->delete if $p;
}

{
    my $p = eval { $mw->Photo(-file => $eurogif) };
    is($@, "", "Create a photo with chars > 0xff in filename");
    $p->delete if $p;
}

######################################################################
# Bitmaps from file
{
    my $l = eval { $mw->Label(-bitmap => '@' . $umlautxbm) };
    is($@, "", "Create a widget with bitmap from filename with non-ascii chars");
    if (Tk::Exists($l)) {
	$l->pack;
	$l->update;
	$l->after(100);
	$l->destroy;
    }
}

######################################################################
# File box
catch_grabs {
    my $fb = $mw->FBox;
    $fb->configure(-initialdir => $umlautdir);
    $fb->after(500, sub { $fb->destroy }) if $ENV{BATCH};
    my $value = $fb->Show;
    Dump($value) if defined $value;
    pass("Setting FBox -initialdir with non-ascii directory name");
} 1;

catch_grabs {
    my $fb = $mw->FBox;
    $fb->configure(-initialfile => $umlautgif);
    $fb->after(500, sub { $fb->destroy }) if $ENV{BATCH};
    my $value = $fb->Show;
    Dump($value) if defined $value;
    pass("Setting FBox -initialfile with non-ascii file name");
} 1;

######################################################################
# Text
{
    my @warnings;
    my $t = $mw->Text->pack;
    $t->insert("end", "\xfc" x 20);
    $t->markSet('insert','end');
    $t->focusForce;
    $t->update;

    {
	@warnings = ();
	local $SIG{__WARN__} = sub { push @warnings, @_ };
	$t->eventGenerate('<Control-KeyPress>', -keysym=>'Left');
	$t->after(100);
	$t->update;

    }
    is("@warnings", "", "No utf-8 warnings");
    is($t->index("insert"), "1.0", "Text: left word movement");

    {
	@warnings = ();
	local $SIG{__WARN__} = sub { push @warnings, @_ };
	$t->eventGenerate('<Control-KeyPress>', -keysym=>'Right');
     	$t->after(100);
	$t->update;
    }
    is("@warnings", "", "No utf-8 warnings");
    is($t->index("insert"), "1.20", "Text: right word movement"); # XXX 1.20 correct?

    $t->destroy;
}

{
    local $TODO = "Fix utf-8 warnings+errors in Text widget";

    my @warnings;
    my $t = $mw->Text->pack;
    $t->insert("end", "\xfc" x 20);
    $t->markSet('anchor',$t->index("current -1c"));
    {
	@warnings = ();
	local $SIG{__WARN__} = sub { push @warnings, @_ };
	is($t->index("1.19 wordstart"), "1.0");
    }
    is("@warnings", "", "No utf-8 warnings");
    $t->destroy;
}

#MainLoop;

__END__