[gjs: 2/14] testFundamental: Add more tests ensuring we can upcast but not downcast




commit e1e61163bbd579b2dd2c9d5de186963e978a31a2
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Thu Apr 8 17:06:19 2021 +0200

    testFundamental: Add more tests ensuring we can upcast but not downcast
    
    It's legal to call a function requiring a super type, but not a subtype.
    We already checked this in code but we did not have a test for it

 installed-tests/js/testFundamental.js | 55 +++++++++++++++++++++++++++++++++--
 1 file changed, 52 insertions(+), 3 deletions(-)
---
diff --git a/installed-tests/js/testFundamental.js b/installed-tests/js/testFundamental.js
index 2467a0e9..4b555b61 100644
--- a/installed-tests/js/testFundamental.js
+++ b/installed-tests/js/testFundamental.js
@@ -6,15 +6,21 @@ const {GObject, Regress} = imports.gi;
 
 const TestObj = GObject.registerClass({
     Signals: {
-        'test-fundamental-value-funcs': {param_types: [Regress.TestFundamentalSubObject.$gtype]},
+        'test-fundamental-value-funcs': {param_types: [Regress.TestFundamentalObject.$gtype]},
+        'test-fundamental-value-funcs-subtype': {param_types: [Regress.TestFundamentalSubObject.$gtype]},
         'test-fundamental-no-funcs': {param_types:
             Regress.TestFundamentalObjectNoGetSetFunc
                 ? [Regress.TestFundamentalObjectNoGetSetFunc.$gtype] : []},
+        'test-fundamental-no-funcs-subtype': {
+            param_types:
+                Regress.TestFundamentalSubObjectNoGetSetFunc
+                    ? [Regress.TestFundamentalSubObjectNoGetSetFunc.$gtype] : [],
+        },
     },
 }, class TestObj extends GObject.Object {});
 
 describe('Fundamental type support', function () {
-    it('can marshal a subtype of a custom fundamental type into a GValue', function () {
+    it('can marshal a subtype of a custom fundamental type into a supertype GValue', function () {
         const fund = new Regress.TestFundamentalSubObject('plop');
         expect(() => GObject.strdup_value_contents(fund)).not.toThrow();
 
@@ -25,6 +31,15 @@ describe('Fundamental type support', function () {
         expect(signalSpy).toHaveBeenCalledWith(obj, fund);
     });
 
+    it('can marshal a subtype of a custom fundamental type into a GValue', function () {
+        const fund = new Regress.TestFundamentalSubObject('plop');
+        const obj = new TestObj();
+        const signalSpy = jasmine.createSpy('signalSpy');
+        obj.connect('test-fundamental-value-funcs-subtype', signalSpy);
+        obj.emit('test-fundamental-value-funcs-subtype', fund);
+        expect(signalSpy).toHaveBeenCalledWith(obj, fund);
+    });
+
     it('can marshal a custom fundamental type into a GValue if contains a pointer and does not provide 
setter and getters', function () {
         const fund = new Regress.TestFundamentalObjectNoGetSetFunc('foo');
         expect(() => GObject.strdup_value_contents(fund)).not.toThrow();
@@ -38,6 +53,18 @@ describe('Fundamental type support', function () {
         expect(signalSpy).toHaveBeenCalledWith(obj, fund);
     }).pend('https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/268');
 
+    it('can marshal a subtype of a custom fundamental type into a GValue if contains a pointer and does not 
provide setter and getters', function () {
+        const fund = new Regress.TestFundamentalSubObjectNoGetSetFunc('foo');
+
+        const obj = new TestObj();
+        const signalSpy = jasmine.createSpy('signalSpy');
+        obj.connect('test-fundamental-no-funcs-subtype', signalSpy);
+        obj.connect('test-fundamental-no-funcs-subtype', (_o, f) =>
+            expect(f.get_data()).toBe('foo'));
+        obj.emit('test-fundamental-no-funcs-subtype', fund);
+        expect(signalSpy).toHaveBeenCalledWith(obj, fund);
+    }).pend('https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/268');
+
     it('cannot marshal a custom fundamental type into a GValue of different gtype', function () {
         const fund = new Regress.TestFundamentalObjectNoGetSetFunc('foo');
 
@@ -45,6 +72,28 @@ describe('Fundamental type support', function () {
         const signalSpy = jasmine.createSpy('signalSpy');
         obj.connect('test-fundamental-value-funcs', signalSpy);
         expect(() => obj.emit('test-fundamental-value-funcs', fund)).toThrowError(
-            /.* RegressTestFundamentalObjectNoGetSetFunc .* conversion to a GValue.* 
RegressTestFundamentalSubObject/);
+            / RegressTestFundamentalObjectNoGetSetFunc .* conversion to a GValue.* 
RegressTestFundamentalObject/);
+    }).pend('https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/268');
+
+    it('can marshal a custom fundamental type into a GValue of super gtype', function () {
+        const fund = new Regress.TestFundamentalSubObjectNoGetSetFunc('foo');
+
+        const obj = new TestObj();
+        const signalSpy = jasmine.createSpy('signalSpy');
+        obj.connect('test-fundamental-no-funcs', signalSpy);
+        obj.connect('test-fundamental-no-funcs', (_o, f) =>
+            expect(f.get_data()).toBe('foo'));
+        obj.emit('test-fundamental-no-funcs', fund);
+        expect(signalSpy).toHaveBeenCalledWith(obj, fund);
+    }).pend('https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/268');
+
+    it('cannot marshal a custom fundamental type into a GValue of sub gtype', function () {
+        const fund = new Regress.TestFundamentalObjectNoGetSetFunc('foo');
+
+        const obj = new TestObj();
+        const signalSpy = jasmine.createSpy('signalSpy');
+        obj.connect('test-fundamental-no-funcs-subtype', signalSpy);
+        expect(() => obj.emit('test-fundamental-no-funcs-subtype', fund)).toThrowError(
+            / RegressTestFundamentalObjectNoGetSetFunc .* conversion to a GValue.* 
RegressTestFundamentalSubObjectNoGetSetFunc/);
     }).pend('https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/268');
 });


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