]> git.sesse.net Git - vlc/blobdiff - src/test/url.c
Merge branch 'master' of git@git.videolan.org:vlc
[vlc] / src / test / url.c
index fa5299d4ac3e4c4dea1a5ee23851e9d7252e9686..3ae9798140a52fe64f99b280f6cb9f88f872a820 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include <vlc/vlc.h>
 #include "vlc_url.h"
+#include "vlc_strings.h"
 
 #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);
@@ -64,5 +84,14 @@ 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 ("f", "Zg==");
+    test_b64 ("fo", "Zm8=");
+    test_b64 ("foo", "Zm9v");
+    test_b64 ("foob", "Zm9vYg==");
+    test_b64 ("fooba", "Zm9vYmE=");
+    test_b64 ("foobar", "Zm9vYmFy");
+
     return 0;
 }