forked from rurban/Net-Ping
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path001_new.t
73 lines (58 loc) · 1.85 KB
/
001_new.t
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
64
65
66
67
68
69
70
71
72
use warnings;
use strict;
BEGIN {
unless (my $port = getservbyname('echo', 'tcp')) {
print "1..0 \# Skip: no echo port\n";
exit;
}
}
use Test::More qw(no_plan);
BEGIN {use_ok('Net::Ping')};
# plain ol' constuctor call
my $p = Net::Ping->new();
isa_ok($p, "Net::Ping");
# call new from an instantiated object
my $p2 = $p->new();
isa_ok($p2, "Net::Ping");
# named args
my $p3 = Net::Ping->new({proto => 'tcp', ttl => 5});
isa_ok($p3, "Net::Ping");
# check for invalid proto
eval {
$p = Net::Ping->new("thwackkk");
};
like($@, qr/Protocol for ping must be "icmp", "icmpv6", "udp", "tcp", "syn", "stream" or "external"/, "new() errors for invalid protocol");
# check for invalid timeout
eval {
$p = Net::Ping->new("tcp", -1);
};
like($@, qr/Default timeout for ping must be greater than 0 seconds/, "new() errors for invalid timeout");
# check for invalid data sizes
eval {
$p = Net::Ping->new("udp", 10, -1);
};
like($@, qr/Data for ping must be from/, "new() errors for invalid data size");
eval {
$p = Net::Ping->new("udp", 10, 70000);
};
like($@, qr/Data for ping must be from/, "new() errors for invalid data size");
# force failures for udp
# force failures for tcp
SKIP: {
# diag "Checking icmp";
eval { $p = Net::Ping->new('icmp'); };
skip "icmp ping requires root privileges.", 3
if !Net::Ping::_isroot() or $^O eq 'MSWin32';
if($> and $^O ne 'VMS' and $^O ne 'cygwin') {
like($@, qr/icmp ping requires root privilege/, "Need root for icmp");
skip "icmp tests require root", 2;
} else {
isa_ok($p, "Net::Ping");
}
# set IP TOS to "Minimum Delay"
$p = Net::Ping->new("icmp", undef, undef, undef, 8);
isa_ok($p, "Net::Ping");
# This really shouldn't work. Not sure who to blame.
$p = Net::Ping->new("icmp", undef, undef, undef, "does this fail");
isa_ok($p, "Net::Ping");
}