From d148e970f1402f650108ceb872ee83e31e1c818e Mon Sep 17 00:00:00 2001 From: Nathan Wagner Date: Fri, 2 Dec 2011 05:23:12 -0500 Subject: [PATCH] Added capabilities response test. --- t/02_capabilities.t | 79 ++++++++++++++++++++++++++++ t/{02_responses.t => 03_responses.t} | 0 2 files changed, 79 insertions(+) create mode 100644 t/02_capabilities.t rename t/{02_responses.t => 03_responses.t} (100%) diff --git a/t/02_capabilities.t b/t/02_capabilities.t new file mode 100644 index 0000000..33b80b0 --- /dev/null +++ b/t/02_capabilities.t @@ -0,0 +1,79 @@ +#!/usr/bin/perl + +use Test::More tests => 17; + +BEGIN { use_ok('Net::Cmd') } +BEGIN { use_ok('Net::NNTP') } + +my $c = Net::NNTP->new(Host => '127.0.0.1', Port => 20203, Reader => 0); + +ok(defined $c, 'connected to localhost'); + +BAIL_OUT(q{can't connect to test server'}) unless $c; + +sub Net::NNTP::issue { + my ($c, @cmd) = @_; + $c->command(@cmd); + $c->response(); + return $c->code(); +} + +sub Net::NNTP::try { + my ($c, $cmd, $test, @valid) = @_; + $c->command($cmd); + $c->response(); + ok(scalar (grep {$c->code == $_} @valid) , "$test ".$c->code." in (@valid)"); + return $c->code; +} + +# 3977:5.1.1 initial greeting must be 200 201 400 502 +my @valid = (200, 201, 400, 502); +my $greeting = $c->code; + +ok(grep {$c->code == $_} @valid, 'correct initial response from server'); + +unless ($greeting == 200 or $greeting = 201) { + BAIL_OUT(q{bad greeting from server'}); +} + +# 4 tests done to here + +$c->try('CAPABILITIES','capabilities',101); + +SKIP: { + skip q{can't get capabilities}, 3 unless $c->code == 101; + + my $capabilities = $c->read_until_dot() if ($c->code == 101); + + my %cap = (); + my $twice = 0; + foreach my $line (@$capabilities) { + my ($capability, @arg) = split(/\s+/, $line); + if (exists($cap{$capability})) { + $twice = 1; + } + $cap{$capability} = \@arg; + } + + ok($twice == 0, 'No capability listed twice (3977:5.2.2)'); + ok(exists $cap{READER}, 'announce READER'); + is($cap{'MODE-READER'}, undef, q{don't announce MODE-READER}); + foreach $trycap qw(ACTIVE NEWSGROUPS OVERVIEW.FMT + ACTIVE.TIMES HEADERS) { + cmp_ok(scalar(grep { $trycap eq $_ } @{$cap{LIST}}), '==', 1, + "list capability $trycap"); + } + foreach $trycap qw(MSGID) { + cmp_ok(scalar(grep { $trycap eq $_ } @{$cap{OVER}}), '==', 1, + "list capability $trycap"); + } + + $capabilities->[0] =~ /(VERSION) (\d+)(\r?)(\n)/; + + is($1, 'VERSION', 'VERSION capability first'); + is($2, 2, 'Version 2 server'); + skip q{can only test version 2 servers}, 0 unless $2 == 2; + +} + +$c->try('QUIT','quit',205); diff --git a/t/02_responses.t b/t/03_responses.t similarity index 100% rename from t/02_responses.t rename to t/03_responses.t -- 2.40.0