]> git.sesse.net Git - vlc/commitdiff
* Tests for previous commit
authorClément Stenac <zorglub@videolan.org>
Sat, 19 Aug 2006 16:19:56 +0000 (16:19 +0000)
committerClément Stenac <zorglub@videolan.org>
Sat, 19 Aug 2006 16:19:56 +0000 (16:19 +0000)
* Improve test output

test/NativeAlgoTest.py [new file with mode: 0644]
test/native/algo.c [new file with mode: 0644]
test/native/gc.c
test/native/init.c
test/native/tests.h
test/native/url.c
test/pyunit.h
test/setup.py
test/test.py
test/test.sh

diff --git a/test/NativeAlgoTest.py b/test/NativeAlgoTest.py
new file mode 100644 (file)
index 0000000..b707e27
--- /dev/null
@@ -0,0 +1,14 @@
+import unittest
+
+import native_libvlc_test
+
+class NativeAlgoTestCase( unittest.TestCase ):
+    def test_bsearch_direct( self ):
+        """[Algo] Check Bsearch with simple types"""
+       native_libvlc_test.bsearch_direct_test()
+    def test_bsearch_struct( self ):
+        """[Algo] Check Bsearch with structs"""
+       native_libvlc_test.bsearch_member_test()
+    def test_dict( self ):
+        """[Algo] Check dictionnaries"""
+       native_libvlc_test.dict_test()
diff --git a/test/native/algo.c b/test/native/algo.c
new file mode 100644 (file)
index 0000000..28c9f12
--- /dev/null
@@ -0,0 +1,147 @@
+/*****************************************************************************
+ * algo.c : Algorithms test
+ *****************************************************************************
+ * Copyright (C) 2006 VideoLAN
+ * $Id: i18n.c 16157 2006-07-29 13:32:12Z zorglub $
+ *
+ * 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.
+ *****************************************************************************/
+
+#include "../pyunit.h"
+#include <vlc/vlc.h>
+
+/**********************************************************************
+ * Binary search
+ *********************************************************************/
+
+PyObject *bsearch_direct_test( PyObject *self, PyObject *args )
+{
+#define DIRCHECK( size, initial, checked, expected ) { \
+    int array[size] = initial; \
+    int answer = -1;  \
+    BSEARCH( array, size, , int, checked, answer ); \
+    ASSERT( answer == expected , "" ); }
+
+#define ORDERED10 {0,1,2,3,4,5,6,7,8,9}
+    DIRCHECK( 10, ORDERED10, 0, 0 );
+    DIRCHECK( 10, ORDERED10, 1, 1 );
+    DIRCHECK( 10, ORDERED10, 2, 2 );
+    DIRCHECK( 10, ORDERED10, 3, 3 );
+    DIRCHECK( 10, ORDERED10, 4, 4 );
+    DIRCHECK( 10, ORDERED10, 5, 5 );
+    DIRCHECK( 10, ORDERED10, 6, 6 );
+    DIRCHECK( 10, ORDERED10, 7, 7 );
+    DIRCHECK( 10, ORDERED10, 8, 8 );
+    DIRCHECK( 10, ORDERED10, 9,9 );
+
+    DIRCHECK( 10, ORDERED10, 10, -1 );
+    DIRCHECK( 10, ORDERED10, -1, -1 );
+
+    /* TODO: tests on unordered arrays, odd number of elements, 1 element, 2 */
+
+    Py_INCREF( Py_None);
+    return Py_None;
+}
+
+struct bsearch_tester
+{
+    int key; int value;
+};
+
+/* Lighter test, we just check correct member access, all the real testing
+ * has been made already */
+PyObject *bsearch_member_test( PyObject *self, PyObject *args )
+{
+    struct bsearch_tester array[] =
+    {
+        { 0, 12 }, { 1, 22 } , { 2, 33 } , { 3, 68 } , { 4, 56 } 
+    };
+#define MEMBCHECK( checked, expected ) { \
+    int answer = -1;  \
+    BSEARCH( array, 5, .key , int, checked, answer ); \
+    ASSERT( answer == expected , "" ); }
+
+    MEMBCHECK( 0, 0 ) ;
+    MEMBCHECK( 1, 1 );
+    MEMBCHECK( 2, 2 );
+    MEMBCHECK( 3, 3 );
+    MEMBCHECK( 4, 4 );
+    MEMBCHECK( 5, -1 );
+
+    Py_INCREF( Py_None);
+    return Py_None;
+}
+
+/**********************************************************************
+ * Dictionnary
+ *********************************************************************/
+static void DumpDict( dict_t *p_dict )
+{
+    int i = 0;
+    fprintf( stderr, "**** Begin Dump ****\n" );
+    for( i = 0 ; i < p_dict->i_entries; i++ )
+    {
+        fprintf( stderr, "Entry %i - hash %lli int %i string %s data %p\n", 
+                        i, p_dict->p_entries[i].i_hash,
+                        p_dict->p_entries[i].i_int,
+                        p_dict->p_entries[i].psz_string,
+                        p_dict->p_entries[i].p_data );
+    }
+    fprintf( stderr, "**** End Dump ****\n" );
+}
+
+PyObject *dict_test( PyObject *self, PyObject *args )
+{
+    int i42 = 42,i40 = 40,i12 = 12, i0 = 0, i00 = 0;
+
+    dict_t *p_dict = vlc_DictNew();
+    ASSERT( p_dict->i_entries == 0, "" );
+    ASSERT( p_dict->p_entries == NULL, "" );
+
+    vlc_DictInsert( p_dict, 0, NULL, (void*)(&i42) );
+    ASSERT( p_dict->i_entries == 1, "" );
+    ASSERT( p_dict->p_entries[0].p_data == (void*)(&i42), "" );
+
+    vlc_DictInsert( p_dict, 1, "42", (void*)(&i42) );
+    ASSERT( p_dict->i_entries == 2, "" );
+    ASSERT( vlc_DictGet( p_dict, 1, "42" ) == (void*)(&i42), "" );
+    ASSERT( vlc_DictGet( p_dict, 0, "42" ) == NULL , "");
+    ASSERT( vlc_DictGet( p_dict, 1, " 42" ) == NULL , "");
+
+    vlc_DictInsert( p_dict, 1, "12", (void*)(&i12) );
+    ASSERT( vlc_DictGet( p_dict, 1, "12") == (void*)(&i12), "" );
+
+    vlc_DictInsert( p_dict, 3, "40", (void*)(&i40) );
+    ASSERT( vlc_DictGet( p_dict, 3, "40") == (void*)(&i40), "" );
+    ASSERT( vlc_DictGet( p_dict, 1, "12") == (void*)(&i12), "" );
+    ASSERT( vlc_DictGet( p_dict, 1, "42") == (void*)(&i42), "" );
+
+    vlc_DictInsert( p_dict, 12, "zero-1", (void*)(&i0) );
+    vlc_DictInsert( p_dict, 5, "zero-0", (void*)(&i00) );
+    ASSERT( vlc_DictGet( p_dict, 12, "zero-1") == (void*)(&i0), "" );
+    ASSERT( vlc_DictGet( p_dict, 5, "zero-0") == (void*)(&i00), "" );
+    ASSERT( vlc_DictGet( p_dict, 12, "zero-0") == NULL, "" );
+
+    vlc_DictInsert( p_dict, 0, "12", (void*)(&i12) );
+    vlc_DictInsert( p_dict, 0, "thisisaverylongstringwith12", (void*)(&i12) );
+    ASSERT( vlc_DictGet( p_dict, 0, "thisisaverylongstringwith12" ) ==
+                    (void*)(&i12),"" );
+    ASSERT( vlc_DictGet( p_dict, 0, "thisisaverylongstringwith13" ) == NULL,"");
+
+    vlc_DictClear( p_dict );
+
+    Py_INCREF( Py_None);
+    return Py_None;
+}
index 9cf14423e2d6fb778dcfff8accd38e0f9cb73dc6..718e1f83beda544f37787d904fd5fd14119c50b7 100644 (file)
@@ -39,4 +39,6 @@ static PyMethodDef native_gc_test_methods[] = {
    { NULL, NULL, 0, NULL }
 };
 
+asserts = 0;
+
 DECLARE_MODULE( native_gc_test )
index c334c3e7cf3d3b626d05d9b881ad173fb0269505..fa35c8b7e99e2382a1b39b4b032af9477bb2125b 100644 (file)
@@ -1,6 +1,15 @@
+#include "../pyunit.h"
 #include "tests.h"
 
+PyObject *init( PyObject *self, PyObject *args )
+{
+    (void)setvbuf (stdout, NULL, _IONBF, 0);
+    Py_INCREF( Py_None );
+    return Py_None;
+}
+
 static PyMethodDef native_libvlc_test_methods[] = {
+   DEF_METHOD( init, "Init some stuff" )
    DEF_METHOD( create_destroy, "Create and destroy" )
    DEF_METHOD( exception_test, "Test Exception handling" )
    DEF_METHOD( playlist_test, "Test Playlist interaction" )
@@ -11,7 +20,12 @@ static PyMethodDef native_libvlc_test_methods[] = {
    DEF_METHOD( chains_test, "Test building of chains" )
    DEF_METHOD( gui_chains_test, "Test interactions between chains and GUI" )
    DEF_METHOD( psz_chains_test, "Test building of chain strings" )
+   DEF_METHOD( bsearch_direct_test, "Test Bsearch without structure" )
+   DEF_METHOD( bsearch_member_test, "Test Bsearch with structure" )
+   DEF_METHOD( dict_test, "Test dictionnaries" )
    { NULL, NULL, 0, NULL }
 };
 
+asserts =0;
+
 DECLARE_MODULE( native_libvlc_test )
index 94b6acb102e625b5cb1a3abd5eb599d6a91980c6..1606c9b57afaf8a56bbaeb4577335318bee9129b 100644 (file)
@@ -1,16 +1,25 @@
 #include "../pyunit.h"
 
+/* Libvlc */
 PyObject *exception_test( PyObject *self, PyObject *args );
 PyObject *create_destroy( PyObject *self, PyObject *args );
 PyObject *playlist_test( PyObject *self, PyObject *args );
 PyObject *vlm_test( PyObject *self, PyObject *args );
 
+/* Stats */
 PyObject *timers_test( PyObject *self, PyObject *args );
 
 PyObject *url_decode_test( PyObject *self, PyObject *args );
 
 PyObject *i18n_atof_test( PyObject *self, PyObject *args );
 
+/* Profiles */
 PyObject *chains_test( PyObject *self, PyObject *args );
 PyObject *gui_chains_test( PyObject *self, PyObject *args );
 PyObject *psz_chains_test( PyObject *self, PyObject *args );
+
+/* Algo */
+PyObject *bsearch_direct_test( PyObject *self, PyObject *args );
+PyObject *bsearch_member_test( PyObject *self, PyObject *args );
+PyObject *dict_test( PyObject *self, PyObject *args );
+
index f97ce032877952754727c3b5a08d0cb3ff628c2d..e43896ecf5a8140ca5c3a6958c14945286478fee 100644 (file)
@@ -42,7 +42,6 @@ PyObject * test_decode (const char *in, const char *out)
 PyObject *url_decode_test( PyObject *self, PyObject *args )
 {
     printf( "\n" );
-    (void)setvbuf (stdout, NULL, _IONBF, 0);
     if( !test_decode ("this_should_not_be_modified_1234",
                      "this_should_not_be_modified_1234") ) return NULL;
 
index c2523d516dbe66e2c63d944a8d2a5fa9bf73647a..726ca8d446a646316e5e97decd8b4a1965d2890e 100644 (file)
@@ -1,16 +1,18 @@
 #include <Python.h>
 
-#define ASSERT( a, message ) if( !(a) ) { PyErr_SetString( PyExc_AssertionError, message " - " #a ); return NULL; }
+extern int asserts;
+
+#define ASSERT( a, message ) asserts++;if( !(a) ) { PyErr_SetString( PyExc_AssertionError, message " - " #a ); return NULL; }
 
 #define DECLARE_MODULE( module ) PyMODINIT_FUNC init##module( void ) {  \
         Py_InitModule( #module, module##_methods );                     \
 }
 
-#define ASSERT_NOEXCEPTION if( libvlc_exception_raised( &exception ) ) { \
+#define ASSERT_NOEXCEPTION asserts++; if( libvlc_exception_raised( &exception ) ) { \
          if( libvlc_exception_get_message( &exception ) )  PyErr_SetString( PyExc_AssertionError, libvlc_exception_get_message( &exception ) ); \
          else PyErr_SetString( PyExc_AssertionError, "Exception raised" ); return NULL; }
 
-#define ASSERT_EXCEPTION if( !libvlc_exception_raised( &exception ) ) { \
+#define ASSERT_EXCEPTION asserts ++; if( !libvlc_exception_raised( &exception ) ) { \
          if( libvlc_exception_get_message( &exception ) )  PyErr_SetString( PyExc_AssertionError, libvlc_exception_get_message( &exception ) ); \
          else PyErr_SetString( PyExc_AssertionError, "Exception not raised" ); return NULL; }
 
index 098b52a0d680050db7544e58e58343ef9634dba8..36fb9f3783160ba66ac11d00f46be6807e91dc79 100644 (file)
@@ -41,7 +41,8 @@ def get_ldflags():
 # To compile in a local vlc tree
 native_libvlc_test = Extension( 'native_libvlc_test',
                 sources = ['native/init.c', 'native/url.c', 'native/i18n.c',
-                           'native/stats.c', 'native/libvlc.c', 'native/profiles.c'],
+                           'native/stats.c', 'native/libvlc.c', 'native/profiles.c',
+                'native/algo.c'],
                 include_dirs = ['../include', '../', '/usr/win32/include' ],
                 extra_objects = [ '../src/.libs/libvlc.so' ],
                 extra_compile_args = get_cflags(),
index 9206c5b5e7acd75139d14b121f35b02d1b6ba0cd..737c10c88f193d5c25cc77bac25e5ab007b9498c 100644 (file)
@@ -8,9 +8,11 @@ found test suites into one big test suite and run them all at once.
 """
 
 import sys, os, re, unittest
+import native_libvlc_test
+
 
 def printAndRun( module ):
-    print "Running tests from module " + module.__name__;
+#    print "Running tests from module " + module.__name__;
     return unittest.defaultTestLoader.loadTestsFromModule( module )
 
 def regressionTest():
@@ -21,6 +23,9 @@ def regressionTest():
     filenameToModuleName = lambda f: os.path.splitext(f)[0]
     moduleNames = map(filenameToModuleName, files)         
     modules = map(__import__, moduleNames)                 
+    
+    native_libvlc_test.init()
+
 #    load = unittest.defaultTestLoader.loadTestsFromModule
     load = printAndRun
     return unittest.TestSuite(map(load, modules))        
index bb9a1086963059cb067e6a325ad7be7cb4a251eb..84fc89d831ac6409428219d0cd3d3d1302958999 100755 (executable)
@@ -1,7 +1,42 @@
 #! /bin/sh
 
+set -e
+python setup.py build 
 
 cd ..
+# TODO: FIXME !!
 export PYTHONPATH=$PYTHONPATH:bindings/mediacontrol-python/build/lib.linux-i686-2.3:test/build/lib.linux-i686-2.3:test/build/lib.linux-x86_64-2.3
 
-LD_LIBRARY_PATH=src/.libs/ python test/test.py -v
+export LD_LIBRARY_PATH=src/.libs/
+
+python test/test.py -v 2>&1|perl  -e \
+'$bold = "\033[1m";
+$grey  = "\033[37m";
+$green  = "\033[32m";
+$blue  = "\033[34m";
+$red  = "\033[31m";
+$reset = "\033[0m";
+
+# Combinations
+$info   = $reset;
+$ok     = $green;
+$err    = $red.$bold;
+
+while(<STDIN>)
+{
+     $line = $_;
+     chomp $line;
+     if( $line =~ s/^(\[[A-z0-9]*\]\s.*)\.\.\.\sok$/$info$1\.\.\.$ok ok/g || 
+         $line =~ s/^(\[[A-z0-9]*\]\s.*)\.\.\.\sFAIL$/$info$1\.\.\.$err FAIL/g||
+         $line =~ s/^(\[[A-z0-9]*\]\s.*)\.\.\.(.)*$/$info$1\.\.\.$2/g || 
+         $line =~ s/^(ok)$/$ok$1/ig || $line =~ s/^FAIL$/$err FAIL/g || 
+         $line =~ s/(Ran\s.*)/$info$1/g )
+     {
+        print $line.$reset."\n";
+     }
+     else
+     {
+        print $grey.$line."\n";
+     }
+}'
+