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

« back to all changes in this revision

Viewing changes to libdb/test/test063.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  test063
9
 
# TEST  Test of the DB_RDONLY flag to DB->open
10
 
# TEST  Attempt to both DB->put and DBC->c_put into a database
11
 
# TEST  that has been opened DB_RDONLY, and check for failure.
12
 
proc test063 { method args } {
13
 
        global errorCode
14
 
        source ./include.tcl
15
 
 
16
 
        set args [convert_args $method $args]
17
 
        set omethod [convert_method $method]
18
 
        set tnum 63
19
 
 
20
 
        set txnenv 0
21
 
        set eindex [lsearch -exact $args "-env"]
22
 
        #
23
 
        # If we are using an env, then testfile should just be the db name.
24
 
        # Otherwise it is the test directory and the name.
25
 
        if { $eindex == -1 } {
26
 
                set testfile $testdir/test0$tnum.db
27
 
                set env NULL
28
 
        } else {
29
 
                set testfile test0$tnum.db
30
 
                incr eindex
31
 
                set env [lindex $args $eindex]
32
 
                set txnenv [is_txnenv $env]
33
 
                if { $txnenv == 1 } {
34
 
                        append args " -auto_commit "
35
 
                }
36
 
                set testdir [get_home $env]
37
 
        }
38
 
        cleanup $testdir $env
39
 
 
40
 
        set key "key"
41
 
        set data "data"
42
 
        set key2 "another_key"
43
 
        set data2 "more_data"
44
 
 
45
 
        set gflags ""
46
 
        set txn ""
47
 
 
48
 
        if { [is_record_based $method] == 1 } {
49
 
            set key "1"
50
 
            set key2 "2"
51
 
            append gflags " -recno"
52
 
        }
53
 
 
54
 
        puts "Test0$tnum: $method ($args) DB_RDONLY test."
55
 
 
56
 
        # Create a test database.
57
 
        puts "\tTest0$tnum.a: Creating test database."
58
 
        set db [eval {berkdb_open_noerr -create -mode 0644} \
59
 
            $omethod $args $testfile]
60
 
        error_check_good db_create [is_valid_db $db] TRUE
61
 
 
62
 
        # Put and get an item so it's nonempty.
63
 
        if { $txnenv == 1 } {
64
 
                set t [$env txn]
65
 
                error_check_good txn [is_valid_txn $t $env] TRUE
66
 
                set txn "-txn $t"
67
 
        }
68
 
        set ret [eval {$db put} $txn {$key [chop_data $method $data]}]
69
 
        error_check_good initial_put $ret 0
70
 
 
71
 
        set dbt [eval {$db get} $txn $gflags {$key}]
72
 
        error_check_good initial_get $dbt \
73
 
            [list [list $key [pad_data $method $data]]]
74
 
 
75
 
        if { $txnenv == 1 } {
76
 
                error_check_good txn [$t commit] 0
77
 
        }
78
 
        error_check_good db_close [$db close] 0
79
 
 
80
 
        if { $eindex == -1 } {
81
 
                # Confirm that database is writable.  If we are
82
 
                # using an env (that may be remote on a server)
83
 
                # we cannot do this check.
84
 
                error_check_good writable [file writable $testfile] 1
85
 
        }
86
 
 
87
 
        puts "\tTest0$tnum.b: Re-opening DB_RDONLY and attempting to put."
88
 
 
89
 
        # Now open it read-only and make sure we can get but not put.
90
 
        set db [eval {berkdb_open_noerr -rdonly} $args {$testfile}]
91
 
        error_check_good db_open [is_valid_db $db] TRUE
92
 
 
93
 
        if { $txnenv == 1 } {
94
 
                set t [$env txn]
95
 
                error_check_good txn [is_valid_txn $t $env] TRUE
96
 
                set txn "-txn $t"
97
 
        }
98
 
        set dbt [eval {$db get} $txn $gflags {$key}]
99
 
        error_check_good db_get $dbt \
100
 
            [list [list $key [pad_data $method $data]]]
101
 
 
102
 
        set ret [catch {eval {$db put} $txn \
103
 
            {$key2 [chop_data $method $data]}} res]
104
 
        error_check_good put_failed $ret 1
105
 
        error_check_good db_put_rdonly [is_substr $errorCode "EACCES"] 1
106
 
        if { $txnenv == 1 } {
107
 
                error_check_good txn [$t commit] 0
108
 
        }
109
 
 
110
 
        set errorCode "NONE"
111
 
 
112
 
        puts "\tTest0$tnum.c: Attempting cursor put."
113
 
 
114
 
        if { $txnenv == 1 } {
115
 
                set t [$env txn]
116
 
                error_check_good txn [is_valid_txn $t $env] TRUE
117
 
                set txn "-txn $t"
118
 
        }
119
 
        set dbc [eval {$db cursor} $txn]
120
 
        error_check_good cursor_create [is_valid_cursor $dbc $db] TRUE
121
 
 
122
 
        error_check_good cursor_set [$dbc get -first] $dbt
123
 
        set ret [catch {eval {$dbc put} -current $data} res]
124
 
        error_check_good c_put_failed $ret 1
125
 
        error_check_good dbc_put_rdonly [is_substr $errorCode "EACCES"] 1
126
 
 
127
 
        set dbt [eval {$db get} $gflags {$key2}]
128
 
        error_check_good db_get_key2 $dbt ""
129
 
 
130
 
        puts "\tTest0$tnum.d: Attempting ordinary delete."
131
 
 
132
 
        set errorCode "NONE"
133
 
        set ret [catch {eval {$db del} $txn {$key}} 1]
134
 
        error_check_good del_failed $ret 1
135
 
        error_check_good db_del_rdonly [is_substr $errorCode "EACCES"] 1
136
 
 
137
 
        set dbt [eval {$db get} $txn $gflags {$key}]
138
 
        error_check_good db_get_key $dbt \
139
 
            [list [list $key [pad_data $method $data]]]
140
 
 
141
 
        puts "\tTest0$tnum.e: Attempting cursor delete."
142
 
        # Just set the cursor to the beginning;  we don't care what's there...
143
 
        # yet.
144
 
        set dbt2 [$dbc get -first]
145
 
        error_check_good db_get_first_key $dbt2 $dbt
146
 
        set errorCode "NONE"
147
 
        set ret [catch {$dbc del} res]
148
 
        error_check_good c_del_failed $ret 1
149
 
        error_check_good dbc_del_rdonly [is_substr $errorCode "EACCES"] 1
150
 
 
151
 
        set dbt2 [$dbc get -current]
152
 
        error_check_good db_get_key $dbt2 $dbt
153
 
 
154
 
        puts "\tTest0$tnum.f: Close, reopen db;  verify unchanged."
155
 
 
156
 
        error_check_good dbc_close [$dbc close] 0
157
 
        if { $txnenv == 1 } {
158
 
                error_check_good txn [$t commit] 0
159
 
        }
160
 
        error_check_good db_close [$db close] 0
161
 
 
162
 
        set db [eval {berkdb_open} $omethod $args $testfile]
163
 
        error_check_good db_reopen [is_valid_db $db] TRUE
164
 
 
165
 
        set dbc [$db cursor]
166
 
        error_check_good cursor_create [is_valid_cursor $dbc $db] TRUE
167
 
 
168
 
        error_check_good first_there [$dbc get -first] \
169
 
            [list [list $key [pad_data $method $data]]]
170
 
        error_check_good nomore_there [$dbc get -next] ""
171
 
 
172
 
        error_check_good dbc_close [$dbc close] 0
173
 
        error_check_good db_close [$db close] 0
174
 
}