Commit | Line | Data |
e82f584b |
1 | # Test to make sure hires feature works. |
2 | |
3 | BEGIN { |
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 |
26 | use Test qw(plan ok $TESTERR); |
e82f584b |
27 | use Net::Ping; |
28 | plan tests => 8; |
29 | |
30 | # Everything loaded fine |
31 | ok 1; |
32 | |
33 | my $p = new Net::Ping "tcp"; |
34 | |
35 | # new() worked? |
36 | ok !!$p; |
37 | |
38 | # Default is to not use Time::HiRes |
39 | ok !$Net::Ping::hires; |
40 | |
41 | # Enable hires |
42 | $p -> hires(); |
43 | ok $Net::Ping::hires; |
44 | |
45 | # Make sure disable works |
46 | $p -> hires(0); |
47 | ok !$Net::Ping::hires; |
48 | |
49 | # Enable again |
50 | $p -> hires(1); |
51 | ok $Net::Ping::hires; |
52 | |
53 | # Test on the default port |
54 | my ($ret, $duration) = $p -> ping("localhost"); |
55 | |
56 | # localhost should always be reachable, right? |
57 | ok $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". |
62 | if (! ok($duration =~ /\.|^[01]$/)) { |
63 | print($TESTERR "# duration=[$duration]\n"); |
64 | } |