[gjs/wip/inheritance-warning] testGObjectClass: Verify the usage of GObject classes with wrong base



commit 2adc750918198c937ffcc5c4aa8c60cb98ef6a1d
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..b140f5e4 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 invalid base classes', 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]