mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-27 07:56:14 +01:00
girepository: Add a couple of very simple unit tests
For the moment, this is enough to roughly verify that the port to `GTypeInstance` has not massively broken things. It’s not anywhere near sufficient to qualify as a proper test suite though. Signed-off-by: Philip Withnall <pwithnall@gnome.org> Helps: #3155
This commit is contained in:
parent
78c94d81ed
commit
e699037fef
@ -252,3 +252,7 @@ if enable_gir
|
|||||||
extra_args: gir_args + libgirepository_gir_args,
|
extra_args: gir_args + libgirepository_gir_args,
|
||||||
)
|
)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if build_tests
|
||||||
|
subdir('tests')
|
||||||
|
endif
|
85
girepository/tests/meson.build
Normal file
85
girepository/tests/meson.build
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
girepository_tests = {}
|
||||||
|
|
||||||
|
# Some GIR files are needed to test against
|
||||||
|
if enable_gir
|
||||||
|
girepository_tests += {
|
||||||
|
'repository' : {
|
||||||
|
'depends': [glib_gir, gobject_gir],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
endif
|
||||||
|
|
||||||
|
test_env = environment()
|
||||||
|
test_env.set('G_TEST_SRCDIR', meson.current_source_dir())
|
||||||
|
test_env.set('G_TEST_BUILDDIR', meson.current_build_dir())
|
||||||
|
|
||||||
|
test_deps = [libm, thread_dep, libgirepository_dep]
|
||||||
|
test_cargs = ['-DG_LOG_DOMAIN="GIRepository"', '-UG_DISABLE_ASSERT']
|
||||||
|
test_cpp_args = test_cargs
|
||||||
|
|
||||||
|
foreach test_name, extra_args : girepository_tests
|
||||||
|
source = extra_args.get('source', test_name + '.c')
|
||||||
|
install = installed_tests_enabled and extra_args.get('install', true)
|
||||||
|
installed_tests_env = extra_args.get('installed_tests_env', {})
|
||||||
|
|
||||||
|
if install
|
||||||
|
test_conf = configuration_data()
|
||||||
|
test_conf.set('installed_tests_dir', installed_tests_execdir)
|
||||||
|
test_conf.set('program', test_name)
|
||||||
|
test_env_override = ''
|
||||||
|
if installed_tests_env != {}
|
||||||
|
envs = []
|
||||||
|
foreach var, value : installed_tests_env
|
||||||
|
envs += '@0@=@1@'.format(var, value)
|
||||||
|
endforeach
|
||||||
|
test_env_override = '@0@ @1@ '.format(env_program.full_path(), ' '.join(envs))
|
||||||
|
endif
|
||||||
|
test_conf.set('env', test_env_override)
|
||||||
|
configure_file(
|
||||||
|
input: installed_tests_template_tap,
|
||||||
|
output: test_name + '.test',
|
||||||
|
install_dir: installed_tests_metadir,
|
||||||
|
install_tag: 'tests',
|
||||||
|
configuration: test_conf
|
||||||
|
)
|
||||||
|
endif
|
||||||
|
|
||||||
|
exe = executable(test_name, source,
|
||||||
|
c_args: test_cargs + extra_args.get('c_args', []),
|
||||||
|
cpp_args: test_cpp_args + extra_args.get('cpp_args', []),
|
||||||
|
link_args: extra_args.get('link_args', []),
|
||||||
|
override_options: extra_args.get('override_options', []),
|
||||||
|
dependencies: test_deps + extra_args.get('dependencies', []),
|
||||||
|
link_with: extra_args.get('link_with', []),
|
||||||
|
install_dir: installed_tests_execdir,
|
||||||
|
install_tag: 'tests',
|
||||||
|
install: install,
|
||||||
|
)
|
||||||
|
|
||||||
|
depends = [extra_args.get('depends', [])]
|
||||||
|
suite = ['girepository', 'core'] + extra_args.get('suite', [])
|
||||||
|
timeout = suite.contains('slow') ? test_timeout_slow : test_timeout
|
||||||
|
|
||||||
|
if extra_args.get('can_fail', false)
|
||||||
|
suite += 'failing'
|
||||||
|
endif
|
||||||
|
|
||||||
|
foreach program : extra_args.get('extra_programs', [])
|
||||||
|
depends += test_extra_programs_targets[program]
|
||||||
|
endforeach
|
||||||
|
|
||||||
|
local_test_env = test_env
|
||||||
|
foreach var, value : extra_args.get('env', {})
|
||||||
|
local_test_env.append(var, value)
|
||||||
|
endforeach
|
||||||
|
|
||||||
|
test(test_name, exe,
|
||||||
|
args: extra_args.get('args', []),
|
||||||
|
protocol: extra_args.get('protocol', test_protocol),
|
||||||
|
depends: depends,
|
||||||
|
env: local_test_env,
|
||||||
|
timeout: timeout,
|
||||||
|
suite: suite,
|
||||||
|
should_fail: extra_args.get('should_fail', false),
|
||||||
|
)
|
||||||
|
endforeach
|
117
girepository/tests/repository.c
Normal file
117
girepository/tests/repository.c
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2023 GNOME Foundation, Inc.
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Author: Philip Withnall <pwithnall@gnome.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "glib.h"
|
||||||
|
#include "girepository.h"
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_repository_basic (void)
|
||||||
|
{
|
||||||
|
GIRepository *repository;
|
||||||
|
char *gobject_typelib_dir = NULL;
|
||||||
|
GSList *search_path;
|
||||||
|
GITypelib *typelib = NULL;
|
||||||
|
char **namespaces = NULL;
|
||||||
|
const char *expected_namespaces[] = { "GLib", NULL };
|
||||||
|
GError *local_error = NULL;
|
||||||
|
|
||||||
|
g_test_summary ("Test basic opening of a repository and requiring a typelib");
|
||||||
|
|
||||||
|
gobject_typelib_dir = g_test_build_filename (G_TEST_BUILT, "..", "..", "gobject", NULL);
|
||||||
|
g_test_message ("Using GI_TYPELIB_DIR = %s", gobject_typelib_dir);
|
||||||
|
gi_repository_prepend_search_path (gobject_typelib_dir);
|
||||||
|
|
||||||
|
repository = gi_repository_new ();
|
||||||
|
g_assert_nonnull (repository);
|
||||||
|
|
||||||
|
search_path = gi_repository_get_search_path ();
|
||||||
|
g_assert_nonnull (search_path);
|
||||||
|
g_assert_cmpstr (search_path->data, ==, gobject_typelib_dir);
|
||||||
|
|
||||||
|
typelib = gi_repository_require (repository, "GLib", "2.0", 0, &local_error);
|
||||||
|
g_assert_no_error (local_error);
|
||||||
|
g_assert_nonnull (typelib);
|
||||||
|
|
||||||
|
namespaces = gi_repository_get_loaded_namespaces (repository);
|
||||||
|
g_assert_cmpstrv (namespaces, expected_namespaces);
|
||||||
|
g_strfreev (namespaces);
|
||||||
|
|
||||||
|
g_free (gobject_typelib_dir);
|
||||||
|
g_clear_object (&repository);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_repository_info (void)
|
||||||
|
{
|
||||||
|
GIRepository *repository;
|
||||||
|
char *gobject_typelib_dir = NULL;
|
||||||
|
GITypelib *typelib = NULL;
|
||||||
|
GIObjectInfo *object_info = NULL;
|
||||||
|
GISignalInfo *signal_info = NULL;
|
||||||
|
GError *local_error = NULL;
|
||||||
|
|
||||||
|
g_test_summary ("Test retrieving some basic info blobs from a typelib");
|
||||||
|
|
||||||
|
gobject_typelib_dir = g_test_build_filename (G_TEST_BUILT, "..", "..", "gobject", NULL);
|
||||||
|
g_test_message ("Using GI_TYPELIB_DIR = %s", gobject_typelib_dir);
|
||||||
|
gi_repository_prepend_search_path (gobject_typelib_dir);
|
||||||
|
g_free (gobject_typelib_dir);
|
||||||
|
|
||||||
|
repository = gi_repository_new ();
|
||||||
|
g_assert_nonnull (repository);
|
||||||
|
|
||||||
|
typelib = gi_repository_require (repository, "GObject", "2.0", 0, &local_error);
|
||||||
|
g_assert_no_error (local_error);
|
||||||
|
g_assert_nonnull (typelib);
|
||||||
|
|
||||||
|
object_info = (GIObjectInfo *) gi_repository_find_by_name (repository, "GObject", "Object");
|
||||||
|
g_assert_nonnull (object_info);
|
||||||
|
|
||||||
|
g_assert_cmpint (gi_base_info_get_info_type ((GIBaseInfo *) object_info), ==, GI_INFO_TYPE_OBJECT);
|
||||||
|
g_assert_cmpstr (gi_base_info_get_name ((GIBaseInfo *) object_info), ==, "Object");
|
||||||
|
g_assert_cmpstr (gi_base_info_get_namespace ((GIBaseInfo *) object_info), ==, "GObject");
|
||||||
|
|
||||||
|
signal_info = gi_object_info_find_signal (object_info, "notify");
|
||||||
|
g_assert_nonnull (signal_info);
|
||||||
|
|
||||||
|
g_assert_cmpint (gi_signal_info_get_flags (signal_info), ==,
|
||||||
|
G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS | G_SIGNAL_ACTION);
|
||||||
|
|
||||||
|
gi_base_info_unref ((GIBaseInfo *) signal_info);
|
||||||
|
gi_base_info_unref ((GIBaseInfo *) object_info);
|
||||||
|
g_clear_object (&repository);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc,
|
||||||
|
char *argv[])
|
||||||
|
{
|
||||||
|
/* Isolate from the system typelibs and GIRs. */
|
||||||
|
g_setenv ("GI_TYPELIB_PATH", "/dev/null", TRUE);
|
||||||
|
g_setenv ("GI_GIR_PATH", "/dev/null", TRUE);
|
||||||
|
|
||||||
|
g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL);
|
||||||
|
|
||||||
|
g_test_add_func ("/repository/basic", test_repository_basic);
|
||||||
|
g_test_add_func ("/repository/info", test_repository_info);
|
||||||
|
|
||||||
|
return g_test_run ();
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user