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