~ubuntu-branches/ubuntu/edgy/rpm/edgy

« back to all changes in this revision

Viewing changes to db/test/test078.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Joey Hess
  • Date: 2002-01-22 20:56:57 UTC
  • Revision ID: james.westby@ubuntu.com-20020122205657-l74j50mr9z8ofcl5
Tags: upstream-4.0.3
ImportĀ upstreamĀ versionĀ 4.0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# See the file LICENSE for redistribution information.
 
2
#
 
3
# Copyright (c) 2000-2001
 
4
#       Sleepycat Software.  All rights reserved.
 
5
#
 
6
# $Id: test078.tcl,v 1.10 2001/01/25 18:23:13 bostic Exp $
 
7
#
 
8
# DB Test 78: Test of DBC->c_count(). [#303]
 
9
proc test078 { method { nkeys 100 } { pagesize 512 } { tnum 78 } args } {
 
10
        source ./include.tcl
 
11
        global alphabet rand_init
 
12
 
 
13
        set args [convert_args $method $args]
 
14
        set omethod [convert_method $method]
 
15
 
 
16
        puts "Test0$tnum: Test of key counts."
 
17
 
 
18
        berkdb srand $rand_init
 
19
 
 
20
        set eindex [lsearch -exact $args "-env"]
 
21
        if { $eindex == -1 } {
 
22
                set testfile $testdir/test0$tnum.db
 
23
                set env NULL
 
24
        } else {
 
25
                set testfile test0$tnum.db
 
26
                incr eindex
 
27
                set env [lindex $args $eindex]
 
28
        }
 
29
        cleanup $testdir $env
 
30
 
 
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"
 
35
                return
 
36
        }
 
37
 
 
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
 
41
 
 
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
 
46
        }
 
47
        error_check_good db_close.a [$db close] 0
 
48
 
 
49
        if { [is_record_based $method] == 1 || [is_rbtree $method] == 1 } {
 
50
                puts \
 
51
            "\tTest0$tnum.b: Duplicates not supported in $method, skipping."
 
52
                return
 
53
        }
 
54
 
 
55
        foreach tuple {{b sorted "-dup -dupsort"} {c unsorted "-dup"}} {
 
56
                set letter [lindex $tuple 0]
 
57
                set dupopt [lindex $tuple 2]
 
58
 
 
59
                puts "\tTest0$tnum.$letter: Duplicates ([lindex $tuple 1])."
 
60
 
 
61
                puts "\t\tTest0$tnum.$letter.1: Populating database."
 
62
 
 
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
 
66
 
 
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
 
71
                        }
 
72
                }
 
73
 
 
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 \
 
78
                            [$db count $i] $i
 
79
                }
 
80
 
 
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 \
 
86
                            [$db count $i] $i
 
87
                }
 
88
                error_check_good db_close.$letter [$db close] 0
 
89
        }
 
90
}