From 88b42e54504747210a84fbe9551502827eef89aa Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Wed, 2 Nov 2016 15:00:11 -0700 Subject: tests: Test hashtables with allocated values In order to test GJS's support for GHashTables with float, double, gint64, and guint64 value types, here are some new GI marshalling tests. https://bugzilla.gnome.org/show_bug.cgi?id=773763 --- tests/gimarshallingtests.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++ tests/gimarshallingtests.h | 13 +++++++ 2 files changed, 97 insertions(+) diff --git a/tests/gimarshallingtests.c b/tests/gimarshallingtests.c index 2e001c02..568492c0 100644 --- a/tests/gimarshallingtests.c +++ b/tests/gimarshallingtests.c @@ -3108,6 +3108,90 @@ gi_marshalling_tests_ghashtable_utf8_none_in (GHashTable *hash_table) g_assert_cmpstr (g_hash_table_lookup (hash_table, "2"), ==, "-2"); } +/** + * gi_marshalling_tests_ghashtable_double_in: + * @hash_table: (element-type utf8 double) (transfer none): + * + * Meant to test a value type that doesn't fit inside a pointer. + */ +void +gi_marshalling_tests_ghashtable_double_in (GHashTable *hash_table) +{ + double *value; + + value = g_hash_table_lookup (hash_table, "-1"); + g_assert_cmpfloat (*value, ==, -0.1); + value = g_hash_table_lookup (hash_table, "0"); + g_assert_cmpfloat (*value, ==, 0.0); + value = g_hash_table_lookup (hash_table, "1"); + g_assert_cmpfloat (*value, ==, 0.1); + value = g_hash_table_lookup (hash_table, "2"); + g_assert_cmpfloat (*value, ==, 0.2); +} + +/** + * gi_marshalling_tests_ghashtable_float_in: + * @hash_table: (element-type utf8 float) (transfer none): + * + * Meant to test a value type that doesn't fit inside a pointer. + */ +void +gi_marshalling_tests_ghashtable_float_in (GHashTable *hash_table) +{ + float *value; + + value = g_hash_table_lookup (hash_table, "-1"); + g_assert_cmpfloat (*value, ==, -0.1f); + value = g_hash_table_lookup (hash_table, "0"); + g_assert_cmpfloat (*value, ==, 0.0f); + value = g_hash_table_lookup (hash_table, "1"); + g_assert_cmpfloat (*value, ==, 0.1f); + value = g_hash_table_lookup (hash_table, "2"); + g_assert_cmpfloat (*value, ==, 0.2f); +} + +/** + * gi_marshalling_tests_ghashtable_int64_in: + * @hash_table: (element-type utf8 gint64) (transfer none): + * + * Meant to test a value type that doesn't fit inside a pointer. + */ +void +gi_marshalling_tests_ghashtable_int64_in (GHashTable *hash_table) +{ + gint64 *value; + + value = g_hash_table_lookup (hash_table, "-1"); + g_assert_cmpint (*value, ==, -1); + value = g_hash_table_lookup (hash_table, "0"); + g_assert_cmpint (*value, ==, 0); + value = g_hash_table_lookup (hash_table, "1"); + g_assert_cmpint (*value, ==, 1); + value = g_hash_table_lookup (hash_table, "2"); + g_assert_cmpint (*value, ==, (gint64) G_MAXUINT32 + 1); +} + +/** + * gi_marshalling_tests_ghashtable_uint64_in: + * @hash_table: (element-type utf8 guint64) (transfer none): + * + * Meant to test a value type that doesn't fit inside a pointer. + */ +void +gi_marshalling_tests_ghashtable_uint64_in (GHashTable *hash_table) +{ + guint64 *value; + + value = g_hash_table_lookup (hash_table, "-1"); + g_assert_cmpuint (*value, ==, (guint64) G_MAXUINT32 + 1); + value = g_hash_table_lookup (hash_table, "0"); + g_assert_cmpuint (*value, ==, 0); + value = g_hash_table_lookup (hash_table, "1"); + g_assert_cmpuint (*value, ==, 1); + value = g_hash_table_lookup (hash_table, "2"); + g_assert_cmpuint (*value, ==, 2); +} + /** * gi_marshalling_tests_ghashtable_utf8_none_out: * @hash_table: (out) (element-type utf8 utf8) (transfer none): diff --git a/tests/gimarshallingtests.h b/tests/gimarshallingtests.h index aa0210c8..cd1aac3a 100644 --- a/tests/gimarshallingtests.h +++ b/tests/gimarshallingtests.h @@ -1049,6 +1049,19 @@ void gi_marshalling_tests_ghashtable_int_none_in (GHashTable *hash_table); _GI_TEST_EXTERN void gi_marshalling_tests_ghashtable_utf8_none_in (GHashTable *hash_table); +_GI_TEST_EXTERN +void gi_marshalling_tests_ghashtable_double_in (GHashTable *hash_table); + +_GI_TEST_EXTERN +void gi_marshalling_tests_ghashtable_float_in (GHashTable *hash_table); + +_GI_TEST_EXTERN +void gi_marshalling_tests_ghashtable_int64_in (GHashTable *hash_table); + +_GI_TEST_EXTERN +void gi_marshalling_tests_ghashtable_uint64_in (GHashTable *hash_table); + + _GI_TEST_EXTERN void gi_marshalling_tests_ghashtable_utf8_container_in (GHashTable *hash_table); -- cgit v1.2.1