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.6 by root, Sat May 24 23:10:18 2008 UTC vs.
Revision 1.11 by root, Fri Jun 6 11:05:16 2008 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::Impl::Perl;
6use AnyEvent::Handle; 8use AnyEvent::Handle;
7use Test::More tests => 4; 9use Test::More tests => 8;
8use Socket; 10use Socket;
11use Errno;
9 12
10{ 13{
11 my $cv = AnyEvent->condvar; 14 my $cv = AnyEvent->condvar;
12 15
13 socketpair my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC; 16 socketpair my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC;
14 17
15 my $rd_ae = AnyEvent::Handle->new ( 18 my $rd_ae = AnyEvent::Handle->new (
16 fh => $rd, 19 fh => $rd,
20 on_error => sub {
21 ok ($! == &Errno::EPIPE);
22 },
17 on_eof => sub { $cv->broadcast }, 23 on_eof => sub { $cv->broadcast },
18 ); 24 );
19 25
20 my $concat; 26 my $concat;
21 27
22 $rd_ae->push_read_line (sub { 28 $rd_ae->push_read (line => sub {
23 is ($_[1], "A", 'A line was read correctly'); 29 is ($_[1], "A", 'A line was read correctly');
24 my $cb; $cb = sub { 30 my $cb; $cb = sub {
25 $concat .= $_[1]; 31 $concat .= $_[1];
26 $_[0]->push_read_line ($cb); 32 $_[0]->push_read (line => $cb);
27 }; 33 };
28 $_[0]->push_read_line ($cb); 34 $_[0]->push_read (line => $cb);
29 }); 35 });
30 36
31 syswrite $wr, "A\nBC\nDEF\nG\n" . ("X" x 113) . "\n"; 37 syswrite $wr, "A\012BC\012DEF\012G\012" . ("X" x 113) . "\012";
32 close $wr; 38 close $wr;
33 39
34 $cv->wait; 40 $cv->wait;
35 is ($concat, "BCDEFG" . ("X" x 113), 'first lines were read correctly'); 41 is ($concat, "BCDEFG" . ("X" x 113), 'initial lines were read correctly');
36} 42}
37 43
38{ 44{
39 my $cv = AnyEvent->condvar; 45 my $cv = AnyEvent->condvar;
40 46
53 } 59 }
54 ); 60 );
55 61
56 my $wr_ae = new AnyEvent::Handle fh => $wr, on_eof => sub { die }; 62 my $wr_ae = new AnyEvent::Handle fh => $wr, on_eof => sub { die };
57 63
64 undef $wr;
65 undef $rd;
66
58 $wr_ae->push_write (netstring => "0:xx,,"); 67 $wr_ae->push_write (netstring => "0:xx,,");
68 $wr_ae->push_write (netstring => "");
69 $wr_ae->push_write (storable => [4,3,2]);
70 $wr_ae->push_write (packstring => "w", "hallole" x 99999); # try to exhaust socket buffer here
59 $wr_ae->push_write ("A\nBC\nDEF\nG\n" . ("X" x 113) . "\n"); 71 $wr_ae->push_write ("A\012BC\012DEF\nG\012" . ("X" x 113) . "\012");
60 undef $wr;
61 undef $wr_ae; 72 undef $wr_ae;
62 73
74 $rd_ae->push_read (netstring => sub { is ($_[1], "0:xx,,") });
63 $rd_ae->push_read (netstring => sub { 75 $rd_ae->push_read (netstring => sub { is ($_[1], "") });
64 is ($_[1], "0:xx,,"); 76 $rd_ae->push_read (storable => "w", sub { is ("@{$_[1]}", "4 3 2") });
65 }); 77 $rd_ae->push_read (packstring => "w", sub { is ($_[1], "hallole" x 99999) });
66 78
67 $cv->wait; 79 $cv->wait;
68 80
69 is ($concat, "A:BC:DEF:G:" . ("X" x 113) . ":", 'second lines were read correctly'); 81 is ($concat, "A:BC:DEF:G:" . ("X" x 113) . ":", 'second set of lines were read correctly');
70} 82}
83

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines