Skeleton for testing libvlc
authorClément Stenac <zorglub@videolan.org>
Sun, 29 Jan 2006 17:00:31 +0000 (17:00 +0000)
committerClément Stenac <zorglub@videolan.org>
Sun, 29 Jan 2006 17:00:31 +0000 (17:00 +0000)
test/BaseTest.py [deleted file]
test/NativeLibvlcTest.py [new file with mode: 0644]
test/PlaylistTest.py [deleted file]
test/PyMediaControlBaseTest.py [new file with mode: 0644]
test/PyMediaControlPlaylistTest.py [new file with mode: 0644]
test/PyMediaControlVariablesTest.py [new file with mode: 0644]
test/VariablesTest.py [deleted file]
test/native_libvlc/native_libvlc_test.c [new file with mode: 0644]
test/pyunit.h [new file with mode: 0644]
test/setup.py [new file with mode: 0644]
test/test.sh

diff --git a/test/BaseTest.py b/test/BaseTest.py
deleted file mode 100644 (file)
index 9e36ce8..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-import vlc
-import unittest
-
-class BaseTestCase( unittest.TestCase ):
-    def testStartup(self):
-        """Checks that VLC starts"""
-       mc = vlc.MediaControl( ['--quiet'])
-        mc.exit()
-
-#    def testHelp(self):
-#        """Check help string"""
-#        mc=vlc.MediaControl( [ '--help'] )
diff --git a/test/NativeLibvlcTest.py b/test/NativeLibvlcTest.py
new file mode 100644 (file)
index 0000000..fcef0a1
--- /dev/null
@@ -0,0 +1,8 @@
+import vlc
+import unittest
+
+import native_libvlc_test
+
+class NativeLibvlcTestCase( unittest.TestCase ):
+    def testMe( self ):
+       native_libvlc_test.create_destroy()
diff --git a/test/PlaylistTest.py b/test/PlaylistTest.py
deleted file mode 100644 (file)
index 396d9b8..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-import vlc
-import unittest
-
-# FIXME: How to avoid creating / killing vlc for each test method ?
-
-class VariablesTestCase( unittest.TestCase ):
-    """Test misc variables interaction"""
-    def setUp( self ):
-        self.mc = vlc.MediaControl( [ '--quiet'] )
-
-    def tearDown( self ):
-        self.mc.exit()
-           
-    def testSimple( self ):
-        """Test simple add/remove"""
-        assert len( self.mc.playlist_get_list() ) == 0
-        self.mc.playlist_add_item( "test" )
-        assert len( self.mc.playlist_get_list() ) == 1
diff --git a/test/PyMediaControlBaseTest.py b/test/PyMediaControlBaseTest.py
new file mode 100644 (file)
index 0000000..9e36ce8
--- /dev/null
@@ -0,0 +1,12 @@
+import vlc
+import unittest
+
+class BaseTestCase( unittest.TestCase ):
+    def testStartup(self):
+        """Checks that VLC starts"""
+       mc = vlc.MediaControl( ['--quiet'])
+        mc.exit()
+
+#    def testHelp(self):
+#        """Check help string"""
+#        mc=vlc.MediaControl( [ '--help'] )
diff --git a/test/PyMediaControlPlaylistTest.py b/test/PyMediaControlPlaylistTest.py
new file mode 100644 (file)
index 0000000..396d9b8
--- /dev/null
@@ -0,0 +1,18 @@
+import vlc
+import unittest
+
+# FIXME: How to avoid creating / killing vlc for each test method ?
+
+class VariablesTestCase( unittest.TestCase ):
+    """Test misc variables interaction"""
+    def setUp( self ):
+        self.mc = vlc.MediaControl( [ '--quiet'] )
+
+    def tearDown( self ):
+        self.mc.exit()
+           
+    def testSimple( self ):
+        """Test simple add/remove"""
+        assert len( self.mc.playlist_get_list() ) == 0
+        self.mc.playlist_add_item( "test" )
+        assert len( self.mc.playlist_get_list() ) == 1
diff --git a/test/PyMediaControlVariablesTest.py b/test/PyMediaControlVariablesTest.py
new file mode 100644 (file)
index 0000000..84d7747
--- /dev/null
@@ -0,0 +1,38 @@
+import vlc
+import unittest
+
+# FIXME: How to avoid creating / killing vlc for each test method ?
+
+class VariablesTestCase( unittest.TestCase ):
+    """Test misc variables interaction"""
+    def setUp( self ):
+        self.mc = vlc.MediaControl( [ '--quiet'] )
+        # FIXME ! - Get this through children test
+        self.libvlc = vlc.Object(1)
+        self.playlist = vlc.Object(268)
+
+    def tearDown( self ):
+        self.playlist.release() 
+        self.libvlc.release() 
+        self.mc.exit()
+            
+    # The Python binding can't create variables, so just get default ones
+    def testInt( self ):
+        """Get/Set integer variable"""
+        assert self.libvlc.get( "width" ) == 0
+        self.libvlc.set( "width", 42 ) 
+        assert self.libvlc.get( 'width' ) == 42
+
+    # FIXME: Python binding should listen to return value and raise exception 
+    def testInvalidInt( self ):
+        """Get/Set invalid integer"""
+        self.libvlc.set( "width" , 5 )
+        self.libvlc.set( "width", "foo" )
+        assert self.libvlc.get( "width" ) == -1
+    
+    def testString( self ):
+        """Get/Set string variable"""
+        assert self.libvlc.get( "open" ) == ''
+        self.libvlc.set( "open", "foo" ) 
+        assert self.libvlc.get( "open" ) == "foo"
+           
diff --git a/test/VariablesTest.py b/test/VariablesTest.py
deleted file mode 100644 (file)
index 84d7747..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-import vlc
-import unittest
-
-# FIXME: How to avoid creating / killing vlc for each test method ?
-
-class VariablesTestCase( unittest.TestCase ):
-    """Test misc variables interaction"""
-    def setUp( self ):
-        self.mc = vlc.MediaControl( [ '--quiet'] )
-        # FIXME ! - Get this through children test
-        self.libvlc = vlc.Object(1)
-        self.playlist = vlc.Object(268)
-
-    def tearDown( self ):
-        self.playlist.release() 
-        self.libvlc.release() 
-        self.mc.exit()
-            
-    # The Python binding can't create variables, so just get default ones
-    def testInt( self ):
-        """Get/Set integer variable"""
-        assert self.libvlc.get( "width" ) == 0
-        self.libvlc.set( "width", 42 ) 
-        assert self.libvlc.get( 'width' ) == 42
-
-    # FIXME: Python binding should listen to return value and raise exception 
-    def testInvalidInt( self ):
-        """Get/Set invalid integer"""
-        self.libvlc.set( "width" , 5 )
-        self.libvlc.set( "width", "foo" )
-        assert self.libvlc.get( "width" ) == -1
-    
-    def testString( self ):
-        """Get/Set string variable"""
-        assert self.libvlc.get( "open" ) == ''
-        self.libvlc.set( "open", "foo" ) 
-        assert self.libvlc.get( "open" ) == "foo"
-           
diff --git a/test/native_libvlc/native_libvlc_test.c b/test/native_libvlc/native_libvlc_test.c
new file mode 100644 (file)
index 0000000..36df199
--- /dev/null
@@ -0,0 +1,16 @@
+#include "../pyunit.h"
+
+static PyObject *create_destroy( PyObject *self, PyObject *args )
+{
+     /* Test stuff here */
+     
+     Py_INCREF( Py_None );
+     return Py_None;
+}
+
+static PyMethodDef native_libvlc_test_methods[] = {
+   DEF_METHOD( create_destroy, "Create and destroy" )
+   { NULL, NULL, 0, NULL }
+};
+
+DECLARE_MODULE( native_libvlc_test )
diff --git a/test/pyunit.h b/test/pyunit.h
new file mode 100644 (file)
index 0000000..3fc5978
--- /dev/null
@@ -0,0 +1,9 @@
+#include <Python.h>
+
+#define ASSERT( a, message ) if( !(a) ) { fprintf( stderr, "ASSERTION FAILED\n" ); PyErr_SetString( PyExc_AssertionError, message ); return NULL; }
+
+#define DECLARE_MODULE( module ) PyMODINIT_FUNC init##module( void ) {  \
+        Py_InitModule( #module, module##_methods );                     \
+}
+
+#define DEF_METHOD( method, desc ) { #method, method, METH_VARARGS, desc},
diff --git a/test/setup.py b/test/setup.py
new file mode 100644 (file)
index 0000000..a43ac97
--- /dev/null
@@ -0,0 +1,49 @@
+from distutils.core import setup,Extension
+import os
+
+def get_vlcconfig():
+    vlcconfig=None
+    for n in ( 'vlc-config',
+               os.path.sep.join( ( '..', 'vlc-config' ))):
+        if os.path.exists(n):
+            vlcconfig=n
+            break
+    if vlcconfig is None:
+        print "*** Warning *** Cannot find vlc-config"
+    elif os.sys.platform == 'win32':
+        # Win32 does not know how to invoke the shell itself.
+        vlcconfig="sh %s" % vlcconfig
+    return vlcconfig
+
+def get_cflags():
+    vlcconfig=get_vlcconfig()
+    if vlcconfig is None:
+        return []
+    else:
+        cflags=os.popen('%s --cflags' % vlcconfig, 'r').readline().rstrip().split()
+        return cflags
+
+def get_ldflags():
+    vlcconfig=get_vlcconfig()
+    if vlcconfig is None:
+        return []
+    else:
+       os.environ['top_builddir'] = '..'
+       ldflags = []
+       if os.sys.platform == 'darwin':
+           ldflags = "-read_only_relocs warning".split()
+        ldflags.extend(os.popen('%s --libs vlc pic builtin' % vlcconfig, 'r').readline().rstrip().split())
+       if os.sys.platform == 'darwin':
+           ldflags.append('-lstdc++')
+        return ldflags
+
+# To compile in a local vlc tree
+native_libvlc_test = Extension( 'native_libvlc_test',
+                sources = ['native_libvlc/native_libvlc_test.c'],
+                include_dirs = ['../include', '../', '/usr/win32/include' ],
+                extra_objects = [ '../lib/libvlc_pic.a' ],
+                extra_compile_args = get_cflags(),
+                           extra_link_args = [ '-L../..' ]  + get_ldflags(),
+                )
+
+setup( name = 'native_libvlc_test' ,version = '1242', ext_modules = [ native_libvlc_test ] )
index 2d41795..9981fa7 100755 (executable)
@@ -2,6 +2,6 @@
 
 # FIXME - Get real .so
 cd ..
 
 # FIXME - Get real .so
 cd ..
-export PYTHONPATH=$PYTHONPATH:bindings/python/build/lib.linux-i686-2.3
+export PYTHONPATH=$PYTHONPATH:bindings/python/build/lib.linux-i686-2.3:test/build/lib.linux-i686-2.3
 
 python test/test.py -v
 
 python test/test.py -v