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.7 by root, Sat May 24 23:15:14 2008 UTC vs.
Revision 1.8 by root, Fri Jun 6 10:23:50 2008 UTC

2 2
3use strict; 3use strict;
4 4
5use AnyEvent::Impl::Perl; 5use AnyEvent::Impl::Perl;
6use AnyEvent::Handle; 6use AnyEvent::Handle;
7use Test::More tests => 4; 7use Test::More tests => 7;
8use Socket; 8use Socket;
9 9
10{ 10{
11 my $cv = AnyEvent->condvar; 11 my $cv = AnyEvent->condvar;
12 12
13 socketpair my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC; 13 socketpair my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC;
14 14
15 my $rd_ae = AnyEvent::Handle->new ( 15 my $rd_ae = AnyEvent::Handle->new (
16 fh => $rd, 16 fh => $rd,
17 on_error => sub {
18 ok ($! == Errno::EPIPE);
19 },
17 on_eof => sub { $cv->broadcast }, 20 on_eof => sub { $cv->broadcast },
18 ); 21 );
19 22
20 my $concat; 23 my $concat;
21 24
22 $rd_ae->push_read (line => sub { 25 $rd_ae->push_read (line => sub {
26 $_[0]->push_read (line => $cb); 29 $_[0]->push_read (line => $cb);
27 }; 30 };
28 $_[0]->push_read (line => $cb); 31 $_[0]->push_read (line => $cb);
29 }); 32 });
30 33
31 syswrite $wr, "A\nBC\nDEF\nG\n" . ("X" x 113) . "\n"; 34 syswrite $wr, "A\012BC\012DEF\012G\012" . ("X" x 113) . "\012";
32 close $wr; 35 close $wr;
33 36
34 $cv->wait; 37 $cv->wait;
35 is ($concat, "BCDEFG" . ("X" x 113), 'first lines were read correctly'); 38 is ($concat, "BCDEFG" . ("X" x 113), 'initial lines were read correctly');
36} 39}
37 40
38{ 41{
39 my $cv = AnyEvent->condvar; 42 my $cv = AnyEvent->condvar;
40 43
53 } 56 }
54 ); 57 );
55 58
56 my $wr_ae = new AnyEvent::Handle fh => $wr, on_eof => sub { die }; 59 my $wr_ae = new AnyEvent::Handle fh => $wr, on_eof => sub { die };
57 60
61 undef $wr;
62 undef $rd;
63
58 $wr_ae->push_write (netstring => "0:xx,,"); 64 $wr_ae->push_write (netstring => "0:xx,,");
65 $wr_ae->push_write (netstring => "");
66 $wr_ae->push_write (packstring => "w", "hallole" x 99);
59 $wr_ae->push_write ("A\nBC\nDEF\nG\n" . ("X" x 113) . "\n"); 67 $wr_ae->push_write ("A\nBC\nDEF\nG\n" . ("X" x 113) . "\n");
60 undef $wr;
61 undef $wr_ae; 68 undef $wr_ae;
62 69
70 $rd_ae->push_read (netstring => sub { is ($_[1], "0:xx,,"); });
63 $rd_ae->push_read (netstring => sub { 71 $rd_ae->push_read (netstring => sub { is ($_[1], ""); });
64 is ($_[1], "0:xx,,"); 72 $rd_ae->push_read (packstring => "w", sub { is ($_[1], "hallole" x 99); });
65 });
66 73
67 $cv->wait; 74 $cv->wait;
68 75
69 is ($concat, "A:BC:DEF:G:" . ("X" x 113) . ":", 'second lines were read correctly'); 76 is ($concat, "A:BC:DEF:G:" . ("X" x 113) . ":", 'second lines were read correctly');
70} 77}
78

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines