Debian Codegraph @

lang/perl/BerkeleyDB/t/mldbm.t

raw
1 #!/usr/bin/perl -w
2
3 use strict ;
4
5 use lib 't';
6 use Test::More ;
7
8 BEGIN
9 {
10 plan skip_all => "this is Perl $], skipping test\n"
11 if $] < 5.005 ;
12
13 eval { require Data::Dumper ; };
14 if ($@) {
15 plan skip_all => "Data::Dumper is not installed on this system.\n";
16 }
17 {
18 local ($^W) = 0 ;
19 if ($Data::Dumper::VERSION < 2.08) {
20 plan skip_all => "Data::Dumper 2.08 or better required (found $Data::Dumper::VERSION).\n";
21 }
22 }
23 eval { require MLDBM ; };
24 if ($@) {
25 plan skip_all => "MLDBM is not installed on this system.\n";
26 }
27
28 plan tests => 12;
29 }
30
31 use lib 't' ;
32 use util ;
33
34 {
35 package BTREE ;
36
37 use BerkeleyDB ;
38 use MLDBM qw(BerkeleyDB::Btree) ;
39 use Data::Dumper;
40 use Test::More;
41
42 my $filename = "";
43 my $lex = new LexFile $filename;
44
45 $MLDBM::UseDB = "BerkeleyDB::Btree" ;
46 my %o ;
47 my $db = tie %o, 'MLDBM', -Filename => $filename,
48 -Flags => DB_CREATE
49 or die $!;
50 ok $db ;
51 ok $db->type() == DB_BTREE ;
52
53 my $c = [\'c'];
54 my $b = {};
55 my $a = [1, $b, $c];
56 $b->{a} = $a;
57 $b->{b} = $a->[1];
58 $b->{c} = $a->[2];
59 @o{qw(a b c)} = ($a, $b, $c);
60 $o{d} = "{once upon a time}";
61 $o{e} = 1024;
62 $o{f} = 1024.1024;
63
64 my $struct = [@o{qw(a b c)}];
65 ok ::_compare([$a, $b, $c], $struct);
66 ok $o{d} eq "{once upon a time}" ;
67 ok $o{e} == 1024 ;
68 ok $o{f} eq 1024.1024 ;
69
70 }
71
72 {
73
74 package HASH ;
75
76 use BerkeleyDB ;
77 use MLDBM qw(BerkeleyDB::Hash) ;
78 use Data::Dumper;
79
80 my $filename = "";
81 my $lex = new LexFile $filename;
82
83 unlink $filename ;
84 $MLDBM::UseDB = "BerkeleyDB::Hash" ;
85 my %o ;
86 my $db = tie %o, 'MLDBM', -Filename => $filename,
87 -Flags => DB_CREATE
88 or die $!;
89 ::ok $db ;
90 ::ok $db->type() == DB_HASH ;
91
92
93 my $c = [\'c'];
94 my $b = {};
95 my $a = [1, $b, $c];
96 $b->{a} = $a;
97 $b->{b} = $a->[1];
98 $b->{c} = $a->[2];
99 @o{qw(a b c)} = ($a, $b, $c);
100 $o{d} = "{once upon a time}";
101 $o{e} = 1024;
102 $o{f} = 1024.1024;
103
104 my $struct = [@o{qw(a b c)}];
105 ::ok ::_compare([$a, $b, $c], $struct);
106 ::ok $o{d} eq "{once upon a time}" ;
107 ::ok $o{e} == 1024 ;
108 ::ok $o{f} eq 1024.1024 ;
109
110 }