#!./perl
# $RCSfile: dbm.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:43 $
BEGIN {
chdir 't' if -d 't';
print "1..0 # Skip: no SDBM_File\n";
exit 0;
}
}
use strict;
use warnings;
sub ok
{
my $no = shift ;
my $result = shift ;
}
require SDBM_File;
#If Fcntl is not available, try 0x202 or 0x102 for O_RDWR|O_CREAT
use Fcntl;
print "1..80\n";
umask(0);
my %h ;
my $Dfile = "Op_dbmx.pag";
if (! -e $Dfile) {
}
if ($^O eq 'amigaos' || $^O eq 'os2' || $^O eq 'MSWin32' || $^O eq 'NetWare' || $^O eq 'dos' || $^O eq 'cygwin') {
print "ok 2 # Skipped: different file permission semantics\n";
}
else {
}
my $i = 0;
$i++;
}
print (!$i ? "ok 3\n" : "not ok 3\n");
$h{'goner1'} = 'snork';
$h{'abc'} = 'ABC';
$h{'def'} = 'DEF';
$h{'jkl','mno'} = "JKL\034MNO";
$h{'a'} = 'A';
$h{'b'} = 'B';
$h{'c'} = 'C';
$h{'d'} = 'D';
$h{'e'} = 'E';
$h{'f'} = 'F';
$h{'g'} = 'G';
$h{'h'} = 'H';
$h{'i'} = 'I';
$h{'goner2'} = 'snork';
delete $h{'goner2'};
untie(%h);
$h{'j'} = 'J';
$h{'k'} = 'K';
$h{'l'} = 'L';
$h{'m'} = 'M';
$h{'n'} = 'N';
$h{'o'} = 'O';
$h{'p'} = 'P';
$h{'q'} = 'Q';
$h{'r'} = 'R';
$h{'s'} = 'S';
$h{'t'} = 'T';
$h{'u'} = 'U';
$h{'v'} = 'V';
$h{'w'} = 'W';
$h{'x'} = 'X';
$h{'y'} = 'Y';
$h{'z'} = 'Z';
$h{'goner3'} = 'snork';
delete $h{'goner1'};
delete $h{'goner3'};
}
}
if ($i == 30) {print "ok 6\n";} else {print "not ok 6\n";}
$h{'foo'} = '';
$h{''} = 'bar';
# check cache overflow and numeric keys and contents
my $ok = 1;
for ($i = 1; $i < 200; $i++) { $h{$i + 0} = $i + 0; }
@h{0..200} = 200..400;
{
# sub-class test
use strict ;
use warnings ;
use strict ;
use warnings ;
require Exporter ;
use SDBM_File;
sub STORE {
my $self = shift ;
my $key = shift ;
my $value = shift ;
}
sub FETCH {
my $self = shift ;
my $key = shift ;
}
sub A_new_method
{
my $self = shift ;
my $key = shift ;
}
1 ;
eval 'use SubDB ; use Fcntl ;';
my %h ;
my $X ;
eval '
$X = tie(%h, "SubDB","dbhash_tmp", O_RDWR|O_CREAT, 0640 );
' ;
undef $X;
}
untie %h;
{
# DBM Filter tests
use strict ;
use warnings ;
sub checkOutput
{
return
$fetch_key eq $fk && $store_key eq $sk &&
$fetch_value eq $fv && $store_value eq $sv &&
}
$_ = "original" ;
$h{"fred"} = "joe" ;
# fk sk fv sv
# fk sk fv sv
# fk sk fv sv
# replace the filters, but remember the previous set
$h{"Fred"} = "Joe" ;
# fk sk fv sv
# fk sk fv sv
# fk sk fv sv
# put the original filters back
$h{"fred"} = "joe" ;
# delete the filters
$h{"fred"} = "joe" ;
untie %h;
}
{
# DBM Filter with a closure
use strict ;
use warnings ;
sub Closure
{
my $count = 0 ;
return sub { ++$count ;
}
}
$_ = "original" ;
$h{"fred"} = "joe" ;
$h{"jim"} = "john" ;
untie %h;
}
{
# DBM Filter recursion detection
use strict ;
use warnings ;
eval '$h{1} = 1234' ;
untie %h;
}
{
# Bug ID 20001013.009
#
# test that $hash{KEY} = undef doesn't produce the warning
# Use of uninitialized value in null operation
use warnings ;
use strict ;
use SDBM_File ;
my %h ;
my $a = "";
untie %h;
}
{
# 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 SDBM_File ;
my $bad_key = 0 ;
my %h = () ;
$h{'Alpha_ABC'} = 2 ;
$h{'Alpha_DEF'} = 5 ;
my ($k, $v) = ("","");
$bad_key = 0 ;
$bad_key = 0 ;
untie %h ;
}
{
# Check that DBM Filter can cope with read-only $_
use warnings ;
use strict ;
my %h ;
$_ = "original" ;
$h{"fred"} = "joe" ;
# delete the filters
$h{"fred"} = "joe" ;
untie %h;
}
exit ;