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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
use warnings;
use strict;
use File::Temp 0.22 qw(tempdir);
use Test::More tests => 89;
BEGIN { use_ok "Hash::SharedMem", qw(
is_shash shash_open
shash_get shash_set
shash_snapshot shash_is_snapshot
shash_idle
); }
my $tmpdir = tempdir(CLEANUP => 1);
my $s0 = shash_open("$tmpdir/t0", "rwc");
ok $s0;
ok is_shash($s0);
ok !shash_is_snapshot($s0);
shash_set($s0, "a", "aa");
shash_set($s0, "b", "bb");
is shash_get($s0, "a"), "aa";
is shash_get($s0, "b"), "bb";
is shash_get($s0, "c"), undef;
is shash_get($s0, "d"), undef;
my $s1 = shash_snapshot($s0);
ok $s1;
ok is_shash($s1);
ok shash_is_snapshot($s1);
is shash_get($s1, "a"), "aa";
is shash_get($s1, "b"), "bb";
is shash_get($s1, "c"), undef;
is shash_get($s1, "d"), undef;
shash_set($s0, "c", "cc");
is shash_get($s0, "a"), "aa";
is shash_get($s0, "b"), "bb";
is shash_get($s0, "c"), "cc";
is shash_get($s0, "d"), undef;
is shash_get($s1, "a"), "aa";
is shash_get($s1, "b"), "bb";
is shash_get($s1, "c"), undef;
is shash_get($s1, "d"), undef;
my $s2 = shash_snapshot($s0);
ok $s2;
ok is_shash($s2);
ok shash_is_snapshot($s2);
is shash_get($s2, "a"), "aa";
is shash_get($s2, "b"), "bb";
is shash_get($s2, "c"), "cc";
is shash_get($s2, "d"), undef;
shash_set($s0, "d", "dd");
is shash_get($s0, "a"), "aa";
is shash_get($s0, "b"), "bb";
is shash_get($s0, "c"), "cc";
is shash_get($s0, "d"), "dd";
is shash_get($s1, "a"), "aa";
is shash_get($s1, "b"), "bb";
is shash_get($s1, "c"), undef;
is shash_get($s1, "d"), undef;
is shash_get($s2, "a"), "aa";
is shash_get($s2, "b"), "bb";
is shash_get($s2, "c"), "cc";
is shash_get($s2, "d"), undef;
shash_idle($s0);
shash_idle($s1);
my $s3 = shash_snapshot($s1);
ok $s3;
ok is_shash($s3);
ok shash_is_snapshot($s3);
is shash_get($s3, "a"), "aa";
is shash_get($s3, "b"), "bb";
is shash_get($s3, "c"), undef;
is shash_get($s3, "d"), undef;
shash_set($s0, "a", undef);
is shash_get($s0, "a"), undef;
is shash_get($s0, "b"), "bb";
is shash_get($s0, "c"), "cc";
is shash_get($s0, "d"), "dd";
is shash_get($s1, "a"), "aa";
is shash_get($s1, "b"), "bb";
is shash_get($s1, "c"), undef;
is shash_get($s1, "d"), undef;
is shash_get($s2, "a"), "aa";
is shash_get($s2, "b"), "bb";
is shash_get($s2, "c"), "cc";
is shash_get($s2, "d"), undef;
is shash_get($s3, "a"), "aa";
is shash_get($s3, "b"), "bb";
is shash_get($s3, "c"), undef;
is shash_get($s3, "d"), undef;
$s0 = undef;
is shash_get($s1, "a"), "aa";
is shash_get($s1, "b"), "bb";
is shash_get($s1, "c"), undef;
is shash_get($s1, "d"), undef;
is shash_get($s2, "a"), "aa";
is shash_get($s2, "b"), "bb";
is shash_get($s2, "c"), "cc";
is shash_get($s2, "d"), undef;
is shash_get($s3, "a"), "aa";
is shash_get($s3, "b"), "bb";
is shash_get($s3, "c"), undef;
is shash_get($s3, "d"), undef;
$s1 = undef;
is shash_get($s2, "a"), "aa";
is shash_get($s2, "b"), "bb";
is shash_get($s2, "c"), "cc";
is shash_get($s2, "d"), undef;
is shash_get($s3, "a"), "aa";
is shash_get($s3, "b"), "bb";
is shash_get($s3, "c"), undef;
is shash_get($s3, "d"), undef;
$s2 = undef;
is shash_get($s3, "a"), "aa";
is shash_get($s3, "b"), "bb";
is shash_get($s3, "c"), undef;
is shash_get($s3, "d"), undef;
1;
|