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.8 by root, Fri Jun 6 10:23:50 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 => 7;
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_error => sub {
18 ok ($! == Errno::EPIPE);
19 },
20 on_eof => sub { $cv->broadcast },
21 );
22
14 my $concat; 23 my $concat;
15 24
16 $rd_ae->on_eof (sub { $cv->broadcast });
17 $rd_ae->readlines (sub { 25 $rd_ae->push_read (line => sub {
18 my ($rd_ae, @lines) = @_; 26 is ($_[1], "A", 'A line was read correctly');
19 for (@lines) { 27 my $cb; $cb = sub {
20 chomp;
21 $concat .= $_; 28 $concat .= $_[1];
29 $_[0]->push_read (line => $cb);
22 } 30 };
31 $_[0]->push_read (line => $cb);
23 }); 32 });
24 33
25 $wr->syswrite ("A\nBC\nDEF\nG\n"); 34 syswrite $wr, "A\012BC\012DEF\012G\012" . ("X" x 113) . "\012";
26 $wr->syswrite (("X" x 113) . "\n"); 35 close $wr;
27 $wr->close;
28 36
29 $cv->wait; 37 $cv->wait;
30
31 is ($concat, "ABCDEFG".("X"x113), 'lines were read correctly'); 38 is ($concat, "BCDEFG" . ("X" x 113), 'initial lines were read correctly');
32} 39}
33 40
34{ 41{
35 my $cv = AnyEvent->condvar; 42 my $cv = AnyEvent->condvar;
36 43
38 45
39 my $concat; 46 my $concat;
40 47
41 my $rd_ae = 48 my $rd_ae =
42 AnyEvent::Handle->new ( 49 AnyEvent::Handle->new (
43 fh => $rd, 50 fh => $rd,
44 on_eof => sub { $cv->broadcast }, 51 on_eof => sub { $cv->broadcast },
45 on_readline => sub { 52 on_read => sub {
46 my ($rd_ae, @lines) = @_; 53 $_[0]->push_read (line => sub {
47 for (@lines) {
48 chomp;
49 $concat .= $_; 54 $concat .= "$_[1]:";
50 } 55 });
51 } 56 }
52 ); 57 );
53 58
54 $wr->syswrite ("A\nBC\nDEF\nG\n"); 59 my $wr_ae = new AnyEvent::Handle fh => $wr, on_eof => sub { die };
55 $wr->syswrite (("X" x 113) . "\n"); 60
56 $wr->close; 61 undef $wr;
62 undef $rd;
63
64 $wr_ae->push_write (netstring => "0:xx,,");
65 $wr_ae->push_write (netstring => "");
66 $wr_ae->push_write (packstring => "w", "hallole" x 99);
67 $wr_ae->push_write ("A\nBC\nDEF\nG\n" . ("X" x 113) . "\n");
68 undef $wr_ae;
69
70 $rd_ae->push_read (netstring => sub { is ($_[1], "0:xx,,"); });
71 $rd_ae->push_read (netstring => sub { is ($_[1], ""); });
72 $rd_ae->push_read (packstring => "w", sub { is ($_[1], "hallole" x 99); });
57 73
58 $cv->wait; 74 $cv->wait;
59 75
60 is ($concat, "ABCDEFG".("X"x113), 'second lines were read correctly'); 76 is ($concat, "A:BC:DEF:G:" . ("X" x 113) . ":", 'second lines were read correctly');
61} 77}
78

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines