Compress::Zlib becomes zlib agnostic
[p5sagit/p5-mst-13.2.git] / ext / Compress / Zlib / t / 23misc.t
CommitLineData
16816334 1BEGIN {
d695c1a1 2 if ($ENV{PERL_CORE}) {
16816334 3 chdir 't' if -d 't';
1a6a8453 4 @INC = ("../lib", "lib/compress");
16816334 5 }
6}
642e522c 7
8use lib 't';
9use strict;
10use warnings;
11use bytes;
12
13use Test::More ;
14use ZlibTestUtils;
15
16BEGIN {
17 # use Test::NoWarnings, if available
18 my $extra = 0 ;
19 $extra = 1
20 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
21
1a6a8453 22 plan tests => 30 + $extra ;
642e522c 23
24
25 use_ok('Compress::Zlib::Common');
26
27 use_ok('Compress::Zlib::ParseParameters');
28
642e522c 29}
30
31
32# Compress::Zlib::Common;
33
34sub My::testParseParameters()
35{
36 eval { ParseParameters(1, {}, 1) ; };
37 like $@, mkErr(': Expected even number of parameters, got 1'),
38 "Trap odd number of params";
39
40 eval { ParseParameters(1, {}, undef) ; };
41 like $@, mkErr(': Expected even number of parameters, got 1'),
42 "Trap odd number of params";
43
44 eval { ParseParameters(1, {}, []) ; };
45 like $@, mkErr(': Expected even number of parameters, got 1'),
46 "Trap odd number of params";
47
1a6a8453 48 eval { ParseParameters(1, {'Fred' => [1, 1, Parse_boolean, 0]}, Fred => 'joe') ; };
49 like $@, mkErr("Parameter 'Fred' must be an int, got 'joe'"),
642e522c 50 "wanted unsigned, got undef";
51
1a6a8453 52 eval { ParseParameters(1, {'Fred' => [1, 1, Parse_unsigned, 0]}, Fred => undef) ; };
53 like $@, mkErr("Parameter 'Fred' must be an unsigned int, got 'undef'"),
54 "wanted unsigned, got undef";
55
56 eval { ParseParameters(1, {'Fred' => [1, 1, Parse_signed, 0]}, Fred => undef) ; };
57 like $@, mkErr("Parameter 'Fred' must be a signed int, got 'undef'"),
642e522c 58 "wanted signed, got undef";
59
1a6a8453 60 eval { ParseParameters(1, {'Fred' => [1, 1, Parse_signed, 0]}, Fred => 'abc') ; };
642e522c 61 like $@, mkErr("Parameter 'Fred' must be a signed int, got 'abc'"),
62 "wanted signed, got 'abc'";
63
1a6a8453 64 my $got = ParseParameters(1, {'Fred' => [1, 1, Parse_store_ref, 0]}, Fred => 'abc') ;
642e522c 65 is ${ $got->value('Fred') }, "abc", "Parse_store_ref" ;
66
1a6a8453 67 $got = ParseParameters(1, {'Fred' => [1, 1, 0x1000000, 0]}, Fred => 'abc') ;
642e522c 68 is $got->value('Fred'), "abc", "other" ;
69
70}
71
72My::testParseParameters();
73
74
75{
76 title "isaFilename" ;
77 ok isaFilename("abc"), "'abc' isaFilename";
78
79 ok ! isaFilename(undef), "undef ! isaFilename";
80 ok ! isaFilename([]), "[] ! isaFilename";
81 $main::X = 1; $main::X = $main::X ;
82 ok ! isaFilename(*X), "glob ! isaFilename";
83}
84
85{
86 title "whatIsInput" ;
87
9f2e3514 88 my $lex = new LexFile my $out_file ;
642e522c 89 open FH, ">$out_file" ;
90 is whatIsInput(*FH), 'handle', "Match filehandle" ;
91 close FH ;
92
93 my $stdin = '-';
94 is whatIsInput($stdin), 'handle', "Match '-' as stdin";
95 #is $stdin, \*STDIN, "'-' changed to *STDIN";
96 #isa_ok $stdin, 'IO::File', "'-' changed to IO::File";
97 is whatIsInput("abc"), 'filename', "Match filename";
98 is whatIsInput(\"abc"), 'buffer', "Match buffer";
99 is whatIsInput(sub { 1 }, 1), 'code', "Match code";
100 is whatIsInput(sub { 1 }), '' , "Don't match code";
101
102}
103
104{
105 title "whatIsOutput" ;
106
9f2e3514 107 my $lex = new LexFile my $out_file ;
642e522c 108 open FH, ">$out_file" ;
109 is whatIsOutput(*FH), 'handle', "Match filehandle" ;
110 close FH ;
111
112 my $stdout = '-';
113 is whatIsOutput($stdout), 'handle', "Match '-' as stdout";
114 #is $stdout, \*STDOUT, "'-' changed to *STDOUT";
115 #isa_ok $stdout, 'IO::File', "'-' changed to IO::File";
116 is whatIsOutput("abc"), 'filename', "Match filename";
117 is whatIsOutput(\"abc"), 'buffer', "Match buffer";
118 is whatIsOutput(sub { 1 }, 1), 'code', "Match code";
119 is whatIsOutput(sub { 1 }), '' , "Don't match code";
120
121}