From: Murray Cumming Date: Tue, 28 Jun 2011 09:12:56 +0000 (+0200) Subject: addressbook tests: Run with private D-Bus session and environment. X-Git-Tag: upstream/3.7.4~174 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ae47997a88442080a49285e279162ac1f20a8483;p=platform%2Fupstream%2Fevolution-data-server.git addressbook tests: Run with private D-Bus session and environment. * tests/: Add a tools/ directory with .sh files from libfolks/tests/tools/, to let us start and stop a private D-Bus session, and set XDG_* environment variables for local use of EDS, when running tests. * tests/libebook/client/Makefile.am: Set TESTS_ENVIRONMENT to run the tests with the private D-Bus session. --- diff --git a/configure.ac b/configure.ac index 20bbaba..b4a2af9 100644 --- a/configure.ac +++ b/configure.ac @@ -1614,6 +1614,7 @@ tests/libecal/client/Makefile tests/libedata-cal/Makefile tests/libedataserver/Makefile tests/libedataserverui/Makefile +tests/tools/Makefile docs/Makefile docs/reference/Makefile docs/reference/addressbook/Makefile diff --git a/tests/Makefile.am b/tests/Makefile.am index 9c4d922..46f96be 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = libedataserver libedataserverui libebook libecal libedata-cal +SUBDIRS = libedataserver libedataserverui libebook libecal libedata-cal tools @GNOME_CODE_COVERAGE_RULES@ diff --git a/tests/libebook/client/Makefile.am b/tests/libebook/client/Makefile.am index edb1920..e0a4295 100644 --- a/tests/libebook/client/Makefile.am +++ b/tests/libebook/client/Makefile.am @@ -63,6 +63,13 @@ TEST_LIBS = \ $(top_builddir)/addressbook/libebook/libebook-1.2.la \ $(EVOLUTION_ADDRESSBOOK_LIBS) \ $(NULL) + +RUN_WITH_PRIVATE_BUS = $(top_srcdir)/tests/tools/with-session-bus-eds.sh + +TESTS_ENVIRONMENT = \ + $(RUN_WITH_PRIVATE_BUS) \ + --session \ + -- test_client_LDADD=$(TEST_LIBS) test_client_CPPFLAGS=$(TEST_CPPFLAGS) diff --git a/tests/tools/Makefile.am b/tests/tools/Makefile.am new file mode 100644 index 0000000..6abf3bc --- /dev/null +++ b/tests/tools/Makefile.am @@ -0,0 +1,5 @@ +EXTRA_DIST = \ + with-session-bus.sh \ + dbus-session.sh + +-include $(top_srcdir)/git.mk diff --git a/tests/tools/dbus-session.sh b/tests/tools/dbus-session.sh new file mode 100644 index 0000000..1f805bf --- /dev/null +++ b/tests/tools/dbus-session.sh @@ -0,0 +1,114 @@ +# +# Helper functions to start your own D-Bus session. +# +# Refactored from with-session-bush.sh (from telepathy-glib). +# +# The canonical location of this program is the telepathy-glib tools/ +# directory, please synchronize any changes with that copy. +# +# Copyright (C) 2007-2008,2011 Collabora Ltd. +# +# Copying and distribution of this file, with or without modification, +# are permitted in any medium without royalty provided the copyright +# notice and this notice are preserved. + + +dbus_daemon_args="--print-address=5 --print-pid=6 --fork" +dbus_verbose=0 +dbus_me=with-session-bus +dbus_sleep=0 +dbus_with_session="" +dbus_config_file="" + +# Params: +# verbose: 0 for off and 1 for on +# +dbus_init () { + exec 5> $dbus_me-$$.address + exec 6> $dbus_me-$$.pid + dbus_verbose=$1 +} + +dbus_usage () +{ + echo "usage: $me [options] -- program [program_options]" >&2 + echo "Requires write access to the current directory." >&2 + echo "" >&2 + echo "If \$WITH_SESSION_BUS_FORK_DBUS_MONITOR is set, fork dbus-monitor" >&2 + echo "with the arguments in \$WITH_SESSION_BUS_FORK_DBUS_MONITOR_OPT." >&2 + echo "The output of dbus-monitor is saved in $me-.dbus-monitor-logs" >&2 + exit 2 +} + +dbus_parse_args () { + while test "z$1" != "z--"; do + case "$1" in + --sleep=*) + sleep="$1" + dbus_sleep="${sleep#--sleep=}" + shift + ;; + --session) + dbus_with_session="--session" + shift + ;; + --config-file=*) + # FIXME: assumes config file doesn't contain any special characters + dbus_config_file="$1" + shift + ;; + *) + dbus_usage + ;; + esac + done +} + +dbus_start () { + local args="$dbus_daemon_args $dbus_with_session $dbus_config_file " + + if [ $dbus_verbose -gt 0 ] ; then + echo -n "dbus args $args " + fi + + dbus-daemon $args + + { + if [ $dbus_verbose -gt 0 ] ; then + echo -n "Temporary bus daemon is "; cat $dbus_me-$$.address; + fi + } >&2 + + { + if [ $dbus_verbose -gt 0 ] ; then + echo -n "Temporary bus daemon PID is "; head -n1 $dbus_me-$$.pid; + fi + } >&2 + + DBUS_SESSION_BUS_ADDRESS="`cat $dbus_me-$$.address`" + export DBUS_SESSION_BUS_ADDRESS + + if [ -n "$WITH_SESSION_BUS_FORK_DBUS_MONITOR" ] ; then + if [ $dbus_verbose -gt 0 ] ; then + echo -n "Forking dbus-monitor " \ + "$WITH_SESSION_BUS_FORK_DBUS_MONITOR_OPT" >&2 + fi + dbus-monitor $WITH_SESSION_BUS_FORK_DBUS_MONITOR_OPT \ + > $dbus_me-$$.dbus-monitor-logs 2>&1 & + fi +} + +# +# This should be called for INT, HUP and TERM signals +# +dbus_stop () { + pid=`head -n1 $dbus_me-$$.pid` + if test -n "$pid" ; then + if [ $dbus_verbose -gt 0 ] ; then + echo "Killing temporary bus daemon: $pid" >&2 + fi + kill -INT "$pid" + fi + rm -f $dbus_me-$$.address + rm -f $dbus_me-$$.pid +} diff --git a/tests/tools/eds.sh b/tests/tools/eds.sh new file mode 100644 index 0000000..a3dc415 --- /dev/null +++ b/tests/tools/eds.sh @@ -0,0 +1,36 @@ +# +# Helper functions to start your own e-d-s instance. This depends +# on you having your own D-Bus session bus started (first). +# +# +# Copyright (C) 2011 Collabora Ltd. +# +# Copying and distribution of this file, with or without modification, +# are permitted in any medium without royalty provided the copyright +# notice and this notice are preserved. + +eds_tmpdir=$(mktemp -d) + +eds_init_settings () { + export XDG_DATA_HOME=$eds_tmpdir/.local + export XDG_CACHE_HOME=$eds_tmpdir/.cache + export XDG_CONFIG_HOME=$eds_tmpdir/.config +} + +# This makes sure that our locally-built service starts, +# in our already-started private D-Bus session, +# so we don't need to use a .service file to make sure that it will be +# activated instead. +eds_start() { + #$(top_builddir)/addressbook/libedata-book/e-addressbook-factory -r + $cur_dir"/../../addressbook/libedata-book/e-addressbook-factory" -r& + eds_pid=$! +} + +# This should be called on INT TERM and EXIT +eds_stop () { + kill $eds_pid + rm -rf $eds_tmpdir + rm -rf $eds_tmpdir +} + diff --git a/tests/tools/with-session-bus-eds.sh b/tests/tools/with-session-bus-eds.sh new file mode 100755 index 0000000..416b8bb --- /dev/null +++ b/tests/tools/with-session-bus-eds.sh @@ -0,0 +1,45 @@ +#!/bin/sh +# with-session-bus-eds.sh - run a program with a temporary D-Bus session daemon +# +# interesting bits have been move into dbus to permit reusability +# +# Copyright (C) 2007-2008 Collabora Ltd. +# +# Copying and distribution of this file, with or without modification, +# are permitted in any medium without royalty provided the copyright +# notice and this notice are preserved. + + +cur_dir=`dirname $0` + +. $cur_dir"/dbus-session.sh" +. $cur_dir"/eds.sh" + +dbus_parse_args $@ +while test "z$1" != "z--"; do + shift +done +shift +if test "z$1" = "z"; then dbus_usage; fi + +cleanup () +{ + eds_stop + dbus_stop +} + +trap cleanup INT HUP TERM + +eds_init_settings +eds_start +dbus_init 0 + +dbus_start + +e=0 +"$@" || e=$? + +trap - INT HUP TERM +cleanup + +exit $e