1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1996-2001
4
# Sleepycat Software. All rights reserved.
6
# $Id: test019.tcl,v 11.17 2001/07/02 01:08:46 bostic Exp $
8
# Test019 { access_method nentries }
9
# Test the partial get functionality.
10
proc test019 { method {nentries 10000} args } {
15
set args [convert_args $method $args]
16
set omethod [convert_method $method]
17
puts "Test019: $method ($args) $nentries partial get test"
19
# Create the database and open the dictionary
20
set eindex [lsearch -exact $args "-env"]
22
# If we are using an env, then testfile should just be the db name.
23
# Otherwise it is the test directory and the name.
24
if { $eindex == -1 } {
25
set testfile $testdir/test019.db
28
set testfile test019.db
30
set env [lindex $args $eindex]
34
set db [eval {berkdb_open \
35
-create -truncate -mode 0644} $args {$omethod $testfile}]
36
error_check_good dbopen [is_valid_db $db] TRUE
38
berkdb srand $rand_init
45
if { [is_record_based $method] == 1 } {
46
append gflags " -recno"
49
puts "\tTest019.a: put/get loop"
50
for { set i 0 } { [gets $did str] != -1 && $i < $nentries } \
53
if { [is_record_based $method] == 1 } {
58
set repl [berkdb random_int $fixed_len 100]
59
set data [chop_data $method [replicate $str $repl]]
60
set ret [eval {$db put} $txn {-nooverwrite $key $data}]
61
error_check_good dbput:$key $ret 0
63
set ret [eval {$db get} $txn $gflags {$key}]
65
dbget:$key $ret [list [list $key [pad_data $method $data]]]
70
puts "\tTest019.b: partial get loop"
72
for { set i 0 } { [gets $did str] != -1 && $i < $nentries } \
74
if { [is_record_based $method] == 1 } {
79
set data [pad_data $method [replicate $str $kvals($key)]]
81
set maxndx [expr [string length $data] - 1]
83
set beg [berkdb random_int 0 [expr $maxndx - 1]]
84
set len [berkdb random_int 0 [expr $maxndx * 2]]
86
set ret [eval {$db get} \
87
$txn {-partial [list $beg $len]} $gflags {$key}]
89
# In order for tcl to handle this, we have to overwrite the
90
# last character with a NULL. That makes the length one less
92
set k [lindex [lindex $ret 0] 0]
93
set d [lindex [lindex $ret 0] 1]
94
error_check_good dbget_key $k $key
96
error_check_good dbget_data $d \
97
[string range $data $beg [expr $beg + $len - 1]]
100
error_check_good db_close [$db close] 0