Sync with libnet 1.18
[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..15\n";
34
35 sub check {
36   my $expect = pop;
37   my $cmd = Foo->new;
38   $cmd->datasend unless @_;
39   foreach my $line (@_) {
40     $cmd->datasend($line);
41   }
42   $cmd->dataend;
43   is($cmd->output, $expect);
44 }
45
46 my $cmd;
47
48 check(
49   # nothing
50
51   ".\015\012"
52 );
53
54 check(
55   "a",
56
57   "a\015\012.\015\012",
58 );
59
60 check(
61   "a\r",
62
63   "a\015\015\012.\015\012",
64 );
65
66 check(
67   "a\rb",
68
69   "a\015b\015\012.\015\012",
70 );
71
72 check(
73   "a\rb\n",
74
75   "a\015b\015\012.\015\012",
76 );
77
78 check(
79   "a\rb\n\n",
80
81   "a\015b\015\012\015\012.\015\012",
82 );
83
84 check(
85   "a\r",
86   "\nb",
87
88   "a\015\012b\015\012.\015\012",
89 );
90
91 check(
92   "a\r",
93   "\nb\n",
94
95   "a\015\012b\015\012.\015\012",
96 );
97
98 check(
99   "a\r",
100   "\nb\r\n",
101
102   "a\015\012b\015\012.\015\012",
103 );
104
105 check(
106   "a\r",
107   "\nb\r\n\n",
108
109   "a\015\012b\015\012\015\012.\015\012",
110 );
111
112 check(
113   "a\n.b\n",
114
115   "a\015\012..b\015\012.\015\012",
116 );
117
118 check(
119   ".a\n.b\n",
120
121   "..a\015\012..b\015\012.\015\012",
122 );
123
124 check(
125   ".a\n",
126   ".b\n",
127
128   "..a\015\012..b\015\012.\015\012",
129 );
130
131 check(
132   ".a",
133   ".b\n",
134
135   "..a.b\015\012.\015\012",
136 );
137
138 check(
139   "a\n.",
140
141   "a\015\012..\015\012.\015\012",
142 );
143