1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
#!perl
use 5.008001;
use strict;
use warnings;
use Test::More;
BEGIN {
if (!eval { require Socket }) {
plan skip_all => "no Socket";
}
elsif (ord('A') == 193 && !eval { require Convert::EBCDIC }) {
plan skip_all => "EBCDIC but no Convert::EBCDIC";
}
else {
plan tests => 54;
}
}
BEGIN {
package Foo;
use IO::File;
use Net::Cmd;
our @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;
}
}
sub check {
my $expect = pop;
my $cmd = Foo->new;
ok($cmd->datasend, 'datasend') unless @_;
foreach my $line (@_) {
ok($cmd->datasend($line), 'datasend');
}
ok($cmd->dataend, 'dataend');
is(
unpack("H*",$cmd->output),
unpack("H*",$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",
);
# Test that datasend() plays nicely with bytes in an upgraded string,
# even though the input should really be encode()d already.
check(
substr("\x{100}", 0, 0) . "\x{e9}",
"\x{e9}\015\012.\015\012"
);
|