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.1 by elmex, Sun Apr 27 16:56:17 2008 UTC vs.
Revision 1.4 by root, Sat May 3 12:17:35 2008 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines