Commit | Line | Data |
---|---|---|
f92f3fcb GB |
1 | #!./perl -w |
2 | ||
3 | BEGIN { | |
c465390a RGS |
4 | if ($ENV{PERL_CORE}) { |
5 | chdir 't' if -d 't'; | |
6 | @INC = '../lib'; | |
7 | } | |
8 | if (!eval "require Socket") { | |
9 | print "1..0 # no Socket\n"; exit 0; | |
10 | } | |
11 | if (ord('A') == 193 && !eval "require Convert::EBCDIC") { | |
12 | print "1..0 # EBCDIC but no Convert::EBCDIC\n"; exit 0; | |
13 | } | |
14 | } | |
15 | ||
16 | BEGIN { | |
f92f3fcb GB |
17 | package Foo; |
18 | ||
19 | use IO::File; | |
20 | use Net::Cmd; | |
21 | @ISA = qw(Net::Cmd IO::File); | |
22 | ||
23 | sub timeout { 0 } | |
24 | ||
25 | sub new { | |
26 | my $fh = shift->new_tmpfile; | |
27 | binmode($fh); | |
28 | $fh; | |
29 | } | |
30 | ||
31 | sub output { | |
32 | my $self = shift; | |
33 | seek($self,0,0); | |
34 | local $/ = undef; | |
35 | scalar(<$self>); | |
36 | } | |
37 | ||
38 | sub response { | |
39 | return Net::Cmd::CMD_OK; | |
40 | } | |
41 | } | |
42 | ||
43 | (my $libnet_t = __FILE__) =~ s/datasend.t/libnet_t.pl/; | |
44 | require $libnet_t or die; | |
45 | ||
9714c667 | 46 | print "1..51\n"; |
f92f3fcb GB |
47 | |
48 | sub check { | |
49 | my $expect = pop; | |
50 | my $cmd = Foo->new; | |
9714c667 | 51 | ok($cmd->datasend, 'datasend') unless @_; |
f92f3fcb | 52 | foreach my $line (@_) { |
9714c667 | 53 | ok($cmd->datasend($line), 'datasend'); |
f92f3fcb | 54 | } |
9714c667 GB |
55 | ok($cmd->dataend, 'dataend'); |
56 | is( | |
57 | unpack("H*",$cmd->output), | |
58 | unpack("H*",$expect) | |
59 | ); | |
f92f3fcb GB |
60 | } |
61 | ||
62 | my $cmd; | |
63 | ||
64 | check( | |
65 | # nothing | |
66 | ||
67 | ".\015\012" | |
68 | ); | |
69 | ||
70 | check( | |
71 | "a", | |
72 | ||
73 | "a\015\012.\015\012", | |
74 | ); | |
75 | ||
76 | check( | |
77 | "a\r", | |
78 | ||
79 | "a\015\015\012.\015\012", | |
80 | ); | |
81 | ||
82 | check( | |
83 | "a\rb", | |
84 | ||
85 | "a\015b\015\012.\015\012", | |
86 | ); | |
87 | ||
88 | check( | |
89 | "a\rb\n", | |
90 | ||
91 | "a\015b\015\012.\015\012", | |
92 | ); | |
93 | ||
94 | check( | |
95 | "a\rb\n\n", | |
96 | ||
97 | "a\015b\015\012\015\012.\015\012", | |
98 | ); | |
99 | ||
100 | check( | |
101 | "a\r", | |
102 | "\nb", | |
103 | ||
104 | "a\015\012b\015\012.\015\012", | |
105 | ); | |
106 | ||
107 | check( | |
108 | "a\r", | |
109 | "\nb\n", | |
110 | ||
111 | "a\015\012b\015\012.\015\012", | |
112 | ); | |
113 | ||
114 | check( | |
115 | "a\r", | |
116 | "\nb\r\n", | |
117 | ||
118 | "a\015\012b\015\012.\015\012", | |
119 | ); | |
120 | ||
121 | check( | |
122 | "a\r", | |
123 | "\nb\r\n\n", | |
124 | ||
125 | "a\015\012b\015\012\015\012.\015\012", | |
126 | ); | |
127 | ||
128 | check( | |
129 | "a\n.b\n", | |
130 | ||
131 | "a\015\012..b\015\012.\015\012", | |
132 | ); | |
133 | ||
134 | check( | |
135 | ".a\n.b\n", | |
136 | ||
137 | "..a\015\012..b\015\012.\015\012", | |
138 | ); | |
139 | ||
140 | check( | |
141 | ".a\n", | |
142 | ".b\n", | |
143 | ||
144 | "..a\015\012..b\015\012.\015\012", | |
145 | ); | |
146 | ||
147 | check( | |
148 | ".a", | |
149 | ".b\n", | |
150 | ||
151 | "..a.b\015\012.\015\012", | |
152 | ); | |
153 | ||
154 | check( | |
155 | "a\n.", | |
156 | ||
157 | "a\015\012..\015\012.\015\012", | |
158 | ); | |
159 |