Debian lenny version packages
[pkg-perl] / deb-src / libnet-ssleay-perl / libnet-ssleay-perl-1.35 / t / handle / external / 10_destroy.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use Test::More;
6
7 my @uris = qw(
8         debianforum.de
9         perldition.org
10 );
11 @uris = split(/:/, $ENV{SSLEAY_URIS}) if exists $ENV{SSLEAY_URIS};
12 if (@uris) {
13     plan tests => scalar @uris * 2;
14 }
15 else {
16     plan skip_all => 'No external hosts specified for SSL testing';
17 }
18
19 use File::Spec;
20 use Symbol qw(gensym);
21 use Net::SSLeay::Handle;
22
23 # On some platforms, such as Solaris, the act of resolving the host name
24 # opens (and leaves open) a connection to the DNS client, which breaks 
25 # the fd counting algorithm below. Make sure the DNS is operating before
26 # we count the FDs for the first time.
27 for my $uri (@uris) {
28     my $dummy = gethostbyname($uri);
29 }
30
31 my $fdcount_start = count_fds();
32
33 for my $uri (@uris) {
34     {
35         my $ssl = gensym();
36         tie(*$ssl, "Net::SSLeay::Handle", $uri, 443);
37         print $ssl "GET / HTTP/1.0\r\n\r\n";
38
39         my $response = do { local $/ = undef; <$ssl> };
40         like( $response, qr/^HTTP\/1/s, 'correct response' );
41     }
42
43     my $fdcount_end = count_fds();
44     is ($fdcount_end, $fdcount_start, 'handle gets destroyed when it goes out of scope');
45 }
46
47 sub count_fds {
48     my $fdpath = File::Spec->devnull();
49     my $fh = gensym();
50     open($fh, $fdpath) or die;
51     my $count = fileno($fh);
52     close($fh);
53     return $count;
54 }