Tests to check cp() doesn't drop set[eu]id bits.
[p5sagit/p5-mst-13.2.git] / lib / Net / Ping / t / 250_ping_hires.t
CommitLineData
e82f584b 1# Test to make sure hires feature works.
2
3BEGIN {
4 if ($ENV{PERL_CORE}) {
5 unless ($ENV{PERL_TEST_Net_Ping}) {
6 print "1..0 # Skip: network dependent test\n";
7 exit;
8 }
9 chdir 't' if -d 't';
10 @INC = qw(../lib);
11 }
12 unless (eval "require Socket") {
13 print "1..0 \# Skip: no Socket\n";
14 exit;
15 }
16 unless (eval "require Time::HiRes") {
17 print "1..0 \# Skip: no Time::HiRes\n";
18 exit;
19 }
20 unless (getservbyname('echo', 'tcp')) {
21 print "1..0 \# Skip: no echo port\n";
22 exit;
23 }
24}
25
629cba96 26use Test qw(plan ok $TESTERR);
e82f584b 27use Net::Ping;
28plan tests => 8;
29
30# Everything loaded fine
31ok 1;
32
33my $p = new Net::Ping "tcp";
34
35# new() worked?
36ok !!$p;
37
38# Default is to not use Time::HiRes
39ok !$Net::Ping::hires;
40
41# Enable hires
42$p -> hires();
43ok $Net::Ping::hires;
44
45# Make sure disable works
46$p -> hires(0);
47ok !$Net::Ping::hires;
48
49# Enable again
50$p -> hires(1);
51ok $Net::Ping::hires;
52
53# Test on the default port
54my ($ret, $duration) = $p -> ping("localhost");
55
56# localhost should always be reachable, right?
57ok $ret;
58
59# It is extremely likely that the duration contains a decimal
5dbd7494 60# point if Time::HiRes is functioning properly, except when it
629cba96 61# is fast enough to be "0", or slow enough to be exactly "1".
62if (! ok($duration =~ /\.|^[01]$/)) {
63 print($TESTERR "# duration=[$duration]\n");
64}