1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2, or (at your option)
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 * Copyright 2010 - 2014 Red Hat, Inc.
21 #include "nm-default.h"
23 #include <dbus/dbus.h>
24 #include <dbus/dbus-glib.h>
25 #include <dbus/dbus-glib-lowlevel.h>
27 #include <sys/types.h>
30 #include "nm-client.h"
31 #include "nm-device-wifi.h"
32 #include "nm-device-ethernet.h"
33 #include "nm-device-wimax.h"
34 #include "nm-connection.h"
35 #include "nm-setting.h"
37 #include "nm-test-libnm-utils.h"
39 static GMainLoop *loop = NULL;
40 static NMTstcServiceInfo *sinfo;
42 /*******************************************************************/
45 loop_quit (gpointer user_data)
47 g_main_loop_quit ((GMainLoop *) user_data);
48 return G_SOURCE_REMOVE;
52 add_device (const char *method, const char *ifname, char **out_path)
57 ret = g_dbus_proxy_call_sync (sinfo->proxy,
59 g_variant_new ("(s)", ifname),
60 G_DBUS_CALL_FLAGS_NO_AUTO_START,
64 g_assert_no_error (error);
66 g_assert_cmpstr (g_variant_get_type_string (ret), ==, "(o)");
68 g_variant_get (ret, "(o)", out_path);
69 g_variant_unref (ret);
74 add_wired_device (const char *method, const char *ifname, char **out_path)
76 const char *empty[] = { NULL };
80 ret = g_dbus_proxy_call_sync (sinfo->proxy,
82 g_variant_new ("(ss^as)", ifname, "/", empty),
83 G_DBUS_CALL_FLAGS_NO_AUTO_START,
87 g_assert_no_error (error);
89 g_assert_cmpstr (g_variant_get_type_string (ret), ==, "(o)");
91 g_variant_get (ret, "(o)", out_path);
92 g_variant_unref (ret);
96 /*******************************************************************/
107 device_add_check_quit (DeviceAddedInfo *info)
110 if (info->quit_count == 0) {
111 g_source_remove (info->quit_id);
113 g_main_loop_quit (info->loop);
118 device_added_cb (NMClient *c,
120 DeviceAddedInfo *info)
123 g_assert_cmpstr (nm_device_get_iface (device), ==, "eth0");
124 info->signaled = TRUE;
125 device_add_check_quit (info);
129 devices_notify_cb (NMClient *c,
131 DeviceAddedInfo *info)
133 const GPtrArray *devices;
136 devices = nm_client_get_devices (c);
138 g_assert_cmpint (devices->len, ==, 1);
140 device = g_ptr_array_index (devices, 0);
142 g_assert_cmpstr (nm_device_get_iface (device), ==, "eth0");
144 info->notified = TRUE;
146 device_add_check_quit (info);
150 test_device_added (void)
153 const GPtrArray *devices;
155 DeviceAddedInfo info = { loop, FALSE, FALSE, 0, 0 };
157 sinfo = nmtstc_service_init ();
158 client = nmtstc_nm_client_new ();
160 devices = nm_client_get_devices (client);
161 g_assert (devices == NULL);
163 /* Tell the test service to add a new device */
164 add_wired_device ("AddWiredDevice", "eth0", NULL);
166 g_signal_connect (client,
168 (GCallback) device_added_cb,
172 g_signal_connect (client,
174 (GCallback) devices_notify_cb,
178 /* Wait for libnm-glib to find the device */
179 info.quit_id = g_timeout_add_seconds (5, loop_quit, loop);
180 g_main_loop_run (loop);
182 g_assert (info.signaled);
183 g_assert (info.notified);
185 g_signal_handlers_disconnect_by_func (client, device_added_cb, &info);
186 g_signal_handlers_disconnect_by_func (client, devices_notify_cb, &info);
188 devices = nm_client_get_devices (client);
190 g_assert_cmpint (devices->len, ==, 1);
192 device = g_ptr_array_index (devices, 0);
194 g_assert_cmpstr (nm_device_get_iface (device), ==, "eth0");
196 g_object_unref (client);
197 g_clear_pointer (&sinfo, nmtstc_service_cleanup);
200 /*******************************************************************/
202 static const char *expected_bssid = "66:55:44:33:22:11";
215 wifi_check_quit (WifiApInfo *info)
218 if (info->quit_count == 0) {
219 g_source_remove (info->quit_id);
221 g_main_loop_quit (info->loop);
226 wifi_device_added_cb (NMClient *c,
230 g_assert_cmpstr (nm_device_get_iface (device), ==, "wlan0");
232 wifi_check_quit (info);
236 got_ap_path (WifiApInfo *info, const char *path)
239 g_assert_cmpstr (info->ap_path, ==, path);
241 info->ap_path = g_strdup (path);
245 wifi_ap_added_cb (NMDeviceWifi *w,
250 g_assert_cmpstr (nm_access_point_get_bssid (ap), ==, expected_bssid);
251 got_ap_path (info, nm_object_get_path (NM_OBJECT (ap)));
253 info->signaled = TRUE;
254 wifi_check_quit (info);
258 wifi_ap_add_notify_cb (NMDeviceWifi *w,
262 const GPtrArray *aps;
265 aps = nm_device_wifi_get_access_points (w);
267 g_assert_cmpint (aps->len, ==, 1);
269 ap = g_ptr_array_index (aps, 0);
271 g_assert_cmpstr (nm_access_point_get_bssid (ap), ==, "66:55:44:33:22:11");
272 got_ap_path (info, nm_object_get_path (NM_OBJECT (ap)));
274 info->notified = TRUE;
275 wifi_check_quit (info);
279 wifi_ap_removed_cb (NMDeviceWifi *w,
284 g_assert_cmpstr (info->ap_path, ==, nm_object_get_path (NM_OBJECT (ap)));
286 info->signaled = TRUE;
287 wifi_check_quit (info);
291 wifi_ap_remove_notify_cb (NMDeviceWifi *w,
295 const GPtrArray *aps;
297 aps = nm_device_wifi_get_access_points (w);
298 g_assert (aps == NULL);
300 info->notified = TRUE;
301 wifi_check_quit (info);
305 test_wifi_ap_added_removed (void)
309 WifiApInfo info = { loop, FALSE, FALSE, 0, 0 };
311 GError *error = NULL;
312 char *expected_path = NULL;
314 sinfo = nmtstc_service_init ();
315 client = nmtstc_nm_client_new ();
317 /*************************************/
318 /* Add the wifi device */
319 add_device ("AddWifiDevice", "wlan0", NULL);
321 g_signal_connect (client,
323 (GCallback) wifi_device_added_cb,
327 /* Wait for libnm-glib to find the device */
328 info.quit_id = g_timeout_add_seconds (5, loop_quit, loop);
329 g_main_loop_run (loop);
331 g_assert (info.found);
332 g_signal_handlers_disconnect_by_func (client, wifi_device_added_cb, &info);
334 wifi = (NMDeviceWifi *) nm_client_get_device_by_iface (client, "wlan0");
335 g_assert (NM_IS_DEVICE_WIFI (wifi));
337 /*************************************/
338 /* Add the wifi device */
339 info.signaled = FALSE;
340 info.notified = FALSE;
343 ret = g_dbus_proxy_call_sync (sinfo->proxy,
345 g_variant_new ("(sss)", "wlan0", "test-ap", expected_bssid),
346 G_DBUS_CALL_FLAGS_NO_AUTO_START,
350 g_assert_no_error (error);
352 g_assert_cmpstr (g_variant_get_type_string (ret), ==, "(o)");
353 g_variant_get (ret, "(o)", &expected_path);
354 g_variant_unref (ret);
356 g_signal_connect (wifi,
357 "access-point-added",
358 (GCallback) wifi_ap_added_cb,
362 g_signal_connect (wifi,
363 "notify::access-points",
364 (GCallback) wifi_ap_add_notify_cb,
368 /* Wait for libnm-glib to find the AP */
369 info.quit_id = g_timeout_add_seconds (5, loop_quit, loop);
370 g_main_loop_run (loop);
372 g_assert (info.signaled);
373 g_assert (info.notified);
374 g_assert (info.ap_path);
375 g_assert_cmpstr (info.ap_path, ==, expected_path);
376 g_signal_handlers_disconnect_by_func (wifi, wifi_ap_added_cb, &info);
377 g_signal_handlers_disconnect_by_func (wifi, wifi_ap_add_notify_cb, &info);
379 /*************************************/
380 /* Remove the wifi device */
381 info.signaled = FALSE;
382 info.notified = FALSE;
385 ret = g_dbus_proxy_call_sync (sinfo->proxy,
387 g_variant_new ("(so)", "wlan0", expected_path),
388 G_DBUS_CALL_FLAGS_NO_AUTO_START,
392 g_assert_no_error (error);
393 g_clear_pointer (&ret, g_variant_unref);
395 g_signal_connect (wifi,
396 "access-point-removed",
397 (GCallback) wifi_ap_removed_cb,
401 g_signal_connect (wifi,
402 "notify::access-points",
403 (GCallback) wifi_ap_remove_notify_cb,
407 /* Wait for libnm-glib to find the AP */
408 info.quit_id = g_timeout_add_seconds (5, loop_quit, loop);
409 g_main_loop_run (loop);
411 g_assert (info.signaled);
412 g_assert (info.notified);
413 g_signal_handlers_disconnect_by_func (wifi, wifi_ap_removed_cb, &info);
414 g_signal_handlers_disconnect_by_func (wifi, wifi_ap_remove_notify_cb, &info);
416 g_free (info.ap_path);
417 g_free (expected_path);
419 g_object_unref (client);
420 g_clear_pointer (&sinfo, nmtstc_service_cleanup);
423 /*******************************************************************/
425 static const char *expected_nsp_name = "Clear";
438 wimax_check_quit (WimaxNspInfo *info)
441 if (info->quit_count == 0) {
442 g_source_remove (info->quit_id);
444 g_main_loop_quit (info->loop);
449 wimax_device_added_cb (NMClient *c,
453 g_assert_cmpstr (nm_device_get_iface (device), ==, "wmx0");
455 wimax_check_quit (info);
459 got_nsp_path (WimaxNspInfo *info, const char *path)
462 g_assert_cmpstr (info->nsp_path, ==, path);
464 info->nsp_path = g_strdup (path);
468 wimax_nsp_added_cb (NMDeviceWimax *w,
473 g_assert_cmpstr (nm_wimax_nsp_get_name (nsp), ==, expected_nsp_name);
474 got_nsp_path (info, nm_object_get_path (NM_OBJECT (nsp)));
476 info->signaled = TRUE;
477 wimax_check_quit (info);
481 wimax_nsp_add_notify_cb (NMDeviceWimax *w,
485 const GPtrArray *nsps;
488 nsps = nm_device_wimax_get_nsps (w);
490 g_assert_cmpint (nsps->len, ==, 1);
492 nsp = g_ptr_array_index (nsps, 0);
494 g_assert_cmpstr (nm_wimax_nsp_get_name (nsp), ==, expected_nsp_name);
495 got_nsp_path (info, nm_object_get_path (NM_OBJECT (nsp)));
497 info->notified = TRUE;
498 wimax_check_quit (info);
502 wimax_nsp_removed_cb (NMDeviceWimax *w,
507 g_assert_cmpstr (info->nsp_path, ==, nm_object_get_path (NM_OBJECT (nsp)));
509 info->signaled = TRUE;
510 wimax_check_quit (info);
514 wimax_nsp_remove_notify_cb (NMDeviceWimax *w,
518 const GPtrArray *nsps;
520 nsps = nm_device_wimax_get_nsps (w);
521 g_assert (nsps == NULL);
523 info->notified = TRUE;
524 wimax_check_quit (info);
528 test_wimax_nsp_added_removed (void)
531 NMDeviceWimax *wimax;
532 WimaxNspInfo info = { loop, FALSE, FALSE, 0, 0 };
534 GError *error = NULL;
535 char *expected_path = NULL;
537 sinfo = nmtstc_service_init ();
538 client = nmtstc_nm_client_new ();
540 /*************************************/
541 /* Add the wimax device */
542 add_device ("AddWimaxDevice", "wmx0", NULL);
544 g_signal_connect (client,
546 (GCallback) wimax_device_added_cb,
550 /* Wait for libnm-glib to find the device */
551 info.quit_id = g_timeout_add_seconds (5, loop_quit, loop);
552 g_main_loop_run (loop);
554 g_assert (info.found);
555 g_signal_handlers_disconnect_by_func (client, wimax_device_added_cb, &info);
557 wimax = (NMDeviceWimax *) nm_client_get_device_by_iface (client, "wmx0");
558 g_assert (NM_IS_DEVICE_WIMAX (wimax));
560 /*************************************/
561 /* Add the wimax NSP */
562 info.signaled = FALSE;
563 info.notified = FALSE;
566 ret = g_dbus_proxy_call_sync (sinfo->proxy,
568 g_variant_new ("(ss)", "wmx0", expected_nsp_name),
569 G_DBUS_CALL_FLAGS_NO_AUTO_START,
573 g_assert_no_error (error);
575 g_assert_cmpstr (g_variant_get_type_string (ret), ==, "(o)");
576 g_variant_get (ret, "(o)", &expected_path);
577 g_variant_unref (ret);
579 g_signal_connect (wimax,
581 (GCallback) wimax_nsp_added_cb,
585 g_signal_connect (wimax,
587 (GCallback) wimax_nsp_add_notify_cb,
591 /* Wait for libnm-glib to find the AP */
592 info.quit_id = g_timeout_add_seconds (5, loop_quit, loop);
593 g_main_loop_run (loop);
595 g_assert (info.signaled);
596 g_assert (info.notified);
597 g_assert (info.nsp_path);
598 g_assert_cmpstr (info.nsp_path, ==, expected_path);
599 g_signal_handlers_disconnect_by_func (wimax, wimax_nsp_added_cb, &info);
600 g_signal_handlers_disconnect_by_func (wimax, wimax_nsp_add_notify_cb, &info);
602 /*************************************/
603 /* Remove the wimax NSP */
604 info.signaled = FALSE;
605 info.notified = FALSE;
608 ret = g_dbus_proxy_call_sync (sinfo->proxy,
610 g_variant_new ("(so)", "wmx0", expected_path),
611 G_DBUS_CALL_FLAGS_NO_AUTO_START,
615 g_assert_no_error (error);
616 g_clear_pointer (&ret, g_variant_unref);
618 g_signal_connect (wimax,
620 (GCallback) wimax_nsp_removed_cb,
624 g_signal_connect (wimax,
626 (GCallback) wimax_nsp_remove_notify_cb,
630 /* Wait for libnm-glib to find the AP */
631 info.quit_id = g_timeout_add_seconds (5, loop_quit, loop);
632 g_main_loop_run (loop);
634 g_assert (info.signaled);
635 g_assert (info.notified);
636 g_signal_handlers_disconnect_by_func (wimax, wimax_nsp_removed_cb, &info);
637 g_signal_handlers_disconnect_by_func (wimax, wimax_nsp_remove_notify_cb, &info);
639 g_free (info.nsp_path);
640 g_free (expected_path);
642 g_object_unref (client);
643 g_clear_pointer (&sinfo, nmtstc_service_cleanup);
646 /*******************************************************************/
657 da_check_quit (DaInfo *info)
659 g_assert (info->quit_count > 0);
661 if (info->quit_count == 0) {
662 g_source_remove (info->quit_id);
664 g_main_loop_quit (info->loop);
669 da_device_added_cb (NMClient *c,
673 da_check_quit (info);
677 da_device_removed_cb (NMClient *c,
681 g_assert_cmpstr (nm_device_get_iface (device), ==, "eth0");
682 info->signaled = TRUE;
683 da_check_quit (info);
687 da_devices_notify_cb (NMClient *c,
691 const GPtrArray *devices;
696 devices = nm_client_get_devices (c);
698 g_assert_cmpint (devices->len, ==, 2);
700 for (i = 0; i < devices->len; i++) {
701 device = g_ptr_array_index (devices, i);
702 iface = nm_device_get_iface (device);
704 g_assert (!strcmp (iface, "wlan0") || !strcmp (iface, "eth1"));
707 info->notified = TRUE;
708 da_check_quit (info);
712 test_devices_array (void)
715 DaInfo info = { loop };
716 char *paths[3] = { NULL, NULL, NULL };
718 const GPtrArray *devices;
719 GError *error = NULL;
722 sinfo = nmtstc_service_init ();
723 client = nmtstc_nm_client_new ();
725 /*************************************/
726 /* Add some devices */
727 add_device ("AddWifiDevice", "wlan0", &paths[0]);
728 add_wired_device ("AddWiredDevice", "eth0", &paths[1]);
729 add_wired_device ("AddWiredDevice", "eth1", &paths[2]);
732 g_signal_connect (client,
734 (GCallback) da_device_added_cb,
737 /* Wait for libnm-glib to find the device */
738 info.quit_id = g_timeout_add_seconds (5, loop_quit, loop);
739 g_main_loop_run (loop);
741 g_assert_cmpint (info.quit_count, ==, 0);
742 g_signal_handlers_disconnect_by_func (client, da_device_added_cb, &info);
744 /* Ensure the devices now exist */
745 devices = nm_client_get_devices (client);
747 g_assert_cmpint (devices->len, ==, 3);
749 device = nm_client_get_device_by_iface (client, "wlan0");
750 g_assert (NM_IS_DEVICE_WIFI (device));
752 device = nm_client_get_device_by_iface (client, "eth0");
753 g_assert (NM_IS_DEVICE_ETHERNET (device));
755 device = nm_client_get_device_by_iface (client, "eth1");
756 g_assert (NM_IS_DEVICE_ETHERNET (device));
758 /********************************/
759 /* Now remove the device in the middle */
760 ret = g_dbus_proxy_call_sync (sinfo->proxy,
762 g_variant_new ("(o)", paths[1]),
763 G_DBUS_CALL_FLAGS_NO_AUTO_START,
767 g_assert_no_error (error);
769 g_variant_unref (ret);
771 g_signal_connect (client,
773 (GCallback) da_device_removed_cb,
776 g_signal_connect (client,
778 (GCallback) da_devices_notify_cb,
782 /* Wait for libnm-glib to find the device */
783 info.quit_id = g_timeout_add_seconds (5, loop_quit, loop);
784 g_main_loop_run (loop);
786 g_assert_cmpint (info.quit_count, ==, 0);
787 g_signal_handlers_disconnect_by_func (client, da_device_removed_cb, &info);
788 g_signal_handlers_disconnect_by_func (client, da_devices_notify_cb, &info);
790 /* Ensure only two are left */
791 devices = nm_client_get_devices (client);
793 g_assert_cmpint (devices->len, ==, 2);
795 device = nm_client_get_device_by_iface (client, "wlan0");
796 g_assert (NM_IS_DEVICE_WIFI (device));
798 device = nm_client_get_device_by_iface (client, "eth1");
799 g_assert (NM_IS_DEVICE_ETHERNET (device));
805 g_object_unref (client);
806 g_clear_pointer (&sinfo, nmtstc_service_cleanup);
810 manager_running_changed (GObject *client,
814 int *running_changed = user_data;
816 (*running_changed)++;
817 g_main_loop_quit (loop);
821 test_client_manager_running (void)
823 NMClient *client1, *client2;
825 int running_changed = 0;
826 GError *error = NULL;
828 client1 = nmtstc_nm_client_new ();
830 g_assert (!nm_client_get_manager_running (client1));
831 g_assert_cmpstr (nm_client_get_version (client1), ==, NULL);
833 g_assert (!nm_client_networking_get_enabled (client1));
834 /* This will have no effect, but it shouldn't cause any warnings either. */
835 nm_client_networking_set_enabled (client1, TRUE);
836 g_assert (!nm_client_networking_get_enabled (client1));
838 /* OTOH, this should result in an error */
839 nm_client_set_logging (client1, "DEFAULT", "INFO", &error);
840 g_assert_error (error, NM_CLIENT_ERROR, NM_CLIENT_ERROR_MANAGER_NOT_RUNNING);
841 g_clear_error (&error);
843 /* Now start the test service. */
844 sinfo = nmtstc_service_init ();
845 client2 = nmtstc_nm_client_new ();
847 /* client2 should know that NM is running, but the previously-created
848 * client1 hasn't gotten the news yet.
850 g_assert (!nm_client_get_manager_running (client1));
851 g_assert (nm_client_get_manager_running (client2));
853 g_signal_connect (client1, "notify::" NM_CLIENT_MANAGER_RUNNING,
854 G_CALLBACK (manager_running_changed), &running_changed);
855 quit_id = g_timeout_add_seconds (5, loop_quit, loop);
856 g_main_loop_run (loop);
857 g_assert_cmpint (running_changed, ==, 1);
858 g_assert (nm_client_get_manager_running (client1));
859 g_source_remove (quit_id);
862 g_clear_pointer (&sinfo, nmtstc_service_cleanup);
864 g_assert (nm_client_get_manager_running (client1));
866 quit_id = g_timeout_add_seconds (5, loop_quit, loop);
867 g_main_loop_run (loop);
868 g_assert_cmpint (running_changed, ==, 2);
869 g_assert (!nm_client_get_manager_running (client1));
870 g_source_remove (quit_id);
872 g_object_unref (client1);
873 g_object_unref (client2);
876 /*******************************************************************/
879 _slist_to_array (GPtrArray **connections, GSList *list)
885 *connections = array = g_ptr_array_new ();
887 array = *connections;
888 g_ptr_array_set_size (array, 0);
890 for (iter = list; iter; iter = iter->next)
891 g_ptr_array_add (array, iter->data);
897 _test_connection_invalid_find_connections (gpointer element, gpointer needle, gpointer user_data)
899 NMRemoteConnection *con = NM_REMOTE_CONNECTION (element);
900 const char *path = needle;
902 g_assert (NM_IS_REMOTE_CONNECTION (con));
903 g_assert (path && *path);
905 return strcmp (path, nm_connection_get_path ((NMConnection *) con)) == 0;
908 #define ASSERT_IDX(i) \
909 g_assert_cmpint (idx[i], >=, 0); \
910 g_assert (path##i && *path##i); \
911 g_assert (NM_IS_REMOTE_CONNECTION (connections->pdata[idx[i]])); \
912 g_assert_cmpstr (nm_connection_get_path (connections->pdata[idx[i]]), ==, path##i);
915 test_connection_invalid (void)
917 NMTSTC_SERVICE_INFO_SETUP (my_sinfo)
918 gs_unref_object NMConnection *connection = NULL;
919 NMSettingConnection *s_con;
920 gs_unref_object NMRemoteSettings *settings = NULL;
921 gs_unref_ptrarray GPtrArray *connections = NULL;
922 gs_free char *path0 = NULL;
923 gs_free char *path1 = NULL;
924 gs_free char *path2 = NULL;
925 gs_free char *uuid2 = NULL;
929 /**************************************************************************
930 * Add two connection before starting libnm. One valid, one invalid.
931 *************************************************************************/
933 connection = nmtst_create_minimal_connection ("test-connection-invalid-0", NULL, NM_SETTING_WIRED_SETTING_NAME, &s_con);
934 nmtst_connection_normalize (connection);
936 NM_SETTING_CONNECTION_UUID, nmtst_uuid_generate (),
938 nmtstc_service_add_connection (my_sinfo,
943 nm_connection_remove_setting (connection, NM_TYPE_SETTING_WIRED);
945 NM_SETTING_CONNECTION_ID, "test-connection-invalid-1",
946 NM_SETTING_CONNECTION_TYPE, "invalid-type-1",
947 NM_SETTING_CONNECTION_UUID, nmtst_uuid_generate (),
949 nmtstc_service_add_connection (my_sinfo,
954 nmtst_main_loop_run (loop, 100);
956 settings = nmtstc_nm_remote_settings_new ();
958 g_test_expect_message ("libnm-glib", G_LOG_LEVEL_WARNING, "*replace_settings: error updating connection*");
960 nmtst_main_loop_run (loop, 100);
962 g_test_assert_expected_messages ();
964 _slist_to_array (&connections, nm_remote_settings_list_connections (settings));
966 g_assert_cmpint (connections->len, ==, 2);
967 n_found = nmtst_find_all_indexes (connections->pdata,
969 (gpointer *) ((const char *[]) { path0, path1 }),
971 _test_connection_invalid_find_connections,
974 g_assert_cmpint (n_found, ==, 2);
977 nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[0]]);
978 nmtst_assert_connection_unnormalizable (connections->pdata[idx[1]], 0, 0);
980 /**************************************************************************
981 * After having the client up and running, add another invalid connection
982 *************************************************************************/
985 NM_SETTING_CONNECTION_ID, "test-connection-invalid-2",
986 NM_SETTING_CONNECTION_TYPE, "invalid-type-2",
987 NM_SETTING_CONNECTION_UUID, (uuid2 = g_strdup (nmtst_uuid_generate ())),
989 nmtstc_service_add_connection (my_sinfo,
994 g_test_expect_message ("libnm-glib", G_LOG_LEVEL_WARNING, "*replace_settings: error updating connection*");
996 nmtst_main_loop_run (loop, 100);
998 g_test_assert_expected_messages ();
1000 _slist_to_array (&connections, nm_remote_settings_list_connections (settings));
1002 g_assert_cmpint (connections->len, ==, 3);
1003 n_found = nmtst_find_all_indexes (connections->pdata,
1005 (gpointer *) ((const char *[]) { path0, path1, path2 }),
1007 _test_connection_invalid_find_connections,
1010 g_assert_cmpint (n_found, ==, 3);
1014 nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[0]]);
1015 nmtst_assert_connection_unnormalizable (connections->pdata[idx[1]], 0, 0);
1016 nmtst_assert_connection_unnormalizable (connections->pdata[idx[2]], 0, 0);
1018 /**************************************************************************
1019 * Modify the invalid connection. Connection disappears
1020 *************************************************************************/
1022 g_object_set (s_con,
1023 NM_SETTING_CONNECTION_ID, "test-connection-invalid-2x",
1025 nmtstc_service_update_connection (my_sinfo,
1030 g_test_expect_message ("libnm-glib", G_LOG_LEVEL_WARNING, "*replace_settings: error updating connection*");
1032 nmtst_main_loop_run (loop, 100);
1034 g_test_assert_expected_messages ();
1036 _slist_to_array (&connections, nm_remote_settings_list_connections (settings));
1038 g_assert_cmpint (connections->len, ==, 2);
1039 n_found = nmtst_find_all_indexes (connections->pdata,
1041 (gpointer *) ((const char *[]) { path0, path1, path2 }),
1043 _test_connection_invalid_find_connections,
1046 g_assert_cmpint (n_found, ==, 2);
1049 g_assert_cmpint (idx[2], ==, -1);
1050 nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[0]]);
1051 nmtst_assert_connection_unnormalizable (connections->pdata[idx[1]], 0, 0);
1053 /**************************************************************************
1054 * Modify the invalid connection again. Note that the connection stays
1055 * invisible (although it exists, and is valid).
1056 *************************************************************************/
1058 g_clear_object (&connection);
1059 connection = nmtst_create_minimal_connection ("test-connection-invalid-2", NULL, NM_SETTING_WIRED_SETTING_NAME, &s_con);
1060 nmtst_connection_normalize (connection);
1061 g_object_set (s_con,
1062 NM_SETTING_CONNECTION_ID, "test-connection-invalid-2z",
1063 NM_SETTING_CONNECTION_TYPE, "802-3-ethernet",
1064 NM_SETTING_CONNECTION_UUID, uuid2,
1067 nmtstc_service_update_connection (my_sinfo,
1072 nmtst_main_loop_run (loop, 100);
1074 _slist_to_array (&connections, nm_remote_settings_list_connections (settings));
1076 g_assert_cmpint (connections->len, ==, 2);
1077 n_found = nmtst_find_all_indexes (connections->pdata,
1079 (gpointer *) ((const char *[]) { path0, path1, path2 }),
1081 _test_connection_invalid_find_connections,
1084 g_assert_cmpint (n_found, ==, 2);
1087 g_assert_cmpint (idx[2], ==, -1);
1088 nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[0]]);
1089 nmtst_assert_connection_unnormalizable (connections->pdata[idx[1]], 0, 0);
1092 /**************************************************************************
1093 * Modify the invalid connection and make it valid
1094 *************************************************************************/
1096 g_clear_object (&connection);
1097 connection = nmtst_create_minimal_connection ("test-connection-invalid-1", NULL, NM_SETTING_WIRED_SETTING_NAME, &s_con);
1098 nmtst_connection_normalize (connection);
1099 g_object_set (s_con,
1100 NM_SETTING_CONNECTION_ID, "test-connection-invalid-1x",
1101 NM_SETTING_CONNECTION_TYPE, "802-3-ethernet",
1102 NM_SETTING_CONNECTION_UUID, nm_connection_get_uuid (connections->pdata[idx[1]]),
1105 nmtstc_service_update_connection (my_sinfo,
1110 nmtst_main_loop_run (loop, 100);
1112 _slist_to_array (&connections, nm_remote_settings_list_connections (settings));
1114 g_assert_cmpint (connections->len, ==, 2);
1115 n_found = nmtst_find_all_indexes (connections->pdata,
1117 (gpointer *) ((const char *[]) { path0, path1, path2 }),
1119 _test_connection_invalid_find_connections,
1122 g_assert_cmpint (n_found, ==, 2);
1125 g_assert_cmpint (idx[2], ==, -1);
1126 nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[0]]);
1127 nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[1]]);
1128 g_assert_cmpstr ("test-connection-invalid-1x", ==, nm_connection_get_id (connections->pdata[idx[1]]));
1133 /*******************************************************************/
1138 main (int argc, char **argv)
1140 nmtst_init (&argc, &argv, TRUE);
1142 loop = g_main_loop_new (NULL, FALSE);
1144 g_test_add_func ("/libnm-glib/device-added", test_device_added);
1145 g_test_add_func ("/libnm-glib/wifi-ap-added-removed", test_wifi_ap_added_removed);
1146 g_test_add_func ("/libnm-glib/wimax-nsp-added-removed", test_wimax_nsp_added_removed);
1147 g_test_add_func ("/libnm-glib/devices-array", test_devices_array);
1148 g_test_add_func ("/libnm-glib/client-manager-running", test_client_manager_running);
1149 g_test_add_func ("/libnm/connection/invalid", test_connection_invalid);
1151 return g_test_run ();