File: xbm.t

package info (click to toggle)
libimage-base-bundle-perl 2%2B~1.17%2B~1.13%2B~1.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 332 kB
  • sloc: perl: 2,302; makefile: 44
file content (59 lines) | stat: -rwxr-xr-x 1,877 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
#!/usr/bin/perl -w

# Copyright (c) 2000 Mark Summerfield. All Rights Reserved.
# May be used/distributed under the GPL.


use strict ;

use File::Temp qw(tempfile);
use Test::More tests => 19 ;

use Image::Xbm ;
pass 'loaded module' ;

my(undef, $fp) = tempfile('image-xbm-XXXXXXXX', SUFFIX => '.xbm', UNLINK => 1);

my $i = Image::Xbm->new_from_string( "#####\n#---#\n-###-\n--#--\n--#--\n#####" ) ;
isa_ok $i, 'Image::Xbm' ;
is $i->as_binstring, '11111100010111000100001001111100', 'expected new_from_string result' ;

my $j = $i->new ;
isa_ok $j, 'Image::Xbm' ;
is $j->as_binstring, '11111100010111000100001001111100', 'expected clone result' ;

$i->save( $fp ) ;
ok -e $fp, 'saved xbm file exists' ;

my $s = $i->serialise ;
ok $s, 'call serialiase' ;

my $k = Image::Xbm->new_from_serialised( $s ) ;
isa_ok $k, 'Image::Xbm' ;
ok $k->is_equal( $i ), 'new_from_serialised is_equal' ;

$i = undef ;
ok !defined $i, 'destroy image' ;

$i = Image::Xbm->new( -file => $fp ) ;
isa_ok $i, 'Image::Xbm' ;
is $i->as_binstring, '11111100010111000100001001111100', 'loaded image from file' ;
is $i->get( -file ), $fp, '-file accessor' ;
is $i->get( -width ), 5, '-width accessor' ;
is $i->get( -height ), 6, '-height accessor' ;

{
    open my $fh, '<', "$fp" or die "Can't open previously created temporary file $fp: $!" ;
    my $ixbm = Image::Xbm->new( -file => $fh ) ;
    isa_ok $i, 'Image::Xbm' ;
    is $i->as_binstring, '11111100010111000100001001111100', 'loaded image from filehandle' ;
}

{
    open my $fh, '<', "$fp" or die "Can't open previously created temporary file $fp: $!" ;
    my $xbm_string = do { local $/; <$fh> } ;
    open my $scalar_fh, '<', \$xbm_string or die $! ;
    my $ixbm = Image::Xbm->new( -file => $scalar_fh ) ;
    isa_ok $i, 'Image::Xbm' ;
    is $i->as_binstring, '11111100010111000100001001111100', 'loaded image from scalar filehandle' ;
}