[vlc-commits] tests: full coverage for var_InheritURational()

Rémi Denis-Courmont git at videolan.org
Sat Apr 2 18:15:44 CEST 2016


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Apr  2 19:15:26 2016 +0300| [ada5cdeeac8a01bce71deb234ce4b2f78e4e4a5c] | committer: Rémi Denis-Courmont

tests: full coverage for var_InheritURational()

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ada5cdeeac8a01bce71deb234ce4b2f78e4e4a5c
---

 test/src/misc/variables.c |   71 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 71 insertions(+)

diff --git a/test/src/misc/variables.c b/test/src/misc/variables.c
index 5d57049..7a9f138 100644
--- a/test/src/misc/variables.c
+++ b/test/src/misc/variables.c
@@ -98,6 +98,74 @@ static void test_floats( libvlc_int_t *p_libvlc )
         var_Destroy( p_libvlc, psz_var_name[i] );
 }
 
+static void test_fracts( libvlc_int_t *p_libvlc )
+{
+    const char *name = psz_var_name[0];
+    unsigned num, den;
+
+    var_Create( p_libvlc, name, VLC_VAR_STRING );
+    assert( var_InheritURational( p_libvlc, &num, &den, name ) != 0 );
+
+    var_SetString( p_libvlc, name, "123garbage" );
+    assert( var_InheritURational( p_libvlc, &num, &den, name ) != 0 );
+
+    var_SetString( p_libvlc, name, "4/5garbage" );
+    assert( var_InheritURational( p_libvlc, &num, &den, name ) != 0 );
+
+    var_SetString( p_libvlc, name, "6.7garbage" );
+    assert( var_InheritURational( p_libvlc, &num, &den, name ) != 0 );
+
+    var_SetString( p_libvlc, name, "." );
+    assert( var_InheritURational( p_libvlc, &num, &den, name ) == 0 );
+    assert( num == 0 && den == 1 );
+
+    var_SetString( p_libvlc, name, "010" );
+    assert( var_InheritURational( p_libvlc, &num, &den, name ) == 0 );
+    assert( num == 10 && den == 1 );
+
+    var_SetString( p_libvlc, name, "30" );
+    assert( var_InheritURational( p_libvlc, &num, &den, name ) == 0 );
+    assert( num == 30 && den == 1 );
+
+    var_SetString( p_libvlc, name, "30.0" );
+    assert( var_InheritURational( p_libvlc, &num, &den, name ) == 0 );
+    assert( num == 30 && den == 1 );
+
+    var_SetString( p_libvlc, name, "030.030" );
+    assert( var_InheritURational( p_libvlc, &num, &den, name ) == 0 );
+    assert( num == 3003 && den == 100 );
+
+    var_SetString( p_libvlc, name, "60/2" );
+    assert( var_InheritURational( p_libvlc, &num, &den, name ) == 0 );
+    assert( num == 30 && den == 1 );
+
+    var_SetString( p_libvlc, name, "29.97" );
+    assert( var_InheritURational( p_libvlc, &num, &den, name ) == 0 );
+    assert( num == 2997 && den == 100 );
+
+    var_SetString( p_libvlc, name, "30000/1001" );
+    assert( var_InheritURational( p_libvlc, &num, &den, name ) == 0 );
+    assert( num == 30000 && den == 1001 );
+
+    var_SetString( p_libvlc, name, ".125" );
+    assert( var_InheritURational( p_libvlc, &num, &den, name ) == 0 );
+    assert( num == 1 && den == 8 );
+
+    var_SetString( p_libvlc, name, "12:9" );
+    assert( var_InheritURational( p_libvlc, &num, &den, name ) == 0 );
+    assert( num == 4 && den == 3 );
+
+    var_SetString( p_libvlc, name, "000000/00000000" );
+    assert( var_InheritURational( p_libvlc, &num, &den, name ) == 0 );
+    assert( num == 0 && den == 0 );
+
+    var_SetString( p_libvlc, name, "12345/0" );
+    assert( var_InheritURational( p_libvlc, &num, &den, name ) == 0 );
+    assert( num == 1 && den == 0 );
+
+    var_Destroy( p_libvlc, name );
+}
+
 static void test_strings( libvlc_int_t *p_libvlc )
 {
     for( unsigned i = 0; i < VAR_COUNT; i++ )
@@ -394,6 +462,9 @@ static void test_variables( libvlc_instance_t *p_vlc )
     log( "Testing for floats\n" );
     test_floats( p_libvlc );
 
+    log( "Testing for rationals\n" );
+    test_fracts( p_libvlc );
+
     log( "Testing for strings\n" );
     test_strings( p_libvlc );
 



More information about the vlc-commits mailing list