#!./perl -w
plan(
skip_all
=>
"POSIX is unavailable"
)
unless
$Config
{extensions} =~ /\bPOSIX\b/;
plan(
skip_all
=>
"sigemptyset is unavailable on $^O"
)
if
$^O eq
'MSWin32'
;
POSIX->
import
();
my
@signo
;
my
(
$min
,
$max
) = (~0, -1);
sub
expected_signals {
my
$sigset
=
shift
;
my
$desc
=
shift
;
my
%expected
;
++
$expected
{
$_
}
foreach
@_
;
local
$Test::Builder::Level
=
$Test::Builder::Level
+ 1;
for
my
$sig
(
$min
..
$max
) {
if
(
$expected
{
$sig
}) {
cmp_ok(
$sigset
->ismember(
$sig
),
'=='
, 1,
"$desc - sig $sig is a member"
);
}
else
{
cmp_ok(
$sigset
->ismember(
$sig
),
'=='
, 0,
"$desc - sig $sig is not a member"
);
}
}
}
foreach
(
@POSIX::EXPORT
) {
next
unless
/^SIG[A-Z0-9]+$/;
my
$val
=
eval
"POSIX::$_"
;
next
unless
defined
$val
;
$min
=
$val
if
$min
>
$val
;
$max
=
$val
if
$max
<
$val
;
push
@signo
,
$val
;
}
cmp_ok(
scalar
@signo
,
'>='
, 6,
'found at least 6 signals (6 are named in the ANSI C spec)'
);
my
$sigset
= POSIX::SigSet->new();
isa_ok(
$sigset
,
'POSIX::SigSet'
,
'checking the type of the object'
);
expected_signals(
$sigset
,
'new object'
);
is(
$sigset
->fillset(),
'0 but true'
,
'fillset'
);
foreach
(
@signo
) {
cmp_ok(
$sigset
->ismember(
$_
),
'=='
, 1,
"after fillset sig $_ is a member"
);
}
is(
$sigset
->emptyset(),
'0 but true'
,
'empyset'
);
expected_signals(
$sigset
,
'after emptyset'
);
is(
$sigset
->addset(
$signo
[1]),
'0 but true'
,
'addset'
);
expected_signals(
$sigset
,
'after addset'
,
$signo
[1]);
is(
$sigset
->addset(
$signo
[2]),
'0 but true'
,
'addset'
);
expected_signals(
$sigset
,
'after addset'
,
$signo
[1],
$signo
[2]);
is(
$sigset
->addset(
$signo
[4]),
'0 but true'
,
'addset'
);
expected_signals(
$sigset
,
'after addset'
,
$signo
[1],
$signo
[2],
$signo
[4]);
is(
$sigset
->addset(
$signo
[2]),
'0 but true'
,
'addset'
);
expected_signals(
$sigset
,
'after addset'
,
$signo
[1],
$signo
[2],
$signo
[4]);
is(
$sigset
->delset(
$signo
[4]),
'0 but true'
,
'delset'
);
expected_signals(
$sigset
,
'after addset'
,
$signo
[1],
$signo
[2]);
is(
$sigset
->addset(
$signo
[0]),
'0 but true'
,
'addset'
);
expected_signals(
$sigset
,
'after addset'
,
$signo
[0],
$signo
[1],
$signo
[2]);
is(
$sigset
->delset(
$signo
[4]),
'0 but true'
,
'delset'
);
expected_signals(
$sigset
,
'after delset'
,
$signo
[0],
$signo
[1],
$signo
[2]);
is(
$sigset
->delset(
$signo
[1]),
'0 but true'
,
'delset'
);
expected_signals(
$sigset
,
'after delset'
,
$signo
[0],
$signo
[2]);
is(
$sigset
->delset(
$signo
[0]),
'0 but true'
,
'delset'
);
expected_signals(
$sigset
,
'after addset'
,
$signo
[2]);
is(
$sigset
->delset(
$signo
[2]),
'0 but true'
,
'delset'
);
expected_signals(
$sigset
,
'empty again'
);
foreach
([
$signo
[0]],
[
$signo
[2]],
[
$signo
[3]],
[
@signo
[2,3,6]],
) {
$sigset
= POSIX::SigSet->new(
@$_
);
isa_ok(
$sigset
,
'POSIX::SigSet'
,
'checking the type of the object'
);
local
$" =
', '
;
expected_signals(
$sigset
,
"new(@$_)"
,
@$_
);
}
SKIP:
{
skip
"Not all systems validate the signal number"
, 2
unless
$^O =~ /^(linux|freebsd)$/;
my
$badsig
= -1;
note
"badsig $badsig"
;
ok(!
eval
{ POSIX::SigSet->new(
$badsig
); 1 },
"POSIX::SigSet->new should throw on large signal number"
);
like($@.
""
,
qr/POSIX::Sigset->new: failed to add signal $badsig/
,
"check message"
);
}
done_testing();