From e85a5a618dde3b1d131ffca1cd373a9d3f845fc6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Cl=C3=A9ment=20Stenac?= Date: Mon, 18 Sep 2006 14:16:14 +0000 Subject: [PATCH] A bit of cleanup and test --- include/libvlc_internal.h | 9 +++-- include/vlc/libvlc.h | 4 +- src/control/core.c | 2 +- src/libvlc-common.c | 3 +- test/NativeLibvlcTest.py | 16 ++++---- test/native/libvlc.c | 78 +++++++++++++++++++++++++++------------ test/test.sh | 3 ++ 7 files changed, 75 insertions(+), 40 deletions(-) diff --git a/include/libvlc_internal.h b/include/libvlc_internal.h index c0d63f3c6d..da05bfa2e6 100644 --- a/include/libvlc_internal.h +++ b/include/libvlc_internal.h @@ -59,9 +59,12 @@ struct libvlc_input_t struct libvlc_instance_t *p_instance; ///< Parent instance }; -#define RAISENULL( psz ) { libvlc_exception_raise( p_e, psz ); return NULL; } -#define RAISEVOID( psz ) { libvlc_exception_raise( p_e, psz ); return; } -#define RAISEZERO( psz ) { libvlc_exception_raise( p_e, psz ); return 0; } +#define RAISENULL( psz,a... ) { libvlc_exception_raise( p_e, psz,##a ); \ + return NULL; } +#define RAISEVOID( psz,a... ) { libvlc_exception_raise( p_e, psz,##a ); \ + return; } +#define RAISEZERO( psz,a... ) { libvlc_exception_raise( p_e, psz,##a ); \ + return 0; } # ifdef __cplusplus } diff --git a/include/vlc/libvlc.h b/include/vlc/libvlc.h index a8173bb07e..01b0bfa22e 100644 --- a/include/vlc/libvlc.h +++ b/include/vlc/libvlc.h @@ -122,10 +122,10 @@ libvlc_instance_t * libvlc_new( int , char **, libvlc_exception_t *); int libvlc_get_vlc_id( libvlc_instance_t *p_instance ); /** - * Destroy a libvlc instance + * Destroy a libvlc instance. * \param p_instance the instance to destroy */ -void libvlc_destroy( libvlc_instance_t *); +void libvlc_destroy( libvlc_instance_t *, libvlc_exception_t * ); /** @}*/ diff --git a/src/control/core.c b/src/control/core.c index 0b869dbcd9..8d4426e8f5 100644 --- a/src/control/core.c +++ b/src/control/core.c @@ -101,7 +101,7 @@ libvlc_instance_t * libvlc_new( int argc, char **argv, return p_new; } -void libvlc_destroy( libvlc_instance_t *p_instance ) +void libvlc_destroy( libvlc_instance_t *p_instance, libvlc_exception_t *p_e ) { libvlc_InternalCleanup( p_instance->p_libvlc_int ); libvlc_InternalDestroy( p_instance->p_libvlc_int, VLC_FALSE ); diff --git a/src/libvlc-common.c b/src/libvlc-common.c index 01c235b44d..05d967ad30 100644 --- a/src/libvlc-common.c +++ b/src/libvlc-common.c @@ -868,14 +868,13 @@ int libvlc_InternalCleanup( libvlc_int_t *p_libvlc ) */ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc, vlc_bool_t b_release ) { - /* Free allocated memory */ if( p_libvlc->p_memcpy_module ) { module_Unneed( p_libvlc, p_libvlc->p_memcpy_module ); p_libvlc->p_memcpy_module = NULL; } - /* Free module bank ! */ + /* Free module bank. It is refcounted, so we call this each time */ module_EndBank( p_libvlc ); FREENULL( p_libvlc->psz_homedir ); diff --git a/test/NativeLibvlcTest.py b/test/NativeLibvlcTest.py index dbcd9ee375..acb74c6510 100644 --- a/test/NativeLibvlcTest.py +++ b/test/NativeLibvlcTest.py @@ -3,15 +3,15 @@ import unittest import native_libvlc_test class NativeLibvlcTestCase( unittest.TestCase ): - def testException( self ): + def test1Exception( self ): """[LibVLC] Checks libvlc_exception""" -# native_libvlc_test.exception_test() - def testStartup( self ): + native_libvlc_test.exception_test() + def test2Startup( self ): """[LibVLC] Checks creation/destroy of libvlc""" -# native_libvlc_test.create_destroy() - def testPlaylist( self ): + native_libvlc_test.create_destroy() + def test3Playlist( self ): """[LibVLC] Checks basic playlist interaction""" -# native_libvlc_test.playlist_test() - def testVLM( self ): + native_libvlc_test.playlist_test() + def test4VLM( self ): """[LibVLC] Checks VLM wrapper""" -# native_libvlc_test.vlm_test() + native_libvlc_test.vlm_test() diff --git a/test/native/libvlc.c b/test/native/libvlc.c index 5611ae5c77..2ff69fa335 100644 --- a/test/native/libvlc.c +++ b/test/native/libvlc.c @@ -1,46 +1,76 @@ #include "../pyunit.h" #include - PyObject *exception_test( PyObject *self, PyObject *args ) +PyObject *exception_test( PyObject *self, PyObject *args ) { - libvlc_exception_t exception; + libvlc_exception_t exception; - libvlc_exception_init( &exception ); - ASSERT( !libvlc_exception_raised( &exception) , "Exception raised" ); - ASSERT( !libvlc_exception_get_message( &exception) , "Exception raised" ); + libvlc_exception_init( &exception ); + ASSERT( !libvlc_exception_raised( &exception) , "Exception raised" ); + ASSERT( !libvlc_exception_get_message( &exception) , "Exception raised" ); - libvlc_exception_raise( &exception, NULL ); - ASSERT( !libvlc_exception_get_message( &exception), "Unexpected message" ); - ASSERT( libvlc_exception_raised( &exception), "Exception not raised" ); + libvlc_exception_raise( &exception, NULL ); + ASSERT( !libvlc_exception_get_message( &exception), "Unexpected message" ); + ASSERT( libvlc_exception_raised( &exception), "Exception not raised" ); - libvlc_exception_raise( &exception, "test" ); - ASSERT( libvlc_exception_get_message( &exception), "No Message" ); - ASSERT( libvlc_exception_raised( &exception), "Exception not raised" ); + libvlc_exception_raise( &exception, "test" ); + ASSERT( libvlc_exception_get_message( &exception), "No Message" ); + ASSERT( libvlc_exception_raised( &exception), "Exception not raised" ); - libvlc_exception_clear( &exception ); - ASSERT( !libvlc_exception_raised( &exception ), "Exception not cleared" ); + libvlc_exception_clear( &exception ); + ASSERT( !libvlc_exception_raised( &exception ), "Exception not cleared" ); - Py_INCREF( Py_None ); - return Py_None; + Py_INCREF( Py_None ); + return Py_None; } - PyObject *create_destroy( PyObject *self, PyObject *args ) +PyObject *create_destroy( PyObject *self, PyObject *args ) { - libvlc_instance_t *p_instance; - char *argv[] = { "vlc", "--quiet" }; + libvlc_instance_t *p_i1, *p_i2; + char *argv1[] = { "vlc", "--quiet" }; + char *argv2[]= { "vlc", "-vvv" }; + int id1,id2; + + printf( "\n" ); libvlc_exception_t exception; libvlc_exception_init( &exception ); - p_instance = libvlc_new( 2, argv, &exception ); + /* Create and destroy a single instance */ + fprintf( stderr, "Create 1\n" ); + p_i1 = libvlc_new( 2, argv1, &exception ); + ASSERT( p_i1 != NULL, "Instance creation failed" ); + ASSERT_NOEXCEPTION; + id1 = libvlc_get_vlc_id( p_i1 ); + libvlc_destroy( p_i1, &exception ); + ASSERT_NOEXCEPTION; + + /* Create and destroy two instances */ + fprintf( stderr, "Create 2\n" ); + p_i1 = libvlc_new( 2, argv1, &exception ); + ASSERT( p_i1 != NULL, "Instance creation failed" ); + ASSERT_NOEXCEPTION; + + fprintf( stderr, "Create 3\n" ); + p_i2 = libvlc_new( 2, argv2, &exception ); + ASSERT( p_i2 != NULL, "Instance creation failed" ); + ASSERT_NOEXCEPTION; - ASSERT( p_instance != NULL, "Instance creation failed" ); + fprintf( stderr, "Destroy 1\n" ); + libvlc_destroy( p_i1, &exception ); + ASSERT_NOEXCEPTION; + fprintf( stderr, "Destroy 2\n" ); + libvlc_destroy( p_i2, &exception ); + ASSERT_NOEXCEPTION; + + /* Deinit */ + fprintf( stderr, "Create 4\n" ); + p_i1 = libvlc_new( 2, argv1, &exception ); + ASSERT_NOEXCEPTION; + id2 = libvlc_get_vlc_id( p_i1 ); - ASSERT( !libvlc_exception_raised( &exception ), - "Exception raised while creating instance" ); + ASSERT( id1 == id2, "libvlc object ids do not match after deinit" ); - libvlc_destroy( p_instance ); - Py_INCREF( Py_None ); return Py_None; } diff --git a/test/test.sh b/test/test.sh index 825f118915..88c8499240 100755 --- a/test/test.sh +++ b/test/test.sh @@ -9,6 +9,9 @@ export PYTHONPATH=$PYTHONPATH:bindings/mediacontrol-python/build/lib.linux-i686- export LD_LIBRARY_PATH=src/.libs/ +# Always dump core +ulimit -c unlimited + python test/test.py -v 2>&1|perl -e \ '$bold = "\033[1m"; $grey = "\033[37m"; -- 2.39.2