~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to libdb/test/test047.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# See the file LICENSE for redistribution information.
2
 
#
3
 
# Copyright (c) 1999-2002
4
 
#       Sleepycat Software.  All rights reserved.
5
 
#
6
 
# $Id$
7
 
#
8
 
# TEST  test047
9
 
# TEST  DBcursor->c_get get test with SET_RANGE option.
10
 
proc test047 { method args } {
11
 
        source ./include.tcl
12
 
 
13
 
        set tstn 047
14
 
        set args [convert_args $method $args]
15
 
 
16
 
        if { [is_btree $method] != 1 } {
17
 
                puts "Test$tstn skipping for method $method"
18
 
                return
19
 
        }
20
 
 
21
 
        set method "-btree"
22
 
 
23
 
        puts "\tTest$tstn: Test of SET_RANGE interface to DB->c_get ($method)."
24
 
 
25
 
        set key "key"
26
 
        set data        "data"
27
 
        set txn ""
28
 
        set flags ""
29
 
 
30
 
        puts "\tTest$tstn.a: Create $method database."
31
 
        set eindex [lsearch -exact $args "-env"]
32
 
        set txnenv 0
33
 
        #
34
 
        # If we are using an env, then testfile should just be the db name.
35
 
        # Otherwise it is the test directory and the name.
36
 
        if { $eindex == -1 } {
37
 
                set testfile $testdir/test0$tstn.db
38
 
                set testfile1 $testdir/test0$tstn.a.db
39
 
                set testfile2 $testdir/test0$tstn.b.db
40
 
                set env NULL
41
 
        } else {
42
 
                set testfile test0$tstn.db
43
 
                set testfile1 test0$tstn.a.db
44
 
                set testfile2 test0$tstn.b.db
45
 
                incr eindex
46
 
                set env [lindex $args $eindex]
47
 
                set txnenv [is_txnenv $env]
48
 
                if { $txnenv == 1 } {
49
 
                        append args " -auto_commit "
50
 
                }
51
 
                set testdir [get_home $env]
52
 
        }
53
 
        set t1 $testdir/t1
54
 
        cleanup $testdir $env
55
 
 
56
 
        set oflags "-create -mode 0644 -dup $args $method"
57
 
        set db [eval {berkdb_open} $oflags $testfile]
58
 
        error_check_good dbopen [is_valid_db $db] TRUE
59
 
 
60
 
        set nkeys 20
61
 
        # Fill page w/ small key/data pairs
62
 
        #
63
 
        puts "\tTest$tstn.b: Fill page with $nkeys small key/data pairs."
64
 
        for { set i 0 } { $i < $nkeys } { incr i } {
65
 
                if { $txnenv == 1 } {
66
 
                        set t [$env txn]
67
 
                        error_check_good txn [is_valid_txn $t $env] TRUE
68
 
                        set txn "-txn $t"
69
 
                }
70
 
                set ret [eval {$db put} $txn {$key$i $data$i}]
71
 
                error_check_good dbput $ret 0
72
 
                if { $txnenv == 1 } {
73
 
                        error_check_good txn [$t commit] 0
74
 
                }
75
 
        }
76
 
 
77
 
        if { $txnenv == 1 } {
78
 
                set t [$env txn]
79
 
                error_check_good txn [is_valid_txn $t $env] TRUE
80
 
                set txn "-txn $t"
81
 
        }
82
 
        # open curs to db
83
 
        set dbc [eval {$db cursor} $txn]
84
 
        error_check_good db_cursor [is_valid_cursor $dbc $db] TRUE
85
 
 
86
 
        puts "\tTest$tstn.c: Get data with SET_RANGE, then delete by cursor."
87
 
        set i 0
88
 
        set ret [$dbc get -set_range $key$i]
89
 
        error_check_bad dbc_get:set_range [llength $ret] 0
90
 
        set curr $ret
91
 
 
92
 
        # delete by cursor, make sure it is gone
93
 
        error_check_good dbc_del [$dbc del] 0
94
 
 
95
 
        set ret [$dbc get -set_range $key$i]
96
 
        error_check_bad dbc_get(post-delete):set_range [llength $ret] 0
97
 
        error_check_bad dbc_get(no-match):set_range $ret $curr
98
 
 
99
 
        puts "\tTest$tstn.d: \
100
 
            Use another cursor to fix item on page, delete by db."
101
 
        set dbcurs2 [eval {$db cursor} $txn]
102
 
        error_check_good db:cursor2 [is_valid_cursor $dbcurs2 $db] TRUE
103
 
 
104
 
        set ret [$dbcurs2 get -set [lindex [lindex $ret 0] 0]]
105
 
        error_check_bad dbc_get(2):set [llength $ret] 0
106
 
        set curr $ret
107
 
        error_check_good db:del [eval {$db del} $txn \
108
 
            {[lindex [lindex $ret 0] 0]}] 0
109
 
 
110
 
        # make sure item is gone
111
 
        set ret [$dbcurs2 get -set_range [lindex [lindex $curr 0] 0]]
112
 
        error_check_bad dbc2_get:set_range [llength $ret] 0
113
 
        error_check_bad dbc2_get:set_range $ret $curr
114
 
 
115
 
        puts "\tTest$tstn.e: Close for second part of test, close db/cursors."
116
 
        error_check_good dbc:close [$dbc close] 0
117
 
        error_check_good dbc2:close [$dbcurs2 close] 0
118
 
        if { $txnenv == 1 } {
119
 
                error_check_good txn [$t commit] 0
120
 
        }
121
 
        error_check_good dbclose [$db close] 0
122
 
 
123
 
        # open db
124
 
        set db [eval {berkdb_open} $oflags $testfile1]
125
 
        error_check_good dbopen2 [is_valid_db $db] TRUE
126
 
 
127
 
        set nkeys 10
128
 
        puts "\tTest$tstn.f: Fill page with $nkeys pairs, one set of dups."
129
 
        for {set i 0} { $i < $nkeys } {incr i} {
130
 
                # a pair
131
 
                if { $txnenv == 1 } {
132
 
                        set t [$env txn]
133
 
                        error_check_good txn [is_valid_txn $t $env] TRUE
134
 
                        set txn "-txn $t"
135
 
                }
136
 
                set ret [eval {$db put} $txn {$key$i $data$i}]
137
 
                error_check_good dbput($i) $ret 0
138
 
                if { $txnenv == 1 } {
139
 
                        error_check_good txn [$t commit] 0
140
 
                }
141
 
        }
142
 
 
143
 
        set j 0
144
 
        for {set i 0} { $i < $nkeys } {incr i} {
145
 
                # a dup set for same  1 key
146
 
                if { $txnenv == 1 } {
147
 
                        set t [$env txn]
148
 
                        error_check_good txn [is_valid_txn $t $env] TRUE
149
 
                        set txn "-txn $t"
150
 
                }
151
 
                set ret [eval {$db put} $txn {$key$i DUP_$data$i}]
152
 
                error_check_good dbput($i):dup $ret 0
153
 
                if { $txnenv == 1 } {
154
 
                        error_check_good txn [$t commit] 0
155
 
                }
156
 
        }
157
 
 
158
 
        puts "\tTest$tstn.g: \
159
 
            Get dups key w/ SET_RANGE, pin onpage with another cursor."
160
 
        set i 0
161
 
        if { $txnenv == 1 } {
162
 
                set t [$env txn]
163
 
                error_check_good txn [is_valid_txn $t $env] TRUE
164
 
                set txn "-txn $t"
165
 
        }
166
 
        set dbc [eval {$db cursor} $txn]
167
 
        error_check_good db_cursor [is_valid_cursor $dbc $db] TRUE
168
 
        set ret [$dbc get -set_range $key$i]
169
 
        error_check_bad dbc_get:set_range [llength $ret] 0
170
 
 
171
 
        set dbc2 [eval {$db cursor} $txn]
172
 
        error_check_good db_cursor [is_valid_cursor $dbc2 $db] TRUE
173
 
        set ret2 [$dbc2 get -set_range $key$i]
174
 
        error_check_bad dbc2_get:set_range [llength $ret] 0
175
 
 
176
 
        error_check_good dbc_compare $ret $ret2
177
 
        puts "\tTest$tstn.h: \
178
 
            Delete duplicates' key, use SET_RANGE to get next dup."
179
 
        set ret [$dbc2 del]
180
 
        error_check_good dbc2_del $ret 0
181
 
        set ret [$dbc get -set_range $key$i]
182
 
        error_check_bad dbc_get:set_range [llength $ret] 0
183
 
        error_check_bad dbc_get:set_range $ret $ret2
184
 
 
185
 
        error_check_good dbc_close [$dbc close] 0
186
 
        error_check_good dbc2_close [$dbc2 close] 0
187
 
        if { $txnenv == 1 } {
188
 
                error_check_good txn [$t commit] 0
189
 
        }
190
 
        error_check_good db_close [$db close] 0
191
 
 
192
 
        set db [eval {berkdb_open} $oflags $testfile2]
193
 
        error_check_good dbopen [is_valid_db $db] TRUE
194
 
 
195
 
        set nkeys 10
196
 
        set ndups 1000
197
 
 
198
 
        puts "\tTest$tstn.i: Fill page with $nkeys pairs and $ndups dups."
199
 
        for {set i 0} { $i < $nkeys } { incr i} {
200
 
                # a pair
201
 
                if { $txnenv == 1 } {
202
 
                        set t [$env txn]
203
 
                        error_check_good txn [is_valid_txn $t $env] TRUE
204
 
                        set txn "-txn $t"
205
 
                }
206
 
                set ret [eval {$db put} $txn {$key$i $data$i}]
207
 
                error_check_good dbput $ret 0
208
 
 
209
 
                # dups for single pair
210
 
                if { $i == 0} {
211
 
                        for {set j 0} { $j < $ndups } { incr j } {
212
 
                                set ret [eval {$db put} $txn \
213
 
                                    {$key$i DUP_$data$i:$j}]
214
 
                                error_check_good dbput:dup $ret 0
215
 
                        }
216
 
                }
217
 
                if { $txnenv == 1 } {
218
 
                        error_check_good txn [$t commit] 0
219
 
                }
220
 
        }
221
 
        set i 0
222
 
        if { $txnenv == 1 } {
223
 
                set t [$env txn]
224
 
                error_check_good txn [is_valid_txn $t $env] TRUE
225
 
                set txn "-txn $t"
226
 
        }
227
 
        set dbc [eval {$db cursor} $txn]
228
 
        error_check_good db_cursor [is_valid_cursor $dbc $db] TRUE
229
 
        set dbc2 [eval {$db cursor} $txn]
230
 
        error_check_good db_cursor [is_valid_cursor $dbc2 $db] TRUE
231
 
        puts "\tTest$tstn.j: \
232
 
            Get key of first dup with SET_RANGE, fix with 2 curs."
233
 
        set ret [$dbc get -set_range $key$i]
234
 
        error_check_bad dbc_get:set_range [llength $ret] 0
235
 
 
236
 
        set ret2 [$dbc2 get -set_range $key$i]
237
 
        error_check_bad dbc2_get:set_range [llength $ret] 0
238
 
        set curr $ret2
239
 
 
240
 
        error_check_good dbc_compare $ret $ret2
241
 
 
242
 
        puts "\tTest$tstn.k: Delete item by cursor, use SET_RANGE to verify."
243
 
        set ret [$dbc2 del]
244
 
        error_check_good dbc2_del $ret 0
245
 
        set ret [$dbc get -set_range $key$i]
246
 
        error_check_bad dbc_get:set_range [llength $ret] 0
247
 
        error_check_bad dbc_get:set_range $ret $curr
248
 
 
249
 
        puts "\tTest$tstn.l: Cleanup."
250
 
        error_check_good dbc_close [$dbc close] 0
251
 
        error_check_good dbc2_close [$dbc2 close] 0
252
 
        if { $txnenv == 1 } {
253
 
                error_check_good txn [$t commit] 0
254
 
        }
255
 
        error_check_good db_close [$db close] 0
256
 
 
257
 
        puts "\tTest$tstn complete."
258
 
}