]> git.sesse.net Git - vlc/blob - test/native/url.c
Rework dicts as macros for type-independance
[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 #define DO_TEST_DECODE( a, b ) if( !test_decode( a, b) ) return NULL;
55      DO_TEST_DECODE ("this_should_not_be_modified_1234",
56                      "this_should_not_be_modified_1234");
57      DO_TEST_DECODE ("This+should+be+modified+1234!",
58                  "This should be modified 1234!");
59      DO_TEST_DECODE ("This%20should%20be%20modified%201234!",
60                  "This should be modified 1234!");
61      DO_TEST_DECODE ("%7E", "~");
62
63     /* tests with invalid input */
64     DO_TEST_DECODE ("%", "%" );
65     DO_TEST_DECODE ("%2", "%2");
66     DO_TEST_DECODE ("%0000", "")
67
68     /* UTF-8 tests */
69     DO_TEST_DECODE ("T%C3%a9l%c3%A9vision+%e2%82%Ac", "Télévision €" );
70     DO_TEST_DECODE ("T%E9l%E9vision", "T?l?vision");
71     DO_TEST_DECODE ("%C1%94%C3%a9l%c3%A9vision",  "??élévision");
72
73 #define DO_TEST_B64( a, b ) if( !test_b64( a, b ) ) return NULL;
74     /* Base 64 tests */
75     DO_TEST_B64 ("", "") ;
76     DO_TEST_B64("d", "ZA==");
77     DO_TEST_B64("ab", "YWI=");
78     DO_TEST_B64("abc", "YWJj");
79     DO_TEST_B64 ("abcd", "YWJjZA==");
80
81     Py_INCREF( Py_None);
82     return Py_None;
83 }