Add libwx-perl
[pkg-perl] / deb-src / libwx-perl / libwx-perl-0.96 / t / 18_unicode.t
1 #!/usr/bin/perl -w
2
3 use strict;
4 use Wx;
5 use lib './t';
6 use Tests_Helper qw(in_frame);
7 use Test::More 'tests' => 12;
8 use encoding qw(iso-8859-1);
9 use Encode qw(is_utf8);
10
11 my $ascii   = 'Abcde';
12 my $ascii2  = 'XXX';
13 my $latin1  = 'Àbcdë';
14 my $unicode = "\x{1234}";
15
16 # needs to be upgraded to characters because wxPerl converts
17 # based upon the current locale, which might not be Latin-1
18 utf8::upgrade( $latin1 ); # safe beacuse it's latin1
19
20 in_frame(
21     sub {
22         my $self = shift;
23
24         my $label = Wx::StaticText->new( $self, -1, $ascii );
25         is( $label->GetLabel, $ascii );
26
27         $label->SetLabel( $ascii2 );
28         is( $label->GetLabel, $ascii2 );
29
30         SKIP: {
31             skip "Only meaningful in ANSI mode", 4
32                 if Wx::wxUNICODE;
33
34             # it would be better to use the latin1 label, but it might
35             # not round trip if the GUI locale is not latin1
36             $label->SetLabel( $ascii );
37
38             Wx::SetAlwaysUTF8( 1 );
39             is( $label->GetLabel, $ascii );
40             ok( is_utf8( $label->GetLabel ) );
41
42             Wx::SetAlwaysUTF8( 0 );
43             is( $label->GetLabel, $ascii );
44             ok( !is_utf8( $label->GetLabel ) );
45         };
46
47         SKIP: {
48             skip "Unicode support needed for the tests", 6
49                 unless Wx::wxUNICODE;
50             skip "wrongly asserts under 2.5.x", 6
51                 if Wx::wxVERSION < 2.006;
52
53             $label->SetLabel( $latin1 );
54             is( $label->GetLabel, $latin1 );
55
56             ok( is_utf8( $latin1 ) );
57             ok( is_utf8( $label->GetLabel ) );
58
59             $label->SetLabel( $unicode );
60             is( $label->GetLabel, $unicode );
61
62             ok( is_utf8( $unicode ) );
63             ok( is_utf8( $label->GetLabel ) );
64         }
65     } );