[gjs/299-can-not-access-gobject-properties-of-classes-without-gi-information: 52/52] Add test for no introspection data.



commit a6a50e10aecd5fa1137882fcfebce6b28f614ab6
Author: Juan Pablo Ugarte <ugarte endlessm com>
Date:   Mon Feb 17 18:54:36 2020 -0300

    Add test for no introspection data.

 test/gjs-test-no-introspection-object.cpp | 92 +++++++++++++++++++++++++++++++
 test/gjs-test-no-introspection-object.h   | 37 +++++++++++++
 test/gjs-tests.cpp                        | 31 +++++++++++
 test/meson.build                          |  1 +
 4 files changed, 161 insertions(+)
---
diff --git a/test/gjs-test-no-introspection-object.cpp b/test/gjs-test-no-introspection-object.cpp
new file mode 100644
index 00000000..0aa24ba1
--- /dev/null
+++ b/test/gjs-test-no-introspection-object.cpp
@@ -0,0 +1,92 @@
+/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright © 2020 Endless Mobile Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "test/gjs-test-no-introspection-object.h"
+
+struct _GjsTestNoIntrospectionObject {
+    GObject parent_instance;
+
+    int a_int;
+};
+
+G_DEFINE_TYPE(GjsTestNoIntrospectionObject, gjstest_no_introspection_object,
+              G_TYPE_OBJECT)
+
+static GjsTestNoIntrospectionObject* last_object = NULL;
+
+static void gjstest_no_introspection_object_init(
+    GjsTestNoIntrospectionObject* self) {
+    self->a_int = 0;
+    last_object = self;
+}
+
+static void gjstest_no_introspection_object_set_property(GObject* object,
+                                                         unsigned prop_id,
+                                                         const GValue* value,
+                                                         GParamSpec* pspec) {
+    GjsTestNoIntrospectionObject* self =
+        GJSTEST_NO_INTROSPECTION_OBJECT(object);
+
+    switch (prop_id) {
+        case 1:
+            self->a_int = g_value_get_int(value);
+            break;
+        default:
+            G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+            break;
+    }
+}
+
+static void gjstest_no_introspection_object_get_property(GObject* object,
+                                                         unsigned prop_id,
+                                                         GValue* value,
+                                                         GParamSpec* pspec) {
+    GjsTestNoIntrospectionObject* self =
+        GJSTEST_NO_INTROSPECTION_OBJECT(object);
+
+    switch (prop_id) {
+        case 1:
+            g_value_set_int(value, self->a_int);
+            break;
+        default:
+            G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+            break;
+    }
+}
+
+static void gjstest_no_introspection_object_class_init(
+    GjsTestNoIntrospectionObjectClass* klass) {
+    GObjectClass* object_class = G_OBJECT_CLASS(klass);
+
+    object_class->set_property = gjstest_no_introspection_object_set_property;
+    object_class->get_property = gjstest_no_introspection_object_get_property;
+
+    g_object_class_install_property(
+        object_class, 1,
+        g_param_spec_int("a-int", "An integer", "An integer property", 0,
+                         100000000, 0, G_PARAM_READWRITE));
+}
+
+GjsTestNoIntrospectionObject* gjstest_no_introspection_object_peek() {
+    return last_object;
+}
diff --git a/test/gjs-test-no-introspection-object.h b/test/gjs-test-no-introspection-object.h
new file mode 100644
index 00000000..07383509
--- /dev/null
+++ b/test/gjs-test-no-introspection-object.h
@@ -0,0 +1,37 @@
+/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright © 2020 Endless Mobile Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef TEST_GJS_TEST_NO_INTROSPECTION_OBJECT_H_
+#define TEST_GJS_TEST_NO_INTROSPECTION_OBJECT_H_
+
+#include <glib-object.h>
+
+#define GJSTEST_TYPE_NO_INTROSPECTION_OBJECT \
+    gjstest_no_introspection_object_get_type()
+G_DECLARE_FINAL_TYPE(GjsTestNoIntrospectionObject,
+                     gjstest_no_introspection_object, GJSTEST,
+                     NO_INTROSPECTION_OBJECT, GObject)
+
+GjsTestNoIntrospectionObject* gjstest_no_introspection_object_peek();
+
+#endif  // TEST_GJS_TEST_NO_INTROSPECTION_OBJECT_H_
diff --git a/test/gjs-tests.cpp b/test/gjs-tests.cpp
index e5922e8d..7d21859d 100644
--- a/test/gjs-tests.cpp
+++ b/test/gjs-tests.cpp
@@ -41,6 +41,7 @@
 #include "gjs/error-types.h"
 #include "gjs/jsapi-util.h"
 #include "gjs/profiler.h"
+#include "test/gjs-test-no-introspection-object.h"
 #include "test/gjs-test-utils.h"
 #include "util/misc.h"
 
@@ -137,6 +138,34 @@ gjstest_test_func_gjs_gobject_js_defined_type(void)
     g_object_unref(context);
 }
 
+static void gjstest_test_func_gjs_gobject_without_introspection(void) {
+    GjsAutoUnref<GjsContext> context = gjs_context_new();
+    GError* error = nullptr;
+    int status;
+
+    /* Ensure class */
+    g_type_class_ref(GJSTEST_TYPE_NO_INTROSPECTION_OBJECT);
+
+#define TESTJS                                                         \
+    "const {GObject} = imports.gi;"                                    \
+    "var obj = GObject.Object.newv("                                   \
+    "    GObject.type_from_name('GjsTestNoIntrospectionObject'), []);" \
+    "obj.a_int = 1234;"
+
+    bool ok = gjs_context_eval(context, TESTJS, -1, "<input>", &status, &error);
+    g_assert_true(ok);
+    g_assert_no_error(error);
+
+    GjsTestNoIntrospectionObject* obj = gjstest_no_introspection_object_peek();
+    g_assert_nonnull(obj);
+
+    int val = 0;
+    g_object_get(obj, "a-int", &val, NULL);
+    g_assert_cmpint(val, ==, 1234);
+
+#undef TESTJS
+}
+
 static void gjstest_test_func_gjs_jsapi_util_string_js_string_utf8(
     GjsUnitTestFixture* fx, const void*) {
     JS::RootedValue js_string(fx->cx);
@@ -372,6 +401,8 @@ main(int    argc,
                     gjstest_test_func_gjs_context_eval_non_zero_terminated);
     g_test_add_func("/gjs/context/exit", gjstest_test_func_gjs_context_exit);
     g_test_add_func("/gjs/gobject/js_defined_type", gjstest_test_func_gjs_gobject_js_defined_type);
+    g_test_add_func("/gjs/gobject/without_introspection",
+                    gjstest_test_func_gjs_gobject_without_introspection);
     g_test_add_func("/gjs/profiler/start_stop", gjstest_test_profiler_start_stop);
     g_test_add_func("/util/misc/strv/concat/null",
                     gjstest_test_func_util_misc_strv_concat_null);
diff --git a/test/meson.build b/test/meson.build
index de2d7c0e..8cea4989 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -11,6 +11,7 @@ gjs_tests_sources = [
     'gjs-test-call-args.cpp',
     'gjs-test-coverage.cpp',
     'gjs-test-rooting.cpp',
+    'gjs-test-no-introspection-object.cpp', 'gjs-test-no-introspection-object.h',
 ]
 
 gjs_tests = executable('gjs-tests', gjs_tests_sources, mock_js_resources_files,


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