]> git.sesse.net Git - vlc/commitdiff
Additionnal unit test for decode_URI
authorRémi Denis-Courmont <rem@videolan.org>
Tue, 11 Apr 2006 15:47:52 +0000 (15:47 +0000)
committerRémi Denis-Courmont <rem@videolan.org>
Tue, 11 Apr 2006 15:47:52 +0000 (15:47 +0000)
src/test/url.c

index 61df8475a5c1d0cddcd1216daff20c677f48aa1d..5bf33bad6d161f0ddc4bc2073577dbcb50e74d94 100644 (file)
 #include <vlc/vlc.h>
 #include "vlc_url.h"
 
-#undef NDEBUG
-#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+void test_decode (const char *in, const char *out)
+{
+    char *res;
+
+    printf ("\"%s\" -> \"%s\" ?\n", in, out);
+    res = decode_URI_duplicate (in);
+    if (res == NULL)
+        exit (1);
+
+    if (strcmp (res, out))
+        exit (2);
+
+    free (res);
+}
 
 int main (void)
 {
-    const char url1[] = "this_should_not_be_modified_1234";
-    const char url2[] = "This+should+be+modified+1234!";
-    const char url3[] = "This%20should%20be%20modified%201234!";
-
-    char *durl = decode_URI_duplicate (url1);
-    assert (durl != NULL);
-    assert (!strcmp (durl, url1));
-    free (durl);
-
-    durl = decode_URI_duplicate (url2);
-    assert (durl != NULL);
-    assert (!strcmp (durl, "This should be modified 1234!"));
-    free (durl);
-
-    durl = decode_URI_duplicate (url3);
-    assert (durl != NULL);
-    assert (!strcmp (durl, "This should be modified 1234!"));
-    free (durl);
+    (void)setvbuf (stdout, NULL, _IONBF, 0);
+    test_decode ("this_should_not_be_modified_1234",
+                 "this_should_not_be_modified_1234");
+
+    test_decode ("This+should+be+modified+1234!",
+                 "This should be modified 1234!");
+
+    test_decode ("This%20should%20be%20modified%201234!",
+                 "This should be modified 1234!");
+
+    /* tests with invalid input */
+    test_decode ("%", "%");
+    test_decode ("%2", "%2");
+    test_decode ("%0000", "");
+
+    /* UTF-8 tests */
+    test_decode ("T%C3%a9l%c3%A9vision", "Télévision");
+    test_decode ("T%E9l%E9vision", "T?l?vision");
 
     return 0;
 }