PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/t/lib/ph.t

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