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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines