[gjs] installed-tests: add test for exceptions inside gobject properties
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] installed-tests: add test for exceptions inside gobject properties
- Date: Fri, 12 Jun 2015 01:37:22 +0000 (UTC)
commit 7a8496400a3d07963df25cdfdbc74991db75b107
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Thu Jun 11 18:12:25 2015 -0700
installed-tests: add test for exceptions inside gobject properties
Add a test for the previous commit.
https://bugzilla.gnome.org/show_bug.cgi?id=730101
Makefile-insttest.am | 1 +
installed-tests/js/testExceptions.js | 101 ++++++++++++++++++++++++++++++++++
2 files changed, 102 insertions(+), 0 deletions(-)
---
diff --git a/Makefile-insttest.am b/Makefile-insttest.am
index bee59f9..f454623 100644
--- a/Makefile-insttest.am
+++ b/Makefile-insttest.am
@@ -124,6 +124,7 @@ dist_jstests_DATA += \
installed-tests/js/testClass.js \
installed-tests/js/testCoverage.js \
installed-tests/js/testGDBus.js \
+ installed-tests/js/testExceptions.js \
installed-tests/js/testEverythingBasic.js \
installed-tests/js/testEverythingEncapsulated.js \
installed-tests/js/testFormat.js \
diff --git a/installed-tests/js/testExceptions.js b/installed-tests/js/testExceptions.js
new file mode 100644
index 0000000..36941b1
--- /dev/null
+++ b/installed-tests/js/testExceptions.js
@@ -0,0 +1,101 @@
+const JSUnit = imports.jsUnit;
+const GLib = imports.gi.GLib;
+const GObject = imports.gi.GObject;
+const Lang = imports.lang;
+
+const Foo = new Lang.Class({
+ Name: 'Foo',
+ Extends: GObject.Object,
+ Properties: {
+ 'prop': GObject.ParamSpec.string('prop', '', '', GObject.ParamFlags.READWRITE, '')
+ },
+
+ set prop(v) {
+ throw new Error('set');
+ },
+
+ get prop() {
+ throw new Error('get');
+ }
+});
+
+const Bar = new Lang.Class({
+ Name: 'Bar',
+ Extends: GObject.Object,
+ Properties: {
+ 'prop': GObject.ParamSpec.string('prop', '', '', GObject.ParamFlags.READWRITE, '')
+ }
+});
+
+function testExceptionInPropertySetter() {
+ let foo = new Foo();
+ GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_WARNING,
+ 'JS ERROR: Error: set*');
+
+ try {
+ foo.prop = 'bar';
+ } catch (e) {
+ logError(e);
+ }
+}
+
+function testExceptionInPropertyGetter() {
+ let foo = new Foo();
+ GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_WARNING,
+ 'JS ERROR: Error: get*');
+
+ try {
+ let bar = foo.prop;
+ } catch (e) {
+ logError(e);
+ }
+}
+
+function testExceptionInPropertySetterFromConstructor() {
+ GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_WARNING,
+ 'JS ERROR: Error: set*');
+
+ try {
+ let foo = new Foo({ prop: 'bar' });
+ } catch (e) {
+ logError(e);
+ }
+}
+
+function testExceptionInPropertySetterWithBinding() {
+ let foo = new Foo();
+ let bar = new Bar();
+
+ bar.bind_property('prop',
+ foo, 'prop',
+ GObject.BindingFlags.DEFAULT);
+ GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_WARNING,
+ 'JS ERROR: Error: set*');
+
+ try {
+ // wake up the binding so that g_object_set() is called on foo
+ bar.notify('prop');
+ } catch (e) {
+ logError(e);
+ }
+}
+
+function testExceptionInPropertyGetterWithBinding() {
+ let foo = new Foo();
+ let bar = new Bar();
+
+ foo.bind_property('prop',
+ bar, 'prop',
+ GObject.BindingFlags.DEFAULT);
+ GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_WARNING,
+ 'JS ERROR: Error: get*');
+
+ try {
+ // wake up the binding so that g_object_get() is called on foo
+ foo.notify('prop');
+ } catch (e) {
+ logError(e);
+ }
+}
+
+JSUnit.gjstestRun(this, JSUnit.setUp, JSUnit.tearDown);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]