X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=test%2Fnative%2Furl.c;h=53ed5eada32adcd94d1184a831ef4878affecf70;hb=be017fb2905530b0895b7158464b3f45a0d29356;hp=e43896ecf5a8140ca5c3a6958c14945286478fee;hpb=0fbf13c30976400ed00ccf72ce8d7c84c981d628;p=vlc diff --git a/test/native/url.c b/test/native/url.c index e43896ecf5..53ed5eada3 100644 --- a/test/native/url.c +++ b/test/native/url.c @@ -20,50 +20,67 @@ *****************************************************************************/ #include "../pyunit.h" +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include "vlc_url.h" -PyObject * test_decode (const char *in, const char *out) +typedef char * (*conv_t ) (const char *); + +PyObject * test (conv_t f, const char *in, const char *out) { char *res; printf ("\"%s\" -> \"%s\" ?\n", in, out); - res = decode_URI_duplicate (in); - ASSERT( res != NULL, "" ); - if (res == NULL) - exit (1); - + res = f(in); + ASSERT( res != NULL, "NULL result" ); ASSERT( strcmp( res, out ) == NULL, "" ); Py_INCREF( Py_None ); return Py_None; } -PyObject *url_decode_test( PyObject *self, PyObject *args ) +static inline PyObject * test_decode( const char *in, const char *out) { - printf( "\n" ); - if( !test_decode ("this_should_not_be_modified_1234", - "this_should_not_be_modified_1234") ) return NULL; - - if( ! test_decode ("This+should+be+modified+1234!", - "This should be modified 1234!") ) return NULL;; + return test( decode_URI_duplicate, in, out ); +} - if( !test_decode ("This%20should%20be%20modified%201234!", - "This should be modified 1234!")) return NULL;; +static inline PyObject* test_b64( const char *in, const char *out ) +{ + return test( vlc_b64_encode, in, out ); +} - if( ! test_decode ("%7E", "~")) return NULL;; +PyObject *url_test( PyObject *self, PyObject *args ) +{ + printf( "\n" ); +#define DO_TEST_DECODE( a, b ) if( !test_decode( a, b) ) return NULL; + DO_TEST_DECODE ("this_should_not_be_modified_1234", + "this_should_not_be_modified_1234"); + DO_TEST_DECODE ("This+should+be+modified+1234!", + "This should be modified 1234!"); + DO_TEST_DECODE ("This%20should%20be%20modified%201234!", + "This should be modified 1234!"); + DO_TEST_DECODE ("%7E", "~"); /* tests with invalid input */ - if(!test_decode ("%", "%")) return NULL;; - if(!test_decode ("%2", "%2")) return NULL;; - if(!test_decode ("%0000", "")) return NULL;; + DO_TEST_DECODE ("%", "%" ); + DO_TEST_DECODE ("%2", "%2"); + DO_TEST_DECODE ("%0000", "") /* UTF-8 tests */ - if(!test_decode ("T%C3%a9l%c3%A9vision+%e2%82%Ac", - "Télévision €" ) ) return NULL; - if(!test_decode ("T%E9l%E9vision", "T?l?vision")) return NULL; - if(!test_decode ("%C1%94%C3%a9l%c3%A9vision", - "??élévision") ) return NULL; /* overlong */ + DO_TEST_DECODE ("T%C3%a9l%c3%A9vision+%e2%82%Ac", "Télévision €" ); + DO_TEST_DECODE ("T%E9l%E9vision", "T?l?vision"); + DO_TEST_DECODE ("%C1%94%C3%a9l%c3%A9vision", "??élévision"); + +#define DO_TEST_B64( a, b ) if( !test_b64( a, b ) ) return NULL; + /* Base 64 tests */ + DO_TEST_B64 ("", "") ; + DO_TEST_B64("d", "ZA=="); + DO_TEST_B64("ab", "YWI="); + DO_TEST_B64("abc", "YWJj"); + DO_TEST_B64 ("abcd", "YWJjZA=="); Py_INCREF( Py_None); return Py_None;