File: bad_master.t

package info (click to toggle)
libhash-sharedmem-perl 0.005-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 600 kB
  • sloc: perl: 463; makefile: 3
file content (64 lines) | stat: -r--r--r-- 2,690 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
57
58
59
60
61
62
63
64
use warnings;
use strict;

use Errno 1.00 qw(EISDIR);
use File::Temp 0.22 qw(tempdir);
use Test::More tests => 28;

my $eisdir = do { local $! = EISDIR; "$!" };

BEGIN { use_ok "Hash::SharedMem", qw(is_shash shash_open); }

my $tmpdir = tempdir(CLEANUP => 1);

my $sh = shash_open("$tmpdir/t0", "rwc");
ok $sh;
ok is_shash($sh);
$sh = undef;
my $master_file = "$tmpdir/t0/iNmv0,m\$%3";
my $size = -s $master_file;
$size or die;

ok is_shash(eval { shash_open("$tmpdir/t0", "rw") });

open(my $fh, ">>", $master_file) or die "can't enlarge $master_file: $!";
print {$fh} ("\0" x $size) or die "can't enlarge $master_file: $!";
close $fh or die "can't enlarge $master_file: $!";
is eval { shash_open("$tmpdir/t0", "r") }, undef;
like $@, qr#\Acan't open shared hash \Q$tmpdir\E/t0: not a shared hash at #;
is eval { shash_open("$tmpdir/t0", "rw") }, undef;
like $@, qr#\Acan't open shared hash \Q$tmpdir\E/t0: not a shared hash at #;
is eval { shash_open("$tmpdir/t0", "rwc") }, undef;
like $@, qr#\Acan't open shared hash \Q$tmpdir\E/t0: not a shared hash at #;

truncate $master_file, $size>>1 or die "can't reduce $master_file: $!";
is eval { shash_open("$tmpdir/t0", "r") }, undef;
like $@, qr#\Acan't open shared hash \Q$tmpdir\E/t0: not a shared hash at #;
is eval { shash_open("$tmpdir/t0", "rw") }, undef;
like $@, qr#\Acan't open shared hash \Q$tmpdir\E/t0: not a shared hash at #;
is eval { shash_open("$tmpdir/t0", "rwc") }, undef;
like $@, qr#\Acan't open shared hash \Q$tmpdir\E/t0: not a shared hash at #;

open($fh, ">", $master_file) or die "can't rewrite $master_file: $!";
print {$fh} ("\0" x $size) or die "can't rewrite $master_file: $!";
close $fh or die "can't rewrite $master_file: $!";
is eval { shash_open("$tmpdir/t0", "r") }, undef;
like $@, qr#\Acan't open shared hash \Q$tmpdir\E/t0: not a shared hash at #;
is eval { shash_open("$tmpdir/t0", "rw") }, undef;
like $@, qr#\Acan't open shared hash \Q$tmpdir\E/t0: not a shared hash at #;
is eval { shash_open("$tmpdir/t0", "rwc") }, undef;
like $@, qr#\Acan't open shared hash \Q$tmpdir\E/t0: not a shared hash at #;

unlink $master_file or die "can't remove $master_file: $!";
mkdir $master_file or die "can't create $master_file: $!";
is eval { shash_open("$tmpdir/t0", "r") }, undef;
like $@, qr#\Acan't\ open\ shared\ hash\ \Q$tmpdir\E/t0:
		\ (?:\Q$eisdir\E|not\ a\ shared\ hash)\ at\ #x;
is eval { shash_open("$tmpdir/t0", "rw") }, undef;
like $@, qr#\Acan't\ open\ shared\ hash\ \Q$tmpdir\E/t0:
		\ (?:\Q$eisdir\E|not\ a\ shared\ hash)\ at\ #x;
is eval { shash_open("$tmpdir/t0", "rwc") }, undef;
like $@, qr#\Acan't\ open\ shared\ hash\ \Q$tmpdir\E/t0:
		\ (?:\Q$eisdir\E|not\ a\ shared\ hash)\ at\ #x;

1;