[gjs/gnome-40: 11/30] testGObjectDestructionAccess: Verify that disposed object is monitored




commit 38adaaff66063e5daf1add773294ebacba1e214e
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Thu Mar 25 21:42:24 2021 +0100

    testGObjectDestructionAccess: Verify that disposed object is monitored
    
    Thanks to the evil hacks we have now we can perform a delayed unref
    without having to rely on pure JS code.
    
    So we can test the case in which a JS-disposed (only) object is later
    finalized by C code.
    
    (cherry-picked from commit a1bbcdae)

 installed-tests/js/testGObjectDestructionAccess.js | 31 ++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)
---
diff --git a/installed-tests/js/testGObjectDestructionAccess.js 
b/installed-tests/js/testGObjectDestructionAccess.js
index 8cd439ad..a0f2c99a 100644
--- a/installed-tests/js/testGObjectDestructionAccess.js
+++ b/installed-tests/js/testGObjectDestructionAccess.js
@@ -4,7 +4,7 @@
 
 imports.gi.versions.Gtk = '3.0';
 
-const {GLib, Gio, GObject, Gtk} = imports.gi;
+const {GLib, Gio, GjsTestTools, GObject, Gtk} = imports.gi;
 const {system: System} = imports;
 
 describe('Access to destroyed GObject', function () {
@@ -164,6 +164,14 @@ describe('Access to destroyed GObject', function () {
 });
 
 describe('Disposed or finalized GObject', function () {
+    beforeAll(function () {
+        GjsTestTools.init();
+    });
+
+    afterEach(function () {
+        GjsTestTools.reset();
+    });
+
     it('is marked as disposed when it is a manually disposed property', function () {
         const emblem = new Gio.EmblemedIcon({
             gicon: new Gio.ThemedIcon({ name: 'alarm' }),
@@ -195,11 +203,30 @@ describe('Disposed or finalized GObject', function () {
         expect(file.toString()).toMatch(
             /\[object \(FINALIZED\) instance wrapper GType:GLocalFile jsobj@0x[a-f0-9]+ 
native@0x[a-f0-9]+\]/);
         file = null;
+        GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_CRITICAL,
+            '*Object 0x* has been finalized *');
+        System.gc();
+        GLib.test_assert_expected_messages_internal('Gjs', 'testGObjectDestructionAccess.js', 0,
+            'generates a warn on object garbage collection if has expando property');
+    });
+
+    it('generates a warn if already disposed at garbage collection', function () {
+        const loop = new GLib.MainLoop(null, false);
+
+        let file = Gio.File.new_for_path('/');
+        GjsTestTools.delayed_unref(file, 1);  // Will happen after dispose
+        file.run_dispose();
+
+        let done = false;
+        GLib.timeout_add(GLib.PRIORITY_DEFAULT, 50, () => (done = true));
+        while (!done)
+            loop.get_context().iteration(true);
 
+        file = null;
         GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_CRITICAL,
             '*Object 0x* has been finalized *');
         System.gc();
         GLib.test_assert_expected_messages_internal('Gjs', 'testGObjectDestructionAccess.js', 0,
-            'generates a warn on object garbage collection');
+            'generates a warn if already disposed at garbage collection');
     });
 });


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