[vlc-devel] [PATCH 5/5] variables: test VLC_VAR_LIST

Thomas Guillem thomas at gllm.fr
Thu Nov 3 10:16:51 CET 2016


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

diff --git a/test/src/misc/variables.c b/test/src/misc/variables.c
index 547375d..d9bce5c 100644
--- a/test/src/misc/variables.c
+++ b/test/src/misc/variables.c
@@ -224,6 +224,88 @@ static void test_address( libvlc_int_t *p_libvlc )
         var_Destroy( p_libvlc, psz_var_name[i] );
 }
 
+static void test_list( libvlc_int_t *p_libvlc, const char *psz_var_name,
+                       const vlc_list_t *p_list )
+{
+    var_Create( p_libvlc, psz_var_name, VLC_VAR_LIST );
+    var_SetList( p_libvlc, psz_var_name, p_list );
+
+    vlc_list_t *p_get_list = var_GetList( p_libvlc, psz_var_name );
+    assert( p_get_list != NULL );
+    assert( p_get_list->i_type == p_list->i_type );
+    assert( p_get_list->i_count == p_list->i_count );
+    assert( p_get_list->p_values != p_list->p_values );
+
+    for( int i = 0; i < p_list->i_count; ++i )
+    {
+        vlc_value_t val1 = p_get_list->p_values[i], val2 = p_list->p_values[i];
+
+        switch( p_list->i_type )
+        {
+            case VLC_VAR_BOOL:
+                break;
+            case VLC_VAR_INTEGER:
+                assert( val1.i_int == val2.i_int );
+                break;
+            case VLC_VAR_STRING:
+                assert( strcmp( val1.psz_string, val2.psz_string ) == 0 );
+                break;
+            case VLC_VAR_FLOAT:
+                assert( val1.f_float == val2.f_float );
+                break;
+            case VLC_VAR_ADDRESS:
+                assert( val1.p_address == val2.p_address );
+                break;
+            default:
+                vlc_assert_unreachable();
+        }
+    }
+    var_FreeList( p_get_list );
+    var_Destroy( p_libvlc, psz_var_name );
+}
+
+static void test_lists( libvlc_int_t *p_libvlc )
+{
+    vlc_value_t val_bools[] = {
+        { .b_bool = true }, { .b_bool = true }, { .b_bool = false }
+    };
+    vlc_list_t list_bools = { VLC_VAR_BOOL, 3, val_bools };
+
+    vlc_value_t val_ints[] = {
+        { .i_int = -4654 }, { .i_int = 4654 }, { .i_int = 42 }
+    };
+    vlc_list_t list_ints = { VLC_VAR_INTEGER, 3, val_ints };
+
+    vlc_value_t val_strs[] = {
+        { .psz_string = strdup("") }, { .psz_string = strdup("test") },
+        { .psz_string = strdup("hello") }
+    };
+    vlc_list_t list_strs = { VLC_VAR_STRING, 3, val_strs };
+
+    vlc_value_t val_floats[] = {
+        { .i_int = 0.0f }, { .i_int = .045545f }, { .i_int = 1.0f }
+    };
+    vlc_list_t list_floats = { VLC_VAR_FLOAT, 3, val_floats };
+
+    vlc_value_t val_adds[] = {
+        { .p_address = val_bools }, { .p_address = val_ints },
+        { .p_address = val_floats }
+    };
+    vlc_list_t list_adds = { VLC_VAR_ADDRESS, 3, val_adds };
+
+    for( unsigned i = 0; i < VAR_COUNT; i++ )
+    {
+        test_list( p_libvlc, psz_var_name[i], &list_bools );
+        test_list( p_libvlc, psz_var_name[i], &list_ints );
+        test_list( p_libvlc, psz_var_name[i], &list_strs );
+        test_list( p_libvlc, psz_var_name[i], &list_floats );
+        test_list( p_libvlc, psz_var_name[i], &list_adds );
+    }
+    free( val_strs[0].psz_string );
+    free( val_strs[1].psz_string );
+    free( val_strs[2].psz_string );
+}
+
 static int callback( vlc_object_t* p_this, char const *psz_var,
                      vlc_value_t oldval, vlc_value_t newval, void *p_data)
 {
@@ -466,6 +548,9 @@ static void test_variables( libvlc_instance_t *p_vlc )
     log( "Testing for addresses\n" );
     test_address( p_libvlc );
 
+    log( "Testing for lists\n" );
+    test_lists( p_libvlc );
+
     log( "Testing the callbacks\n" );
     test_callbacks( p_libvlc );
 
-- 
2.9.3



More information about the vlc-devel mailing list