[gjs/gnome-3-34] testGObjectClass: Verify the usage of GObject classes with wrong base



commit 7a0a2cd89a071a9ed072334b653754c7e8e38797
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Sun Sep 1 05:38:08 2019 +0200

    testGObjectClass: Verify the usage of GObject classes with wrong base
    
    Test that both registering a GObject with no GObject base and
    intializing a object that has a GObject base fails throwing errors

 installed-tests/js/testGObjectClass.js | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
---
diff --git a/installed-tests/js/testGObjectClass.js b/installed-tests/js/testGObjectClass.js
index 0a68c576..77c6f3ab 100644
--- a/installed-tests/js/testGObjectClass.js
+++ b/installed-tests/js/testGObjectClass.js
@@ -453,3 +453,19 @@ describe('GObject virtual function', function () {
         expect(() => GObject.registerClass({GTypeName: 'SimpleTestClass3'}, _SimpleTestClass3)).toThrow();
     });
 });
+
+describe('GObject creation using base classes without registered GType', function () {
+    it('fails when trying to instantiate a class that inherits from a GObject type', function () {
+        const BadInheritance = class extends GObject.Object {};
+        const BadDerivedInheritance = class extends Derived {};
+
+        expect(() => new BadInheritance()).toThrowError(/Tried to construct an object without a GType/);
+        expect(() => new BadDerivedInheritance()).toThrowError(/Tried to construct an object without a 
GType/);
+    });
+
+    it('fails when trying to register a GObject class that inherits from a non-GObject type', function () {
+        const BadInheritance = class extends GObject.Object {};
+        expect(() => GObject.registerClass(class BadInheritanceDerived extends BadInheritance {}))
+            .toThrowError(/Object 0x[a-f0-9]+ is not a subclass of GObject_Object, it's a Object/);
+    });
+});


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