1 /*****************************************************************************
2 * url.c: Test for url encoding/decoding stuff
3 *****************************************************************************
4 * Copyright (C) 2006 Rémi Denis-Courmont
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
20 *****************************************************************************/
26 #include <vlc_common.h>
28 #include "vlc_strings.h"
34 typedef char * (*conv_t) (const char *);
36 static void test (conv_t f, const char *in, const char *out)
40 printf ("\"%s\" -> \"%s\" ?\n", in, out);
45 if (strcmp (res, out))
47 printf (" ERROR: got \"%s\"\n", res);
54 static inline void test_decode (const char *in, const char *out)
56 test (decode_URI_duplicate, in, out);
59 static inline void test_b64 (const char *in, const char *out)
61 test (vlc_b64_encode, in, out);
64 static inline void test_path (const char *in, const char *out)
66 test (make_URI, in, out);
69 static inline void test_current_directory_path (const char *in, const char *cwd, const char *out)
71 char * expected_result = NULL;
72 int val = asprintf(&expected_result, "file://%s/%s", cwd, out);
75 test (make_URI, in, expected_result);
82 (void)setvbuf (stdout, NULL, _IONBF, 0);
83 test_decode ("this_should_not_be_modified_1234",
84 "this_should_not_be_modified_1234");
86 test_decode ("This+should+be+modified+1234!",
87 "This should be modified 1234!");
89 test_decode ("This%20should%20be%20modified%201234!",
90 "This should be modified 1234!");
92 test_decode ("%7E", "~");
94 /* tests with invalid input */
95 test_decode ("%", "%");
96 test_decode ("%2", "%2");
97 test_decode ("%0000", "");
100 test_decode ("T%C3%a9l%c3%A9vision+%e2%82%Ac", "Télévision €");
101 test_decode ("T%E9l%E9vision", "T?l?vision");
102 test_decode ("%C1%94%C3%a9l%c3%A9vision", "??élévision"); /* overlong */
106 test_b64 ("f", "Zg==");
107 test_b64 ("fo", "Zm8=");
108 test_b64 ("foo", "Zm9v");
109 test_b64 ("foob", "Zm9vYg==");
110 test_b64 ("fooba", "Zm9vYmE=");
111 test_b64 ("foobar", "Zm9vYmFy");
114 test_path ("file:///", "file:///");
115 test_path ("http://www.example.com/%7Ejohn/",
116 "http://www.example.com/%7Ejohn/");
117 test_path ("/", "file:///");
118 test_path ("/home/john/", "file:///home/john/");
119 test_path ("/home/john/music.ogg", "file:///home/john/music.ogg");
120 test_path ("\\\\server/pub/music.ogg", "smb://server/pub/music.ogg");
121 test_path ("\\\\server\\pub\\music.ogg", "smb://server/pub/music.ogg");
123 /*int fd = open (".", O_RDONLY);
125 val = chdir ("/tmp");
130 tmpdir = getcwd(buf, sizeof(buf)/sizeof(*buf));
133 test_current_directory_path ("movie.ogg", tmpdir, "movie.ogg");
134 test_current_directory_path (".", tmpdir, ".");
135 test_current_directory_path ("", tmpdir, "");
138 assert (val != -1);*/