From 3e2cca38b6b923fad018b56ab5f497a208170159 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 23 Aug 2020 16:50:30 +0100 Subject: tests: Add a test-case for a vfunc returning flags in different ways We already had a test for enums, but flags are not precisely the same, so testing both can give bindings better coverage. Signed-off-by: Simon McVittie --- tests/gimarshallingtests.c | 27 +++++++++++++++++++++++++++ tests/gimarshallingtests.h | 17 +++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/tests/gimarshallingtests.c b/tests/gimarshallingtests.c index 53c17818..fbb1273e 100644 --- a/tests/gimarshallingtests.c +++ b/tests/gimarshallingtests.c @@ -4767,6 +4767,33 @@ gi_marshalling_tests_object_vfunc_out_enum (GIMarshallingTestsObject *self, GIMa g_assert_cmpint (local, ==, 0x12345678); } +/** + * gi_marshalling_tests_object_vfunc_return_flags: + */ +GIMarshallingTestsFlags +gi_marshalling_tests_object_vfunc_return_flags (GIMarshallingTestsObject *self) +{ + /* make sure that local variables don't get smashed */ + GIMarshallingTestsFlags return_value; + glong local = 0x12345678; + return_value = GI_MARSHALLING_TESTS_OBJECT_GET_CLASS (self)->vfunc_return_flags (self); + g_assert_cmpint (local, ==, 0x12345678); + return return_value; +} + +/** + * gi_marshalling_tests_object_vfunc_out_flags: + * @flags: (out): + */ +void +gi_marshalling_tests_object_vfunc_out_flags (GIMarshallingTestsObject *self, GIMarshallingTestsFlags *flags) +{ + /* make sure that local variables don't get smashed */ + gulong local = 0x12345678; + GI_MARSHALLING_TESTS_OBJECT_GET_CLASS (self)->vfunc_out_flags (self, flags); + g_assert_cmpuint (local, ==, 0x12345678); +} + /* NOTE: * diff --git a/tests/gimarshallingtests.h b/tests/gimarshallingtests.h index 747a075d..656cadd9 100644 --- a/tests/gimarshallingtests.h +++ b/tests/gimarshallingtests.h @@ -1515,6 +1515,17 @@ struct _GIMarshallingTestsObjectClass * @object: (in) (transfer full): */ void (* vfunc_in_object_transfer_full) (GIMarshallingTestsObject *self, GObject *object); + + /** + * GIMarshallingTestsObjectClass::vfunc_return_flags: + */ + GIMarshallingTestsFlags (* vfunc_return_flags) (GIMarshallingTestsObject *self); + + /** + * GIMarshallingTestsObjectClass::vfunc_out_flags: + * @flags: (out): + */ + void (* vfunc_out_flags) (GIMarshallingTestsObject *self, GIMarshallingTestsFlags *flags); }; struct _GIMarshallingTestsObject @@ -1620,6 +1631,12 @@ GIMarshallingTestsEnum gi_marshalling_tests_object_vfunc_return_enum (GIMarshall _GI_TEST_EXTERN void gi_marshalling_tests_object_vfunc_out_enum (GIMarshallingTestsObject *self, GIMarshallingTestsEnum *_enum); +_GI_TEST_EXTERN +GIMarshallingTestsFlags gi_marshalling_tests_object_vfunc_return_flags (GIMarshallingTestsObject *self); + +_GI_TEST_EXTERN +void gi_marshalling_tests_object_vfunc_out_flags (GIMarshallingTestsObject *self, GIMarshallingTestsFlags *flags); + _GI_TEST_EXTERN void gi_marshalling_tests_object_get_ref_info_for_vfunc_return_object_transfer_none (GIMarshallingTestsObject *self, guint *ref_count, gboolean *is_floating); -- cgit v1.2.1 From 503723cf4472d70fd7c7e21a6137a82a6b116e18 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 23 Aug 2020 18:32:59 +0100 Subject: gimarshallingtests: Add more tests for flags Bindings sometimes need to handle flags and enums separately, so everything that is tested for enums should ideally be tested separately for flags. Signed-off-by: Simon McVittie --- tests/gimarshallingtests.c | 24 ++++++++++++++++++++++++ tests/gimarshallingtests.h | 6 ++++++ 2 files changed, 30 insertions(+) diff --git a/tests/gimarshallingtests.c b/tests/gimarshallingtests.c index fbb1273e..571b7a2e 100644 --- a/tests/gimarshallingtests.c +++ b/tests/gimarshallingtests.c @@ -1522,6 +1522,20 @@ gi_marshalling_tests_array_enum_in (GIMarshallingTestsEnum *v, gint length) g_assert_cmpint (v[2], ==, GI_MARSHALLING_TESTS_ENUM_VALUE3); } +/** + * gi_marshalling_tests_array_flags_in: + * @flags: (array length=length) (transfer none): + * @length: + */ +void +gi_marshalling_tests_array_flags_in (GIMarshallingTestsFlags *v, gint length) +{ + g_assert_cmpint (length, ==, 3); + g_assert_cmpint (v[0], ==, GI_MARSHALLING_TESTS_FLAGS_VALUE1); + g_assert_cmpint (v[1], ==, GI_MARSHALLING_TESTS_FLAGS_VALUE2); + g_assert_cmpint (v[2], ==, GI_MARSHALLING_TESTS_FLAGS_VALUE3); +} + /** * gi_marshalling_tests_array_in_guint64_len: * @ints: (array length=length) (transfer none): @@ -3434,6 +3448,16 @@ gi_marshalling_tests_gvalue_in_enum (GValue *value) g_assert (g_value_get_enum (value) == GI_MARSHALLING_TESTS_ENUM_VALUE3); } +/** + * gi_marshalling_tests_gvalue_in_flags: + * @value: (transfer none): + */ +void +gi_marshalling_tests_gvalue_in_flags (GValue *value) +{ + g_assert_cmpint (g_value_get_flags (value), ==, GI_MARSHALLING_TESTS_FLAGS_VALUE3); +} + /** * gi_marshalling_tests_gvalue_out: * @value: (out) (transfer none): diff --git a/tests/gimarshallingtests.h b/tests/gimarshallingtests.h index 656cadd9..5df1035e 100644 --- a/tests/gimarshallingtests.h +++ b/tests/gimarshallingtests.h @@ -748,6 +748,9 @@ void gi_marshalling_tests_multi_array_key_value_in (gint length, const gchar **k _GI_TEST_EXTERN void gi_marshalling_tests_array_enum_in (GIMarshallingTestsEnum *_enum, gint length); +_GI_TEST_EXTERN +void gi_marshalling_tests_array_flags_in (GIMarshallingTestsFlags *flags, gint length); + _GI_TEST_EXTERN void gi_marshalling_tests_array_in_guint64_len (const gint *ints, guint64 length); @@ -1117,6 +1120,9 @@ void gi_marshalling_tests_gvalue_in_with_modification (GValue *value); _GI_TEST_EXTERN void gi_marshalling_tests_gvalue_in_enum (GValue *value); +_GI_TEST_EXTERN +void gi_marshalling_tests_gvalue_in_flags (GValue *value); + _GI_TEST_EXTERN void gi_marshalling_tests_gvalue_out (GValue **value); -- cgit v1.2.1 From ae2952e6167be60663d587a605e38e97d5f4978c Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 23 Aug 2020 18:34:04 +0100 Subject: girmarshalling tests: Diagnose GValue not holding enum/flags If g_value_get_enum() or g_value_get_flags() is about to fail with a precondition check failure, we can improve diagnostics by issuing a more informative critical warning. Signed-off-by: Simon McVittie --- tests/gimarshallingtests.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/gimarshallingtests.c b/tests/gimarshallingtests.c index 571b7a2e..483fb619 100644 --- a/tests/gimarshallingtests.c +++ b/tests/gimarshallingtests.c @@ -3445,6 +3445,8 @@ gi_marshalling_tests_gvalue_in_with_modification (GValue *value) void gi_marshalling_tests_gvalue_in_enum (GValue *value) { + if (!G_VALUE_HOLDS_ENUM (value)) + g_critical ("Expected enum, got %s", G_VALUE_TYPE_NAME (value)); g_assert (g_value_get_enum (value) == GI_MARSHALLING_TESTS_ENUM_VALUE3); } @@ -3455,6 +3457,8 @@ gi_marshalling_tests_gvalue_in_enum (GValue *value) void gi_marshalling_tests_gvalue_in_flags (GValue *value) { + if (!G_VALUE_HOLDS_FLAGS (value)) + g_critical ("Expected flags, got %s", G_VALUE_TYPE_NAME (value)); g_assert_cmpint (g_value_get_flags (value), ==, GI_MARSHALLING_TESTS_FLAGS_VALUE3); } -- cgit v1.2.1