summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2022-02-09 11:03:57 +0100
committerBastien Nocera <hadess@hadess.net>2022-02-09 11:21:55 +0100
commit090674700a8a2ac338d787a054c30b0e4924871e (patch)
tree5c3d14e33960a9d264c1dc496323f0d9671ffed3
parent2b6f80da8c8fe21dd5b4194d45457dc08e8cc005 (diff)
downloadgtk+-wip/hadess/gtkbuilder-initable-gtk3.tar.gz
tests: Add test for GtkBuilder GInitable supportwip/hadess/gtkbuilder-initable-gtk3
-rw-r--r--tests/meson.build1
-rw-r--r--tests/testbuilder.c114
-rw-r--r--tests/testbuilder.ui20
3 files changed, 135 insertions, 0 deletions
diff --git a/tests/meson.build b/tests/meson.build
index 586fe2f45e..7d5fb6e4c7 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -26,6 +26,7 @@ gtk_tests = [
['testbbox'],
['testbox'],
['testboxcss'],
+ ['testbuilder'],
['testbuttons'],
['testcairo'],
['testcalendar'],
diff --git a/tests/testbuilder.c b/tests/testbuilder.c
new file mode 100644
index 0000000000..94266c9518
--- /dev/null
+++ b/tests/testbuilder.c
@@ -0,0 +1,114 @@
+#include <gtk/gtk.h>
+
+static gboolean should_fail = FALSE;
+
+
+#define BACON_TYPE_VIDEO_WIDGET (bacon_video_widget_get_type ())
+G_DECLARE_FINAL_TYPE(BaconVideoWidget, bacon_video_widget, BACON, VIDEO_WIDGET, GtkOverlay)
+
+static void bacon_video_widget_initable_iface_init (GInitableIface *iface);
+
+struct _BaconVideoWidget
+{
+ GtkOverlay parent;
+ gboolean object_init;
+ gboolean initable_init;
+};
+
+G_DEFINE_TYPE_WITH_CODE (BaconVideoWidget, bacon_video_widget, GTK_TYPE_OVERLAY,
+ G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
+ bacon_video_widget_initable_iface_init))
+
+static gboolean
+bacon_video_widget_initable_init (GInitable *initable,
+ GCancellable *cancellable,
+ GError **error)
+{
+ BaconVideoWidget *bvw;
+
+ bvw = BACON_VIDEO_WIDGET (initable);
+
+ if (should_fail) {
+ g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "Initable widget was setup to fail.");
+ g_object_ref_sink (G_OBJECT (initable));
+ return FALSE;
+ }
+
+ bvw->initable_init = TRUE;
+
+ return TRUE;
+}
+
+static void
+bacon_video_widget_initable_iface_init (GInitableIface *iface)
+{
+ iface->init = bacon_video_widget_initable_init;
+}
+
+static void
+bacon_video_widget_class_init (BaconVideoWidgetClass *klass)
+{
+ /* empty */
+}
+
+static void
+bacon_video_widget_init (BaconVideoWidget *bvw)
+{
+ bvw->object_init = TRUE;
+}
+
+int main (int argc, char **argv)
+{
+ GtkBuilder *builder;
+ guint num_objects;
+ GError *error = NULL;
+ GObject *bvw;
+ GSList *list = NULL;
+
+ gtk_init (&argc, &argv);
+
+ builder = gtk_builder_new ();
+ num_objects = gtk_builder_add_from_file (builder, "testbuilder.ui", &error);
+ g_assert_cmpint (num_objects, >, 0);
+ g_assert_no_error (error);
+ bvw = gtk_builder_get_object (builder, "bvw");
+ g_assert_nonnull (bvw);
+ g_assert_true(BACON_VIDEO_WIDGET(bvw)->initable_init);
+ list = gtk_builder_get_objects (builder);
+ g_assert_cmpint (g_slist_length (list), ==, 3);
+ g_clear_pointer (&list, g_slist_free);
+ gtk_widget_destroy (GTK_WIDGET (gtk_builder_get_object (builder, "totem_main_window")));
+ g_clear_object (&builder);
+
+ builder = gtk_builder_new_from_file ("testbuilder.ui");
+ bvw = gtk_builder_get_object (builder, "bvw");
+ g_assert_nonnull (bvw);
+ g_assert_true(BACON_VIDEO_WIDGET(bvw)->initable_init);
+ list = gtk_builder_get_objects (builder);
+ g_assert_cmpint (g_slist_length (list), ==, 3);
+ g_clear_pointer (&list, g_slist_free);
+ gtk_widget_destroy (GTK_WIDGET (gtk_builder_get_object (builder, "totem_main_window")));
+ g_clear_object (&builder);
+
+ should_fail = TRUE;
+
+ builder = gtk_builder_new ();
+ num_objects = gtk_builder_add_from_file (builder, "testbuilder.ui", &error);
+ g_assert_error(error, G_IO_ERROR, G_IO_ERROR_FAILED);
+ g_clear_error (&error);
+ g_assert_cmpint (num_objects, ==, 0);
+ list = gtk_builder_get_objects (builder);
+ g_assert_cmpint (g_slist_length (list), ==, 2);
+ g_clear_pointer (&list, g_slist_free);
+ g_clear_object (&builder);
+
+ /* This calls g_error() so disabled
+ builder = gtk_builder_new_from_file ("testbuilder.ui");
+ bvw = gtk_builder_get_object (builder, "bvw");
+ g_assert_null (bvw);
+ g_clear_object (&builder);
+ */
+
+ return 0;
+}
diff --git a/tests/testbuilder.ui b/tests/testbuilder.ui
new file mode 100644
index 0000000000..d7c084dc80
--- /dev/null
+++ b/tests/testbuilder.ui
@@ -0,0 +1,20 @@
+<?xml version="1.0" ?>
+<!--*- mode: xml -*--><!DOCTYPE glade-interface
+ SYSTEM 'http://glade.gnome.org/glade-2.0.dtd'>
+<interface>
+ <object class="GtkWindow" id="totem_main_window">
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkStack" id="tmw_main_stack">
+ <property name="visible">True</property>
+ <property name="homogeneous">True</property>
+ <child>
+ <object class="BaconVideoWidget" id="bvw"/>
+ <packing>
+ <property name="name">player</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>