[gobject-introspection] tests: Test hashtables with allocated values



commit 88b42e54504747210a84fbe9551502827eef89aa
Author: Philip Chimento <philip endlessm com>
Date:   Wed Nov 2 15:00:11 2016 -0700

    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(+), 0 deletions(-)
---
diff --git a/tests/gimarshallingtests.c b/tests/gimarshallingtests.c
index 2e001c0..568492c 100644
--- a/tests/gimarshallingtests.c
+++ b/tests/gimarshallingtests.c
@@ -3109,6 +3109,90 @@ gi_marshalling_tests_ghashtable_utf8_none_in (GHashTable *hash_table)
 }
 
 /**
+ * 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 aa0210c..cd1aac3 100644
--- a/tests/gimarshallingtests.h
+++ b/tests/gimarshallingtests.h
@@ -1050,6 +1050,19 @@ _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);
 
 _GI_TEST_EXTERN


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]