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



commit a6e9ba197ca696f3d2c501f6ed928a52050a8c70
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 | 94 +++++++++++++++++++++++++++++++
 test/gjs-test-no-introspection-object.h   | 38 +++++++++++++
 test/gjs-tests.cpp                        | 69 +++++++++++++++--------
 test/meson.build                          |  1 +
 4 files changed, 179 insertions(+), 23 deletions(-)
---
diff --git a/test/gjs-test-no-introspection-object.cpp b/test/gjs-test-no-introspection-object.cpp
new file mode 100644
index 00000000..89e0c778
--- /dev/null
+++ b/test/gjs-test-no-introspection-object.cpp
@@ -0,0 +1,94 @@
+/* -*- 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;
+
+    gint 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,
+                                             guint         prop_id,
+                                             const GValue *value,
+                                             GParamSpec   *pspec) {
+    GjsTestNoIntrospectionObject *self = reinterpret_cast<GjsTestNoIntrospectionObject *>(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,
+                                             guint       prop_id,
+                                             GValue     *value,
+                                             GParamSpec *pspec) {
+    GjsTestNoIntrospectionObject *self = reinterpret_cast<GjsTestNoIntrospectionObject *>(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..a0ad11b3
--- /dev/null
+++ b/test/gjs-test-no-introspection-object.h
@@ -0,0 +1,38 @@
+/* -*- 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 45ebe243..93a3b22f 100644
--- a/test/gjs-tests.cpp
+++ b/test/gjs-tests.cpp
@@ -35,13 +35,13 @@
 #include "gjs/jsapi-util.h"
 #include "gjs/profiler.h"
 #include "test/gjs-test-utils.h"
+#include "test/gjs-test-no-introspection-object.h"
 #include "util/misc.h"
 
 #define VALID_UTF8_STRING "\303\211\303\226 foobar \343\203\237"
 
 static void
-gjstest_test_func_gjs_context_construct_destroy(void)
-{
+gjstest_test_func_gjs_context_construct_destroy(void) {
     GjsContext *context;
 
     /* Construct twice just to possibly a case where global state from
@@ -55,8 +55,7 @@ gjstest_test_func_gjs_context_construct_destroy(void)
 }
 
 static void
-gjstest_test_func_gjs_context_construct_eval(void)
-{
+gjstest_test_func_gjs_context_construct_eval(void) {
     GjsContext *context;
     int estatus;
     GError *error = NULL;
@@ -81,8 +80,7 @@ static void gjstest_test_func_gjs_context_eval_non_zero_terminated(void) {
 }
 
 static void
-gjstest_test_func_gjs_context_exit(void)
-{
+gjstest_test_func_gjs_context_exit(void) {
     GjsContext *context = gjs_context_new();
     GError *error = NULL;
     int status;
@@ -111,8 +109,7 @@ const FooBar = GObject.registerClass(class FooBar extends GObject.Object {}); \
 "
 
 static void
-gjstest_test_func_gjs_gobject_js_defined_type(void)
-{
+gjstest_test_func_gjs_gobject_js_defined_type(void) {
     GjsContext *context = gjs_context_new();
     GError *error = NULL;
     int status;
@@ -130,6 +127,33 @@ 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;\
+"
+    if (!gjs_context_eval(context, TESTJS, -1, "<input>", &status, &error))
+        g_printerr("ERROR: %s", error->message);
+
+    GjsTestNoIntrospectionObject *obj = gjstest_no_introspection_object_peek();
+    g_assert(obj != NULL);
+
+    gint val = 0;
+    g_object_get(obj, "a-int", &val, NULL);
+    g_assert(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);
@@ -288,8 +312,7 @@ static void test_jsapi_util_debug_string_object_with_complicated_to_string(
 }
 
 static void
-gjstest_test_func_util_misc_strv_concat_null(void)
-{
+gjstest_test_func_util_misc_strv_concat_null(void) {
     char **ret;
 
     ret = gjs_g_strv_concat(NULL, 0);
@@ -300,8 +323,7 @@ gjstest_test_func_util_misc_strv_concat_null(void)
 }
 
 static void
-gjstest_test_func_util_misc_strv_concat_pointers(void)
-{
+gjstest_test_func_util_misc_strv_concat_pointers(void) {
     char  *strv0[2] = {(char*)"foo", NULL};
     char  *strv1[1] = {NULL};
     char **strv2    = NULL;
@@ -326,8 +348,7 @@ gjstest_test_func_util_misc_strv_concat_pointers(void)
 }
 
 static void
-gjstest_test_strip_shebang_no_advance_for_no_shebang(void)
-{
+gjstest_test_strip_shebang_no_advance_for_no_shebang(void) {
     unsigned line_number = 1;
     size_t offset = gjs_unix_shebang_len(u"foo\nbar", &line_number);
 
@@ -344,8 +365,7 @@ static void gjstest_test_strip_shebang_no_advance_for_too_short_string(void) {
 }
 
 static void
-gjstest_test_strip_shebang_advance_for_shebang(void)
-{
+gjstest_test_strip_shebang_advance_for_shebang(void) {
     unsigned line_number = 1;
     size_t offset = gjs_unix_shebang_len(u"#!foo\nbar", &line_number);
 
@@ -362,8 +382,7 @@ static void gjstest_test_strip_shebang_advance_to_end_for_just_shebang(void) {
 }
 
 static void
-gjstest_test_profiler_start_stop(void)
-{
+gjstest_test_profiler_start_stop(void) {
     GjsAutoUnref<GjsContext> context =
         static_cast<GjsContext *>(g_object_new(GJS_TYPE_CONTEXT,
                                                "profiler-enabled", TRUE,
@@ -389,24 +408,28 @@ gjstest_test_profiler_start_stop(void)
 
 int
 main(int    argc,
-     char **argv)
-{
+     char **argv) {
     /* Avoid interference in the tests from stray environment variable */
     g_unsetenv("GJS_ENABLE_PROFILER");
     g_unsetenv("GJS_TRACE_FD");
 
     g_test_init(&argc, &argv, NULL);
 
-    g_test_add_func("/gjs/context/construct/destroy", gjstest_test_func_gjs_context_construct_destroy);
+    g_test_add_func("/gjs/context/construct/destroy",
+                    gjstest_test_func_gjs_context_construct_destroy);
     g_test_add_func("/gjs/context/construct/eval", gjstest_test_func_gjs_context_construct_eval);
     g_test_add_func("/gjs/context/eval/non-zero-terminated",
                     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/jsutil/strip_shebang/no_shebang", 
gjstest_test_strip_shebang_no_advance_for_no_shebang);
+    g_test_add_func("/gjs/gobject/without_introspection",
+                    gjstest_test_func_gjs_gobject_without_introspection);
+    g_test_add_func("/gjs/jsutil/strip_shebang/no_shebang",
+                    gjstest_test_strip_shebang_no_advance_for_no_shebang);
     g_test_add_func("/gjs/jsutil/strip_shebang/short_string",
                     gjstest_test_strip_shebang_no_advance_for_too_short_string);
-    g_test_add_func("/gjs/jsutil/strip_shebang/have_shebang", 
gjstest_test_strip_shebang_advance_for_shebang);
+    g_test_add_func("/gjs/jsutil/strip_shebang/have_shebang",
+                    gjstest_test_strip_shebang_advance_for_shebang);
     g_test_add_func("/gjs/jsutil/strip_shebang/only_shebang",
                     gjstest_test_strip_shebang_advance_to_end_for_just_shebang);
     g_test_add_func("/gjs/profiler/start_stop", gjstest_test_profiler_start_stop);
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]