File: db-4.x.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 (56 lines) | stat: -rwxr-xr-x 967 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
#!./perl -w

use strict ;
use lib 't';
use BerkeleyDB;
use Test::More;
use util ;

plan(skip_all => "this needs Berkeley DB 4.x.x or better\n" )
    if $BerkeleyDB::db_version < 4;


plan tests => 9;

my $Dfile = "dbhash.tmp";
unlink $Dfile;

umask(0) ;

my $db = BerkeleyDB::Btree->new(
	-Filename => $Dfile,
	-Flags    => DB_CREATE,
	-Property => DB_DUP | DB_DUPSORT
) || die "Cannot open file $Dfile: $! $BerkeleyDB::Error\n" ;

my $cursor = $db->db_cursor();

my @pairs = qw(
	Alabama/Athens
	Alabama/Florence
	Alaska/Anchorage
	Alaska/Fairbanks
	Arizona/Avondale
	Arizona/Florence
);

for (@pairs) {
	$db->db_put(split '/');
}

my @tests = (
	["Alaska", "Fa", "Alaska", "Fairbanks"],
	["Arizona", "Fl", "Arizona", "Florence"],
	["Alaska", "An", "Alaska", "Anchorage"],
);

#my $i;
while (my $test = shift @tests) {
	my ($k1, $v1, $k2, $v2) = @$test;
	ok $cursor->c_get($k1, $v1, DB_GET_BOTH_RANGE) ==  0;
	is $k1, $k2;
	is $v1, $v2;
}

undef $db;
unlink $Dfile;