1# See the file LICENSE for redistribution information.
2#
3# Copyright (c) 2001,2008 Oracle.  All rights reserved.
4#
5# $Id: rsrc004.tcl,v 12.6 2008/01/08 20:58:53 bostic Exp $
6#
7# TEST	rsrc004
8# TEST	Recno backing file test for EOF-terminated records.
9proc rsrc004 { } {
10	source ./include.tcl
11
12	foreach isfixed { 0 1 } {
13		cleanup $testdir NULL
14
15		# Create the backing text file.
16		set oid1 [open $testdir/rsrc.txt w]
17		if { $isfixed == 1 } {
18			puts -nonewline $oid1 "record 1xxx"
19			puts -nonewline $oid1 "record 2xxx"
20		} else {
21			puts $oid1 "record 1xxx"
22			puts $oid1 "record 2xxx"
23		}
24		puts -nonewline $oid1 "record 3"
25		close $oid1
26
27		set args "-create -mode 0644 -recno -source $testdir/rsrc.txt"
28		if { $isfixed == 1 } {
29			append args " -len [string length "record 1xxx"]"
30			set match "record 3   "
31			puts "Rsrc004: EOF-terminated recs: fixed length"
32		} else {
33			puts "Rsrc004: EOF-terminated recs: variable length"
34			set match "record 3"
35		}
36
37		puts "\tRsrc004.a: Read file, verify correctness."
38		set db [eval berkdb_open $args "$testdir/rsrc004.db"]
39		error_check_good dbopen [is_valid_db $db] TRUE
40
41		# Read the last record
42		set dbc [eval {$db cursor} ""]
43		error_check_good db_cursor [is_valid_cursor $dbc $db] TRUE
44
45		set rec [$dbc get -last]
46		error_check_good get_last $rec [list [list 3 $match]]
47
48		error_check_good dbc_close [$dbc close] 0
49		error_check_good db_close [$db close] 0
50	}
51}
52