Enhanced DBM Filters
[p5sagit/p5-mst-13.2.git] / lib / DBM_Filter / t / compress.t
CommitLineData
0e9b1cbd 1
2use strict;
3use warnings;
4use Carp;
5
6BEGIN
7{
8 eval { require Compress::Zlib ; };
9 if ($@) {
10 print "1..0 # Skip: Compress::Zlib is not available\n";
11print "# $@\n";
12 exit 0;
13 }
14}
15require "dbm_filter_util.pl";
16
17use Test::More tests => 23;
18
19BEGIN { use_ok('DBM_Filter') };
20BEGIN { use_ok('SDBM_File') };
21BEGIN { use_ok('Fcntl') };
22BEGIN { use_ok('Compress::Zlib') };
23
24unlink <Op_dbmx*>;
25END { unlink <Op_dbmx*>; }
26
27my %h1 = () ;
28my $db1 = tie(%h1, 'SDBM_File','Op_dbmx', O_RDWR|O_CREAT, 0640) ;
29
30ok $db1, "tied to SDBM_File";
31
32# store before adding the filter
33
34StoreData(\%h1,
35 {
36 1234 => 5678,
37 -3 => -5,
38 "22" => "88",
39 "-45" => "-88",
40 "fred" => "Joe",
41 "alpha" => "Alpha",
42 "Beta" => "beta",
43 });
44
45VerifyData(\%h1,
46 {
47 1234 => 5678,
48 -3 => -5,
49 "22" => "88",
50 "-45" => "-88",
51 "fred" => "Joe",
52 "alpha" => "Alpha",
53 "Beta" => "beta",
54 });
55
56
57eval { $db1->Filter_Push('compress') };
58is $@, '', "push a 'compress' filter" ;
59
60{
61 no warnings 'uninitialized';
62 StoreData(\%h1,
63 {
64 undef() => undef(),
65 "400" => "500",
66 0 => 1,
67 1 => 0,
68 "abc" => "de0",
69 "\x00\x01" => "\x03\xFF",
70 });
71
72}
73
74undef $db1;
75{
76 use warnings FATAL => 'untie';
77 eval { untie %h1 };
78 is $@, '', "untie without inner references" ;
79}
80
81# read the dbm file without the filter
82my %h2 = () ;
83my $db2 = tie(%h2, 'SDBM_File','Op_dbmx', O_RDWR|O_CREAT, 0640) ;
84
85ok $db2, "tied to SDBM_File";
86
87VerifyData(\%h2,
88 {
89 1234 => 5678,
90 -3 => -5,
91 "22" => "88",
92 "-45" => "-88",
93 "fred" => "Joe",
94 "alpha" => "Alpha",
95 "Beta" => "beta",
96
97 compress("") => compress(""),
98 compress("400") => compress("500"),
99 compress("0") => compress("1"),
100 compress("1") => compress("0"),
101 compress("abc") => compress("de0"),
102 compress("\x00\x01") => compress("\x03\xFF"),
103 });
104
105undef $db2;
106{
107 use warnings FATAL => 'untie';
108 eval { untie %h2 };
109 is $@, '', "untie without inner references" ;
110}
111