]> pd.if.org Git - newsd/blob - t/02_responses.t
Added stat response tests.
[newsd] / t / 02_responses.t
1 #!/usr/bin/perl
2
3 use Test::More tests => 8; 
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('STAT','stat with no newsgroup',412);
42 $c->try('GROUP de.test','group selection',211);
43 $c->try('STAT','stat with newsgroup',223,420);
44
45 goto quit;
46
47 quit:
48
49 $c->try('QUIT','quit',205);