diff options
author | Nicholas Clark <nick@ccl4.org> | 2009-09-28 15:48:08 +0100 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2009-09-29 11:12:38 +0100 |
commit | 1996665eb2c109625e05a30baf70adf11570e7e1 (patch) | |
tree | 82ec5c328a57c440413d36dabd34db1a8923edd0 /dist/Net-Ping/t/250_ping_hires.t | |
parent | f690bb0c344f8c3bfb040e8baf11083c2a2ae536 (diff) | |
download | perl-1996665eb2c109625e05a30baf70adf11570e7e1.tar.gz |
Move Net::Ping from ext/ to dist/
Diffstat (limited to 'dist/Net-Ping/t/250_ping_hires.t')
-rw-r--r-- | dist/Net-Ping/t/250_ping_hires.t | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/dist/Net-Ping/t/250_ping_hires.t b/dist/Net-Ping/t/250_ping_hires.t new file mode 100644 index 0000000000..1f4bcb3770 --- /dev/null +++ b/dist/Net-Ping/t/250_ping_hires.t @@ -0,0 +1,62 @@ +# Test to make sure hires feature works. + +BEGIN { + if ($ENV{PERL_CORE}) { + unless ($ENV{PERL_TEST_Net_Ping}) { + print "1..0 # Skip: network dependent test\n"; + exit; + } + } + unless (eval "require Socket") { + print "1..0 \# Skip: no Socket\n"; + exit; + } + unless (eval "require Time::HiRes") { + print "1..0 \# Skip: no Time::HiRes\n"; + exit; + } + unless (getservbyname('echo', 'tcp')) { + print "1..0 \# Skip: no echo port\n"; + exit; + } +} + +use Test qw(plan ok $TESTERR); +use Net::Ping; +plan tests => 8; + +# Everything loaded fine +ok 1; + +my $p = new Net::Ping "tcp"; + +# new() worked? +ok !!$p; + +# Default is to not use Time::HiRes +ok !$Net::Ping::hires; + +# Enable hires +$p -> hires(); +ok $Net::Ping::hires; + +# Make sure disable works +$p -> hires(0); +ok !$Net::Ping::hires; + +# Enable again +$p -> hires(1); +ok $Net::Ping::hires; + +# Test on the default port +my ($ret, $duration) = $p -> ping("localhost"); + +# localhost should always be reachable, right? +ok $ret; + +# It is extremely likely that the duration contains a decimal +# point if Time::HiRes is functioning properly, except when it +# is fast enough to be "0", or slow enough to be exactly "1". +if (! ok($duration =~ /\.|^[01]$/)) { + print($TESTERR "# duration=[$duration]\n"); +} |