[pygobject] flags: Add testcase for bug 786948



commit 5f41add624990255dfebf2d726af946599f7bcf6
Author: Christoph Reiter <creiter src gnome org>
Date:   Mon Oct 23 12:41:45 2017 +0200

    flags: Add testcase for bug 786948
    
    Add a flags type which has a value with the highes bit set
    and fits in an int. While the C type is a signed int, the type
    is registered as flags, which GI interprets as unsigned.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=786948

 tests/gimarshallingtestsextra.c |   29 +++++++++++++++++++++++++++++
 tests/gimarshallingtestsextra.h |   11 +++++++++++
 tests/test_gi.py                |    5 +++++
 3 files changed, 45 insertions(+), 0 deletions(-)
---
diff --git a/tests/gimarshallingtestsextra.c b/tests/gimarshallingtestsextra.c
index 3f4dcac..ae6a033 100644
--- a/tests/gimarshallingtestsextra.c
+++ b/tests/gimarshallingtestsextra.c
@@ -125,3 +125,32 @@ gi_marshalling_tests_enum_array_return_type (gsize *n_members)
 
   return res;
 }
+
+GType
+gi_marshalling_tests_extra_flags_get_type (void)
+{
+  static GType type = 0;
+  if (G_UNLIKELY (type == 0))
+    {
+      static const GFlagsValue values[] = {
+        {GI_MARSHALLING_TESTS_EXTRA_FLAGS_VALUE1,
+         "GI_MARSHALLING_TESTS_EXTRA_FLAGS_VALUE1", "value1"},
+        {GI_MARSHALLING_TESTS_EXTRA_FLAGS_VALUE2,
+         "GI_MARSHALLING_TESTS_EXTRA_FLAGS_VALUE2", "value2"},
+        {0, NULL, NULL}
+      };
+      type = g_flags_register_static (
+        g_intern_static_string ("GIMarshallingTestsExtraFlags"), values);
+    }
+
+  return type;
+}
+
+/**
+ * gi_marshalling_tests_extra_flags_large_in:
+ */
+void
+gi_marshalling_tests_extra_flags_large_in (GIMarshallingTestsExtraFlags value)
+{
+  g_assert_cmpint (value, ==, GI_MARSHALLING_TESTS_EXTRA_FLAGS_VALUE2);
+}
diff --git a/tests/gimarshallingtestsextra.h b/tests/gimarshallingtestsextra.h
index 70c2cfa..57f52f4 100644
--- a/tests/gimarshallingtestsextra.h
+++ b/tests/gimarshallingtestsextra.h
@@ -29,6 +29,15 @@ typedef enum
 } GIMarshallingTestsExtraEnum;
 
 
+typedef enum
+{
+  GI_MARSHALLING_TESTS_EXTRA_FLAGS_VALUE1 = 0,
+  GI_MARSHALLING_TESTS_EXTRA_FLAGS_VALUE2 = (gint)(1 << 31),
+} GIMarshallingTestsExtraFlags;
+
+GType gi_marshalling_tests_extra_flags_get_type (void) G_GNUC_CONST;
+#define GI_MARSHALLING_TESTS_TYPE_EXTRA_FLAGS (gi_marshalling_tests_extra_flags_get_type ())
+
 void gi_marshalling_tests_compare_two_gerrors_in_gvalue (GValue *v, GValue *v1);
 void gi_marshalling_tests_ghashtable_enum_none_in (GHashTable *hash_table);
 GHashTable * gi_marshalling_tests_ghashtable_enum_none_return (void);
@@ -39,4 +48,6 @@ gchar * gi_marshalling_tests_filename_to_glib_repr (gchar *path_in, gsize *len);
 
 GIMarshallingTestsExtraEnum * gi_marshalling_tests_enum_array_return_type (gsize *n_members);
 
+void gi_marshalling_tests_extra_flags_large_in (GIMarshallingTestsExtraFlags value);
+
 #endif /* EXTRA_TESTS */
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 3072974..b5aeb52 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -1887,6 +1887,11 @@ class TestGFlags(unittest.TestCase):
                          "<flags GI_MARSHALLING_TESTS_FLAGS_VALUE2 of type "
                          "GIMarshallingTests.Flags>")
 
+    def test_flags_large_in(self):
+        self.assertEqual(int(GIMarshallingTests.ExtraFlags.VALUE2), 1 << 31)
+        GIMarshallingTests.extra_flags_large_in(
+            GIMarshallingTests.ExtraFlags.VALUE2)
+
 
 class TestNoTypeFlags(unittest.TestCase):
 


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