From db115bfece264d66e0f61e4b3fb492a0dc188d58 Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Sun, 9 Sep 2007 19:15:57 +0300 Subject: [PATCH] Add tests for cwd-relative file URIs. Test 6 currently fails. --- src/protocol/test/test-get-translated-uri | 55 +++++++++++++++++++++++ src/protocol/test/uri-test.c | 5 +++ 2 files changed, 60 insertions(+) create mode 100755 src/protocol/test/test-get-translated-uri diff --git a/src/protocol/test/test-get-translated-uri b/src/protocol/test/test-get-translated-uri new file mode 100755 index 00000000..77d89771 --- /dev/null +++ b/src/protocol/test/test-get-translated-uri @@ -0,0 +1,55 @@ +#! /bin/sh + +test_description='Test URI translation' + +. "$TEST_LIB" + +test_uri_translation () { + before="$1"; shift + cwd="$1"; shift + translated="$(uri-test "$before" "$cwd")" + cond="" + for expected; do + cond="${cond:+$cond || +}test \"$translated\" = \"$expected\"" + done + + test_expect_success "Translate $before in $cwd" "$cond" +} + +################################################################ + +# RFC 1738 section 3.10 says "localhost" and "" as mean +# the same thing. So we disregard the spelling in these tests. + +test_uri_translation "/usr/bin/elinks" "/srv/git" \ + "file://localhost/usr/bin/elinks" \ + "file:///usr/bin/elinks" + +test_uri_translation "index.html" "/var/www" \ + "file://localhost/var/www/index.html" \ + "file:///var/www/index.html" + +test_uri_translation "../" "/usr/share/doc" \ + "file://localhost/usr/share/" \ + "file:///usr/share/" + +test_uri_translation "../../lib/libc.so" "/usr/include/rpc" \ + "file://localhost/usr/lib/libc.so" \ + "file:///usr/lib/libc.so" + +test_uri_translation "etc/issue" "/" \ + "file://localhost/etc/issue" \ + "file:///etc/issue" + +# SUSv2: "A pathname that begins with two successive slashes may be +# interpreted in an implementation-defined manner." Domain/OS and +# Cygwin are said to do so. +test_uri_translation "apollo_logo" "//melchior/sys" \ + "file://melchior/sys/apollo_logo" \ + "file://localhost//melchior/sys/apollo_logo" \ + "file://localhost/%2Fmelchior/sys/apollo_logo" \ + "file:////melchior/sys/apollo_logo" \ + "file:///%2Fmelchior/sys/apollo_logo" + +test_done diff --git a/src/protocol/test/uri-test.c b/src/protocol/test/uri-test.c index c1bb40e7..8681bfd2 100644 --- a/src/protocol/test/uri-test.c +++ b/src/protocol/test/uri-test.c @@ -16,6 +16,11 @@ main(int argc, char **argv) * taking arguments like --normalize-uri= etc. */ if (argc == 2) { fprintf(stdout, "%s\n", normalize_uri(NULL, argv[1])); + } else if (argc == 3) { + struct uri *translated = get_translated_uri(argv[1], argv[2]); + if (translated == NULL) + return EXIT_FAILURE; + fprintf(stdout, "%s\n", struri(translated)); } return 0; }