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