From 614437107a6db8cdcbac6c94fcb67ee50aabc1c9 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Mon, 5 Feb 2024 18:40:58 +0000 Subject: [PATCH] tests: Add a test for finding methods and vfuncs in a GIObjectInfo Helps: #3246 --- girepository/tests/meson.build | 3 ++ girepository/tests/object-info.c | 82 ++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 girepository/tests/object-info.c diff --git a/girepository/tests/meson.build b/girepository/tests/meson.build index 3af29bd36..9fb30e322 100644 --- a/girepository/tests/meson.build +++ b/girepository/tests/meson.build @@ -17,6 +17,9 @@ if enable_gir 'dependencies': [libffi_dep], 'depends': [glib_gir], }, + 'object-info' : { + 'depends': [gio_gir], + }, 'repository' : { 'depends': [glib_gir, gio_gir, gobject_gir], }, diff --git a/girepository/tests/object-info.c b/girepository/tests/object-info.c new file mode 100644 index 000000000..7245dae84 --- /dev/null +++ b/girepository/tests/object-info.c @@ -0,0 +1,82 @@ +/* + * Copyright 2024 Philip Chimento + * Copyright 2024 GNOME Foundation + * + * SPDX-License-Identifier: LGPL-2.1-or-later + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, see . + */ + +#include "config.h" + +#include "girepository.h" +#include "test-common.h" + +static void +test_object_info_find_method_using_interfaces (RepositoryFixture *fx, + const void *unused) +{ + GIObjectInfo *class_info = NULL; + GIFunctionInfo *method_info = NULL; + GIBaseInfo *declarer_info = NULL; + + class_info = GI_OBJECT_INFO (gi_repository_find_by_name (fx->repository, "Gio", "DBusProxy")); + g_assert_nonnull (class_info); + + method_info = gi_object_info_find_method_using_interfaces (class_info, "init", &declarer_info); + + g_assert_nonnull (declarer_info); + g_assert_cmpstr (gi_base_info_get_namespace (declarer_info), ==, "Gio"); + g_assert_cmpstr (gi_base_info_get_name (declarer_info), ==, "Initable"); + g_assert_true (GI_IS_INTERFACE_INFO (declarer_info)); + + g_clear_pointer (&class_info, gi_base_info_unref); + g_clear_pointer (&method_info, gi_base_info_unref); + g_clear_pointer (&declarer_info, gi_base_info_unref); +} + +static void +test_object_info_find_vfunc_using_interfaces (RepositoryFixture *fx, + const void *unused) +{ + GIObjectInfo *class_info = NULL; + GIVFuncInfo *vfunc_info = NULL; + GIBaseInfo *declarer_info = NULL; + + class_info = GI_OBJECT_INFO (gi_repository_find_by_name (fx->repository, "Gio", "Application")); + g_assert_nonnull (class_info); + + vfunc_info = gi_object_info_find_vfunc_using_interfaces (class_info, "after_emit", &declarer_info); + + g_assert_nonnull (declarer_info); + g_assert_cmpstr (gi_base_info_get_namespace (declarer_info), ==, "Gio"); + g_assert_cmpstr (gi_base_info_get_name (declarer_info), ==, "Application"); + g_assert_true (GI_IS_OBJECT_INFO (declarer_info)); + + g_clear_pointer (&class_info, gi_base_info_unref); + g_clear_pointer (&vfunc_info, gi_base_info_unref); + g_clear_pointer (&declarer_info, gi_base_info_unref); +} + +int +main (int argc, + char *argv[]) +{ + repository_init (&argc, &argv); + + ADD_REPOSITORY_TEST ("/object-info/find-method-using-interfaces", test_object_info_find_method_using_interfaces, &typelib_load_spec_gio); + ADD_REPOSITORY_TEST ("/object-info/find-vfunc-using-interfaces", test_object_info_find_vfunc_using_interfaces, &typelib_load_spec_gio); + + return g_test_run (); +}