18_unicode.t 1.55 KB
Newer Older
1 2 3 4 5 6
#!/usr/bin/perl -w

use strict;
use Wx;
use lib './t';
use Tests_Helper qw(in_frame);
7
use Test::More 'tests' => 12;
8
use utf8;
9 10 11 12
use Encode qw(is_utf8);

my $ascii   = 'Abcde';
my $ascii2  = 'XXX';
13
my $utf8    = 'Àbcdë';
14 15 16 17 18 19 20 21 22 23 24 25
my $unicode = "\x{1234}";

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 );

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
        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 ) );
        };

43 44 45 46 47 48
        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;

49 50
            $label->SetLabel( $utf8 );
            is( $label->GetLabel, $utf8 );
51

52
            ok( is_utf8( $utf8 ) );
53 54 55 56 57 58 59 60 61
            ok( is_utf8( $label->GetLabel ) );

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

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