From 895e5d3f33d11052afeb53ceca2f132316b4d2ed Mon Sep 17 00:00:00 2001 From: Julian Bouzas <julian.bouzas@collabora.com> Date: Thu, 14 May 2020 11:16:56 -0400 Subject: [PATCH] tests: spa-props: fix memleaks shown with valgrind --- tests/wp/spa-props.c | 321 ++++++++++++++++++++++++------------------- 1 file changed, 180 insertions(+), 141 deletions(-) diff --git a/tests/wp/spa-props.c b/tests/wp/spa-props.c index 634a1f5a..bccc91f8 100644 --- a/tests/wp/spa-props.c +++ b/tests/wp/spa-props.c @@ -21,7 +21,6 @@ test_spa_props_set_get (void) g_assert_true (wp_spa_type_register (WP_SPA_TYPE_TABLE_PROPS, "Wp:Test:Property", "wp-test-property")); WpSpaProps props = {0}; - g_autoptr (WpSpaPod) pod = NULL; float float_value = 0.0; const gchar *string_value = NULL; @@ -30,26 +29,40 @@ test_spa_props_set_get (void) wp_spa_props_register (&props, "wp-test-property", "Test property", wp_spa_pod_new_string ("default value")); - g_assert_nonnull (pod = wp_spa_props_get_stored (&props, "volume")); - g_assert_true (wp_spa_pod_get_float (pod, &float_value)); - g_assert_cmpfloat_with_epsilon (float_value, 1.0, 0.001); - - g_assert_nonnull (pod = wp_spa_props_get_stored (&props, "wp-test-property")); - g_assert_true (wp_spa_pod_get_string (pod, &string_value)); - g_assert_cmpstr (string_value, ==, "default value"); - - g_autoptr (WpSpaPod) new_float = wp_spa_pod_new_float (0.8); - g_autoptr (WpSpaPod) new_str = wp_spa_pod_new_string ("test value"); - g_assert_true (wp_spa_props_store (&props, "volume", new_float)); - g_assert_true (wp_spa_props_store (&props, "wp-test-property", new_str)); - - g_assert_nonnull (pod = wp_spa_props_get_stored (&props, "volume")); - g_assert_true (wp_spa_pod_get_float (pod, &float_value)); - g_assert_cmpfloat_with_epsilon (float_value, 0.8, 0.001); - - g_assert_nonnull (pod = wp_spa_props_get_stored (&props, "wp-test-property")); - g_assert_true (wp_spa_pod_get_string (pod, &string_value)); - g_assert_cmpstr (string_value, ==, "test value"); + { + g_autoptr (WpSpaPod) pod = wp_spa_props_get_stored (&props, "volume"); + g_assert_nonnull (pod); + g_assert_true (wp_spa_pod_get_float (pod, &float_value)); + g_assert_cmpfloat_with_epsilon (float_value, 1.0, 0.001); + } + + { + g_autoptr (WpSpaPod) pod = wp_spa_props_get_stored (&props, "wp-test-property"); + g_assert_nonnull (pod); + g_assert_true (wp_spa_pod_get_string (pod, &string_value)); + g_assert_cmpstr (string_value, ==, "default value"); + } + + { + g_autoptr (WpSpaPod) new_float = wp_spa_pod_new_float (0.8); + g_autoptr (WpSpaPod) new_str = wp_spa_pod_new_string ("test value"); + g_assert_true (wp_spa_props_store (&props, "volume", new_float)); + g_assert_true (wp_spa_props_store (&props, "wp-test-property", new_str)); + } + + { + g_autoptr (WpSpaPod) pod = wp_spa_props_get_stored (&props, "volume"); + g_assert_nonnull (pod); + g_assert_true (wp_spa_pod_get_float (pod, &float_value)); + g_assert_cmpfloat_with_epsilon (float_value, 0.8, 0.001); + } + + { + g_autoptr (WpSpaPod) pod = wp_spa_props_get_stored (&props, "wp-test-property"); + g_assert_nonnull (pod); + g_assert_true (wp_spa_pod_get_string (pod, &string_value)); + g_assert_cmpstr (string_value, ==, "test value"); + } wp_spa_props_clear (&props); @@ -63,10 +76,8 @@ test_spa_props_build_all (void) g_assert_true (wp_spa_type_register (WP_SPA_TYPE_TABLE_PROPS, "Wp:Test:Property", "wp-test-property")); WpSpaProps props = {0}; - WpSpaPod *pod = NULL; float float_value = 0.0; const gchar *string_value = NULL; - g_autoptr (WpSpaPod) pod_value = NULL; g_autoptr (GPtrArray) arr = NULL; const gchar *id_name; guint32 id; @@ -76,50 +87,60 @@ test_spa_props_build_all (void) wp_spa_props_register (&props, "wp-test-property", "Test property", wp_spa_pod_new_string ("default value")); - g_autoptr (WpSpaPod) new_float = wp_spa_pod_new_float (0.8); - g_autoptr (WpSpaPod) new_str = wp_spa_pod_new_string ("test value"); - g_assert_true (wp_spa_props_store (&props, "volume", new_float)); - g_assert_true (wp_spa_props_store (&props, "wp-test-property", new_str)); + { + g_autoptr (WpSpaPod) new_float = wp_spa_pod_new_float (0.8); + g_autoptr (WpSpaPod) new_str = wp_spa_pod_new_string ("test value"); + g_assert_true (wp_spa_props_store (&props, "volume", new_float)); + g_assert_true (wp_spa_props_store (&props, "wp-test-property", new_str)); + } arr = wp_spa_props_build_all_pods (&props); g_assert_nonnull (arr); g_assert_cmpint (arr->len, ==, 3); - pod = g_ptr_array_index (arr, 0); - g_assert_nonnull (pod); - g_assert_true (wp_spa_pod_get_object (pod, - "Props", &id_name, - "volume", "f", &float_value, - "wp-test-property", "s", &string_value, - NULL)); - g_assert_cmpfloat_with_epsilon (float_value, 0.8, 0.001); - g_assert_cmpstr (string_value, ==, "test value"); - - pod = g_ptr_array_index (arr, 1); - g_assert_nonnull (pod); - g_assert_true (wp_spa_pod_get_object (pod, - "PropInfo", &id_name, - "id", "I", &id, - "name", "s", &string_value, - "type", "P", &pod_value, - NULL)); - g_assert_cmpuint (id, ==, SPA_PROP_volume); - g_assert_cmpstr (string_value, ==, "Volume"); - g_assert_nonnull (pod_value); - g_assert_true (wp_spa_pod_is_choice (pod_value)); - - pod = g_ptr_array_index (arr, 2); - g_assert_nonnull (pod); - g_assert_true (wp_spa_pod_get_object (pod, - "PropInfo", &id_name, - "id", "I", &id, - "name", "s", &string_value, - "type", "P", &pod_value, - NULL)); - g_assert_cmpuint (id, >, SPA_PROP_START_CUSTOM); - g_assert_cmpstr (string_value, ==, "Test property"); - g_assert_nonnull (pod_value); - g_assert_true (wp_spa_pod_is_string (pod_value)); + { + WpSpaPod *pod = g_ptr_array_index (arr, 0); + g_assert_nonnull (pod); + g_assert_true (wp_spa_pod_get_object (pod, + "Props", &id_name, + "volume", "f", &float_value, + "wp-test-property", "s", &string_value, + NULL)); + g_assert_cmpfloat_with_epsilon (float_value, 0.8, 0.001); + g_assert_cmpstr (string_value, ==, "test value"); + } + + { + g_autoptr (WpSpaPod) pod_value = NULL; + WpSpaPod *pod = g_ptr_array_index (arr, 1); + g_assert_nonnull (pod); + g_assert_true (wp_spa_pod_get_object (pod, + "PropInfo", &id_name, + "id", "I", &id, + "name", "s", &string_value, + "type", "P", &pod_value, + NULL)); + g_assert_cmpuint (id, ==, SPA_PROP_volume); + g_assert_cmpstr (string_value, ==, "Volume"); + g_assert_nonnull (pod_value); + g_assert_true (wp_spa_pod_is_choice (pod_value)); + } + + { + g_autoptr (WpSpaPod) pod_value = NULL; + WpSpaPod *pod = g_ptr_array_index (arr, 2); + g_assert_nonnull (pod); + g_assert_true (wp_spa_pod_get_object (pod, + "PropInfo", &id_name, + "id", "I", &id, + "name", "s", &string_value, + "type", "P", &pod_value, + NULL)); + g_assert_cmpuint (id, >, SPA_PROP_START_CUSTOM); + g_assert_cmpstr (string_value, ==, "Test property"); + g_assert_nonnull (pod_value); + g_assert_true (wp_spa_pod_is_string (pod_value)); + } wp_spa_props_clear (&props); @@ -133,7 +154,6 @@ test_spa_props_store_from_props (void) g_assert_true (wp_spa_type_register (WP_SPA_TYPE_TABLE_PROPS, "Wp:Test:Property", "wp-test-property")); WpSpaProps props = {0}; - g_autoptr (WpSpaPod) pod = NULL; float float_value = 0.0; const gchar *string_value = NULL; g_autoptr (GPtrArray) arr = g_ptr_array_new_with_free_func (g_free); @@ -143,24 +163,32 @@ test_spa_props_store_from_props (void) wp_spa_props_register (&props, "wp-test-property", "Test property", wp_spa_pod_new_string ("default value")); - pod = wp_spa_pod_new_object ( - "Props", "Props", - "volume", "f", 0.8, - "wp-test-property", "s", "test value", - NULL); - g_assert_nonnull (pod); - g_assert_true (wp_spa_props_store_from_props (&props, pod, arr)); - g_assert_cmpint (arr->len, ==, 2); - g_assert_cmpstr ((const gchar *)g_ptr_array_index (arr, 0), ==, "volume"); - g_assert_cmpstr ((const gchar *)g_ptr_array_index (arr, 1), ==, "wp-test-property"); - - g_assert_nonnull (pod = wp_spa_props_get_stored (&props, "volume")); - g_assert_true (wp_spa_pod_get_float (pod, &float_value)); - g_assert_cmpfloat_with_epsilon (float_value, 0.8, 0.001); - - g_assert_nonnull (pod = wp_spa_props_get_stored (&props, "wp-test-property")); - g_assert_true (wp_spa_pod_get_string (pod, &string_value)); - g_assert_cmpstr (string_value, ==, "test value"); + { + g_autoptr (WpSpaPod) pod = wp_spa_pod_new_object ( + "Props", "Props", + "volume", "f", 0.8, + "wp-test-property", "s", "test value", + NULL); + g_assert_nonnull (pod); + g_assert_true (wp_spa_props_store_from_props (&props, pod, arr)); + g_assert_cmpint (arr->len, ==, 2); + g_assert_cmpstr ((const gchar *)g_ptr_array_index (arr, 0), ==, "volume"); + g_assert_cmpstr ((const gchar *)g_ptr_array_index (arr, 1), ==, "wp-test-property"); + } + + { + g_autoptr (WpSpaPod) pod = wp_spa_props_get_stored (&props, "volume"); + g_assert_nonnull (pod); + g_assert_true (wp_spa_pod_get_float (pod, &float_value)); + g_assert_cmpfloat_with_epsilon (float_value, 0.8, 0.001); + } + + { + g_autoptr (WpSpaPod) pod = wp_spa_props_get_stored (&props, "wp-test-property"); + g_assert_nonnull (pod); + g_assert_true (wp_spa_pod_get_string (pod, &string_value)); + g_assert_cmpstr (string_value, ==, "test value"); + } wp_spa_props_clear (&props); @@ -176,77 +204,88 @@ test_spa_props_register_from_prop_info (void) wp_spa_type_get_by_nick (WP_SPA_TYPE_TABLE_PROPS, "wp-test-property", &test_property_id, NULL, NULL); WpSpaProps props = {0}; - g_autoptr (WpSpaPod) prop_info = NULL; - WpSpaPod *pod = NULL; float float_value = 0.0; const gchar *string_value = NULL; - g_autoptr (WpSpaPod) pod_value = NULL; g_autoptr (GPtrArray) arr = NULL; const gchar *id_name; guint32 id; - prop_info = wp_spa_pod_new_object ( - "PropInfo", "PropInfo", - "id", "I", SPA_PROP_volume, - "name", "s", "Volume", - "type", SPA_POD_CHOICE_RANGE_Float (1.0, 0.0, 10.0), - NULL); - g_assert_nonnull (prop_info); - g_assert_true (wp_spa_props_register_from_prop_info (&props, prop_info)); - - prop_info = wp_spa_pod_new_object ( - "PropInfo", "PropInfo", - "id", "I", test_property_id, - "name", "s", "Test property", - "type", "s", "default value", - NULL); - g_assert_nonnull (prop_info); - g_assert_true (wp_spa_props_register_from_prop_info (&props, prop_info)); - - g_autoptr (WpSpaPod) float_pod = wp_spa_pod_new_float (0.8); - g_autoptr (WpSpaPod) string_pod = wp_spa_pod_new_string ("test value"); - g_assert_true (wp_spa_props_store (&props, "volume", float_pod)); - g_assert_true (wp_spa_props_store (&props, "wp-test-property", string_pod)); + { + g_autoptr (WpSpaPod) prop_info = wp_spa_pod_new_object ( + "PropInfo", "PropInfo", + "id", "I", SPA_PROP_volume, + "name", "s", "Volume", + "type", SPA_POD_CHOICE_RANGE_Float (1.0, 0.0, 10.0), + NULL); + g_assert_nonnull (prop_info); + g_assert_true (wp_spa_props_register_from_prop_info (&props, prop_info)); + } + + { + g_autoptr (WpSpaPod) prop_info = wp_spa_pod_new_object ( + "PropInfo", "PropInfo", + "id", "I", test_property_id, + "name", "s", "Test property", + "type", "s", "default value", + NULL); + g_assert_nonnull (prop_info); + g_assert_true (wp_spa_props_register_from_prop_info (&props, prop_info)); + } + + { + g_autoptr (WpSpaPod) float_pod = wp_spa_pod_new_float (0.8); + g_autoptr (WpSpaPod) string_pod = wp_spa_pod_new_string ("test value"); + g_assert_true (wp_spa_props_store (&props, "volume", float_pod)); + g_assert_true (wp_spa_props_store (&props, "wp-test-property", string_pod)); + } arr = wp_spa_props_build_all_pods (&props); g_assert_nonnull (arr); g_assert_cmpint (arr->len, ==, 3); - pod = g_ptr_array_index (arr, 0); - g_assert_nonnull (pod); - g_assert_true (wp_spa_pod_get_object (pod, - "Props", &id_name, - "volume", "f", &float_value, - "wp-test-property", "s", &string_value, - NULL)); - g_assert_cmpfloat_with_epsilon (float_value, 0.8, 0.001); - g_assert_cmpstr (string_value, ==, "test value"); - - pod = g_ptr_array_index (arr, 1); - g_assert_nonnull (pod); - g_assert_true (wp_spa_pod_get_object (pod, - "PropInfo", &id_name, - "id", "I", &id, - "name", "s", &string_value, - "type", "P", &pod_value, - NULL)); - g_assert_cmpuint (id, ==, SPA_PROP_volume); - g_assert_cmpstr (string_value, ==, "Volume"); - g_assert_nonnull (pod_value); - g_assert_true (wp_spa_pod_is_choice (pod_value)); - - pod = g_ptr_array_index (arr, 2); - g_assert_nonnull (pod); - g_assert_true (wp_spa_pod_get_object (pod, - "PropInfo", &id_name, - "id", "I", &id, - "name", "s", &string_value, - "type", "P", &pod_value, - NULL)); - g_assert_cmpuint (id, ==, test_property_id); - g_assert_cmpstr (string_value, ==, "Test property"); - g_assert_nonnull (pod_value); - g_assert_true (wp_spa_pod_is_string (pod_value)); + { + WpSpaPod *pod = g_ptr_array_index (arr, 0); + g_assert_nonnull (pod); + g_assert_true (wp_spa_pod_get_object (pod, + "Props", &id_name, + "volume", "f", &float_value, + "wp-test-property", "s", &string_value, + NULL)); + g_assert_cmpfloat_with_epsilon (float_value, 0.8, 0.001); + g_assert_cmpstr (string_value, ==, "test value"); + } + + { + g_autoptr (WpSpaPod) pod_value = NULL; + WpSpaPod *pod = g_ptr_array_index (arr, 1); + g_assert_nonnull (pod); + g_assert_true (wp_spa_pod_get_object (pod, + "PropInfo", &id_name, + "id", "I", &id, + "name", "s", &string_value, + "type", "P", &pod_value, + NULL)); + g_assert_cmpuint (id, ==, SPA_PROP_volume); + g_assert_cmpstr (string_value, ==, "Volume"); + g_assert_nonnull (pod_value); + g_assert_true (wp_spa_pod_is_choice (pod_value)); + } + + { + g_autoptr (WpSpaPod) pod_value = NULL; + WpSpaPod *pod = g_ptr_array_index (arr, 2); + g_assert_nonnull (pod); + g_assert_true (wp_spa_pod_get_object (pod, + "PropInfo", &id_name, + "id", "I", &id, + "name", "s", &string_value, + "type", "P", &pod_value, + NULL)); + g_assert_cmpuint (id, ==, test_property_id); + g_assert_cmpstr (string_value, ==, "Test property"); + g_assert_nonnull (pod_value); + g_assert_true (wp_spa_pod_is_string (pod_value)); + } wp_spa_props_clear (&props); -- GitLab