[gjs: 5/14] testGObjectValue: Add GValue conversion test for GObject objects




commit f42a870af5582608789cfe32a9ba079c27d2d19b
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Fri Apr 9 04:06:05 2021 +0200

    testGObjectValue: Add GValue conversion test for GObject objects

 installed-tests/js/testGObjectValue.js | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)
---
diff --git a/installed-tests/js/testGObjectValue.js b/installed-tests/js/testGObjectValue.js
index c063fbb8..a0a32996 100644
--- a/installed-tests/js/testGObjectValue.js
+++ b/installed-tests/js/testGObjectValue.js
@@ -1,15 +1,17 @@
 // SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
 // SPDX-FileCopyrightText: 2020 Marco Trevisan <marco trevisan canonical com>
 
-const {GLib, GObject} = imports.gi;
+const {GLib, GObject, GIMarshallingTests} = imports.gi;
 
 GObject.TYPE_SCHAR = GObject.TYPE_CHAR;
 
 const SIGNED_TYPES = ['schar', 'int', 'int64', 'long'];
 const UNSIGNED_TYPES = ['char', 'uchar', 'uint', 'uint64', 'ulong'];
 const FLOATING_TYPES = ['double', 'float'];
-const SPECIFIC_TYPES = ['gtype', 'boolean', 'string', 'variant'];
-const ALL_TYPES = [...SIGNED_TYPES, ...UNSIGNED_TYPES, ...FLOATING_TYPES, ...SPECIFIC_TYPES];
+const NUMERIC_TYPES = [...SIGNED_TYPES, ...UNSIGNED_TYPES, ...FLOATING_TYPES];
+const SPECIFIC_TYPES = ['gtype', 'boolean', 'string', 'param', 'variant'];
+const INSTANCED_TYPES = ['object'];
+const ALL_TYPES = [...NUMERIC_TYPES, ...SPECIFIC_TYPES, ...INSTANCED_TYPES];
 
 describe('GObject value (GValue)', function () {
     let v;
@@ -32,6 +34,25 @@ describe('GObject value (GValue)', function () {
             const other = ALL_TYPES[Math.random() * ALL_TYPES.length | 0];
             return GObject[`TYPE_${other.toUpperCase()}`];
         }
+        if (type === 'object') {
+            const wasCreatingObject = this.creatingObject;
+            this.creatingObject = true;
+            const props = ALL_TYPES.filter(e =>
+                (e !== 'object' || !wasCreatingObject) &&
+                e !== 'gtype' &&
+                e !== 'param' &&
+                // Include string when gobject-introspection!268 is merged
+                e !== 'string' &&
+                e !== 'schar').reduce((ac, a) => ({
+                ...ac, [`some-${a}`]: getDefaultContentByType(a)
+            }), {});
+            delete this.creatingObject;
+            return new GIMarshallingTests.PropertiesObject(props);
+        }
+        if (type === 'param') {
+            return GObject.ParamSpec.string('test-param', '', getDefaultContentByType('string'),
+                GObject.ParamFlags.READABLE, '');
+        }
         if (type === 'variant') {
             return new GLib.Variant('a{sv}', {
                 pasta: new GLib.Variant('s', 'Carbonara (con guanciale)'),


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