summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiovanni Campagna <gcampagna@src.gnome.org>2011-05-12 23:38:17 +0200
committerColin Walters <walters@verbum.org>2011-06-13 18:45:17 -0400
commitb62e22c0633f897435125ebf5812d5f419b3937e (patch)
tree22deb007dd8906002b84ed15a79ff4436b18aee9
parent88e8592c5bb8709c035865f084e104db54564a89 (diff)
downloadgobject-introspection-b62e22c0633f897435125ebf5812d5f419b3937e.tar.gz
Add tests for complex arrays as in argumentsGOBJECT_INTROSPECTION_1_29_0
Previously gjs supported only arrays of integers. Now that this changed, we need tests to avoid regressions. https://bugzilla.gnome.org/show_bug.cgi?id=646632
-rw-r--r--tests/gimarshallingtests.c136
-rw-r--r--tests/gimarshallingtests.h192
2 files changed, 235 insertions, 93 deletions
diff --git a/tests/gimarshallingtests.c b/tests/gimarshallingtests.c
index 7275f795..2f7eef83 100644
--- a/tests/gimarshallingtests.c
+++ b/tests/gimarshallingtests.c
@@ -6,6 +6,7 @@
#include <string.h>
+static void gi_marshalling_tests_boxed_struct_free (GIMarshallingTestsBoxedStruct *struct_);
/* Booleans */
@@ -1233,6 +1234,7 @@ gi_marshalling_tests_array_return_etc (gint first, gint *length, gint last, gint
/**
* gi_marshalling_tests_array_in:
* @ints: (array length=length):
+ * @length:
*/
void
gi_marshalling_tests_array_in (const gint *ints, gint length)
@@ -1245,6 +1247,48 @@ gi_marshalling_tests_array_in (const gint *ints, gint length)
}
/**
+ * gi_marshalling_tests_array_in_len_before:
+ * @length:
+ * @ints: (array length=length):
+ */
+void
+gi_marshalling_tests_array_in_len_before (gint length, const gint *ints)
+{
+ gi_marshalling_tests_array_in (ints, length);
+}
+
+/**
+ * gi_marshalling_tests_array_in_len_zero_terminated:
+ * @ints: (array length=length zero-terminated=1):
+ * @length:
+ */
+void
+gi_marshalling_tests_array_in_len_zero_terminated (const gint *ints, gint length)
+{
+ g_assert (length == 4);
+
+ g_assert (ints[0] == -1);
+ g_assert (ints[1] == 0);
+ g_assert (ints[2] == 1);
+ g_assert (ints[3] == 2);
+
+ /* One past the end, null terminator */
+ g_assert (ints[4] == 0);
+}
+
+/**
+ * gi_marshalling_tests_array_string_in:
+ * @strings: (array length=length):
+ */
+void
+gi_marshalling_tests_array_string_in (const gchar **strings, gint length)
+{
+ g_assert(length == 2);
+ g_assert(g_strcmp0(strings[0], "foo") == 0);
+ g_assert(g_strcmp0(strings[1], "bar") == 0);
+}
+
+/**
* gi_marshalling_tests_array_uint8_in:
* @chars: (array length=length):
*/
@@ -1259,6 +1303,98 @@ gi_marshalling_tests_array_uint8_in (const guint8 *chars, gint length)
}
/**
+ * gi_marshalling_tests_array_struct_in:
+ * @structs: (array length=length):
+ */
+void
+gi_marshalling_tests_array_struct_in (GIMarshallingTestsBoxedStruct **structs, gint length)
+{
+ g_assert(length == 3);
+ g_assert(structs[0]->long_ == 1);
+ g_assert(structs[1]->long_ == 2);
+ g_assert(structs[2]->long_ == 3);
+}
+
+/**
+ * gi_marshalling_tests_array_struct_take_in:
+ * @structs: (array length=length) (transfer full):
+ */
+void
+gi_marshalling_tests_array_struct_take_in (GIMarshallingTestsBoxedStruct **structs, gint length)
+{
+ gi_marshalling_tests_array_struct_in (structs, length);
+
+ /* only really useful if run in valgrind actually */
+ gi_marshalling_tests_boxed_struct_free (structs[0]);
+ gi_marshalling_tests_boxed_struct_free (structs[1]);
+ gi_marshalling_tests_boxed_struct_free (structs[2]);
+ g_free (structs);
+}
+
+/**
+ * gi_marshalling_tests_array_enum_in:
+ * @_enum: (array length=length) (transfer none):
+ * @length:
+ */
+void
+gi_marshalling_tests_array_enum_in (GIMarshallingTestsEnum *_enum, gint length)
+{
+ g_assert (length == 3);
+ g_assert (_enum[0] == GI_MARSHALLING_TESTS_ENUM_VALUE1);
+ g_assert (_enum[1] == GI_MARSHALLING_TESTS_ENUM_VALUE2);
+ g_assert (_enum[2] == GI_MARSHALLING_TESTS_ENUM_VALUE3);
+}
+
+/**
+ * gi_marshalling_tests_array_nested_in:
+ * @list: (array length=length) (element-type GSList<gint>):
+ * @length:
+ */
+void
+gi_marshalling_tests_array_nested_in (GSList **list, gint length)
+{
+ g_assert (length == 3);
+
+ g_assert (g_slist_length (list[0]) == 1);
+ g_assert (list[0]->data == GINT_TO_POINTER (11));
+
+ g_assert (g_slist_length (list[1]) == 3);
+ g_assert (list[1]->data == GINT_TO_POINTER (21));
+ g_assert (list[1]->next->data == GINT_TO_POINTER (22));
+ g_assert (list[1]->next->next->data == GINT_TO_POINTER (23));
+
+ g_assert (g_slist_length (list[2]) == 2);
+ g_assert (list[2]->data == GINT_TO_POINTER (31));
+ g_assert (list[2]->next->data == GINT_TO_POINTER (32));
+}
+
+/**
+ * gi_marshalling_tests_array_in_guint64_len:
+ * @ints: (array length=length) (transfer none):
+ * @length:
+ */
+void
+gi_marshalling_tests_array_in_guint64_len (const gint *ints, guint64 length)
+{
+ g_assert (length == 4);
+
+ gi_marshalling_tests_array_in (ints, length);
+}
+
+/**
+ * gi_marshalling_tests_array_in_guint8_len:
+ * @ints: (array length=length) (transfer none):
+ * @length:
+ */
+void
+gi_marshalling_tests_array_in_guint8_len (const gint *ints, guint8 length)
+{
+ g_assert (length == 4);
+
+ gi_marshalling_tests_array_in (ints, length);
+}
+
+/**
* gi_marshalling_tests_array_out:
* @ints: (out) (array length=length) (transfer none):
*/
diff --git a/tests/gimarshallingtests.h b/tests/gimarshallingtests.h
index ef80a4cf..7a8ec067 100644
--- a/tests/gimarshallingtests.h
+++ b/tests/gimarshallingtests.h
@@ -261,6 +261,96 @@ void gi_marshalling_tests_utf8_full_inout (gchar **utf8);
GSList *gi_marshalling_tests_filename_list_return (void);
+/* Enum */
+
+typedef enum
+{
+ GI_MARSHALLING_TESTS_ENUM_VALUE1,
+ GI_MARSHALLING_TESTS_ENUM_VALUE2,
+ GI_MARSHALLING_TESTS_ENUM_VALUE3 = 42
+} GIMarshallingTestsEnum;
+
+typedef enum
+{
+ GI_MARSHALLING_TESTS_SECOND_ENUM_SECONDVALUE1,
+ GI_MARSHALLING_TESTS_SECOND_ENUM_SECONDVALUE2,
+} GIMarshallingTestsSecondEnum;
+
+GIMarshallingTestsEnum gi_marshalling_tests_enum_returnv (void);
+
+void gi_marshalling_tests_enum_in (GIMarshallingTestsEnum enum_);
+
+void gi_marshalling_tests_enum_out (GIMarshallingTestsEnum *enum_);
+
+void gi_marshalling_tests_enum_inout (GIMarshallingTestsEnum *enum_);
+
+
+/* GEnum */
+
+typedef enum
+{
+ GI_MARSHALLING_TESTS_GENUM_VALUE1,
+ GI_MARSHALLING_TESTS_GENUM_VALUE2,
+ GI_MARSHALLING_TESTS_GENUM_VALUE3 = 42
+} GIMarshallingTestsGEnum;
+
+GType gi_marshalling_tests_genum_get_type (void) G_GNUC_CONST;
+#define GI_MARSHALLING_TESTS_TYPE_GENUM (gi_marshalling_tests_genum_get_type ())
+
+GIMarshallingTestsEnum gi_marshalling_tests_genum_returnv (void);
+
+void gi_marshalling_tests_genum_in (GIMarshallingTestsGEnum enum_);
+
+void gi_marshalling_tests_genum_out (GIMarshallingTestsGEnum *enum_);
+
+void gi_marshalling_tests_genum_inout (GIMarshallingTestsGEnum *enum_);
+
+
+/* GFlags */
+
+typedef enum
+{
+ GI_MARSHALLING_TESTS_FLAGS_VALUE1 = 1 << 0,
+ GI_MARSHALLING_TESTS_FLAGS_VALUE2 = 1 << 1,
+ GI_MARSHALLING_TESTS_FLAGS_VALUE3 = 1 << 2,
+ GI_MARSHALLING_TESTS_FLAGS_MASK = GI_MARSHALLING_TESTS_FLAGS_VALUE1 |
+ GI_MARSHALLING_TESTS_FLAGS_VALUE2,
+ GI_MARSHALLING_TESTS_FLAGS_MASK2 = GI_MARSHALLING_TESTS_FLAGS_MASK
+} GIMarshallingTestsFlags;
+
+GType gi_marshalling_tests_flags_get_type (void) G_GNUC_CONST;
+#define GI_MARSHALLING_TESTS_TYPE_FLAGS (gi_marshalling_tests_flags_get_type ())
+
+GIMarshallingTestsFlags gi_marshalling_tests_flags_returnv (void);
+
+void gi_marshalling_tests_flags_in (GIMarshallingTestsFlags flags_);
+void gi_marshalling_tests_flags_in_zero (GIMarshallingTestsFlags flags);
+
+void gi_marshalling_tests_flags_out (GIMarshallingTestsFlags *flags_);
+
+void gi_marshalling_tests_flags_inout (GIMarshallingTestsFlags *flags_);
+
+/* Flags with no GType */
+
+typedef enum
+{
+ GI_MARSHALLING_TESTS_NO_TYPE_FLAGS_VALUE1 = 1 << 0,
+ GI_MARSHALLING_TESTS_NO_TYPE_FLAGS_VALUE2 = 1 << 1,
+ GI_MARSHALLING_TESTS_NO_TYPE_FLAGS_VALUE3 = 1 << 2,
+ GI_MARSHALLING_TESTS_NO_TYPE_FLAGS_MASK = GI_MARSHALLING_TESTS_NO_TYPE_FLAGS_VALUE1 |
+ GI_MARSHALLING_TESTS_NO_TYPE_FLAGS_VALUE2,
+ GI_MARSHALLING_TESTS_NO_TYPE_FLAGS_MASK2 = GI_MARSHALLING_TESTS_FLAGS_MASK
+} GIMarshallingTestsNoTypeFlags;
+
+GIMarshallingTestsNoTypeFlags gi_marshalling_tests_no_type_flags_returnv (void);
+
+void gi_marshalling_tests_no_type_flags_in (GIMarshallingTestsNoTypeFlags flags_);
+void gi_marshalling_tests_no_type_flags_in_zero (GIMarshallingTestsNoTypeFlags flags);
+
+void gi_marshalling_tests_no_type_flags_out (GIMarshallingTestsNoTypeFlags *flags_);
+
+void gi_marshalling_tests_no_type_flags_inout (GIMarshallingTestsNoTypeFlags *flags_);
+
/* Arrays */
/* Fixed-size */
@@ -282,8 +372,16 @@ const gint *gi_marshalling_tests_array_return (gint *length);
const gint *gi_marshalling_tests_array_return_etc (gint first, gint *length, gint last, gint *sum);
void gi_marshalling_tests_array_in (const gint *ints, gint length);
-
+void gi_marshalling_tests_array_in_len_before (gint length, const gint *ints);
+void gi_marshalling_tests_array_in_len_zero_terminated (const gint *ints, gint length);
+void gi_marshalling_tests_array_string_in (const gchar **strings, gint length);
void gi_marshalling_tests_array_uint8_in (const guint8 *chars, gint length);
+void gi_marshalling_tests_array_struct_in (GIMarshallingTestsBoxedStruct **structs, gint length);
+void gi_marshalling_tests_array_struct_take_in (GIMarshallingTestsBoxedStruct **structs, gint length);
+void gi_marshalling_tests_array_enum_in (GIMarshallingTestsEnum *_enum, gint length);
+void gi_marshalling_tests_array_nested_in (GSList **list, gint length);
+void gi_marshalling_tests_array_in_guint64_len (const gint *ints, guint64 length);
+void gi_marshalling_tests_array_in_guint8_len (const gint *ints, guint8 length);
void gi_marshalling_tests_array_out (gint **ints, gint *length);
void gi_marshalling_tests_array_out_etc (gint first, gint **ints, gint *length, gint last, gint *sum);
@@ -420,98 +518,6 @@ GClosure *gi_marshalling_tests_gclosure_return (void);
gpointer gi_marshalling_tests_pointer_in_return (gpointer pointer);
-
-/* Enum */
-
-typedef enum
-{
- GI_MARSHALLING_TESTS_ENUM_VALUE1,
- GI_MARSHALLING_TESTS_ENUM_VALUE2,
- GI_MARSHALLING_TESTS_ENUM_VALUE3 = 42
-} GIMarshallingTestsEnum;
-
-typedef enum
-{
- GI_MARSHALLING_TESTS_SECOND_ENUM_SECONDVALUE1,
- GI_MARSHALLING_TESTS_SECOND_ENUM_SECONDVALUE2,
-} GIMarshallingTestsSecondEnum;
-
-GIMarshallingTestsEnum gi_marshalling_tests_enum_returnv (void);
-
-void gi_marshalling_tests_enum_in (GIMarshallingTestsEnum enum_);
-
-void gi_marshalling_tests_enum_out (GIMarshallingTestsEnum *enum_);
-
-void gi_marshalling_tests_enum_inout (GIMarshallingTestsEnum *enum_);
-
-
-/* GEnum */
-
-typedef enum
-{
- GI_MARSHALLING_TESTS_GENUM_VALUE1,
- GI_MARSHALLING_TESTS_GENUM_VALUE2,
- GI_MARSHALLING_TESTS_GENUM_VALUE3 = 42
-} GIMarshallingTestsGEnum;
-
-GType gi_marshalling_tests_genum_get_type (void) G_GNUC_CONST;
-#define GI_MARSHALLING_TESTS_TYPE_GENUM (gi_marshalling_tests_genum_get_type ())
-
-GIMarshallingTestsEnum gi_marshalling_tests_genum_returnv (void);
-
-void gi_marshalling_tests_genum_in (GIMarshallingTestsGEnum enum_);
-
-void gi_marshalling_tests_genum_out (GIMarshallingTestsGEnum *enum_);
-
-void gi_marshalling_tests_genum_inout (GIMarshallingTestsGEnum *enum_);
-
-
-/* GFlags */
-
-typedef enum
-{
- GI_MARSHALLING_TESTS_FLAGS_VALUE1 = 1 << 0,
- GI_MARSHALLING_TESTS_FLAGS_VALUE2 = 1 << 1,
- GI_MARSHALLING_TESTS_FLAGS_VALUE3 = 1 << 2,
- GI_MARSHALLING_TESTS_FLAGS_MASK = GI_MARSHALLING_TESTS_FLAGS_VALUE1 |
- GI_MARSHALLING_TESTS_FLAGS_VALUE2,
- GI_MARSHALLING_TESTS_FLAGS_MASK2 = GI_MARSHALLING_TESTS_FLAGS_MASK
-} GIMarshallingTestsFlags;
-
-GType gi_marshalling_tests_flags_get_type (void) G_GNUC_CONST;
-#define GI_MARSHALLING_TESTS_TYPE_FLAGS (gi_marshalling_tests_flags_get_type ())
-
-GIMarshallingTestsFlags gi_marshalling_tests_flags_returnv (void);
-
-void gi_marshalling_tests_flags_in (GIMarshallingTestsFlags flags_);
-void gi_marshalling_tests_flags_in_zero (GIMarshallingTestsFlags flags);
-
-void gi_marshalling_tests_flags_out (GIMarshallingTestsFlags *flags_);
-
-void gi_marshalling_tests_flags_inout (GIMarshallingTestsFlags *flags_);
-
-/* Flags with no GType */
-
-typedef enum
-{
- GI_MARSHALLING_TESTS_NO_TYPE_FLAGS_VALUE1 = 1 << 0,
- GI_MARSHALLING_TESTS_NO_TYPE_FLAGS_VALUE2 = 1 << 1,
- GI_MARSHALLING_TESTS_NO_TYPE_FLAGS_VALUE3 = 1 << 2,
- GI_MARSHALLING_TESTS_NO_TYPE_FLAGS_MASK = GI_MARSHALLING_TESTS_NO_TYPE_FLAGS_VALUE1 |
- GI_MARSHALLING_TESTS_NO_TYPE_FLAGS_VALUE2,
- GI_MARSHALLING_TESTS_NO_TYPE_FLAGS_MASK2 = GI_MARSHALLING_TESTS_FLAGS_MASK
-} GIMarshallingTestsNoTypeFlags;
-
-GIMarshallingTestsNoTypeFlags gi_marshalling_tests_no_type_flags_returnv (void);
-
-void gi_marshalling_tests_no_type_flags_in (GIMarshallingTestsNoTypeFlags flags_);
-void gi_marshalling_tests_no_type_flags_in_zero (GIMarshallingTestsNoTypeFlags flags);
-
-void gi_marshalling_tests_no_type_flags_out (GIMarshallingTestsNoTypeFlags *flags_);
-
-void gi_marshalling_tests_no_type_flags_inout (GIMarshallingTestsNoTypeFlags *flags_);
-
-
/* Structure */
struct _GIMarshallingTestsSimpleStruct {