Integrate win32 branch into mainline
[p5sagit/p5-mst-13.2.git] / t / lib / ph.t
CommitLineData
50f6e060 1#!./perl
2
3# Check for presence and correctness of .ph files; for now,
4# just socket.ph and pals.
5# -- Kurt Starsinic <kstar@isinet.com>
6
7use lib '../lib';
8
9
10# All the constants which Socket.pm tries to make available:
11my @possibly_defined = qw(
12 INADDR_ANY INADDR_LOOPBACK INADDR_NONE AF_802 AF_APPLETALK AF_CCITT
13 AF_CHAOS AF_DATAKIT AF_DECnet AF_DLI AF_ECMA AF_GOSIP AF_HYLINK AF_IMPLINK
14 AF_INET AF_LAT AF_MAX AF_NBS AF_NIT AF_NS AF_OSI AF_OSINET AF_PUP
15 AF_SNA AF_UNIX AF_UNSPEC AF_X25 MSG_DONTROUTE MSG_MAXIOVLEN MSG_OOB
16 MSG_PEEK PF_802 PF_APPLETALK PF_CCITT PF_CHAOS PF_DATAKIT PF_DECnet PF_DLI
17 PF_ECMA PF_GOSIP PF_HYLINK PF_IMPLINK PF_INET PF_LAT PF_MAX PF_NBS PF_NIT
18 PF_NS PF_OSI PF_OSINET PF_PUP PF_SNA PF_UNIX PF_UNSPEC PF_X25 SOCK_DGRAM
19 SOCK_RAW SOCK_RDM SOCK_SEQPACKET SOCK_STREAM SOL_SOCKET SOMAXCONN
20 SO_ACCEPTCONN SO_BROADCAST SO_DEBUG SO_DONTLINGER SO_DONTROUTE SO_ERROR
21 SO_KEEPALIVE SO_LINGER SO_OOBINLINE SO_RCVBUF SO_RCVLOWAT SO_RCVTIMEO
22 SO_REUSEADDR SO_SNDBUF SO_SNDLOWAT SO_SNDTIMEO SO_TYPE SO_USELOOPBACK
23);
24
25
26# The libraries which I'm going to require:
27my @libs = qw(Socket "sys/types.ph" "sys/socket.ph" "netinet/in.ph");
28
29
30# These are defined by Socket.pm even if the C header files don't define them:
31my %ok_to_miss = (
32 INADDR_NONE => 1,
33 INADDR_LOOPBACK => 1,
34);
35
36
37my $total_tests = scalar @libs + scalar @possibly_defined;
38my $i = 0;
39
40print "1..$total_tests\n";
41
42
43foreach (@libs) {
44 $i++;
45
46 if (eval "require $_" ) {
47 print "ok $i\n";
48 } else {
49 print "# Skipping tests; $_ may be missing\n";
50 foreach ($i .. $total_tests) { print "ok $_\n" }
51 exit;
52 }
53}
54
55
56foreach (@possibly_defined) {
57 $i++;
58
59 $pm_val = eval "Socket::$_()";
60 $ph_val = eval "main::$_()";
61
62 if (defined $pm_val and !defined $ph_val) {
63 if ($ok_to_miss{$_}) { print "ok $i\n" }
64 else { print "not ok $i\n" }
65 next;
66 } elsif (defined $ph_val and !defined $pm_val) {
67 print "not ok $i\n";
68 next;
69 }
70
71 # Socket.pm converts these to network byte order, so we convert the
72 # socket.ph version to match; note that these cases skip the following
73 # `elsif', which is only applied to _numeric_ values, not literal
74 # bitmasks.
75 if ($_ eq 'INADDR_ANY'
76 or $_ eq 'INADDR_LOOPBACK'
77 or $_ eq 'INADDR_NONE') {
78 $ph_val = pack("N*", $ph_val); # htonl(3) equivalent
79 }
80
81 # Since Socket.pm and socket.ph wave their hands over macros differently,
82 # they could return functionally equivalent bitmaps with different numeric
83 # interpretations (due to sign extension). The only apparent case of this
84 # is SO_DONTLINGER (only on Solaris, and deprecated, at that):
85 elsif ($pm_val != $ph_val) {
86 $pm_val = oct(sprintf "0x%lx", $pm_val);
87 $ph_val = oct(sprintf "0x%lx", $ph_val);
88 }
89
90 if ($pm_val == $ph_val) { print "ok $i\n" }
91 else { print "not ok $i\n" }
92}
93
94