mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-05 10:38:08 +01:00
Merge branch 'module_tests' into 'main'
Move tests/module-test.c to gmodules/tests/ See merge request GNOME/glib!2660
This commit is contained in:
commit
8625d8144b
@ -22,11 +22,7 @@
|
|||||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#undef G_DISABLE_ASSERT
|
|
||||||
#undef G_LOG_DOMAIN
|
|
||||||
|
|
||||||
#include <gmodule.h>
|
#include <gmodule.h>
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
G_MODULE_EXPORT void gplugin_a_func (void);
|
G_MODULE_EXPORT void gplugin_a_func (void);
|
||||||
G_MODULE_EXPORT void gplugin_clash_func (void);
|
G_MODULE_EXPORT void gplugin_clash_func (void);
|
@ -22,9 +22,6 @@
|
|||||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#undef G_DISABLE_ASSERT
|
|
||||||
#undef G_LOG_DOMAIN
|
|
||||||
|
|
||||||
#include <gmodule.h>
|
#include <gmodule.h>
|
||||||
|
|
||||||
G_MODULE_EXPORT gchar* gplugin_b_state;
|
G_MODULE_EXPORT gchar* gplugin_b_state;
|
@ -2,8 +2,40 @@ gmodule_tests = {
|
|||||||
'cxx' : {
|
'cxx' : {
|
||||||
'source' : ['cxx.cpp'],
|
'source' : ['cxx.cpp'],
|
||||||
},
|
},
|
||||||
|
'module-test-library' : {
|
||||||
|
'export_dynamic' : true,
|
||||||
|
'source': 'module-test.c',
|
||||||
|
'c_args': ['-DMODULE_TYPE="library"'],
|
||||||
|
},
|
||||||
|
'module-test-plugin' : {
|
||||||
|
'export_dynamic' : true,
|
||||||
|
'source': 'module-test.c',
|
||||||
|
'c_args': ['-DMODULE_TYPE="plugin"'],
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module_suffix = []
|
||||||
|
# Keep the autotools convention for shared module suffix because GModule
|
||||||
|
# depends on it: https://gitlab.gnome.org/GNOME/glib/issues/520
|
||||||
|
if ['darwin', 'ios'].contains(host_machine.system())
|
||||||
|
module_suffix = 'so'
|
||||||
|
endif
|
||||||
|
|
||||||
|
foreach module : ['moduletestplugin_a', 'moduletestplugin_b']
|
||||||
|
shared_module(module + '_plugin', 'lib@0@.c'.format(module),
|
||||||
|
dependencies : [libglib_dep, libgmodule_dep],
|
||||||
|
install_dir : installed_tests_execdir,
|
||||||
|
install : installed_tests_enabled,
|
||||||
|
name_suffix : module_suffix
|
||||||
|
)
|
||||||
|
shared_library(module + '_library', 'lib@0@.c'.format(module),
|
||||||
|
dependencies : [libglib_dep, libgmodule_dep],
|
||||||
|
install_dir : installed_tests_execdir,
|
||||||
|
install : installed_tests_enabled,
|
||||||
|
name_suffix : module_suffix
|
||||||
|
)
|
||||||
|
endforeach
|
||||||
|
|
||||||
test_env = environment()
|
test_env = environment()
|
||||||
test_env.set('G_TEST_SRCDIR', meson.current_source_dir())
|
test_env.set('G_TEST_SRCDIR', meson.current_source_dir())
|
||||||
test_env.set('G_TEST_BUILDDIR', meson.current_build_dir())
|
test_env.set('G_TEST_BUILDDIR', meson.current_build_dir())
|
||||||
@ -35,6 +67,7 @@ foreach test_name, extra_args : gmodule_tests
|
|||||||
c_args : test_cargs + extra_args.get('c_args', []),
|
c_args : test_cargs + extra_args.get('c_args', []),
|
||||||
link_args : extra_args.get('link_args', []),
|
link_args : extra_args.get('link_args', []),
|
||||||
dependencies : test_deps + extra_args.get('dependencies', []),
|
dependencies : test_deps + extra_args.get('dependencies', []),
|
||||||
|
export_dynamic : extra_args.get('export_dynamic', false),
|
||||||
install_dir: installed_tests_execdir,
|
install_dir: installed_tests_execdir,
|
||||||
install: install,
|
install: install,
|
||||||
)
|
)
|
||||||
|
@ -22,11 +22,7 @@
|
|||||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#undef G_DISABLE_ASSERT
|
|
||||||
#undef G_LOG_DOMAIN
|
|
||||||
|
|
||||||
#include <gmodule.h>
|
#include <gmodule.h>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
# define MODULE_FILENAME_PREFIX ""
|
# define MODULE_FILENAME_PREFIX ""
|
||||||
@ -34,7 +30,7 @@
|
|||||||
# define MODULE_FILENAME_PREFIX "lib"
|
# define MODULE_FILENAME_PREFIX "lib"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
gchar* global_state;
|
gchar *global_state = NULL;
|
||||||
|
|
||||||
G_MODULE_EXPORT void g_clash_func (void);
|
G_MODULE_EXPORT void g_clash_func (void);
|
||||||
|
|
||||||
@ -64,8 +60,7 @@ compare (const gchar *desc, const gchar *expected, const gchar *found)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_states (const gchar *global, const gchar *gplugin_a,
|
test_states (const gchar *global, const gchar *gplugin_a, const gchar *gplugin_b)
|
||||||
const gchar *gplugin_b)
|
|
||||||
{
|
{
|
||||||
compare ("global", global, global_state);
|
compare ("global", global, global_state);
|
||||||
compare ("Plugin A", gplugin_a, *gplugin_a_state);
|
compare ("Plugin A", gplugin_a, *gplugin_a_state);
|
||||||
@ -76,9 +71,8 @@ test_states (const gchar *global, const gchar *gplugin_a,
|
|||||||
|
|
||||||
static SimpleFunc plugin_clash_func = NULL;
|
static SimpleFunc plugin_clash_func = NULL;
|
||||||
|
|
||||||
int
|
static void
|
||||||
main (int argc,
|
test_module_basics (void)
|
||||||
char **argv)
|
|
||||||
{
|
{
|
||||||
GModule *module_self, *module_a, *module_b;
|
GModule *module_self, *module_a, *module_b;
|
||||||
gchar *plugin_a, *plugin_b;
|
gchar *plugin_a, *plugin_b;
|
||||||
@ -86,8 +80,6 @@ main (int argc,
|
|||||||
GModuleFunc gmod_f;
|
GModuleFunc gmod_f;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
g_test_init (&argc, &argv, NULL);
|
|
||||||
|
|
||||||
if (!g_module_supported ())
|
if (!g_module_supported ())
|
||||||
g_error ("dynamic modules not supported");
|
g_error ("dynamic modules not supported");
|
||||||
|
|
||||||
@ -121,16 +113,16 @@ main (int argc,
|
|||||||
/* get plugin state vars */
|
/* get plugin state vars */
|
||||||
|
|
||||||
if (!g_module_symbol (module_a, "gplugin_a_state",
|
if (!g_module_symbol (module_a, "gplugin_a_state",
|
||||||
(gpointer *) &gplugin_a_state))
|
(gpointer *) &gplugin_a_state))
|
||||||
g_error ("error: %s", g_module_error ());
|
g_error ("error: %s", g_module_error ());
|
||||||
|
|
||||||
if (!g_module_symbol (module_b, "gplugin_b_state",
|
if (!g_module_symbol (module_b, "gplugin_b_state",
|
||||||
(gpointer *) &gplugin_b_state))
|
(gpointer *) &gplugin_b_state))
|
||||||
g_error ("error: %s", g_module_error ());
|
g_error ("error: %s", g_module_error ());
|
||||||
test_states (NULL, NULL, "check-init");
|
test_states (NULL, NULL, "check-init");
|
||||||
|
|
||||||
/* get plugin specific symbols and call them
|
/* get plugin specific symbols and call them */
|
||||||
*/
|
|
||||||
if (!g_module_symbol (module_a, "gplugin_a_func", (gpointer *) &f_a))
|
if (!g_module_symbol (module_a, "gplugin_a_func", (gpointer *) &f_a))
|
||||||
g_error ("error: %s", g_module_error ());
|
g_error ("error: %s", g_module_error ());
|
||||||
test_states (NULL, NULL, NULL);
|
test_states (NULL, NULL, NULL);
|
||||||
@ -145,8 +137,7 @@ main (int argc,
|
|||||||
f_b ();
|
f_b ();
|
||||||
test_states (NULL, NULL, "Hello world");
|
test_states (NULL, NULL, "Hello world");
|
||||||
|
|
||||||
/* get and call globally clashing functions
|
/* get and call globally clashing functions */
|
||||||
*/
|
|
||||||
|
|
||||||
if (!g_module_symbol (module_self, "g_clash_func", (gpointer *) &f_self))
|
if (!g_module_symbol (module_self, "g_clash_func", (gpointer *) &f_self))
|
||||||
g_error ("error: %s", g_module_error ());
|
g_error ("error: %s", g_module_error ());
|
||||||
@ -210,5 +201,14 @@ main (int argc,
|
|||||||
g_free (plugin_a);
|
g_free (plugin_a);
|
||||||
g_free (plugin_b);
|
g_free (plugin_b);
|
||||||
g_module_close (module_self);
|
g_module_close (module_self);
|
||||||
return 0;
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
|
{
|
||||||
|
g_test_init (&argc, &argv, NULL);
|
||||||
|
|
||||||
|
g_test_add_func ("/module/basics", test_module_basics);
|
||||||
|
|
||||||
|
return g_test_run ();
|
||||||
}
|
}
|
@ -15,21 +15,6 @@ test_cargs = ['-DG_LOG_DOMAIN="GLib"', '-UG_DISABLE_ASSERT']
|
|||||||
subdir('gobject')
|
subdir('gobject')
|
||||||
subdir('refcount')
|
subdir('refcount')
|
||||||
|
|
||||||
tests = {
|
|
||||||
'module-test-library' : {
|
|
||||||
'dependencies' : [libgmodule_dep],
|
|
||||||
'export_dynamic' : true,
|
|
||||||
'source': 'module-test.c',
|
|
||||||
'c_args': ['-DMODULE_TYPE="library"'],
|
|
||||||
},
|
|
||||||
'module-test-plugin' : {
|
|
||||||
'dependencies' : [libgmodule_dep],
|
|
||||||
'export_dynamic' : true,
|
|
||||||
'source': 'module-test.c',
|
|
||||||
'c_args': ['-DMODULE_TYPE="plugin"'],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
test_extra_programs = {
|
test_extra_programs = {
|
||||||
'slice-test' : {
|
'slice-test' : {
|
||||||
'extra_sources' : ['memchunks.c'],
|
'extra_sources' : ['memchunks.c'],
|
||||||
@ -37,66 +22,9 @@ test_extra_programs = {
|
|||||||
'assert-msg-test' : {},
|
'assert-msg-test' : {},
|
||||||
}
|
}
|
||||||
|
|
||||||
module_suffix = []
|
|
||||||
# Keep the autotools convention for shared module suffix because GModule
|
|
||||||
# depends on it: https://gitlab.gnome.org/GNOME/glib/issues/520
|
|
||||||
if ['darwin', 'ios'].contains(host_machine.system())
|
|
||||||
module_suffix = 'so'
|
|
||||||
endif
|
|
||||||
|
|
||||||
foreach module : ['moduletestplugin_a', 'moduletestplugin_b']
|
|
||||||
shared_module(module + '_plugin', 'lib@0@.c'.format(module),
|
|
||||||
dependencies : [libglib_dep, libgmodule_dep],
|
|
||||||
install_dir : installed_tests_execdir,
|
|
||||||
install : installed_tests_enabled,
|
|
||||||
name_suffix : module_suffix
|
|
||||||
)
|
|
||||||
shared_library(module + '_library', 'lib@0@.c'.format(module),
|
|
||||||
dependencies : [libglib_dep, libgmodule_dep],
|
|
||||||
install_dir : installed_tests_execdir,
|
|
||||||
install : installed_tests_enabled,
|
|
||||||
name_suffix : module_suffix
|
|
||||||
)
|
|
||||||
endforeach
|
|
||||||
|
|
||||||
common_c_args = test_cargs + ['-DGLIB_DISABLE_DEPRECATION_WARNINGS']
|
common_c_args = test_cargs + ['-DGLIB_DISABLE_DEPRECATION_WARNINGS']
|
||||||
common_deps = [libm, thread_dep, libglib_dep]
|
common_deps = [libm, thread_dep, libglib_dep]
|
||||||
|
|
||||||
foreach test_name, extra_args : tests
|
|
||||||
source = extra_args.get('source', test_name + '.c')
|
|
||||||
extra_sources = extra_args.get('extra_sources', [])
|
|
||||||
install = installed_tests_enabled and extra_args.get('install', true)
|
|
||||||
template = extra_args.get('tap', false) ? installed_tests_template_tap : installed_tests_template
|
|
||||||
|
|
||||||
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: template,
|
|
||||||
output: test_name + '.test',
|
|
||||||
install_dir: installed_tests_metadir,
|
|
||||||
configuration: test_conf
|
|
||||||
)
|
|
||||||
endif
|
|
||||||
|
|
||||||
# FIXME? $(GLIB_DEBUG_FLAGS)
|
|
||||||
exe = executable(test_name, [source, extra_sources],
|
|
||||||
c_args : common_c_args + extra_args.get('c_args', []),
|
|
||||||
dependencies : common_deps + extra_args.get('dependencies', []),
|
|
||||||
export_dynamic : extra_args.get('export_dynamic', false),
|
|
||||||
include_directories : extra_args.get('include_directories', []),
|
|
||||||
install_dir: installed_tests_execdir,
|
|
||||||
install: install,
|
|
||||||
)
|
|
||||||
|
|
||||||
suite = ['glib'] + extra_args.get('suite', [])
|
|
||||||
timeout = suite.contains('slow') ? test_timeout_slow : test_timeout
|
|
||||||
# FIXME? TESTS_ENVIRONMENT = LIBCHARSET_ALIAS_DIR=$(top_builddir)/glib/libcharset
|
|
||||||
test(test_name, exe, env : test_env, timeout : timeout, suite : suite)
|
|
||||||
endforeach
|
|
||||||
|
|
||||||
foreach program_name, extra_args : test_extra_programs
|
foreach program_name, extra_args : test_extra_programs
|
||||||
source = extra_args.get('source', program_name + '.c')
|
source = extra_args.get('source', program_name + '.c')
|
||||||
extra_sources = extra_args.get('extra_sources', [])
|
extra_sources = extra_args.get('extra_sources', [])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user