File: mldbm.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 (110 lines) | stat: -rw-r--r-- 2,256 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
#!/usr/bin/perl -w

use strict ;

use lib 't';
use Test::More ;

BEGIN
{
	plan skip_all => "this is Perl $], skipping test\n"
        if $] < 5.005 ;

    eval { require Data::Dumper ; };
    if ($@) {
        plan skip_all =>  "Data::Dumper is not installed on this system.\n";
    }
    {
        local ($^W) = 0 ;
        if ($Data::Dumper::VERSION < 2.08) {
            plan skip_all =>  "Data::Dumper 2.08 or better required (found $Data::Dumper::VERSION).\n";
    }
    }
    eval { require MLDBM ; };
    if ($@) {
        plan skip_all =>  "MLDBM is not installed on this system.\n";
    }

    plan tests => 12;
}

use lib 't' ;
use util ;

{
    package BTREE ;

    use BerkeleyDB ;
    use MLDBM qw(BerkeleyDB::Btree) ;
    use Data::Dumper;
    use Test::More;

    my $filename = "";
    my $lex = new LexFile $filename;

    $MLDBM::UseDB = "BerkeleyDB::Btree" ;
    my %o ;
    my $db = tie %o, 'MLDBM', -Filename => $filename,
    		     -Flags    => DB_CREATE
    		or die $!;
    ok $db ;
    ok $db->type() == DB_BTREE ;

    my $c = [\'c'];
    my $b = {};
    my $a = [1, $b, $c];
    $b->{a} = $a;
    $b->{b} = $a->[1];
    $b->{c} = $a->[2];
    @o{qw(a b c)} = ($a, $b, $c);
    $o{d} = "{once upon a time}";
    $o{e} = 1024;
    $o{f} = 1024.1024;

    my $struct = [@o{qw(a b c)}];
    ok ::_compare([$a, $b, $c], $struct);
    ok $o{d} eq "{once upon a time}" ;
    ok $o{e} == 1024 ;
    ok $o{f} eq 1024.1024 ;

}

{

    package HASH ;

    use BerkeleyDB ;
    use MLDBM qw(BerkeleyDB::Hash) ;
    use Data::Dumper;

    my $filename = "";
    my $lex = new LexFile $filename;

    unlink $filename ;
    $MLDBM::UseDB = "BerkeleyDB::Hash" ;
    my %o ;
    my $db = tie %o, 'MLDBM', -Filename => $filename,
		         -Flags    => DB_CREATE
		    or die $!;
    ::ok $db ;
    ::ok $db->type() == DB_HASH ;


    my $c = [\'c'];
    my $b = {};
    my $a = [1, $b, $c];
    $b->{a} = $a;
    $b->{b} = $a->[1];
    $b->{c} = $a->[2];
    @o{qw(a b c)} = ($a, $b, $c);
    $o{d} = "{once upon a time}";
    $o{e} = 1024;
    $o{f} = 1024.1024;

    my $struct = [@o{qw(a b c)}];
    ::ok ::_compare([$a, $b, $c], $struct);
    ::ok $o{d} eq "{once upon a time}" ;
    ::ok $o{e} == 1024 ;
    ::ok $o{f} eq 1024.1024 ;

}