summaryrefslogtreecommitdiff
path: root/libnm-glib/tests/test-remote-settings-client.c
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2014-07-31 14:00:22 -0400
committerDan Winship <danw@gnome.org>2014-08-01 12:12:42 -0400
commit08b91199fb95d9178feaeaa58381847332f22ad8 (patch)
tree9cc7c3ab8c111ad8d8f5662d1220c52c3b553922 /libnm-glib/tests/test-remote-settings-client.c
parentbd8a7f74b1f7d9b1712741797096bf97ef5df9aa (diff)
downloadNetworkManager-08b91199fb95d9178feaeaa58381847332f22ad8.tar.gz
libnm-glib: make test-networkmanager-service.py automatically exit with its parent
test-nm-client.c and test-remote-settings-client.c were using their own assertion macros so they could kill the test service on assertion failure. Except that some new code didn't get the memo and used the g_assert* macros. Not to mention that sometimes the tests would crash outside of an assertion macro. We can make test-networkmanager-service.py notice that its parent has crashed by opening a pipe between them and taking advantage of the fact that the pipe will be automatically closed if the parent crashes. So then test-networkmanager-service.py just has to watch for that, and exit if the pipe closes. Then that lets us drop the test_assert* macros and just use g_assert* instead.
Diffstat (limited to 'libnm-glib/tests/test-remote-settings-client.c')
-rw-r--r--libnm-glib/tests/test-remote-settings-client.c79
1 files changed, 30 insertions, 49 deletions
diff --git a/libnm-glib/tests/test-remote-settings-client.c b/libnm-glib/tests/test-remote-settings-client.c
index 7b4bdce36b..e8dd95596f 100644
--- a/libnm-glib/tests/test-remote-settings-client.c
+++ b/libnm-glib/tests/test-remote-settings-client.c
@@ -42,18 +42,6 @@ NMRemoteConnection *remote = NULL;
/*******************************************************************/
-#define test_assert(condition) \
-do { \
- gboolean _condition = !!( condition ); \
- \
- if (G_UNLIKELY (!_condition)) { \
- nm_test_service_cleanup (sinfo); \
- g_assert (!"test_assert() failed for" # condition); \
- } \
-} while (0)
-
-/*******************************************************************/
-
static void
add_cb (NMRemoteSettings *s,
NMRemoteConnection *connection,
@@ -100,20 +88,20 @@ test_add_connection (void)
connection,
add_cb,
&done);
- test_assert (success == TRUE);
+ g_assert (success == TRUE);
start = time (NULL);
do {
now = time (NULL);
g_main_context_iteration (NULL, FALSE);
} while ((done == FALSE) && (now - start < 5));
- test_assert (done == TRUE);
- test_assert (remote != NULL);
+ g_assert (done == TRUE);
+ g_assert (remote != NULL);
/* Make sure the connection is the same as what we added */
- test_assert (nm_connection_compare (connection,
- NM_CONNECTION (remote),
- NM_SETTING_COMPARE_FLAG_EXACT) == TRUE);
+ g_assert (nm_connection_compare (connection,
+ NM_CONNECTION (remote),
+ NM_SETTING_COMPARE_FLAG_EXACT) == TRUE);
}
/*******************************************************************/
@@ -127,10 +115,8 @@ set_visible_cb (DBusGProxy *proxy,
gboolean success;
success = dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID);
- if (!success)
- g_warning ("Failed to change connection visibility: %s", error->message);
- test_assert (success == TRUE);
- test_assert (error == NULL);
+ g_assert_no_error (error);
+ g_assert (success == TRUE);
}
static void
@@ -158,7 +144,7 @@ test_make_invisible (void)
gboolean done = FALSE, has_settings = FALSE;
char *path;
- test_assert (remote != NULL);
+ g_assert (remote != NULL);
/* Listen for the remove event when the connection becomes invisible */
g_signal_connect (remote, "removed", G_CALLBACK (invis_removed_cb), &done);
@@ -168,7 +154,7 @@ test_make_invisible (void)
NM_DBUS_SERVICE,
path,
NM_DBUS_IFACE_SETTINGS_CONNECTION);
- test_assert (proxy != NULL);
+ g_assert (proxy != NULL);
/* Bypass the NMRemoteSettings object so we can test it independently */
dbus_g_proxy_begin_call (proxy, "SetVisible", set_visible_cb, NULL, NULL,
@@ -180,7 +166,7 @@ test_make_invisible (void)
now = time (NULL);
g_main_context_iteration (NULL, FALSE);
} while ((done == FALSE) && (now - start < 5));
- test_assert (done == TRUE);
+ g_assert (done == TRUE);
g_assert (remote);
g_signal_handlers_disconnect_by_func (remote, G_CALLBACK (invis_removed_cb), &done);
@@ -190,8 +176,8 @@ test_make_invisible (void)
for (iter = list; iter; iter = g_slist_next (iter)) {
NMConnection *candidate = NM_CONNECTION (iter->data);
- test_assert ((gpointer) remote != (gpointer) candidate);
- test_assert (strcmp (path, nm_connection_get_path (candidate)) != 0);
+ g_assert ((gpointer) remote != (gpointer) candidate);
+ g_assert (strcmp (path, nm_connection_get_path (candidate)) != 0);
}
/* And ensure the invisible connection no longer has any settings */
@@ -199,7 +185,7 @@ test_make_invisible (void)
nm_connection_for_each_setting_value (NM_CONNECTION (remote),
invis_has_settings_cb,
&has_settings);
- test_assert (has_settings == FALSE);
+ g_assert (has_settings == FALSE);
g_free (path);
g_object_unref (proxy);
@@ -225,7 +211,7 @@ test_make_visible (void)
char *path;
NMRemoteConnection *new = NULL;
- test_assert (remote != NULL);
+ g_assert (remote != NULL);
/* Wait for the new-connection signal when the connection is visible again */
g_signal_connect (settings, NM_REMOTE_SETTINGS_NEW_CONNECTION,
@@ -236,7 +222,7 @@ test_make_visible (void)
NM_DBUS_SERVICE,
path,
NM_DBUS_IFACE_SETTINGS_CONNECTION);
- test_assert (proxy != NULL);
+ g_assert (proxy != NULL);
/* Bypass the NMRemoteSettings object so we can test it independently */
dbus_g_proxy_begin_call (proxy, "SetVisible", set_visible_cb, NULL, NULL,
@@ -251,8 +237,8 @@ test_make_visible (void)
} while ((new == NULL) && (now - start < 5));
/* Ensure the new connection is the same as the one we made visible again */
- test_assert (new);
- test_assert (new == remote);
+ g_assert (new);
+ g_assert (new == remote);
g_signal_handlers_disconnect_by_func (settings, G_CALLBACK (vis_new_connection_cb), &new);
@@ -262,13 +248,13 @@ test_make_visible (void)
NMConnection *candidate = NM_CONNECTION (iter->data);
if ((gpointer) remote == (gpointer) candidate) {
- test_assert (strcmp (path, nm_connection_get_path (candidate)) == 0);
- test_assert (strcmp (TEST_CON_ID, nm_connection_get_id (candidate)) == 0);
+ g_assert_cmpstr (path, ==, nm_connection_get_path (candidate));
+ g_assert_cmpstr (TEST_CON_ID, ==, nm_connection_get_id (candidate));
found = TRUE;
break;
}
}
- test_assert (found == TRUE);
+ g_assert (found == TRUE);
g_free (path);
g_object_unref (proxy);
@@ -285,10 +271,8 @@ deleted_cb (DBusGProxy *proxy,
gboolean success;
success = dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID);
- if (!success)
- g_warning ("Failed to delete connection: %s", error->message);
- test_assert (success == TRUE);
- test_assert (error == NULL);
+ g_assert_no_error (error);
+ g_assert (success == TRUE);
}
static void
@@ -309,7 +293,7 @@ test_remove_connection (void)
/* Find a connection to delete */
list = nm_remote_settings_list_connections (settings);
- test_assert (g_slist_length (list) > 0);
+ g_assert_cmpint (g_slist_length (list), >, 0);
connection = NM_REMOTE_CONNECTION (list->data);
g_assert (connection);
@@ -321,7 +305,7 @@ test_remove_connection (void)
NM_DBUS_SERVICE,
path,
NM_DBUS_IFACE_SETTINGS_CONNECTION);
- test_assert (proxy != NULL);
+ g_assert (proxy != NULL);
/* Bypass the NMRemoteSettings object so we can test it independently */
dbus_g_proxy_begin_call (proxy, "Delete", deleted_cb, NULL, NULL, G_TYPE_INVALID);
@@ -331,7 +315,7 @@ test_remove_connection (void)
now = time (NULL);
g_main_context_iteration (NULL, FALSE);
} while ((done == FALSE) && (now - start < 5));
- test_assert (done == TRUE);
+ g_assert (done == TRUE);
g_assert (!remote);
@@ -340,8 +324,8 @@ test_remove_connection (void)
for (iter = list; iter; iter = g_slist_next (iter)) {
NMConnection *candidate = NM_CONNECTION (iter->data);
- test_assert ((gpointer) connection != (gpointer) candidate);
- test_assert (strcmp (path, nm_connection_get_path (candidate)) != 0);
+ g_assert ((gpointer) connection != (gpointer) candidate);
+ g_assert_cmpstr (path, ==, nm_connection_get_path (candidate));
}
g_free (path);
@@ -363,15 +347,12 @@ main (int argc, char **argv)
g_test_init (&argc, &argv, NULL);
bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
- if (!bus) {
- g_warning ("Error connecting to D-Bus: %s", error->message);
- g_assert (error == NULL);
- }
+ g_assert_no_error (error);
sinfo = nm_test_service_init ();
settings = nm_remote_settings_new (bus);
- test_assert (settings != NULL);
+ g_assert (settings != NULL);
g_test_add_func ("/remote_settings/add_connection", test_add_connection);
g_test_add_func ("/remote_settings/make_invisible", test_make_invisible);