1#!./perl -w 2 3use strict ; 4 5BEGIN { 6 unless(grep /blib/, @INC) { 7 chdir 't' if -d 't'; 8 @INC = '../lib' if -d '../lib'; 9 } 10} 11 12use lib 't'; 13use BerkeleyDB; 14use Test::More; 15use util (1); 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 25plan(skip_all => "this needs Berkeley DB 3.x or better\n" ) 26 if $BerkeleyDB::db_version < 3; 27 28 29 30plan tests => 2; 31 32 33my $Dfile = "dbhash.tmp"; 34my $Dfile2 = "dbhash2.tmp"; 35my $Dfile3 = "dbhash3.tmp"; 36unlink $Dfile; 37 38umask(0) ; 39 40my $redirect = "xyzt" ; 41 42 43{ 44my $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') ; 81green -> apple 82green -> banana 83orange -> orange 84red -> apple 85red -> tomato 86yellow -> banana 87EOM 88 89} 90 91{ 92my $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') ; 129green -> apple 130green -> banana 131orange -> orange 132red -> apple 133red -> tomato 134yellow -> banana 135EOM 136 137} 138 139 140