~ubuntu-branches/ubuntu/edgy/rpm/edgy

« back to all changes in this revision

Viewing changes to db/test/test055.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Joey Hess
  • Date: 2002-01-22 20:56:57 UTC
  • Revision ID: james.westby@ubuntu.com-20020122205657-l74j50mr9z8ofcl5
Tags: upstream-4.0.3
ImportĀ upstreamĀ versionĀ 4.0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# See the file LICENSE for redistribution information.
 
2
#
 
3
# Copyright (c) 1996-2001
 
4
#       Sleepycat Software.  All rights reserved.
 
5
#
 
6
# $Id: test055.tcl,v 11.12 2001/01/25 18:23:12 bostic Exp $
 
7
#
 
8
# Test055:
 
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 } {
 
15
        global errorInfo
 
16
        source ./include.tcl
 
17
 
 
18
        set args [convert_args $method $args]
 
19
        set omethod [convert_method $method]
 
20
 
 
21
        puts "Test055: $method interspersed cursor and normal operations"
 
22
 
 
23
        # Create the database and open the dictionary
 
24
        set eindex [lsearch -exact $args "-env"]
 
25
        #
 
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
 
30
                set env NULL
 
31
        } else {
 
32
                set testfile test055.db
 
33
                incr eindex
 
34
                set env [lindex $args $eindex]
 
35
        }
 
36
        cleanup $testdir $env
 
37
 
 
38
        set flags ""
 
39
        set txn ""
 
40
 
 
41
        puts "\tTest055.a: No duplicates"
 
42
        set db [eval {berkdb_open -create -truncate -mode 0644 $omethod } \
 
43
            $args {$testfile}]
 
44
        error_check_good db_open:nodup [is_valid_db $db] TRUE
 
45
 
 
46
        set curs [eval {$db cursor} $txn]
 
47
        error_check_good curs_open:nodup [is_substr $curs $db] 1
 
48
 
 
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
 
53
        }
 
54
 
 
55
        # Retrieve keys sequentially so we can figure out their order
 
56
        set i 1
 
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]
 
60
                incr i
 
61
        }
 
62
 
 
63
        # TEST CASE 1
 
64
        puts "\tTest055.a1: Set cursor, retrieve current"
 
65
 
 
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)
 
72
        error_check_good \
 
73
            curs_get:DB_SET:data $d [pad_data $method datum$key_set(2)]
 
74
 
 
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)
 
81
        error_check_good \
 
82
            curs_get:DB_CURRENT:data $d [pad_data $method datum$key_set(2)]
 
83
 
 
84
        # TEST CASE 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)
 
91
        error_check_good \
 
92
            curs_get:DB_PREV:data $d [pad_data $method datum$key_set(1)]
 
93
 
 
94
        #TEST CASE 3
 
95
        puts "\tTest055.a2: Set cursor, retrieve next"
 
96
 
 
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)
 
103
        error_check_good \
 
104
            curs_get:DB_SET:data $d [pad_data $method datum$key_set(2)]
 
105
 
 
106
        # Now retrieve next
 
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)
 
112
        error_check_good \
 
113
            curs_get:DB_NEXT:data $d [pad_data $method datum$key_set(3)]
 
114
 
 
115
        # Close cursor and database.
 
116
        error_check_good curs_close [$curs close] 0
 
117
        error_check_good db_close [$db close] 0
 
118
}