summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac.in1
-rw-r--r--tests/Makefile.am8
-rw-r--r--tests/Makefile.inc3
-rw-r--r--tests/tests-common.h2
-rwxr-xr-xtests/tests-driver.sh106
-rw-r--r--tests/tests-end/Makefile.am6
-rw-r--r--tests/tests-end/t-tests-end.c8
-rw-r--r--xfconf/xfconf.c8
-rw-r--r--xfconfd/main.c6
9 files changed, 139 insertions, 9 deletions
diff --git a/configure.ac.in b/configure.ac.in
index bc15f81..217715e 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -210,6 +210,7 @@ tests/get-properties/Makefile
tests/reset-properties/Makefile
tests/object-bindings/Makefile
tests/property-changed-signal/Makefile
+tests/tests-end/Makefile
xfconf/Makefile
xfconf/libxfconf-0.pc
xfconf-query/Makefile
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 57ba7e8..f1b06c0 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -5,12 +5,10 @@ SUBDIRS = \
get-properties \
reset-properties \
property-changed-signal \
- object-bindings
+ object-bindings \
+ tests-end
# list-channels
-clean-local:
- -rm -rf test-xdg_config_home
-
EXTRA_DIST = \
- $(test_scripts) \
+ tests-driver.sh \
tests-common.h
diff --git a/tests/Makefile.inc b/tests/Makefile.inc
index 36b8cde..86556dc 100644
--- a/tests/Makefile.inc
+++ b/tests/Makefile.inc
@@ -13,8 +13,9 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+LOG_COMPILER = $(top_srcdir)/tests/tests-driver.sh $(top_builddir)/xfconfd
+
TESTS = $(check_PROGRAMS)
-TESTS_ENVIRONMENT = XDG_CONFIG_HOME="$(top_builddir)/tests/test-xdg_config_home" XFCONFD="$(top_builddir)/xfconfd/xfconfd"
AM_CFLAGS = \
-I$(top_srcdir) \
diff --git a/tests/tests-common.h b/tests/tests-common.h
index b763aac..28eb3d6 100644
--- a/tests/tests-common.h
+++ b/tests/tests-common.h
@@ -89,7 +89,7 @@ xfconf_tests_start(void)
xfconf_tests_end();
return FALSE;
}
- msg = g_dbus_message_new_method_call("org.xfce.Xfconf",
+ msg = g_dbus_message_new_method_call("org.xfce.XfconfTest",
"/org/xfce/Xfconf",
"org.freedesktop.DBus.Peer",
"Ping");
diff --git a/tests/tests-driver.sh b/tests/tests-driver.sh
new file mode 100755
index 0000000..430a8c3
--- /dev/null
+++ b/tests/tests-driver.sh
@@ -0,0 +1,106 @@
+#!/bin/sh
+# Copyright (C) 2020 Ali Abdallah <ali.abdallah@suse.com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+XFCONFD_DIR=$1
+TEST=$2
+XFCONFD=$XFCONFD_DIR/xfconfd
+
+XFCONF_RUN_IN_TEST_MODE=1; export XFCONF_RUN_IN_TEST_MODE;
+
+exec_xfconfd()
+{
+ rm $XFCONFD_DIR/.xfconfd-test-pid >/dev/null 2>&1
+ rm $XFCONFD_DIR/.xfconfd-sum >/dev/null 2>&1
+
+ exec ${XFCONFD} &
+ echo $! > $XFCONFD_DIR/.xfconfd-test-pid
+ pid=`cat $XFCONFD_DIR/.xfconfd-test-pid`
+ sum $XFCONFD > $XFCONFD_DIR/.xfconfd-sum
+}
+
+cleanup()
+{
+ pid=`cat $XFCONFD_DIR/.xfconfd-test-pid`
+
+ rm $XFCONFD_DIR/.xfconfd-test-pid >/dev/null 2>&1
+ rm $XFCONFD_DIR/.xfconfd-sum >/dev/null 2>&1
+
+ while kill -0 $pid >/dev/null 2>&1; do
+ kill -s TERM $pid >/dev/null 2>&1
+ sleep 0.1
+ done
+}
+
+prepare()
+{
+ if [ ! -f $XFCONFD ]; then
+ exit 1
+ fi
+
+ # Start xfconfd only if it is not started already
+ if [ ! -f $XFCONFD_DIR/.xfconfd-test-pid ]; then
+ exec_xfconfd
+ elif [ ! -f $XFCONFD_DIR/.xfconfd-sum ]; then
+ cleanup
+ exec_xfconfd
+ else
+ oldsum=`cat $XFCONFD_DIR/.xfconfd-sum`
+ newsum=`sum ${XFCONFD}`
+
+ # Did xfconfd changes ?
+ if [ "$newsum" != "$oldsum" ]; then
+ cleanup
+ exec_xfconfd
+ else
+ pid=`cat $XFCONFD_DIR/.xfconfd-test-pid`
+ kill -s 0 $pid >/dev/null 2>&1
+
+ # Is it still running ?
+ if [ $? != 0 ]; then
+ cleanup
+ exec_xfconfd
+ fi
+ fi
+ fi
+}
+
+sigint()
+{
+ cleanup
+ exit 1
+}
+
+trap 'sigint' INT
+
+# Last test, cleanup
+TEST_NAME=$(basename $TEST)
+
+if [ "$TEST_NAME" == "t-tests-end" ]; then
+ cleanup
+ exit 0
+fi
+
+# Prepare xfconfd
+prepare $XFCONFD_DIR
+
+# Execute the test
+exec $TEST
+ret = $?
+# Test failed, cleanup
+if [ $ret != 0 ]; then
+ cleanup
+fi
+exit $ret
diff --git a/tests/tests-end/Makefile.am b/tests/tests-end/Makefile.am
new file mode 100644
index 0000000..66c92de
--- /dev/null
+++ b/tests/tests-end/Makefile.am
@@ -0,0 +1,6 @@
+check_PROGRAMS = \
+ t-tests-end
+
+t_tests_end_SOURCES = t-tests-end.c
+
+include $(top_srcdir)/tests/Makefile.inc
diff --git a/tests/tests-end/t-tests-end.c b/tests/tests-end/t-tests-end.c
new file mode 100644
index 0000000..caa92ab
--- /dev/null
+++ b/tests/tests-end/t-tests-end.c
@@ -0,0 +1,8 @@
+/* It is just a dummy test in order to shutdown
+ * xfconfd, see tests-driver.sh for more details */
+
+int
+main(void)
+{
+ return 0;
+}
diff --git a/xfconf/xfconf.c b/xfconf/xfconf.c
index 228bdc3..748a55f 100644
--- a/xfconf/xfconf.c
+++ b/xfconf/xfconf.c
@@ -41,6 +41,9 @@ static GDBusConnection *gdbus = NULL;
static GDBusProxy *gproxy = NULL;
static GHashTable *named_structs = NULL;
+#define XFCONF_DBUS_NAME "org.xfce.Xfconf"
+#define XFCONF_DBUS_NAME_TEST "org.xfce.XfconfTest"
+
/* private api */
@@ -108,6 +111,8 @@ _xfconf_named_struct_free(XfconfNamedStruct *ns)
gboolean
xfconf_init(GError **error)
{
+ const gchar *is_test_mode;
+
if(xfconf_refcnt) {
++xfconf_refcnt;
return TRUE;
@@ -122,10 +127,11 @@ xfconf_init(GError **error)
if (!gdbus)
return FALSE;
+ is_test_mode = g_getenv ("XFCONF_RUN_IN_TEST_MODE");
gproxy = g_dbus_proxy_new_sync(gdbus,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
- "org.xfce.Xfconf",
+ is_test_mode == NULL ? XFCONF_DBUS_NAME : XFCONF_DBUS_NAME_TEST,
"/org/xfce/Xfconf",
"org.xfce.Xfconf",
NULL,
diff --git a/xfconfd/main.c b/xfconfd/main.c
index 8a8fc2a..45c31e8 100644
--- a/xfconfd/main.c
+++ b/xfconfd/main.c
@@ -55,6 +55,8 @@
#include "xfconf-backend-factory.h"
#define DEFAULT_BACKEND "xfce-perchannel-xml"
+#define XFCONF_DBUS_NAME "org.xfce.Xfconf"
+#define XFCONF_DBUS_NAME_TEST "org.xfce.XfconfTest"
enum
{
@@ -137,6 +139,7 @@ main(int argc,
GError *error = NULL;
struct sigaction act;
GIOChannel *signal_io;
+ const gchar *is_test_mode;
guint signal_watch = 0;
GOptionContext *opt_ctx;
@@ -232,8 +235,9 @@ main(int argc,
g_strfreev(backends);
/* acquire name */
+ is_test_mode = g_getenv ("XFCONF_RUN_IN_TEST_MODE");
g_bus_own_name (G_BUS_TYPE_SESSION,
- "org.xfce.Xfconf",
+ is_test_mode == NULL ? XFCONF_DBUS_NAME : XFCONF_DBUS_NAME_TEST,
G_BUS_NAME_OWNER_FLAGS_NONE,
NULL,
NULL,