5 require Config; import Config;
6 if ($Config{'extensions'} !~ /\bDB_File\b/) {
15 use vars qw($dbh $Dfile) ;
22 print "not " unless $result ;
28 my $Dfile = "recno.tmp";
33 # Check the interface to RECNOINFO
35 my $dbh = new DB_File::RECNOINFO ;
37 ok(1, $dbh->{bval} == undef ) ;
38 ok(2, $dbh->{cachesize} == undef) ;
39 ok(3, $dbh->{psize} == undef) ;
40 ok(4, $dbh->{flags} == undef) ;
41 ok(5, $dbh->{lorder} == undef);
42 ok(6, $dbh->{reclen} == undef);
43 ok(7, $dbh->{bfname} eq undef);
47 ok(8, $dbh->{bval} == 3000 );
49 $dbh->{cachesize} = 9000 ;
50 ok(9, $dbh->{cachesize} == 9000 );
53 ok(10, $dbh->{psize} == 400 );
56 ok(11, $dbh->{flags} == 65 );
58 $dbh->{lorder} = 123 ;
59 ok(12, $dbh->{lorder} == 123 );
61 $dbh->{reclen} = 1234 ;
62 ok(13, $dbh->{reclen} == 1234 );
64 $dbh->{bfname} = 1234 ;
65 ok(14, $dbh->{bfname} == 1234 );
68 # Check that an invalid entry is caught both for store & fetch
69 eval '$dbh->{fred} = 1234' ;
70 ok(15, $@ =~ /^DB_File::RECNOINFO::STORE - Unknown element 'fred' at/ );
71 eval 'my $q = $dbh->{fred}' ;
72 ok(16, $@ =~ /^DB_File::RECNOINFO::FETCH - Unknown element 'fred' at/ );
74 # Now check the interface to RECNOINFO
78 ok(17, $X = tie @h, 'DB_File', $Dfile, O_RDWR|O_CREAT, 0640, $DB_RECNO ) ;
80 ok(18, ( (stat($Dfile))[2] & 0777) == 0640) ;
86 my @data = qw( a b c d ever f g h i j k longername m n o p) ;
89 ok(20, $h[0] eq 'a' );
95 unshift (@data, 'a') ;
97 ok(21, defined $h[1] );
98 ok(22, ! defined $h[16] );
99 ok(23, $X->length == @data );
102 # Overwrite an entry & check fetch it
104 $data[3] = 'replaced' ;
105 ok(24, $h[3] eq 'replaced' );
108 my @push_data = qw(added to the end) ;
109 #my push (@h, @push_data) ;
110 $X->push(@push_data) ;
111 push (@data, @push_data) ;
112 ok(25, $h[++$i] eq 'added' );
113 ok(26, $h[++$i] eq 'to' );
114 ok(27, $h[++$i] eq 'the' );
115 ok(28, $h[++$i] eq 'end' );
118 my $popped = pop (@data) ;
119 #my $value = pop(@h) ;
120 my $value = $X->pop ;
121 ok(29, $value eq $popped) ;
126 my $shifted = shift @data ;
127 ok(30, $value eq $shifted );
133 ok(31, $X->length == @data );
135 my @new_data = qw(add this to the start of the array) ;
136 #unshift @h, @new_data ;
137 $X->unshift (@new_data) ;
138 unshift (@data, @new_data) ;
139 ok(32, $X->length == @data );
140 ok(33, $h[0] eq "add") ;
141 ok(34, $h[1] eq "this") ;
142 ok(35, $h[2] eq "to") ;
143 ok(36, $h[3] eq "the") ;
144 ok(37, $h[4] eq "start") ;
145 ok(38, $h[5] eq "of") ;
146 ok(39, $h[6] eq "the") ;
147 ok(40, $h[7] eq "array") ;
148 ok(41, $h[8] eq $data[8]) ;
152 # Now both arrays should be identical
158 $ok = 0, last if $_ ne $h[$j ++] ;
162 # Neagtive subscripts
164 # get the last element of the array
165 ok(43, $h[-1] eq $data[-1] );
166 ok(44, $h[-1] eq $h[$X->length -1] );
168 # get the first element using a negative subscript
169 eval '$h[ - ( $X->length)] = "abcd"' ;
171 ok(46, $h[0] eq "abcd" );
173 # now try to read before the start of the array
174 eval '$h[ - (1 + $X->length)] = 1234' ;
175 ok(47, $@ =~ '^Modification of non-creatable array value attempted' );
177 # IMPORTANT - $X must be undefined before the untie otherwise the
178 # underlying DB close routine will not get called.