X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=ext%2FDB_File%2Ft%2Fdb-btree.t;h=529a600cf96738cb647c51ed1e45fcf3c4b0f7de;hb=13d11c6e852aaac8eff257adcc793baa531c16b1;hp=4b4a7967eef554bbfaf5843b7cb853bb274537fc;hpb=b695f709e8a342e35e482b0437eb6cdacdc58b6b;p=p5sagit%2Fp5-mst-13.2.git diff --git a/ext/DB_File/t/db-btree.t b/ext/DB_File/t/db-btree.t index 4b4a796..529a600 100755 --- a/ext/DB_File/t/db-btree.t +++ b/ext/DB_File/t/db-btree.t @@ -1,6 +1,7 @@ #!./perl -w BEGIN { + chdir 't' if -d 't'; @INC = '../lib'; require Config; import Config; if ($Config{'extensions'} !~ /\bDB_File\b/) { @@ -14,7 +15,7 @@ use strict; use DB_File; use Fcntl; -print "1..157\n"; +print "1..163\n"; sub ok { @@ -142,7 +143,8 @@ ok(19, $X = tie(%h, 'DB_File',$Dfile, O_RDWR|O_CREAT, 0640, $DB_BTREE )) ; my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, $blksize,$blocks) = stat($Dfile); -ok(20, ($mode & 0777) == ($^O eq 'os2' ? 0666 : 0640) || $^O eq 'amigaos' || $^O eq 'MSWin32' || $^O eq 'NetWare'); +ok(20, ($mode & 0777) == (($^O eq 'os2' || $^O eq 'MacOS') ? 0666 : 0640) + || $^O eq 'amigaos' || $^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'NetWare'); my ($key, $value, $i); while (($key,$value) = each(%h)) { @@ -1293,4 +1295,46 @@ EOM unlink $Dfile; } +{ + # When iterating over a tied hash using "each", the key passed to FETCH + # will be recycled and passed to NEXTKEY. If a Source Filter modifies the + # key in FETCH via a filter_fetch_key method we need to check that the + # modified key doesn't get passed to NEXTKEY. + # Also Test "keys" & "values" while we are at it. + + use warnings ; + use strict ; + use DB_File ; + + unlink $Dfile; + my $bad_key = 0 ; + my %h = () ; + my $db ; + ok(158, $db = tie(%h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0640, $DB_BTREE ) ); + $db->filter_fetch_key (sub { $_ =~ s/^Beta_/Alpha_/ if defined $_}) ; + $db->filter_store_key (sub { $bad_key = 1 if /^Beta_/ ; $_ =~ s/^Alpha_/Beta_/}) ; + + $h{'Alpha_ABC'} = 2 ; + $h{'Alpha_DEF'} = 5 ; + + ok(159, $h{'Alpha_ABC'} == 2); + ok(160, $h{'Alpha_DEF'} == 5); + + my ($k, $v) = ("",""); + while (($k, $v) = each %h) {} + ok(161, $bad_key == 0); + + $bad_key = 0 ; + foreach $k (keys %h) {} + ok(162, $bad_key == 0); + + $bad_key = 0 ; + foreach $v (values %h) {} + ok(163, $bad_key == 0); + + undef $db ; + untie %h ; + unlink $Dfile; +} + exit ;