summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu@sugarlabs.org>2009-11-28 11:03:51 +0000
committerTomeu Vizoso <tomeu@sugarlabs.org>2009-11-28 11:04:21 +0000
commit96f6c638709636d7e2ddf560b877879691da3314 (patch)
tree4c10dfff0d5099cfc02201a9c5f40d8f60aec5fd
parent076ba3156c13375a75983cef7a409c8c8afea119 (diff)
downloadpygi-96f6c638709636d7e2ddf560b877879691da3314.tar.gz
pygi-96f6c638709636d7e2ddf560b877879691da3314.tar.xz
pygi-96f6c638709636d7e2ddf560b877879691da3314.zip
A few tests about interfaces
https://bugzilla.gnome.org/show_bug.cgi?id=601181
-rw-r--r--tests/libtestgi.c23
-rw-r--r--tests/libtestgi.h16
-rw-r--r--tests/test_gi.py21
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))
+