3 use Test::More tests => 17;
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, $cmd, $test, @valid) = @_;
25 ok(scalar (grep {$c->code == $_} @valid) , "$test ".$c->code." in (@valid)");
29 # 3977:5.1.1 initial greeting must be 200 201 400 502
30 my @valid = (200, 201, 400, 502);
31 my $greeting = $c->code;
33 ok(grep {$c->code == $_} @valid, 'correct initial response from server');
35 unless ($greeting == 200 or $greeting = 201) {
36 BAIL_OUT(q{bad greeting from server'});
39 # 4 tests done to here
41 $c->try('CAPABILITIES','capabilities',101);
44 skip q{can't get capabilities}, 3 unless $c->code == 101;
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})) {
55 $cap{$capability} = \@arg;
58 ok($twice == 0, 'No capability listed twice (3977:5.2.2)');
59 ok(exists $cap{READER}, 'announce READER');
60 is($cap{'MODE-READER'}, undef, q{don't announce MODE-READER});
61 foreach $trycap (qw(ACTIVE NEWSGROUPS OVERVIEW.FMT
62 ACTIVE.TIMES HEADERS)) {
63 cmp_ok(scalar(grep { $trycap eq $_ } @{$cap{LIST}}), '==', 1,
64 "list capability $trycap");
66 foreach $trycap (qw(MSGID)) {
67 cmp_ok(scalar(grep { $trycap eq $_ } @{$cap{OVER}}), '==', 1,
68 "list capability $trycap");
71 $capabilities->[0] =~ /(VERSION) (\d+)(\r?)(\n)/;
73 is($1, 'VERSION', 'VERSION capability first');
74 is($2, 2, 'Version 2 server');
75 skip q{can only test version 2 servers}, 0 unless $2 == 2;
79 $c->try('QUIT','quit',205);