[vlc-commits] url: add some tests for vlc_uri_fixup()

Rémi Denis-Courmont git at videolan.org
Sat Oct 15 11:15:29 CEST 2016


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Oct 15 12:14:02 2016 +0300| [0ba278cae7fffaf8d9c8abb4aa34fce2c38826cb] | committer: Rémi Denis-Courmont

url: add some tests for vlc_uri_fixup()

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=0ba278cae7fffaf8d9c8abb4aa34fce2c38826cb
---

 src/test/url.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/src/test/url.c b/src/test/url.c
index bc515cf..01d18ce 100644
--- a/src/test/url.c
+++ b/src/test/url.c
@@ -133,6 +133,20 @@ static void test_rfc3986(const char *reference, const char *expected)
     test_url_resolve("http://a/b/c/d;p?q", reference, expected);
 }
 
+static void test_fixup_noop(const char *expected)
+{
+    fprintf(stderr, "\"%s\" -> \"%s\" ?\n", expected, expected);
+
+    char *result = vlc_uri_fixup(expected);
+    assert(result != NULL);
+    if (strcmp(result, expected))
+    {
+        fprintf(stderr, " ERROR: got \"%s\"\n", result);
+        abort();
+    }
+    free(result);
+}
+
 int main (void)
 {
     int val;
@@ -322,5 +336,26 @@ int main (void)
     for (size_t i = 0; i < ARRAY_SIZE(rfc3986_cases); i += 2)
         test_rfc3986(rfc3986_cases[i], rfc3986_cases[i + 1]);
 
+    /* Check that fixup does not mangle valid URIs */
+    static const char *valid_uris[] =
+    {
+        "#href", "?opt=val",
+        ".", "..", "/", "../../dir/subdir/subsubdir/file.ext",
+        "//example.com?q=info",
+        "//192.0.2.1/index.html",
+        "//[2001:db8::1]/index.html",
+        "https://www.example.com:8443/?opt1=val1&opt2=val2",
+        "https://192.0.2.1:8443/#foobar",
+        "https://[2001:db8::1]:8443/file?opt=val#foobar",
+        "https://[v9.abcd:efgh]:8443/welcome?to=the#future",
+        "mailto:john at example.com",
+        "mailto:mailman at example.com?subject=help",
+        "mailto:mailman at example.com?body=subscribe%20news-flash",
+        "mailto:literal@[192.0.2.1],literal@[IPv6:2001:db8::1]",
+    };
+
+    for (size_t i = 0; i < ARRAY_SIZE(valid_uris); i++)
+        test_fixup_noop(valid_uris[i]);
+
     return 0;
 }



More information about the vlc-commits mailing list