Add tests to check treatment of numbers between 0 and -1
[p5sagit/p5-mst-13.2.git] / t / lib / db-recno.t
CommitLineData
a0d0e21e 1#!./perl
2
3BEGIN {
4 @INC = '../lib';
5 require Config; import Config;
6 if ($Config{'extensions'} !~ /\bDB_File\b/) {
7 print "1..0\n";
8 exit 0;
9 }
10}
11
12use DB_File;
13use Fcntl;
14
15print "1..30\n";
16
17$Dfile = "Op.db-recno";
18unlink $Dfile;
19
20umask(0);
21
22# Check the interface to RECNOINFO
23
24$dbh = TIEHASH DB_File::RECNOINFO ;
25print (($dbh->{bval} == undef) ? "ok 1\n" : "not ok 1\n") ;
26print (($dbh->{cachesize} == undef) ? "ok 2\n" : "not ok 2\n") ;
27print (($dbh->{psize} == undef) ? "ok 3\n" : "not ok 3\n") ;
28print (($dbh->{flags} == undef) ? "ok 4\n" : "not ok 4\n") ;
29print (($dbh->{lorder} == undef) ? "ok 5\n" : "not ok 5\n") ;
30print (($dbh->{reclen} == undef) ? "ok 6\n" : "not ok 6\n") ;
31print (($dbh->{bfname} == undef) ? "ok 7\n" : "not ok 7\n") ;
32
33$dbh->{bval} = 3000 ;
34print ($dbh->{bval} == 3000 ? "ok 8\n" : "not ok 8\n") ;
35
36$dbh->{cachesize} = 9000 ;
37print ($dbh->{cachesize} == 9000 ? "ok 9\n" : "not ok 9\n") ;
38
39$dbh->{psize} = 400 ;
40print (($dbh->{psize} == 400) ? "ok 10\n" : "not ok 10\n") ;
41
42$dbh->{flags} = 65 ;
43print (($dbh->{flags} == 65) ? "ok 11\n" : "not ok 11\n") ;
44
45$dbh->{lorder} = 123 ;
46print (($dbh->{lorder} == 123) ? "ok 12\n" : "not ok 12\n") ;
47
48$dbh->{reclen} = 1234 ;
49print ($dbh->{reclen} == 1234 ? "ok 13\n" : "not ok 13\n") ;
50
51$dbh->{bfname} = 1234 ;
52print ($dbh->{bfname} == 1234 ? "ok 14\n" : "not ok 14\n") ;
53
54
55# Check that an invalid entry is caught both for store & fetch
56eval '$dbh->{fred} = 1234' ;
57print ($@ eq '' ? "ok 15\n" : "not ok 15\n") ;
58eval '$q = $dbh->{fred}' ;
59print ($@ eq '' ? "ok 16\n" : "not ok 16\n") ;
60
61# Now check the interface to RECNOINFO
62
63print (($X = tie(@h, DB_File,$Dfile, O_RDWR|O_CREAT, 0640, $DB_RECNO )) ? "ok 17\n" : "not ok 17");
64
65($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
66 $blksize,$blocks) = stat($Dfile);
67print (($mode & 0777) == 0640 ? "ok 18\n" : "not ok 18\n");
68
69#$l = @h ;
70$l = $X->length ;
71print (!$l ? "ok 19\n" : "not ok 19\n");
72
73@data = qw( a b c d ever f g h i j k longername m n o p) ;
74
75$h[0] = shift @data ;
76print ($h[0] eq 'a' ? "ok 20\n" : "not ok 20\n") ;
77
78foreach (@data)
79 { $h[++$i] = $_ }
80
81unshift (@data, 'a') ;
82
83print (defined $h[1] ? "ok 21\n" : "not ok 21\n");
84print (! defined $h[16] ? "ok 22\n" : "not ok 22\n");
85print ($X->length == @data ? "ok 23\n" : "not ok 23\n") ;
86
87
88# Overwrite an entry & check fetch it
89$h[3] = 'replaced' ;
90$data[3] = 'replaced' ;
91print ($h[3] eq 'replaced' ? "ok 24\n" : "not ok 24\n");
92
93#PUSH
94@push_data = qw(added to the end) ;
95#push (@h, @push_data) ;
96$X->push(@push_data) ;
97push (@data, @push_data) ;
98print ($h[++$i] eq 'added' ? "ok 25\n" : "not ok 25\n");
99
100# POP
101pop (@data) ;
102#$value = pop(@h) ;
103$value = $X->pop ;
104print ($value eq 'end' ? "not ok 26\n" : "ok 26\n");
105
106# SHIFT
107#$value = shift @h
108$value = $X->shift ;
109print ($value eq shift @data ? "not ok 27\n" : "ok 27\n");
110
111# UNSHIFT
112
113# empty list
114$X->unshift ;
115print ($X->length == @data ? "ok 28\n" : "not ok 28\n") ;
116
117@new_data = qw(add this to the start of the array) ;
118#unshift @h, @new_data ;
119$X->unshift (@new_data) ;
120unshift (@data, @new_data) ;
121print ($X->length == @data ? "ok 29\n" : "not ok 29\n") ;
122
123# SPLICE
124
125# Now both arrays should be identical
126
127$ok = 1 ;
128$j = 0 ;
129foreach (@data)
130{
131 $ok = 0, last if $_ ne $h[$j ++] ;
132}
133print ($ok ? "ok 30\n" : "not ok 30\n") ;
134
135# IMPORTANT - $X must be undefined before the untie otherwise the
136# underlying DB close routine will not get called.
137undef $X ;
138untie(@h);
139
140unlink $Dfile;
141
142exit ;