This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
APItest/t/handy.t: Use abbrev. char name in test names
[perl5.git] / cpan / libnet / t / datasend.t
CommitLineData
2e173144
CBW
1#!perl
2
3use 5.008001;
4
5use strict;
6use warnings;
f92f3fcb
GB
7
8BEGIN {
162b417c 9 if (!eval { require Socket }) {
5abafd4c 10 print "1..0 # no Socket\n"; exit 0;
c465390a 11 }
162b417c 12 if (ord('A') == 193 && !eval { require Convert::EBCDIC }) {
c465390a
RGS
13 print "1..0 # EBCDIC but no Convert::EBCDIC\n"; exit 0;
14 }
15}
16
17BEGIN {
f92f3fcb
GB
18 package Foo;
19
20 use IO::File;
21 use Net::Cmd;
2e173144 22 our @ISA = qw(Net::Cmd IO::File);
f92f3fcb 23
a9282e3c
SH
24 sub timeout { 0 }
25
f92f3fcb
GB
26 sub new {
27 my $fh = shift->new_tmpfile;
28 binmode($fh);
29 $fh;
30 }
31
32 sub output {
33 my $self = shift;
34 seek($self,0,0);
35 local $/ = undef;
36 scalar(<$self>);
37 }
38
39 sub response {
40 return Net::Cmd::CMD_OK;
41 }
42}
43
44(my $libnet_t = __FILE__) =~ s/datasend.t/libnet_t.pl/;
45require $libnet_t or die;
46
db956464 47print "1..54\n";
f92f3fcb
GB
48
49sub check {
50 my $expect = pop;
51 my $cmd = Foo->new;
9714c667 52 ok($cmd->datasend, 'datasend') unless @_;
f92f3fcb 53 foreach my $line (@_) {
9714c667 54 ok($cmd->datasend($line), 'datasend');
f92f3fcb 55 }
9714c667
GB
56 ok($cmd->dataend, 'dataend');
57 is(
58 unpack("H*",$cmd->output),
59 unpack("H*",$expect)
60 );
f92f3fcb
GB
61}
62
63my $cmd;
64
65check(
66 # nothing
67
68 ".\015\012"
69);
70
71check(
72 "a",
73
74 "a\015\012.\015\012",
75);
76
77check(
78 "a\r",
79
80 "a\015\015\012.\015\012",
81);
82
83check(
84 "a\rb",
85
86 "a\015b\015\012.\015\012",
87);
88
89check(
90 "a\rb\n",
91
92 "a\015b\015\012.\015\012",
93);
94
95check(
96 "a\rb\n\n",
97
98 "a\015b\015\012\015\012.\015\012",
99);
100
101check(
102 "a\r",
103 "\nb",
104
105 "a\015\012b\015\012.\015\012",
106);
107
108check(
109 "a\r",
110 "\nb\n",
111
112 "a\015\012b\015\012.\015\012",
113);
114
115check(
116 "a\r",
117 "\nb\r\n",
118
119 "a\015\012b\015\012.\015\012",
120);
121
122check(
123 "a\r",
124 "\nb\r\n\n",
125
126 "a\015\012b\015\012\015\012.\015\012",
127);
128
129check(
130 "a\n.b\n",
131
132 "a\015\012..b\015\012.\015\012",
133);
134
135check(
136 ".a\n.b\n",
137
138 "..a\015\012..b\015\012.\015\012",
139);
140
141check(
142 ".a\n",
143 ".b\n",
144
145 "..a\015\012..b\015\012.\015\012",
146);
147
148check(
149 ".a",
150 ".b\n",
151
152 "..a.b\015\012.\015\012",
153);
154
155check(
156 "a\n.",
157
158 "a\015\012..\015\012.\015\012",
159);
160
db956464
CBW
161# Test that datasend() plays nicely with bytes in an upgraded string,
162# even though the input should really be encode()d already.
163check(
164 substr("\x{100}", 0, 0) . "\x{e9}",
165
166 "\x{e9}\015\012.\015\012"
167);