File: 16_stream.t

package info (click to toggle)
libwx-perl 1%3A0.9909-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,912 kB
  • sloc: cpp: 9,728; perl: 8,182; ansic: 626; makefile: 41
file content (60 lines) | stat: -rwxr-xr-x 1,287 bytes parent folder | download | duplicates (6)
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
#!/usr/bin/perl -w

use strict;
use Wx qw(wxBITMAP_TYPE_ICO);
use lib './t';
use Test::More 'tests' => 8;
use Fatal qw(open);

my $app = Wx::SimpleApp->new;
Wx::InitAllImageHandlers;

sub _slurp {
    local $/;
    open my $fh, '< :raw', $_[0];
    return <$fh>;
}

# plain Perl handle (file)
{
    open my $fh, '< :raw', 'wxpl.ico';
    my $img = Wx::Image->new( $fh, wxBITMAP_TYPE_ICO );
    ok( $img->Ok );
    is( $img->GetWidth, 32 );
}

# in-memory file (uses PerlIO, hasn't a filehandle
SKIP: {
    skip 'Perl 5.8 required', 2 if $] < 5.008;

    my $data = _slurp( 'wxpl.ico' );
    open my $fh, '<', \$data;
    my $img = Wx::Image->new( $fh, wxBITMAP_TYPE_ICO );
    ok( $img->Ok );
    is( $img->GetWidth, 32 );
    
}

# Tied filehandles
SKIP: {
    eval { require IO::String };
    skip 'IO::String required', 2 if $@;

    my $data = _slurp( 'wxpl.ico' );
    my $fh = IO::String->new( $data );
    my $img = Wx::Image->new( $fh, wxBITMAP_TYPE_ICO );
    ok( $img->Ok );
    is( $img->GetWidth, 32 );
}

SKIP: {
    eval { require IO::Scalar };
    skip 'IO::Scalar required', 2 if $@;

    my $data = _slurp( 'wxpl.ico' );
    my $fh = IO::Scalar->new( \$data );
    my $img = Wx::Image->new( $fh, wxBITMAP_TYPE_ICO );
    ok( $img->Ok );
    is( $img->GetWidth, 32 );
}