1# See the file LICENSE for redistribution information. 2# 3# Copyright (c) 1999-2009 Oracle. All rights reserved. 4# 5# $Id$ 6# 7# TEST rsrc002 8# TEST Recno backing file test #2: test of set_re_delim. Specify a backing 9# TEST file with colon-delimited records, and make sure they are correctly 10# TEST interpreted. 11proc 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} 66