line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Before `make install' is performed this script should be runnable with |
2
|
|
|
|
|
|
|
# `make test'. After `make install' it should work as `perl test.pl' |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
######################### We start with some black magic to print on failure. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# Change 1..1 below to 1..last_test_to_print . |
7
|
|
|
|
|
|
|
# (It may become useful if the test is moved to ./t subdirectory.) |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
BEGIN { |
10
|
6
|
|
|
6
|
|
18
|
$| = 1; |
11
|
6
|
|
|
|
|
516
|
print "1..6\n"; # 5 tests in total |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
END { |
14
|
6
|
50
|
|
6
|
|
|
print "not ok 1\n" unless $loaded; # we couldn't create an object |
15
|
|
|
|
|
|
|
} |
16
|
6
|
|
|
6
|
|
4368
|
use NetServer::Generic; |
|
6
|
|
|
|
|
30
|
|
|
6
|
|
|
|
|
324
|
|
17
|
6
|
|
|
6
|
|
66
|
use IO::Handle; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
1002
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# first test; can we create a new NetServer::Generic? |
20
|
|
|
|
|
|
|
|
21
|
6
|
|
|
|
|
66
|
my $dummy = new NetServer::Generic(); |
22
|
6
|
50
|
|
|
|
156
|
if (ref($dummy) =~ /NetServer::Generic/i) { |
23
|
6
|
|
|
|
|
12
|
$loaded = 1; |
24
|
6
|
|
|
|
|
186
|
print "ok 1\n"; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# next tests: first, we fork. |
28
|
|
|
|
|
|
|
# The parent spawns a new NetServer::Generic server. It prints whatever |
29
|
|
|
|
|
|
|
# comes to it on $out (which is aliased to the original STDOUT). |
30
|
|
|
|
|
|
|
# The child spawns a NetServer::Generic client() server, with a trigger |
31
|
|
|
|
|
|
|
# that fires three times. It prints "ok .. $n" each time, and this is picked |
32
|
|
|
|
|
|
|
# up by the parent (if successful). |
33
|
|
|
|
|
|
|
# |
34
|
|
|
|
|
|
|
# The parent prints ok .. 5 when it exits. |
35
|
|
|
|
|
|
|
# |
36
|
|
|
|
|
|
|
# Test meanings are: |
37
|
|
|
|
|
|
|
# |
38
|
|
|
|
|
|
|
# 1 we could create a NetServer::Generic |
39
|
|
|
|
|
|
|
# 2 - 5 inclusive: the client repeatedly forked and sent these strings |
40
|
|
|
|
|
|
|
# to the server, which echoed them to STDOUT |
41
|
|
|
|
|
|
|
# |
42
|
|
|
|
|
|
|
# NOTE: as yet, no testing for the non-forking server is available. |
43
|
|
|
|
|
|
|
# |
44
|
|
|
|
|
|
|
|
45
|
6
|
|
|
|
|
12
|
my $port = 10101; |
46
|
6
|
|
|
|
|
12
|
my $host = localhost; |
47
|
|
|
|
|
|
|
|
48
|
6
|
|
|
6
|
|
42
|
no strict "vars"; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
21432
|
|
49
|
|
|
|
|
|
|
|
50
|
6
|
|
|
|
|
12
|
$j = 1; |
51
|
|
|
|
|
|
|
|
52
|
6
|
|
|
|
|
24
|
$out = *STDOUT; |
53
|
6
|
|
|
|
|
18
|
select STDERR; $| = 1; |
|
6
|
|
|
|
|
24
|
|
54
|
6
|
|
|
|
|
12
|
select STDOUT; $| = 1; |
|
6
|
|
|
|
|
12
|
|
55
|
|
|
|
|
|
|
#select STDIN; |
56
|
|
|
|
|
|
|
|
57
|
6
|
|
|
|
|
12
|
eval { |
58
|
|
|
|
|
|
|
{ |
59
|
6
|
100
|
|
|
|
12
|
if ($pid = fork) { |
|
6
|
50
|
|
|
|
8777
|
|
|
|
0
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# parent |
61
|
1
|
|
|
|
|
73
|
my ($foo) = new NetServer::Generic(); |
62
|
1
|
|
|
|
|
97
|
$foo->port($port); |
63
|
1
|
|
|
|
|
66
|
$foo->hostname($host); |
64
|
|
|
|
|
|
|
#$foo->allowed([ "localhost"]); |
65
|
|
|
|
|
|
|
my $server = sub { |
66
|
1
|
|
|
1
|
|
15
|
my $self = shift; |
67
|
1
|
|
|
|
|
76
|
while (defined($tmp = )) { |
68
|
2
|
100
|
|
|
|
51
|
if ($tmp !~ /exit/) { |
69
|
1
|
|
|
|
|
96
|
print $out "ok $tmp"; |
70
|
1
|
|
|
|
|
30
|
$val = $tmp; chomp $val; |
|
1
|
|
|
|
|
13
|
|
71
|
|
|
|
|
|
|
} else { |
72
|
1
|
50
|
|
|
|
18
|
if ($val !~ /5/) { |
73
|
0
|
|
|
|
|
0
|
exit; |
74
|
|
|
|
|
|
|
} else { |
75
|
1
|
|
|
|
|
45
|
$self->quit(); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
1
|
|
|
|
|
38
|
}; |
80
|
1
|
|
|
|
|
15
|
$foo->callback($server); |
81
|
1
|
|
|
|
|
18
|
$foo->mode(forking); |
82
|
1
|
|
|
|
|
5
|
$foo->run(); |
83
|
0
|
|
|
|
|
0
|
exit; |
84
|
|
|
|
|
|
|
} elsif (defined $pid) { |
85
|
|
|
|
|
|
|
# child |
86
|
5
|
|
|
|
|
610
|
my ($foo) = new NetServer::Generic(); |
87
|
5
|
|
|
|
|
695
|
$foo->port($port); |
88
|
5
|
|
|
|
|
450
|
$foo->hostname($host); |
89
|
|
|
|
|
|
|
my $client = sub { |
90
|
1
|
|
|
1
|
|
4
|
my $self = shift; |
91
|
1
|
|
|
|
|
58
|
print STDOUT "$j\nexit\n"; |
92
|
1
|
|
|
|
|
386
|
exit 0; |
93
|
5
|
|
|
|
|
220
|
}; |
94
|
5
|
|
|
|
|
135
|
$foo->callback($client); |
95
|
|
|
|
|
|
|
my $trigger = sub { |
96
|
15
|
|
|
15
|
|
218
|
$j++; |
97
|
15
|
100
|
|
|
|
699
|
return(($j > 5) ? 0 : 1 ); #make three connections |
98
|
5
|
|
|
|
|
100
|
}; |
99
|
5
|
|
|
|
|
165
|
$foo->trigger($trigger); |
100
|
5
|
|
|
|
|
85
|
$foo->mode(client); |
101
|
5
|
|
|
|
|
120
|
$foo->run(); |
102
|
1
|
|
|
|
|
212
|
exit; |
103
|
|
|
|
|
|
|
} elsif ($! =~ /no more processes/i) { |
104
|
0
|
|
|
|
|
0
|
print $out "not ok 1\n"; |
105
|
0
|
|
|
|
|
0
|
print STDERR "Are you running a Win32 system? If so, this \n", |
106
|
|
|
|
|
|
|
"test script will not and cannot work\n"; |
107
|
0
|
|
|
|
|
0
|
exit 0; |
108
|
|
|
|
|
|
|
} else { |
109
|
0
|
|
|
|
|
0
|
die "Can't fork: $!\n"; |
110
|
0
|
|
|
|
|
0
|
exit 0; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
}; # end eval |
114
|
|
|
|
|
|
|
|
115
|
3
|
50
|
|
|
|
130
|
if ($@ ne '') { |
116
|
3
|
|
|
|
|
114
|
print "eval(): $@\n"; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
3
|
|
|
|
|
628
|
exit 0; |