[gjs] Gtk: Add test case for template from resource
- From: Jonas Danielsson <jonasdn src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] Gtk: Add test case for template from resource
- Date: Mon, 17 Nov 2014 06:19:58 +0000 (UTC)
commit d383df7928441565b06d28c5e5caa4788dc03018
Author: Jonas Danielsson <jonas threetimestwo org>
Date: Sun Nov 9 20:17:35 2014 +0100
Gtk: Add test case for template from resource
https://bugzilla.gnome.org/show_bug.cgi?id=739739
Makefile-insttest.am | 19 +++++++++++++++--
installed-tests/js/complex.ui | 28 ++++++++++++++++++++++++++
installed-tests/js/jsunit.gresources.xml | 6 +++++
installed-tests/js/testGtk.js | 32 ++++++++++++++++++++++++++---
4 files changed, 78 insertions(+), 7 deletions(-)
---
diff --git a/Makefile-insttest.am b/Makefile-insttest.am
index fb27c36..bee59f9 100644
--- a/Makefile-insttest.am
+++ b/Makefile-insttest.am
@@ -1,6 +1,8 @@
EXTRA_DIST += \
- installed-tests/jsunit.test.in \
- installed-tests/script.test.in \
+ installed-tests/jsunit.test.in \
+ installed-tests/script.test.in \
+ installed-tests/js/jsunit.gresources.xml \
+ installed-tests/js/complex.ui \
$(NULL)
installedtestmetadir = $(datadir)/installed-tests/gjs
@@ -26,7 +28,18 @@ jsunit_CPPFLAGS = $(AM_CPPFLAGS) $(GJS_CFLAGS) -DPKGLIBDIR=\"$(pkglibdir)\" -DIN
jsunit_CFLAGS = $(AM_CFLAGS) $(GJS_CFLAGS) -I$(top_srcdir)
jsunit_LDADD = $(GJS_LIBS) libgjs.la
jsunit_LDFLAGS = -rpath $(pkglibdir)
-jsunit_SOURCES = installed-tests/gjs-unit.cpp
+jsunit_SOURCES = \
+ installed-tests/gjs-unit.cpp \
+ jsunit-resources.c \
+ jsunit-resources.h
+
+jsunit_resources_files = $(shell glib-compile-resources --sourcedir=$(srcdir)/installed-tests/js
--generate-dependencies $(srcdir)/test/jsunit.gresource.xml)
+jsunit-resources.h: $(srcdir)/installed-tests/js/jsunit.gresources.xml $(jsunit_resource_files)
+ $(AM_V_GEN) glib-compile-resources --target=$@ --sourcedir=$(srcdir)/installed-tests/js
--sourcedir=$(builddir) --generate --c-name jsunit_resources $<
+jsunit-resources.c: $(srcdir)/installed-tests/js/jsunit.gresources.xml $(jsunit_resource_files)
+ $(AM_V_GEN) glib-compile-resources --target=$@ --sourcedir=$(srcdir)/installed-tests/js
--sourcedir=$(builddir) --generate --c-name jsunit_resources $<
+
+CLEANFILES += jsunit-resources.h jsunit-resources.c
privlibdir = $(pkglibdir)
privlib_LTLIBRARIES =
diff --git a/installed-tests/js/complex.ui b/installed-tests/js/complex.ui
new file mode 100644
index 0000000..c11f1c1
--- /dev/null
+++ b/installed-tests/js/complex.ui
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <template class="Gjs_MyComplexGtkSubclassFromResource" parent="GtkGrid">
+ <property name="margin_top">10</property>
+ <property name="margin_bottom">10</property>
+ <property name="margin_start">10</property>
+ <property name="margin_end">10</property>
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkLabel" id="label-child">
+ <property name="label">Complex!</property>
+ <property name="visible">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label-child2">
+ <property name="label">Complex as well!</property>
+ <property name="visible">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="internal-label-child">
+ <property name="label">Complex and internal!</property>
+ <property name="visible">True</property>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/installed-tests/js/jsunit.gresources.xml b/installed-tests/js/jsunit.gresources.xml
new file mode 100644
index 0000000..1086841
--- /dev/null
+++ b/installed-tests/js/jsunit.gresources.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/org/gjs/jsunit">
+ <file preprocess="xml-stripblanks">complex.ui</file>
+ </gresource>
+</gresources>
diff --git a/installed-tests/js/testGtk.js b/installed-tests/js/testGtk.js
index bc8ab19..b324653 100755
--- a/installed-tests/js/testGtk.js
+++ b/installed-tests/js/testGtk.js
@@ -56,16 +56,40 @@ const MyComplexGtkSubclass = new Lang.Class({
}
});
-function testGtk() {
- Gtk.init(null);
- let win = new Gtk.Window({ type: Gtk.WindowType.TOPLEVEL });
- let content = new MyComplexGtkSubclass();
+const MyComplexGtkSubclassFromResource = new Lang.Class({
+ Name: 'MyComplexGtkSubclassFromResource',
+ Extends: Gtk.Grid,
+ Template: 'resource:///org/gjs/jsunit/complex.ui',
+ Children: ['label-child', 'label-child2'],
+ InternalChildren: ['internal-label-child'],
+
+ _init: function(params) {
+ this.parent(params);
+
+ this._internalLabel = this.label_child;
+ JSUnit.assertNotEquals(this.label_child, null);
+ JSUnit.assertNotEquals(this.label_child2, null);
+ JSUnit.assertNotEquals(this._internal_label_child, null);
+ }
+});
+
+function validateTemplate(content) {
+ let win = new Gtk.Window({ type: Gtk.WindowType.TOPLEVEL });
win.add(content);
JSUnit.assertEquals("label is set to 'Complex!'", 'Complex!', content._internalLabel.get_label());
JSUnit.assertEquals("label is set to 'Complex as well!'", 'Complex as well!',
content.label_child2.get_label());
JSUnit.assertEquals("label is set to 'Complex and internal!'", 'Complex and internal!',
content._internal_label_child.get_label());
+
+ win.destroy();
+}
+
+function testGtk() {
+ Gtk.init(null);
+
+ validateTemplate(new MyComplexGtkSubclass());
+ validateTemplate(new MyComplexGtkSubclassFromResource());
}
JSUnit.gjstestRun(this, JSUnit.setUp, JSUnit.tearDown);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]