]> git.sesse.net Git - vlc/blobdiff - src/test/url.c
*Really* fix base 64 encoding
[vlc] / src / test / url.c
index 2e2e26b0ff6ca2ca5b510824d2d4d15ed434982b..df8961704d8159a6f9e2857a4b2349fd22556b80 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 
-void test_decode (const char *in, const char *out)
+typedef char * (*conv_t) (const char *);
+
+static void test (conv_t f, const char *in, const char *out)
 {
     char *res;
 
     printf ("\"%s\" -> \"%s\" ?\n", in, out);
-    res = decode_URI_duplicate (in);
+    res = f (in);
     if (res == NULL)
         exit (1);
 
     if (strcmp (res, out))
+    {
+        printf (" ERROR: got \"%s\"\n", res);
         exit (2);
+    }
 
     free (res);
 }
 
+static inline void test_decode (const char *in, const char *out)
+{
+    test (decode_URI_duplicate, in, out);
+}
+
+static inline void test_b64 (const char *in, const char *out)
+{
+    test (vlc_b64_encode, in, out);
+}
+
 int main (void)
 {
     (void)setvbuf (stdout, NULL, _IONBF, 0);
@@ -52,6 +67,8 @@ int main (void)
     test_decode ("This%20should%20be%20modified%201234!",
                  "This should be modified 1234!");
 
+    test_decode ("%7E", "~");
+
     /* tests with invalid input */
     test_decode ("%", "%");
     test_decode ("%2", "%2");
@@ -62,5 +79,12 @@ int main (void)
     test_decode ("T%E9l%E9vision", "T?l?vision");
     test_decode ("%C1%94%C3%a9l%c3%A9vision", "??élévision"); /* overlong */
 
+    /* Base 64 tests */
+    test_b64 ("", "");
+    test_b64 ("d", "ZA==");
+    test_b64 ("ab", "YWI=");
+    test_b64 ("abc", "YWJj");
+    test_b64 ("abcd", "YWJjZA==");
+
     return 0;
 }