proc test068 { method args } {
source ./include.tcl
global alphabet
global errorCode
set tnum "068"
set args [convert_args $method $args]
set omethod [convert_method $method]
set txnenv 0
set eindex [lsearch -exact $args "-env"]
set nkeys 1000
if { $eindex == -1 } {
set testfile $testdir/test$tnum.db
set env NULL
} else {
set testfile test$tnum.db
incr eindex
set env [lindex $args $eindex]
set txnenv [is_txnenv $env]
if { $txnenv == 1 } {
append args " -auto_commit "
set nkeys 100
}
set testdir [get_home $env]
}
puts "Test$tnum:\
$method ($args) Test of DB_BEFORE/DB_AFTER and partial puts."
if { [is_record_based $method] == 1 } {
puts "\tTest$tnum: skipping for method $method."
return
}
puts "\tTest$tnum.a: Initialize word list."
set txn ""
set wordlist {}
set count 0
set did [open $dict]
while { [gets $did str] != -1 && $count < $nkeys } {
lappend wordlist $str
incr count
}
close $did
error_check_good enough_keys [llength $wordlist] $nkeys
if { [is_rbtree $method] == 1 } {
set dupoptlist { "" }
} else {
set dupoptlist { "" "-dup" "-dup -dupsort" }
}
foreach dupopt $dupoptlist {
if { $env != "NULL" } {
set testdir [get_home $env]
}
cleanup $testdir $env
set db [eval {berkdb_open_noerr -create -mode 0644 \
$omethod} $args $dupopt {$testfile}]
error_check_good db_open [is_valid_db $db] TRUE
puts "\tTest$tnum.b ($dupopt): DB initialization: put loop."
foreach word $wordlist {
if { $txnenv == 1 } {
set t [$env txn]
error_check_good txn [is_valid_txn $t $env] TRUE
set txn "-txn $t"
}
set ret [eval {$db put} $txn {$word $word}]
error_check_good db_put $ret 0
if { $txnenv == 1 } {
error_check_good txn [$t commit] 0
}
}
puts "\tTest$tnum.c ($dupopt): get loop."
foreach word $wordlist {
set dbt [$db get $word]
error_check_good get_key [list [list $word $word]] $dbt
}
if { $txnenv == 1 } {
set t [$env txn]
error_check_good txn [is_valid_txn $t $env] TRUE
set txn "-txn $t"
}
set dbc [eval {$db cursor} $txn]
error_check_good cursor_open [is_valid_cursor $dbc $db] TRUE
puts "\tTest$tnum.d ($dupopt): DBC->put w/ DB_AFTER."
set dbt [eval {$dbc get -first}]
error_check_good \
dbc_get_first [llength $dbt] 1
if { $dupopt != "-dup" } {
set errorCode "NONE"
set ret [catch {eval $dbc put -after \
{-partial [list 6 0]} "after"} res]
error_check_good dbc_put_after_fail $ret 1
error_check_good dbc_put_after_einval \
[is_substr $errorCode EINVAL] 1
puts "\tTest$tnum ($dupopt): DB_AFTER returns EINVAL."
set errorCode "NONE"
set ret [catch {eval $dbc put -before \
{-partial [list 6 0]} "before"} res]
error_check_good dbc_put_before_fail $ret 1
error_check_good dbc_put_before_einval \
[is_substr $errorCode EINVAL] 1
puts "\tTest$tnum ($dupopt): DB_BEFORE returns EINVAL."
puts "\tTest$tnum ($dupopt): Correct error returns,\
skipping further test."
error_check_good dbc_close [$dbc close] 0
if { $txnenv == 1 } {
error_check_good txn [$t commit] 0
}
error_check_good db_close [$db close] 0
continue
}
puts "\tTest$tnum.e ($dupopt): DBC->put(DB_AFTER) loop."
foreach word $wordlist {
set dbt [$dbc get -set $word]
error_check_good \
dbc_get_set $dbt [list [list $word $word]]
set ret [$dbc put -after -partial {4 0} after]
error_check_good dbc_put_after $ret 0
}
puts "\tTest$tnum.f ($dupopt): DBC->put(DB_BEFORE) loop."
foreach word $wordlist {
set dbt [$dbc get -set $word]
error_check_good \
dbc_get_set $dbt [list [list $word $word]]
set ret [$dbc put -before -partial {6 0} before]
error_check_good dbc_put_before $ret 0
}
error_check_good dbc_close [$dbc close] 0
if { $txnenv == 1 } {
error_check_good txn [$t commit] 0
}
eval $db sync
puts "\tTest$tnum.g ($dupopt): Verify correctness."
if { $txnenv == 1 } {
set t [$env txn]
error_check_good txn [is_valid_txn $t $env] TRUE
set txn "-txn $t"
}
set dbc [eval {$db cursor} $txn]
error_check_good db_cursor [is_valid_cursor $dbc $db] TRUE
set count 0
while { $count < $nkeys } {
set dbt [$dbc get -next]
set word [lindex [lindex $dbt 0] 0]
error_check_good dbc_get_one $dbt \
[list [list $word "\0\0\0\0\0\0before"]]
set dbt [$dbc get -next]
error_check_good \
dbc_get_two $dbt [list [list $word $word]]
set dbt [$dbc get -next]
error_check_good dbc_get_three $dbt \
[list [list $word "\0\0\0\0after"]]
incr count
}
error_check_good dbc_close [$dbc close] 0
if { $txnenv == 1 } {
error_check_good txn [$t commit] 0
}
error_check_good db_close [$db close] 0
}
}