[glade] Tests: add python and javascript test case



commit 779d9d8c85dab2929de0a43867139d60f89e2f52
Author: Juan Pablo Ugarte <juanpablougarte gmail com>
Date:   Mon Jun 8 20:51:01 2020 -0300

    Tests: add python and javascript test case
    
    Add test case to make sure both python and js plugins work

 tests/meson.build             | 35 +++++++++++++++++++++++------------
 tests/modules.c               | 40 ++++++++++++++++++++++++++++++++++++++++
 tests/modules/gjsplugin.js    | 13 +++++++++++++
 tests/modules/pythonplugin.py |  7 +++++++
 4 files changed, 83 insertions(+), 12 deletions(-)
---
diff --git a/tests/meson.build b/tests/meson.build
index 52594753..1b9b6a84 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -1,6 +1,25 @@
+envs = [
+  'GLADE_TESTING=1',
+  'GLADE_CATALOG_SEARCH_PATH=' + (source_root / 'plugins/gtk+'),
+  'GLADE_MODULE_SEARCH_PATH=' + (build_root / 'plugins/gtk+'),
+  'GLADE_PIXMAP_DIR=' + (source_root / 'data/icons'),
+  'GLADE_ICON_THEME_PATH=' + (source_root / 'plugins/gtk+/icons/22x22'),
+]
+
+modenvs = [
+  'GLADE_TESTING=1',
+  'GLADE_CATALOG_SEARCH_PATH=' + (source_root / 'plugins/gtk+:') +
+    (source_root / 'plugins/python:') + (source_root / 'plugins/gjs:') + (source_root / 'tests/catalogs'),
+  'GLADE_MODULE_SEARCH_PATH=' + (build_root / 'plugins/gtk+:') +
+    (build_root / 'plugins/python:') + (build_root / 'plugins/gjs:') + (source_root / 'tests/modules'),
+  'GLADE_PIXMAP_DIR=' + (source_root / 'data/icons'),
+  'GLADE_ICON_THEME_PATH=' + (source_root / 'plugins/gtk+/icons/22x22'),
+]
+
 test_unit = [
-  ['add-child', {'sources': 'add-child.c'}],
-  ['create-widgets', {'sources': 'create-widgets.c'}],
+  ['add-child', {'sources': 'add-child.c'}, envs],
+  ['create-widgets', {'sources': 'create-widgets.c'}, envs],
+  ['modules', {'sources': 'modules.c'}, modenvs],
 ]
 
 sources = files('toplevel-order.c')
@@ -25,15 +44,7 @@ sources += gnome.compile_resources(
   export: true,
 )
 
-test_unit += [['toplevel-order', {'sources': sources}]]
-
-envs = [
-  'GLADE_TESTING=1',
-  'GLADE_CATALOG_SEARCH_PATH=' + (source_root / 'plugins/gtk+'),
-  'GLADE_MODULE_SEARCH_PATH=' + (build_root / 'plugins/gtk+'),
-  'GLADE_PIXMAP_DIR=' + (source_root / 'data/icons'),
-  'GLADE_ICON_THEME_PATH=' + (source_root / 'plugins/gtk+/icons/22x22'),
-]
+test_unit += [['toplevel-order', {'sources': sources}, envs]]
 
 foreach unit: test_unit
   exe = executable(
@@ -47,6 +58,6 @@ foreach unit: test_unit
   test(
     unit[0],
     exe,
-    env: envs,
+    env: unit[2],
   )
 endforeach
diff --git a/tests/modules.c b/tests/modules.c
new file mode 100644
index 00000000..ac087988
--- /dev/null
+++ b/tests/modules.c
@@ -0,0 +1,40 @@
+#include <glib.h>
+#include <glib-object.h>
+
+#include <gladeui/glade-app.h>
+#include <gladeui/glade-widget-adaptor.h>
+
+static void
+test_object_class (gconstpointer data)
+{
+  GladeWidgetAdaptor *adaptor = glade_widget_adaptor_get_by_name(data);
+  GladeWidget        *widget;
+  GObject            *object;
+
+  g_assert (GLADE_IS_WIDGET_ADAPTOR (adaptor));
+
+  widget = glade_widget_adaptor_create_widget (adaptor, FALSE, NULL);
+  g_assert (GLADE_IS_WIDGET (widget));
+
+  object = glade_widget_get_object (widget);
+  g_assert (G_IS_OBJECT (object));
+
+  g_assert (g_strcmp0 (G_OBJECT_TYPE_NAME (object), data) == 0);
+
+  g_object_unref (widget);
+}
+
+int
+main (int argc, char *argv[])
+{
+  gtk_test_init (&argc, &argv, NULL);
+
+  glade_init ();
+  glade_app_get ();
+
+  g_test_add_data_func ("/Modules/Python", "MyPythonBox", test_object_class);
+  g_test_add_data_func ("/Modules/JavaScript", "MyJSGrid", test_object_class);
+
+  return g_test_run ();
+}
+
diff --git a/tests/modules/gjsplugin.js b/tests/modules/gjsplugin.js
new file mode 100644
index 00000000..f5f6c1ed
--- /dev/null
+++ b/tests/modules/gjsplugin.js
@@ -0,0 +1,13 @@
+#!/usr/bin/gjs
+
+const GObject = imports.gi.GObject;
+const Gtk     = imports.gi.Gtk;
+
+var MyJSGrid = GObject.registerClass({
+    GTypeName: 'MyJSGrid',
+}, class MyJSGrid extends Gtk.Grid {
+    _init() {
+        super._init();
+    }
+});
+
diff --git a/tests/modules/pythonplugin.py b/tests/modules/pythonplugin.py
new file mode 100644
index 00000000..cb5b6a9d
--- /dev/null
+++ b/tests/modules/pythonplugin.py
@@ -0,0 +1,7 @@
+from gi.repository import Gtk
+
+class MyPythonBox(Gtk.Box):
+  __gtype_name__ = 'MyPythonBox'
+
+  def __init__ (self):
+    Gtk.Box.__init__ (self)


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