]> pd.if.org Git - newsd/blob - t/02_capabilities.t
Added SKIP block for useless follow up tests.
[newsd] / t / 02_capabilities.t
1 #!/usr/bin/perl
2
3 use Test::More tests => 17; 
4
5 BEGIN { use_ok('Net::Cmd') }
6 BEGIN { use_ok('Net::NNTP') }
7
8 my $c = Net::NNTP->new(Host => '127.0.0.1', Port => 20203, Reader => 0);
9
10 ok(defined $c, 'connected to localhost');
11
12 BAIL_OUT(q{can't connect to test server'}) unless $c;
13
14 sub Net::NNTP::issue {
15         my ($c, @cmd) = @_;
16         $c->command(@cmd);
17         $c->response();
18         return $c->code();
19 }
20
21 sub Net::NNTP::try {
22         my ($c, $cmd, $test, @valid) = @_;
23         $c->command($cmd);
24         $c->response();
25         ok(scalar (grep {$c->code == $_} @valid) , "$test ".$c->code." in (@valid)");
26         return $c->code;
27 }
28
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;
32
33 ok(grep {$c->code == $_} @valid, 'correct initial response from server');
34
35 unless ($greeting == 200 or $greeting = 201) {
36         BAIL_OUT(q{bad greeting from server'});
37 }
38
39 # 4 tests done to here
40
41 $c->try('CAPABILITIES','capabilities',101);
42
43 SKIP: {
44         skip q{can't get capabilities}, 3 unless $c->code == 101;
45
46         my $capabilities = $c->read_until_dot() if ($c->code == 101);
47
48         my %cap = ();
49         my $twice = 0;
50         foreach my $line (@$capabilities) {
51                 my ($capability, @arg) = split(/\s+/, $line);
52                 if (exists($cap{$capability})) {
53                         $twice = 1;
54                 }
55                 $cap{$capability} = \@arg;
56         }
57
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");
65         }
66         foreach $trycap (qw(MSGID)) {
67                 cmp_ok(scalar(grep { $trycap eq $_ } @{$cap{OVER}}), '==', 1,
68                         "list capability $trycap");
69         }
70
71         $capabilities->[0] =~ /(VERSION) (\d+)(\r?)(\n)/;
72
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;
76
77 }
78
79 $c->try('QUIT','quit',205);