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.3 by root, Sun Apr 27 19:08:38 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 => 2;
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 (fh => $rd);
15 my $concat;
12 16
13my $line_cnt = 3; 17 $rd_ae->on_eof (sub { $cv->broadcast });
14my $concat; 18 $rd_ae->readlines (sub {
19 my ($rd_ae, @lines) = @_;
20 for (@lines) {
21 chomp;
22 $concat .= $_;
23 }
24 });
15 25
16$rd_ae->readlines (sub { 26 $wr->syswrite ("A\nBC\nDEF\nG\n");
17 my ($rd_ae, @lines) = @_; 27 $wr->syswrite (("X" x 113) . "\n");
18 for (@lines) { 28 $wr->close;
19 chomp;
20 $line_cnt--;
21 $concat .= $_;
22 }
23 if ($line_cnt <= 0) { $cv->broadcast }
24});
25 29
26$wr->syswrite ("A\nBC\nDEF\nG\n"); 30 $cv->wait;
27$wr->syswrite (("X" x 113) . "\n");
28 31
29$cv->wait; 32 is ($concat, "ABCDEFG".("X" x 113), 'lines were read correctly');
33}
30 34
35{
36 my $cv = AnyEvent->condvar;
37
38 socketpair my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC;
39
40 my $concat;
41
42 my $rd_ae =
43 AnyEvent::Handle->new (
44 fh => $rd,
45 on_eof => sub { $cv->broadcast },
46 on_readline => sub {
47 my ($rd_ae, @lines) = @_;
48 for (@lines) {
49 chomp;
50 $concat .= $_;
51 }
52 }
53 );
54
55 $wr->syswrite ("A\nBC\nDEF\nG\n");
56 $wr->syswrite (("X" x 113) . "\n");
57 $wr->close;
58
59 $cv->wait;
60
31is ($concat, "ABCDEFG".("X"x113), 'lines were read correctly'); 61 is ($concat, "ABCDEFG".("X" x 113), 'second lines were read correctly');
62}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines