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

« back to all changes in this revision

Viewing changes to db/perl.BerkeleyDB/t/db-3.0.t

  • 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
#!./perl -w
 
2
 
 
3
# ID: 1.2, 7/17/97
 
4
 
 
5
use strict ;
 
6
 
 
7
BEGIN {
 
8
    unless(grep /blib/, @INC) {
 
9
        chdir 't' if -d 't';
 
10
        @INC = '../lib' if -d '../lib';
 
11
    }
 
12
}
 
13
 
 
14
use BerkeleyDB; 
 
15
use File::Path qw(rmtree);
 
16
 
 
17
BEGIN
 
18
{
 
19
    if ($BerkeleyDB::db_version < 3) {
 
20
        print "1..0 # Skipped - this needs Berkeley DB 3.x or better\n" ;
 
21
        exit 0 ;
 
22
    }
 
23
}        
 
24
 
 
25
print "1..14\n";
 
26
 
 
27
 
 
28
{
 
29
    package LexFile ;
 
30
 
 
31
    sub new
 
32
    {
 
33
        my $self = shift ;
 
34
        unlink @_ ;
 
35
        bless [ @_ ], $self ;
 
36
    }
 
37
 
 
38
    sub DESTROY
 
39
    {
 
40
        my $self = shift ;
 
41
        unlink @{ $self } ;
 
42
    }
 
43
}
 
44
 
 
45
sub ok
 
46
{
 
47
    my $no = shift ;
 
48
    my $result = shift ;
 
49
 
 
50
    print "not " unless $result ;
 
51
    print "ok $no\n" ;
 
52
}
 
53
 
 
54
sub docat
 
55
{
 
56
    my $file = shift;
 
57
    local $/ = undef;
 
58
    open(CAT,$file) || die "Cannot open $file:$!";
 
59
    my $result = <CAT>;
 
60
    close(CAT);
 
61
    return $result;
 
62
}
 
63
 
 
64
 
 
65
my $Dfile = "dbhash.tmp";
 
66
 
 
67
umask(0);
 
68
 
 
69
{
 
70
    # set_mutexlocks
 
71
 
 
72
    my $home = "./fred" ;
 
73
    ok 1, -d $home ? chmod 0777, $home : mkdir($home, 0777) ;
 
74
    mkdir "./fred", 0777 ;
 
75
    chdir "./fred" ;
 
76
    ok 2, my $env = new BerkeleyDB::Env -Flags => DB_CREATE ;
 
77
    ok 3, $env->set_mutexlocks(0) == 0 ;
 
78
    chdir ".." ;
 
79
    undef $env ;
 
80
    rmtree $home ;
 
81
}
 
82
 
 
83
{
 
84
    # c_dup
 
85
 
 
86
 
 
87
    my $lex = new LexFile $Dfile ;
 
88
    my %hash ;
 
89
    my ($k, $v) ;
 
90
    ok 4, my $db = new BerkeleyDB::Hash -Filename => $Dfile, 
 
91
                                     -Flags    => DB_CREATE ;
 
92
 
 
93
    # create some data
 
94
    my %data =  (
 
95
                "red"   => 2,
 
96
                "green" => "house",
 
97
                "blue"  => "sea",
 
98
                ) ;
 
99
 
 
100
    my $ret = 0 ;
 
101
    while (($k, $v) = each %data) {
 
102
        $ret += $db->db_put($k, $v) ;
 
103
    }
 
104
    ok 5, $ret == 0 ;
 
105
 
 
106
    # create a cursor
 
107
    ok 6, my $cursor = $db->db_cursor() ;
 
108
 
 
109
    # point to a specific k/v pair
 
110
    $k = "green" ;
 
111
    ok 7, $cursor->c_get($k, $v, DB_SET) == 0 ;
 
112
    ok 8, $v eq "house" ;
 
113
 
 
114
    # duplicate the cursor
 
115
    my $dup_cursor = $cursor->c_dup(DB_POSITION);
 
116
    ok 9, $dup_cursor ;
 
117
 
 
118
    # move original cursor off green/house
 
119
    $cursor->c_get($k, $v, DB_NEXT) ;
 
120
    ok 10, $k ne "green" ;
 
121
    ok 11, $v ne "house" ;
 
122
 
 
123
    # duplicate cursor should still be on green/house
 
124
    ok 12, $dup_cursor->c_get($k, $v, DB_CURRENT) == 0;
 
125
    ok 13, $k eq "green" ;
 
126
    ok 14, $v eq "house" ;
 
127
    
 
128
}