1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1996-2001
4
# Sleepycat Software. All rights reserved.
6
# $Id: test036.tcl,v 11.14 2001/01/25 18:23:10 bostic Exp $
8
# DB Test 36 {access method}
9
# Put nentries key/data pairs (from the dictionary) using a cursor
10
# and KEYFIRST and KEYLAST (this tests the case where use use cursor
11
# put for non-existent keys).
12
proc test036 { method {nentries 10000} args } {
15
set args [convert_args $method $args]
16
set omethod [convert_method $method]
18
puts "Test036: $method ($args) $nentries equal key/data pairs"
19
if { [is_record_based $method] == 1 } {
20
puts "Test036 skipping for method recno"
24
# Create the database and open the dictionary
25
set eindex [lsearch -exact $args "-env"]
27
# If we are using an env, then testfile should just be the db name.
28
# Otherwise it is the test directory and the name.
29
if { $eindex == -1 } {
30
set testfile $testdir/test036.db
33
set testfile test036.db
35
set env [lindex $args $eindex]
41
set db [eval {berkdb_open \
42
-create -truncate -mode 0644} $args {$omethod $testfile}]
43
error_check_good dbopen [is_valid_db $db] TRUE
51
if { [is_record_based $method] == 1 } {
52
set checkfunc test036_recno.check
53
append gflags " -recno"
55
set checkfunc test036.check
57
puts "\tTest036.a: put/get loop KEYFIRST"
58
# Here is the loop where we put and get each key/data pair
59
set dbc [eval {$db cursor} $txn]
60
error_check_good cursor [is_substr $dbc $db] 1
61
while { [gets $did str] != -1 && $count < $nentries } {
62
if { [is_record_based $method] == 1 } {
65
set key [expr $count + 1]
70
set ret [eval {$dbc put} $txn $pflags {-keyfirst $key $str}]
71
error_check_good put $ret 0
73
set ret [eval {$db get} $txn $gflags {$key}]
74
error_check_good get [lindex [lindex $ret 0] 1] $str
77
error_check_good dbc_close [$dbc close] 0
79
puts "\tTest036.a: put/get loop KEYLAST"
80
set dbc [eval {$db cursor} $txn]
81
error_check_good cursor [is_substr $dbc $db] 1
82
while { [gets $did str] != -1 && $count < $nentries } {
83
if { [is_record_based $method] == 1 } {
86
set key [expr $count + 1]
91
set ret [eval {$dbc put} $txn $pflags {-keylast $key $str}]
92
error_check_good put $ret 0
94
set ret [eval {$db get} $txn $gflags {$key}]
95
error_check_good get [lindex [lindex $ret 0] 1] $str
98
error_check_good dbc_close [$dbc close] 0
101
# Now we will get each key from the DB and compare the results
103
puts "\tTest036.c: dump file"
104
dump_file $db $txn $t1 $checkfunc
105
error_check_good db_close [$db close] 0
107
# Now compare the keys to see if they match the dictionary (or ints)
108
if { [is_record_based $method] == 1 } {
110
for {set i 1} {$i <= $nentries} {set i [incr i]} {
114
file rename -force $t1 $t3
117
filehead $nentries $dict $t3
124
# Check function for test036; keys and data are identical
125
proc test036.check { key data } {
126
error_check_good "key/data mismatch" $data $key
129
proc test036_recno.check { key data } {
133
error_check_good key"$key"_exists [info exists kvals($key)] 1
134
error_check_good "key/data mismatch, key $key" $data $kvals($key)