File: strict.t

package info (click to toggle)
libberkeleydb-perl 0.66-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,996 kB
  • sloc: perl: 10,202; ansic: 6,484; makefile: 7
file content (172 lines) | stat: -rw-r--r-- 5,229 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!./perl -w

use strict ;

use lib 't' ;
use BerkeleyDB;
use util ;

use Test::More ;

plan tests => 44;

my $Dfile = "dbhash.tmp";
my $home = "./fred" ;

umask(0);

{
    # closing a database & an environment in the correct order.
    my $lex = new LexFile $Dfile ;
    my %hash ;
    my $status ;

    ok my $lexD = new LexDir($home);
    ok my $env = new BerkeleyDB::Env -Home => $home,@StdErrFile,
                                     -Flags => DB_CREATE|DB_INIT_TXN|
                                                DB_INIT_MPOOL|DB_INIT_LOCK ;

    ok my $db1 = tie %hash, 'BerkeleyDB::Hash', -Filename => $Dfile,
                                      	       	-Flags     => DB_CREATE ,
					       	-Env 	   => $env;

    ok $db1->db_close() == 0 ;

    eval { $status = $env->db_appexit() ; } ;
    ok $status == 0 ;
    ok $@ eq "" ;
    #print "[$@]\n" ;

}

{
    # closing an environment with an open database
    my $lex = new LexFile $Dfile ;
    my %hash ;

    ok my $lexD = new LexDir($home);
    ok my $env = new BerkeleyDB::Env -Home => $home,@StdErrFile,
                                     -Flags => DB_CREATE|DB_INIT_TXN|
                                                DB_INIT_MPOOL|DB_INIT_LOCK ;

    ok my $db1 = tie %hash, 'BerkeleyDB::Hash', -Filename => $Dfile,
                                      	       	-Flags     => DB_CREATE ,
					       	-Env 	   => $env;

    eval { $env->db_appexit() ; } ;
    ok $@ =~ /BerkeleyDB Aborting: attempted to close an environment with 1 open database/ ;
    #print "[$@]\n" ;

    undef $db1 ;
    untie %hash ;
    undef $env ;
}

{
    # closing a transaction & a database
    my $lex = new LexFile $Dfile ;
    my %hash ;
    my $status ;

    ok my $lexD = new LexDir($home);
    ok my $env = new BerkeleyDB::Env -Home => $home,@StdErrFile,
                                     -Flags => DB_CREATE|DB_INIT_TXN|
                                                DB_INIT_MPOOL|DB_INIT_LOCK ;

    ok my $txn = $env->txn_begin() ;
    ok my $db = tie %hash, 'BerkeleyDB::Hash', -Filename => $Dfile,
                                                -Flags     => DB_CREATE ,
					       	-Env 	   => $env,
                                                -Txn       => $txn  ;

    ok $txn->txn_commit()  == 0 ;
    eval { $status = $db->db_close() ; } ;
    ok $status == 0 ;
    ok $@ eq "" ;
    #print "[$@]\n" ;
    eval { $status = $env->db_appexit() ; } ;
    ok $status == 0 ;
    ok $@ eq "" ;
    #print "[$@]\n" ;
}

{
    # closing a database with an open transaction
    my $lex = new LexFile $Dfile ;
    my %hash ;

    ok my $lexD = new LexDir($home);
    ok my $env = new BerkeleyDB::Env -Home => $home,@StdErrFile,
                                     -Flags => DB_CREATE|DB_INIT_TXN|
                                                DB_INIT_MPOOL|DB_INIT_LOCK ;

    ok my $txn = $env->txn_begin() ;
    ok my $db = tie %hash, 'BerkeleyDB::Hash', -Filename => $Dfile,
                                                -Flags     => DB_CREATE ,
					       	-Env 	   => $env,
                                                -Txn       => $txn  ;

    eval { $db->db_close() ; } ;
    ok $@ =~ /BerkeleyDB Aborting: attempted to close a database while a transaction was still open at/ ;
    #print "[$@]\n" ;
    $txn->txn_abort();
    $db->db_close();
}

{
    # closing a cursor & a database
    my $lex = new LexFile $Dfile ;
    my %hash ;
    my $status ;
    ok my $db = tie %hash, 'BerkeleyDB::Hash', -Filename => $Dfile,
                                                -Flags     => DB_CREATE ;
    ok my $cursor = $db->db_cursor() ;
    ok $cursor->c_close() == 0 ;
    eval { $status = $db->db_close() ; } ;
    ok $status == 0 ;
    ok $@ eq "" ;
    #print "[$@]\n" ;
}

{
    # closing a database with an open cursor
    my $lex = new LexFile $Dfile ;
    my %hash ;
    ok my $db = tie %hash, 'BerkeleyDB::Hash', -Filename => $Dfile,
                                                -Flags     => DB_CREATE ;
    ok my $cursor = $db->db_cursor() ;
    eval { $db->db_close() ; } ;
    ok $@ =~ /\QBerkeleyDB Aborting: attempted to close a database with 1 open cursor(s) at/;
    #print "[$@]\n" ;
}

{
    # closing a transaction & a cursor
    my $lex = new LexFile $Dfile ;
    my %hash ;
    my $status ;
    my $home = 'fred1';

    ok my $lexD = new LexDir($home);
    ok my $env = new BerkeleyDB::Env -Home => $home,@StdErrFile,
                                     -Flags => DB_CREATE|DB_INIT_TXN|
                                                DB_INIT_MPOOL|DB_INIT_LOCK ;
    ok my $txn = $env->txn_begin() ;
    ok my $db = tie %hash, 'BerkeleyDB::Hash', -Filename => $Dfile,
                                                -Flags     => DB_CREATE ,
					       	-Env 	   => $env,
                                                -Txn       => $txn  ;
    ok my $cursor = $db->db_cursor() ;
    eval { $status = $cursor->c_close() ; } ;
    ok $status == 0 ;
    ok $txn->txn_commit() == 0 ;
    ok $@ eq "" ;
    eval { $status = $db->db_close() ; } ;
    ok $status == 0 ;
    ok $@ eq "" ;
    #print "[$@]\n" ;
    eval { $status = $env->db_appexit() ; } ;
    ok $status == 0 ;
    ok $@ eq "" ;
    #print "[$@]\n" ;
}