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

« back to all changes in this revision

Viewing changes to db/test/rsrc002.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) 1999-2001
 
4
#       Sleepycat Software.  All rights reserved.
 
5
#
 
6
# $Id: rsrc002.tcl,v 11.12 2001/01/25 18:23:06 bostic Exp $
 
7
#
 
8
# Recno backing file test #2: test of set_re_delim.
 
9
#       Specify a backing file with colon-delimited records,
 
10
#       and make sure they are correctly interpreted.
 
11
proc rsrc002 { } {
 
12
        source ./include.tcl
 
13
 
 
14
        puts "Rsrc002: Alternate variable-length record delimiters."
 
15
 
 
16
        # We run this test essentially twice, once with a db file
 
17
        # and once without (an in-memory database).
 
18
        foreach testfile { "$testdir/rsrc002.db" "" } {
 
19
 
 
20
                cleanup $testdir NULL
 
21
 
 
22
                # Create the starting files
 
23
                set oid1 [open $testdir/rsrc.txt w]
 
24
                set oid2 [open $testdir/check.txt w]
 
25
                puts -nonewline $oid1 "ostrich:emu:kiwi:moa:cassowary:rhea:"
 
26
                puts -nonewline $oid2 "ostrich:emu:kiwi:penguin:cassowary:rhea:"
 
27
                close $oid1
 
28
                close $oid2
 
29
 
 
30
                if { $testfile == "" } {
 
31
                        puts "Rsrc002: Testing with in-memory database."
 
32
                } else {
 
33
                        puts "Rsrc002: Testing with disk-backed database."
 
34
                }
 
35
 
 
36
                puts "\tRsrc002.a: Read file, verify correctness."
 
37
                set db [eval {berkdb_open -create -mode 0644 -delim 58 \
 
38
                    -recno -source $testdir/rsrc.txt} $testfile]
 
39
                error_check_good dbopen [is_valid_db $db] TRUE
 
40
 
 
41
                # Read the last record; replace it (but we won't change it).
 
42
                # Then close the file and diff the two files.
 
43
                set txn ""
 
44
                set dbc [eval {$db cursor} $txn]
 
45
                error_check_good db_cursor [is_valid_cursor $dbc $db] TRUE
 
46
 
 
47
                set rec [$dbc get -first]
 
48
                error_check_good get_first $rec [list [list 1 "ostrich"]]
 
49
                set rec [$dbc get -next]
 
50
                error_check_good get_next $rec [list [list 2 "emu"]]
 
51
 
 
52
                puts "\tRsrc002.b: Write record, verify correctness."
 
53
 
 
54
                eval {$dbc get -set 4}
 
55
                set ret [$dbc put -current "penguin"]
 
56
                error_check_good dbc_put $ret 0
 
57
 
 
58
                error_check_good dbc_close [$dbc close] 0
 
59
                error_check_good db_close [$db close] 0
 
60
 
 
61
                error_check_good \
 
62
                    Rsrc002:diff($testdir/rsrc.txt,$testdir/check.txt) \
 
63
                    [filecmp $testdir/rsrc.txt $testdir/check.txt] 0
 
64
        }
 
65
}