]> git.sesse.net Git - vlc/blob - test/native/url.c
Fix and port 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     printf( "\n\"%s\"\n",res );
36     ASSERT( strcmp( res, out ) == NULL, "" );
37
38     Py_INCREF( Py_None );
39     return Py_None;
40 }
41
42 static inline PyObject * test_decode( const char *in, const char *out)
43 {
44     return test( decode_URI_duplicate, in, out );
45 }
46
47 static inline PyObject* test_b64( const char *in, const char *out )
48 {
49     return test( vlc_b64_encode, in, out );
50 }
51
52 PyObject *url_test( PyObject *self, PyObject *args )
53 {
54     printf( "\n" );
55 #define DO_TEST_DECODE( a, b ) if( !test_decode( a, b) ) return NULL;
56      DO_TEST_DECODE ("this_should_not_be_modified_1234",
57                      "this_should_not_be_modified_1234");
58      DO_TEST_DECODE ("This+should+be+modified+1234!",
59                  "This should be modified 1234!");
60      DO_TEST_DECODE ("This%20should%20be%20modified%201234!",
61                  "This should be modified 1234!");
62      DO_TEST_DECODE ("%7E", "~");
63
64     /* tests with invalid input */
65     DO_TEST_DECODE ("%", "%" );
66     DO_TEST_DECODE ("%2", "%2");
67     DO_TEST_DECODE ("%0000", "")
68
69     /* UTF-8 tests */
70     DO_TEST_DECODE ("T%C3%a9l%c3%A9vision+%e2%82%Ac", "Télévision €" );
71     DO_TEST_DECODE ("T%E9l%E9vision", "T?l?vision");
72     DO_TEST_DECODE ("%C1%94%C3%a9l%c3%A9vision",  "??élévision");
73
74 #define DO_TEST_B64( a, b ) if( !test_b64( a, b ) ) return NULL;
75     /* Base 64 tests */
76     DO_TEST_B64 ("", "") ;
77     DO_TEST_B64("d", "ZA==");
78     DO_TEST_B64("ab", "YWI=");
79     DO_TEST_B64("abc", "YWJj");
80     DO_TEST_B64 ("abcd", "YWJjZA==");
81
82     Py_INCREF( Py_None);
83     return Py_None;
84 }