From 385e783648e0a477f0957d45791dbb60df67468d Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Sat, 29 Apr 2017 23:07:55 +0000 Subject: Avoid crash during test runs. Don't initialize new NMClient instance during unit tests. --- src/uccs-server.c | 24 ++++++++++++++---------- tests/Makefile.am | 1 + 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/uccs-server.c b/src/uccs-server.c index c83db35..b045673 100644 --- a/src/uccs-server.c +++ b/src/uccs-server.c @@ -112,19 +112,23 @@ uccs_server_init (UccsServer *self) /* Start as unavailable */ self->parent.state = SERVER_STATE_UNAVAILABLE; - if (global_client == NULL) { - global_client = nm_client_new(); + if (g_strcmp0(g_getenv("DBUS_TEST_RUNNER"), "1")) { - if (global_client != NULL) { - g_object_add_weak_pointer(G_OBJECT(global_client), (gpointer *)&global_client); - self->nm_client = global_client; + if (global_client == NULL) { + global_client = nm_client_new(); + + if (global_client != NULL) { + g_object_add_weak_pointer(G_OBJECT(global_client), (gpointer *)&global_client); + self->nm_client = global_client; + } + } else { + self->nm_client = g_object_ref(global_client); + } + + if (self->nm_client != NULL) { + self->nm_signal = g_signal_connect(self->nm_client, "notify::" NM_CLIENT_STATE, G_CALLBACK(nm_state_changed), self); } - } else { - self->nm_client = g_object_ref(global_client); - } - if (self->nm_client != NULL) { - self->nm_signal = g_signal_connect(self->nm_client, "notify::" NM_CLIENT_STATE, G_CALLBACK(nm_state_changed), self); } self->verify_server = TRUE; diff --git a/tests/Makefile.am b/tests/Makefile.am index 9a34654..7927598 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -15,6 +15,7 @@ TESTS = \ SERVER_XML_REPORT = server-test.xml server-tester: server-test Makefile.am @echo "#!/bin/bash" > $@ + @echo export DBUS_TEST_RUNNER=1 >> $@ @echo gtester --verbose -k -o $(SERVER_XML_REPORT) $(abs_builddir)/server-test >> $@ @chmod +x $@ -- cgit v1.2.3