[vlc-devel] [PATCH 2/4] test/url: make it easier to check invalid URLs

Filip Roséen filip at atch.se
Fri Oct 28 10:49:45 CEST 2016


The previous implementation, somewhat unconditionally, made
assumptions about the internal state of the result of `vlc_UrlParse`,
meaning that it was inherently difficult to check if invalid URLs was
correctly rejected.

These changes simply asserts that vlc_UrlParse failed if all of the
arguments (used to verify the result) are NULL or 0.
---
 src/test/url.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/test/url.c b/src/test/url.c
index ffb073c..3ebc2be 100644
--- a/src/test/url.c
+++ b/src/test/url.c
@@ -106,6 +106,14 @@ static void test_url_parse(const char* in, const char* protocol, const char* use
     vlc_url_t url;
     int ret = vlc_UrlParse(&url, in);
 
+    /* XXX: only checking that the port-part is parsed correctly, and
+     *      equal to 0, is currently not supported due to the below. */
+    if( !protocol && !user && !pass && !host && !i_port && !path && !option )
+    {
+        assert( ret == -1 );
+        return;
+    }
+
     CHECK( url.psz_protocol, protocol );
     CHECK( url.psz_username, user );
     CHECK( url.psz_password, pass );
@@ -300,10 +308,9 @@ int main (void)
     test_url_parse("//example.com/f?o=v", NULL, NULL, NULL, "example.com", 0,
                    "/f", "o=v");
     /* 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);
-    test_url_parse("http://example.com:123xyz", "http", NULL, NULL,
-                   "example.com", 123, NULL, NULL);
+    test_url_parse("p://G a r b a g e", NULL, NULL, NULL, NULL, 0, NULL, NULL);
+    test_url_parse("p://h/G a r b a g e", NULL, NULL, NULL, NULL, 0, NULL, NULL);
+    test_url_parse("http://example.com:123xyz", NULL, NULL, NULL, NULL, 0, NULL, NULL);
 
     /* Reference test cases for reference URI resolution */
     static const char *rfc3986_cases[] =
-- 
2.10.1



More information about the vlc-devel mailing list