This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Net-Ping: creating an icmp socket requires admin access on recent cygwin
[perl5.git] / dist / Net-Ping / t / 110_icmp_inst.t
CommitLineData
505f3f16
JH
1# Test to make sure object can be instantiated for icmp protocol.
2# Root access is required to actually perform icmp testing.
3
2f794ae1
NC
4use strict;
5
a2a978ac 6BEGIN {
49afa5f6
JH
7 unless (eval "require Socket") {
8 print "1..0 \# Skip: no Socket\n";
9 exit;
10 }
a2a978ac
JH
11}
12
2f794ae1
NC
13use Test::More tests => 2;
14BEGIN {use_ok('Net::Ping')};
505f3f16 15
2f794ae1
NC
16SKIP: {
17 skip "icmp ping requires root privileges.", 1
18 if ($> and $^O ne 'VMS' and $^O ne 'cygwin')
062ba7df 19 or (($^O eq 'MSWin32' or $^O eq 'cygwin')
2f794ae1
NC
20 and !IsAdminUser())
21 or ($^O eq 'VMS'
22 and (`write sys\$output f\$privilege("SYSPRV")` =~ m/FALSE/));
ddbbf559 23 my $p = new Net::Ping "icmp";
2f794ae1 24 isa_ok($p, 'Net::Ping', 'object can be instantiated for icmp protocol');
ddbbf559 25}
2d706fb2
JD
26
27sub IsAdminUser {
062ba7df 28 return unless $^O eq 'MSWin32' or $^O eq 'cygwin';
2d706fb2
JD
29 return unless eval { require Win32 };
30 return unless defined &Win32::IsAdminUser;
31 return Win32::IsAdminUser();
32}