blob: 91e905fb26ba12d00d268bd1bee40d73a085f0ad (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# 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;
}
chdir 't' if -d 't';
@INC = qw(../lib);
}
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;
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
# it is fast enough to be "zero".
print "# duration=[$duration]\n";
ok $duration =~ /\.|^0$/;
|