5 use Test::More tests => 14;
6 use File::Temp qw( tempfile tempdir );
10 my $dir = tempdir( CLEANUP => 1 );
11 my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
15 my $db = new DBM::Deep(
22 $db->_get_self->{engine}->set_digest( \&my_digest, 8 );
27 $db->{key1} = "value1";
28 ok( $db->{key1} eq "value1" );
30 $db->put("key2", "value2");
31 ok( $db->get("key2") eq "value2" );
36 ok( $db->exists("key1") );
37 ok( exists $db->{key2} );
42 ok( scalar keys %$db == 2 );
48 while ( my ($key, $value) = each %$db ) {
49 $temphash->{$key} = $value;
52 ok( ($temphash->{key1} eq "value1") && ($temphash->{key2} eq "value2") );
55 my $key = $db->first_key();
57 $temphash->{$key} = $db->get($key);
58 $key = $db->next_key($key);
61 ok( ($temphash->{key1} eq "value1") && ($temphash->{key2} eq "value2") );
66 ok( delete $db->{key1} );
67 ok( $db->delete("key2") );
69 ok( scalar keys %$db == 0 );
74 $db->put("another", "value");
77 ok( scalar keys %$db == 0 );
82 $db->put("key1", "value1");
83 $db->put("key1", "value2");
85 ok( $db->get("key1") eq "value2" );
87 $db->put("key1", "value222222222222222222222222");
89 ok( $db->get("key1") eq "value222222222222222222222222" );
93 # Warning: This digest function is for testing ONLY
94 # It is NOT intended for actual use
99 for (my $k=0; $k<length($key); $k++) {
100 $num += ord( substr($key, $k, 1) );
103 return sprintf("%00000008d", $num);