1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1996-2001
4
# Sleepycat Software. All rights reserved.
6
# $Id: test055.tcl,v 11.12 2001/01/25 18:23:12 bostic Exp $
9
# This test checks basic cursor operations.
10
# There are N different scenarios to tests:
11
# 1. (no dups) Set cursor, retrieve current.
12
# 2. (no dups) Set cursor, retrieve next.
13
# 3. (no dups) Set cursor, retrieve prev.
14
proc test055 { method args } {
18
set args [convert_args $method $args]
19
set omethod [convert_method $method]
21
puts "Test055: $method interspersed cursor and normal operations"
23
# Create the database and open the dictionary
24
set eindex [lsearch -exact $args "-env"]
26
# If we are using an env, then testfile should just be the db name.
27
# Otherwise it is the test directory and the name.
28
if { $eindex == -1 } {
29
set testfile $testdir/test055.db
32
set testfile test055.db
34
set env [lindex $args $eindex]
41
puts "\tTest055.a: No duplicates"
42
set db [eval {berkdb_open -create -truncate -mode 0644 $omethod } \
44
error_check_good db_open:nodup [is_valid_db $db] TRUE
46
set curs [eval {$db cursor} $txn]
47
error_check_good curs_open:nodup [is_substr $curs $db] 1
49
# Put three keys in the database
50
for { set key 1 } { $key <= 3 } {incr key} {
51
set r [eval {$db put} $txn $flags {$key datum$key}]
52
error_check_good put $r 0
55
# Retrieve keys sequentially so we can figure out their order
57
for {set d [$curs get -first] } { [llength $d] != 0 } {\
58
set d [$curs get -next] } {
59
set key_set($i) [lindex [lindex $d 0] 0]
64
puts "\tTest055.a1: Set cursor, retrieve current"
66
# Now set the cursor on the middle on.
67
set r [$curs get -set $key_set(2)]
68
error_check_bad cursor_get:DB_SET [llength $r] 0
69
set k [lindex [lindex $r 0] 0]
70
set d [lindex [lindex $r 0] 1]
71
error_check_good curs_get:DB_SET:key $k $key_set(2)
73
curs_get:DB_SET:data $d [pad_data $method datum$key_set(2)]
75
# Now retrieve current
76
set r [$curs get -current]
77
error_check_bad cursor_get:DB_CURRENT [llength $r] 0
78
set k [lindex [lindex $r 0] 0]
79
set d [lindex [lindex $r 0] 1]
80
error_check_good curs_get:DB_CURRENT:key $k $key_set(2)
82
curs_get:DB_CURRENT:data $d [pad_data $method datum$key_set(2)]
85
puts "\tTest055.a2: Set cursor, retrieve previous"
86
set r [$curs get -prev]
87
error_check_bad cursor_get:DB_PREV [llength $r] 0
88
set k [lindex [lindex $r 0] 0]
89
set d [lindex [lindex $r 0] 1]
90
error_check_good curs_get:DB_PREV:key $k $key_set(1)
92
curs_get:DB_PREV:data $d [pad_data $method datum$key_set(1)]
95
puts "\tTest055.a2: Set cursor, retrieve next"
97
# Now set the cursor on the middle on.
98
set r [$curs get -set $key_set(2)]
99
error_check_bad cursor_get:DB_SET [llength $r] 0
100
set k [lindex [lindex $r 0] 0]
101
set d [lindex [lindex $r 0] 1]
102
error_check_good curs_get:DB_SET:key $k $key_set(2)
104
curs_get:DB_SET:data $d [pad_data $method datum$key_set(2)]
107
set r [$curs get -next]
108
error_check_bad cursor_get:DB_NEXT [llength $r] 0
109
set k [lindex [lindex $r 0] 0]
110
set d [lindex [lindex $r 0] 1]
111
error_check_good curs_get:DB_NEXT:key $k $key_set(3)
113
curs_get:DB_NEXT:data $d [pad_data $method datum$key_set(3)]
115
# Close cursor and database.
116
error_check_good curs_close [$curs close] 0
117
error_check_good db_close [$db close] 0