Add ARM files
[dh-make-perl] / dev / arm / libnet-ssleay-perl / libnet-ssleay-perl-1.35 / t / local / 08_pipe.t
diff --git a/dev/arm/libnet-ssleay-perl/libnet-ssleay-perl-1.35/t/local/08_pipe.t b/dev/arm/libnet-ssleay-perl/libnet-ssleay-perl-1.35/t/local/08_pipe.t
new file mode 100644 (file)
index 0000000..f8f2275
--- /dev/null
@@ -0,0 +1,102 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Test::More;
+use Net::SSLeay;
+use Symbol qw( gensym );
+use IO::Handle;
+use File::Spec;
+
+if ($^O eq 'MSWin32')
+{
+    plan skip_all => 'pipes not properly supported on Windows' if 1;
+    exit;
+}
+else
+{
+    plan tests => 11;
+}
+
+Net::SSLeay::randomize();
+Net::SSLeay::load_error_strings();
+Net::SSLeay::OpenSSL_add_ssl_algorithms();
+
+my $cert = File::Spec->catfile(qw( t data cert.pem ));
+my $key  = File::Spec->catfile(qw( t data key.pem  ));
+
+my $how_much = 1024 ** 2;
+
+my $rs = gensym();
+my $ws = gensym();
+my $rc = gensym();
+my $wc = gensym();
+
+pipe $rs, $wc or die "pipe 1 ($!)";
+pipe $rc, $ws or die "pipe 2 ($!)";
+
+for my $h ($rs, $ws, $rc, $wc) {
+    my $old_select = select $h;
+    $| = 1;
+    select $old_select;
+}
+
+my $pid = fork();
+die unless defined $pid;
+
+if ($pid == 0) {
+    my $ctx = Net::SSLeay::CTX_new();
+    Net::SSLeay::set_server_cert_and_key($ctx, $cert, $key);
+
+    my $ssl = Net::SSLeay::new($ctx);
+
+    ok( Net::SSLeay::set_rfd($ssl, fileno($rs)), 'set_rfd using fileno' );
+    ok( Net::SSLeay::set_wfd($ssl, fileno($ws)), 'set_wfd using fileno' );
+
+    ok( Net::SSLeay::accept($ssl), 'accept' );
+
+    ok( my $got = Net::SSLeay::ssl_read_all($ssl, $how_much), 'ssl_read_all' );
+
+    is( Net::SSLeay::ssl_write_all($ssl, \$got), length $got, 'ssl_write_all' );
+
+    Net::SSLeay::free($ssl);
+    Net::SSLeay::CTX_free($ctx);
+
+    close $ws;
+    close $rs;
+    exit;
+}
+
+my @results;
+{
+    my $ctx = Net::SSLeay::CTX_new();
+    my $ssl = Net::SSLeay::new($ctx);
+
+    my $rc_handle = IO::Handle->new_from_fd( fileno($rc), 'r' );
+    my $wc_handle = IO::Handle->new_from_fd( fileno($wc), 'w' );
+    push @results, [ Net::SSLeay::set_rfd($ssl, $rc_handle), 'set_rfd using an io handle' ];
+    push @results, [ Net::SSLeay::set_wfd($ssl, $wc_handle), 'set_wfd using an io handle' ];
+
+    push @results, [ Net::SSLeay::connect($ssl), 'connect' ];
+
+    my $data = 'B' x $how_much;
+
+    push @results, [ Net::SSLeay::ssl_write_all($ssl, \$data) == length $data, 'ssl_write_all' ];
+
+    my $got = Net::SSLeay::ssl_read_all($ssl, $how_much);
+    push @results, [ $got eq $data, 'ssl_read_all' ];
+
+    Net::SSLeay::free($ssl);
+    Net::SSLeay::CTX_free($ctx);
+
+    close $wc;
+    close $rc;
+}
+
+waitpid $pid, 0;
+push @results, [ $? == 0, 'server exited with 0' ];
+
+Test::More->builder->current_test(5);
+for my $t (@results) {
+    ok( $t->[0], $t->[1] );
+}