3 use Test::More tests => 14;
5 BEGIN { use_ok('Net::Cmd') }
6 BEGIN { use_ok('Net::NNTP') }
8 my $c = Net::NNTP->new(Host => '127.0.0.1', Port => 20203, Reader => 0);
10 ok(defined $c, 'connected to localhost');
12 BAIL_OUT(q{can't connect to test server'}) unless $c;
14 sub Net::NNTP::issue {
22 my ($c, $valid, @cmd) = @_;
24 ok(grep {$c->code == $_} @$valid, "valid response for @$cmd = @$valid");
28 # 3977:5.1.1 initial greeting must be 200 201 400 502
29 my @valid = (200, 201, 400, 502);
30 my $greeting = $c->code;
32 ok(grep {$c->code == $_} @valid, 'correct initial response from server');
34 unless ($greeting == 200 or $greeting = 201) {
38 $c->command('CAPABILITIES');
40 is($c->code, 101, 'correct response to capabilities');
41 $c->read_until_dot() if ($c->code == 101);
43 $c->command('capabilities');
45 is($c->code, 101, 'lower case capabilities ok');
46 my $capabilities = $c->read_until_dot() if ($c->code == 101);
50 foreach my $line (@$capabilities) {
51 my ($capability, @arg) = split(/\s+/, $line);
52 if (exists($cap{$capability})) {
58 ok($twice == 0, 'Capability listed twice (3977:5.2.2)');
60 $capabilities->[0] =~ /(VERSION) (\d+)(\r?)(\n)/;
62 is($1, 'VERSION', 'VERSION capability first');
63 is($2, 2, 'Version 2 server');
66 diag('can only test version 2 servers');
71 skip 'Net::Cmd strips \r, skipping \r\n testing', 2;
72 is($3, "\r", 'Server terminated line with \r');
73 is($4, "\n", 'Server terminated line with \n');
76 is($c->issue('aninvalidcommand'), 500, 'responds with 500 to unknown command');
79 skip 'No LIST capability, skipping list tests', 1 unless $cap{'LIST'};
80 is($c->issue('list aninvalidlist'), 501, 'responds with 501 to unknown list');
84 if ($cap{'STREAMING'}) {
92 is($c->code, 205, 'correct response to quit');
99 my ($cmd, $args, $valid) = @_;