Commit 3ccac3e7 authored by Philip Chimento's avatar Philip Chimento

Merge branch 'allow-checking-vfunc-props' into 'master'

Add regression tests for GObject vfuncs

See merge request GNOME/gjs!259
parents 7b9d03de 5a681bde
......@@ -658,6 +658,81 @@ describe('Virtual function', function () {
});
});
describe('GObject virtual function', function () {
it('can have its property read', function () {
expect(GObject.Object.prototype.vfunc_constructed).toBeTruthy();
});
it('can have its property overridden with an anonymous function', function () {
let callback;
let key = 'vfunc_constructed';
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);
callback('123');
};
} else {
_SimpleTestClass1.prototype[key] = function () {
callback('abc');
};
}
callback = jasmine.createSpy('callback');
const SimpleTestClass1 = GObject.registerClass({GTypeName: 'SimpleTestClass1'}, _SimpleTestClass1);
new SimpleTestClass1();
expect(callback).toHaveBeenCalledWith('123');
});
it('can access the parent prototype with super()', function () {
let callback;
class _SimpleTestClass2 extends GObject.Object {
_init() {
super._init(...arguments);
}
vfunc_constructed() {
super.vfunc_constructed();
callback('vfunc_constructed');
}
}
callback = jasmine.createSpy('callback');
const SimpleTestClass2 = GObject.registerClass({GTypeName: 'SimpleTestClass2'}, _SimpleTestClass2);
new SimpleTestClass2();
expect(callback).toHaveBeenCalledWith('vfunc_constructed');
});
it('handles non-existing properties', function () {
const _SimpleTestClass3 = class extends GObject.Object {
_init() {
super._init(...arguments);
}
};
_SimpleTestClass3.prototype.vfunc_doesnt_exist = function () {};
if (GObject.Object.prototype.vfunc_doesnt_exist) {
fail('Virtual function should not exist');
}
expect(() => GObject.registerClass({GTypeName: 'SimpleTestClass3'}, _SimpleTestClass3)).toThrow();
});
});
describe('Interface', function () {
it('can be returned', function () {
let ifaceImpl = new GIMarshallingTests.InterfaceImpl();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment