X-Git-Url: http://sjero.net/git/?p=wget;a=blobdiff_plain;f=tests%2FHTTPTest.pm;h=883213d19f387ad9cd52c7afb8bfccaa59ec47ab;hp=f17486596c42cfc540462a7b13944de7c47b7a09;hb=d763f8bf6d6e13ce006ffab616cc8a77e747a633;hpb=4e1481d22b6b473d0f749e8936398c2c229cf3c1 diff --git a/tests/HTTPTest.pm b/tests/HTTPTest.pm old mode 100755 new mode 100644 index f1748659..883213d1 --- a/tests/HTTPTest.pm +++ b/tests/HTTPTest.pm @@ -1,100 +1,54 @@ -#!/usr/bin/perl -w - -use Test; - package HTTPTest; -our @ISA = qw(Test); -$VERSION = 0.01; use strict; +use warnings; use HTTPServer; +use WgetTest; + +our @ISA = qw(WgetTest); +my $VERSION = 0.01; { my %_attr_data = ( # DEFAULT - _urls => {}, - _cmdline => "", - _errcode => 0, - _downloads => {}, ); - - sub _default_for - { - my ($self, $attr) = @_; + + sub _default_for + { + my ($self, $attr) = @_; return $_attr_data{$attr} if exists $_attr_data{$attr}; - return $self->SUPER::_default_for($attr); - } + return $self->SUPER::_default_for($attr); + } - sub _standard_keys - { + sub _standard_keys + { my ($self) = @_; - ($self->SUPER::_standard_keys(), keys %_attr_data); - } -} - - -sub run { - my $self = shift; - - my $pid = fork(); - - if($pid == 0) { - my $server = HTTPServer->new (LocalAddr => 'localhost', - LocalPort => '8080', - ReuseAddr => 1) or die "Cannot create server!!!"; - $server->run ($self->{_urls}); + ($self->SUPER::_standard_keys(), keys %_attr_data); } +} - # print "Spawned HTTP server with pid: $pid\n"; - - # print "Calling $self->{_cmdline}\n"; - my $errcode = system ($self->{_cmdline}); - - kill ('TERM', $pid); - # print "Killed HTTP server\n"; +sub _setup_server { + my $self = shift; + $self->{_server} = HTTPServer->new (LocalAddr => 'localhost', + ReuseAddr => 1) + or die "Cannot create server!!!"; +} - $errcode == $self->{_errcode} - or die "Test failed: wrong code returned (was: $errcode, expected: $self->{_errcode})"; - if (my $error_str = $self->_verify_download()) { - die $error_str; - } +sub _launch_server { + my $self = shift; + my $synch_func = shift; - print "Test successful.\n" + $self->{_server}->run ($self->{_input}, $synch_func); } - -sub _verify_download { +sub _substitute_port { my $self = shift; - - # use slurp mode to read file content - my $old_input_record_separator = $/; - undef $/; - - while (my ($filename, $filedata) = each %{$self->{_downloads}}) { - open (FILE, $filename) - or return "Test failed: file $filename not downloaded"; - - my $content = ; - $content eq $filedata->{'content'} - or return "Test failed: wrong content for file $filename"; - - if (exists($filedata->{'timestamp'})) { - my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, - $atime,$mtime,$ctime,$blksize,$blocks) = stat FILE; - - $mtime == $filedata->{'timestamp'} - or return "Test failed: wrong timestamp for file $filename"; - } - - close (FILE); - } - - $/ = $old_input_record_separator; - - return ""; + my $ret = shift; + $ret =~ s/{{port}}/$self->{_server}->sockport/eg; + return $ret; } 1;