1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 2000-2001
4
# Sleepycat Software. All rights reserved.
6
# $Id: test078.tcl,v 1.10 2001/01/25 18:23:13 bostic Exp $
8
# DB Test 78: Test of DBC->c_count(). [#303]
9
proc test078 { method { nkeys 100 } { pagesize 512 } { tnum 78 } args } {
11
global alphabet rand_init
13
set args [convert_args $method $args]
14
set omethod [convert_method $method]
16
puts "Test0$tnum: Test of key counts."
18
berkdb srand $rand_init
20
set eindex [lsearch -exact $args "-env"]
21
if { $eindex == -1 } {
22
set testfile $testdir/test0$tnum.db
25
set testfile test0$tnum.db
27
set env [lindex $args $eindex]
31
puts "\tTest0$tnum.a: No duplicates, trivial answer."
32
set pgindex [lsearch -exact $args "-pagesize"]
33
if { $pgindex != -1 } {
34
puts "Test078: skipping for specific pagesizes"
38
set db [eval {berkdb_open -create -truncate -mode 0644\
39
-pagesize $pagesize} $omethod $args {$testfile}]
40
error_check_good db_open [is_valid_db $db] TRUE
42
for { set i 1 } { $i <= $nkeys } { incr i } {
43
error_check_good put.a($i) [$db put $i\
44
[pad_data $method $alphabet$i]] 0
45
error_check_good count.a [$db count $i] 1
47
error_check_good db_close.a [$db close] 0
49
if { [is_record_based $method] == 1 || [is_rbtree $method] == 1 } {
51
"\tTest0$tnum.b: Duplicates not supported in $method, skipping."
55
foreach tuple {{b sorted "-dup -dupsort"} {c unsorted "-dup"}} {
56
set letter [lindex $tuple 0]
57
set dupopt [lindex $tuple 2]
59
puts "\tTest0$tnum.$letter: Duplicates ([lindex $tuple 1])."
61
puts "\t\tTest0$tnum.$letter.1: Populating database."
63
set db [eval {berkdb_open -create -truncate -mode 0644\
64
-pagesize $pagesize} $dupopt $omethod $args {$testfile}]
65
error_check_good db_open [is_valid_db $db] TRUE
67
for { set i 1 } { $i <= $nkeys } { incr i } {
68
for { set j 0 } { $j < $i } { incr j } {
69
error_check_good put.$letter,$i [$db put $i\
70
[pad_data $method $j$alphabet]] 0
74
puts -nonewline "\t\tTest0$tnum.$letter.2: "
75
puts "Verifying dup counts on first dup."
76
for { set i 1 } { $i < $nkeys } { incr i } {
77
error_check_good count.$letter,$i \
81
puts -nonewline "\t\tTest0$tnum.$letter.3: "
82
puts "Verifying dup counts on random dup."
83
for { set i 1 } { $i < $nkeys } { incr i } {
84
set key [berkdb random_int 1 $nkeys]
85
error_check_good count.$letter,$i \
88
error_check_good db_close.$letter [$db close] 0