]> sjero.net Git - wget/commitdiff
[svn] Added testing for -np option.
authormtortonesi <devnull@localhost>
Fri, 10 Nov 2006 11:06:24 +0000 (03:06 -0800)
committermtortonesi <devnull@localhost>
Fri, 10 Nov 2006 11:06:24 +0000 (03:06 -0800)
tests/ChangeLog
tests/HTTPServer.pm
tests/Test-np.px [new file with mode: 0755]

index daaa10fc30d334697bcd4d460297c96bf832079c..618e6563cb6176d6345290dc984be473fb3d14b2 100644 (file)
@@ -1,3 +1,9 @@
+2006-11-10  Mauro Tortonesi  <mauro@ferrara.linux.it>
+
+       * Test-np.px: Added test for -np.
+
+       * HTTPTest.pm: Ignore initial '/' character in requested URLs.
+       
 2006-10-12  Mauro Tortonesi  <mauro@ferrara.linux.it>
 
        * Test1.px: Renamed to Test-noop.px.
index 88224f4f9be1c5b456ba7f2d6478462dc146b3a3..2d56160a16f708558de817fc3084a9f119bbd5c0 100755 (executable)
@@ -29,9 +29,12 @@ sub run {
         print STDERR "Accepted a new connection\n" if $log;
         while (my $req = $con->get_request) {
             my $url_path = $req->url->path;
-            if ($url_path =~ m{/$}) {
+            if ($url_path =~ m{/$}) { # append 'index.html'
                 $url_path .= 'index.html';
             }
+            if ($url_path =~ m{^/}) { # remove trailing '/'
+                $url_path = substr ($url_path, 1);
+            }
             if ($log) {
                 print STDERR "Method: ", $req->method, "\n";
                 print STDERR "Path: ", $url_path, "\n";
diff --git a/tests/Test-np.px b/tests/Test-np.px
new file mode 100755 (executable)
index 0000000..09b77da
--- /dev/null
@@ -0,0 +1,148 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+use HTTPTest;
+
+
+###############################################################################
+
+my $mainpage = <<EOF;
+<html>
+<head>
+  <title>Main Page</title>
+</head>
+<body>
+  <p>
+    Some text and a link to a <a href="http://localhost:8080/firstlevel/secondpage.html">second page</a>.
+  </p>
+</body>
+</html>
+EOF
+
+my $secondpage = <<EOF;
+<html>
+<head>
+  <title>Second Page</title>
+</head>
+<body>
+  <p>
+    Some text and a link to a <a href="http://localhost:8080/firstlevel/lowerlevel/thirdpage.html">third page</a>.
+  </p>
+</body>
+</html>
+EOF
+
+my $thirdpage = <<EOF;
+<html>
+<head>
+  <title>Third Page</title>
+</head>
+<body>
+  <p>
+    Some text and a link to a <a href="http://localhost:8080/higherlevelpage.html">higher level page</a>.
+  </p>
+</body>
+</html>
+EOF
+
+my $fourthpage = <<EOF;
+<html>
+<head>
+  <title>Fourth Page</title>
+</head>
+<body>
+  <p>
+    This page is only linked by the higher level page. Therefore, it should not
+    be downloaded. 
+  </p>
+</body>
+</html>
+EOF
+
+my $higherlevelpage = <<EOF;
+<html>
+<head>
+  <title>Higher Level Page</title>
+</head>
+<body>
+  <p>
+    This page is on a higher level in the URL path hierarchy. Therefore, it
+    should not be downloaded. Wget should not visit the following link to a 
+    <a href="http://localhost:8080/firstlevel/fourthpage.html">fourth page</a>.
+  </p>
+</body>
+</html>
+EOF
+
+# code, msg, headers, content
+my %urls = (
+    'firstlevel/index.html' => {
+        code => "200",
+        msg => "Dontcare",
+        headers => {
+            "Content-type" => "text/html",
+        },
+        content => $mainpage,
+    },
+    'firstlevel/secondpage.html' => {
+        code => "200",
+        msg => "Dontcare",
+        headers => {
+            "Content-type" => "text/html",
+        },
+        content => $secondpage,
+    },
+    'firstlevel/lowerlevel/thirdpage.html' => {
+        code => "200",
+        msg => "Dontcare",
+        headers => {
+            "Content-type" => "text/html",
+        },
+        content => $thirdpage,
+    },
+    'firstlevel/fourthpage.html' => {
+        code => "200",
+        msg => "Dontcare",
+        headers => {
+            "Content-type" => "text/plain",
+        },
+        content => $fourthpage,
+    },
+    'higherlevelpage.html' => {
+        code => "200",
+        msg => "Dontcare",
+        headers => {
+            "Content-type" => "text/plain",
+        },
+        content => $higherlevelpage,
+    },
+);
+
+my $cmdline = "wget -np -nH -r http://localhost:8080/firstlevel/";
+
+my $expected_error_code = 0;
+
+my %expected_downloaded_files = (
+    'firstlevel/index.html' => {
+        content => $mainpage,
+    },
+    'firstlevel/secondpage.html' => {
+        content => $secondpage,
+    },
+    'firstlevel/lowerlevel/thirdpage.html' => {
+        content => $thirdpage,
+    },
+);
+
+###############################################################################
+
+my $the_test = HTTPTest->new (name => "Test-np",
+                              input => \%urls, 
+                              cmdline => $cmdline, 
+                              errcode => $expected_error_code, 
+                              output => \%expected_downloaded_files);
+$the_test->run();
+
+# vim: et ts=4 sw=4
+