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

« back to all changes in this revision

Viewing changes to db/test/test012.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: test012.tcl,v 11.16 2001/05/14 21:55:55 krinsky Exp $
 
7
#
 
8
# DB Test 12 {access method}
 
9
# Take the source files and dbtest executable and enter their contents as
 
10
# the key with their names as data.  After all are entered, retrieve all;
 
11
# compare output to original. Close file, reopen, do retrieve and re-verify.
 
12
proc test012 { method args} {
 
13
        global names
 
14
        source ./include.tcl
 
15
 
 
16
        set args [convert_args $method $args]
 
17
        set omethod [convert_method $method]
 
18
 
 
19
        if { [is_record_based $method] == 1 } {
 
20
                puts "Test012 skipping for method $method"
 
21
                return
 
22
        }
 
23
 
 
24
        puts "Test012: $method ($args) filename=data filecontents=key pairs"
 
25
 
 
26
        # Create the database and open the dictionary
 
27
        set eindex [lsearch -exact $args "-env"]
 
28
        #
 
29
        # If we are using an env, then testfile should just be the db name.
 
30
        # Otherwise it is the test directory and the name.
 
31
        if { $eindex == -1 } {
 
32
                set testfile $testdir/test012.db
 
33
                set env NULL
 
34
        } else {
 
35
                set testfile test012.db
 
36
                incr eindex
 
37
                set env [lindex $args $eindex]
 
38
        }
 
39
        set t1 $testdir/t1
 
40
        set t2 $testdir/t2
 
41
        set t3 $testdir/t3
 
42
        set t4 $testdir/t4
 
43
 
 
44
        cleanup $testdir $env
 
45
 
 
46
        set db [eval {berkdb_open \
 
47
             -create -truncate -mode 0644} $args {$omethod $testfile}]
 
48
        error_check_good dbopen [is_valid_db $db] TRUE
 
49
 
 
50
        set pflags ""
 
51
        set gflags ""
 
52
        set txn ""
 
53
 
 
54
        # Here is the loop where we put and get each key/data pair
 
55
        set file_list [get_file_list]
 
56
 
 
57
        puts "\tTest012.a: put/get loop"
 
58
        set count 0
 
59
        foreach f $file_list {
 
60
                put_file_as_key $db $txn $pflags $f
 
61
 
 
62
                set kd [get_file_as_key $db $txn $gflags $f]
 
63
                incr count
 
64
        }
 
65
 
 
66
        # Now we will get each key from the DB and compare the results
 
67
        # to the original.
 
68
        puts "\tTest012.b: dump file"
 
69
        dump_binkey_file $db $txn $t1 test012.check
 
70
        error_check_good db_close [$db close] 0
 
71
 
 
72
        # Now compare the data to see if they match the .o and dbtest files
 
73
        set oid [open $t2.tmp w]
 
74
        foreach f $file_list {
 
75
                puts $oid $f
 
76
        }
 
77
        close $oid
 
78
        filesort $t2.tmp $t2
 
79
        fileremove $t2.tmp
 
80
        filesort $t1 $t3
 
81
 
 
82
        error_check_good Test012:diff($t3,$t2) \
 
83
            [filecmp $t3 $t2] 0
 
84
 
 
85
        # Now, reopen the file and run the last test again.
 
86
        puts "\tTest012.c: close, open, and dump file"
 
87
        open_and_dump_file $testfile $env $txn $t1 test012.check \
 
88
            dump_binkey_file_direction "-first" "-next"
 
89
 
 
90
        filesort $t1 $t3
 
91
 
 
92
        error_check_good Test012:diff($t3,$t2) \
 
93
            [filecmp $t3 $t2] 0
 
94
 
 
95
        # Now, reopen the file and run the last test again in reverse direction.
 
96
        puts "\tTest012.d: close, open, and dump file in reverse direction"
 
97
        open_and_dump_file $testfile $env $txn $t1 test012.check\
 
98
            dump_binkey_file_direction "-last" "-prev"
 
99
 
 
100
        filesort $t1 $t3
 
101
 
 
102
        error_check_good Test012:diff($t3,$t2) \
 
103
            [filecmp $t3 $t2] 0
 
104
}
 
105
 
 
106
# Check function for test012; key should be file name; data should be contents
 
107
proc test012.check { binfile tmpfile } {
 
108
        source ./include.tcl
 
109
 
 
110
        error_check_good Test012:diff($binfile,$tmpfile) \
 
111
            [filecmp $binfile $tmpfile] 0
 
112
}