]> git.sesse.net Git - vlc/blob - test/native/url.c
Port new URL tests to test/
[vlc] / test / native / 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 #include "../pyunit.h"
23 #include <vlc/vlc.h>
24 #include "vlc_url.h"
25
26 typedef char * (*conv_t ) (const char *);
27
28 PyObject * test (conv_t f, const char *in, const char *out)
29 {
30     char *res;
31
32     printf ("\"%s\" -> \"%s\" ?\n", in, out);
33     res = f(in);
34     ASSERT( res != NULL, "NULL result" );
35     ASSERT( strcmp( res, out ) == NULL, "" );
36
37     Py_INCREF( Py_None );
38     return Py_None;
39 }
40
41 static inline PyObject * test_decode( const char *in, const char *out)
42 {
43     return test( decode_URI_duplicate, in, out );
44 }
45
46 static inline PyObject* test_b64( const char *in, const char *out )
47 {
48     return test( vlc_b64_encode, in, out );
49 }
50
51 PyObject *url_test( PyObject *self, PyObject *args )
52 {
53     printf( "\n" );
54     if( !test_decode ("this_should_not_be_modified_1234",
55                      "this_should_not_be_modified_1234") ) return NULL;
56
57     if( ! test_decode ("This+should+be+modified+1234!",
58                  "This should be modified 1234!") ) return NULL;;
59
60     if( !test_decode ("This%20should%20be%20modified%201234!",
61                  "This should be modified 1234!")) return NULL;;
62
63     if( ! test_decode ("%7E", "~")) return NULL;;
64
65     /* tests with invalid input */
66     if(!test_decode ("%", "%")) return NULL;;
67     if(!test_decode ("%2", "%2")) return NULL;;
68     if(!test_decode ("%0000", "")) return NULL;;
69
70     /* UTF-8 tests */
71     if(!test_decode ("T%C3%a9l%c3%A9vision+%e2%82%Ac",
72                       "Télévision €" ) ) return NULL;
73     if(!test_decode ("T%E9l%E9vision", "T?l?vision")) return NULL;
74     if(!test_decode ("%C1%94%C3%a9l%c3%A9vision",
75                          "??élévision") ) return NULL; /* overlong */
76
77     /* Base 64 tests */
78     test_b64 ("", "");
79     test_b64 ("d", "ZA==");
80     test_b64 ("ab", "YQG=");
81     test_b64 ("abc", "YQGI");
82     test_b64 ("abcd", "YQGIZA==");
83
84     Py_INCREF( Py_None);
85     return Py_None;
86 }