~ubuntu-branches/ubuntu/edgy/rpm/edgy

« back to all changes in this revision

Viewing changes to db/test/test025.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Joey Hess
  • Date: 2002-01-22 20:56:57 UTC
  • Revision ID: james.westby@ubuntu.com-20020122205657-l74j50mr9z8ofcl5
Tags: upstream-4.0.3
ImportĀ upstreamĀ versionĀ 4.0.3

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-2001
 
4
#       Sleepycat Software.  All rights reserved.
 
5
#
 
6
# $Id: test025.tcl,v 11.13 2001/05/17 20:37:08 bostic Exp $
 
7
#
 
8
# DB Test 25 {method nentries}
 
9
# Test the DB_APPEND flag.
 
10
proc test025 { method {nentries 10000} {start 0 } {tnum "25" } args} {
 
11
        global kvals
 
12
        source ./include.tcl
 
13
 
 
14
        set args [convert_args $method $args]
 
15
        set omethod [convert_method $method]
 
16
        puts "Test0$tnum: $method ($args)"
 
17
 
 
18
        if { [string compare $omethod "-btree"] == 0 } {
 
19
                puts "Test0$tnum skipping for method BTREE"
 
20
                return
 
21
        }
 
22
        if { [string compare $omethod "-hash"] == 0 } {
 
23
                puts "Test0$tnum skipping for method HASH"
 
24
                return
 
25
        }
 
26
 
 
27
        # Create the database and open the dictionary
 
28
        set eindex [lsearch -exact $args "-env"]
 
29
        #
 
30
        # If we are using an env, then testfile should just be the db name.
 
31
        # Otherwise it is the test directory and the name.
 
32
        if { $eindex == -1 } {
 
33
                set testfile $testdir/test0$tnum.db
 
34
                set env NULL
 
35
        } else {
 
36
                set testfile test0$tnum.db
 
37
                incr eindex
 
38
                set env [lindex $args $eindex]
 
39
        }
 
40
        set t1 $testdir/t1
 
41
 
 
42
        cleanup $testdir $env
 
43
        set db [eval {berkdb_open \
 
44
             -create -truncate -mode 0644} $args {$omethod $testfile}]
 
45
        error_check_good dbopen [is_valid_db $db] TRUE
 
46
        set did [open $dict]
 
47
 
 
48
        puts "\tTest0$tnum.a: put/get loop"
 
49
        set gflags " -recno"
 
50
        set pflags " -append"
 
51
        set txn ""
 
52
        set checkfunc test025_check
 
53
 
 
54
        # Here is the loop where we put and get each key/data pair
 
55
        set count $start
 
56
        set nentries [expr $start + $nentries]
 
57
        if { $count != 0 } {
 
58
                gets $did str
 
59
                set k [expr $count + 1]
 
60
                set kvals($k) [pad_data $method $str]
 
61
                set ret [eval {$db put} $txn $k {[chop_data $method $str]}]
 
62
                error_check_good db_put $ret 0
 
63
                incr count
 
64
        }
 
65
 
 
66
        while { [gets $did str] != -1 && $count < $nentries } {
 
67
                set k [expr $count + 1]
 
68
                set kvals($k) [pad_data $method $str]
 
69
                set ret [eval {$db put} $txn $pflags {[chop_data $method $str]}]
 
70
                error_check_good db_put $ret $k
 
71
 
 
72
                set ret [eval {$db get} $txn $gflags {$k}]
 
73
                error_check_good \
 
74
                    get $ret [list [list $k [pad_data $method $str]]]
 
75
                incr count
 
76
                if { [expr $count + 1] == 0 } {
 
77
                        incr count
 
78
                }
 
79
        }
 
80
        close $did
 
81
 
 
82
        # Now we will get each key from the DB and compare the results
 
83
        # to the original.
 
84
        puts "\tTest0$tnum.b: dump file"
 
85
        dump_file $db $txn $t1 $checkfunc
 
86
        error_check_good db_close [$db close] 0
 
87
 
 
88
        puts "\tTest0$tnum.c: close, open, and dump file"
 
89
        # Now, reopen the file and run the last test again.
 
90
        open_and_dump_file $testfile $env $txn $t1 $checkfunc \
 
91
            dump_file_direction -first -next
 
92
 
 
93
        # Now, reopen the file and run the last test again in the
 
94
        # reverse direction.
 
95
        puts "\tTest0$tnum.d: close, open, and dump file in reverse direction"
 
96
        open_and_dump_file $testfile $env $txn $t1 $checkfunc \
 
97
                dump_file_direction -last -prev
 
98
}
 
99
 
 
100
proc test025_check { key data } {
 
101
        global kvals
 
102
 
 
103
        error_check_good key"$key"_exists [info exists kvals($key)] 1
 
104
        error_check_good " key/data mismatch for |$key|" $data $kvals($key)
 
105
}