[pygobject] Add test for GValue signal return values



commit fddb01b0b71b68d154d130cf40fd5f38647b1a4d
Author: Martin Pitt <martinpitt gnome org>
Date:   Tue Sep 11 09:31:18 2012 +0200

    Add test for GValue signal return values
    
    Another attempt to reproduce the reported error in
    https://bugzilla.gnome.org/show_bug.cgi?id=683596
    but this works already.

 tests/test_signal.py     |   13 +++++++++++++
 tests/testhelpermodule.c |   36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 0 deletions(-)
---
diff --git a/tests/test_signal.py b/tests/test_signal.py
index 80f5a2b..510d8af 100644
--- a/tests/test_signal.py
+++ b/tests/test_signal.py
@@ -362,6 +362,7 @@ class CM(GObject.GObject):
         test_string=(l, str, (str, )),
         test_object=(l, object, (object, )),
         test_paramspec=(l, GObject.ParamSpec, ()),
+        test_gvalue_ret=(l, GObject.Value, (GObject.TYPE_GTYPE, )),
     )
 
     testprop = GObject.Property(type=int)
@@ -428,6 +429,18 @@ class _TestCMarshaller:
         self.obj.set_property("testprop", 42)
         self.assertTrue(self.notify_called)
 
+    def testTestReturnValue(self):
+        self.assertEqual(self.obj.emit("test-gvalue-ret", GObject.TYPE_INT),
+                         GObject.G_MAXINT)
+        self.assertEqual(self.obj.emit("test-gvalue-ret", GObject.TYPE_UINT),
+                         GObject.G_MAXUINT)
+        self.assertEqual(self.obj.emit("test-gvalue-ret", GObject.TYPE_INT64),
+                         GObject.G_MAXINT64)
+        self.assertEqual(self.obj.emit("test-gvalue-ret", GObject.TYPE_UINT64),
+                         GObject.G_MAXUINT64)
+        self.assertEqual(self.obj.emit("test-gvalue-ret", GObject.TYPE_STRING),
+                         "hello")
+
 if 'generic-c-marshaller' in GObject.features:
     class TestCMarshaller(_TestCMarshaller, unittest.TestCase):
         pass
diff --git a/tests/testhelpermodule.c b/tests/testhelpermodule.c
index d9036db..fa95752 100644
--- a/tests/testhelpermodule.c
+++ b/tests/testhelpermodule.c
@@ -357,6 +357,38 @@ test_paramspec_callback (GObject *object)
   return g_param_spec_boolean ("test-param", "test", "test boolean", TRUE, G_PARAM_READABLE);
 }
 
+static GValue *
+test_gvalue_ret_callback (GObject *object, GType type)
+{
+  GValue *ret = g_malloc0 (sizeof (GValue));
+
+  g_return_val_if_fail (G_IS_OBJECT (object), NULL);
+
+  g_value_init (ret, type);
+
+  switch (type) {
+    case G_TYPE_INT:
+      g_value_set_int(ret, G_MAXINT);
+      break;
+    case G_TYPE_INT64:
+      g_value_set_int64(ret, G_MAXINT64);
+      break;
+    case G_TYPE_UINT:
+      g_value_set_uint(ret, G_MAXUINT);
+      break;
+    case G_TYPE_UINT64:
+      g_value_set_uint64(ret, G_MAXUINT64);
+      break;
+    case G_TYPE_STRING:
+      g_value_set_string(ret, "hello");
+      break;
+    default:
+      g_critical ("test_gvalue_ret_callback() does not support type %s", g_type_name (type));
+  }
+
+  return ret;
+}
+
 static void
 connectcallbacks (GObject *object)
 {
@@ -407,6 +439,10 @@ connectcallbacks (GObject *object)
                     "test_paramspec",
                     G_CALLBACK (test_paramspec_callback), 
                     NULL);
+  g_signal_connect (G_OBJECT (object),
+                    "test_gvalue_ret",
+                    G_CALLBACK (test_gvalue_ret_callback), 
+                    NULL);
 }
 
 static PyObject *



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