File: 18_unicode.t

package info (click to toggle)
libwx-perl 1%3A0.9928-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,300 kB
  • ctags: 2,322
  • sloc: cpp: 11,044; perl: 8,646; ansic: 710; makefile: 48
file content (65 lines) | stat: -rw-r--r-- 1,785 bytes parent folder | download
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
#!/usr/bin/perl -w

use strict;
use Wx;
use lib './t';
use Tests_Helper qw(in_frame);
use Test::More 'tests' => 12;
#use encoding qw(iso-8859-1);
use Encode qw(is_utf8);

my $ascii   = 'Abcde';
my $ascii2  = 'XXX';
my $latin1  = 'bcd';
my $unicode = "\x{1234}";

# needs to be upgraded to characters because wxPerl converts
# based upon the current locale, which might not be Latin-1
utf8::upgrade( $latin1 ); # safe beacuse it's latin1

in_frame(
    sub {
        my $self = shift;

        my $label = Wx::StaticText->new( $self, -1, $ascii );
        is( $label->GetLabel, $ascii );

        $label->SetLabel( $ascii2 );
        is( $label->GetLabel, $ascii2 );

        SKIP: {
            skip "Only meaningful in ANSI mode", 4
                if Wx::wxUNICODE;

            # it would be better to use the latin1 label, but it might
            # not round trip if the GUI locale is not latin1
            $label->SetLabel( $ascii );

            Wx::SetAlwaysUTF8( 1 );
            is( $label->GetLabel, $ascii );
            ok( is_utf8( $label->GetLabel ) );

            Wx::SetAlwaysUTF8( 0 );
            is( $label->GetLabel, $ascii );
            ok( !is_utf8( $label->GetLabel ) );
        };

        SKIP: {
            skip "Unicode support needed for the tests", 6
                unless Wx::wxUNICODE;
            skip "wrongly asserts under 2.5.x", 6
                if Wx::wxVERSION < 2.006;

            $label->SetLabel( $latin1 );
            is( $label->GetLabel, $latin1 );

            ok( is_utf8( $latin1 ) );
            ok( is_utf8( $label->GetLabel ) );

            $label->SetLabel( $unicode );
            is( $label->GetLabel, $unicode );

            ok( is_utf8( $unicode ) );
            ok( is_utf8( $label->GetLabel ) );
        }
    } );