11 if ( ! -d 'DBM_Filter')
13 mkdir 'DBM_Filter', 0777
14 or die "Cannot create directory 'DBM_Filter': $!\n" ;
18 END { rmdir 'DBM_Filter' }
22 my $filename = shift ;
24 open F, ">$filename" or croak "Cannot open $filename: $!" ;
34 print "# runFilter $name\n" ;
35 my $filename = "DBM_Filter/$name.pm";
36 $filter = "package DBM_Filter::$name ;\n$filter"
37 unless $filter =~ /^\s*package/ ;
39 writeFile($filename, $filter);
40 eval { $db->Filter_Push($name) };
45 use Test::More tests => 21;
47 BEGIN { use_ok('DBM_Filter') };
51 foreach (qw/ODBM_File SDBM_File NDBM_File GDBM_File DB_File/) {
52 if ($Config{extensions} =~ /\b$_\b/) {
59 BEGIN { use_ok('Fcntl') };
62 END { unlink <Op_dbmx*>; }
66 $db = tie(%h1, $db_file,'Op_dbmx', O_RDWR|O_CREAT, 0640) ;
68 ok $db, "tied to $db_file ok";
73 eval { $db->Filter_Push() ; };
74 like $@, qr/^Filter_Push: no parameters present/,
75 "croak if not parameters passed to Filter_Push";
77 eval { $db->Filter_Push("unknown_class") ; };
78 like $@, qr/^Filter_Push: Cannot Load DBM Filter 'DBM_Filter::unknown_class'/,
79 "croak on unknown class" ;
81 eval { $db->Filter_Push("Some::unknown_class") ; };
82 like $@, qr/^Filter_Push: Cannot Load DBM Filter 'Some::unknown_class'/,
83 "croak on unknown fully qualified class" ;
85 eval { $db->Filter_Push('Store') ; };
86 like $@, qr/^Filter_Push: not even params/,
87 "croak if not passing even number or params to Filter_Push";
89 runFilter('bad1', <<'EOM');
90 package DBM_Filter::bad1 ;
94 like $@, qr/^Filter_Push: No methods \(Filter, Fetch or Store\) found in class 'DBM_Filter::bad1'/,
95 "croak if none of Filter/Fetch/Store in filter" ;
98 runFilter('bad2', <<'EOM');
99 package DBM_Filter::bad2 ;
109 like $@, qr/^Filter_Push: 'DBM_Filter::bad2::Filter' did not return a hash reference./,
110 "croak if Filter doesn't return hash reference" ;
112 runFilter('bad3', <<'EOM');
113 package DBM_Filter::bad3 ;
117 return { BadKey => sub { } } ;
124 like $@, qr/^Filter_Push: Unknown key 'BadKey'/,
125 "croak if bad keyword returned from Filter";
127 runFilter('bad4', <<'EOM');
128 package DBM_Filter::bad4 ;
132 return { Store => "abc" } ;
138 like $@, qr/^Filter_Push: value associated with key 'Store' is not a code reference/,
139 "croak if not a code reference";
141 runFilter('bad5', <<'EOM');
142 package DBM_Filter::bad5 ;
152 like $@, qr/^Filter_Push: expected both Store & Fetch - got neither/,
153 "croak if neither fetch or store is present";
155 runFilter('bad6', <<'EOM');
156 package DBM_Filter::bad6 ;
160 return { Store => sub {} } ;
166 like $@, qr/^Filter_Push: expected both Store & Fetch - got Store/,
167 "croak if store is present but fetch isn't";
169 runFilter('bad7', <<'EOM');
170 package DBM_Filter::bad7 ;
174 return { Fetch => sub {} } ;
180 like $@, qr/^Filter_Push: expected both Store & Fetch - got Fetch/,
181 "croak if fetch is present but store isn't";
183 runFilter('bad8', <<'EOM');
184 package DBM_Filter::bad8 ;
193 like $@, qr/^Filter_Push: Can't mix Filter with Store and Fetch in class 'DBM_Filter::bad8'/,
194 "croak if Fetch, Store and Filter";
196 runFilter('bad9', <<'EOM');
197 package DBM_Filter::bad9 ;
205 like $@, qr/^Filter_Push: Can't mix Filter with Store and Fetch in class 'DBM_Filter::bad9'/,
206 "croak if Store and Filter";
208 runFilter('bad10', <<'EOM');
209 package DBM_Filter::bad10 ;
217 like $@, qr/^Filter_Push: Can't mix Filter with Store and Fetch in class 'DBM_Filter::bad10'/,
218 "croak if Fetch and Filter";
220 runFilter('bad11', <<'EOM');
221 package DBM_Filter::bad11 ;
228 like $@, qr/^Filter_Push: Missing method 'Store' in class 'DBM_Filter::bad11'/,
229 "croak if Fetch but no Store";
231 runFilter('bad12', <<'EOM');
232 package DBM_Filter::bad12 ;
239 like $@, qr/^Filter_Push: Missing method 'Fetch' in class 'DBM_Filter::bad12'/,
240 "croak if Store but no Fetch";
244 use warnings FATAL => 'untie';
246 is $@, '', "untie without inner references" ;