summaryrefslogtreecommitdiff
path: root/bdb/test/test055.tcl
blob: fc5ce4e98bdcd0646fcdd678af5bcde56de644bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# See the file LICENSE for redistribution information.
#
# Copyright (c) 1996, 1997, 1998, 1999, 2000
#	Sleepycat Software.  All rights reserved.
#
#	$Id: test055.tcl,v 11.11 2000/08/25 14:21:57 sue Exp $
#
# Test055:
# This test checks basic cursor operations.
# There are N different scenarios to tests:
# 1. (no dups) Set cursor, retrieve current.
# 2. (no dups) Set cursor, retrieve next.
# 3. (no dups) Set cursor, retrieve prev.
proc test055 { method args } {
	global errorInfo
	source ./include.tcl

	set args [convert_args $method $args]
	set omethod [convert_method $method]

	puts "Test055: $method interspersed cursor and normal operations"

	# Create the database and open the dictionary
	set eindex [lsearch -exact $args "-env"]
	#
	# If we are using an env, then testfile should just be the db name.
	# Otherwise it is the test directory and the name.
	if { $eindex == -1 } {
		set testfile $testdir/test055.db
		set env NULL
	} else {
		set testfile test055.db
		incr eindex
		set env [lindex $args $eindex]
	}
	cleanup $testdir $env

	set flags ""
	set txn ""

	puts "\tTest055.a: No duplicates"
	set db [eval {berkdb_open -create -truncate -mode 0644 $omethod } \
	    $args {$testfile}]
	error_check_good db_open:nodup [is_valid_db $db] TRUE

	set curs [eval {$db cursor} $txn]
	error_check_good curs_open:nodup [is_substr $curs $db] 1

	# Put three keys in the database
	for { set key 1 } { $key <= 3 } {incr key} {
		set r [eval {$db put} $txn $flags {$key datum$key}]
		error_check_good put $r 0
	}

	# Retrieve keys sequentially so we can figure out their order
	set i 1
	for {set d [$curs get -first] } { [llength $d] != 0 } {\
		set d [$curs get -next] } {
		set key_set($i) [lindex [lindex $d 0] 0]
		incr i
	}

	# TEST CASE 1
	puts "\tTest055.a1: Set cursor, retrieve current"

	# Now set the cursor on the middle on.
	set r [$curs get -set $key_set(2)]
	error_check_bad cursor_get:DB_SET [llength $r] 0
	set k [lindex [lindex $r 0] 0]
	set d [lindex [lindex $r 0] 1]
	error_check_good curs_get:DB_SET:key $k $key_set(2)
	error_check_good \
	    curs_get:DB_SET:data $d [pad_data $method datum$key_set(2)]

	# Now retrieve current
	set r [$curs get -current]
	error_check_bad cursor_get:DB_CURRENT [llength $r] 0
	set k [lindex [lindex $r 0] 0]
	set d [lindex [lindex $r 0] 1]
	error_check_good curs_get:DB_CURRENT:key $k $key_set(2)
	error_check_good \
	    curs_get:DB_CURRENT:data $d [pad_data $method datum$key_set(2)]

	# TEST CASE 2
	puts "\tTest055.a2: Set cursor, retrieve previous"
	set r [$curs get -prev]
	error_check_bad cursor_get:DB_PREV [llength $r] 0
	set k [lindex [lindex $r 0] 0]
	set d [lindex [lindex $r 0] 1]
	error_check_good curs_get:DB_PREV:key $k $key_set(1)
	error_check_good \
	    curs_get:DB_PREV:data $d [pad_data $method datum$key_set(1)]

	#TEST CASE 3
	puts "\tTest055.a2: Set cursor, retrieve next"

	# Now set the cursor on the middle on.
	set r [$curs get -set $key_set(2)]
	error_check_bad cursor_get:DB_SET [llength $r] 0
	set k [lindex [lindex $r 0] 0]
	set d [lindex [lindex $r 0] 1]
	error_check_good curs_get:DB_SET:key $k $key_set(2)
	error_check_good \
	    curs_get:DB_SET:data $d [pad_data $method datum$key_set(2)]

	# Now retrieve next
	set r [$curs get -next]
	error_check_bad cursor_get:DB_NEXT [llength $r] 0
	set k [lindex [lindex $r 0] 0]
	set d [lindex [lindex $r 0] 1]
	error_check_good curs_get:DB_NEXT:key $k $key_set(3)
	error_check_good \
	    curs_get:DB_NEXT:data $d [pad_data $method datum$key_set(3)]

	# Close cursor and database.
	error_check_good curs_close [$curs close] 0
	error_check_good db_close [$db close] 0
}