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
|
use warnings;
use strict;
use File::Temp 0.22 qw(tempdir);
use Test::More tests => 109;
BEGIN { use_ok "Hash::SharedMem", qw(is_shash shash_open shash_set shash_get); }
my $tmpdir = tempdir(CLEANUP => 1);
sub mkd($) {
my($fn) = @_;
mkdir $fn or die "can't create $fn: $!";
}
sub chd($) {
my($fn) = @_;
chdir $fn or die "can't chdir to $fn: $!";
}
sub test_chdir($$$$$) {
my($absloc, $firstdir, $relloc, $seconddir, $aval) = @_;
ok !-e $absloc;
chd $firstdir;
my $sh = shash_open($relloc, "rwce");
ok $sh;
ok is_shash($sh);
chd $seconddir;
shash_set($sh, "a", $aval);
$sh = undef;
chd "/";
ok -d $absloc;
ok -f "$absloc/iNmv0,m\$%3";
ok -f "$absloc/&\"JBLMEgGm0000000000000001";
$sh = shash_open($absloc, "r");
ok $sh;
ok is_shash($sh);
is shash_get($sh, "a"), $aval;
}
mkd "$tmpdir/t0";
mkd "$tmpdir/t0/t1";
mkd "$tmpdir/t2";
mkd "$tmpdir/t2/t3";
test_chdir "$tmpdir/t2/t4", "$tmpdir/t0", "$tmpdir/t2/t4",
"$tmpdir/t0/t1", "a4";
test_chdir "$tmpdir/t2/t5", "$tmpdir/t0", "../t2/t5",
"$tmpdir/t0/t1", "a5";
test_chdir "$tmpdir/t2/t6", "$tmpdir/t0/t1", "$tmpdir/t2/t6",
"$tmpdir/t0", "a6";
test_chdir "$tmpdir/t2/t7", "$tmpdir/t0/t1", "../../t2/t7",
"$tmpdir/t0", "a7";
test_chdir "$tmpdir/t2/t3/t8", "$tmpdir/t0", "$tmpdir/t2/t3/t8",
"$tmpdir/t0/t1", "a8";
test_chdir "$tmpdir/t2/t3/t9", "$tmpdir/t0", "../t2/t3/t9",
"$tmpdir/t0/t1", "a9";
test_chdir "$tmpdir/t2/t3/t10", "$tmpdir/t0/t1", "$tmpdir/t2/t3/t10",
"$tmpdir/t0", "a10";
test_chdir "$tmpdir/t2/t3/t11", "$tmpdir/t0/t1", "../../t2/t3/t11",
"$tmpdir/t0", "a11";
test_chdir "$tmpdir/t2/t12", "$tmpdir", "$tmpdir/t2/t12",
"$tmpdir/t0/t1", "a12";
test_chdir "$tmpdir/t2/t13", "$tmpdir", "t2/t13",
"$tmpdir/t0/t1", "a13";
test_chdir "$tmpdir/t2/t14", "$tmpdir/t0/t1", "$tmpdir/t2/t14",
"$tmpdir", "a14";
test_chdir "$tmpdir/t2/t15", "$tmpdir/t0/t1", "../../t2/t15",
"$tmpdir", "a15";
1;
|