[gjs: 4/6] testGDBus: Verify that properties are set/got to/from server
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 4/6] testGDBus: Verify that properties are set/got to/from server
- Date: Thu, 20 Jun 2019 05:11:55 +0000 (UTC)
commit bd70fbc36b3a3edf69ac0d03121bea5a00556772
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date: Mon Jun 17 17:13:04 2019 +0200
testGDBus: Verify that properties are set/got to/from server
installed-tests/js/testGDBus.js | 68 +++++++++++++++++++++++++++++++++++++++--
1 file changed, 66 insertions(+), 2 deletions(-)
---
diff --git a/installed-tests/js/testGDBus.js b/installed-tests/js/testGDBus.js
index 66f7b985..61786b01 100644
--- a/installed-tests/js/testGDBus.js
+++ b/installed-tests/js/testGDBus.js
@@ -103,6 +103,7 @@ const PROP_WRITE_ONLY_INITIAL_VALUE = "Initial value";
/* Test is the actual object exporting the dbus methods */
class Test {
constructor() {
+ this._propReadOnly = PROP_READ_ONLY_INITIAL_VALUE;
this._propWriteOnly = PROP_WRITE_ONLY_INITIAL_VALUE;
this._propReadWrite = PROP_READ_WRITE_INITIAL_VALUE;
@@ -195,9 +196,9 @@ class Test {
});
}
- // boolean
+ // double
get PropReadOnly() {
- return true;
+ return this._propReadOnly;
}
// string
@@ -260,6 +261,23 @@ describe('Exported DBus object', function () {
var proxy;
let loop;
+ let waitForServerProperty = function (property, value = undefined, timeout = 500) {
+ let waitId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, timeout, () => {
+ waitId = 0;
+ throw new Error(`Timeout waiting for property ${property} expired`);
+ });
+
+ while (waitId && (!test[property] ||
+ (value !== undefined && test[property] != value)))
+ loop.get_context().iteration(true);
+
+ if (waitId)
+ GLib.source_remove(waitId);
+
+ expect(waitId).not.toBe(0);
+ return test[property];
+ };
+
beforeAll(function () {
loop = new GLib.MainLoop(null, false);
@@ -593,4 +611,50 @@ describe('Exported DBus object', function () {
const fdList = new Gio.UnixFDList();
expect(() => proxy.fdInRemote(0, fdList, () => {})).toThrow();
});
+
+ it('Has defined properties', function () {
+ expect(proxy.hasOwnProperty('PropReadWrite')).toBeTruthy();
+ expect(proxy.hasOwnProperty('PropReadOnly')).toBeTruthy();
+ expect(proxy.hasOwnProperty('PropWriteOnly')).toBeTruthy();
+ });
+
+ it('reading readonly property works', function () {
+ expect(proxy.PropReadOnly).toEqual(PROP_READ_ONLY_INITIAL_VALUE);
+ });
+
+ it('reading readwrite property works', function () {
+ expect(proxy.PropReadWrite).toEqual(
+ GLib.Variant.new_string(PROP_READ_WRITE_INITIAL_VALUE.toString()));
+ });
+
+ it('reading writeonly property returns null', function () {
+ expect(proxy.PropWriteOnly).toBeNull();
+ });
+
+ it('Setting a readwrite property works', function () {
+ let testStr = 'GjsVariantValue';
+ expect(() => {
+ proxy.PropReadWrite = GLib.Variant.new_string(testStr);
+ }).not.toThrow();
+
+ expect(proxy.PropReadWrite.deep_unpack()).toEqual(testStr);
+
+ expect(waitForServerProperty('_propReadWrite', testStr)).toEqual(testStr);
+ });
+
+ it('Setting a writeonly property works', function () {
+ let testValue = Math.random().toString();
+ expect(() => {
+ proxy.PropWriteOnly = testValue;
+ }).not.toThrow();
+
+ expect(waitForServerProperty('_propWriteOnly', testValue)).toEqual(testValue);
+ });
+
+ it('Setting a readonly property does not throw', function () {
+ let testValue = Math.random().toString();
+ expect(() => {
+ proxy.PropReadOnly = testValue;
+ }).not.toThrow();
+ });
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]