diff options
author | Dan Winship <danw@gnome.org> | 2014-07-31 14:00:22 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2014-08-01 12:12:42 -0400 |
commit | 08b91199fb95d9178feaeaa58381847332f22ad8 (patch) | |
tree | 9cc7c3ab8c111ad8d8f5662d1220c52c3b553922 /libnm-glib/tests | |
parent | bd8a7f74b1f7d9b1712741797096bf97ef5df9aa (diff) | |
download | NetworkManager-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')
-rw-r--r-- | libnm-glib/tests/common.c | 8 | ||||
-rw-r--r-- | libnm-glib/tests/common.h | 1 | ||||
-rw-r--r-- | libnm-glib/tests/test-nm-client.c | 188 | ||||
-rw-r--r-- | libnm-glib/tests/test-remote-settings-client.c | 79 |
4 files changed, 118 insertions, 158 deletions
diff --git a/libnm-glib/tests/common.c b/libnm-glib/tests/common.c index 0cc5da0130..0dbdac54c2 100644 --- a/libnm-glib/tests/common.c +++ b/libnm-glib/tests/common.c @@ -64,7 +64,12 @@ nm_test_service_init (void) info->bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); g_assert_no_error (error); - g_spawn_async (NULL, (char **) args, NULL, 0, NULL, NULL, &info->pid, &error); + /* Spawn the test service. info->keepalive_fd will be a pipe to the service's + * stdin; if it closes, the service will exit immediately. We use this to + * make sure the service exits if the test program crashes. + */ + g_spawn_async_with_pipes (NULL, (char **) args, NULL, 0, NULL, NULL, + &info->pid, &info->keepalive_fd, NULL, NULL, &error); g_assert_no_error (error); /* Wait until the service is registered on the bus */ @@ -107,6 +112,7 @@ nm_test_service_cleanup (NMTestServiceInfo *info) g_assert (i > 0); g_object_unref (info->bus); + close (info->keepalive_fd); memset (info, 0, sizeof (*info)); g_free (info); diff --git a/libnm-glib/tests/common.h b/libnm-glib/tests/common.h index a35274a41d..7c49d2532b 100644 --- a/libnm-glib/tests/common.h +++ b/libnm-glib/tests/common.h @@ -24,6 +24,7 @@ typedef struct { GDBusConnection *bus; GDBusProxy *proxy; GPid pid; + int keepalive_fd; } NMTestServiceInfo; NMTestServiceInfo *nm_test_service_init (void); diff --git a/libnm-glib/tests/test-nm-client.c b/libnm-glib/tests/test-nm-client.c index e34d12516a..dc6126451b 100644 --- a/libnm-glib/tests/test-nm-client.c +++ b/libnm-glib/tests/test-nm-client.c @@ -40,34 +40,6 @@ static NMTestServiceInfo *sinfo; /*******************************************************************/ -#define test_assert(condition) \ -do { \ - if (!G_LIKELY (condition)) \ - nm_test_service_cleanup (sinfo); \ - g_assert (condition); \ -} while (0) - -#define test_assert_cmpint(a, b, c) \ -do { \ - if (!G_LIKELY (a b c)) \ - nm_test_service_cleanup (sinfo); \ - g_assert_cmpint (a, b, c); \ -} while (0) - -#define test_assert_cmpstr(a, b, c) \ -do { \ - if (!G_LIKELY (g_str_hash (a) b g_str_hash (c))) \ - nm_test_service_cleanup (sinfo); \ - g_assert_cmpstr (a, b, c); \ -} while (0) - -#define test_assert_no_error(e) \ -do { \ - if (G_UNLIKELY (e)) \ - nm_test_service_cleanup (sinfo); \ - g_assert_no_error (e); \ -} while (0) - static NMClient * test_client_new (void) { @@ -82,7 +54,7 @@ test_client_new (void) NM_OBJECT_DBUS_CONNECTION, bus, NM_OBJECT_DBUS_PATH, NM_DBUS_PATH, NULL); - test_assert (client != NULL); + g_assert (client != NULL); dbus_g_connection_unref (bus); @@ -114,9 +86,9 @@ add_device (const char *method, const char *ifname, char **out_path) 3000, NULL, &error); - test_assert_no_error (error); - test_assert (ret); - test_assert_cmpstr (g_variant_get_type_string (ret), ==, "(o)"); + g_assert_no_error (error); + g_assert (ret); + g_assert_cmpstr (g_variant_get_type_string (ret), ==, "(o)"); if (out_path) g_variant_get (ret, "(o)", out_path); g_variant_unref (ret); @@ -149,8 +121,8 @@ device_added_cb (NMClient *c, NMDevice *device, DeviceAddedInfo *info) { - test_assert (device); - test_assert_cmpstr (nm_device_get_iface (device), ==, "eth0"); + g_assert (device); + g_assert_cmpstr (nm_device_get_iface (device), ==, "eth0"); info->signaled = TRUE; device_add_check_quit (info); } @@ -164,12 +136,12 @@ devices_notify_cb (NMClient *c, NMDevice *device; devices = nm_client_get_devices (c); - test_assert (devices); - test_assert_cmpint (devices->len, ==, 1); + g_assert (devices); + g_assert_cmpint (devices->len, ==, 1); device = g_ptr_array_index (devices, 0); - test_assert (device); - test_assert_cmpstr (nm_device_get_iface (device), ==, "eth0"); + g_assert (device); + g_assert_cmpstr (nm_device_get_iface (device), ==, "eth0"); info->notified = TRUE; @@ -188,7 +160,7 @@ test_device_added (void) client = test_client_new (); devices = nm_client_get_devices (client); - test_assert (devices == NULL); + g_assert (devices == NULL); /* Tell the test service to add a new device */ add_device ("AddWiredDevice", "eth0", NULL); @@ -209,19 +181,19 @@ test_device_added (void) info.quit_id = g_timeout_add_seconds (5, loop_quit, loop); g_main_loop_run (loop); - test_assert (info.signaled); - test_assert (info.notified); + g_assert (info.signaled); + g_assert (info.notified); g_signal_handlers_disconnect_by_func (client, device_added_cb, &info); g_signal_handlers_disconnect_by_func (client, devices_notify_cb, &info); devices = nm_client_get_devices (client); - test_assert (devices); - test_assert_cmpint (devices->len, ==, 1); + g_assert (devices); + g_assert_cmpint (devices->len, ==, 1); device = g_ptr_array_index (devices, 0); - test_assert (device); - test_assert_cmpstr (nm_device_get_iface (device), ==, "eth0"); + g_assert (device); + g_assert_cmpstr (nm_device_get_iface (device), ==, "eth0"); g_object_unref (client); g_clear_pointer (&sinfo, nm_test_service_cleanup); @@ -257,7 +229,7 @@ wifi_device_added_cb (NMClient *c, NMDevice *device, WifiApInfo *info) { - test_assert_cmpstr (nm_device_get_iface (device), ==, "wlan0"); + g_assert_cmpstr (nm_device_get_iface (device), ==, "wlan0"); info->found = TRUE; wifi_check_quit (info); } @@ -266,7 +238,7 @@ static void got_ap_path (WifiApInfo *info, const char *path) { if (info->ap_path) - test_assert_cmpstr (info->ap_path, ==, path); + g_assert_cmpstr (info->ap_path, ==, path); else info->ap_path = g_strdup (path); } @@ -276,8 +248,8 @@ wifi_ap_added_cb (NMDeviceWifi *w, NMAccessPoint *ap, WifiApInfo *info) { - test_assert (ap); - test_assert_cmpstr (nm_access_point_get_bssid (ap), ==, expected_bssid); + g_assert (ap); + g_assert_cmpstr (nm_access_point_get_bssid (ap), ==, expected_bssid); got_ap_path (info, nm_object_get_path (NM_OBJECT (ap))); info->signaled = TRUE; @@ -293,12 +265,12 @@ wifi_ap_add_notify_cb (NMDeviceWifi *w, NMAccessPoint *ap; aps = nm_device_wifi_get_access_points (w); - test_assert (aps); - test_assert_cmpint (aps->len, ==, 1); + g_assert (aps); + g_assert_cmpint (aps->len, ==, 1); ap = g_ptr_array_index (aps, 0); - test_assert (ap); - test_assert_cmpstr (nm_access_point_get_bssid (ap), ==, "66:55:44:33:22:11"); + g_assert (ap); + g_assert_cmpstr (nm_access_point_get_bssid (ap), ==, "66:55:44:33:22:11"); got_ap_path (info, nm_object_get_path (NM_OBJECT (ap))); info->notified = TRUE; @@ -310,8 +282,8 @@ wifi_ap_removed_cb (NMDeviceWifi *w, NMAccessPoint *ap, WifiApInfo *info) { - test_assert (ap); - test_assert_cmpstr (info->ap_path, ==, nm_object_get_path (NM_OBJECT (ap))); + g_assert (ap); + g_assert_cmpstr (info->ap_path, ==, nm_object_get_path (NM_OBJECT (ap))); info->signaled = TRUE; wifi_check_quit (info); @@ -325,7 +297,7 @@ wifi_ap_remove_notify_cb (NMDeviceWifi *w, const GPtrArray *aps; aps = nm_device_wifi_get_access_points (w); - test_assert (aps == NULL); + g_assert (aps == NULL); info->notified = TRUE; wifi_check_quit (info); @@ -358,11 +330,11 @@ test_wifi_ap_added_removed (void) info.quit_id = g_timeout_add_seconds (5, loop_quit, loop); g_main_loop_run (loop); - test_assert (info.found); + g_assert (info.found); g_signal_handlers_disconnect_by_func (client, wifi_device_added_cb, &info); wifi = (NMDeviceWifi *) nm_client_get_device_by_iface (client, "wlan0"); - test_assert (NM_IS_DEVICE_WIFI (wifi)); + g_assert (NM_IS_DEVICE_WIFI (wifi)); /*************************************/ /* Add the wifi device */ @@ -377,9 +349,9 @@ test_wifi_ap_added_removed (void) 3000, NULL, &error); - test_assert_no_error (error); - test_assert (ret); - test_assert_cmpstr (g_variant_get_type_string (ret), ==, "(o)"); + g_assert_no_error (error); + g_assert (ret); + g_assert_cmpstr (g_variant_get_type_string (ret), ==, "(o)"); g_variant_get (ret, "(o)", &expected_path); g_variant_unref (ret); @@ -399,10 +371,10 @@ test_wifi_ap_added_removed (void) info.quit_id = g_timeout_add_seconds (5, loop_quit, loop); g_main_loop_run (loop); - test_assert (info.signaled); - test_assert (info.notified); - test_assert (info.ap_path); - test_assert_cmpstr (info.ap_path, ==, expected_path); + g_assert (info.signaled); + g_assert (info.notified); + g_assert (info.ap_path); + g_assert_cmpstr (info.ap_path, ==, expected_path); g_signal_handlers_disconnect_by_func (wifi, wifi_ap_added_cb, &info); g_signal_handlers_disconnect_by_func (wifi, wifi_ap_add_notify_cb, &info); @@ -419,7 +391,7 @@ test_wifi_ap_added_removed (void) 3000, NULL, &error); - test_assert_no_error (error); + g_assert_no_error (error); g_clear_pointer (&ret, g_variant_unref); g_signal_connect (wifi, @@ -438,8 +410,8 @@ test_wifi_ap_added_removed (void) info.quit_id = g_timeout_add_seconds (5, loop_quit, loop); g_main_loop_run (loop); - test_assert (info.signaled); - test_assert (info.notified); + g_assert (info.signaled); + g_assert (info.notified); g_signal_handlers_disconnect_by_func (wifi, wifi_ap_removed_cb, &info); g_signal_handlers_disconnect_by_func (wifi, wifi_ap_remove_notify_cb, &info); @@ -480,7 +452,7 @@ wimax_device_added_cb (NMClient *c, NMDevice *device, WimaxNspInfo *info) { - test_assert_cmpstr (nm_device_get_iface (device), ==, "wmx0"); + g_assert_cmpstr (nm_device_get_iface (device), ==, "wmx0"); info->found = TRUE; wimax_check_quit (info); } @@ -489,7 +461,7 @@ static void got_nsp_path (WimaxNspInfo *info, const char *path) { if (info->nsp_path) - test_assert_cmpstr (info->nsp_path, ==, path); + g_assert_cmpstr (info->nsp_path, ==, path); else info->nsp_path = g_strdup (path); } @@ -499,8 +471,8 @@ wimax_nsp_added_cb (NMDeviceWimax *w, NMWimaxNsp *nsp, WimaxNspInfo *info) { - test_assert (nsp); - test_assert_cmpstr (nm_wimax_nsp_get_name (nsp), ==, expected_nsp_name); + g_assert (nsp); + g_assert_cmpstr (nm_wimax_nsp_get_name (nsp), ==, expected_nsp_name); got_nsp_path (info, nm_object_get_path (NM_OBJECT (nsp))); info->signaled = TRUE; @@ -516,12 +488,12 @@ wimax_nsp_add_notify_cb (NMDeviceWimax *w, NMWimaxNsp *nsp; nsps = nm_device_wimax_get_nsps (w); - test_assert (nsps); - test_assert_cmpint (nsps->len, ==, 1); + g_assert (nsps); + g_assert_cmpint (nsps->len, ==, 1); nsp = g_ptr_array_index (nsps, 0); - test_assert (nsp); - test_assert_cmpstr (nm_wimax_nsp_get_name (nsp), ==, expected_nsp_name); + g_assert (nsp); + g_assert_cmpstr (nm_wimax_nsp_get_name (nsp), ==, expected_nsp_name); got_nsp_path (info, nm_object_get_path (NM_OBJECT (nsp))); info->notified = TRUE; @@ -533,8 +505,8 @@ wimax_nsp_removed_cb (NMDeviceWimax *w, NMWimaxNsp *nsp, WimaxNspInfo *info) { - test_assert (nsp); - test_assert_cmpstr (info->nsp_path, ==, nm_object_get_path (NM_OBJECT (nsp))); + g_assert (nsp); + g_assert_cmpstr (info->nsp_path, ==, nm_object_get_path (NM_OBJECT (nsp))); info->signaled = TRUE; wimax_check_quit (info); @@ -548,7 +520,7 @@ wimax_nsp_remove_notify_cb (NMDeviceWimax *w, const GPtrArray *nsps; nsps = nm_device_wimax_get_nsps (w); - test_assert (nsps == NULL); + g_assert (nsps == NULL); info->notified = TRUE; wimax_check_quit (info); @@ -581,11 +553,11 @@ test_wimax_nsp_added_removed (void) info.quit_id = g_timeout_add_seconds (5, loop_quit, loop); g_main_loop_run (loop); - test_assert (info.found); + g_assert (info.found); g_signal_handlers_disconnect_by_func (client, wimax_device_added_cb, &info); wimax = (NMDeviceWimax *) nm_client_get_device_by_iface (client, "wmx0"); - test_assert (NM_IS_DEVICE_WIMAX (wimax)); + g_assert (NM_IS_DEVICE_WIMAX (wimax)); /*************************************/ /* Add the wimax NSP */ @@ -600,9 +572,9 @@ test_wimax_nsp_added_removed (void) 3000, NULL, &error); - test_assert_no_error (error); - test_assert (ret); - test_assert_cmpstr (g_variant_get_type_string (ret), ==, "(o)"); + g_assert_no_error (error); + g_assert (ret); + g_assert_cmpstr (g_variant_get_type_string (ret), ==, "(o)"); g_variant_get (ret, "(o)", &expected_path); g_variant_unref (ret); @@ -622,10 +594,10 @@ test_wimax_nsp_added_removed (void) info.quit_id = g_timeout_add_seconds (5, loop_quit, loop); g_main_loop_run (loop); - test_assert (info.signaled); - test_assert (info.notified); - test_assert (info.nsp_path); - test_assert_cmpstr (info.nsp_path, ==, expected_path); + g_assert (info.signaled); + g_assert (info.notified); + g_assert (info.nsp_path); + g_assert_cmpstr (info.nsp_path, ==, expected_path); g_signal_handlers_disconnect_by_func (wimax, wimax_nsp_added_cb, &info); g_signal_handlers_disconnect_by_func (wimax, wimax_nsp_add_notify_cb, &info); @@ -642,7 +614,7 @@ test_wimax_nsp_added_removed (void) 3000, NULL, &error); - test_assert_no_error (error); + g_assert_no_error (error); g_clear_pointer (&ret, g_variant_unref); g_signal_connect (wimax, @@ -661,8 +633,8 @@ test_wimax_nsp_added_removed (void) info.quit_id = g_timeout_add_seconds (5, loop_quit, loop); g_main_loop_run (loop); - test_assert (info.signaled); - test_assert (info.notified); + g_assert (info.signaled); + g_assert (info.notified); g_signal_handlers_disconnect_by_func (wimax, wimax_nsp_removed_cb, &info); g_signal_handlers_disconnect_by_func (wimax, wimax_nsp_remove_notify_cb, &info); @@ -707,7 +679,7 @@ da_device_removed_cb (NMClient *c, NMDevice *device, DaInfo *info) { - test_assert_cmpstr (nm_device_get_iface (device), ==, "eth0"); + g_assert_cmpstr (nm_device_get_iface (device), ==, "eth0"); info->signaled = TRUE; da_check_quit (info); } @@ -723,14 +695,14 @@ da_devices_notify_cb (NMClient *c, const char *iface; devices = nm_client_get_devices (c); - test_assert (devices); - test_assert_cmpint (devices->len, ==, 2); + g_assert (devices); + g_assert_cmpint (devices->len, ==, 2); for (i = 0; i < devices->len; i++) { device = g_ptr_array_index (devices, i); iface = nm_device_get_iface (device); - test_assert (!strcmp (iface, "wlan0") || !strcmp (iface, "eth1")); + g_assert (!strcmp (iface, "wlan0") || !strcmp (iface, "eth1")); } info->notified = TRUE; @@ -767,22 +739,22 @@ test_devices_array (void) info.quit_id = g_timeout_add_seconds (5, loop_quit, loop); g_main_loop_run (loop); - test_assert_cmpint (info.quit_count, ==, 0); + g_assert_cmpint (info.quit_count, ==, 0); g_signal_handlers_disconnect_by_func (client, da_device_added_cb, &info); /* Ensure the devices now exist */ devices = nm_client_get_devices (client); - test_assert (devices); - test_assert_cmpint (devices->len, ==, 3); + g_assert (devices); + g_assert_cmpint (devices->len, ==, 3); device = nm_client_get_device_by_iface (client, "wlan0"); - test_assert (NM_IS_DEVICE_WIFI (device)); + g_assert (NM_IS_DEVICE_WIFI (device)); device = nm_client_get_device_by_iface (client, "eth0"); - test_assert (NM_IS_DEVICE_ETHERNET (device)); + g_assert (NM_IS_DEVICE_ETHERNET (device)); device = nm_client_get_device_by_iface (client, "eth1"); - test_assert (NM_IS_DEVICE_ETHERNET (device)); + g_assert (NM_IS_DEVICE_ETHERNET (device)); /********************************/ /* Now remove the device in the middle */ @@ -793,8 +765,8 @@ test_devices_array (void) 3000, NULL, &error); - test_assert_no_error (error); - test_assert (ret); + g_assert_no_error (error); + g_assert (ret); g_variant_unref (ret); g_signal_connect (client, @@ -812,20 +784,20 @@ test_devices_array (void) info.quit_id = g_timeout_add_seconds (5, loop_quit, loop); g_main_loop_run (loop); - test_assert_cmpint (info.quit_count, ==, 0); + g_assert_cmpint (info.quit_count, ==, 0); g_signal_handlers_disconnect_by_func (client, da_device_removed_cb, &info); g_signal_handlers_disconnect_by_func (client, da_devices_notify_cb, &info); /* Ensure only two are left */ devices = nm_client_get_devices (client); - test_assert (devices); - test_assert_cmpint (devices->len, ==, 2); + g_assert (devices); + g_assert_cmpint (devices->len, ==, 2); device = nm_client_get_device_by_iface (client, "wlan0"); - test_assert (NM_IS_DEVICE_WIFI (device)); + g_assert (NM_IS_DEVICE_WIFI (device)); device = nm_client_get_device_by_iface (client, "eth1"); - test_assert (NM_IS_DEVICE_ETHERNET (device)); + g_assert (NM_IS_DEVICE_ETHERNET (device)); g_free (paths[0]); g_free (paths[1]); 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); |