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.2 by elmex, Sun Apr 27 17:27:34 2008 UTC vs.
Revision 1.5 by root, Wed May 21 14:37:55 2008 UTC

1#!perl 1#!perl
2
2use strict; 3use strict;
4
5use AnyEvent::Impl::Perl;
3use AnyEvent::Handle; 6use AnyEvent::Handle;
4use Test::More tests => 2; 7use Test::More tests => 3;
5use Socket; 8use Socket;
6
7 9
8{ 10{
9 my $cv = AnyEvent->condvar; 11 my $cv = AnyEvent->condvar;
10 12
11 socketpair my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC; 13 socketpair my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC;
12 14
13 my $rd_ae = AnyEvent::Handle->new (fh => $rd); 15 my $rd_ae = AnyEvent::Handle->new (
16 fh => $rd,
17 on_eof => sub { $cv->broadcast },
18 );
19
14 my $concat; 20 my $concat;
15 21
16 $rd_ae->on_eof (sub { $cv->broadcast });
17 $rd_ae->readlines (sub { 22 $rd_ae->push_read_line (sub {
18 my ($rd_ae, @lines) = @_; 23 is ($_[1], "A", 'A line was read correctly');
19 for (@lines) { 24 my $cb; $cb = sub {
20 chomp;
21 $concat .= $_; 25 $concat .= $_[1];
26 $_[0]->push_read_line ($cb);
22 } 27 };
28 $_[0]->push_read_line ($cb);
23 }); 29 });
24 30
25 $wr->syswrite ("A\nBC\nDEF\nG\n"); 31 syswrite $wr, "A\nBC\nDEF\nG\n" . ("X" x 113) . "\n";
26 $wr->syswrite (("X" x 113) . "\n"); 32 close $wr;
27 $wr->close;
28 33
29 $cv->wait; 34 $cv->wait;
30
31 is ($concat, "ABCDEFG".("X"x113), 'lines were read correctly'); 35 is ($concat, "BCDEFG" . ("X" x 113), 'first lines were read correctly');
32} 36}
33 37
34{ 38{
35 my $cv = AnyEvent->condvar; 39 my $cv = AnyEvent->condvar;
36 40
38 42
39 my $concat; 43 my $concat;
40 44
41 my $rd_ae = 45 my $rd_ae =
42 AnyEvent::Handle->new ( 46 AnyEvent::Handle->new (
43 fh => $rd, 47 fh => $rd,
44 on_eof => sub { $cv->broadcast }, 48 on_eof => sub { $cv->broadcast },
45 on_readline => sub { 49 on_read => sub {
46 my ($rd_ae, @lines) = @_; 50 $_[0]->push_read_line (sub {
47 for (@lines) {
48 chomp;
49 $concat .= $_; 51 $concat .= "$_[1]:";
50 } 52 });
51 } 53 }
52 ); 54 );
53 55
54 $wr->syswrite ("A\nBC\nDEF\nG\n"); 56 my $wr_ae = new AnyEvent::Handle fh => $wr, on_eof => sub { die };
55 $wr->syswrite (("X" x 113) . "\n"); 57
56 $wr->close; 58 $wr_ae->push_write ("A\nBC\nDEF\nG\n" . ("X" x 113) . "\n");
59 undef $wr;
60 undef $wr_ae;
57 61
58 $cv->wait; 62 $cv->wait;
59 63
60 is ($concat, "ABCDEFG".("X"x113), 'second lines were read correctly'); 64 is ($concat, "A:BC:DEF:G:" . ("X" x 113) . ":", 'second lines were read correctly');
61} 65}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines