~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to libdb/perl/BerkeleyDB/t/join.t

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!./perl -w
2
 
 
3
 
# ID: %I%, %G%   
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 t::util ;
16
 
 
17
 
if ($BerkeleyDB::db_ver < 2.005002)
18
 
{
19
 
    print "1..0 # Skip: join needs Berkeley DB 2.5.2 or later\n" ;
20
 
    exit 0 ;
21
 
}
22
 
 
23
 
 
24
 
print "1..37\n";
25
 
 
26
 
my $Dfile1 = "dbhash1.tmp";
27
 
my $Dfile2 = "dbhash2.tmp";
28
 
my $Dfile3 = "dbhash3.tmp";
29
 
unlink $Dfile1, $Dfile2, $Dfile3 ;
30
 
 
31
 
umask(0) ;
32
 
 
33
 
{
34
 
    # error cases
35
 
    my $lex = new LexFile $Dfile1, $Dfile2, $Dfile3 ;
36
 
    my %hash1 ;
37
 
    my $value ;
38
 
    my $status ;
39
 
    my $cursor ;
40
 
 
41
 
    ok 1, my $db1 = tie %hash1, 'BerkeleyDB::Hash', 
42
 
                                -Filename => $Dfile1,
43
 
                                -Flags     => DB_CREATE,
44
 
                                -DupCompare   => sub { $_[0] lt $_[1] },
45
 
                                -Property  => DB_DUP|DB_DUPSORT ;
46
 
 
47
 
    # no cursors supplied
48
 
    eval '$cursor = $db1->db_join() ;' ;
49
 
    ok 2, $@ =~ /Usage: \$db->BerkeleyDB::Common::db_join\Q([cursors], flags=0)/;
50
 
 
51
 
    # empty list
52
 
    eval '$cursor = $db1->db_join([]) ;' ;
53
 
    ok 3, $@ =~ /db_join: No cursors in parameter list/;
54
 
 
55
 
    # cursor list, isn't a []
56
 
    eval '$cursor = $db1->db_join({}) ;' ;
57
 
    ok 4, $@ =~ /cursors is not an array reference at/ ;
58
 
 
59
 
    eval '$cursor = $db1->db_join(\1) ;' ;
60
 
    ok 5, $@ =~ /cursors is not an array reference at/ ;
61
 
 
62
 
}
63
 
 
64
 
{
65
 
    # test a 2-way & 3-way join
66
 
 
67
 
    my $lex = new LexFile $Dfile1, $Dfile2, $Dfile3 ;
68
 
    my %hash1 ;
69
 
    my %hash2 ;
70
 
    my %hash3 ;
71
 
    my $value ;
72
 
    my $status ;
73
 
 
74
 
    my $home = "./fred" ;
75
 
    ok 6, my $lexD = new LexDir($home);
76
 
    ok 7, my $env = new BerkeleyDB::Env -Home => $home,
77
 
                                     -Flags => DB_CREATE|DB_INIT_TXN
78
 
                                                |DB_INIT_MPOOL;
79
 
                                                #|DB_INIT_MPOOL| DB_INIT_LOCK;
80
 
    ok 8, my $txn = $env->txn_begin() ;
81
 
    ok 9, my $db1 = tie %hash1, 'BerkeleyDB::Hash', 
82
 
                                -Filename => $Dfile1,
83
 
                                -Flags     => DB_CREATE,
84
 
                                -DupCompare   => sub { $_[0] cmp $_[1] },
85
 
                                -Property  => DB_DUP|DB_DUPSORT,
86
 
                                -Env       => $env,
87
 
                                -Txn       => $txn  ;
88
 
                                ;
89
 
 
90
 
    ok 10, my $db2 = tie %hash2, 'BerkeleyDB::Hash', 
91
 
                                -Filename => $Dfile2,
92
 
                                -Flags     => DB_CREATE,
93
 
                                -DupCompare   => sub { $_[0] cmp $_[1] },
94
 
                                -Property  => DB_DUP|DB_DUPSORT,
95
 
                                -Env       => $env,
96
 
                                -Txn       => $txn  ;
97
 
 
98
 
    ok 11, my $db3 = tie %hash3, 'BerkeleyDB::Btree', 
99
 
                                -Filename => $Dfile3,
100
 
                                -Flags     => DB_CREATE,
101
 
                                -DupCompare   => sub { $_[0] cmp $_[1] },
102
 
                                -Property  => DB_DUP|DB_DUPSORT,
103
 
                                -Env       => $env,
104
 
                                -Txn       => $txn  ;
105
 
 
106
 
    
107
 
    ok 12, addData($db1, qw(    apple           Convenience
108
 
                                peach           Shopway
109
 
                                pear            Farmer
110
 
                                raspberry       Shopway
111
 
                                strawberry      Shopway
112
 
                                gooseberry      Farmer
113
 
                                blueberry       Farmer
114
 
                        ));
115
 
 
116
 
    ok 13, addData($db2, qw(    red     apple
117
 
                                red     raspberry
118
 
                                red     strawberry
119
 
                                yellow  peach
120
 
                                yellow  pear
121
 
                                green   gooseberry
122
 
                                blue    blueberry)) ;
123
 
 
124
 
    ok 14, addData($db3, qw(    expensive       apple
125
 
                                reasonable      raspberry
126
 
                                expensive       strawberry
127
 
                                reasonable      peach
128
 
                                reasonable      pear
129
 
                                expensive       gooseberry
130
 
                                reasonable      blueberry)) ;
131
 
 
132
 
    ok 15, my $cursor2 = $db2->db_cursor() ;
133
 
    my $k = "red" ;
134
 
    my $v = "" ;
135
 
    ok 16, $cursor2->c_get($k, $v, DB_SET) == 0 ;
136
 
 
137
 
    # Two way Join
138
 
    ok 17, my $cursor1 = $db1->db_join([$cursor2]) ;
139
 
 
140
 
    my %expected = qw( apple Convenience
141
 
                        raspberry Shopway
142
 
                        strawberry Shopway
143
 
                ) ;
144
 
 
145
 
    # sequence forwards
146
 
    while ($cursor1->c_get($k, $v) == 0) {
147
 
        delete $expected{$k} 
148
 
            if defined $expected{$k} && $expected{$k} eq $v ;
149
 
        #print "[$k] [$v]\n" ;
150
 
    }
151
 
    ok 18, keys %expected == 0 ;
152
 
    ok 19, $cursor1->status() == DB_NOTFOUND ;
153
 
 
154
 
    # Three way Join
155
 
    ok 20, $cursor2 = $db2->db_cursor() ;
156
 
    $k = "red" ;
157
 
    $v = "" ;
158
 
    ok 21, $cursor2->c_get($k, $v, DB_SET) == 0 ;
159
 
 
160
 
    ok 22, my $cursor3 = $db3->db_cursor() ;
161
 
    $k = "expensive" ;
162
 
    $v = "" ;
163
 
    ok 23, $cursor3->c_get($k, $v, DB_SET) == 0 ;
164
 
    ok 24, $cursor1 = $db1->db_join([$cursor2, $cursor3]) ;
165
 
 
166
 
    %expected = qw( apple Convenience
167
 
                        strawberry Shopway
168
 
                ) ;
169
 
 
170
 
    # sequence forwards
171
 
    while ($cursor1->c_get($k, $v) == 0) {
172
 
        delete $expected{$k} 
173
 
            if defined $expected{$k} && $expected{$k} eq $v ;
174
 
        #print "[$k] [$v]\n" ;
175
 
    }
176
 
    ok 25, keys %expected == 0 ;
177
 
    ok 26, $cursor1->status() == DB_NOTFOUND ;
178
 
 
179
 
    # test DB_JOIN_ITEM
180
 
    # #################
181
 
    ok 27, $cursor2 = $db2->db_cursor() ;
182
 
    $k = "red" ;
183
 
    $v = "" ;
184
 
    ok 28, $cursor2->c_get($k, $v, DB_SET) == 0 ;
185
 
 
186
 
    ok 29, $cursor3 = $db3->db_cursor() ;
187
 
    $k = "expensive" ;
188
 
    $v = "" ;
189
 
    ok 30, $cursor3->c_get($k, $v, DB_SET) == 0 ;
190
 
    ok 31, $cursor1 = $db1->db_join([$cursor2, $cursor3]) ;
191
 
 
192
 
    %expected = qw( apple 1
193
 
                        strawberry 1
194
 
                ) ;
195
 
 
196
 
    # sequence forwards
197
 
    $k = "" ;
198
 
    $v = "" ;
199
 
    while ($cursor1->c_get($k, $v, DB_JOIN_ITEM) == 0) {
200
 
        delete $expected{$k}
201
 
            if defined $expected{$k} ;
202
 
        #print "[$k]\n" ;
203
 
    }
204
 
    ok 32, keys %expected == 0 ;
205
 
    ok 33, $cursor1->status() == DB_NOTFOUND ;
206
 
 
207
 
    ok 34, $cursor1->c_close() == 0 ;
208
 
    ok 35, $cursor2->c_close() == 0 ;
209
 
    ok 36, $cursor3->c_close() == 0 ;
210
 
 
211
 
    ok 37, ($status = $txn->txn_commit) == 0;
212
 
 
213
 
    undef $txn ;
214
 
    #undef $cursor1;
215
 
    #undef $cursor2;
216
 
    #undef $cursor3;
217
 
    undef $db1 ;
218
 
    undef $db2 ;
219
 
    undef $db3 ;
220
 
    undef $env ;
221
 
    untie %hash1 ;
222
 
    untie %hash2 ;
223
 
    untie %hash3 ;
224
 
}
225
 
print "# at the end\n";