config-parser: Don't use dbus_setenv() to test service directories

We can rely on the Autotools build system to pass in some safe values
for XDG_DATA_HOME and XDG_DATA_DIRS that match DBUS_TEST_BUILDDIR.

This test will now be skipped when running test-bus manually,
or under the CMake build system. Under CMake it could be reinstated
by setting the right environment variables.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99825
Reviewed-by: Philip Withnall <withnall@endlessm.com>
[smcv: add missing newline as requested]
[smcv: align DBUS_TEST_BUILDDIR with G_TEST_BUILDDIR]
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
This commit is contained in:
Simon McVittie 2017-02-17 17:15:34 +00:00
parent 5476b8fad0
commit 024bcd407b
2 changed files with 61 additions and 21 deletions

View file

@ -3380,16 +3380,15 @@ process_test_equiv_subdir (const DBusString *test_base_dir,
static const char *test_session_service_dir_matches[] = static const char *test_session_service_dir_matches[] =
{ {
#ifdef DBUS_UNIX
"/testhome/foo/.testlocal/testshare/dbus-1/services",
"/testusr/testlocal/testshare/dbus-1/services",
"/testusr/testshare/dbus-1/services",
DBUS_DATADIR"/dbus-1/services",
#endif
/* will be filled in test_default_session_servicedirs() */ /* will be filled in test_default_session_servicedirs() */
#ifdef DBUS_WIN #ifdef DBUS_WIN
NULL, NULL, /* install root-based */
NULL, NULL, /* CommonProgramFiles-based */
#else
NULL, /* XDG_DATA_HOME-based */
NULL, /* XDG_DATA_DIRS-based */
NULL, /* XDG_DATA_DIRS-based */
DBUS_DATADIR "/dbus-1/services",
#endif #endif
NULL NULL
}; };
@ -3401,16 +3400,26 @@ test_default_session_servicedirs (void)
DBusList *link; DBusList *link;
DBusString progs; DBusString progs;
DBusString install_root_based; DBusString install_root_based;
DBusString data_home_based;
DBusString data_dirs_based;
DBusString data_dirs_based2;
int i; int i;
dbus_bool_t ret = FALSE; dbus_bool_t ret = FALSE;
#ifdef DBUS_WIN #ifdef DBUS_WIN
const char *common_progs; const char *common_progs;
#else
const char *dbus_test_builddir;
const char *xdg_data_home;
#endif #endif
/* On Unix we don't actually use these, but it's easier to handle the /* On each platform we don't actually use all of these, but it's easier to
* deallocation if we always allocate them, whether needed or not */ * handle the deallocation if we always allocate them, whether needed or
* not */
if (!_dbus_string_init (&progs) || if (!_dbus_string_init (&progs) ||
!_dbus_string_init (&install_root_based)) !_dbus_string_init (&install_root_based) ||
!_dbus_string_init (&data_home_based) ||
!_dbus_string_init (&data_dirs_based) ||
!_dbus_string_init (&data_dirs_based2))
_dbus_assert_not_reached ("OOM allocating strings"); _dbus_assert_not_reached ("OOM allocating strings");
#ifdef DBUS_WIN #ifdef DBUS_WIN
@ -3436,18 +3445,42 @@ test_default_session_servicedirs (void)
test_session_service_dir_matches[1] = _dbus_string_get_const_data(&progs); test_session_service_dir_matches[1] = _dbus_string_get_const_data(&progs);
} }
#else
dbus_test_builddir = _dbus_getenv ("DBUS_TEST_BUILDDIR");
xdg_data_home = _dbus_getenv ("XDG_DATA_HOME");
if (dbus_test_builddir == NULL || xdg_data_home == NULL)
{
printf ("Not testing default session service directories because a "
"build-time testing environment variable is not set: "
"see AM_TESTS_ENVIRONMENT in tests/Makefile.am\n");
ret = TRUE;
goto out;
}
if (!_dbus_string_append (&data_dirs_based, dbus_test_builddir) ||
!_dbus_string_append (&data_dirs_based, "/XDG_DATA_DIRS/dbus-1/services") ||
!_dbus_string_append (&data_dirs_based2, dbus_test_builddir) ||
!_dbus_string_append (&data_dirs_based2, "/XDG_DATA_DIRS2/dbus-1/services") ||
!_dbus_string_append (&data_home_based, xdg_data_home) ||
!_dbus_string_append (&data_home_based, "/dbus-1/services"))
_dbus_assert_not_reached ("out of memory");
/* Sanity check: the Makefile sets this up. We assume that if this is
* right, the XDG_DATA_DIRS will be too. */
if (!_dbus_string_starts_with_c_str (&data_home_based, dbus_test_builddir))
_dbus_assert_not_reached ("$XDG_DATA_HOME should start with $DBUS_TEST_BUILDDIR");
test_session_service_dir_matches[0] = _dbus_string_get_const_data (
&data_home_based);
test_session_service_dir_matches[1] = _dbus_string_get_const_data (
&data_dirs_based);
test_session_service_dir_matches[2] = _dbus_string_get_const_data (
&data_dirs_based2);
#endif #endif
dirs = NULL; dirs = NULL;
printf ("Testing retrieving the default session service directories\n");
#ifdef DBUS_UNIX
if (!dbus_setenv ("XDG_DATA_HOME", "/testhome/foo/.testlocal/testshare"))
_dbus_assert_not_reached ("couldn't setenv XDG_DATA_HOME");
if (!dbus_setenv ("XDG_DATA_DIRS", ":/testusr/testlocal/testshare: :/testusr/testshare:"))
_dbus_assert_not_reached ("couldn't setenv XDG_DATA_DIRS");
#endif
if (!_dbus_get_standard_session_servicedirs (&dirs)) if (!_dbus_get_standard_session_servicedirs (&dirs))
_dbus_assert_not_reached ("couldn't get stardard dirs"); _dbus_assert_not_reached ("couldn't get stardard dirs");
@ -3494,6 +3527,9 @@ test_default_session_servicedirs (void)
out: out:
_dbus_string_free (&install_root_based); _dbus_string_free (&install_root_based);
_dbus_string_free (&progs); _dbus_string_free (&progs);
_dbus_string_free (&data_home_based);
_dbus_string_free (&data_dirs_based);
_dbus_string_free (&data_dirs_based2);
return ret; return ret;
} }

View file

@ -238,11 +238,15 @@ installcheck_environment = \
export DBUS_TEST_DATADIR=$(DESTDIR)$(datadir); \ export DBUS_TEST_DATADIR=$(DESTDIR)$(datadir); \
${NULL} ${NULL}
# Tests in bus/config-parser.c rely on these specific values for XDG_* and
# DBUS_TEST_BUILDDIR.
AM_TESTS_ENVIRONMENT = \ AM_TESTS_ENVIRONMENT = \
export XDG_DATA_HOME=@abs_top_builddir@/test/XDG_DATA_HOME; \ export XDG_DATA_HOME=@abs_top_builddir@/test/XDG_DATA_HOME; \
export XDG_DATA_DIRS=@abs_top_builddir@/test/XDG_DATA_DIRS; \ export XDG_DATA_DIRS=@abs_top_builddir@/test/XDG_DATA_DIRS:@abs_top_builddir@/test/XDG_DATA_DIRS2; \
export XDG_RUNTIME_DIR=@abs_top_builddir@/test/XDG_RUNTIME_DIR; \ export XDG_RUNTIME_DIR=@abs_top_builddir@/test/XDG_RUNTIME_DIR; \
export DBUS_FATAL_WARNINGS=1; \ export DBUS_FATAL_WARNINGS=1; \
export DBUS_TEST_BUILDDIR=@abs_builddir@; \
export DBUS_TEST_SRCDIR=@abs_srcdir@; \
export DBUS_TEST_DAEMON=@abs_top_builddir@/bus/dbus-daemon$(EXEEXT); \ export DBUS_TEST_DAEMON=@abs_top_builddir@/bus/dbus-daemon$(EXEEXT); \
export DBUS_TEST_DBUS_LAUNCH=@abs_top_builddir@/tools/dbus-launch$(EXEEXT); \ export DBUS_TEST_DBUS_LAUNCH=@abs_top_builddir@/tools/dbus-launch$(EXEEXT); \
export DBUS_TEST_DBUS_MONITOR=@abs_top_builddir@/tools/dbus-monitor$(EXEEXT); \ export DBUS_TEST_DBUS_MONITOR=@abs_top_builddir@/tools/dbus-monitor$(EXEEXT); \