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

« back to all changes in this revision

Viewing changes to libdb/test/test099.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) 1996-2002
4
 
#       Sleepycat Software.  All rights reserved.
5
 
#
6
 
# $Id$
7
 
#
8
 
# TEST  test099
9
 
# TEST
10
 
# TEST  Test of DB->get and DBC->c_get with set_recno and get_recno.
11
 
# TEST
12
 
# TEST  Populate a small btree -recnum database.
13
 
# TEST  After all are entered, retrieve each using -recno with DB->get.
14
 
# TEST  Open a cursor and do the same for DBC->c_get with set_recno.
15
 
# TEST  Verify that set_recno sets the record number position properly.
16
 
# TEST  Verify that get_recno returns the correct record numbers.
17
 
proc test099 { method {nentries 10000} args } {
18
 
        source ./include.tcl
19
 
 
20
 
        set args [convert_args $method $args]
21
 
        set omethod [convert_method $method]
22
 
 
23
 
        puts "Test099: Test of set_recno and get_recno in DBC->c_get."
24
 
        if { [is_rbtree $method] != 1 } {
25
 
                puts "Test099: skipping for method $method."
26
 
                return
27
 
        }
28
 
 
29
 
        set txnenv 0
30
 
        set eindex [lsearch -exact $args "-env"]
31
 
        #
32
 
        # If we are using an env, then testfile should just be the db name.
33
 
        # Otherwise it is the test directory and the name.
34
 
        if { $eindex == -1 } {
35
 
                set testfile $testdir/test099.db
36
 
                set env NULL
37
 
        } else {
38
 
                set testfile test099.db
39
 
                incr eindex
40
 
                set env [lindex $args $eindex]
41
 
                set txnenv [is_txnenv $env]
42
 
                if { $txnenv == 1 } {
43
 
                        append args " -auto_commit "
44
 
                        #
45
 
                        # If we are using txns and running with the
46
 
                        # default, set the default down a bit.
47
 
                        #
48
 
                        if { $nentries == 10000 } {
49
 
                                set nentries 100
50
 
                        }
51
 
                }
52
 
                set testdir [get_home $env]
53
 
        }
54
 
        set t1 $testdir/t1
55
 
        cleanup $testdir $env
56
 
 
57
 
        # Create the database and open the dictionary
58
 
        set db [eval {berkdb_open \
59
 
             -create -mode 0644} $args {$omethod $testfile}]
60
 
        error_check_good dbopen [is_valid_db $db] TRUE
61
 
 
62
 
        set did [open $dict]
63
 
 
64
 
        set pflags ""
65
 
        set gflags ""
66
 
        set txn ""
67
 
        set count 1
68
 
 
69
 
        append gflags " -recno"
70
 
 
71
 
        puts "\tTest099.a: put loop"
72
 
        # Here is the loop where we put each key/data pair
73
 
        while { [gets $did str] != -1 && $count < $nentries } {
74
 
#               global kvals
75
 
#               set key [expr $count]
76
 
#               set kvals($key) [pad_data $method $str]
77
 
                set key $str
78
 
                if { $txnenv == 1 } {
79
 
                        set t [$env txn]
80
 
                        error_check_good txn [is_valid_txn $t $env] TRUE
81
 
                        set txn "-txn $t"
82
 
                }
83
 
                set r [eval {$db put} \
84
 
                    $txn $pflags {$key [chop_data $method $str]}]
85
 
                error_check_good db_put $r 0
86
 
                if { $txnenv == 1 } {
87
 
                        error_check_good txn [$t commit] 0
88
 
                }
89
 
                incr count
90
 
        }
91
 
        close $did
92
 
 
93
 
        puts "\tTest099.b: dump file"
94
 
        if { $txnenv == 1 } {
95
 
                set t [$env txn]
96
 
                error_check_good txn [is_valid_txn $t $env] TRUE
97
 
                set txn "-txn $t"
98
 
        }
99
 
        dump_file $db $txn $t1 test099.check
100
 
        if { $txnenv == 1 } {
101
 
                error_check_good txn [$t commit] 0
102
 
        }
103
 
        error_check_good db_close [$db close] 0
104
 
 
105
 
        puts "\tTest099.c: Test set_recno then get_recno"
106
 
        set db [eval {berkdb_open -rdonly} $args $omethod $testfile ]
107
 
        error_check_good dbopen [is_valid_db $db] TRUE
108
 
 
109
 
        # Open a cursor
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 db_cursor [is_substr $dbc $db] 1
117
 
 
118
 
        set did [open $t1]
119
 
        set recno 1
120
 
 
121
 
        # Create key(recno) array to use for later comparison
122
 
        while { [gets $did str] != -1 } {
123
 
                set kvals($recno) $str
124
 
                incr recno
125
 
        }
126
 
 
127
 
        set recno 1
128
 
        set ret [$dbc get -first]
129
 
        error_check_bad dbc_get_first [llength $ret] 0
130
 
 
131
 
        # First walk forward through the database ....
132
 
        while { $recno < $count } {
133
 
                # Test set_recno: verify it sets the record number properly.
134
 
                set current [$dbc get -current]
135
 
                set r [$dbc get -set_recno $recno]
136
 
                error_check_good set_recno $current $r
137
 
                # Test set_recno: verify that we find the expected key
138
 
                # at the current record number position.
139
 
                set k [lindex [lindex $r 0] 0]
140
 
                error_check_good set_recno $kvals($recno) $k
141
 
 
142
 
                # Test get_recno: verify that the return from
143
 
                # get_recno matches the record number just set.
144
 
                set g [$dbc get -get_recno]
145
 
                error_check_good get_recno $recno $g
146
 
                set ret [$dbc get -next]
147
 
                incr recno
148
 
        }
149
 
 
150
 
        # ... and then backward.
151
 
        set recno [expr $count - 1]
152
 
        while { $recno > 0 } {
153
 
                # Test set_recno: verify that we find the expected key
154
 
                # at the current record number position.
155
 
                set r [$dbc get -set_recno $recno]
156
 
                set k [lindex [lindex $r 0] 0]
157
 
                error_check_good set_recno $kvals($recno) $k
158
 
 
159
 
                # Test get_recno: verify that the return from
160
 
                # get_recno matches the record number just set.
161
 
                set g [$dbc get -get_recno]
162
 
                error_check_good get_recno $recno $g
163
 
                set recno [expr $recno - 1]
164
 
        }
165
 
 
166
 
        error_check_good cursor_close [$dbc close] 0
167
 
        if { $txnenv == 1 } {
168
 
                error_check_good txn [$t commit] 0
169
 
        }
170
 
        error_check_good db_close [$db close] 0
171
 
        close $did
172
 
}
173
 
 
174
 
# Check function for dumped file; data should be fixed are identical
175
 
proc test099.check { key data } {
176
 
        error_check_good "data mismatch for key $key" $key $data
177
 
}