[gjs: 10/22] installed-tests: Add GjsTestTools utilities to call native code for evil ops




commit 79c2ac3a935fa71181614e86902c122941b950f6
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Thu Mar 25 21:29:10 2021 +0100

    installed-tests: Add GjsTestTools utilities to call native code for evil ops
    
    At times we may need to simulate bad behaviors of other libraries, so to
    check this we need to do evil hacks with the objects like ref or unref
    them without having JS envolved.
    
    To allow this, add an utility class that we introspect and can use for
    testing.

 .../js/libgjstesttools/gjs-test-tools.cpp          | 39 ++++++++++++++++++++++
 .../js/libgjstesttools/gjs-test-tools.h            | 23 +++++++++++++
 installed-tests/js/libgjstesttools/meson.build     | 19 +++++++++++
 installed-tests/js/meson.build                     |  3 ++
 meson.build                                        |  5 +--
 5 files changed, 87 insertions(+), 2 deletions(-)
---
diff --git a/installed-tests/js/libgjstesttools/gjs-test-tools.cpp 
b/installed-tests/js/libgjstesttools/gjs-test-tools.cpp
new file mode 100644
index 00000000..4474e6e0
--- /dev/null
+++ b/installed-tests/js/libgjstesttools/gjs-test-tools.cpp
@@ -0,0 +1,39 @@
+/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
+// SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
+// SPDX-FileCopyrightText: 2021 Marco Trevisan <marco trevisan canonical com>
+
+#include "installed-tests/js/libgjstesttools/gjs-test-tools.h"
+
+void gjs_test_tools_init() {}
+
+void gjs_test_tools_reset() {}
+
+void gjs_test_tools_delayed_ref(GObject* object, int interval) {
+    g_timeout_add(
+        interval,
+        [](void *data) {
+            g_object_ref(G_OBJECT(data));
+            return G_SOURCE_REMOVE;
+        },
+        object);
+}
+
+void gjs_test_tools_delayed_unref(GObject* object, int interval) {
+    g_timeout_add(
+        interval,
+        [](void *data) {
+            g_object_unref(G_OBJECT(data));
+            return G_SOURCE_REMOVE;
+        },
+        object);
+}
+
+void gjs_test_tools_delayed_dispose(GObject* object, int interval) {
+    g_timeout_add(
+        interval,
+        [](void *data) {
+            g_object_run_dispose(G_OBJECT(data));
+            return G_SOURCE_REMOVE;
+        },
+        object);
+}
diff --git a/installed-tests/js/libgjstesttools/gjs-test-tools.h 
b/installed-tests/js/libgjstesttools/gjs-test-tools.h
new file mode 100644
index 00000000..478a2bc3
--- /dev/null
+++ b/installed-tests/js/libgjstesttools/gjs-test-tools.h
@@ -0,0 +1,23 @@
+/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
+// SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
+// SPDX-FileCopyrightText: 2021 Marco Trevisan <marco trevisan canonical com>
+
+#pragma once
+
+#include <gio/gio.h>
+#include <glib-object.h>
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+void gjs_test_tools_init(void);
+
+void gjs_test_tools_reset(void);
+
+void gjs_test_tools_delayed_ref(GObject* object, int interval);
+
+void gjs_test_tools_delayed_unref(GObject* object, int interval);
+
+void gjs_test_tools_delayed_dispose(GObject* object, int interval);
+
+G_END_DECLS
diff --git a/installed-tests/js/libgjstesttools/meson.build b/installed-tests/js/libgjstesttools/meson.build
new file mode 100644
index 00000000..2371f6fd
--- /dev/null
+++ b/installed-tests/js/libgjstesttools/meson.build
@@ -0,0 +1,19 @@
+# SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
+# SPDX-FileCopyrightText: 2021 Marco Trevisan <marco trevisan canonical com>
+
+gjstest_tools_sources = [
+    'gjs-test-tools.cpp',
+    'gjs-test-tools.h',
+]
+libgjstesttools = library('gjstesttools',
+    gjstest_tools_sources, dependencies: [glib, gobject, gio],
+    include_directories: top_include, dependencies: libgjs_dep,
+    cpp_args: libgjs_cpp_args + test_gir_extra_c_args + test_gir_warning_c_args,
+    install: get_option('installed_tests'), install_dir: installed_tests_execdir)
+gjstest_tools_gir = gnome.generate_gir(libgjstesttools,
+    includes: ['GObject-2.0', 'Gio-2.0'], sources: gjstest_tools_sources,
+    namespace: 'GjsTestTools', nsversion: '1.0',
+    symbol_prefix: 'gjs_test_tools_', extra_args: '--warn-error',
+    install: get_option('installed_tests'), install_dir_gir: false,
+    install_dir_typelib: installed_tests_execdir)
+gjstest_tools_typelib = gjstest_tools_gir[1]
diff --git a/installed-tests/js/meson.build b/installed-tests/js/meson.build
index 8026f903..97f9cd07 100644
--- a/installed-tests/js/meson.build
+++ b/installed-tests/js/meson.build
@@ -89,6 +89,8 @@ gimarshallingtests_gir = gnome.generate_gir(libgimarshallingtests,
     install_dir_typelib: installed_tests_execdir)
 gimarshallingtests_typelib = gimarshallingtests_gir[1]
 
+subdir('libgjstesttools')
+
 jasmine_tests = [
     'self',
     'ByteArray',
@@ -149,6 +151,7 @@ foreach test : jasmine_tests
     test(test, minijasmine, args: test_file,
         depends: [
             gschemas_compiled,
+            gjstest_tools_typelib,
             gimarshallingtests_typelib,
             regress_typelib,
             warnlib_typelib,
diff --git a/meson.build b/meson.build
index 33a3389d..272f2033 100644
--- a/meson.build
+++ b/meson.build
@@ -577,15 +577,16 @@ pkg.generate(libgjs, name: api_name, description: 'JS bindings for GObjects',
 
 tests_environment = environment()
 js_tests_builddir = meson.current_build_dir() / 'installed-tests' / 'js'
+libgjs_test_tools_builddir = js_tests_builddir / 'libgjstesttools'
 # GJS_PATH is empty here since we want to force the use of our own
 # resources. G_FILENAME_ENCODING ensures filenames are not UTF-8
 tests_environment.set('TOP_BUILDDIR', meson.build_root())
 tests_environment.set('GJS_USE_UNINSTALLED_FILES', '1')
 tests_environment.set('GJS_PATH', '')
 tests_environment.prepend('GI_TYPELIB_PATH', meson.current_build_dir(),
-    js_tests_builddir)
+    js_tests_builddir, libgjs_test_tools_builddir)
 tests_environment.prepend('LD_LIBRARY_PATH', meson.current_build_dir(),
-    js_tests_builddir)
+    js_tests_builddir, libgjs_test_tools_builddir)
 tests_environment.set('G_FILENAME_ENCODING', 'latin1')
 # Workaround for https://github.com/google/sanitizers/issues/1322
 tests_environment.set('ASAN_OPTIONS', 'intercept_tls_get_addr=0')


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