Debian Codegraph @

lang/perl/BerkeleyDB/t/examples3.t

raw
1 #!./perl -w
2
3 use strict ;
4
5 BEGIN {
6 unless(grep /blib/, @INC) {
7 chdir 't' if -d 't';
8 @INC = '../lib' if -d '../lib';
9 }
10 }
11
12 use lib 't';
13 use BerkeleyDB;
14 use Test::More;
15 use util ;
16
17 #BEGIN
18 #{
19 # if ($BerkeleyDB::db_version < 3) {
20 # print "1..0 # Skipping test, this needs Berkeley DB 3.x or better\n" ;
21 # exit 0 ;
22 # }
23 #}
24
25 plan(skip_all => "this needs Berkeley DB 3.x or better\n" )
26 if $BerkeleyDB::db_version < 3;
27
28
29
30 plan tests => 2;
31
32
33 my $Dfile = "dbhash.tmp";
34 my $Dfile2 = "dbhash2.tmp";
35 my $Dfile3 = "dbhash3.tmp";
36 unlink $Dfile;
37
38 umask(0) ;
39
40 my $redirect = "xyzt" ;
41
42
43 {
44 my $redirect = "xyzt" ;
45 {
46
47 my $redirectObj = new Redirect $redirect ;
48
49 use strict ;
50 use BerkeleyDB ;
51
52 my $filename = "fruit" ;
53 unlink $filename ;
54 my $db = new BerkeleyDB::Hash
55 -Filename => $filename,
56 -Flags => DB_CREATE,
57 -Property => DB_DUP
58 or die "Cannot open file $filename: $! $BerkeleyDB::Error\n" ;
59
60 # Add a few key/value pairs to the file
61 $db->db_put("red", "apple") ;
62 $db->db_put("orange", "orange") ;
63 $db->db_put("green", "banana") ;
64 $db->db_put("yellow", "banana") ;
65 $db->db_put("red", "tomato") ;
66 $db->db_put("green", "apple") ;
67
68 # print the contents of the file
69 my ($k, $v) = ("", "") ;
70 my $cursor = $db->db_cursor() ;
71 while ($cursor->c_get($k, $v, DB_NEXT) == 0)
72 { print "$k -> $v\n" }
73
74 undef $cursor ;
75 undef $db ;
76 unlink $filename ;
77 }
78
79 #print "[" . docat($redirect) . "]" ;
80 is(docat_del_sort($redirect), <<'EOM') ;
81 green -> apple
82 green -> banana
83 orange -> orange
84 red -> apple
85 red -> tomato
86 yellow -> banana
87 EOM
88
89 }
90
91 {
92 my $redirect = "xyzt" ;
93 {
94
95 my $redirectObj = new Redirect $redirect ;
96
97 use strict ;
98 use BerkeleyDB ;
99
100 my $filename = "fruit" ;
101 unlink $filename ;
102 my $db = new BerkeleyDB::Hash
103 -Filename => $filename,
104 -Flags => DB_CREATE,
105 -Property => DB_DUP | DB_DUPSORT
106 or die "Cannot open file $filename: $! $BerkeleyDB::Error\n" ;
107
108 # Add a few key/value pairs to the file
109 $db->db_put("red", "apple") ;
110 $db->db_put("orange", "orange") ;
111 $db->db_put("green", "banana") ;
112 $db->db_put("yellow", "banana") ;
113 $db->db_put("red", "tomato") ;
114 $db->db_put("green", "apple") ;
115
116 # print the contents of the file
117 my ($k, $v) = ("", "") ;
118 my $cursor = $db->db_cursor() ;
119 while ($cursor->c_get($k, $v, DB_NEXT) == 0)
120 { print "$k -> $v\n" }
121
122 undef $cursor ;
123 undef $db ;
124 unlink $filename ;
125 }
126
127 #print "[" . docat($redirect) . "]" ;
128 is(docat_del_sort($redirect), <<'EOM') ;
129 green -> apple
130 green -> banana
131 orange -> orange
132 red -> apple
133 red -> tomato
134 yellow -> banana
135 EOM
136
137 }
138
139