1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 2000-2002
4
# Sleepycat Software. All rights reserved.
9
# TEST Test of DBC->c_count(). [#303]
10
proc test078 { method { nkeys 100 } { pagesize 512 } { tnum 78 } args } {
12
global alphabet rand_init
14
set args [convert_args $method $args]
15
set omethod [convert_method $method]
17
puts "Test0$tnum: Test of key counts."
19
berkdb srand $rand_init
22
set eindex [lsearch -exact $args "-env"]
23
if { $eindex != -1 } {
27
if { $eindex == -1 } {
28
set testfile $testdir/test0$tnum-a.db
31
set testfile test0$tnum-a.db
32
set env [lindex $args $eindex]
33
set txnenv [is_txnenv $env]
35
append args " -auto_commit "
37
set testdir [get_home $env]
41
puts "\tTest0$tnum.a: No duplicates, trivial answer."
42
set pgindex [lsearch -exact $args "-pagesize"]
43
if { $pgindex != -1 } {
44
puts "Test078: skipping for specific pagesizes"
48
set db [eval {berkdb_open -create -mode 0644\
49
-pagesize $pagesize} $omethod $args {$testfile}]
50
error_check_good db_open [is_valid_db $db] TRUE
53
for { set i 1 } { $i <= $nkeys } { incr i } {
56
error_check_good txn [is_valid_txn $t $env] TRUE
59
set ret [eval {$db put} $txn {$i\
60
[pad_data $method $alphabet$i]}]
61
error_check_good put.a($i) $ret 0
63
error_check_good txn [$t commit] 0
65
error_check_good count.a [$db count $i] 1
67
error_check_good db_close.a [$db close] 0
69
if { [is_record_based $method] == 1 || [is_rbtree $method] == 1 } {
71
"\tTest0$tnum.b: Duplicates not supported in $method, skipping."
75
foreach tuple {{b sorted "-dup -dupsort"} {c unsorted "-dup"}} {
76
set letter [lindex $tuple 0]
77
set dupopt [lindex $tuple 2]
79
if { $eindex == -1 } {
80
set testfile $testdir/test0$tnum-b.db
83
set testfile test0$tnum-b.db
84
set env [lindex $args $eindex]
85
set testdir [get_home $env]
89
puts "\tTest0$tnum.$letter: Duplicates ([lindex $tuple 1])."
91
puts "\t\tTest0$tnum.$letter.1: Populating database."
93
set db [eval {berkdb_open -create -mode 0644\
94
-pagesize $pagesize} $dupopt $omethod $args {$testfile}]
95
error_check_good db_open [is_valid_db $db] TRUE
97
for { set i 1 } { $i <= $nkeys } { incr i } {
98
for { set j 0 } { $j < $i } { incr j } {
101
error_check_good txn \
102
[is_valid_txn $t $env] TRUE
105
set ret [eval {$db put} $txn {$i\
106
[pad_data $method $j$alphabet]}]
107
error_check_good put.$letter,$i $ret 0
108
if { $txnenv == 1 } {
109
error_check_good txn [$t commit] 0
114
puts -nonewline "\t\tTest0$tnum.$letter.2: "
115
puts "Verifying dup counts on first dup."
116
for { set i 1 } { $i < $nkeys } { incr i } {
117
error_check_good count.$letter,$i \
121
puts -nonewline "\t\tTest0$tnum.$letter.3: "
122
puts "Verifying dup counts on random dup."
123
for { set i 1 } { $i < $nkeys } { incr i } {
124
set key [berkdb random_int 1 $nkeys]
125
error_check_good count.$letter,$i \
128
error_check_good db_close.$letter [$db close] 0