ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/handle/01_readline.t
(Generate patch)

Comparing AnyEvent/t/handle/01_readline.t (file contents):
Revision 1.9 by root, Fri Jun 6 10:49:20 2008 UTC vs.
Revision 1.14 by root, Fri Aug 26 03:34:01 2011 UTC

1#!perl 1#!perl
2
3# actually tests a few other read/write types as well
2 4
3use strict; 5use strict;
4 6
5use AnyEvent::Impl::Perl; 7use AnyEvent;
8BEGIN { require AnyEvent::Impl::Perl unless $ENV{PERL_ANYEVENT_MODEL} }
6use AnyEvent::Handle; 9use AnyEvent::Handle;
10use AnyEvent::Util;
7use Test::More tests => 7; 11use Test::More tests => 8;
8use Socket; 12use Socket;
13use Errno;
9 14
10{ 15{
11 my $cv = AnyEvent->condvar; 16 my $cv = AnyEvent->condvar;
12 17
13 socketpair my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC; 18 my ($rd, $wr) = portable_socketpair;
14 19
15 my $rd_ae = AnyEvent::Handle->new ( 20 my $rd_ae = AnyEvent::Handle->new (
16 fh => $rd, 21 fh => $rd,
17 on_error => sub { 22 on_error => sub {
18 ok ($! == Errno::EPIPE); 23 ok ($! == &Errno::EPIPE);
24 $cv->broadcast;
19 }, 25 },
20 on_eof => sub { $cv->broadcast }, 26 on_eof => sub {
27 ok (0, "got eof");
28 },
21 ); 29 );
22 30
23 my $concat; 31 my $concat;
24 32
25 $rd_ae->push_read (line => sub { 33 $rd_ae->push_read (line => sub {
39} 47}
40 48
41{ 49{
42 my $cv = AnyEvent->condvar; 50 my $cv = AnyEvent->condvar;
43 51
44 socketpair my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC; 52 my ($rd, $wr) = portable_socketpair;
45 53
46 my $concat; 54 my $concat;
47 55
48 my $rd_ae = 56 my $rd_ae =
49 AnyEvent::Handle->new ( 57 AnyEvent::Handle->new (
61 undef $wr; 69 undef $wr;
62 undef $rd; 70 undef $rd;
63 71
64 $wr_ae->push_write (netstring => "0:xx,,"); 72 $wr_ae->push_write (netstring => "0:xx,,");
65 $wr_ae->push_write (netstring => ""); 73 $wr_ae->push_write (netstring => "");
74 $wr_ae->push_write (storable => [4,3,2]);
66 $wr_ae->push_write (packstring => "w", "hallole" x 99999); # try to exhaust socket buffer here 75 $wr_ae->push_write (packstring => "w", "hallole" x 99999); # try to exhaust socket buffer here
67 $wr_ae->push_write ("A\nBC\nDEF\nG\n" . ("X" x 113) . "\n"); 76 $wr_ae->push_write ("A\012BC\012DEF\nG\012" . ("X" x 113) . "\012");
68 undef $wr_ae; 77 undef $wr_ae;
69 78
70 $rd_ae->push_read (netstring => sub { is ($_[1], "0:xx,,"); }); 79 $rd_ae->push_read (netstring => sub { is ($_[1], "0:xx,,") });
71 $rd_ae->push_read (netstring => sub { is ($_[1], ""); }); 80 $rd_ae->push_read (netstring => sub { is ($_[1], "") });
81 $rd_ae->push_read (storable => "w", sub { is ("@{$_[1]}", "4 3 2") });
72 $rd_ae->push_read (packstring => "w", sub { is ($_[1], "hallole" x 99999); }); 82 $rd_ae->push_read (packstring => "w", sub { is ($_[1], "hallole" x 99999) });
73 83
74 $cv->wait; 84 $cv->wait;
75 85
76 is ($concat, "A:BC:DEF:G:" . ("X" x 113) . ":", 'second lines were read correctly'); 86 is ($concat, "A:BC:DEF:G:" . ("X" x 113) . ":", 'second set of lines were read correctly');
77} 87}
78 88

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines