]> git.sesse.net Git - vlc/blob - src/test/url.c
test cases for make_URI()
[vlc] / src / test / url.c
1 /*****************************************************************************
2  * url.c: Test for url encoding/decoding stuff
3  *****************************************************************************
4  * Copyright (C) 2006 Rémi Denis-Courmont
5  * $Id$
6  *
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.
11  *
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.
16  *
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  *****************************************************************************/
21
22 #ifdef HAVE_CONFIG_H
23 # include "config.h"
24 #endif
25
26 #include <vlc_common.h>
27 #include "vlc_url.h"
28 #include "vlc_strings.h"
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <assert.h>
33
34 typedef char * (*conv_t) (const char *);
35
36 static void test (conv_t f, const char *in, const char *out)
37 {
38     char *res;
39
40     printf ("\"%s\" -> \"%s\" ?\n", in, out);
41     res = f (in);
42     if (res == NULL)
43         exit (1);
44
45     if (strcmp (res, out))
46     {
47         printf (" ERROR: got \"%s\"\n", res);
48         exit (2);
49     }
50
51     free (res);
52 }
53
54 static inline void test_decode (const char *in, const char *out)
55 {
56     test (decode_URI_duplicate, in, out);
57 }
58
59 static inline void test_b64 (const char *in, const char *out)
60 {
61     test (vlc_b64_encode, in, out);
62 }
63
64 static inline void test_path (const char *in, const char *out)
65 {
66     test (make_URI, in, out);
67 }
68
69 int main (void)
70 {
71     int val;
72
73     (void)setvbuf (stdout, NULL, _IONBF, 0);
74     test_decode ("this_should_not_be_modified_1234",
75                  "this_should_not_be_modified_1234");
76
77     test_decode ("This+should+be+modified+1234!",
78                  "This should be modified 1234!");
79
80     test_decode ("This%20should%20be%20modified%201234!",
81                  "This should be modified 1234!");
82
83     test_decode ("%7E", "~");
84
85     /* tests with invalid input */
86     test_decode ("%", "%");
87     test_decode ("%2", "%2");
88     test_decode ("%0000", "");
89
90     /* UTF-8 tests */
91     test_decode ("T%C3%a9l%c3%A9vision+%e2%82%Ac", "Télévision €");
92     test_decode ("T%E9l%E9vision", "T?l?vision");
93     test_decode ("%C1%94%C3%a9l%c3%A9vision", "??élévision"); /* overlong */
94
95     /* Base 64 tests */
96     test_b64 ("", "");
97     test_b64 ("f", "Zg==");
98     test_b64 ("fo", "Zm8=");
99     test_b64 ("foo", "Zm9v");
100     test_b64 ("foob", "Zm9vYg==");
101     test_b64 ("fooba", "Zm9vYmE=");
102     test_b64 ("foobar", "Zm9vYmFy");
103
104     /* Path test */
105     test_path ("file:///", "file:///");
106     test_path ("http://www.example.com/%7Ejohn/",
107                "http://www.example.com/%7Ejohn/");
108     test_path ("/", "file:///");
109     test_path ("/home/john/", "file:///home/john/");
110     test_path ("/home/john/music.ogg", "file:///home/john/music.ogg");
111     //test_path ("\\\\server/pub/music.ogg", "file://server/pub/music.ogg");
112
113     /*int fd = open (".", O_RDONLY);
114     assert (fd != -1);*/
115     val = chdir ("/tmp");
116     assert (val != -1);
117     test_path ("movie.ogg", "file:///tmp/movie.ogg");
118     test_path (".", "file:///tmp/.");
119     test_path ("", "file:///tmp/");
120     /*val = fchdir (fd);
121     assert (val != -1);*/
122
123     return 0;
124 }