ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/80_ssltest.t
(Generate patch)

Comparing AnyEvent/t/80_ssltest.t (file contents):
Revision 1.4 by root, Thu Jul 9 18:58:19 2009 UTC vs.
Revision 1.6 by root, Fri Jul 24 22:47:04 2009 UTC

1#!/usr/bin/perl 1#!/usr/bin/perl
2
3BEGIN { eval "use Net::SSLeay (); 1" or ((print "1..0 # SKIP no Net::SSLeay\n"), exit 0) }
2 4
3use Test::More tests => 410; 5use Test::More tests => 410;
4 6
5use strict qw(vars subs); 7use strict qw(vars subs);
6 8
78 80
79 }, sub { 81 }, sub {
80 $server_port->send ($_[2]); 82 $server_port->send ($_[2]);
81 }; 83 };
82 84
85 my $hd; $hd = new AnyEvent::Handle
83 tcp_connect "localhost", $server_port->recv, sub { 86 connect => ["localhost", $server_port->recv],
84 my ($fh) = @_; 87 tls => "connect",
88 tls_ctx => $ctx,
89 timeout => 8,
90 on_connect => sub {
91 ok (1, "client_connect $mode");
92 },
93 on_error => sub {
94 ok (0, "client_error <$!>");
95 $client_done->send; undef $hd;
96 },
97 on_eof => sub {
98 ok (1, "client_eof");
99 $client_done->send; undef $hd;
100 };
85 101
86 ok (1, "client_connect $mode"); 102 if ($mode == 1) {
87 103 $hd->push_write ("1\n");
88 my $hd; $hd = new AnyEvent::Handle 104 $hd->on_drain (sub {
89 tls => "connect",
90 tls_ctx => $ctx,
91 fh => $fh,
92 timeout => 8,
93 on_error => sub {
94 ok (0, "client_error <$!>"); 105 ok (1, "client_drain");
95 $client_done->send; undef $hd; 106 $client_done->send; undef $hd;
96 },
97 on_eof => sub {
98 ok (1, "client_eof");
99 $client_done->send; undef $hd;
100 }; 107 });
101
102 if ($mode == 1) { 108 } elsif ($mode == 2) {
109 $hd->push_read (line => sub {
110 ok ($_[1] eq "2", "line 2 <$_[1]>");
111 });
112 } elsif ($mode == 3) {
113 $hd->push_write ("3\n");
114 $hd->push_read (line => sub {
115 ok ($_[1] eq "4", "line 4 <$_[1]>");
116 });
117 } elsif ($mode == 4) {
118 $hd->push_read (line => sub {
119 ok ($_[1] eq "5", "line 5 <$_[1]>");
103 $hd->push_write ("1\n"); 120 $hd->push_write ("6\n");
104 $hd->on_drain (sub { 121 $hd->on_drain (sub {
105 ok (1, "client_drain"); 122 ok (1, "client_drain");
106 $client_done->send; undef $hd; 123 $client_done->send; undef $hd;
107 }); 124 });
125 });
108 } elsif ($mode == 2) { 126 } elsif ($mode == 5) {
127 # some randomly-sized blocks
128 srand 0;
129 my $cnt = 64;
130 my $block; $block = sub {
131 my $len = (16 << int rand 14) - 16 + int rand 32;
132 ok (1, "write $len");
133 $hd->push_write ("$len\n");
134 $hd->push_write (packstring => "N", "\x00" x $len);
135 };
136
137 for my $i (1..$cnt) {
109 $hd->push_read (line => sub { 138 $hd->push_read (line => sub {
110 ok ($_[1] eq "2", "line 2 <$_[1]>"); 139 my $len = $_[1];
111 }); 140 ok (1, "client block $len/1");
112 } elsif ($mode == 3) {
113 $hd->push_write ("3\n");
114 $hd->push_read (line => sub { 141 $hd->unshift_read (packstring => "N", sub {
115 ok ($_[1] eq "4", "line 4 <$_[1]>"); 142 ok ($len == length $_[1], "client block $len/2");
116 }); 143
117 } elsif ($mode == 4) { 144 if ($i != $cnt) {
118 $hd->push_read (line => sub { 145 $block->();
119 ok ($_[1] eq "5", "line 5 <$_[1]>"); 146 } else {
120 $hd->push_write ("6\n");
121 $hd->on_drain (sub {
122 ok (1, "client_drain"); 147 ok (1, "client_drain");
123 $client_done->send; undef $hd; 148 $client_done->send; undef $hd;
149 }
124 }); 150 });
125 }); 151 });
126 } elsif ($mode == 5) {
127 # some randomly-sized blocks
128 srand 0;
129 my $cnt = 64;
130 my $block; $block = sub {
131 my $len = (16 << int rand 14) - 16 + int rand 32;
132 ok (1, "write $len");
133 $hd->push_write ("$len\n");
134 $hd->push_write (packstring => "N", "\x00" x $len);
135 }; 152 }
136 153
137 for my $i (1..$cnt) {
138 $hd->push_read (line => sub {
139 my $len = $_[1];
140 ok (1, "client block $len/1");
141 $hd->unshift_read (packstring => "N", sub {
142 ok ($len == length $_[1], "client block $len/2");
143
144 if ($i != $cnt) {
145 $block->();
146 } else {
147 ok (1, "client_drain");
148 $client_done->send; undef $hd;
149 }
150 });
151 });
152 }
153
154 $block->(); 154 $block->();
155 }
156 }; 155 }
157 156
158 $server_done->recv; 157 $server_done->recv;
159 $client_done->recv; 158 $client_done->recv;
160} 159}
161 160

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines