[gobject-introspection] fixes and more tests for marshalling of arrays of gvariants
- From: Martin Pitt <martinpitt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection] fixes and more tests for marshalling of arrays of gvariants
- Date: Tue, 25 Oct 2011 06:47:08 +0000 (UTC)
commit e05ed0f9c1de597cb6f925505f58cb919a5bf1c4
Author: Mikkel Kamstrup Erlandsen <mikkel kamstrup canonical com>
Date: Tue Oct 4 12:01:42 2011 +0200
fixes and more tests for marshalling of arrays of gvariants
Fix return type annotation for gi_marshalling_tests_array_gvariant_in()
Add function variations of gi_marshalling_tests_array_gvariant_i() with
different transfer modes.
Make gi_marshalling_tests_array_gvariant_none_in() actually respect
the transfer none annotation on the return value.
https://bugzilla.gnome.org/show_bug.cgi?id=638915
Signed-off-by: Martin Pitt <martin pitt ubuntu com>
tests/gimarshallingtests.c | 65 +++++++++++++++++++++++++++++++++++++++++--
tests/gimarshallingtests.h | 6 +++-
2 files changed, 67 insertions(+), 4 deletions(-)
---
diff --git a/tests/gimarshallingtests.c b/tests/gimarshallingtests.c
index 637c7d5..073d153 100644
--- a/tests/gimarshallingtests.c
+++ b/tests/gimarshallingtests.c
@@ -1578,18 +1578,77 @@ gi_marshalling_tests_array_zero_terminated_inout (gchar ***utf8s)
}
/**
- * gi_marshalling_tests_array_gvariant_in:
+ * gi_marshalling_tests_array_gvariant_none_in:
* @variants: (array zero-terminated=1) (transfer none):
+ * Returns: (array zero-terminated=1) (transfer none):
+ */
+GVariant **
+gi_marshalling_tests_array_gvariant_none_in (GVariant **variants)
+{
+ /* Use a static container to detect if someone tries to free it */
+ static GVariant *private_container[3] = { NULL, NULL, NULL };
+
+ if (private_container[0] == NULL) {
+ private_container[0] = g_variant_new_int32 (27);
+ private_container[1] = g_variant_new_string ("Hello");
+ }
+
+ g_assert (variants != NULL);
+ g_assert_cmpint (g_variant_get_int32 (variants[0]), ==, 27);
+ g_assert_cmpstr (g_variant_get_string (variants[1], NULL), ==, "Hello");
+ g_assert (variants[2] == NULL);
+
+ return private_container;
+}
+
+/**
+ * gi_marshalling_tests_array_gvariant_container_in:
+ * @variants: (array zero-terminated=1) (transfer container):
+ * Returns: (array zero-terminated=1) (transfer container):
*/
GVariant **
-gi_marshalling_tests_array_gvariant_in (GVariant **variants)
+gi_marshalling_tests_array_gvariant_container_in (GVariant **variants)
{
+ GVariant **container;
+
g_assert (variants != NULL);
g_assert_cmpint (g_variant_get_int32 (variants[0]), ==, 27);
g_assert_cmpstr (g_variant_get_string (variants[1], NULL), ==, "Hello");
g_assert (variants[2] == NULL);
+
+ container = g_new0 (GVariant*, 3);
+ container[0] = variants[0];
+ container[1] = variants[1];
+ g_free (variants);
+
+ return container;
+}
+
+/**
+ * gi_marshalling_tests_array_gvariant_full_in:
+ * @variants: (array zero-terminated=1) (transfer full):
+ * Returns: (array zero-terminated=1) (transfer full):
+ */
+GVariant **
+gi_marshalling_tests_array_gvariant_full_in (GVariant **variants)
+{
+ GVariant **container;
- return variants;
+ g_assert (variants != NULL);
+ g_assert_cmpint (g_variant_get_int32 (variants[0]), ==, 27);
+ g_assert_cmpstr (g_variant_get_string (variants[1], NULL), ==, "Hello");
+ g_assert (variants[2] == NULL);
+
+ /* To catch different behaviors we reconstruct one variant from scratch,
+ * while leaving the other untouched. Both approaches are legal with full
+ * transfer in and out */
+ container = g_new0 (GVariant*, 3);
+ container[0] = g_variant_new_int32 (g_variant_get_int32 (variants[0]));
+ g_variant_unref (variants[0]);
+ container[1] = variants[1];
+ g_free (variants);
+
+ return container;
}
/**
diff --git a/tests/gimarshallingtests.h b/tests/gimarshallingtests.h
index 81c3a50..388ee05 100644
--- a/tests/gimarshallingtests.h
+++ b/tests/gimarshallingtests.h
@@ -403,7 +403,11 @@ void gi_marshalling_tests_array_zero_terminated_out (gchar ***utf8s);
void gi_marshalling_tests_array_zero_terminated_inout (gchar ***utf8s);
-GVariant **gi_marshalling_tests_array_gvariant_in (GVariant **variants);
+GVariant **gi_marshalling_tests_array_gvariant_none_in (GVariant **variants);
+
+GVariant **gi_marshalling_tests_array_gvariant_container_in (GVariant **variants);
+
+GVariant **gi_marshalling_tests_array_gvariant_full_in (GVariant **variants);
/* GArray */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]