Commit | Line | Data |
ffed8b01 |
1 | ## |
2 | # DBM::Deep Test |
3 | ## |
4 | use strict; |
217fef02 |
5 | use Test::More tests => 11; |
6 | use Test::Exception; |
ffed8b01 |
7 | |
217fef02 |
8 | use_ok( 'DBM::Deep' ); |
ffed8b01 |
9 | |
10 | ## |
11 | # testing the various modes of opening a file |
12 | ## |
13 | { |
14 | unlink "t/test.db"; |
15 | my %hash; |
16 | my $db = tie %hash, 'DBM::Deep', 't/test.db'; |
17 | |
18 | if ($db->error()) { |
19 | print "ERROR: " . $db->error(); |
20 | ok(0); |
21 | exit(0); |
22 | } |
3e97ba2a |
23 | else { ok(1, "Tied an hash with an array for params" ); } |
ffed8b01 |
24 | } |
25 | |
26 | { |
27 | unlink "t/test.db"; |
28 | my %hash; |
29 | my $db = tie %hash, 'DBM::Deep', { |
30 | file => 't/test.db', |
31 | }; |
32 | |
33 | if ($db->error()) { |
34 | print "ERROR: " . $db->error(); |
35 | ok(0); |
36 | exit(0); |
37 | } |
3e97ba2a |
38 | else { ok(1, "Tied a hash with a hashref for params" ); } |
ffed8b01 |
39 | } |
40 | |
41 | { |
42 | unlink "t/test.db"; |
43 | my @array; |
44 | my $db = tie @array, 'DBM::Deep', 't/test.db'; |
45 | |
46 | if ($db->error()) { |
47 | print "ERROR: " . $db->error(); |
48 | ok(0); |
49 | exit(0); |
50 | } |
3e97ba2a |
51 | else { ok(1, "Tied an array with an array for params" ); } |
ffed8b01 |
52 | |
3e97ba2a |
53 | is( $db->{type}, DBM::Deep->TYPE_ARRAY, "TIE_ARRAY sets the correct type" ); |
ffed8b01 |
54 | } |
55 | |
56 | { |
57 | unlink "t/test.db"; |
58 | my @array; |
59 | my $db = tie @array, 'DBM::Deep', { |
60 | file => 't/test.db', |
61 | }; |
62 | |
63 | if ($db->error()) { |
64 | print "ERROR: " . $db->error(); |
65 | ok(0); |
66 | exit(0); |
67 | } |
3e97ba2a |
68 | else { ok(1, "Tied an array with a hashref for params" ); } |
ffed8b01 |
69 | |
3e97ba2a |
70 | is( $db->{type}, DBM::Deep->TYPE_ARRAY, "TIE_ARRAY sets the correct type" ); |
ffed8b01 |
71 | } |
72 | |
e1b265cc |
73 | unlink "t/test.db"; |
74 | throws_ok { |
75 | tie my %hash, 'DBM::Deep', [ file => 't/test.db' ]; |
76 | } qr/Not a hashref/, "Passing an arrayref to TIEHASH fails"; |
ffed8b01 |
77 | |
e1b265cc |
78 | unlink "t/test.db"; |
79 | throws_ok { |
80 | tie my @array, 'DBM::Deep', [ file => 't/test.db' ]; |
81 | } qr/Not a hashref/, "Passing an arrayref to TIEARRAY fails"; |
ffed8b01 |
82 | |
217fef02 |
83 | unlink "t/test.db"; |
84 | throws_ok { |
85 | tie my %hash, 'DBM::Deep', undef, file => 't/test.db'; |
86 | } qr/Odd number of parameters/, "Odd number of params to TIEHASH fails"; |
ffed8b01 |
87 | |
217fef02 |
88 | unlink "t/test.db"; |
89 | throws_ok { |
90 | tie my @array, 'DBM::Deep', undef, file => 't/test.db'; |
91 | } qr/Odd number of parameters/, "Odd number of params to TIEARRAY fails"; |