[vlc-commits] uri: test cases for vlc_uri_resolve()

Rémi Denis-Courmont git at videolan.org
Sun Jul 17 16:13:57 CEST 2016


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Jul 17 16:28:57 2016 +0300| [833d3e9790a6fcc0215ed7b9d390e7a71117f5f9] | committer: Rémi Denis-Courmont

uri: test cases for vlc_uri_resolve()

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

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

diff --git a/src/test/url.c b/src/test/url.c
index 7710dcb..7846de5 100644
--- a/src/test/url.c
+++ b/src/test/url.c
@@ -113,6 +113,26 @@ static void test_url_parse(const char* in, const char* protocol, const char* use
 #undef CHECK
 }
 
+static void test_url_resolve(const char *base, const char *reference,
+                             const char *expected)
+{
+    fprintf(stderr, "(%s) \"%s\" -> \"%s\" ?\n", base, reference, expected);
+
+    char *result = vlc_uri_resolve(base, reference);
+    assert(result != NULL);
+    if (strcmp(result, expected))
+    {
+        fprintf(stderr, " ERROR: got \"%s\"\n", result);
+        abort();
+    }
+    free(result);
+}
+
+static void test_rfc3986(const char *reference, const char *expected)
+{
+    test_url_resolve("http://a/b/c/d;p?q", reference, expected);
+}
+
 int main (void)
 {
     int val;
@@ -246,5 +266,59 @@ int main (void)
     /* Invalid URIs */
     test_url_parse("p://G a r b a g e", "p", NULL, NULL, NULL, 0, NULL, NULL);
     test_url_parse("p://h/G a r b a g e", "p", NULL, NULL, "h", 0, NULL, NULL);
+
+    /* Reference test cases for reference URI resolution */
+    static const char *rfc3986_cases[] =
+    {
+        "g:h",           "g:h",
+        "g",             "http://a/b/c/g",
+        "./g",           "http://a/b/c/g",
+        "g/",            "http://a/b/c/g/",
+        "/g",            "http://a/g",
+        "//g",           "http://g",
+        "?y",            "http://a/b/c/d;p?y",
+        "g?y",           "http://a/b/c/g?y",
+        //"#s",            "http://a/b/c/d;p?q#s",
+        //"g#s",           "http://a/b/c/g#s",
+        //"g?y#s",         "http://a/b/c/g?y#s",
+        ";x",            "http://a/b/c/;x",
+        "g;x",           "http://a/b/c/g;x",
+        //"g;x?y#s",       "http://a/b/c/g;x?y#s",
+        "",              "http://a/b/c/d;p?q",
+        ".",             "http://a/b/c/",
+        "./",            "http://a/b/c/",
+        "..",            "http://a/b/",
+        "../",           "http://a/b/",
+        "../g",          "http://a/b/g",
+        "../..",         "http://a/",
+        "../../",        "http://a/",
+        "../../g",       "http://a/g",
+
+        "../../../g",    "http://a/g",
+        "../../../../g", "http://a/g",
+
+        "/./g",          "http://a/g",
+        "/../g",         "http://a/g",
+        "g.",            "http://a/b/c/g.",
+        ".g",            "http://a/b/c/.g",
+        "g..",           "http://a/b/c/g..",
+        "..g",           "http://a/b/c/..g",
+
+        "./../g",        "http://a/b/g",
+        "./g/.",         "http://a/b/c/g/",
+        "g/./h",         "http://a/b/c/g/h",
+        "g/../h",        "http://a/b/c/h",
+        "g;x=1/./y",     "http://a/b/c/g;x=1/y",
+        "g;x=1/../y",    "http://a/b/c/y",
+
+        "g?y/./x",       "http://a/b/c/g?y/./x",
+        "g?y/../x",      "http://a/b/c/g?y/../x",
+        //"g#s/./x",       "http://a/b/c/g#s/./x",
+        //"g#s/../x",      "http://a/b/c/g#s/../x",
+    };
+
+    for (size_t i = 0; i < ARRAY_SIZE(rfc3986_cases); i += 2)
+        test_rfc3986(rfc3986_cases[i], rfc3986_cases[i + 1]);
+
     return 0;
 }



More information about the vlc-commits mailing list