mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-26 22:16:16 +01:00
Merge branch 'gthread-tests' into 'main'
tests: Add some trivial tests for g_thread_init() See merge request GNOME/glib!3065
This commit is contained in:
commit
57ee7f914c
@ -36,3 +36,7 @@ pkg.generate(libgthread,
|
|||||||
|
|
||||||
libgthread_dep = declare_dependency(link_with : libgthread)
|
libgthread_dep = declare_dependency(link_with : libgthread)
|
||||||
meson.override_dependency('gthread-2.0', libgthread_dep)
|
meson.override_dependency('gthread-2.0', libgthread_dep)
|
||||||
|
|
||||||
|
if build_tests
|
||||||
|
subdir('tests')
|
||||||
|
endif
|
||||||
|
68
gthread/tests/init.c
Normal file
68
gthread/tests/init.c
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/* GLib testing framework examples and tests
|
||||||
|
*
|
||||||
|
* Copyright © 2022 Endless OS Foundation, LLC
|
||||||
|
*
|
||||||
|
* 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@endlessos.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
#include <locale.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* All of GThread is deprecated, but that’s OK */
|
||||||
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_thread_deprecated_init (void)
|
||||||
|
{
|
||||||
|
const GThreadFunctions functions = { NULL, };
|
||||||
|
|
||||||
|
/* Should be a no-op. */
|
||||||
|
g_thread_init (NULL);
|
||||||
|
|
||||||
|
/* Should emit a warning. */
|
||||||
|
g_test_expect_message ("GThread", G_LOG_LEVEL_WARNING,
|
||||||
|
"GThread system no longer supports custom thread implementations.");
|
||||||
|
g_thread_init ((gpointer) &functions);
|
||||||
|
g_test_assert_expected_messages ();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_thread_deprecated_init_with_errorcheck_mutexes (void)
|
||||||
|
{
|
||||||
|
/* Should warn. */
|
||||||
|
g_test_expect_message ("GThread", G_LOG_LEVEL_WARNING,
|
||||||
|
"GThread system no longer supports errorcheck mutexes.");
|
||||||
|
g_thread_init_with_errorcheck_mutexes (NULL);
|
||||||
|
g_test_assert_expected_messages ();
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc,
|
||||||
|
char *argv[])
|
||||||
|
{
|
||||||
|
setlocale (LC_ALL, "");
|
||||||
|
g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL);
|
||||||
|
|
||||||
|
g_test_add_func ("/thread/deprecated/init", test_thread_deprecated_init);
|
||||||
|
g_test_add_func ("/thread/deprecated/init-with-errorcheck-mutexes", test_thread_deprecated_init_with_errorcheck_mutexes);
|
||||||
|
|
||||||
|
return g_test_run ();
|
||||||
|
}
|
||||||
|
|
||||||
|
G_GNUC_END_IGNORE_DEPRECATIONS
|
48
gthread/tests/meson.build
Normal file
48
gthread/tests/meson.build
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
gthread_tests = {
|
||||||
|
'init' : {},
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = [thread_dep, libglib_dep, libgthread_dep]
|
||||||
|
test_cargs = ['-DG_LOG_DOMAIN="GLib-GThread"', '-UG_DISABLE_ASSERT']
|
||||||
|
test_cpp_args = test_cargs
|
||||||
|
|
||||||
|
foreach test_name, extra_args : gthread_tests
|
||||||
|
source = extra_args.get('source', test_name + '.c')
|
||||||
|
install = installed_tests_enabled and extra_args.get('install', true)
|
||||||
|
|
||||||
|
if install
|
||||||
|
test_conf = configuration_data()
|
||||||
|
test_conf.set('installed_tests_dir', installed_tests_execdir)
|
||||||
|
test_conf.set('program', test_name)
|
||||||
|
test_conf.set('env', '')
|
||||||
|
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', []),
|
||||||
|
dependencies : test_deps + extra_args.get('dependencies', []),
|
||||||
|
install_dir: installed_tests_execdir,
|
||||||
|
install_tag: 'tests',
|
||||||
|
install: install,
|
||||||
|
)
|
||||||
|
|
||||||
|
suite = ['gthread'] + extra_args.get('suite', [])
|
||||||
|
timeout = suite.contains('slow') ? test_timeout_slow : test_timeout
|
||||||
|
|
||||||
|
if extra_args.get('can_fail', false)
|
||||||
|
suite += 'failing'
|
||||||
|
endif
|
||||||
|
|
||||||
|
test(test_name, exe, env : test_env, timeout : timeout, suite : suite)
|
||||||
|
endforeach
|
Loading…
Reference in New Issue
Block a user