summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGustavo J. A. M. Carneiro <gjc@src.gnome.org>2006-08-27 12:02:33 +0000
committerGustavo J. A. M. Carneiro <gjc@src.gnome.org>2006-08-27 12:02:33 +0000
commitd05fccab23aef7fa4c406352552262782bf1066c (patch)
tree0e35f797d3aaacf586384e343120ea06f8ae5358
parent3938273dfd085dc75f64ce44706cf508fd971099 (diff)
downloadpygobject-d05fccab23aef7fa4c406352552262782bf1066c.tar.gz
pygobject-d05fccab23aef7fa4c406352552262782bf1066c.tar.xz
pygobject-d05fccab23aef7fa4c406352552262782bf1066c.zip
interface fixes and tests
-rw-r--r--ChangeLog17
-rw-r--r--gobject/gobjectmodule.c7
-rw-r--r--tests/test-unknown.c62
-rw-r--r--tests/test_interface.py30
4 files changed, 111 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 6632da5..b514be0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,22 @@
2006-08-27 Gustavo J. A. M. Carneiro <gjc@gnome.org>
+ * gobject/gobjectmodule.c (pyg_type_register): Correct a bug in
+ the code that checks if parent already implements an interface or not.
+
+ * tests/test-unknown.c (test_interface_base_init),
+ (test_interface_get_type): Add a property to the interface, for
+ better testing.
+ (test_unknown_get_property),
+ (test_unknown_set_property, test_unknown_class_init): Add a
+ property to the class as required by the interface.
+
+ * tests/test_interface.py: More thorough interface testing, with
+ properties and test both the case of implementing an interface
+ from scratch, and re-implementing and interface that a parent
+ already implements.
+
+2006-08-27 Gustavo J. A. M. Carneiro <gjc@gnome.org>
+
* gobject/gobjectmodule.c (pygobject__g_instance_init): If
necessary, attach the GObject to the PyGObject here.
(pygobject_constructv): Cope with the fact that wrapper->obj may
diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c
index dde48b6..fa6ffbc 100644
--- a/gobject/gobjectmodule.c
+++ b/gobject/gobjectmodule.c
@@ -1295,6 +1295,7 @@ pyg_type_register(PyTypeObject *class, const char *type_name)
continue;
itype = pyg_type_from_object((PyObject *) base);
+
/* ignore interface unless defined in parent type */
if (n_parent_interfaces == 0)
continue;
@@ -1305,7 +1306,7 @@ pyg_type_register(PyTypeObject *class, const char *type_name)
if (parent_interfaces[parent_interface_iter] == itype)
break;
}
- if (parent_interface_iter != n_parent_interfaces)
+ if (parent_interface_iter == n_parent_interfaces)
continue;
iinfo = pyg_lookup_interface_info(itype);
@@ -1393,9 +1394,11 @@ pyg_type_register(PyTypeObject *class, const char *type_name)
++parent_interface_iter)
{
if (parent_interfaces[parent_interface_iter] == itype)
- continue;
+ break;
}
}
+ if (parent_interface_iter < n_parent_interfaces)
+ continue;
iinfo = pyg_lookup_interface_info(itype);
iinfo_copy = *iinfo;
diff --git a/tests/test-unknown.c b/tests/test-unknown.c
index 2602b4a..4a569fa 100644
--- a/tests/test-unknown.c
+++ b/tests/test-unknown.c
@@ -1,5 +1,28 @@
#include "test-unknown.h"
+enum {
+ PROP_SOME_PROPERTY = 1,
+};
+
+
+static void
+test_interface_base_init (gpointer g_iface)
+{
+ static gboolean initialized = FALSE;
+
+ if (!initialized)
+ {
+ g_object_interface_install_property (g_iface,
+ g_param_spec_string ("some-property",
+ "some-property",
+ "A simple test property",
+ NULL,
+ G_PARAM_READWRITE));
+ initialized = TRUE;
+ }
+}
+
+
GType
test_interface_get_type (void)
{
@@ -10,7 +33,7 @@ test_interface_get_type (void)
static const GTypeInfo info =
{
sizeof (TestInterfaceIface), /* class_size */
- NULL, /* base_init */
+ test_interface_base_init, /* base_init */
NULL, /* base_finalize */
NULL,
NULL, /* class_finalize */
@@ -45,7 +68,42 @@ G_DEFINE_TYPE_WITH_CODE (TestUnknown, test_unknown, G_TYPE_OBJECT,
test_unknown_test_interface_init));
static void test_unknown_init (TestUnknown *self) {}
-static void test_unknown_class_init (TestUnknownClass *klass) {}
+
+
+static void
+test_unknown_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+
+}
+
+static void
+test_unknown_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+
+}
+
+static void test_unknown_class_init (TestUnknownClass *klass)
+{
+ GObjectClass *gobject_class = (GObjectClass*) klass;
+
+ gobject_class->get_property = test_unknown_get_property;
+ gobject_class->set_property = test_unknown_set_property;
+
+
+ g_object_class_install_property (G_OBJECT_CLASS (klass),
+ PROP_SOME_PROPERTY,
+ g_param_spec_string ("some-property",
+ "some-property",
+ "A simple test property",
+ NULL,
+ G_PARAM_READWRITE));
+}
void test_interface_iface_method (TestInterface *instance)
{
diff --git a/tests/test_interface.py b/tests/test_interface.py
index 2e45e1d..d54515d 100644
--- a/tests/test_interface.py
+++ b/tests/test_interface.py
@@ -8,6 +8,11 @@ GUnknown = gobject.type_from_name("TestUnknown")
Unknown = GUnknown.pytype
class MyUnknown(Unknown, testhelper.Interface):
+ __gproperties__ = {
+ 'some-property': (str, 'blurb', 'description', 'default',
+ gobject.PARAM_READWRITE),
+ }
+
def __init__(self):
Unknown.__init__(self)
self.called = False
@@ -18,8 +23,31 @@ class MyUnknown(Unknown, testhelper.Interface):
gobject.type_register(MyUnknown)
+class MyObject(gobject.GObject, testhelper.Interface):
+ __gproperties__ = {
+ 'some-property': (str, 'blurb', 'description', 'default',
+ gobject.PARAM_READWRITE),
+ }
+
+ def __init__(self):
+ GObject.__init__(self)
+ self.called = False
+
+ def do_iface_method(self):
+ self.called = True
+
+gobject.type_register(MyObject)
+
+
class TestIfaceImpl(unittest.TestCase):
- def testMethodCall(self):
+
+ def testReImplementInterface(self):
m = MyUnknown()
m.iface_method()
self.assertEqual(m.called, True)
+
+ def testImplementInterface(self):
+ m = MyObject()
+ m.iface_method()
+ self.assertEqual(m.called, True)
+