[gjs: 4/5] Fix GObject vfunc regression tests



commit 5a681bdeae122d2366b62dd4d62abb3cd01cbfa3
Author: Jason Hicks <jaszhix gmail com>
Date:   Thu Jan 10 18:34:06 2019 -0600

    Fix GObject vfunc regression tests

 installed-tests/js/testGIMarshalling.js | 108 +++++++++++++-------------------
 1 file changed, 45 insertions(+), 63 deletions(-)
---
diff --git a/installed-tests/js/testGIMarshalling.js b/installed-tests/js/testGIMarshalling.js
index 2310725a..b6ed566c 100644
--- a/installed-tests/js/testGIMarshalling.js
+++ b/installed-tests/js/testGIMarshalling.js
@@ -664,90 +664,72 @@ describe('GObject virtual function', function () {
     });
 
     it('can have its property overridden with an anonymous function', function () {
-        try {
-            let callback = {
-                vfunc_constructed: (a) => `constructed${a}`
-            };
+        let callback;
 
-            let key = 'vfunc_constructed';
+        let key = 'vfunc_constructed';
 
-            class _SimpleTestClass1 extends GObject.Object {
-                constructor() {
-                    super(...arguments);
-                    this.__constructed = false;
-                }
+        class _SimpleTestClass1 extends GObject.Object {
+            _init() {
+                super._init(...arguments);
             }
+        }
 
-            if (GObject.Object.prototype.vfunc_constructed) {
-                let parentFunc = GObject.Object.prototype.vfunc_constructed;
-                _SimpleTestClass1.prototype[key] = function () {
-                    parentFunc.call(this, ...arguments);
-                    this.__constructed = callback[key]('123');
-                };
-            } else {
-                _SimpleTestClass1.prototype[key] = function () {
-                    this.__constructed = true;
-                };
-            }
+        if (GObject.Object.prototype.vfunc_constructed) {
+            let parentFunc = GObject.Object.prototype.vfunc_constructed;
+            _SimpleTestClass1.prototype[key] = function () {
+                parentFunc.call(this, ...arguments);
+                callback('123');
+            };
+        } else {
+            _SimpleTestClass1.prototype[key] = function () {
+                callback('abc');
+            };
+        }
 
-            const SimpleTestClass1 = GObject.registerClass({GTypeName: 'SimpleTestClass1'}, 
_SimpleTestClass1);
+        callback = jasmine.createSpy('callback');
 
-            let testInstance = new SimpleTestClass1();
+        const SimpleTestClass1 = GObject.registerClass({GTypeName: 'SimpleTestClass1'}, _SimpleTestClass1);
+        new SimpleTestClass1();
 
-            expect(testInstance.__constructed).toEqual('constructed123');
-        } catch (e) {
-            fail('Exception should not be thrown');
-        }
+        expect(callback).toHaveBeenCalledWith('123');
     });
 
     it('can access the parent prototype with super()', function () {
-        try {
-            class _SimpleTestClass2 extends GObject.Object {
-                constructor() {
-                    super(...arguments);
-                    this.__constructed = false;
-                }
-
-                vfunc_constructed() {
-                    super.vfunc_constructed();
-                    this.__constructed = true;
-                }
-            }
-
-            const SimpleTestClass2 = GObject.registerClass({GTypeName: 'SimpleTestClass2'}, 
_SimpleTestClass2);
+        let callback;
 
-            let testInstance = new SimpleTestClass2();
+        class _SimpleTestClass2 extends GObject.Object {
+            _init() {
+                super._init(...arguments);
+            }
 
-            expect(testInstance.__constructed).toEqual(true);
-        } catch (e) {
-            fail('Exception should not be thrown');
+            vfunc_constructed() {
+                super.vfunc_constructed();
+                callback('vfunc_constructed');
+            }
         }
-    });
 
-    it('handles non-existing properties', function () {
-        try {
+        callback = jasmine.createSpy('callback');
 
-            const _SimpleTestClass3 = class extends GObject.Object {
-                constructor() {
-                    super(...arguments);
-                    this.__constructed = false;
-                }
-            };
+        const SimpleTestClass2 = GObject.registerClass({GTypeName: 'SimpleTestClass2'}, _SimpleTestClass2);
+        new SimpleTestClass2();
 
-            _SimpleTestClass3.prototype.vfunc_doesnt_exist = function () {};
+        expect(callback).toHaveBeenCalledWith('vfunc_constructed');
+    });
 
-            if (GObject.Object.prototype.vfunc_doesnt_exist) {
-                fail('Virtual function should not exist');
+    it('handles non-existing properties', function () {
+        const _SimpleTestClass3 = class extends GObject.Object {
+            _init() {
+                super._init(...arguments);
             }
+        };
 
-            const SimpleTestClass3 = GObject.registerClass({GTypeName: 'SimpleTestClass3'}, 
_SimpleTestClass3);
-
-            let testInstance = new SimpleTestClass3();
+        _SimpleTestClass3.prototype.vfunc_doesnt_exist = function () {};
 
-            expect(testInstance.__constructed).toEqual(undefined);
+        if (GObject.Object.prototype.vfunc_doesnt_exist) {
+            fail('Virtual function should not exist');
+        }
 
-            fail('Exception should be thrown');
-        } catch (e) {}
+        expect(() => GObject.registerClass({GTypeName: 'SimpleTestClass3'}, _SimpleTestClass3)).toThrow();
     });
 });
 


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