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

« back to all changes in this revision

Viewing changes to libdb/test/test068.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  test068
9
 
# TEST  Test of DB_BEFORE and DB_AFTER with partial puts.
10
 
# TEST  Make sure DB_BEFORE and DB_AFTER work properly with partial puts, and
11
 
# TEST  check that they return EINVAL if DB_DUPSORT is set or if DB_DUP is not.
12
 
proc test068 { method args } {
13
 
        source ./include.tcl
14
 
        global alphabet
15
 
        global errorCode
16
 
 
17
 
        set tnum 68
18
 
 
19
 
        set args [convert_args $method $args]
20
 
        set omethod [convert_method $method]
21
 
 
22
 
        set txnenv 0
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
 
        set nkeys 1000
28
 
        if { $eindex == -1 } {
29
 
                set testfile $testdir/test0$tnum.db
30
 
                set env NULL
31
 
        } else {
32
 
                set testfile test0$tnum.db
33
 
                incr eindex
34
 
                set env [lindex $args $eindex]
35
 
                set txnenv [is_txnenv $env]
36
 
                if { $txnenv == 1 } {
37
 
                        append args " -auto_commit "
38
 
                        set nkeys 100
39
 
                }
40
 
                set testdir [get_home $env]
41
 
        }
42
 
 
43
 
        puts "Test0$tnum:\
44
 
            $method ($args) Test of DB_BEFORE/DB_AFTER and partial puts."
45
 
        if { [is_record_based $method] == 1 } {
46
 
            puts "\tTest0$tnum: skipping for method $method."
47
 
            return
48
 
        }
49
 
 
50
 
        # Create a list of $nkeys words to insert into db.
51
 
        puts "\tTest0$tnum.a: Initialize word list."
52
 
        set txn ""
53
 
        set wordlist {}
54
 
        set count 0
55
 
        set did [open $dict]
56
 
        while { [gets $did str] != -1 && $count < $nkeys } {
57
 
                lappend wordlist $str
58
 
                incr count
59
 
        }
60
 
        close $did
61
 
 
62
 
        # Sanity check:  did we get $nkeys words?
63
 
        error_check_good enough_keys [llength $wordlist] $nkeys
64
 
 
65
 
        # rbtree can't handle dups, so just test the non-dup case
66
 
        # if it's the current method.
67
 
        if { [is_rbtree $method] == 1 } {
68
 
                set dupoptlist { "" }
69
 
        } else {
70
 
                set dupoptlist { "" "-dup" "-dup -dupsort" }
71
 
        }
72
 
 
73
 
        foreach dupopt $dupoptlist {
74
 
                #
75
 
                # Testdir might be reset in the loop by some proc sourcing
76
 
                # include.tcl.  Reset it to the env's home here, before
77
 
                # cleanup.
78
 
                if { $env != "NULL" } {
79
 
                        set testdir [get_home $env]
80
 
                }
81
 
                cleanup $testdir $env
82
 
                set db [eval {berkdb_open_noerr -create -mode 0644 \
83
 
                    $omethod} $args $dupopt {$testfile}]
84
 
                error_check_good db_open [is_valid_db $db] TRUE
85
 
 
86
 
                puts "\tTest0$tnum.b ($dupopt): DB initialization: put loop."
87
 
                foreach word $wordlist {
88
 
                        if { $txnenv == 1 } {
89
 
                                set t [$env txn]
90
 
                                error_check_good txn [is_valid_txn $t $env] TRUE
91
 
                                set txn "-txn $t"
92
 
                        }
93
 
                        set ret [eval {$db put} $txn {$word $word}]
94
 
                        error_check_good db_put $ret 0
95
 
                        if { $txnenv == 1 } {
96
 
                                error_check_good txn [$t commit] 0
97
 
                        }
98
 
                }
99
 
 
100
 
                puts "\tTest0$tnum.c ($dupopt): get loop."
101
 
                foreach word $wordlist {
102
 
                        # Make sure that the Nth word has been correctly
103
 
                        # inserted, and also that the Nth word is the
104
 
                        # Nth one we pull out of the database using a cursor.
105
 
 
106
 
                        set dbt [$db get $word]
107
 
                        error_check_good get_key [list [list $word $word]] $dbt
108
 
                }
109
 
 
110
 
                if { $txnenv == 1 } {
111
 
                        set t [$env txn]
112
 
                        error_check_good txn [is_valid_txn $t $env] TRUE
113
 
                        set txn "-txn $t"
114
 
                }
115
 
                set dbc [eval {$db cursor} $txn]
116
 
                error_check_good cursor_open [is_valid_cursor $dbc $db] TRUE
117
 
 
118
 
                puts "\tTest0$tnum.d ($dupopt): DBC->put w/ DB_AFTER."
119
 
 
120
 
                # Set cursor to the first key;  make sure it succeeds.
121
 
                # With an unsorted wordlist, we can't be sure that the
122
 
                # first item returned will equal the first item in the
123
 
                # wordlist, so we just make sure it got something back.
124
 
                set dbt [eval {$dbc get -first}]
125
 
                error_check_good \
126
 
                    dbc_get_first [llength $dbt] 1
127
 
 
128
 
                # If -dup is not set, or if -dupsort is set too, we
129
 
                # need to verify that DB_BEFORE and DB_AFTER fail
130
 
                # and then move on to the next $dupopt.
131
 
                if { $dupopt != "-dup" } {
132
 
                        set errorCode "NONE"
133
 
                        set ret [catch {eval $dbc put -after \
134
 
                                {-partial [list 6 0]} "after"} res]
135
 
                        error_check_good dbc_put_after_fail $ret 1
136
 
                        error_check_good dbc_put_after_einval \
137
 
                                [is_substr $errorCode EINVAL] 1
138
 
                        puts "\tTest0$tnum ($dupopt): DB_AFTER returns EINVAL."
139
 
                        set errorCode "NONE"
140
 
                        set ret [catch {eval $dbc put -before \
141
 
                                {-partial [list 6 0]} "before"} res]
142
 
                        error_check_good dbc_put_before_fail $ret 1
143
 
                        error_check_good dbc_put_before_einval \
144
 
                                [is_substr $errorCode EINVAL] 1
145
 
                        puts "\tTest0$tnum ($dupopt): DB_BEFORE returns EINVAL."
146
 
                        puts "\tTest0$tnum ($dupopt): Correct error returns,\
147
 
                                skipping further test."
148
 
                        # continue with broad foreach
149
 
                        error_check_good dbc_close [$dbc close] 0
150
 
                        if { $txnenv == 1 } {
151
 
                                error_check_good txn [$t commit] 0
152
 
                        }
153
 
                        error_check_good db_close [$db close] 0
154
 
                        continue
155
 
                }
156
 
 
157
 
                puts "\tTest0$tnum.e ($dupopt): DBC->put(DB_AFTER) loop."
158
 
                foreach word $wordlist {
159
 
                        # set cursor to $word
160
 
                        set dbt [$dbc get -set $word]
161
 
                        error_check_good \
162
 
                            dbc_get_set $dbt [list [list $word $word]]
163
 
                        # put after it
164
 
                        set ret [$dbc put -after -partial {4 0} after]
165
 
                        error_check_good dbc_put_after $ret 0
166
 
                }
167
 
 
168
 
                puts "\tTest0$tnum.f ($dupopt): DBC->put(DB_BEFORE) loop."
169
 
                foreach word $wordlist {
170
 
                        # set cursor to $word
171
 
                        set dbt [$dbc get -set $word]
172
 
                        error_check_good \
173
 
                            dbc_get_set $dbt [list [list $word $word]]
174
 
                        # put before it
175
 
                        set ret [$dbc put -before -partial {6 0} before]
176
 
                        error_check_good dbc_put_before $ret 0
177
 
                }
178
 
 
179
 
                error_check_good dbc_close [$dbc close] 0
180
 
                if { $txnenv == 1 } {
181
 
                        error_check_good txn [$t commit] 0
182
 
                }
183
 
 
184
 
                eval $db sync
185
 
                puts "\tTest0$tnum.g ($dupopt): Verify correctness."
186
 
 
187
 
                if { $txnenv == 1 } {
188
 
                        set t [$env txn]
189
 
                        error_check_good txn [is_valid_txn $t $env] TRUE
190
 
                        set txn "-txn $t"
191
 
                }
192
 
                set dbc [eval {$db cursor} $txn]
193
 
                error_check_good db_cursor [is_valid_cursor $dbc $db] TRUE
194
 
 
195
 
                # loop through the whole db beginning to end,
196
 
                # make sure we have, in order, {$word "\0\0\0\0\0\0before"},
197
 
                # {$word $word}, {$word "\0\0\0\0after"} for each word.
198
 
                set count 0
199
 
                while { $count < $nkeys } {
200
 
                        # Get the first item of each set of three.
201
 
                        # We don't know what the word is, but set $word to
202
 
                        # the key and check that the data is
203
 
                        # "\0\0\0\0\0\0before".
204
 
                        set dbt [$dbc get -next]
205
 
                        set word [lindex [lindex $dbt 0] 0]
206
 
 
207
 
                        error_check_good dbc_get_one $dbt \
208
 
                            [list [list $word "\0\0\0\0\0\0before"]]
209
 
 
210
 
                        set dbt [$dbc get -next]
211
 
                        error_check_good \
212
 
                            dbc_get_two $dbt [list [list $word $word]]
213
 
 
214
 
                        set dbt [$dbc get -next]
215
 
                        error_check_good dbc_get_three $dbt \
216
 
                            [list [list $word "\0\0\0\0after"]]
217
 
 
218
 
                        incr count
219
 
                }
220
 
                error_check_good dbc_close [$dbc close] 0
221
 
                if { $txnenv == 1 } {
222
 
                        error_check_good txn [$t commit] 0
223
 
                }
224
 
                error_check_good db_close [$db close] 0
225
 
        }
226
 
}