1
mirror of https://code.videolan.org/videolan/vlc synced 2024-10-11 06:21:30 +02:00
vlc/test/native/url.c

84 lines
2.8 KiB
C
Raw Normal View History

2006-04-14 16:16:46 +02:00
/*****************************************************************************
* url.c: Test for url encoding/decoding stuff
*****************************************************************************
* Copyright (C) 2006 Rémi Denis-Courmont
2006-07-29 15:32:12 +02:00
* $Id$
2006-04-14 16:16:46 +02:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
2006-04-14 16:25:26 +02:00
#include "../pyunit.h"
2006-04-14 16:16:46 +02:00
#include <vlc/vlc.h>
#include "vlc_url.h"
typedef char * (*conv_t ) (const char *);
PyObject * test (conv_t f, const char *in, const char *out)
2006-04-14 16:16:46 +02:00
{
char *res;
printf ("\"%s\" -> \"%s\" ?\n", in, out);
res = f(in);
ASSERT( res != NULL, "NULL result" );
2006-04-14 16:16:46 +02:00
ASSERT( strcmp( res, out ) == NULL, "" );
Py_INCREF( Py_None );
return Py_None;
}
static inline PyObject * test_decode( const char *in, const char *out)
{
return test( decode_URI_duplicate, in, out );
}
static inline PyObject* test_b64( const char *in, const char *out )
{
return test( vlc_b64_encode, in, out );
}
PyObject *url_test( PyObject *self, PyObject *args )
2006-04-14 16:16:46 +02:00
{
printf( "\n" );
2006-08-30 19:40:36 +02:00
#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", "~");
2006-04-14 16:16:46 +02:00
/* tests with invalid input */
2006-08-30 19:40:36 +02:00
DO_TEST_DECODE ("%", "%" );
DO_TEST_DECODE ("%2", "%2");
DO_TEST_DECODE ("%0000", "")
2006-04-14 16:16:46 +02:00
/* UTF-8 tests */
2006-08-30 19:40:36 +02:00
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");
2006-04-14 16:16:46 +02:00
2006-08-30 19:40:36 +02:00
#define DO_TEST_B64( a, b ) if( !test_b64( a, b ) ) return NULL;
/* Base 64 tests */
2006-08-30 19:40:36 +02:00
DO_TEST_B64 ("", "") ;
DO_TEST_B64("d", "ZA==");
DO_TEST_B64("ab", "YWI=");
DO_TEST_B64("abc", "YWJj");
DO_TEST_B64 ("abcd", "YWJjZA==");
2006-04-14 16:16:46 +02:00
Py_INCREF( Py_None);
return Py_None;
}