1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1996-2002
4
# Sleepycat Software. All rights reserved.
8
# Historic NDBM interface test.
9
# Use the first 1000 entries from the dictionary.
10
# Insert each with self as key and data; retrieve each.
11
# After all are entered, retrieve all; compare output to original.
12
# Then reopen the file, re-retrieve everything.
13
# Finally, delete everything.
14
proc ndbm { { nentries 1000 } } {
17
puts "NDBM interfaces test: $nentries"
19
# Create the database and open the dictionary
20
set testfile $testdir/ndbmtest
26
set db [berkdb ndbm_open -create -truncate -mode 0644 $testfile]
27
error_check_good ndbm_open [is_substr $db ndbm] 1
30
error_check_good rdonly_false [$db rdonly] 0
37
puts "\tNDBM.a: put/get loop"
38
# Here is the loop where we put and get each key/data pair
39
while { [gets $did str] != -1 && $count < $nentries } {
40
# NDBM can't handle zero-length keys
41
if { [string length $str] == 0 } {
46
set ret [$db store $str $str insert]
47
error_check_good ndbm_store $ret 0
49
set d [$db fetch $str]
50
error_check_good ndbm_fetch $d $str
55
# Now we will get each key from the DB and compare the results
57
puts "\tNDBM.b: dump file"
59
for { set key [$db firstkey] } { $key != -1 } {
60
set key [$db nextkey] } {
62
set d [$db fetch $key]
63
error_check_good ndbm_refetch $d $key
66
# If we had to skip a zero-length key, juggle things to cover up
67
# this fact in the dump.
68
if { $skippednullkey == 1 } {
74
# Now compare the keys to see if they match the dictionary (or ints)
76
filehead $nentries $dict $t3
80
error_check_good NDBM:diff($t3,$t2) \
83
# File descriptors tests won't work under Windows.
84
if { $is_windows_test != 1 } {
85
puts "\tNDBM.c: pagf/dirf test"
87
error_check_bad pagf $fd -1
89
error_check_bad dirf $fd -1
92
puts "\tNDBM.d: close, open, and dump file"
94
# Now, reopen the file and run the last test again.
95
error_check_good ndbm_close [$db close] 0
96
set db [berkdb ndbm_open -rdonly $testfile]
97
error_check_good ndbm_open2 [is_substr $db ndbm] 1
100
error_check_good rdonly_true [$db rdonly] "rdonly:not owner"
102
for { set key [$db firstkey] } { $key != -1 } {
103
set key [$db nextkey] } {
105
set d [$db fetch $key]
106
error_check_good ndbm_refetch2 $d $key
108
if { $skippednullkey == 1 } {
113
# Now compare the keys to see if they match the dictionary (or ints)
116
error_check_good NDBM:diff($t2,$t3) \
119
# Now, reopen the file and delete each entry
120
puts "\tNDBM.e: sequential scan and delete"
122
error_check_good ndbm_close [$db close] 0
123
set db [berkdb ndbm_open $testfile]
124
error_check_good ndbm_open3 [is_substr $db ndbm] 1
127
for { set key [$db firstkey] } { $key != -1 } {
128
set key [$db nextkey] } {
130
set ret [$db delete $key]
131
error_check_good ndbm_delete $ret 0
133
if { $skippednullkey == 1 } {
138
# Now compare the keys to see if they match the dictionary (or ints)
141
error_check_good NDBM:diff($t2,$t3) \
143
error_check_good ndbm_close [$db close] 0