]> sjero.net Git - wget/blobdiff - tests/HTTPTest.pm
[svn] Major improvement of testing suite.
[wget] / tests / HTTPTest.pm
index f17486596c42cfc540462a7b13944de7c47b7a09..20e9442f01692bfff03e8a6a16f9ca41590360b9 100755 (executable)
@@ -1,22 +1,18 @@
 #!/usr/bin/perl -w
 
-use Test;
-
 package HTTPTest;
-our @ISA = qw(Test);
-$VERSION = 0.01;
 
 use strict;
 
 use HTTPServer;
+use Test;
+
+our @ISA = qw(Test);
+my $VERSION = 0.01;
 
 
 {
     my %_attr_data = ( # DEFAULT
-        _urls         => {},
-        _cmdline      => "",
-        _errcode      => 0,
-        _downloads    => {},
     );
     
        sub _default_for
@@ -34,67 +30,16 @@ use HTTPServer;
 }
     
 
-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});
-    }
-
-    # print "Spawned HTTP server with pid: $pid\n"; 
-
-    # print "Calling $self->{_cmdline}\n";
-    my $errcode = system ($self->{_cmdline});
+sub _setup_server {}
 
-    kill ('TERM', $pid);
 
-    # print "Killed HTTP server\n";
-
-    $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;
-    }
-
-    print "Test successful.\n"
-}
-
-
-sub _verify_download {    
+sub _launch_server {
     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 = <FILE>;
-        $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 $server = HTTPServer->new (LocalAddr => 'localhost',
+                                  LocalPort => '8080',
+                                  ReuseAddr => 1) or die "Cannot create server!!!";
+    $server->run ($self->{_input});
 }
 
 1;