1# See the file LICENSE for redistribution information.
2#
3# Copyright (c) 2000-2009 Oracle.  All rights reserved.
4#
5# $Id$
6#
7# TEST	test077
8# TEST	Test of DB_GET_RECNO [#1206].
9proc test077 { method { nkeys 1000 } { tnum "077" } args } {
10	source ./include.tcl
11	global alphabet
12
13	set omethod [convert_method $method]
14	set args [convert_args $method $args]
15
16	puts "Test$tnum: Test of DB_GET_RECNO."
17
18	if { [is_rbtree $method] != 1 } {
19		puts "\tTest$tnum: Skipping for method $method."
20		return
21	}
22
23	set data $alphabet
24
25	set txnenv 0
26	set eindex [lsearch -exact $args "-env"]
27	if { $eindex == -1 } {
28		set testfile $testdir/test$tnum.db
29		set env NULL
30	} else {
31		set testfile test$tnum.db
32		incr eindex
33		set env [lindex $args $eindex]
34		set txnenv [is_txnenv $env]
35		if { $txnenv == 1 } {
36			append args " -auto_commit "
37		}
38		set testdir [get_home $env]
39	}
40	cleanup $testdir $env
41
42	set db [eval {berkdb_open -create -mode 0644} \
43	    $omethod $args {$testfile}]
44	error_check_good db_open [is_valid_db $db] TRUE
45
46	puts "\tTest$tnum.a: Populating database."
47	set txn ""
48
49	for { set i 1 } { $i <= $nkeys } { incr i } {
50		set key [format %5d $i]
51		if { $txnenv == 1 } {
52			set t [$env txn]
53			error_check_good txn [is_valid_txn $t $env] TRUE
54			set txn "-txn $t"
55		}
56		set ret [eval {$db put} $txn {$key $data}]
57		error_check_good db_put($key) $ret 0
58		if { $txnenv == 1 } {
59			error_check_good txn [$t commit] 0
60		}
61	}
62
63	puts "\tTest$tnum.b: Verifying record numbers."
64
65	if { $txnenv == 1 } {
66		set t [$env txn]
67		error_check_good txn [is_valid_txn $t $env] TRUE
68		set txn "-txn $t"
69	}
70	set dbc [eval {$db cursor} $txn]
71	error_check_good dbc_open [is_valid_cursor $dbc $db] TRUE
72
73	set i 1
74	for { set dbt [$dbc get -first] } \
75	    { [string length $dbt] != 0 } \
76	    { set dbt [$dbc get -next] } {
77		set recno [$dbc get -get_recno]
78		set keynum [expr [lindex [lindex $dbt 0] 0]]
79
80		# Verify that i, the number that is the key, and recno
81		# are all equal.
82		error_check_good key($i) $keynum $i
83		error_check_good recno($i) $recno $i
84		incr i
85	}
86
87	error_check_good dbc_close [$dbc close] 0
88	if { $txnenv == 1 } {
89		error_check_good txn [$t commit] 0
90	}
91	error_check_good db_close [$db close] 0
92}
93