summaryrefslogtreecommitdiff
path: root/t/lib
diff options
context:
space:
mode:
authorPaul Marquess <paul.marquess@btinternet.com>2000-12-11 23:07:17 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2000-12-12 19:48:26 +0000
commit3245f0580c13b3ab105e59fb6c74519f9d8c8ef0 (patch)
treede2b1ccd02b733ca5a43ba53eb4e4737bff4ee42 /t/lib
parent3601bd2ab5316cf7ceba3f53d5e81474fb7d9b12 (diff)
downloadperl-3245f0580c13b3ab105e59fb6c74519f9d8c8ef0.tar.gz
DB_File-1.74
Message-ID: <000001c063c7$1b9d28a0$a20a140a@bfs.phone.com> p4raw-id: //depot/perl@8094
Diffstat (limited to 't/lib')
-rwxr-xr-xt/lib/db-btree.t116
-rwxr-xr-xt/lib/db-hash.t71
-rwxr-xr-xt/lib/db-recno.t34
3 files changed, 170 insertions, 51 deletions
diff --git a/t/lib/db-btree.t b/t/lib/db-btree.t
index 11e86afc1d..1822823563 100755
--- a/t/lib/db-btree.t
+++ b/t/lib/db-btree.t
@@ -9,10 +9,12 @@ BEGIN {
}
}
+use warnings;
+use strict;
use DB_File;
use Fcntl;
-print "1..156\n";
+print "1..157\n";
sub ok
{
@@ -82,7 +84,9 @@ sub docat_del
}
-$db185mode = ($DB_File::db_version == 1 && ! $DB_File::db_185_compat) ;
+my $db185mode = ($DB_File::db_version == 1 && ! $DB_File::db_185_compat) ;
+my $null_keys_allowed = ($DB_File::db_ver < 2.004010
+ || $DB_File::db_ver >= 3.1 );
my $Dfile = "dbbtree.tmp";
unlink $Dfile;
@@ -128,17 +132,19 @@ ok(16, $dbh->{prefix} == 1234 );
# Check that an invalid entry is caught both for store & fetch
eval '$dbh->{fred} = 1234' ;
ok(17, $@ =~ /^DB_File::BTREEINFO::STORE - Unknown element 'fred' at/ ) ;
-eval '$q = $dbh->{fred}' ;
+eval 'my $q = $dbh->{fred}' ;
ok(18, $@ =~ /^DB_File::BTREEINFO::FETCH - Unknown element 'fred' at/ ) ;
# Now check the interface to BTREE
+my ($X, %h) ;
ok(19, $X = tie(%h, 'DB_File',$Dfile, O_RDWR|O_CREAT, 0640, $DB_BTREE )) ;
-($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
+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');
+my ($key, $value, $i);
while (($key,$value) = each(%h)) {
$i++;
}
@@ -209,8 +215,8 @@ $h{'goner3'} = 'snork';
delete $h{'goner1'};
$X->DELETE('goner3');
-@keys = keys(%h);
-@values = values(%h);
+my @keys = keys(%h);
+my @values = values(%h);
ok(27, $#keys == 29 && $#values == 29) ;
@@ -235,12 +241,19 @@ ok(30, ArrayCompare(\@b, \@c)) ;
$h{'foo'} = '';
ok(31, $h{'foo'} eq '' ) ;
-#$h{''} = 'bar';
-#ok(32, $h{''} eq 'bar' );
-ok(32,1) ;
+# Berkeley DB from version 2.4.10 to 3.0 does not allow null keys.
+# This feature was reenabled in version 3.1 of Berkeley DB.
+my $result = 0 ;
+if ($null_keys_allowed) {
+ $h{''} = 'bar';
+ $result = ( $h{''} eq 'bar' );
+}
+else
+ { $result = 1 }
+ok(32, $result) ;
# check cache overflow and numeric keys and contents
-$ok = 1;
+my $ok = 1;
for ($i = 1; $i < 200; $i++) { $h{$i + 0} = $i + 0; }
for ($i = 1; $i < 200; $i++) { $ok = 0 unless $h{$i} == $i; }
ok(33, $ok);
@@ -250,7 +263,7 @@ ok(33, $ok);
ok(34, $size > 0 );
@h{0..200} = 200..400;
-@foo = @h{0..200};
+my @foo = @h{0..200};
ok(35, join(':',200..400) eq join(':',@foo) );
# Now check all the non-tie specific stuff
@@ -259,7 +272,7 @@ ok(35, join(':',200..400) eq join(':',@foo) );
# Check R_NOOVERWRITE flag will make put fail when attempting to overwrite
# an existing record.
-$status = $X->put( 'x', 'newvalue', R_NOOVERWRITE) ;
+my $status = $X->put( 'x', 'newvalue', R_NOOVERWRITE) ;
ok(36, $status == 1 );
# check that the value of the key 'x' has not been changed by the
@@ -280,9 +293,12 @@ ok(40, $value eq 'value' );
$status = $X->del('q') ;
ok(41, $status == 0 );
-#$status = $X->del('') ;
-#ok(42, $status == 0 );
-ok(42,1) ;
+if ($null_keys_allowed) {
+ $status = $X->del('') ;
+} else {
+ $status = 0 ;
+}
+ok(42, $status == 0 );
# Make sure that the key deleted, cannot be retrieved
ok(43, ! defined $h{'q'}) ;
@@ -362,7 +378,7 @@ ok(65, 1) ; # hard-wire to always pass. the previous test ($status == 1)
$status = $X->seq($key, $value, R_FIRST) ;
ok(66, $status == 0 );
-$previous = $key ;
+my $previous = $key ;
$ok = 1 ;
while (($status = $X->seq($key, $value, R_NEXT)) == 0)
@@ -411,6 +427,7 @@ untie %h ;
unlink $Dfile;
# Now try an in memory file
+my $Y;
ok(74, $Y = tie(%h, 'DB_File',undef, O_RDWR|O_CREAT, 0640, $DB_BTREE ));
# fd with an in memory file should return failure
@@ -424,6 +441,7 @@ untie %h ;
# Duplicate keys
my $bt = new DB_File::BTREEINFO ;
$bt->{flags} = R_DUP ;
+my ($YY, %hh);
ok(76, $YY = tie(%hh, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0640, $bt )) ;
$hh{'Wall'} = 'Larry' ;
@@ -469,34 +487,38 @@ unlink $Dfile;
# test multiple callbacks
-$Dfile1 = "btree1" ;
-$Dfile2 = "btree2" ;
-$Dfile3 = "btree3" ;
+my $Dfile1 = "btree1" ;
+my $Dfile2 = "btree2" ;
+my $Dfile3 = "btree3" ;
-$dbh1 = new DB_File::BTREEINFO ;
-{ local $^W = 0 ;
- $dbh1->{compare} = sub { $_[0] <=> $_[1] } ; }
+my $dbh1 = new DB_File::BTREEINFO ;
+$dbh1->{compare} = sub {
+ no warnings 'numeric' ;
+ $_[0] <=> $_[1] } ;
-$dbh2 = new DB_File::BTREEINFO ;
+my $dbh2 = new DB_File::BTREEINFO ;
$dbh2->{compare} = sub { $_[0] cmp $_[1] } ;
-$dbh3 = new DB_File::BTREEINFO ;
+my $dbh3 = new DB_File::BTREEINFO ;
$dbh3->{compare} = sub { length $_[0] <=> length $_[1] } ;
-tie(%h, 'DB_File',$Dfile1, O_RDWR|O_CREAT, 0640, $dbh1 ) ;
+my (%g, %k);
+tie(%h, 'DB_File',$Dfile1, O_RDWR|O_CREAT, 0640, $dbh1 ) ;
tie(%g, 'DB_File',$Dfile2, O_RDWR|O_CREAT, 0640, $dbh2 ) ;
tie(%k, 'DB_File',$Dfile3, O_RDWR|O_CREAT, 0640, $dbh3 ) ;
-@Keys = qw( 0123 12 -1234 9 987654321 def ) ;
-{ local $^W = 0 ;
- @srt_1 = sort { $a <=> $b } @Keys ; }
+my @Keys = qw( 0123 12 -1234 9 987654321 def ) ;
+my (@srt_1, @srt_2, @srt_3);
+{
+ no warnings 'numeric' ;
+ @srt_1 = sort { $a <=> $b } @Keys ;
+}
@srt_2 = sort { $a cmp $b } @Keys ;
@srt_3 = sort { length $a <=> length $b } @Keys ;
foreach (@Keys) {
- { local $^W = 0 ;
- $h{$_} = 1 ; }
+ $h{$_} = 1 ;
$g{$_} = 1 ;
$k{$_} = 1 ;
}
@@ -566,6 +588,7 @@ unlink $Dfile1 ;
package Another ;
+ use warnings ;
use strict ;
open(FILE, ">SubDB.pm") or die "Cannot open SubDB.pm: $!\n" ;
@@ -573,6 +596,7 @@ unlink $Dfile1 ;
package SubDB ;
+ use warnings ;
use strict ;
use vars qw( @ISA @EXPORT) ;
@@ -656,6 +680,7 @@ EOM
{
# DBM Filter tests
+ use warnings ;
use strict ;
my (%h, $db) ;
my ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
@@ -762,6 +787,7 @@ EOM
{
# DBM Filter with a closure
+ use warnings ;
use strict ;
my (%h, $db) ;
@@ -824,6 +850,7 @@ EOM
{
# DBM Filter recursion detection
+ use warnings ;
use strict ;
my (%h, $db) ;
unlink $Dfile;
@@ -852,6 +879,7 @@ EOM
# BTREE example 1
###
+ use warnings FATAL => qw(all) ;
use strict ;
use DB_File ;
@@ -904,6 +932,7 @@ EOM
# BTREE example 2
###
+ use warnings FATAL => qw(all) ;
use strict ;
use DB_File ;
@@ -955,6 +984,7 @@ EOM
# BTREE example 3
###
+ use warnings FATAL => qw(all) ;
use strict ;
use DB_File ;
@@ -1010,6 +1040,7 @@ EOM
# BTREE example 4
###
+ use warnings FATAL => qw(all) ;
use strict ;
use DB_File ;
@@ -1058,6 +1089,7 @@ EOM
# BTREE example 5
###
+ use warnings FATAL => qw(all) ;
use strict ;
use DB_File ;
@@ -1092,6 +1124,7 @@ EOM
# BTREE example 6
###
+ use warnings FATAL => qw(all) ;
use strict ;
use DB_File ;
@@ -1126,6 +1159,7 @@ EOM
# BTREE example 7
###
+ use warnings FATAL => qw(all) ;
use strict ;
use DB_File ;
use Fcntl ;
@@ -1231,7 +1265,7 @@ EOM
my $a = "";
local $SIG{__WARN__} = sub {$a = $_[0]} ;
- tie %h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0664, $DB_BTREE
+ tie %h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0664, $DB_BTREE
or die "Can't open file: $!\n" ;
$h{ABC} = undef;
ok(156, $a eq "") ;
@@ -1239,4 +1273,24 @@ EOM
unlink $Dfile;
}
+{
+ # test that %hash = () doesn't produce the warning
+ # Argument "" isn't numeric in entersub
+ use warnings ;
+ use strict ;
+ use DB_File ;
+
+ unlink $Dfile;
+ my %h ;
+ my $a = "";
+ local $SIG{__WARN__} = sub {$a = $_[0]} ;
+
+ tie %h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0664, $DB_BTREE
+ or die "Can't open file: $!\n" ;
+ %h = (); ;
+ ok(157, $a eq "") ;
+ untie %h ;
+ unlink $Dfile;
+}
+
exit ;
diff --git a/t/lib/db-hash.t b/t/lib/db-hash.t
index 462796926c..effc60b7dd 100755
--- a/t/lib/db-hash.t
+++ b/t/lib/db-hash.t
@@ -9,10 +9,12 @@ BEGIN {
}
}
+use strict;
+use warnings;
use DB_File;
use Fcntl;
-print "1..110\n";
+print "1..111\n";
sub ok
{
@@ -57,6 +59,9 @@ sub docat_del
}
my $Dfile = "dbhash.tmp";
+my $null_keys_allowed = ($DB_File::db_ver < 2.004010
+ || $DB_File::db_ver >= 3.1 );
+
unlink $Dfile;
umask(0);
@@ -98,13 +103,14 @@ ok(14, $@ =~ /^DB_File::HASHINFO::FETCH - Unknown element 'fred' at/ );
# Now check the interface to HASH
-
+my ($X, %h);
ok(15, $X = tie(%h, 'DB_File',$Dfile, O_RDWR|O_CREAT, 0640, $DB_HASH ) );
-($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
+my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
$blksize,$blocks) = stat($Dfile);
ok(16, ($mode & 0777) == ($^O eq 'os2' ? 0666 : 0640) || $^O eq 'amigaos' || $^O eq 'MSWin32');
+my ($key, $value, $i);
while (($key,$value) = each(%h)) {
$i++;
}
@@ -176,8 +182,8 @@ $h{'goner3'} = 'snork';
delete $h{'goner1'};
$X->DELETE('goner3');
-@keys = keys(%h);
-@values = values(%h);
+my @keys = keys(%h);
+my @values = values(%h);
ok(23, $#keys == 29 && $#values == 29) ;
@@ -197,14 +203,19 @@ ok(25, $#keys == 31) ;
$h{'foo'} = '';
ok(26, $h{'foo'} eq '' );
-# Berkeley DB 2 from version 2.4.10 onwards does not allow null keys.
-# This feature will be reenabled in a future version of Berkeley DB.
-#$h{''} = 'bar';
-#ok(27, $h{''} eq 'bar' );
-ok(27,1) ;
+# Berkeley DB from version 2.4.10 to 3.0 does not allow null keys.
+# This feature was reenabled in version 3.1 of Berkeley DB.
+my $result = 0 ;
+if ($null_keys_allowed) {
+ $h{''} = 'bar';
+ $result = ( $h{''} eq 'bar' );
+}
+else
+ { $result = 1 }
+ok(27, $result) ;
# check cache overflow and numeric keys and contents
-$ok = 1;
+my $ok = 1;
for ($i = 1; $i < 200; $i++) { $h{$i + 0} = $i + 0; }
for ($i = 1; $i < 200; $i++) { $ok = 0 unless $h{$i} == $i; }
ok(28, $ok );
@@ -214,7 +225,7 @@ ok(28, $ok );
ok(29, $size > 0 );
@h{0..200} = 200..400;
-@foo = @h{0..200};
+my @foo = @h{0..200};
ok(30, join(':',200..400) eq join(':',@foo) );
@@ -223,7 +234,7 @@ ok(30, join(':',200..400) eq join(':',@foo) );
# Check NOOVERWRITE will make put fail when attempting to overwrite
# an existing record.
-$status = $X->put( 'x', 'newvalue', R_NOOVERWRITE) ;
+my $status = $X->put( 'x', 'newvalue', R_NOOVERWRITE) ;
ok(31, $status == 1 );
# check that the value of the key 'x' has not been changed by the
@@ -246,9 +257,10 @@ $status = $X->del('q') ;
ok(36, $status == 0 );
# Make sure that the key deleted, cannot be retrieved
-$^W = 0 ;
-ok(37, $h{'q'} eq undef );
-$^W = 1 ;
+{
+ no warnings 'uninitialized' ;
+ ok(37, $h{'q'} eq undef );
+}
# Attempting to delete a non-existant key should fail
@@ -361,6 +373,7 @@ untie %h ;
package Another ;
+ use warnings ;
use strict ;
open(FILE, ">SubDB.pm") or die "Cannot open SubDB.pm: $!\n" ;
@@ -368,6 +381,7 @@ untie %h ;
package SubDB ;
+ use warnings ;
use strict ;
use vars qw( @ISA @EXPORT) ;
@@ -451,6 +465,7 @@ EOM
{
# DBM Filter tests
+ use warnings ;
use strict ;
my (%h, $db) ;
my ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
@@ -557,6 +572,7 @@ EOM
{
# DBM Filter with a closure
+ use warnings ;
use strict ;
my (%h, $db) ;
@@ -619,6 +635,7 @@ EOM
{
# DBM Filter recursion detection
+ use warnings ;
use strict ;
my (%h, $db) ;
unlink $Dfile;
@@ -643,6 +660,7 @@ EOM
{
my $redirect = new Redirect $file ;
+ use warnings FATAL => qw(all);
use strict ;
use DB_File ;
use vars qw( %h $k $v ) ;
@@ -699,7 +717,26 @@ EOM
tie %h, 'DB_File', $Dfile or die "Can't open file: $!\n" ;
$h{ABC} = undef;
ok(110, $a eq "") ;
- untie %h;
+ untie %h ;
+ unlink $Dfile;
+}
+
+{
+ # test that %hash = () doesn't produce the warning
+ # Argument "" isn't numeric in entersub
+ use warnings ;
+ use strict ;
+ use DB_File ;
+
+ unlink $Dfile;
+ my %h ;
+ my $a = "";
+ local $SIG{__WARN__} = sub {$a = $_[0]} ;
+
+ tie %h, 'DB_File', $Dfile or die "Can't open file: $!\n" ;
+ %h = (); ;
+ ok(111, $a eq "") ;
+ untie %h ;
unlink $Dfile;
}
diff --git a/t/lib/db-recno.t b/t/lib/db-recno.t
index f932a8938c..8b5a88cc6d 100755
--- a/t/lib/db-recno.t
+++ b/t/lib/db-recno.t
@@ -12,6 +12,7 @@ BEGIN {
use DB_File;
use Fcntl;
use strict ;
+use warnings;
use vars qw($dbh $Dfile $bad_ones $FA) ;
# full tied array support started in Perl 5.004_57
@@ -99,7 +100,7 @@ sub bad_one
EOM
}
-print "1..127\n";
+print "1..128\n";
my $Dfile = "recno.tmp";
unlink $Dfile ;
@@ -340,6 +341,7 @@ unlink $Dfile;
package Another ;
+ use warnings ;
use strict ;
open(FILE, ">SubDB.pm") or die "Cannot open SubDB.pm: $!\n" ;
@@ -347,6 +349,7 @@ unlink $Dfile;
package SubDB ;
+ use warnings ;
use strict ;
use vars qw( @ISA @EXPORT) ;
@@ -487,6 +490,7 @@ EOM
{
# DBM Filter tests
+ use warnings ;
use strict ;
my (@h, $db) ;
my ($fetch_key, $store_key, $fetch_value, $store_value) = ("") x 4 ;
@@ -593,6 +597,7 @@ EOM
{
# DBM Filter with a closure
+ use warnings ;
use strict ;
my (@h, $db) ;
@@ -655,6 +660,7 @@ EOM
{
# DBM Filter recursion detection
+ use warnings ;
use strict ;
my (@h, $db) ;
unlink $Dfile;
@@ -679,6 +685,7 @@ EOM
{
my $redirect = new Redirect $file ;
+ use warnings FATAL => qw(all);
use strict ;
use DB_File ;
@@ -734,6 +741,7 @@ EOM
{
my $redirect = new Redirect $save_output ;
+ use warnings FATAL => qw(all);
use strict ;
use vars qw(@h $H $file $i) ;
use DB_File ;
@@ -850,11 +858,31 @@ EOM
my $a = "";
local $SIG{__WARN__} = sub {$a = $_[0]} ;
- tie @h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0664, $DB_RECNO
+ tie @h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0664, $DB_RECNO
or die "Can't open file: $!\n" ;
$h[0] = undef;
ok(127, $a eq "") ;
- untie @h;
+ untie @h ;
+ unlink $Dfile;
+}
+
+{
+ # test that %hash = () doesn't produce the warning
+ # Argument "" isn't numeric in entersub
+ use warnings ;
+ use strict ;
+ use DB_File ;
+ my $a = "";
+ local $SIG{__WARN__} = sub {$a = $_[0]} ;
+
+ unlink $Dfile;
+ my @h ;
+
+ tie @h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0664, $DB_RECNO
+ or die "Can't open file: $!\n" ;
+ @h = (); ;
+ ok(128, $a eq "") ;
+ untie @h ;
unlink $Dfile;
}