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

« back to all changes in this revision

Viewing changes to db/test/test059.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: test059.tcl,v 11.13 2001/01/25 18:23:12 bostic Exp $
 
7
#
 
8
# Test059:
 
9
# Make sure that we handle retrieves of zero-length data items correctly.
 
10
# The following ops, should allow a partial data retrieve of 0-length.
 
11
#       db_get
 
12
#       db_cget FIRST, NEXT, LAST, PREV, CURRENT, SET, SET_RANGE
 
13
#
 
14
proc test059 { method args } {
 
15
        source ./include.tcl
 
16
 
 
17
        set args [convert_args $method $args]
 
18
        set omethod [convert_method $method]
 
19
 
 
20
        puts "Test059: $method 0-length partial data retrieval"
 
21
 
 
22
        # Create the database and open the dictionary
 
23
        set eindex [lsearch -exact $args "-env"]
 
24
        #
 
25
        # If we are using an env, then testfile should just be the db name.
 
26
        # Otherwise it is the test directory and the name.
 
27
        if { $eindex == -1 } {
 
28
                set testfile $testdir/test059.db
 
29
                set env NULL
 
30
        } else {
 
31
                set testfile test059.db
 
32
                incr eindex
 
33
                set env [lindex $args $eindex]
 
34
        }
 
35
        cleanup $testdir $env
 
36
 
 
37
        set pflags ""
 
38
        set gflags ""
 
39
        set txn ""
 
40
        set count 0
 
41
 
 
42
        if { [is_record_based $method] == 1 } {
 
43
                append gflags " -recno"
 
44
        }
 
45
 
 
46
        puts "\tTest059.a: Populate a database"
 
47
        set oflags "-create -truncate -mode 0644 $omethod $args $testfile"
 
48
        set db [eval {berkdb_open} $oflags]
 
49
        error_check_good db_create [is_substr $db db] 1
 
50
 
 
51
        # Put ten keys in the database
 
52
        for { set key 1 } { $key <= 10 } {incr key} {
 
53
                set r [eval {$db put} $txn $pflags {$key datum$key}]
 
54
                error_check_good put $r 0
 
55
        }
 
56
 
 
57
        # Retrieve keys sequentially so we can figure out their order
 
58
        set i 1
 
59
        set curs [$db cursor]
 
60
        error_check_good db_curs [is_substr $curs $db] 1
 
61
 
 
62
        for {set d [$curs get -first] } { [llength $d] != 0 } {
 
63
            set d [$curs get -next] } {
 
64
                set key_set($i) [lindex [lindex $d 0] 0]
 
65
                incr i
 
66
        }
 
67
 
 
68
        puts "\tTest059.a: db get with 0 partial length retrieve"
 
69
 
 
70
        # Now set the cursor on the middle one.
 
71
        set ret [eval {$db get -partial {0 0}} $gflags {$key_set(5)}]
 
72
        error_check_bad db_get_0 [llength $ret] 0
 
73
 
 
74
        puts "\tTest059.a: db cget FIRST with 0 partial length retrieve"
 
75
        set ret [$curs get -first -partial {0 0}]
 
76
        set data [lindex [lindex $ret 0] 1]
 
77
        set key [lindex [lindex $ret 0] 0]
 
78
        error_check_good key_check_first $key $key_set(1)
 
79
        error_check_good db_cget_first [string length $data] 0
 
80
 
 
81
        puts "\tTest059.b: db cget NEXT with 0 partial length retrieve"
 
82
        set ret [$curs get -next -partial {0 0}]
 
83
        set data [lindex [lindex $ret 0] 1]
 
84
        set key [lindex [lindex $ret 0] 0]
 
85
        error_check_good key_check_next $key $key_set(2)
 
86
        error_check_good db_cget_next [string length $data] 0
 
87
 
 
88
        puts "\tTest059.c: db cget LAST with 0 partial length retrieve"
 
89
        set ret [$curs get -last -partial {0 0}]
 
90
        set data [lindex [lindex $ret 0] 1]
 
91
        set key [lindex [lindex $ret 0] 0]
 
92
        error_check_good key_check_last $key $key_set(10)
 
93
        error_check_good db_cget_last [string length $data] 0
 
94
 
 
95
        puts "\tTest059.d: db cget PREV with 0 partial length retrieve"
 
96
        set ret [$curs get -prev -partial {0 0}]
 
97
        set data [lindex [lindex $ret 0] 1]
 
98
        set key [lindex [lindex $ret 0] 0]
 
99
        error_check_good key_check_prev $key $key_set(9)
 
100
        error_check_good db_cget_prev [string length $data] 0
 
101
 
 
102
        puts "\tTest059.e: db cget CURRENT with 0 partial length retrieve"
 
103
        set ret [$curs get -current -partial {0 0}]
 
104
        set data [lindex [lindex $ret 0] 1]
 
105
        set key [lindex [lindex $ret 0] 0]
 
106
        error_check_good key_check_current $key $key_set(9)
 
107
        error_check_good db_cget_current [string length $data] 0
 
108
 
 
109
        puts "\tTest059.f: db cget SET with 0 partial length retrieve"
 
110
        set ret [$curs get -set -partial {0 0} $key_set(7)]
 
111
        set data [lindex [lindex $ret 0] 1]
 
112
        set key [lindex [lindex $ret 0] 0]
 
113
        error_check_good key_check_set $key $key_set(7)
 
114
        error_check_good db_cget_set [string length $data] 0
 
115
 
 
116
        if {[is_btree $method] == 1} {
 
117
                puts "\tTest059.g:\
 
118
                    db cget SET_RANGE with 0 partial length retrieve"
 
119
                set ret [$curs get -set_range -partial {0 0} $key_set(5)]
 
120
                set data [lindex [lindex $ret 0] 1]
 
121
                set key [lindex [lindex $ret 0] 0]
 
122
                error_check_good key_check_set $key $key_set(5)
 
123
                error_check_good db_cget_set [string length $data] 0
 
124
        }
 
125
 
 
126
        error_check_good curs_close [$curs close] 0
 
127
        error_check_good db_close [$db close] 0
 
128
}