[pygi] A few tests about interfaces
- From: Tomeu Vizoso <tomeuv src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [pygi] A few tests about interfaces
- Date: Sat, 28 Nov 2009 15:49:10 +0000 (UTC)
commit 96f6c638709636d7e2ddf560b877879691da3314
Author: Tomeu Vizoso <tomeu sugarlabs org>
Date: Sat Nov 28 11:03:51 2009 +0000
A few tests about interfaces
https://bugzilla.gnome.org/show_bug.cgi?id=601181
tests/libtestgi.c | 23 +++++++++++++++++++++++
tests/libtestgi.h | 16 ++++++++++++++++
tests/test_gi.py | 21 +++++++++++++++++++++
3 files changed, 60 insertions(+), 0 deletions(-)
---
diff --git a/tests/libtestgi.c b/tests/libtestgi.c
index 87f95ae..613c0d9 100644
--- a/tests/libtestgi.c
+++ b/tests/libtestgi.c
@@ -3394,6 +3394,29 @@ test_gi_sub_object_overwritten_method (TestGISubObject *object)
g_assert(TESTGI_OBJECT(object)->int_ == 0);
}
+/* Interfaces */
+
+static void
+test_gi_interface_class_init(void *g_iface)
+{
+}
+
+GType
+test_gi_interface_get_type(void)
+{
+ static GType type = 0;
+ if (type == 0) {
+ type = g_type_register_static_simple (G_TYPE_INTERFACE,
+ "TestGIInterface",
+ sizeof (TestGIInterfaceIface),
+ (GClassInitFunc) test_gi_interface_class_init,
+ 0, NULL, 0);
+ }
+
+ return type;
+}
+
+
/**
* test_gi_int_out_out:
* int0: (out):
diff --git a/tests/libtestgi.h b/tests/libtestgi.h
index 1ec4777..7c344af 100644
--- a/tests/libtestgi.h
+++ b/tests/libtestgi.h
@@ -636,6 +636,22 @@ GType test_gi_sub_object_get_type (void) G_GNUC_CONST;
void test_gi_sub_object_sub_method (TestGISubObject *object);
void test_gi_sub_object_overwritten_method (TestGISubObject *object);
+/* Interfaces */
+
+#define TESTGI_TYPE_INTERFACE (test_gi_interface_get_type ())
+#define TESTGI_INTERFACE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), TESTGI_TYPE_INTERFACE, TestGIInterface))
+#define TESTGI_IS_INTERFACE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), TESTGI_TYPE_INTERFACE))
+#define TESTGI_INTERFACE_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TESTGI_TYPE_INTERFACE, TestGIInterfaceIface))
+
+typedef struct _TestGIInterface TestGIInterface;
+typedef struct _TestGIInterfaceIface TestGIInterfaceIface;
+
+struct _TestGIInterfaceIface {
+ GTypeInterface base_iface;
+};
+
+GType test_gi_interface_get_type (void) G_GNUC_CONST;
+
/* Multiple output arguments */
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 2d9c002..4503d62 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -1450,3 +1450,24 @@ class TestMultiOutputArgs(unittest.TestCase):
self.assertEquals((6, 7), TestGI.int_return_out())
+# Interface
+
+class TestInterfaces(unittest.TestCase):
+
+ def test_wrapper(self):
+ self.assertTrue(issubclass(TestGI.Interface, gobject.GInterface))
+ self.assertEquals(TestGI.Interface.__gtype__.name, 'TestGIInterface')
+ self.assertRaises(NotImplementedError, TestGI.Interface)
+
+ def test_implementation(self):
+
+ class TestInterfaceImpl(gobject.GObject, TestGI.Interface):
+ __gtype_name__ = 'TestInterfaceImpl'
+ def __init__(self):
+ gobject.GObject.__init__(self)
+
+ self.assertTrue(issubclass(TestInterfaceImpl, TestGI.Interface))
+
+ instance = TestInterfaceImpl()
+ self.assertTrue(isinstance(instance, TestGI.Interface))
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]