summaryrefslogtreecommitdiff
path: root/tests/check/gst
diff options
context:
space:
mode:
authorNicolas Dufresne <nicolas.dufresne@collabora.com>2017-03-20 15:40:25 -0400
committerNicolas Dufresne <nicolas.dufresne@collabora.com>2017-03-24 13:30:45 -0400
commit84f826a937ea639e8a28e2a9621b09247813a01f (patch)
tree17688a2ed723a2318e1d4d6ac2193d98091b5ee1 /tests/check/gst
parent50ec7129bb82581377f9200e091c0be6c134f125 (diff)
gstvalue: Add transformation to/from GValueArray
This allow transforming a GValue of type G_TYPE_VALUE_ARRAY to and from GST_TYPE_ARRAY/LIST. https://bugzilla.gnome.org/show_bug.cgi?id=753754
Diffstat (limited to 'tests/check/gst')
-rw-r--r--tests/check/gst/gstvalue.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/tests/check/gst/gstvalue.c b/tests/check/gst/gstvalue.c
index 644d244c1..9d3ae43bd 100644
--- a/tests/check/gst/gstvalue.c
+++ b/tests/check/gst/gstvalue.c
@@ -21,6 +21,7 @@
*/
+#define GLIB_DISABLE_DEPRECATION_WARNINGS
#include <gst/check/gstcheck.h>
@@ -3311,6 +3312,85 @@ GST_START_TEST (test_structure_ops)
GST_END_TEST;
+static void
+setup_test_value_array (GValue * value)
+{
+ GValueArray *array;
+ GValue v = G_VALUE_INIT;
+
+ g_value_init (&v, G_TYPE_INT);
+ g_value_init (value, G_TYPE_VALUE_ARRAY);
+
+ array = g_value_array_new (3);
+ g_value_set_int (&v, 1);
+ g_value_array_append (array, &v);
+ g_value_set_int (&v, 2);
+ g_value_array_append (array, &v);
+ g_value_set_int (&v, 3);
+ g_value_array_append (array, &v);
+
+ g_value_take_boxed (value, array);
+}
+
+static void
+test_revert_array_transform (GValue * v1, GValue * v2)
+{
+ GValueArray *array;
+
+ g_value_reset (v1);
+
+ fail_unless (g_value_transform (v2, v1));
+ array = g_value_get_boxed (v1);
+ fail_unless (array->n_values == 3);
+ fail_unless (g_value_get_int (g_value_array_get_nth (array, 0)) == 1);
+ fail_unless (g_value_get_int (g_value_array_get_nth (array, 1)) == 2);
+ fail_unless (g_value_get_int (g_value_array_get_nth (array, 2)) == 3);
+}
+
+GST_START_TEST (test_transform_array)
+{
+ GValue v1 = G_VALUE_INIT, v2 = G_VALUE_INIT;
+
+ setup_test_value_array (&v1);
+
+ g_value_init (&v2, GST_TYPE_ARRAY);
+
+ fail_unless (g_value_transform (&v1, &v2));
+ fail_unless (gst_value_array_get_size (&v2) == 3);
+ fail_unless (g_value_get_int (gst_value_array_get_value (&v2, 0)) == 1);
+ fail_unless (g_value_get_int (gst_value_array_get_value (&v2, 1)) == 2);
+ fail_unless (g_value_get_int (gst_value_array_get_value (&v2, 2)) == 3);
+
+ test_revert_array_transform (&v1, &v2);
+
+ g_value_unset (&v1);
+ g_value_unset (&v2);
+}
+
+GST_END_TEST;
+
+GST_START_TEST (test_transform_list)
+{
+ GValue v1 = G_VALUE_INIT, v2 = G_VALUE_INIT;
+
+ setup_test_value_array (&v1);
+
+ g_value_init (&v2, GST_TYPE_LIST);
+
+ fail_unless (g_value_transform (&v1, &v2));
+ fail_unless (gst_value_list_get_size (&v2) == 3);
+ fail_unless (g_value_get_int (gst_value_list_get_value (&v2, 0)) == 1);
+ fail_unless (g_value_get_int (gst_value_list_get_value (&v2, 1)) == 2);
+ fail_unless (g_value_get_int (gst_value_list_get_value (&v2, 2)) == 3);
+
+ test_revert_array_transform (&v1, &v2);
+
+ g_value_unset (&v1);
+ g_value_unset (&v2);
+}
+
+GST_END_TEST;
+
static Suite *
gst_value_suite (void)
{
@@ -3360,6 +3440,8 @@ gst_value_suite (void)
tcase_add_test (tc_chain, test_structure_basic);
tcase_add_test (tc_chain, test_structure_single_ops);
tcase_add_test (tc_chain, test_structure_ops);
+ tcase_add_test (tc_chain, test_transform_array);
+ tcase_add_test (tc_chain, test_transform_list);
return s;
}