db-btree.t
上传用户:tsgydb
上传日期:2007-04-14
资源大小:10674k
文件大小:28k
- #!./perl -w
- use warnings;
- use strict;
- BEGIN {
- unless(grep /blib/, @INC) {
- chdir 't' if -d 't';
- @INC = '../lib' if -d '../lib';
- }
- }
-
- use Config;
-
- BEGIN {
- if(-d "lib" && -f "TEST") {
- if ($Config{'extensions'} !~ /bDB_Fileb/ ) {
- print "1..157n";
- exit 0;
- }
- }
- }
- use DB_File;
- use Fcntl;
- print "1..157n";
- sub ok
- {
- my $no = shift ;
- my $result = shift ;
-
- print "not " unless $result ;
- print "ok $non" ;
- }
- sub lexical
- {
- my(@a) = unpack ("C*", $a) ;
- my(@b) = unpack ("C*", $b) ;
- my $len = (@a > @b ? @b : @a) ;
- my $i = 0 ;
- foreach $i ( 0 .. $len -1) {
- return $a[$i] - $b[$i] if $a[$i] != $b[$i] ;
- }
- return @a - @b ;
- }
- {
- package Redirect ;
- use Symbol ;
- sub new
- {
- my $class = shift ;
- my $filename = shift ;
- my $fh = gensym ;
- open ($fh, ">$filename") || die "Cannot open $filename: $!" ;
- my $real_stdout = select($fh) ;
- return bless [$fh, $real_stdout ] ;
- }
- sub DESTROY
- {
- my $self = shift ;
- close $self->[0] ;
- select($self->[1]) ;
- }
- }
- sub docat
- {
- my $file = shift;
- #local $/ = undef unless wantarray ;
- open(CAT,$file) || die "Cannot open $file: $!";
- my @result = <CAT>;
- close(CAT);
- wantarray ? @result : join("", @result) ;
- }
- sub docat_del
- {
- my $file = shift;
- #local $/ = undef unless wantarray ;
- open(CAT,$file) || die "Cannot open $file: $!";
- my @result = <CAT>;
- close(CAT);
- unlink $file ;
- wantarray ? @result : join("", @result) ;
- }
- 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;
- umask(0);
- # Check the interface to BTREEINFO
- my $dbh = new DB_File::BTREEINFO ;
- ok(1, ! defined $dbh->{flags}) ;
- ok(2, ! defined $dbh->{cachesize}) ;
- ok(3, ! defined $dbh->{psize}) ;
- ok(4, ! defined $dbh->{lorder}) ;
- ok(5, ! defined $dbh->{minkeypage}) ;
- ok(6, ! defined $dbh->{maxkeypage}) ;
- ok(7, ! defined $dbh->{compare}) ;
- ok(8, ! defined $dbh->{prefix}) ;
- $dbh->{flags} = 3000 ;
- ok(9, $dbh->{flags} == 3000) ;
- $dbh->{cachesize} = 9000 ;
- ok(10, $dbh->{cachesize} == 9000);
- $dbh->{psize} = 400 ;
- ok(11, $dbh->{psize} == 400) ;
- $dbh->{lorder} = 65 ;
- ok(12, $dbh->{lorder} == 65) ;
- $dbh->{minkeypage} = 123 ;
- ok(13, $dbh->{minkeypage} == 123) ;
- $dbh->{maxkeypage} = 1234 ;
- ok(14, $dbh->{maxkeypage} == 1234 );
- $dbh->{compare} = 1234 ;
- ok(15, $dbh->{compare} == 1234) ;
- $dbh->{prefix} = 1234 ;
- 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 '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 )) ;
- 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++;
- }
- ok(21, !$i ) ;
- $h{'goner1'} = 'snork';
- $h{'abc'} = 'ABC';
- ok(22, $h{'abc'} eq 'ABC' );
- ok(23, ! defined $h{'jimmy'} ) ;
- ok(24, ! exists $h{'jimmy'} ) ;
- ok(25, defined $h{'abc'} ) ;
- $h{'def'} = 'DEF';
- $h{'jkl','mno'} = "JKL 34MNO";
- $h{'a',2,3,4,5} = join("