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

« back to all changes in this revision

Viewing changes to libdb/test/rsrc001.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  rsrc001
9
 
# TEST  Recno backing file test.  Try different patterns of adding
10
 
# TEST  records and making sure that the corresponding file matches.
11
 
proc rsrc001 { } {
12
 
        source ./include.tcl
13
 
 
14
 
        puts "Rsrc001: Basic recno backing file writeback tests"
15
 
 
16
 
        # We run this test essentially twice, once with a db file
17
 
        # and once without (an in-memory database).
18
 
        set rec1 "This is record 1"
19
 
        set rec2 "This is record 2 This is record 2"
20
 
        set rec3 "This is record 3 This is record 3 This is record 3"
21
 
        set rec4 [replicate "This is record 4 " 512]
22
 
 
23
 
        foreach testfile { "$testdir/rsrc001.db" "" } {
24
 
 
25
 
                cleanup $testdir NULL
26
 
 
27
 
                if { $testfile == "" } {
28
 
                        puts "Rsrc001: Testing with in-memory database."
29
 
                } else {
30
 
                        puts "Rsrc001: Testing with disk-backed database."
31
 
                }
32
 
 
33
 
                # Create backing file for the empty-file test.
34
 
                set oid1 [open $testdir/rsrc.txt w]
35
 
                close $oid1
36
 
 
37
 
                puts "\tRsrc001.a: Put to empty file."
38
 
                set db [eval {berkdb_open -create -mode 0644\
39
 
                    -recno -source $testdir/rsrc.txt} $testfile]
40
 
                error_check_good dbopen [is_valid_db $db] TRUE
41
 
                set txn ""
42
 
 
43
 
                set ret [eval {$db put} $txn {1 $rec1}]
44
 
                error_check_good put_to_empty $ret 0
45
 
                error_check_good db_close [$db close] 0
46
 
 
47
 
                # Now fill out the backing file and create the check file.
48
 
                set oid1 [open $testdir/rsrc.txt a]
49
 
                set oid2 [open $testdir/check.txt w]
50
 
 
51
 
                # This one was already put into rsrc.txt.
52
 
                puts $oid2 $rec1
53
 
 
54
 
                # These weren't.
55
 
                puts $oid1 $rec2
56
 
                puts $oid2 $rec2
57
 
                puts $oid1 $rec3
58
 
                puts $oid2 $rec3
59
 
                puts $oid1 $rec4
60
 
                puts $oid2 $rec4
61
 
                close $oid1
62
 
                close $oid2
63
 
 
64
 
                puts -nonewline "\tRsrc001.b: Read file, rewrite last record;"
65
 
                puts " write it out and diff"
66
 
                set db [eval {berkdb_open -create -mode 0644\
67
 
                    -recno -source $testdir/rsrc.txt} $testfile]
68
 
                error_check_good dbopen [is_valid_db $db] TRUE
69
 
 
70
 
                # Read the last record; replace it (but we won't change it).
71
 
                # Then close the file and diff the two files.
72
 
                set dbc [eval {$db cursor} $txn]
73
 
                error_check_good db_cursor [is_valid_cursor $dbc $db] TRUE
74
 
 
75
 
                set rec [$dbc get -last]
76
 
                error_check_good get_last [llength [lindex $rec 0]] 2
77
 
                set key [lindex [lindex $rec 0] 0]
78
 
                set data [lindex [lindex $rec 0] 1]
79
 
 
80
 
                # Get the last record from the text file
81
 
                set oid [open $testdir/rsrc.txt]
82
 
                set laststr ""
83
 
                while { [gets $oid str] != -1 } {
84
 
                        set laststr $str
85
 
                }
86
 
                close $oid
87
 
                set data [sanitize_record $data]
88
 
                error_check_good getlast $data $laststr
89
 
 
90
 
                set ret [eval {$db put} $txn {$key $data}]
91
 
                error_check_good replace_last $ret 0
92
 
 
93
 
                error_check_good curs_close [$dbc close] 0
94
 
                error_check_good db_sync [$db sync] 0
95
 
                error_check_good db_sync [$db sync] 0
96
 
                error_check_good \
97
 
                    Rsrc001:diff($testdir/rsrc.txt,$testdir/check.txt) \
98
 
                    [filecmp $testdir/rsrc.txt $testdir/check.txt] 0
99
 
 
100
 
                puts -nonewline "\tRsrc001.c: "
101
 
                puts "Append some records in tree and verify in file."
102
 
                set oid [open $testdir/check.txt a]
103
 
                for {set i 1} {$i < 10} {incr i} {
104
 
                        set rec [replicate "New Record $i" $i]
105
 
                        puts $oid $rec
106
 
                        incr key
107
 
                        set ret [eval {$db put} $txn {-append $rec}]
108
 
                        error_check_good put_append $ret $key
109
 
                }
110
 
                error_check_good db_sync [$db sync] 0
111
 
                error_check_good db_sync [$db sync] 0
112
 
                close $oid
113
 
                set ret [filecmp $testdir/rsrc.txt $testdir/check.txt]
114
 
                error_check_good \
115
 
                    Rsrc001:diff($testdir/{rsrc.txt,check.txt}) $ret 0
116
 
 
117
 
                puts "\tRsrc001.d: Append by record number"
118
 
                set oid [open $testdir/check.txt a]
119
 
                for {set i 1} {$i < 10} {incr i} {
120
 
                        set rec [replicate "New Record (set 2) $i" $i]
121
 
                        puts $oid $rec
122
 
                        incr key
123
 
                        set ret [eval {$db put} $txn {$key $rec}]
124
 
                        error_check_good put_byno $ret 0
125
 
                }
126
 
 
127
 
                error_check_good db_sync [$db sync] 0
128
 
                error_check_good db_sync [$db sync] 0
129
 
                close $oid
130
 
                set ret [filecmp $testdir/rsrc.txt $testdir/check.txt]
131
 
                error_check_good \
132
 
                    Rsrc001:diff($testdir/{rsrc.txt,check.txt}) $ret 0
133
 
 
134
 
                puts "\tRsrc001.e: Put beyond end of file."
135
 
                set oid [open $testdir/check.txt a]
136
 
                for {set i 1} {$i < 10} {incr i} {
137
 
                        puts $oid ""
138
 
                        incr key
139
 
                }
140
 
                set rec "Last Record"
141
 
                puts $oid $rec
142
 
                incr key
143
 
 
144
 
                set ret [eval {$db put} $txn {$key $rec}]
145
 
                error_check_good put_byno $ret 0
146
 
 
147
 
                puts "\tRsrc001.f: Put beyond end of file, after reopen."
148
 
 
149
 
                error_check_good db_close [$db close] 0
150
 
                set db [eval {berkdb_open -create -mode 0644\
151
 
                    -recno -source $testdir/rsrc.txt} $testfile]
152
 
                error_check_good dbopen [is_valid_db $db] TRUE
153
 
 
154
 
                set rec "Last record with reopen"
155
 
                puts $oid $rec
156
 
 
157
 
                incr key
158
 
                set ret [eval {$db put} $txn {$key $rec}]
159
 
                error_check_good put_byno_with_reopen $ret 0
160
 
 
161
 
                puts "\tRsrc001.g:\
162
 
                    Put several beyond end of file, after reopen with snapshot."
163
 
                error_check_good db_close [$db close] 0
164
 
                set db [eval {berkdb_open -create -mode 0644\
165
 
                    -snapshot -recno -source $testdir/rsrc.txt} $testfile]
166
 
                error_check_good dbopen [is_valid_db $db] TRUE
167
 
 
168
 
                set rec "Really really last record with reopen"
169
 
                puts $oid ""
170
 
                puts $oid ""
171
 
                puts $oid ""
172
 
                puts $oid $rec
173
 
 
174
 
                incr key
175
 
                incr key
176
 
                incr key
177
 
                incr key
178
 
 
179
 
                set ret [eval {$db put} $txn {$key $rec}]
180
 
                error_check_good put_byno_with_reopen $ret 0
181
 
 
182
 
                error_check_good db_sync [$db sync] 0
183
 
                error_check_good db_sync [$db sync] 0
184
 
 
185
 
                close $oid
186
 
                set ret [filecmp $testdir/rsrc.txt $testdir/check.txt]
187
 
                error_check_good \
188
 
                    Rsrc001:diff($testdir/{rsrc.txt,check.txt}) $ret 0
189
 
 
190
 
                puts "\tRsrc001.h: Verify proper syncing of changes on close."
191
 
                error_check_good Rsrc001:db_close [$db close] 0
192
 
                set db [eval {berkdb_open -create -mode 0644 -recno \
193
 
                    -source $testdir/rsrc.txt} $testfile]
194
 
                set oid [open $testdir/check.txt a]
195
 
                for {set i 1} {$i < 10} {incr i} {
196
 
                        set rec [replicate "New Record $i" $i]
197
 
                        puts $oid $rec
198
 
                        set ret [eval {$db put} $txn {-append $rec}]
199
 
                        # Don't bother checking return;  we don't know what
200
 
                        # the key number is, and we'll pick up a failure
201
 
                        # when we compare.
202
 
                }
203
 
                error_check_good Rsrc001:db_close [$db close] 0
204
 
                close $oid
205
 
                set ret [filecmp $testdir/rsrc.txt $testdir/check.txt]
206
 
                error_check_good Rsrc001:diff($testdir/{rsrc,check}.txt) $ret 0
207
 
        }
208
 
}
209
 
 
210
 
# Strip CRs from a record.
211
 
# Needed on Windows when a file is created as text (with CR/LF)
212
 
# but read as binary (where CR is read as a separate character)
213
 
proc sanitize_record { rec } {
214
 
        source ./include.tcl
215
 
 
216
 
        if { $is_windows_test != 1 } {
217
 
                return $rec
218
 
        }
219
 
        regsub -all \15 $rec "" data
220
 
        return $data
221
 
}