diff options
author | Graham Barr <gbarr@pobox.com> | 2003-10-20 18:57:34 +0000 |
---|---|---|
committer | Graham Barr <gbarr@pobox.com> | 2003-10-20 18:57:34 +0000 |
commit | ee63997e76534467b2d8acee08fcc3e6b09a4aca (patch) | |
tree | 8e8b1dc97fd6993f091230669fa9ac3ebc1b39a1 /t | |
parent | 0802651ae943c08913aa28ce2aa139089527bced (diff) | |
download | perl-libnet-ee63997e76534467b2d8acee08fcc3e6b09a4aca.tar.gz |
Net::Cmd
- Fix bug in CRLF translation in datasend/dataend
Diffstat (limited to 't')
-rw-r--r-- | t/datasend.t | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/t/datasend.t b/t/datasend.t new file mode 100644 index 0000000..48655fa --- /dev/null +++ b/t/datasend.t @@ -0,0 +1,143 @@ +#!./perl -w + +BEGIN { + package Foo; + + use IO::File; + use Net::Cmd; + @ISA = qw(Net::Cmd IO::File); + + sub timeout { 0 } + + sub new { + my $fh = shift->new_tmpfile; + binmode($fh); + $fh; + } + + sub output { + my $self = shift; + seek($self,0,0); + local $/ = undef; + scalar(<$self>); + } + + sub response { + return Net::Cmd::CMD_OK; + } +} + +(my $libnet_t = __FILE__) =~ s/datasend.t/libnet_t.pl/; +require $libnet_t or die; + +print "1..15\n"; + +sub check { + my $expect = pop; + my $cmd = Foo->new; + $cmd->datasend unless @_; + foreach my $line (@_) { + $cmd->datasend($line); + } + $cmd->dataend; + is($cmd->output, $expect); +} + +my $cmd; + +check( + # nothing + + ".\015\012" +); + +check( + "a", + + "a\015\012.\015\012", +); + +check( + "a\r", + + "a\015\015\012.\015\012", +); + +check( + "a\rb", + + "a\015b\015\012.\015\012", +); + +check( + "a\rb\n", + + "a\015b\015\012.\015\012", +); + +check( + "a\rb\n\n", + + "a\015b\015\012\015\012.\015\012", +); + +check( + "a\r", + "\nb", + + "a\015\012b\015\012.\015\012", +); + +check( + "a\r", + "\nb\n", + + "a\015\012b\015\012.\015\012", +); + +check( + "a\r", + "\nb\r\n", + + "a\015\012b\015\012.\015\012", +); + +check( + "a\r", + "\nb\r\n\n", + + "a\015\012b\015\012\015\012.\015\012", +); + +check( + "a\n.b\n", + + "a\015\012..b\015\012.\015\012", +); + +check( + ".a\n.b\n", + + "..a\015\012..b\015\012.\015\012", +); + +check( + ".a\n", + ".b\n", + + "..a\015\012..b\015\012.\015\012", +); + +check( + ".a", + ".b\n", + + "..a.b\015\012.\015\012", +); + +check( + "a\n.", + + "a\015\012..\015\012.\015\012", +); + |