Change %d into %PRId64
[vlc/asuraparaju-public.git] / src / test / url.c
blob20849866305616cb146fc9540fde642b2f43a182
1 /*****************************************************************************
2 * url.c: Test for url encoding/decoding stuff
3 *****************************************************************************
4 * Copyright (C) 2006 Rémi Denis-Courmont
5 * $Id$
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 *****************************************************************************/
22 #ifdef HAVE_CONFIG_H
23 # include "config.h"
24 #endif
26 #include <vlc_common.h>
27 #include "vlc_url.h"
28 #include "vlc_strings.h"
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <assert.h>
34 typedef char * (*conv_t) (const char *);
36 static void test (conv_t f, const char *in, const char *out)
38 char *res;
40 if (out != NULL)
41 printf ("\"%s\" -> \"%s\" ?\n", in, out);
42 else
43 printf ("\"%s\" -> NULL ?\n", in);
44 res = f (in);
45 if (res == NULL)
47 if (out == NULL)
48 return; /* good: NULL -> NULL */
49 puts (" ERROR: got NULL");
50 exit (2);
52 if (out == NULL || strcmp (res, out))
54 printf (" ERROR: got \"%s\"\n", res);
55 exit (2);
58 free (res);
61 static inline void test_decode (const char *in, const char *out)
63 test (decode_URI_duplicate, in, out);
66 static inline void test_b64 (const char *in, const char *out)
68 test (vlc_b64_encode, in, out);
71 static char *make_URI_def (const char *in)
73 return make_URI (in, NULL);
76 static inline void test_path (const char *in, const char *out)
78 test (make_URI_def, in, out);
81 static inline void test_current_directory_path (const char *in, const char *cwd, const char *out)
83 char * expected_result = NULL;
84 int val = asprintf(&expected_result, "file://%s/%s", cwd, out);
85 assert (val != -1);
87 test (make_URI_def, in, expected_result);
90 int main (void)
92 int val;
94 (void)setvbuf (stdout, NULL, _IONBF, 0);
95 test_decode ("this_should_not_be_modified_1234",
96 "this_should_not_be_modified_1234");
98 test_decode ("This%20should%20be%20modified%201234!",
99 "This should be modified 1234!");
101 test_decode ("%7E", "~");
103 /* tests with invalid input */
104 test_decode ("%", "%");
105 test_decode ("%2", "%2");
106 test_decode ("%0000", "");
108 /* Non-ASCII tests */
109 test_decode ("T%C3%a9l%c3%A9vision %e2%82%Ac", "Télévision €");
110 test_decode ("T%E9l%E9vision", "T\xe9l\xe9vision");
112 /* Base 64 tests */
113 test_b64 ("", "");
114 test_b64 ("f", "Zg==");
115 test_b64 ("fo", "Zm8=");
116 test_b64 ("foo", "Zm9v");
117 test_b64 ("foob", "Zm9vYg==");
118 test_b64 ("fooba", "Zm9vYmE=");
119 test_b64 ("foobar", "Zm9vYmFy");
121 /* Path test */
122 test_path ("file:///", "file:///");
123 test_path ("http://www.example.com/%7Ejohn/",
124 "http://www.example.com/%7Ejohn/");
125 test_path ("/", "file:///");
126 test_path ("/home/john/", "file:///home/john/");
127 test_path ("/home/john/music.ogg", "file:///home/john/music.ogg");
128 test_path ("\\\\server/pub/music.ogg", "smb://server/pub/music.ogg");
129 test_path ("\\\\server\\pub\\music.ogg", "smb://server/pub/music.ogg");
130 test_path ("\\\\server", "smb://server");
132 /*int fd = open (".", O_RDONLY);
133 assert (fd != -1);*/
134 val = chdir ("/tmp");
135 assert (val != -1);
137 char buf[256];
138 char * tmpdir;
139 tmpdir = getcwd(buf, sizeof(buf)/sizeof(*buf));
140 assert (tmpdir);
142 test_current_directory_path ("movie.ogg", tmpdir, "movie.ogg");
143 test_current_directory_path (".", tmpdir, ".");
144 test_current_directory_path ("", tmpdir, "");
146 /*val = fchdir (fd);
147 assert (val != -1);*/
149 /* URI to path tests */
150 #define test( a, b ) test (make_path, a, b)
151 test ("mailto:john@example.com", NULL);
152 test ("http://www.example.com/file.html#ref", NULL);
153 test ("file://", NULL);
154 test ("file:///", "/");
155 test ("file://localhost/home/john/music%2Eogg", "/home/john/music.ogg");
156 test ("file://localhost/home/john/text#ref", "/home/john/text");
157 test ("fd://0foobar", NULL);
158 test ("fd://0#ref", "/dev/stdin");
159 test ("fd://1", "/dev/stdout");
160 test ("fd://12345", "/dev/fd/12345");
161 #undef test
163 return 0;