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

« back to all changes in this revision

Viewing changes to libdb/test/test002.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  test002
9
 
# TEST  Small keys/medium data
10
 
# TEST          Put/get per key
11
 
# TEST          Dump file
12
 
# TEST          Close, reopen
13
 
# TEST          Dump file
14
 
# TEST
15
 
# TEST  Use the first 10,000 entries from the dictionary.
16
 
# TEST  Insert each with self as key and a fixed, medium length data string;
17
 
# TEST  retrieve each. After all are entered, retrieve all; compare output
18
 
# TEST  to original. Close file, reopen, do retrieve and re-verify.
19
 
 
20
 
proc test002 { method {nentries 10000} args } {
21
 
        global datastr
22
 
        global pad_datastr
23
 
        source ./include.tcl
24
 
 
25
 
        set args [convert_args $method $args]
26
 
        set omethod [convert_method $method]
27
 
 
28
 
        set txnenv 0
29
 
        set eindex [lsearch -exact $args "-env"]
30
 
        #
31
 
        # If we are using an env, then testfile should just be the db name.
32
 
        # Otherwise it is the test directory and the name.
33
 
        if { $eindex == -1 } {
34
 
                set testfile $testdir/test002.db
35
 
                set env NULL
36
 
        } else {
37
 
                set testfile test002.db
38
 
                incr eindex
39
 
                set env [lindex $args $eindex]
40
 
                set txnenv [is_txnenv $env]
41
 
                if { $txnenv == 1 } {
42
 
                        append args " -auto_commit "
43
 
                        #
44
 
                        # If we are using txns and running with the
45
 
                        # default, set the default down a bit.
46
 
                        #
47
 
                        if { $nentries == 10000 } {
48
 
                                set nentries 100
49
 
                        }
50
 
                }
51
 
                set testdir [get_home $env]
52
 
        }
53
 
        # Create the database and open the dictionary
54
 
        puts "Test002: $method ($args) $nentries key <fixed data> pairs"
55
 
 
56
 
        set t1 $testdir/t1
57
 
        set t2 $testdir/t2
58
 
        set t3 $testdir/t3
59
 
        cleanup $testdir $env
60
 
        set db [eval {berkdb_open \
61
 
             -create -mode 0644} $args {$omethod $testfile}]
62
 
        error_check_good dbopen [is_valid_db $db] TRUE
63
 
        set did [open $dict]
64
 
 
65
 
        set pflags ""
66
 
        set gflags ""
67
 
        set txn ""
68
 
        set count 0
69
 
 
70
 
        # Here is the loop where we put and get each key/data pair
71
 
 
72
 
        if { [is_record_based $method] == 1 } {
73
 
                append gflags "-recno"
74
 
        }
75
 
        set pad_datastr [pad_data $method $datastr]
76
 
        puts "\tTest002.a: put/get loop"
77
 
        while { [gets $did str] != -1 && $count < $nentries } {
78
 
                if { [is_record_based $method] == 1 } {
79
 
                        set key [expr $count + 1]
80
 
                } else {
81
 
                        set key $str
82
 
                }
83
 
                if { $txnenv == 1 } {
84
 
                        set t [$env txn]
85
 
                        error_check_good txn [is_valid_txn $t $env] TRUE
86
 
                        set txn "-txn $t"
87
 
                }
88
 
                set ret [eval {$db put} $txn $pflags {$key [chop_data $method $datastr]}]
89
 
                error_check_good put $ret 0
90
 
                if { $txnenv == 1 } {
91
 
                        error_check_good txn [$t commit] 0
92
 
                }
93
 
 
94
 
                set ret [eval {$db get} $gflags {$key}]
95
 
 
96
 
                error_check_good get $ret [list [list $key [pad_data $method $datastr]]]
97
 
                incr count
98
 
        }
99
 
        close $did
100
 
 
101
 
        # Now we will get each key from the DB and compare the results
102
 
        # to the original.
103
 
        puts "\tTest002.b: dump file"
104
 
        if { $txnenv == 1 } {
105
 
                set t [$env txn]
106
 
                error_check_good txn [is_valid_txn $t $env] TRUE
107
 
                set txn "-txn $t"
108
 
        }
109
 
        dump_file $db $txn $t1 test002.check
110
 
        if { $txnenv == 1 } {
111
 
                error_check_good txn [$t commit] 0
112
 
        }
113
 
        error_check_good db_close [$db close] 0
114
 
 
115
 
        # Now compare the keys to see if they match the dictionary
116
 
        if { [is_record_based $method] == 1 } {
117
 
                set oid [open $t2 w]
118
 
                for {set i 1} {$i <= $nentries} {set i [incr i]} {
119
 
                        puts $oid $i
120
 
                }
121
 
                close $oid
122
 
                filesort $t2 $t3
123
 
                file rename -force $t3 $t2
124
 
        } else {
125
 
                set q q
126
 
                filehead $nentries $dict $t3
127
 
                filesort $t3 $t2
128
 
        }
129
 
        filesort $t1 $t3
130
 
 
131
 
        error_check_good Test002:diff($t3,$t2) \
132
 
            [filecmp $t3 $t2] 0
133
 
 
134
 
        # Now, reopen the file and run the last test again.
135
 
        puts "\tTest002.c: close, open, and dump file"
136
 
        open_and_dump_file $testfile $env $t1 test002.check \
137
 
            dump_file_direction "-first" "-next"
138
 
 
139
 
        if { [string compare $omethod "-recno"] != 0 } {
140
 
                filesort $t1 $t3
141
 
        }
142
 
        error_check_good Test002:diff($t3,$t2) \
143
 
            [filecmp $t3 $t2] 0
144
 
 
145
 
        # Now, reopen the file and run the last test again in reverse direction.
146
 
        puts "\tTest002.d: close, open, and dump file in reverse direction"
147
 
        open_and_dump_file $testfile $env $t1 test002.check \
148
 
            dump_file_direction "-last" "-prev"
149
 
 
150
 
        if { [string compare $omethod "-recno"] != 0 } {
151
 
                filesort $t1 $t3
152
 
        }
153
 
        error_check_good Test002:diff($t3,$t2) \
154
 
            [filecmp $t3 $t2] 0
155
 
}
156
 
 
157
 
# Check function for test002; data should be fixed are identical
158
 
proc test002.check { key data } {
159
 
        global pad_datastr
160
 
        error_check_good "data mismatch for key $key" $data $pad_datastr
161
 
}