| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
#include "../pyunit.h" |
|---|
| 23 |
#ifdef HAVE_CONFIG_H |
|---|
| 24 |
# include "config.h" |
|---|
| 25 |
#endif |
|---|
| 26 |
|
|---|
| 27 |
#include <vlc/vlc.h> |
|---|
| 28 |
#include "vlc_url.h" |
|---|
| 29 |
|
|---|
| 30 |
typedef char * (*conv_t ) (const char *); |
|---|
| 31 |
|
|---|
| 32 |
PyObject * test (conv_t f, const char *in, const char *out) |
|---|
| 33 |
{ |
|---|
| 34 |
char *res; |
|---|
| 35 |
|
|---|
| 36 |
printf ("\"%s\" -> \"%s\" ?\n", in, out); |
|---|
| 37 |
res = f(in); |
|---|
| 38 |
ASSERT( res != NULL, "NULL result" ); |
|---|
| 39 |
ASSERT( strcmp( res, out ) == NULL, "" ); |
|---|
| 40 |
|
|---|
| 41 |
Py_INCREF( Py_None ); |
|---|
| 42 |
return Py_None; |
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
static inline PyObject * test_decode( const char *in, const char *out) |
|---|
| 46 |
{ |
|---|
| 47 |
return test( decode_URI_duplicate, in, out ); |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
static inline PyObject* test_b64( const char *in, const char *out ) |
|---|
| 51 |
{ |
|---|
| 52 |
return test( vlc_b64_encode, in, out ); |
|---|
| 53 |
} |
|---|
| 54 |
|
|---|
| 55 |
PyObject *url_test( PyObject *self, PyObject *args ) |
|---|
| 56 |
{ |
|---|
| 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", "~"); |
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
DO_TEST_DECODE ("%", "%" ); |
|---|
| 69 |
DO_TEST_DECODE ("%2", "%2"); |
|---|
| 70 |
DO_TEST_DECODE ("%0000", "") |
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 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"); |
|---|
| 76 |
|
|---|
| 77 |
#define DO_TEST_B64( a, b ) if( !test_b64( a, b ) ) return NULL; |
|---|
| 78 |
|
|---|
| 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=="); |
|---|
| 84 |
|
|---|
| 85 |
Py_INCREF( Py_None); |
|---|
| 86 |
return Py_None; |
|---|
| 87 |
} |
|---|