break
[vlc/multisubs.git] / test / native / url.c
blob53ed5eada32adcd94d1184a831ef4878affecf70
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 #include "../pyunit.h"
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
27 #include <vlc/vlc.h>
28 #include "vlc_url.h"
30 typedef char * (*conv_t ) (const char *);
32 PyObject * test (conv_t f, const char *in, const char *out)
34 char *res;
36 printf ("\"%s\" -> \"%s\" ?\n", in, out);
37 res = f(in);
38 ASSERT( res != NULL, "NULL result" );
39 ASSERT( strcmp( res, out ) == NULL, "" );
41 Py_INCREF( Py_None );
42 return Py_None;
45 static inline PyObject * test_decode( const char *in, const char *out)
47 return test( decode_URI_duplicate, in, out );
50 static inline PyObject* test_b64( const char *in, const char *out )
52 return test( vlc_b64_encode, in, out );
55 PyObject *url_test( PyObject *self, PyObject *args )
57 printf( "\n" );
58 #define DO_TEST_DECODE( a, b ) if( !test_decode( a, b) ) return NULL;
59 DO_TEST_DECODE ("this_should_not_be_modified_1234",
60 "this_should_not_be_modified_1234");
61 DO_TEST_DECODE ("This+should+be+modified+1234!",
62 "This should be modified 1234!");
63 DO_TEST_DECODE ("This%20should%20be%20modified%201234!",
64 "This should be modified 1234!");
65 DO_TEST_DECODE ("%7E", "~");
67 /* tests with invalid input */
68 DO_TEST_DECODE ("%", "%" );
69 DO_TEST_DECODE ("%2", "%2");
70 DO_TEST_DECODE ("%0000", "")
72 /* UTF-8 tests */
73 DO_TEST_DECODE ("T%C3%a9l%c3%A9vision+%e2%82%Ac", "Télévision €" );
74 DO_TEST_DECODE ("T%E9l%E9vision", "T?l?vision");
75 DO_TEST_DECODE ("%C1%94%C3%a9l%c3%A9vision", "??élévision");
77 #define DO_TEST_B64( a, b ) if( !test_b64( a, b ) ) return NULL;
78 /* Base 64 tests */
79 DO_TEST_B64 ("", "") ;
80 DO_TEST_B64("d", "ZA==");
81 DO_TEST_B64("ab", "YWI=");
82 DO_TEST_B64("abc", "YWJj");
83 DO_TEST_B64 ("abcd", "YWJjZA==");
85 Py_INCREF( Py_None);
86 return Py_None;