[gjs: 5/12] tests: Increase coverage of Regress and GIMarshalling test suite




commit ef05c105bb9d144b06f440862ef34bb4a6c23e5f
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat Mar 20 12:39:25 2021 -0700

    tests: Increase coverage of Regress and GIMarshalling test suite
    
    These tests are available in the GIMarshallingTests and Regress typelibs,
    but never had corresponding tests added in GJS.
    
    Some of them are skipped due to not being supported yet, and are annotated
    with the corresponding issue or merge request.

 installed-tests/js/testGIMarshalling.js |  85 ++++++++++++++++++++++
 installed-tests/js/testRegress.js       | 125 ++++++++++++++++++++++++++++++++
 2 files changed, 210 insertions(+)
---
diff --git a/installed-tests/js/testGIMarshalling.js b/installed-tests/js/testGIMarshalling.js
index b148b0e7..83902f0d 100644
--- a/installed-tests/js/testGIMarshalling.js
+++ b/installed-tests/js/testGIMarshalling.js
@@ -329,6 +329,7 @@ describe('Fixed-size C array', function () {
     describe('of ints', function () {
         testReturnValue('array_fixed_int', [-1, 0, 1, 2]);
         testInParameter('array_fixed_int', [-1, 0, 1, 2]);
+        testOutParameter('array_fixed', [-1, 0, 1, 2]);
         testInoutParameter('array_fixed', [-1, 0, 1, 2], [2, 1, 0, -1]);
     });
 
@@ -903,6 +904,13 @@ describe('Callback', function () {
         expect(GIMarshallingTests.callback_array_out_parameter(() => [50, 51]))
             .toEqual([50, 51]);
     }).pend('Function not added to gobject-introspection test suite yet');
+
+    it('marshals a callback parameter that can be called from C', function () {
+        expect(GIMarshallingTests.callback_owned_boxed(box => {
+            expect(box.long_).toEqual(1);
+            box.long_ = 52;
+        })).toEqual(52);
+    });
 });
 
 describe('Raw pointers', function () {
@@ -936,6 +944,10 @@ describe('Registered flags type', function () {
                 funcName: 'flags_returnv',
             },
         });
+
+    it('accepts zero', function () {
+        expect(() => GIMarshallingTests.flags_in_zero(0)).not.toThrow();
+    });
 });
 
 describe('Bare flags type', function () {
@@ -945,6 +957,10 @@ describe('Bare flags type', function () {
                 funcName: 'no_type_flags_returnv',
             },
         });
+
+    it('accepts zero', function () {
+        expect(() => GIMarshallingTests.no_type_flags_in_zero(0)).not.toThrow();
+    });
 });
 
 describe('Simple struct', function () {
@@ -1101,6 +1117,34 @@ describe('GObject', function () {
 });
 
 let VFuncTester = GObject.registerClass(class VFuncTester extends GIMarshallingTests.Object {
+    vfunc_method_int8_in(i) {
+        this.int = i;
+    }
+
+    vfunc_method_int8_out() {
+        return 40;
+    }
+
+    vfunc_method_int8_arg_and_out_caller(i) {
+        return i + 3;
+    }
+
+    vfunc_method_int8_arg_and_out_callee(i) {
+        return i + 4;
+    }
+
+    vfunc_method_str_arg_out_ret(s) {
+        return [`Called with ${s}`, 41];
+    }
+
+    vfunc_method_with_default_implementation(i) {
+        this.int = i + 2;
+    }
+
+    // vfunc_vfunc_with_callback(callback) {
+    //     this.int = callback(41);
+    // }
+
     vfunc_vfunc_return_value_only() {
         return 42;
     }
@@ -1223,6 +1267,37 @@ describe('Virtual function', function () {
         tester = new VFuncTester();
     });
 
+    it('marshals an in argument', function () {
+        tester.method_int8_in(39);
+        expect(tester.int).toEqual(39);
+    });
+
+    it('marshals an out argument', function () {
+        expect(tester.method_int8_out()).toEqual(40);
+    });
+
+    xit('marshals a POD out argument', function () {
+        expect(tester.method_int8_arg_and_out_caller(39)).toEqual(42);
+    }).pend('https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/263');
+
+    it('marshals a callee-allocated pointer out argument', function () {
+        expect(tester.method_int8_arg_and_out_callee(38)).toEqual(42);
+    });
+
+    xit('marshals a string out argument and return value', function () {
+        expect(tester.method_str_arg_out_ret('a string')).toEqual(['Called with a string', 41]);
+    }).pend('https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/263');
+
+    it('can override a default implementation in JS', function () {
+        tester.method_with_default_implementation(40);
+        expect(tester.int).toEqual(42);
+    });
+
+    xit('marshals a callback', function () {
+        tester.call_vfunc_with_callback();
+        expect(tester.int).toEqual(41);
+    }).pend('callback parameters to vfuncs not supported');
+
     it('marshals a return value', function () {
         expect(tester.vfunc_return_value_only()).toEqual(42);
     });
@@ -1660,6 +1735,11 @@ describe('Overrides', function () {
         expect(struct.method()).toEqual(6);
     });
 
+    it('returns the overridden struct', function () {
+        const obj = GIMarshallingTests.OverridesStruct.returnv();
+        expect(obj).toBeInstanceOf(GIMarshallingTests.OverridesStruct);
+    });
+
     it('can override an object constructor', function () {
         const obj = new GIMarshallingTests.OverridesObject(42);
         expect(obj.num).toEqual(42);
@@ -1669,6 +1749,11 @@ describe('Overrides', function () {
         const obj = new GIMarshallingTests.OverridesObject();
         expect(obj.method()).toEqual(6);
     });
+
+    it('returns the overridden object', function () {
+        const obj = GIMarshallingTests.OverridesObject.returnv();
+        expect(obj).toBeInstanceOf(GIMarshallingTests.OverridesObject);
+    });
 });
 
 describe('Filename', function () {
diff --git a/installed-tests/js/testRegress.js b/installed-tests/js/testRegress.js
index f067f1a1..7a1fea42 100644
--- a/installed-tests/js/testRegress.js
+++ b/installed-tests/js/testRegress.js
@@ -285,6 +285,11 @@ describe('Life, the Universe and Everything', function () {
         });
     });
 
+    it('integer array with static length', function () {
+        const arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
+        expect(() => Regress.test_array_static_in_int(arr)).not.toThrow();
+    });
+
     it("string array that's const in C", function () {
         expect(Regress.test_strv_out_c()).toEqual(['thanks', 'for', 'all', 'the', 'fish']);
     });
@@ -925,6 +930,113 @@ describe('Life, the Universe and Everything', function () {
             expect(v).toEqual(jasmine.any(Regress.TestObj));
         });
 
+        describe('GProperty', function () {
+            let t, boxed, hashTable, hashTable2, list2, string, gtype, byteArray;
+            const list = null;
+            const int = 42;
+            const double = Math.PI;
+            const double2 = Math.E;
+
+            beforeEach(function () {
+                boxed = new Regress.TestBoxed({some_int8: 127});
+                hashTable = {a: 1, b: 2};
+                hashTable2 = {c: 3, d: 4};
+                list2 = ['j', 'k', 'l'];
+                string = 'cauliflower';
+                gtype = GObject.Object.$gtype;
+                byteArray = Uint8Array.from('abcd', c => c.charCodeAt(0));
+                t = new Regress.TestObj({
+                    boxed,
+                    // hashTable,
+                    list,
+                    // pptrarray: list,
+                    // hashTableOld: hashTable,
+                    listOld: list,
+                    int,
+                    float: double,
+                    double,
+                    string,
+                    gtype,
+                    // byteArray,
+                });
+            });
+
+            it('Boxed type', function () {
+                expect(t.boxed.some_int8).toBe(127);
+                const boxed2 = new Regress.TestBoxed({some_int8: 31});
+                t.boxed = boxed2;
+                expect(t.boxed.some_int8).toBe(31);
+            });
+
+            xit('Hash table', function () {
+                expect(t.hashTable).toBe(hashTable);
+                t.hashTable = hashTable2;
+                expect(t.hashTable).toBe(hashTable2);
+            }).pend('https://gitlab.gnome.org/GNOME/gjs/-/issues/83');
+
+            xit('List', function () {
+                expect(t.list).toBe(list);
+                t.list = list2;
+                expect(t.list).toBe(list2);
+            }).pend('https://gitlab.gnome.org/GNOME/gjs/-/issues/83');
+
+            xit('Pointer array', function () {
+                expect(t.pptrarray).toBe(list);
+                t.pptrarray = list2;
+                expect(t.pptrarray).toBe(list2);
+            }).pend('https://gitlab.gnome.org/GNOME/gjs/-/issues/83');
+
+            xit('Hash table with old-style annotation', function () {
+                expect(t.hashTableOld).toBe(hashTable);
+                t.hashTableOld = hashTable2;
+                expect(t.hashTableOld).toBe(hashTable2);
+            }).pend('https://gitlab.gnome.org/GNOME/gjs/-/issues/83');
+
+            xit('List with old-style annotation', function () {
+                expect(t.listOld).toBe(list);
+                t.listOld = list2;
+                expect(t.listOld).toBe(list2);
+            }).pend('https://gitlab.gnome.org/GNOME/gjs/-/issues/83');
+
+            it('Integer', function () {
+                expect(t.int).toBe(int);
+                t.int = 35;
+                expect(t.int).toBe(35);
+            });
+
+            it('Float', function () {
+                expect(t.float).toBeCloseTo(double);
+                t.float = double2;
+                expect(t.float).toBeCloseTo(double2);
+            });
+
+            it('Double', function () {
+                expect(t.double).toBeCloseTo(double);
+                t.double = double2;
+                expect(t.double).toBeCloseTo(double2);
+            });
+
+            it('String', function () {
+                expect(t.string).toBe(string);
+                t.string = 'string2';
+                expect(t.string).toBe('string2');
+            });
+
+            xit('GType object', function () {
+                expect(t.gtype).toBe(gtype);
+                const gtype2 = GObject.InitiallyUnowned.$gtype;
+                t.gtype = gtype2;
+                expect(t.gtype).toBe(gtype2);
+            }).pend('https://gitlab.gnome.org/GNOME/gjs/-/issues/83');
+
+            xit('Byte array', function () {
+                expect(t.byteArray).toBe(byteArray);
+                const byteArray2 = Uint8Array.from('efgh', c => c.charCodeAt(0));
+                t.byteArray = byteArray2;
+                expect(t.byteArray).toBe(byteArray2);
+            }).pend('https://gitlab.gnome.org/GNOME/gjs/-/issues/276');
+        });
+
         describe('Object-valued GProperty', function () {
             let o1, t1, t2;
             beforeEach(function () {
@@ -1250,6 +1362,7 @@ describe('Life, the Universe and Everything', function () {
                 int: 42,
                 float: Math.PI,
                 double: Math.E,
+                boolean: true,
             });
         });
 
@@ -1267,6 +1380,12 @@ describe('Life, the Universe and Everything', function () {
         it('can call an instance method that overrides the parent class', function () {
             expect(subobj.instance_method()).toEqual(0);
         });
+
+        it('can have its own properties', function () {
+            expect(subobj.boolean).toBeTruthy();
+            subobj.boolean = false;
+            expect(subobj.boolean).toBeFalsy();
+        });
     });
 
     describe('Overridden properties on interfaces', function () {
@@ -1403,6 +1522,12 @@ describe('Life, the Universe and Everything', function () {
         expect(callback).toHaveBeenCalled();
     });
 
+    it('static method taking a callback', function () {
+        const callback = jasmine.createSpy('callback');
+        Regress.TestObj.static_method_callback(callback);
+        expect(callback).toHaveBeenCalled();
+    });
+
     it('constructor taking a callback', function () {
         const callback = jasmine.createSpy('callback').and.returnValue(42);
         void Regress.TestObj.new_callback(callback);


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