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.4 by root, Sat May 3 12:17:35 2008 UTC vs.
Revision 1.14 by root, Fri Aug 26 03:34:01 2011 UTC

1#!perl 1#!perl
2 2
3# actually tests a few other read/write types as well
4
3use strict; 5use strict;
4use AnyEvent::Impl::Perl; 6
7use AnyEvent;
8BEGIN { require AnyEvent::Impl::Perl unless $ENV{PERL_ANYEVENT_MODEL} }
5use AnyEvent::Handle; 9use AnyEvent::Handle;
10use AnyEvent::Util;
6use Test::More tests => 3; 11use Test::More tests => 8;
7use Socket; 12use Socket;
13use Errno;
8 14
9{ 15{
10 my $cv = AnyEvent->condvar; 16 my $cv = AnyEvent->condvar;
11 17
12 socketpair my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC; 18 my ($rd, $wr) = portable_socketpair;
13 19
14 my $rd_ae = AnyEvent::Handle->new ( 20 my $rd_ae = AnyEvent::Handle->new (
15 fh => $rd, 21 fh => $rd,
16 on_eof => sub { $cv->broadcast }, 22 on_error => sub {
23 ok ($! == &Errno::EPIPE);
24 $cv->broadcast;
25 },
26 on_eof => sub {
27 ok (0, "got eof");
28 },
17 ); 29 );
18 30
19 my $concat; 31 my $concat;
20 32
21 $rd_ae->push_read_line (sub { 33 $rd_ae->push_read (line => sub {
22 is ($_[1], "A", 'A line was read correctly'); 34 is ($_[1], "A", 'A line was read correctly');
23 my $cb; $cb = sub { 35 my $cb; $cb = sub {
24 $concat .= $_[1]; 36 $concat .= $_[1];
25 $_[0]->push_read_line ($cb); 37 $_[0]->push_read (line => $cb);
26 }; 38 };
27 $_[0]->push_read_line ($cb); 39 $_[0]->push_read (line => $cb);
28 }); 40 });
29 41
30 syswrite $wr, "A\nBC\nDEF\nG\n" . ("X" x 113) . "\n"; 42 syswrite $wr, "A\012BC\012DEF\012G\012" . ("X" x 113) . "\012";
31 close $wr; 43 close $wr;
32 44
33 $cv->wait; 45 $cv->wait;
34 is ($concat, "BCDEFG" . ("X" x 113), 'first lines were read correctly'); 46 is ($concat, "BCDEFG" . ("X" x 113), 'initial lines were read correctly');
35} 47}
36 48
37{ 49{
38 my $cv = AnyEvent->condvar; 50 my $cv = AnyEvent->condvar;
39 51
40 socketpair my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC; 52 my ($rd, $wr) = portable_socketpair;
41 53
42 my $concat; 54 my $concat;
43 55
44 my $rd_ae = 56 my $rd_ae =
45 AnyEvent::Handle->new ( 57 AnyEvent::Handle->new (
46 fh => $rd, 58 fh => $rd,
47 on_eof => sub { $cv->broadcast }, 59 on_eof => sub { $cv->broadcast },
48 on_read => sub { 60 on_read => sub {
49 $_[0]->push_read_line (sub { 61 $_[0]->push_read (line => sub {
50 $concat .= "$_[1]:"; 62 $concat .= "$_[1]:";
51 }); 63 });
52 } 64 }
53 ); 65 );
54 66
55 my $wr_ae = new AnyEvent::Handle fh => $wr, on_eof => sub { die }; 67 my $wr_ae = new AnyEvent::Handle fh => $wr, on_eof => sub { die };
56 68
57 $wr_ae->push_write ("A\nBC\nDEF\nG\n" . ("X" x 113) . "\n");
58 undef $wr; 69 undef $wr;
70 undef $rd;
71
72 $wr_ae->push_write (netstring => "0:xx,,");
73 $wr_ae->push_write (netstring => "");
74 $wr_ae->push_write (storable => [4,3,2]);
75 $wr_ae->push_write (packstring => "w", "hallole" x 99999); # try to exhaust socket buffer here
76 $wr_ae->push_write ("A\012BC\012DEF\nG\012" . ("X" x 113) . "\012");
59 undef $wr_ae; 77 undef $wr_ae;
78
79 $rd_ae->push_read (netstring => sub { is ($_[1], "0:xx,,") });
80 $rd_ae->push_read (netstring => sub { is ($_[1], "") });
81 $rd_ae->push_read (storable => "w", sub { is ("@{$_[1]}", "4 3 2") });
82 $rd_ae->push_read (packstring => "w", sub { is ($_[1], "hallole" x 99999) });
60 83
61 $cv->wait; 84 $cv->wait;
62 85
63 is ($concat, "A:BC:DEF:G:" . ("X" x 113) . ":", 'second lines were read correctly'); 86 is ($concat, "A:BC:DEF:G:" . ("X" x 113) . ":", 'second set of lines were read correctly');
64} 87}
88

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines