diff --git a/Makefile.am b/Makefile.am index a86bf9029d..25ea649484 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1172,6 +1172,7 @@ src_libnm_core_impl_lib_h_pub_real = \ src/libnm-core-public/nm-setting-8021x.h \ src/libnm-core-public/nm-setting-adsl.h \ src/libnm-core-public/nm-setting-bluetooth.h \ + src/libnm-core-public/nm-setting-bond-port.h \ src/libnm-core-public/nm-setting-bond.h \ src/libnm-core-public/nm-setting-bridge-port.h \ src/libnm-core-public/nm-setting-bridge.h \ @@ -1252,6 +1253,7 @@ src_libnm_core_impl_lib_c_settings_real = \ src/libnm-core-impl/nm-setting-8021x.c \ src/libnm-core-impl/nm-setting-adsl.c \ src/libnm-core-impl/nm-setting-bluetooth.c \ + src/libnm-core-impl/nm-setting-bond-port.c \ src/libnm-core-impl/nm-setting-bond.c \ src/libnm-core-impl/nm-setting-bridge-port.c \ src/libnm-core-impl/nm-setting-bridge.c \ @@ -3412,6 +3414,7 @@ EXTRA_DIST += \ src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bond-eth-type \ src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bond-main \ src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bond-mode-numeric \ + src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bond-port \ src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bond-slave \ src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bond-slave-ib \ src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bridge-component \ @@ -5084,12 +5087,14 @@ src_nmtui_nmtui_SOURCES = \ src/nmtui/nmt-mac-entry.h \ src/nmtui/nmt-mtu-entry.c \ src/nmtui/nmt-mtu-entry.h \ + src/nmtui/nmt-page-bond-port.c \ + src/nmtui/nmt-page-bond-port.h \ src/nmtui/nmt-page-bond.c \ src/nmtui/nmt-page-bond.h \ - src/nmtui/nmt-page-bridge.c \ - src/nmtui/nmt-page-bridge.h \ src/nmtui/nmt-page-bridge-port.c \ src/nmtui/nmt-page-bridge-port.h \ + src/nmtui/nmt-page-bridge.c \ + src/nmtui/nmt-page-bridge.h \ src/nmtui/nmt-page-dsl.c \ src/nmtui/nmt-page-dsl.h \ src/nmtui/nmt-page-ethernet.c \ @@ -5104,10 +5109,10 @@ src_nmtui_nmtui_SOURCES = \ src/nmtui/nmt-page-ip6.h \ src/nmtui/nmt-page-ppp.c \ src/nmtui/nmt-page-ppp.h \ - src/nmtui/nmt-page-team.c \ - src/nmtui/nmt-page-team.h \ src/nmtui/nmt-page-team-port.c \ src/nmtui/nmt-page-team-port.h \ + src/nmtui/nmt-page-team.c \ + src/nmtui/nmt-page-team.h \ src/nmtui/nmt-page-vlan.c \ src/nmtui/nmt-page-vlan.h \ src/nmtui/nmt-page-wifi.c \ @@ -5126,12 +5131,12 @@ src_nmtui_nmtui_SOURCES = \ src/nmtui/nmt-route-table.h \ src/nmtui/nmt-slave-list.c \ src/nmtui/nmt-slave-list.h \ - src/nmtui/nmt-wireguard-peer-list.c \ - src/nmtui/nmt-wireguard-peer-list.h \ - src/nmtui/nmt-wireguard-peer-editor.c \ - src/nmtui/nmt-wireguard-peer-editor.h \ src/nmtui/nmt-utils.c \ src/nmtui/nmt-utils.h \ + src/nmtui/nmt-wireguard-peer-editor.c \ + src/nmtui/nmt-wireguard-peer-editor.h \ + src/nmtui/nmt-wireguard-peer-list.c \ + src/nmtui/nmt-wireguard-peer-list.h \ src/nmtui/nmt-widget-list.c \ src/nmtui/nmt-widget-list.h \ $(NULL) diff --git a/docs/libnm/libnm-docs.xml b/docs/libnm/libnm-docs.xml index fad9552283..e9811c1485 100644 --- a/docs/libnm/libnm-docs.xml +++ b/docs/libnm/libnm-docs.xml @@ -315,6 +315,7 @@ print ("NetworkManager version " + client.get_version())]]> + @@ -326,20 +327,20 @@ print ("NetworkManager version " + client.get_version())]]> - - + + - + + - diff --git a/po/POTFILES.in b/po/POTFILES.in index 597035e6f6..0cd24d9940 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -83,6 +83,7 @@ src/libnm-core-impl/nm-setting-6lowpan.c src/libnm-core-impl/nm-setting-8021x.c src/libnm-core-impl/nm-setting-adsl.c src/libnm-core-impl/nm-setting-bluetooth.c +src/libnm-core-impl/nm-setting-bond-port.c src/libnm-core-impl/nm-setting-bond.c src/libnm-core-impl/nm-setting-bridge-port.c src/libnm-core-impl/nm-setting-bridge.c @@ -159,6 +160,7 @@ src/nmtui/nmt-edit-connection-list.c src/nmtui/nmt-editor-section.c src/nmtui/nmt-editor.c src/nmtui/nmt-mtu-entry.c +src/nmtui/nmt-page-bond-port.c src/nmtui/nmt-page-bond.c src/nmtui/nmt-page-bridge-port.c src/nmtui/nmt-page-bridge.c @@ -179,9 +181,9 @@ src/nmtui/nmt-password-fields.c src/nmtui/nmt-route-editor.c src/nmtui/nmt-route-table.c src/nmtui/nmt-slave-list.c -src/nmtui/nmt-wireguard-peer-list.c -src/nmtui/nmt-wireguard-peer-editor.c src/nmtui/nmt-widget-list.c +src/nmtui/nmt-wireguard-peer-editor.c +src/nmtui/nmt-wireguard-peer-list.c src/nmtui/nmtui-connect.c src/nmtui/nmtui-edit.c src/nmtui/nmtui-hostname.c diff --git a/src/core/devices/nm-device-bond.c b/src/core/devices/nm-device-bond.c index 5222381d3a..f7d78f57b7 100644 --- a/src/core/devices/nm-device-bond.c +++ b/src/core/devices/nm-device-bond.c @@ -17,6 +17,7 @@ #include "libnm-core-aux-intern/nm-libnm-core-utils.h" #include "libnm-core-intern/nm-core-internal.h" #include "nm-ip4-config.h" +#include "nm-setting-bond-port.h" #define _NMLOG_DEVICE_TYPE NMDeviceBond #include "nm-device-logging.h" @@ -215,11 +216,29 @@ update_connection(NMDevice *device, NMConnection *connection) } static gboolean -master_update_slave_connection(NMDevice * self, - NMDevice * slave, - NMConnection *connection, - GError ** error) +controller_update_port_connection(NMDevice * self, + NMDevice * port, + NMConnection *connection, + GError ** error) { + NMSettingBondPort *s_port; + int ifindex_port = nm_device_get_ifindex(port); + uint queue_id = NM_BOND_PORT_QUEUE_ID_DEF; + gs_free char * queue_id_str = NULL; + + g_return_val_if_fail(ifindex_port > 0, FALSE); + + s_port = _nm_connection_ensure_setting(connection, NM_TYPE_SETTING_BOND_PORT); + + queue_id_str = + nm_platform_sysctl_slave_get_option(nm_device_get_platform(self), ifindex_port, "queue_id"); + if (queue_id_str) { + queue_id = + _nm_utils_ascii_str_to_int64(queue_id_str, 10, 0, 65535, NM_BOND_PORT_QUEUE_ID_DEF); + g_object_set(s_port, NM_SETTING_BOND_PORT_QUEUE_ID, queue_id, NULL); + } else + _LOGW(LOGD_BOND, "failed to read bond port setting '%s'", NM_SETTING_BOND_PORT_QUEUE_ID); + g_object_set(nm_connection_get_setting_connection(connection), NM_SETTING_CONNECTION_MASTER, nm_device_get_iface(self), @@ -384,30 +403,57 @@ act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason) return ret; } -static gboolean -enslave_slave(NMDevice *device, NMDevice *slave, NMConnection *connection, gboolean configure) +static void +commit_port_options(NMDevice *bond_device, NMDevice *port, NMSettingBondPort *s_port) { - NMDeviceBond *self = NM_DEVICE_BOND(device); + char queue_id_str[IFNAMSIZ + NM_STRLEN(":") + 5 + 100]; - nm_device_master_check_slave_physical_port(device, slave, LOGD_BOND); + /* + * The queue-id of bond port is read only, we should modify bond interface using: + * echo "eth1:2" > /sys/class/net/bond0/bonding/queue_id + * Kernel allows parital editing, so no need to care about other bond ports. + */ + g_snprintf(queue_id_str, + sizeof(queue_id_str), + "%s:%" G_GUINT32_FORMAT, + nm_device_get_iface(port), + s_port ? nm_setting_bond_port_get_queue_id(s_port) : NM_BOND_PORT_QUEUE_ID_DEF); + + nm_platform_sysctl_master_set_option(nm_device_get_platform(bond_device), + nm_device_get_ifindex(bond_device), + "queue_id", + queue_id_str); +} + +static gboolean +enslave_slave(NMDevice *device, NMDevice *port, NMConnection *connection, gboolean configure) +{ + NMDeviceBond * self = NM_DEVICE_BOND(device); + NMSettingBondPort *s_port; + + nm_device_master_check_slave_physical_port(device, port, LOGD_BOND); if (configure) { gboolean success; - nm_device_take_down(slave, TRUE); + nm_device_take_down(port, TRUE); success = nm_platform_link_enslave(nm_device_get_platform(device), nm_device_get_ip_ifindex(device), - nm_device_get_ip_ifindex(slave)); - nm_device_bring_up(slave, TRUE, NULL); + nm_device_get_ip_ifindex(port)); + nm_device_bring_up(port, TRUE, NULL); if (!success) { - _LOGI(LOGD_BOND, "enslaved bond slave %s: failed", nm_device_get_ip_iface(slave)); + _LOGI(LOGD_BOND, "assigning bond port %s: failed", nm_device_get_ip_iface(port)); return FALSE; } - _LOGI(LOGD_BOND, "enslaved bond slave %s", nm_device_get_ip_iface(slave)); + s_port = _nm_connection_get_setting(connection, NM_TYPE_SETTING_BOND_PORT); + + commit_port_options(device, port, s_port); + + _LOGI(LOGD_BOND, "assigned bond port %s", nm_device_get_ip_iface(port)); } else - _LOGI(LOGD_BOND, "bond slave %s was enslaved", nm_device_get_ip_iface(slave)); + _LOGI(LOGD_BOND, "bond port %s was assigned", nm_device_get_ip_iface(port)); return TRUE; } @@ -613,7 +659,7 @@ nm_device_bond_class_init(NMDeviceBondClass *klass) device_class->complete_connection = complete_connection; device_class->update_connection = update_connection; - device_class->master_update_slave_connection = master_update_slave_connection; + device_class->master_update_slave_connection = controller_update_port_connection; device_class->create_and_realize = create_and_realize; device_class->act_stage1_prepare = act_stage1_prepare; diff --git a/src/core/dhcp/nm-dhcp-dhclient-utils.c b/src/core/dhcp/nm-dhcp-dhclient-utils.c index 3ea481c385..341ac7b2fa 100644 --- a/src/core/dhcp/nm-dhcp-dhclient-utils.c +++ b/src/core/dhcp/nm-dhcp-dhclient-utils.c @@ -282,7 +282,7 @@ read_interface(const char *line, char *interface, guint size) if (ptr[0] == '\0' || strlen(ptr) + 1 > size) return FALSE; - snprintf(interface, size, "%s", ptr); + g_snprintf(interface, size, "%s", ptr); return TRUE; } diff --git a/src/core/platform/tests/test-link.c b/src/core/platform/tests/test-link.c index 69e4846d6f..88049092da 100644 --- a/src/core/platform/tests/test-link.c +++ b/src/core/platform/tests/test-link.c @@ -1494,7 +1494,7 @@ test_software_detect(gconstpointer user_data) * The fix (17af2bce) is included kernel 4.7, dated 24 July, 2016. */ for (i = ifindex_parent + 1; i < ifindex_parent + 100; i++) { - snprintf(buf, sizeof(buf), "/sys/class/macvtap/tap%d", i); + g_snprintf(buf, sizeof(buf), "/sys/class/macvtap/tap%d", i); if (!g_file_test(buf, G_FILE_TEST_IS_SYMLINK)) break; diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c index aaf11777cd..f48b04e2df 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c @@ -31,6 +31,7 @@ #include "nm-setting-ethtool.h" #include "nm-setting-8021x.h" #include "nm-setting-bond.h" +#include "nm-setting-bond-port.h" #include "nm-setting-team.h" #include "nm-setting-team-port.h" #include "nm-setting-bridge.h" @@ -5493,6 +5494,31 @@ make_bond_setting(shvarFile *ifcfg, const char *file, GError **error) return (NMSetting *) s_bond; } +static NMSetting * +make_bond_port_setting(shvarFile *ifcfg) +{ + NMSetting * s_port = NULL; + gs_free char *value_to_free = NULL; + const char * value; + guint queue_id; + + g_return_val_if_fail(ifcfg != NULL, FALSE); + + value = svGetValue(ifcfg, "BOND_PORT_QUEUE_ID", &value_to_free); + if (value) { + s_port = nm_setting_bond_port_new(); + queue_id = + _nm_utils_ascii_str_to_uint64(value, 10, 0, G_MAXUINT16, NM_BOND_PORT_QUEUE_ID_DEF); + if (errno != 0) { + PARSE_WARNING("Invalid bond port queue_id value '%s'", value); + return s_port; + } + g_object_set(G_OBJECT(s_port), NM_SETTING_BOND_PORT_QUEUE_ID, queue_id, NULL); + } + + return s_port; +} + static NMConnection * bond_connection_from_ifcfg(const char *file, shvarFile *ifcfg, GError **error) { @@ -6660,6 +6686,10 @@ connection_from_file_full(const char *filename, if (setting) nm_connection_add_setting(connection, setting); + setting = make_bond_port_setting(main_ifcfg); + if (setting) + nm_connection_add_setting(connection, setting); + setting = make_team_port_setting(main_ifcfg); if (setting) nm_connection_add_setting(connection, setting); diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c index febfc120c1..7ae6a94555 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c @@ -827,6 +827,7 @@ const NMSIfcfgKeyTypeInfo nms_ifcfg_well_known_keys[] = { _KEY_TYPE("BAND", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("BONDING_MASTER", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("BONDING_OPTS", NMS_IFCFG_KEY_TYPE_IS_PLAIN), + _KEY_TYPE("BOND_PORT_QUEUE_ID", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("BOOTPROTO", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("BRIDGE", NMS_IFCFG_KEY_TYPE_IS_PLAIN), _KEY_TYPE("BRIDGE_MACADDR", NMS_IFCFG_KEY_TYPE_IS_PLAIN), diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h index b7751ec96c..2b16668c75 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h @@ -33,7 +33,7 @@ typedef struct { NMSIfcfgKeyTypeFlags key_flags; } NMSIfcfgKeyTypeInfo; -extern const NMSIfcfgKeyTypeInfo nms_ifcfg_well_known_keys[251]; +extern const NMSIfcfgKeyTypeInfo nms_ifcfg_well_known_keys[252]; const NMSIfcfgKeyTypeInfo *nms_ifcfg_well_known_key_find_info(const char *key, gssize *out_idx); diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c index 4510576811..0ef2f3e5dc 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c @@ -19,6 +19,7 @@ #include "libnm-glib-aux/nm-str-buf.h" #include "libnm-glib-aux/nm-io-utils.h" #include "nm-manager.h" +#include "nm-setting-bond-port.h" #include "nm-setting-connection.h" #include "nm-setting-wired.h" #include "nm-setting-wireless.h" @@ -1888,6 +1889,16 @@ write_bridge_port_setting(NMConnection *connection, shvarFile *ifcfg, GError **e return TRUE; } +static void +write_bond_port_setting(NMConnection *connection, shvarFile *ifcfg) +{ + NMSettingBondPort *s_port; + + s_port = _nm_connection_get_setting(connection, NM_TYPE_SETTING_BOND_PORT); + if (s_port) + svSetValueInt64(ifcfg, "BOND_PORT_QUEUE_ID", nm_setting_bond_port_get_queue_id(s_port)); +} + static gboolean write_team_port_setting(NMConnection *connection, shvarFile *ifcfg, GError **error) { @@ -3370,6 +3381,8 @@ do_write_construct(NMConnection * connection, if (!write_bridge_port_setting(connection, ifcfg, error)) return FALSE; + write_bond_port_setting(connection, ifcfg); + if (!write_team_port_setting(connection, ifcfg, error)) return FALSE; diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bond-port b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bond-port new file mode 100644 index 0000000000..111924c0b0 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bond-port @@ -0,0 +1,9 @@ +TYPE=Ethernet +NAME=eth0 +UUID=43737e70-7c4f-4b67-9f4f-6d2d4747b1ff +DEVICE=eth0 +ONBOOT=yes +LLDP=no +MASTER=bond99 +SLAVE=yes +BOND_PORT_QUEUE_ID=1 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index bc34ec124a..09ab88b6dc 100644 --- a/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -167,9 +167,8 @@ _assert_expected_content(NMConnection *connection, const char *filename, const c g_string_erase(str, i, NM_STRLEN("${UUID}")); g_string_insert_len(str, i, uuid, j); - g_free(content_expectd); - len_expectd = str->len; - content_expectd = g_string_free(str, FALSE); + len_expectd = str->len; + nm_strdup_reset_take(&content_expectd, g_string_free(str, FALSE)); i += j; continue; } @@ -344,7 +343,7 @@ _writer_new_connection_reread(NMConnection * connection, { gboolean success; GError * error = NULL; - char * filename = NULL; + gs_free char * filename = NULL; gs_unref_object NMConnection *con_verified = NULL; gs_unref_object NMConnection *reread_copy = NULL; NMConnection **reread = out_reread ?: ((nmtst_get_rand_uint32() % 2) ? &reread_copy : NULL); @@ -372,11 +371,9 @@ _writer_new_connection_reread(NMConnection * connection, _assert_expected_content(con_verified, filename, expected); if (out_filename) - *out_filename = filename; - else { + *out_filename = g_steal_pointer(&filename); + else nmtst_file_unlink(filename); - g_free(filename); - } } static void @@ -467,12 +464,10 @@ test_read_netmask_1(void) connection = _connection_from_file(FILENAME, NULL, TYPE_ETHERNET, NULL); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System netmask-1"); - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpuint(nm_setting_ip_config_get_num_dns(s_ip4), ==, 1); ip4_addr = nm_setting_ip_config_get_address(s_ip4, 0); g_assert(ip4_addr); @@ -501,12 +496,12 @@ verify_cert_or_key(NMSetting8021x *s_compare, const char * privkey_password, const char * property) { - NMSetting8021x * s_8021x; - GError * error = NULL; - gboolean success = FALSE; - const char * expected = NULL, *setting = NULL; - gboolean phase2 = FALSE; - NMSetting8021xCKScheme scheme = NM_SETTING_802_1X_CK_SCHEME_UNKNOWN; + gs_unref_object NMSetting8021x *s_8021x = NULL; + GError * error = NULL; + gboolean success = FALSE; + const char * expected = NULL, *setting = NULL; + gboolean phase2 = FALSE; + NMSetting8021xCKScheme scheme = NM_SETTING_802_1X_CK_SCHEME_UNKNOWN; if (strstr(property, "phase2")) phase2 = TRUE; @@ -615,28 +610,24 @@ verify_cert_or_key(NMSetting8021x *s_compare, setting = nm_setting_802_1x_get_private_key_path(s_compare); } g_assert_cmpstr(setting, ==, expected); - - g_object_unref(s_8021x); return TRUE; } static void test_read_basic(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - const char * mac; - char expected_mac_address[ETH_ALEN] = {0x00, 0x16, 0x41, 0x11, 0x22, 0x33}; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + const char * mac; + char expected_mac_address[ETH_ALEN] = {0x00, 0x16, 0x41, 0x11, 0x22, 0x33}; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-minimal", NULL, TYPE_ETHERNET, NULL); - /* ===== CONNECTION SETTING ===== */ - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-minimal"); g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, 0); g_assert(nm_setting_connection_get_autoconnect(s_con)); @@ -647,47 +638,38 @@ test_read_basic(void) * depending on where the tests are run. */ - /* ===== WIRED SETTING ===== */ - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); + s_wired = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); g_assert_cmpint(nm_setting_wired_get_mtu(s_wired), ==, 0); - /* MAC address */ mac = nm_setting_wired_get_mac_address(s_wired); g_assert(mac); g_assert(nm_utils_hwaddr_matches(mac, -1, expected_mac_address, ETH_ALEN)); - /* ===== IPv4 SETTING ===== */ - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_DISABLED); g_assert(nm_setting_ip_config_get_never_default(s_ip4) == FALSE); - /* ===== IPv6 SETTING ===== */ - s_ip6 = nm_connection_get_setting_ip6_config(connection); - g_assert(s_ip6); + s_ip6 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_IGNORE); g_assert(nm_setting_ip_config_get_never_default(s_ip6) == FALSE); - - g_object_unref(connection); } static void test_read_miscellaneous_variables(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - char * expected_mac_blacklist[3] = {"00:16:41:11:22:88", + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + char * expected_mac_blacklist[3] = {"00:16:41:11:22:88", "00:16:41:11:22:99", "6a:5d:5a:fa:dd:f0"}; - int mac_blacklist_num, i; - guint64 expected_timestamp = 0; + int mac_blacklist_num, i; + guint64 expected_timestamp = 0; NMTST_EXPECT_NM_WARN("*invalid MAC in HWADDR_BLACKLIST 'XX:aa:invalid'*"); connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-misc-variables", @@ -696,19 +678,14 @@ test_read_miscellaneous_variables(void) NULL); g_test_assert_expected_messages(); - /* ===== CONNECTION SETTING ===== */ - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, expected_timestamp); g_assert(nm_setting_connection_get_autoconnect(s_con)); g_assert_cmpint(nm_setting_connection_get_autoconnect_retries(s_con), ==, 100); - /* ===== WIRED SETTING ===== */ - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); + s_wired = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); g_assert_cmpint(nm_setting_wired_get_mtu(s_wired), ==, 0); - /* MAC blacklist */ mac_blacklist_num = nm_setting_wired_get_num_mac_blacklist_items(s_wired); g_assert_cmpint(mac_blacklist_num, ==, 3); for (i = 0; i < mac_blacklist_num; i++) @@ -717,26 +694,22 @@ test_read_miscellaneous_variables(void) expected_mac_blacklist[i], -1)); - /* ===== IPv4 SETTING ===== */ - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_DISABLED); g_assert(nm_setting_ip_config_get_never_default(s_ip4) == FALSE); - - g_object_unref(connection); } static void test_read_variables_corner_cases(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - const char * mac; - char expected_mac_address[ETH_ALEN] = {0x00, 0x16, 0x41, 0x11, 0x22, 0x33}; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + const char * mac; + char expected_mac_address[ETH_ALEN] = {0x00, 0x16, 0x41, 0x11, 0x22, 0x33}; NMTST_EXPECT_NM_WARN("*key NAME is badly quoted and is treated as \"\"*"); NMTST_EXPECT_NM_WARN("*key ZONE is badly quoted and is treated as \"\"*"); @@ -746,9 +719,7 @@ test_read_variables_corner_cases(void) NULL); g_test_assert_expected_messages(); - /* ===== CONNECTION SETTING ===== */ - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-variables-corner-cases-1"); @@ -756,34 +727,27 @@ test_read_variables_corner_cases(void) g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, 0); g_assert(nm_setting_connection_get_autoconnect(s_con)); - /* ===== WIRED SETTING ===== */ - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); + s_wired = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); g_assert_cmpint(nm_setting_wired_get_mtu(s_wired), ==, 0); - /* MAC address */ mac = nm_setting_wired_get_mac_address(s_wired); g_assert(mac); g_assert(nm_utils_hwaddr_matches(mac, -1, expected_mac_address, ETH_ALEN)); - /* ===== IPv4 SETTING ===== */ - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_DISABLED); g_assert(nm_setting_ip_config_get_never_default(s_ip4) == FALSE); - - g_object_unref(connection); } static void test_read_unmanaged(void) { - NMConnection * connection; - NMSettingConnection *s_con; - char * unhandled_spec = NULL; - guint64 expected_timestamp = 0; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + gs_free char * unhandled_spec = NULL; + guint64 expected_timestamp = 0; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-nm-controlled", NULL, @@ -791,24 +755,19 @@ test_read_unmanaged(void) &unhandled_spec); g_assert_cmpstr(unhandled_spec, ==, "unmanaged:mac:00:11:22:33:f8:9f"); - /* ===== CONNECTION SETTING ===== */ - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-nm-controlled"); g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, expected_timestamp); g_assert(nm_setting_connection_get_autoconnect(s_con)); - - g_free(unhandled_spec); - g_object_unref(connection); } static void test_read_unmanaged_unrecognized(void) { - NMConnection * connection; - NMSettingConnection *s_con; - gs_free char * unhandled_spec = NULL; - guint64 expected_timestamp = 0; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + gs_free char * unhandled_spec = NULL; + guint64 expected_timestamp = 0; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-nm-controlled-unrecognized", NULL, @@ -816,22 +775,18 @@ test_read_unmanaged_unrecognized(void) &unhandled_spec); g_assert_cmpstr(unhandled_spec, ==, "unmanaged:interface-name:=ipoac0"); - /* ===== CONNECTION SETTING ===== */ - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "PigeonNet"); g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, expected_timestamp); - - g_object_unref(connection); } static void test_read_unrecognized(void) { - NMConnection * connection; - NMSettingConnection *s_con; - gs_free char * unhandled_spec = NULL; - guint64 expected_timestamp = 0; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + gs_free char * unhandled_spec = NULL; + guint64 expected_timestamp = 0; NMTST_EXPECT_NM_WARN("*key NAME is badly quoted and is treated as \"\"*"); connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-unrecognized", @@ -841,30 +796,26 @@ test_read_unrecognized(void) g_test_assert_expected_messages(); g_assert_cmpstr(unhandled_spec, ==, "unrecognized:mac:00:11:22:33"); - /* ===== CONNECTION SETTING ===== */ - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-unrecognized"); g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, expected_timestamp); - - g_object_unref(connection); } static void test_read_wired_static(gconstpointer test_data) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - char * unmanaged = NULL; - const char * mac; - char expected_mac_address[ETH_ALEN] = {0x00, 0x11, 0x22, 0x33, 0x44, 0xee}; - NMIPAddress * ip4_addr; - NMIPAddress * ip6_addr; - const char * file, *expected_id; - gpointer expect_ip6_p; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + char * unmanaged = NULL; + const char * mac; + char expected_mac_address[ETH_ALEN] = {0x00, 0x11, 0x22, 0x33, 0x44, 0xee}; + NMIPAddress *ip4_addr; + NMIPAddress *ip6_addr; + const char * file, *expected_id; + gpointer expect_ip6_p; nmtst_test_data_unpack(test_data, &file, &expected_id, &expect_ip6_p); @@ -873,26 +824,19 @@ test_read_wired_static(gconstpointer test_data) connection = _connection_from_file(file, NULL, TYPE_ETHERNET, &unmanaged); g_assert_cmpstr(unmanaged, ==, NULL); - /* ===== CONNECTION SETTING ===== */ - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, expected_id); g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, 0); g_assert(nm_setting_connection_get_autoconnect(s_con)); - /* ===== WIRED SETTING ===== */ - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); + s_wired = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); g_assert_cmpint(nm_setting_wired_get_mtu(s_wired), ==, 1492); - /* MAC address */ mac = nm_setting_wired_get_mac_address(s_wired); g_assert(mac); g_assert(nm_utils_hwaddr_matches(mac, -1, expected_mac_address, ETH_ALEN)); - /* ===== IPv4 SETTING ===== */ - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL); @@ -901,24 +845,19 @@ test_read_wired_static(gconstpointer test_data) g_assert(nm_setting_ip_config_has_dns_options(s_ip4)); g_assert_cmpint(nm_setting_ip_config_get_num_dns_options(s_ip4), ==, 0); - /* DNS Addresses */ g_assert_cmpint(nm_setting_ip_config_get_num_dns(s_ip4), ==, 2); g_assert_cmpstr(nm_setting_ip_config_get_dns(s_ip4, 0), ==, "4.2.2.1"); g_assert_cmpstr(nm_setting_ip_config_get_dns(s_ip4, 1), ==, "4.2.2.2"); - /* IP addresses */ g_assert_cmpint(nm_setting_ip_config_get_num_addresses(s_ip4), ==, 1); ip4_addr = nm_setting_ip_config_get_address(s_ip4, 0); g_assert(ip4_addr); g_assert_cmpint(nm_ip_address_get_prefix(ip4_addr), ==, 24); g_assert_cmpstr(nm_ip_address_get_address(ip4_addr), ==, "192.168.1.5"); - /* Gateway */ g_assert_cmpstr(nm_setting_ip_config_get_gateway(s_ip4), ==, "192.168.1.1"); - /* ===== IPv6 SETTING ===== */ - s_ip6 = nm_connection_get_setting_ip6_config(connection); - g_assert(s_ip6); + s_ip6 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); if (GPOINTER_TO_INT(expect_ip6_p)) { g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), ==, @@ -951,19 +890,18 @@ test_read_wired_static(gconstpointer test_data) NM_SETTING_IP6_CONFIG_METHOD_IGNORE); g_assert(!nm_setting_ip_config_has_dns_options(s_ip6)); } - - g_object_unref(connection); } static void test_read_wired_static_no_prefix(gconstpointer user_data) { - guint32 expected_prefix = GPOINTER_TO_UINT(user_data); - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingIPConfig * s_ip4; - NMIPAddress * ip4_addr; - char * file, *expected_id; + guint32 expected_prefix = GPOINTER_TO_UINT(user_data); + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + NMIPAddress * ip4_addr; + gs_free char * file = NULL; + gs_free char * expected_id = NULL; file = g_strdup_printf(TEST_IFCFG_DIR "/ifcfg-test-wired-static-no-prefix-%u", expected_prefix); expected_id = g_strdup_printf("System test-wired-static-no-prefix-%u", expected_prefix); @@ -972,14 +910,10 @@ test_read_wired_static_no_prefix(gconstpointer user_data) connection = _connection_from_file(file, NULL, TYPE_ETHERNET, NULL); g_test_assert_expected_messages(); - /* ===== CONNECTION SETTING ===== */ - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, expected_id); - /* ===== IPv4 SETTING ===== */ - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL); @@ -991,23 +925,19 @@ test_read_wired_static_no_prefix(gconstpointer user_data) ip4_addr = nm_setting_ip_config_get_address(s_ip4, 0); g_assert(ip4_addr); g_assert_cmpint(nm_ip_address_get_prefix(ip4_addr), ==, expected_prefix); - - g_free(file); - g_free(expected_id); - g_object_unref(connection); } static void test_read_wired_dhcp(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - char * unmanaged = NULL; - char expected_mac_address[ETH_ALEN] = {0x00, 0x11, 0x22, 0x33, 0x44, 0xee}; - const char * mac; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + char * unmanaged = NULL; + char expected_mac_address[ETH_ALEN] = {0x00, 0x11, 0x22, 0x33, 0x44, 0xee}; + const char *mac; NMTST_EXPECT_NM_WARN("*key IPV6INIT is duplicated and the early occurrence ignored*"); connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-dhcp", @@ -1017,25 +947,18 @@ test_read_wired_dhcp(void) g_test_assert_expected_messages(); g_assert(unmanaged == NULL); - /* ===== CONNECTION SETTING ===== */ - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-wired-dhcp"); g_assert_cmpuint(nm_setting_connection_get_timestamp(s_con), ==, 0); g_assert(nm_setting_connection_get_autoconnect(s_con)); - /* ===== WIRED SETTING ===== */ - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); + s_wired = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); - /* MAC address */ mac = nm_setting_wired_get_mac_address(s_wired); g_assert(mac); g_assert(nm_utils_hwaddr_matches(mac, -1, expected_mac_address, sizeof(expected_mac_address))); - /* ===== IPv4 SETTING ===== */ - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); g_assert_cmpstr(nm_setting_ip4_config_get_dhcp_fqdn(NM_SETTING_IP4_CONFIG(s_ip4)), ==, @@ -1048,35 +971,29 @@ test_read_wired_dhcp(void) ==, NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED | NM_DHCP_HOSTNAME_FLAG_FQDN_NO_UPDATE); - /* ===== IPv6 SETTING ===== */ - s_ip6 = nm_connection_get_setting_ip6_config(connection); - g_assert(s_ip6); + s_ip6 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_DHCP); g_assert_cmpstr(nm_setting_ip_config_get_dhcp_hostname(s_ip6), ==, "foo.bar"); g_assert_cmpuint(nm_setting_ip_config_get_dhcp_hostname_flags(s_ip6), ==, NM_DHCP_HOSTNAME_FLAG_FQDN_CLEAR_FLAGS); - - g_object_unref(connection); } static void test_read_wired_dhcp_plus_ip(void) { - NMConnection * connection; - NMSettingIPConfig *s_ip4; - NMSettingIPConfig *s_ip6; - NMIPAddress * ip4_addr; - NMIPAddress * ip6_addr; + gs_unref_object NMConnection *connection = NULL; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + NMIPAddress * ip4_addr; + NMIPAddress * ip6_addr; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-dhcp-plus-ip", NULL, TYPE_ETHERNET, NULL); - /* ===== IPv4 SETTING ===== */ - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); g_assert(nm_setting_ip_config_get_may_fail(s_ip4)); @@ -1100,9 +1017,7 @@ test_read_wired_dhcp_plus_ip(void) g_assert_cmpint(nm_ip_address_get_prefix(ip4_addr), ==, 16); g_assert_cmpstr(nm_ip_address_get_address(ip4_addr), ==, "9.8.7.6"); - /* ===== IPv6 SETTING ===== */ - s_ip6 = nm_connection_get_setting_ip6_config(connection); - g_assert(s_ip6); + s_ip6 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_AUTO); g_assert(nm_setting_ip_config_get_may_fail(s_ip6)); @@ -1127,25 +1042,21 @@ test_read_wired_dhcp_plus_ip(void) g_assert(ip6_addr); g_assert_cmpint(nm_ip_address_get_prefix(ip6_addr), ==, 96); g_assert_cmpstr(nm_ip_address_get_address(ip6_addr), ==, "3001:abba::3234"); - - g_object_unref(connection); } static void test_read_wired_shared_plus_ip(void) { - NMConnection * connection; - NMSettingIPConfig *s_ip4; - NMIPAddress * ip4_addr; + gs_unref_object NMConnection *connection = NULL; + NMSettingIPConfig * s_ip4; + NMIPAddress * ip4_addr; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-shared-plus-ip", NULL, TYPE_ETHERNET, NULL); - /* ===== IPv4 SETTING ===== */ - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_SHARED); @@ -1160,19 +1071,16 @@ test_read_wired_shared_plus_ip(void) /* Gateway */ g_assert_cmpstr(nm_setting_ip_config_get_gateway(s_ip4), ==, "1.1.1.1"); - - g_object_unref(connection); } static void test_read_wired_global_gateway(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMIPAddress * ip4_addr; - char * unmanaged = NULL; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + NMIPAddress * ip4_addr; + char * unmanaged = NULL; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-global-gateway", TEST_IFCFG_DIR "/network-test-wired-global-gateway", @@ -1180,18 +1088,12 @@ test_read_wired_global_gateway(void) &unmanaged); g_assert(unmanaged == NULL); - /* ===== CONNECTION SETTING ===== */ - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-wired-global-gateway"); - /* ===== WIRED SETTING ===== */ - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); - /* ===== IPv4 SETTING ===== */ - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL); @@ -1204,19 +1106,16 @@ test_read_wired_global_gateway(void) /* Gateway */ g_assert_cmpstr(nm_setting_ip_config_get_gateway(s_ip4), ==, "192.168.1.2"); - - g_object_unref(connection); } /* Ignore GATEWAY from /etc/sysconfig/network for automatic connections */ static void test_read_wired_global_gateway_ignore(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - char * unmanaged = NULL; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + char * unmanaged = NULL; NMTST_EXPECT_NM_WARN("*ignoring GATEWAY (/etc/sysconfig/network) for * because the connection " "has no static addresses"); @@ -1227,20 +1126,14 @@ test_read_wired_global_gateway_ignore(void) g_test_assert_expected_messages(); g_assert(unmanaged == NULL); - /* ===== CONNECTION SETTING ===== */ - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-wired-global-gateway-ignore"); - /* ===== WIRED SETTING ===== */ - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); - /* ===== IPv4 SETTING ===== */ - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); /* Addresses */ @@ -1248,25 +1141,21 @@ test_read_wired_global_gateway_ignore(void) /* Gateway */ g_assert_cmpstr(nm_setting_ip_config_get_gateway(s_ip4), ==, NULL); - - g_object_unref(connection); } static void test_read_wired_obsolete_gateway_n(void) { - NMConnection * connection; - NMSettingIPConfig *s_ip4; - NMIPAddress * ip4_addr; + gs_unref_object NMConnection *connection = NULL; + NMSettingIPConfig * s_ip4; + NMIPAddress * ip4_addr; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-obsolete-gateway-n", NULL, TYPE_ETHERNET, NULL); - /* ===== IPv4 SETTING ===== */ - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL); @@ -1280,8 +1169,6 @@ test_read_wired_obsolete_gateway_n(void) /* Gateway */ g_assert_cmpstr(nm_setting_ip_config_get_gateway(s_ip4), ==, "1.1.1.1"); - - g_object_unref(connection); } static void @@ -1294,7 +1181,8 @@ test_user_1(void) connection = nmtst_create_minimal_connection("Test User 1", NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); - s_user = NM_SETTING_USER(nm_setting_user_new()); + + s_user = _nm_connection_new_setting(connection, NM_TYPE_SETTING_USER); #define _USER_SET_DATA(s_user, key, val) \ G_STMT_START \ @@ -1330,8 +1218,6 @@ test_user_1(void) _USER_SET_DATA_X(s_user, "my.keys.1"); _USER_SET_DATA_X(s_user, "my.other.KEY.42"); - nm_connection_add_setting(connection, NM_SETTING(s_user)); - _writer_new_connec_exp(connection, TEST_SCRATCH_DIR, TEST_IFCFG_DIR "/ifcfg-Test_User_1.cexpected", @@ -1345,42 +1231,35 @@ test_user_1(void) static void test_read_wired_never_default(void) { - NMConnection * connection; - NMSettingIPConfig *s_ip4; - NMSettingIPConfig *s_ip6; + gs_unref_object NMConnection *connection = NULL; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-never-default", TEST_IFCFG_DIR "/network-test-wired-never-default", TYPE_ETHERNET, NULL); - /* ===== WIRED SETTING ===== */ - g_assert(nm_connection_get_setting_wired(connection)); + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); - /* ===== IPv4 SETTING ===== */ - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); g_assert(nm_setting_ip_config_get_never_default(s_ip4)); g_assert_cmpint(nm_setting_ip_config_get_num_dns(s_ip4), ==, 0); - /* ===== IPv6 SETTING ===== */ - s_ip6 = nm_connection_get_setting_ip6_config(connection); - g_assert(s_ip6); + s_ip6 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_AUTO); g_assert(nm_setting_ip_config_get_never_default(s_ip6)); - - g_object_unref(connection); } static void test_read_wired_defroute_no(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - char * unmanaged = NULL; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + char * unmanaged = NULL; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-defroute-no", NULL, @@ -1388,33 +1267,28 @@ test_read_wired_defroute_no(void) &unmanaged); g_assert(unmanaged == NULL); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-wired-defroute-no"); - g_assert(nm_connection_get_setting_wired(connection)); + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); g_assert(nm_setting_ip_config_get_never_default(s_ip4)); - s_ip6 = nm_connection_get_setting_ip6_config(connection); - g_assert(s_ip6); + s_ip6 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_AUTO); g_assert(nm_setting_ip_config_get_never_default(s_ip6)); - - g_object_unref(connection); } static void test_read_wired_defroute_no_gatewaydev_yes(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - char * unmanaged = NULL; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + char * unmanaged = NULL; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-defroute-no-gatewaydev-yes", @@ -1422,58 +1296,45 @@ test_read_wired_defroute_no_gatewaydev_yes(void) TYPE_ETHERNET, &unmanaged); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-wired-defroute-no-gatewaydev-yes"); - g_assert(nm_connection_get_setting_wired(connection)); + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); g_assert(nm_setting_ip_config_get_never_default(s_ip4) == FALSE); - s_ip6 = nm_connection_get_setting_ip6_config(connection); - g_assert(s_ip6); + s_ip6 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_AUTO); g_assert(nm_setting_ip_config_get_never_default(s_ip6) == FALSE); - - g_object_unref(connection); } static void test_read_wired_static_routes(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMIPRoute * ip4_route; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + NMIPRoute * ip4_route; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-static-routes", NULL, TYPE_ETHERNET, NULL); - /* ===== CONNECTION SETTING ===== */ - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-wired-static-routes"); - /* ===== WIRED SETTING ===== */ - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); - /* ===== IPv4 SETTING ===== */ - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL); - /* Routes */ g_assert_cmpint(nm_setting_ip_config_get_num_routes(s_ip4), ==, 4); ip4_route = nm_setting_ip_config_get_route(s_ip4, 0); @@ -1524,19 +1385,16 @@ test_read_wired_static_routes(void) g_assert_cmpint(nm_ip_route_get_prefix(ip4_route), ==, 32); nmtst_assert_route_attribute_string(ip4_route, NM_IP_ROUTE_ATTRIBUTE_TYPE, "local"); nmtst_assert_route_attribute_byte(ip4_route, NM_IP_ROUTE_ATTRIBUTE_SCOPE, 254); - - g_object_unref(connection); } static void test_read_wired_static_routes_legacy(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - char * unmanaged = NULL; - NMIPRoute * ip4_route; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + char * unmanaged = NULL; + NMIPRoute * ip4_route; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-static-routes-legacy", NULL, @@ -1544,28 +1402,18 @@ test_read_wired_static_routes_legacy(void) &unmanaged); g_assert(!unmanaged); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-wired-static-routes-legacy"); - /* ===== WIRED SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); - - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL); - /* Routes */ g_assert_cmpint(nm_setting_ip_config_get_num_routes(s_ip4), ==, 5); /* Route #1 */ @@ -1612,20 +1460,17 @@ test_read_wired_static_routes_legacy(void) g_assert(ip4_route != NULL); g_assert_cmpstr(nm_ip_route_get_dest(ip4_route), ==, "1.2.3.4"); nmtst_assert_route_attribute_string(ip4_route, NM_IP_ROUTE_ATTRIBUTE_TYPE, "local"); - - g_object_unref(connection); } static void test_read_wired_ipv4_manual(gconstpointer data) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - char * unmanaged = NULL; - NMIPAddress * ip4_addr; - const char * file, *expected_id; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + char * unmanaged = NULL; + NMIPAddress * ip4_addr; + const char * file, *expected_id; nmtst_test_data_unpack(data, &file, &expected_id); @@ -1634,21 +1479,12 @@ test_read_wired_ipv4_manual(gconstpointer data) connection = _connection_from_file(file, NULL, TYPE_ETHERNET, &unmanaged); g_assert(!unmanaged); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, expected_id); - /* ===== WIRED SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); - - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL); @@ -1674,21 +1510,18 @@ test_read_wired_ipv4_manual(gconstpointer data) g_assert(ip4_addr != NULL); g_assert_cmpstr(nm_ip_address_get_address(ip4_addr), ==, "3.3.3.3"); g_assert_cmpint(nm_ip_address_get_prefix(ip4_addr), ==, 8); - - g_object_unref(connection); } static void test_read_wired_ipv6_manual(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - char * unmanaged = NULL; - NMIPAddress * ip6_addr; - NMIPRoute * ip6_route; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + char * unmanaged = NULL; + NMIPAddress * ip6_addr; + NMIPRoute * ip6_route; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-ipv6-manual", NULL, @@ -1696,21 +1529,12 @@ test_read_wired_ipv6_manual(void) &unmanaged); g_assert(!unmanaged); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-wired-ipv6-manual"); - /* ===== WIRED SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); - - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); /* DNS Addresses */ g_assert_cmpint(nm_setting_ip_config_get_num_dns(s_ip4), ==, 2); @@ -1721,10 +1545,7 @@ test_read_wired_ipv6_manual(void) g_assert_cmpstr(nm_setting_ip_config_get_dns_search(s_ip4, 1), ==, "ipsum.org"); g_assert_cmpstr(nm_setting_ip_config_get_dns_search(s_ip4, 2), ==, "dolor.edu"); - /* ===== IPv6 SETTING ===== */ - - s_ip6 = nm_connection_get_setting_ip6_config(connection); - g_assert(s_ip6); + s_ip6 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_MANUAL); @@ -1794,22 +1615,19 @@ test_read_wired_ipv6_manual(void) /* DNS domains - none as domains are stuffed to 'ipv4' setting */ g_assert_cmpint(nm_setting_ip_config_get_num_dns_searches(s_ip6), ==, 0); - - g_object_unref(connection); } static void test_read_wired_ipv6_only(gconstpointer test_data) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - char * unmanaged = NULL; - NMIPAddress * ip6_addr; - const char * method; - const char * file, *expected_id; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + char * unmanaged = NULL; + NMIPAddress * ip6_addr; + const char * method; + const char * file, *expected_id; nmtst_test_data_unpack(test_data, &file, &expected_id); @@ -1818,29 +1636,17 @@ test_read_wired_ipv6_only(gconstpointer test_data) connection = _connection_from_file(file, NULL, TYPE_ETHERNET, &unmanaged); g_assert(!unmanaged); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, expected_id); - /* ===== WIRED SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); - - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); method = nm_setting_ip_config_get_method(s_ip4); g_assert_cmpstr(method, ==, NM_SETTING_IP4_CONFIG_METHOD_DISABLED); - /* ===== IPv6 SETTING ===== */ - - s_ip6 = nm_connection_get_setting_ip6_config(connection); - g_assert(s_ip6); + s_ip6 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_MANUAL); @@ -1863,20 +1669,17 @@ test_read_wired_ipv6_only(gconstpointer test_data) g_assert_cmpstr(nm_setting_ip_config_get_dns_search(s_ip6, 0), ==, "lorem.com"); g_assert_cmpstr(nm_setting_ip_config_get_dns_search(s_ip6, 1), ==, "ipsum.org"); g_assert_cmpstr(nm_setting_ip_config_get_dns_search(s_ip6, 2), ==, "dolor.edu"); - - g_object_unref(connection); } static void test_read_wired_dhcp6_only(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - char * unmanaged = NULL; - const char * method; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + char * unmanaged = NULL; + const char * method; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-dhcp6-only", NULL, @@ -1884,32 +1687,18 @@ test_read_wired_dhcp6_only(void) &unmanaged); g_assert(!unmanaged); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-wired-dhcp6-only"); - /* ===== WIRED SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); - - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); method = nm_setting_ip_config_get_method(s_ip4); g_assert_cmpstr(method, ==, NM_SETTING_IP4_CONFIG_METHOD_DISABLED); - /* ===== IPv6 SETTING ===== */ - - s_ip6 = nm_connection_get_setting_ip6_config(connection); - g_assert(s_ip6); + s_ip6 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_DHCP); - - g_object_unref(connection); } static void @@ -1926,24 +1715,23 @@ test_read_wired_autoip(void) &unmanaged); g_assert(unmanaged == NULL); - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL); g_assert(!nm_setting_ip_config_get_may_fail(s_ip4)); g_assert(nm_setting_ip_config_get_ignore_auto_dns(s_ip4)); - s_con = nm_connection_get_setting_connection(connection); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpint(nm_setting_connection_get_wait_device_timeout(s_con), ==, 2600); } static void test_read_onboot_no(void) { - NMConnection * connection; - NMSettingConnection *s_con; - char * unmanaged = NULL; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + char * unmanaged = NULL; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-onboot-no", NULL, @@ -1951,39 +1739,32 @@ test_read_onboot_no(void) &unmanaged); g_assert(!unmanaged); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert(!nm_setting_connection_get_autoconnect(s_con)); - - g_object_unref(connection); } static void test_read_noip(void) { - NMConnection * connection; - NMSettingIPConfig *s_ip4; - NMSettingIPConfig *s_ip6; + gs_unref_object NMConnection *connection = NULL; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-noip", NULL, TYPE_ETHERNET, NULL); - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_DISABLED); g_assert(nm_setting_ip_config_get_never_default(s_ip4) == FALSE); - s_ip6 = nm_connection_get_setting_ip6_config(connection); - g_assert(s_ip6); + s_ip6 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_IGNORE); g_assert(nm_setting_ip_config_get_never_default(s_ip6) == FALSE); - - g_object_unref(connection); } #define TEST_IFCFG_WIRED_8021x_PEAP_MSCHAPV2_CA_CERT TEST_IFCFG_DIR "/test_ca_cert.pem" @@ -1991,16 +1772,15 @@ test_read_noip(void) static void test_read_wired_8021x_peap_mschapv2(void) { - NMConnection * connection; - NMSettingWired * s_wired; - NMSettingIPConfig *s_ip4; - NMSetting8021x * s_8021x; - NMSetting8021x * tmp_8021x; - char * unmanaged = NULL; - GError * error = NULL; - gboolean success = FALSE; - const char * expected_ca_cert_path; - const char * read_ca_cert_path; + gs_unref_object NMConnection *connection = NULL; + NMSettingIPConfig * s_ip4; + NMSetting8021x * s_8021x; + gs_unref_object NMSetting8021x *tmp_8021x = NULL; + char * unmanaged = NULL; + GError * error = NULL; + gboolean success = FALSE; + const char * expected_ca_cert_path; + const char * read_ca_cert_path; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-8021x-peap-mschapv2", NULL, @@ -2008,20 +1788,12 @@ test_read_wired_8021x_peap_mschapv2(void) &unmanaged); g_assert(!unmanaged); - /* ===== WIRED SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); - - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); - /* ===== 802.1x SETTING ===== */ - s_8021x = nm_connection_get_setting_802_1x(connection); - g_assert(s_8021x); + s_8021x = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_802_1X); g_assert_cmpint(nm_setting_802_1x_get_num_eap_methods(s_8021x), ==, 1); g_assert_cmpstr(nm_setting_802_1x_get_eap_method(s_8021x, 0), ==, "peap"); @@ -2049,33 +1821,26 @@ test_read_wired_8021x_peap_mschapv2(void) g_assert(read_ca_cert_path); g_assert_cmpstr(read_ca_cert_path, ==, expected_ca_cert_path); - - g_object_unref(tmp_8021x); - - g_object_unref(connection); } static void test_read_wired_8021x_tls_secret_flags(gconstpointer test_data) { - NMConnection * connection; - NMSettingWired *s_wired; - NMSetting8021x *s_8021x; - char * dirname, *tmp; - const char * ifcfg; - gpointer expected_flags_p; + gs_unref_object NMConnection *connection = NULL; + NMSetting8021x * s_8021x; + gs_free char * dirname = NULL; + gs_free char * tmp1 = NULL; + gs_free char * tmp2 = NULL; + const char * ifcfg; + gpointer expected_flags_p; nmtst_test_data_unpack(test_data, &ifcfg, &expected_flags_p); connection = _connection_from_file(ifcfg, NULL, TYPE_ETHERNET, NULL); - /* ===== WIRED SETTING ===== */ - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); - /* ===== 802.1x SETTING ===== */ - s_8021x = nm_connection_get_setting_802_1x(connection); - g_assert(s_8021x); + s_8021x = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_802_1X); g_assert_cmpint(nm_setting_802_1x_get_num_eap_methods(s_8021x), ==, 1); g_assert_cmpstr(nm_setting_802_1x_get_eap_method(s_8021x, 0), ==, "tls"); g_assert_cmpstr(nm_setting_802_1x_get_identity(s_8021x), ==, "David Smith"); @@ -2084,18 +1849,13 @@ test_read_wired_8021x_tls_secret_flags(gconstpointer test_data) GPOINTER_TO_INT(expected_flags_p)); dirname = g_path_get_dirname(ifcfg); - tmp = g_build_path("/", dirname, "test_ca_cert.pem", NULL); - g_assert_cmpstr(nm_setting_802_1x_get_ca_cert_path(s_8021x), ==, tmp); - g_free(tmp); - tmp = g_build_path("/", dirname, "test1_key_and_cert.pem", NULL); - g_assert_cmpstr(nm_setting_802_1x_get_client_cert_path(s_8021x), ==, tmp); - g_assert_cmpstr(nm_setting_802_1x_get_private_key_path(s_8021x), ==, tmp); - g_free(tmp); + tmp1 = g_build_path("/", dirname, "test_ca_cert.pem", NULL); + g_assert_cmpstr(nm_setting_802_1x_get_ca_cert_path(s_8021x), ==, tmp1); - g_free(dirname); - - g_object_unref(connection); + tmp2 = g_build_path("/", dirname, "test1_key_and_cert.pem", NULL); + g_assert_cmpstr(nm_setting_802_1x_get_client_cert_path(s_8021x), ==, tmp2); + g_assert_cmpstr(nm_setting_802_1x_get_private_key_path(s_8021x), ==, tmp2); } static void @@ -2111,9 +1871,7 @@ test_read_write_802_1X_subj_matches(void) TYPE_ETHERNET, NULL); - /* ===== 802.1x SETTING ===== */ - s_8021x = nm_connection_get_setting_802_1x(connection); - g_assert(s_8021x); + s_8021x = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_802_1X); g_assert_cmpint(nm_setting_802_1x_get_num_eap_methods(s_8021x), ==, 1); g_assert_cmpstr(nm_setting_802_1x_get_eap_method(s_8021x, 0), ==, "peap"); g_assert_cmpstr(nm_setting_802_1x_get_identity(s_8021x), ==, "Jara Cimrman"); @@ -2143,8 +1901,7 @@ test_read_write_802_1X_subj_matches(void) nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); /* Check 802.1X stuff of the re-read connection. */ - s_8021x = nm_connection_get_setting_802_1x(reread); - g_assert(s_8021x); + s_8021x = nmtst_connection_assert_setting(reread, NM_TYPE_SETTING_802_1X); g_assert_cmpint(nm_setting_802_1x_get_num_eap_methods(s_8021x), ==, 1); g_assert_cmpstr(nm_setting_802_1x_get_eap_method(s_8021x, 0), ==, "peap"); g_assert_cmpstr(nm_setting_802_1x_get_identity(s_8021x), ==, "Jara Cimrman"); @@ -2168,8 +1925,8 @@ test_read_write_802_1X_subj_matches(void) static void test_read_802_1x_ttls_eapgtc(void) { - NMConnection * connection; - NMSetting8021x *s_8021x; + gs_unref_object NMConnection *connection = NULL; + NMSetting8021x * s_8021x; /* Test that EAP-* inner methods are correctly read into the * NMSetting8021x::autheap property. @@ -2180,9 +1937,7 @@ test_read_802_1x_ttls_eapgtc(void) TYPE_WIRELESS, NULL); - /* ===== 802.1x SETTING ===== */ - s_8021x = nm_connection_get_setting_802_1x(connection); - g_assert(s_8021x); + s_8021x = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_802_1X); /* EAP methods */ g_assert_cmpint(nm_setting_802_1x_get_num_eap_methods(s_8021x), ==, 1); @@ -2191,8 +1946,6 @@ test_read_802_1x_ttls_eapgtc(void) /* Auth methods */ g_assert_cmpstr(nm_setting_802_1x_get_phase2_auth(s_8021x), ==, NULL); g_assert_cmpstr(nm_setting_802_1x_get_phase2_autheap(s_8021x), ==, "gtc"); - - g_object_unref(connection); } static void @@ -2208,8 +1961,7 @@ test_read_802_1x_tls_p12_no_client_cert(void) TYPE_ETHERNET, NULL); - s_8021x = nm_connection_get_setting_802_1x(connection); - g_assert(s_8021x); + s_8021x = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_802_1X); g_assert_cmpint(nm_setting_802_1x_get_private_key_scheme(s_8021x), ==, @@ -2242,9 +1994,7 @@ test_read_write_802_1x_password_raw(void) TYPE_ETHERNET, NULL); - /* ===== 802.1x SETTING ===== */ - s_8021x = nm_connection_get_setting_802_1x(connection); - g_assert(s_8021x); + s_8021x = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_802_1X); bytes = nm_setting_802_1x_get_password_raw(s_8021x); g_assert(bytes); @@ -2269,18 +2019,18 @@ test_read_write_802_1x_password_raw(void) static void test_read_wired_aliases_good(gconstpointer test_data) { - const int N = GPOINTER_TO_INT(test_data); - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingIPConfig * s_ip4; - int expected_num_addresses; - const char * expected_address_0[] = {"192.168.1.5", + const int N = GPOINTER_TO_INT(test_data); + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + int expected_num_addresses; + const char * expected_address_0[] = {"192.168.1.5", "192.168.1.6", "192.168.1.9", "192.168.1.99", NULL}; - const char * expected_address_3[] = {"192.168.1.5", "192.168.1.6", NULL}; - const char * expected_label_0[] = { + const char * expected_address_3[] = {"192.168.1.5", "192.168.1.6", NULL}; + const char * expected_label_0[] = { NULL, "aliasem0:1", "aliasem0:2", @@ -2305,19 +2055,13 @@ test_read_wired_aliases_good(gconstpointer test_data) connection = _connection_from_file(path, NULL, TYPE_ETHERNET, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); if (N == 0) g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System aliasem0"); else g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System aliasem3"); - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL); @@ -2358,33 +2102,25 @@ test_read_wired_aliases_good(gconstpointer test_data) for (i = 0; i < expected_num_addresses; i++) g_assert(!expected_address[i]); - - g_object_unref(connection); } static void test_read_wired_aliases_bad(const char *base, const char *expected_id) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingIPConfig * s_ip4; - NMIPAddress * ip4_addr; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + NMIPAddress * ip4_addr; g_assert(expected_id); connection = _connection_from_file(base, NULL, TYPE_ETHERNET, NULL); g_test_assert_expected_messages(); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, expected_id); - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL); @@ -2400,8 +2136,6 @@ test_read_wired_aliases_bad(const char *base, const char *expected_id) /* Gateway */ g_assert_cmpstr(nm_setting_ip_config_get_gateway(s_ip4), ==, "192.168.1.1"); - - g_object_unref(connection); } static void @@ -2421,13 +2155,15 @@ test_read_wired_aliases_bad_2(void) static void test_read_dns_options(void) { - NMConnection * connection; - NMSettingIPConfig *s_ip4, *s_ip6; - char * unmanaged = NULL; - const char * option; - const char * options4[] = {"ndots:3", "single-request-reopen"}; - const char * options6[] = {"inet6"}; - guint32 i, num; + gs_unref_object NMConnection *connection = NULL; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + char * unmanaged = NULL; + const char * option; + const char * options4[] = {"ndots:3", "single-request-reopen"}; + const char * options6[] = {"inet6"}; + guint32 num; + guint32 i; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-dns-options", NULL, @@ -2435,11 +2171,9 @@ test_read_dns_options(void) &unmanaged); g_assert_cmpstr(unmanaged, ==, NULL); - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); - s_ip6 = nm_connection_get_setting_ip6_config(connection); - g_assert(s_ip6); + s_ip6 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); num = nm_setting_ip_config_get_num_dns_options(s_ip4); g_assert_cmpint(num, ==, G_N_ELEMENTS(options4)); @@ -2456,8 +2190,6 @@ test_read_dns_options(void) option = nm_setting_ip_config_get_dns_option(s_ip6, i); g_assert_cmpstr(options6[i], ==, option); } - - g_object_unref(connection); } static void @@ -2477,8 +2209,7 @@ test_clear_master(void) &unmanaged); g_assert_cmpstr(unmanaged, ==, NULL); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_master(s_con), ==, "br0"); g_assert_cmpstr(nm_setting_connection_get_slave_type(s_con), ==, "bridge"); @@ -2534,10 +2265,7 @@ test_write_dns_options(void) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test DNS options", @@ -2549,16 +2277,10 @@ test_write_dns_options(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - + s_wired = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); g_object_set(s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac, NM_SETTING_WIRED_MTU, mtu, NULL); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, @@ -2576,10 +2298,7 @@ test_write_dns_options(void) nm_setting_ip_config_add_dns_option(s_ip4, "debug"); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL, @@ -2608,23 +2327,20 @@ test_write_dns_options(void) static void test_read_wifi_open(void) { - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWireless * s_wireless; - NMSettingWirelessSecurity *s_wsec; - NMSettingIPConfig * s_ip4, *s_ip6; - GBytes * ssid; - const char * mac; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + GBytes * ssid; + const char * mac; char expected_mac_address[ETH_ALEN] = {0x00, 0x16, 0x41, 0x11, 0x22, 0x33}; const char *expected_ssid = "blahblah"; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-open", NULL, TYPE_WIRELESS, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System blahblah (test-wifi-open)"); /* UUID can't be tested if the ifcfg does not contain the UUID key, because @@ -2636,109 +2352,83 @@ test_read_wifi_open(void) g_assert(nm_setting_connection_get_autoconnect(s_con)); g_assert_cmpint(nm_setting_connection_get_autoconnect_priority(s_con), ==, -1); - /* ===== WIRELESS SETTING ===== */ + s_wifi = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); - - /* MAC address */ - mac = nm_setting_wireless_get_mac_address(s_wireless); + mac = nm_setting_wireless_get_mac_address(s_wifi); g_assert(mac); g_assert(nm_utils_hwaddr_matches(mac, -1, expected_mac_address, sizeof(expected_mac_address))); - g_assert_cmpint(nm_setting_wireless_get_mtu(s_wireless), ==, 0); + g_assert_cmpint(nm_setting_wireless_get_mtu(s_wifi), ==, 0); - ssid = nm_setting_wireless_get_ssid(s_wireless); + ssid = nm_setting_wireless_get_ssid(s_wifi); g_assert(ssid); g_assert_cmpmem(g_bytes_get_data(ssid, NULL), g_bytes_get_size(ssid), expected_ssid, strlen(expected_ssid)); - g_assert(!nm_setting_wireless_get_bssid(s_wireless)); - g_assert_cmpstr(nm_setting_wireless_get_mode(s_wireless), ==, "infrastructure"); - g_assert_cmpint(nm_setting_wireless_get_channel(s_wireless), ==, 1); + g_assert(!nm_setting_wireless_get_bssid(s_wifi)); + g_assert_cmpstr(nm_setting_wireless_get_mode(s_wifi), ==, "infrastructure"); + g_assert_cmpint(nm_setting_wireless_get_channel(s_wifi), ==, 1); - /* ===== Wi-Fi SECURITY SETTING ===== */ - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec == NULL); + nmtst_connection_assert_no_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpint(nm_setting_ip_config_get_route_metric(s_ip4), ==, 104); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); - s_ip6 = nm_connection_get_setting_ip6_config(connection); - g_assert(s_ip6); + s_ip6 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_assert_cmpint(nm_setting_ip_config_get_route_metric(s_ip6), ==, 106); - - g_object_unref(connection); } static void test_read_wifi_open_auto(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWireless * s_wireless; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-open-auto", NULL, TYPE_WIRELESS, NULL); - /* ===== CONNECTION SETTING ===== */ - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System blahblah (test-wifi-open-auto)"); - /* ===== WIRELESS SETTING ===== */ - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); - g_assert_cmpstr(nm_setting_wireless_get_mode(s_wireless), ==, "infrastructure"); - - g_object_unref(connection); + s_wifi = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); + g_assert_cmpstr(nm_setting_wireless_get_mode(s_wifi), ==, "infrastructure"); } static void test_read_wifi_open_ssid_hex(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWireless * s_wireless; - GBytes * ssid; - const char * expected_ssid = "blahblah"; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + GBytes * ssid; + const char * expected_ssid = "blahblah"; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-open-ssid-hex", NULL, TYPE_WIRELESS, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System blahblah (test-wifi-open-ssid-hex)"); - /* ===== WIRELESS SETTING ===== */ + s_wifi = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); - - ssid = nm_setting_wireless_get_ssid(s_wireless); + ssid = nm_setting_wireless_get_ssid(s_wifi); g_assert(ssid); g_assert_cmpmem(g_bytes_get_data(ssid, NULL), g_bytes_get_size(ssid), expected_ssid, strlen(expected_ssid)); - - g_object_unref(connection); } static void @@ -2746,7 +2436,7 @@ test_read_wifi_open_ssid_hex_bad(void) { gs_unref_object NMConnection *connection = NULL; NMSettingConnection * s_con; - NMSettingWireless * s_wireless; + NMSettingWireless * s_wifi; GBytes * ssid; const char * expected_ssid = "0x626cxx"; @@ -2755,16 +2445,14 @@ test_read_wifi_open_ssid_hex_bad(void) TYPE_WIRELESS, NULL); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System 0x626cxx (test-wifi-open-ssid-bad-hex)"); - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); + s_wifi = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - ssid = nm_setting_wireless_get_ssid(s_wireless); + ssid = nm_setting_wireless_get_ssid(s_wifi); g_assert(ssid); g_assert_cmpmem(g_bytes_get_data(ssid, NULL), g_bytes_get_size(ssid), @@ -2781,50 +2469,42 @@ test_read_wifi_open_ssid_bad(gconstpointer data) static void test_read_wifi_open_ssid_quoted(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWireless * s_wireless; - GBytes * ssid; - const char * expected_ssid = "foo\"bar\\"; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + GBytes * ssid; + const char * expected_ssid = "foo\"bar\\"; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-open-ssid-quoted", NULL, TYPE_WIRELESS, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System foo\"bar\\ (test-wifi-open-ssid-quoted)"); - /* ===== WIRELESS SETTING ===== */ + s_wifi = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); - - ssid = nm_setting_wireless_get_ssid(s_wireless); + ssid = nm_setting_wireless_get_ssid(s_wifi); g_assert(ssid); g_assert_cmpmem(g_bytes_get_data(ssid, NULL), g_bytes_get_size(ssid), expected_ssid, strlen(expected_ssid)); - - g_object_unref(connection); } static void test_read_wifi_wep(void) { - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWireless * s_wireless; - NMSettingWirelessSecurity *s_wsec; - NMSettingIPConfig * s_ip4; - GBytes * ssid; - const char * mac; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + NMSettingWirelessSecurity * s_wsec; + NMSettingIPConfig * s_ip4; + GBytes * ssid; + const char * mac; char expected_mac_address[ETH_ALEN] = {0x00, 0x16, 0x41, 0x11, 0x22, 0x33}; const char * expected_ssid = "blahblah"; NMWepKeyType key_type; @@ -2832,10 +2512,7 @@ test_read_wifi_wep(void) connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wep", NULL, TYPE_WIRELESS, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System blahblah (test-wifi-wep)"); /* UUID can't be tested if the ifcfg does not contain the UUID key, because @@ -2846,34 +2523,27 @@ test_read_wifi_wep(void) g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, 0); g_assert(nm_setting_connection_get_autoconnect(s_con)); - /* ===== WIRELESS SETTING ===== */ + s_wifi = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); - - /* MAC address */ - mac = nm_setting_wireless_get_mac_address(s_wireless); + mac = nm_setting_wireless_get_mac_address(s_wifi); g_assert(mac); g_assert(nm_utils_hwaddr_matches(mac, -1, expected_mac_address, sizeof(expected_mac_address))); /* MTU */ - g_assert_cmpint(nm_setting_wireless_get_mtu(s_wireless), ==, 0); + g_assert_cmpint(nm_setting_wireless_get_mtu(s_wifi), ==, 0); - ssid = nm_setting_wireless_get_ssid(s_wireless); + ssid = nm_setting_wireless_get_ssid(s_wifi); g_assert(ssid); g_assert_cmpmem(g_bytes_get_data(ssid, NULL), g_bytes_get_size(ssid), expected_ssid, strlen(expected_ssid)); - g_assert(!nm_setting_wireless_get_bssid(s_wireless)); - g_assert_cmpstr(nm_setting_wireless_get_mode(s_wireless), ==, "infrastructure"); - g_assert_cmpint(nm_setting_wireless_get_channel(s_wireless), ==, 1); + g_assert(!nm_setting_wireless_get_bssid(s_wifi)); + g_assert_cmpstr(nm_setting_wireless_get_mode(s_wifi), ==, "infrastructure"); + g_assert_cmpint(nm_setting_wireless_get_channel(s_wifi), ==, 1); - /* ===== WIRELESS SECURITY SETTING ===== */ - - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "none"); g_assert_cmpstr(nm_setting_wireless_security_get_auth_alg(s_wsec), ==, "shared"); g_assert_cmpint(nm_setting_wireless_security_get_wep_tx_keyidx(s_wsec), ==, 0); @@ -2888,35 +2558,27 @@ test_read_wifi_wep(void) g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 2)); g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 3)); - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); - - g_object_unref(connection); } static void test_read_wifi_wep_adhoc(void) { - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWireless * s_wireless; - NMSettingWirelessSecurity *s_wsec; - NMSettingIPConfig * s_ip4; - GBytes * ssid; - const char * expected_ssid = "blahblah"; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + NMSettingWirelessSecurity * s_wsec; + NMSettingIPConfig * s_ip4; + GBytes * ssid; + const char * expected_ssid = "blahblah"; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wep-adhoc", NULL, TYPE_WIRELESS, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System blahblah (test-wifi-wep-adhoc)"); @@ -2928,26 +2590,20 @@ test_read_wifi_wep_adhoc(void) g_assert(!nm_setting_connection_get_autoconnect(s_con)); - /* ===== WIRELESS SETTING ===== */ + s_wifi = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); - - ssid = nm_setting_wireless_get_ssid(s_wireless); + ssid = nm_setting_wireless_get_ssid(s_wifi); g_assert(ssid); g_assert_cmpmem(g_bytes_get_data(ssid, NULL), g_bytes_get_size(ssid), expected_ssid, strlen(expected_ssid)); - g_assert(!nm_setting_wireless_get_bssid(s_wireless)); - g_assert_cmpstr(nm_setting_wireless_get_mode(s_wireless), ==, "adhoc"); - g_assert_cmpint(nm_setting_wireless_get_channel(s_wireless), ==, 11); + g_assert(!nm_setting_wireless_get_bssid(s_wifi)); + g_assert_cmpstr(nm_setting_wireless_get_mode(s_wifi), ==, "adhoc"); + g_assert_cmpint(nm_setting_wireless_get_channel(s_wifi), ==, 11); - /* ===== WIRELESS SECURITY SETTING ===== */ - - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "none"); g_assert(!nm_setting_wireless_security_get_auth_alg(s_wsec)); g_assert_cmpint(nm_setting_wireless_security_get_wep_tx_keyidx(s_wsec), ==, 0); @@ -2959,10 +2615,7 @@ test_read_wifi_wep_adhoc(void) g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 2)); g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 3)); - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); /* Ignore auto DNS */ @@ -2972,37 +2625,24 @@ test_read_wifi_wep_adhoc(void) g_assert_cmpint(nm_setting_ip_config_get_num_dns(s_ip4), ==, 2); g_assert_cmpstr(nm_setting_ip_config_get_dns(s_ip4, 0), ==, "4.2.2.1"); g_assert_cmpstr(nm_setting_ip_config_get_dns(s_ip4, 1), ==, "4.2.2.2"); - - g_object_unref(connection); } static void test_read_wifi_wep_passphrase(void) { - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWireless * s_wireless; - NMSettingWirelessSecurity *s_wsec; + gs_unref_object NMConnection *connection = NULL; + NMSettingWirelessSecurity * s_wsec; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wep-passphrase", NULL, TYPE_WIRELESS, NULL); - /* ===== CONNECTION SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - /* ===== WIRELESS SETTING ===== */ - - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); - - /* ===== WIRELESS SECURITY SETTING ===== */ - - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "none"); g_assert_cmpint(nm_setting_wireless_security_get_wep_tx_keyidx(s_wsec), ==, 0); g_assert_cmpint(nm_setting_wireless_security_get_wep_key_type(s_wsec), @@ -3012,38 +2652,25 @@ test_read_wifi_wep_passphrase(void) g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 1)); g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 2)); g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 3)); - - g_object_unref(connection); } static void test_read_wifi_wep_40_ascii(void) { - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWireless * s_wireless; - NMSettingWirelessSecurity *s_wsec; - NMWepKeyType key_type; + gs_unref_object NMConnection *connection = NULL; + NMSettingWirelessSecurity * s_wsec; + NMWepKeyType key_type; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wep-40-ascii", NULL, TYPE_WIRELESS, NULL); - /* ===== CONNECTION SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - /* ===== WIRELESS SETTING ===== */ - - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); - - /* ===== WIRELESS SECURITY SETTING ===== */ - - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "none"); g_assert_cmpint(nm_setting_wireless_security_get_wep_tx_keyidx(s_wsec), ==, 0); @@ -3054,38 +2681,25 @@ test_read_wifi_wep_40_ascii(void) g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 1)); g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 2)); g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 3)); - - g_object_unref(connection); } static void test_read_wifi_wep_104_ascii(void) { - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWireless * s_wireless; - NMSettingWirelessSecurity *s_wsec; - NMWepKeyType key_type; + gs_unref_object NMConnection *connection = NULL; + NMSettingWirelessSecurity * s_wsec; + NMWepKeyType key_type; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wep-104-ascii", NULL, TYPE_WIRELESS, NULL); - /* ===== CONNECTION SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - /* ===== WIRELESS SETTING ===== */ - - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); - - /* ===== WIRELESS SECURITY SETTING ===== */ - - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "none"); g_assert_cmpint(nm_setting_wireless_security_get_wep_tx_keyidx(s_wsec), ==, 0); @@ -3096,64 +2710,45 @@ test_read_wifi_wep_104_ascii(void) g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 1)); g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 2)); g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 3)); - - g_object_unref(connection); } static void test_read_wifi_leap(void) { - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWireless * s_wireless; - NMSettingWirelessSecurity *s_wsec; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWirelessSecurity * s_wsec; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-leap", NULL, TYPE_WIRELESS, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System blahblah (test-wifi-leap)"); - /* ===== WIRELESS SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); - - /* ===== WIRELESS SECURITY SETTING ===== */ - - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "ieee8021x"); g_assert_cmpstr(nm_setting_wireless_security_get_auth_alg(s_wsec), ==, "leap"); g_assert_cmpstr(nm_setting_wireless_security_get_leap_username(s_wsec), ==, "Bill Smith"); g_assert_cmpstr(nm_setting_wireless_security_get_leap_password(s_wsec), ==, "foobarblah"); - - g_object_unref(connection); } static void test_read_wifi_leap_secret_flags(gconstpointer test_data) { - NMConnection * connection; - NMSettingWireless * s_wifi; - NMSettingWirelessSecurity *s_wsec; - const char * file; - gpointer expected_flags_p; + gs_unref_object NMConnection *connection = NULL; + NMSettingWirelessSecurity * s_wsec; + const char * file; + gpointer expected_flags_p; nmtst_test_data_unpack(test_data, &file, &expected_flags_p); connection = _connection_from_file(file, NULL, TYPE_WIRELESS, NULL); - /* ===== WIRELESS SETTING ===== */ - s_wifi = nm_connection_get_setting_wireless(connection); - g_assert(s_wifi); + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - /* ===== WIRELESS SECURITY SETTING ===== */ - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_assert(g_strcmp0(nm_setting_wireless_security_get_key_mgmt(s_wsec), "ieee8021x") == 0); g_assert(g_strcmp0(nm_setting_wireless_security_get_auth_alg(s_wsec), "leap") == 0); @@ -3162,8 +2757,6 @@ test_read_wifi_leap_secret_flags(gconstpointer test_data) g_assert(nm_setting_wireless_security_get_leap_password_flags(s_wsec) == GPOINTER_TO_INT(expected_flags_p)); g_assert(nm_setting_wireless_security_get_leap_password(s_wsec) == NULL); - - g_object_unref(connection); } static void @@ -3179,13 +2772,13 @@ test_ifcfg_no_trailing_newline(void) static void test_read_wifi_wpa_psk(void) { - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWireless * s_wireless; - NMSettingWirelessSecurity *s_wsec; - NMSettingIPConfig * s_ip4; - GBytes * ssid; - const char * mac; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + NMSettingWirelessSecurity * s_wsec; + NMSettingIPConfig * s_ip4; + GBytes * ssid; + const char * mac; char expected_mac_address[ETH_ALEN] = {0x00, 0x16, 0x41, 0x11, 0x22, 0x33}; const char *expected_ssid = "blahblah"; guint32 n, i; @@ -3201,10 +2794,7 @@ test_read_wifi_wpa_psk(void) connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-psk", NULL, TYPE_WIRELESS, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System blahblah (test-wifi-wpa-psk)"); /* UUID can't be tested if the ifcfg does not contain the UUID key, because @@ -3215,32 +2805,26 @@ test_read_wifi_wpa_psk(void) g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, 0); g_assert(nm_setting_connection_get_autoconnect(s_con)); - /* ===== WIRELESS SETTING ===== */ + s_wifi = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); - - mac = nm_setting_wireless_get_mac_address(s_wireless); + mac = nm_setting_wireless_get_mac_address(s_wifi); g_assert(mac); g_assert(nm_utils_hwaddr_matches(mac, -1, expected_mac_address, sizeof(expected_mac_address))); - g_assert_cmpint(nm_setting_wireless_get_mtu(s_wireless), ==, 0); + g_assert_cmpint(nm_setting_wireless_get_mtu(s_wifi), ==, 0); - ssid = nm_setting_wireless_get_ssid(s_wireless); + ssid = nm_setting_wireless_get_ssid(s_wifi); g_assert(ssid); g_assert_cmpmem(g_bytes_get_data(ssid, NULL), g_bytes_get_size(ssid), expected_ssid, strlen(expected_ssid)); - g_assert(!nm_setting_wireless_get_bssid(s_wireless)); - g_assert_cmpstr(nm_setting_wireless_get_mode(s_wireless), ==, "infrastructure"); - g_assert_cmpint(nm_setting_wireless_get_channel(s_wireless), ==, 1); + g_assert(!nm_setting_wireless_get_bssid(s_wifi)); + g_assert_cmpstr(nm_setting_wireless_get_mode(s_wifi), ==, "infrastructure"); + g_assert_cmpint(nm_setting_wireless_get_channel(s_wifi), ==, 1); - /* ===== WIRELESS SECURITY SETTING ===== */ - - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "wpa-psk"); g_assert_cmpstr(nm_setting_wireless_security_get_psk(s_wsec), ==, @@ -3295,13 +2879,8 @@ test_read_wifi_wpa_psk(void) g_assert(found_proto_wpa); g_assert(found_proto_rsn); - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); - - g_object_unref(connection); } static void @@ -3309,7 +2888,7 @@ test_read_wifi_sae(void) { gs_unref_object NMConnection *connection = NULL; NMSettingConnection * s_con; - NMSettingWireless * s_wireless; + NMSettingWireless * s_wifi; NMSettingWirelessSecurity * s_wsec; GBytes * ssid; const char * expected_ssid = "blahblah"; @@ -3317,30 +2896,27 @@ test_read_wifi_sae(void) connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-sae", NULL, TYPE_WIRELESS, NULL); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System blahblah (test-wifi-sae)"); g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, 0); g_assert(nm_setting_connection_get_autoconnect(s_con)); - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); + s_wifi = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - g_assert_cmpint(nm_setting_wireless_get_mtu(s_wireless), ==, 0); + g_assert_cmpint(nm_setting_wireless_get_mtu(s_wifi), ==, 0); - ssid = nm_setting_wireless_get_ssid(s_wireless); + ssid = nm_setting_wireless_get_ssid(s_wifi); g_assert(ssid); g_assert_cmpmem(g_bytes_get_data(ssid, NULL), g_bytes_get_size(ssid), expected_ssid, strlen(expected_ssid)); - g_assert(!nm_setting_wireless_get_bssid(s_wireless)); - g_assert_cmpstr(nm_setting_wireless_get_mode(s_wireless), ==, "infrastructure"); + g_assert(!nm_setting_wireless_get_bssid(s_wifi)); + g_assert_cmpstr(nm_setting_wireless_get_mode(s_wifi), ==, "infrastructure"); - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "sae"); g_assert_cmpstr(nm_setting_wireless_security_get_psk(s_wsec), ==, "The king is dead."); g_assert(!nm_setting_wireless_security_get_auth_alg(s_wsec)); @@ -3351,7 +2927,7 @@ test_read_wifi_owe(void) { gs_unref_object NMConnection *connection = NULL; NMSettingConnection * s_con; - NMSettingWireless * s_wireless; + NMSettingWireless * s_wifi; NMSettingWirelessSecurity * s_wsec; GBytes * ssid; const char * expected_ssid = "blahblah_owe"; @@ -3359,30 +2935,27 @@ test_read_wifi_owe(void) connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-owe", NULL, TYPE_WIRELESS, NULL); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System blahblah_owe (test-wifi-owe)"); g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, 0); g_assert(nm_setting_connection_get_autoconnect(s_con)); - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); + s_wifi = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - g_assert_cmpint(nm_setting_wireless_get_mtu(s_wireless), ==, 0); + g_assert_cmpint(nm_setting_wireless_get_mtu(s_wifi), ==, 0); - ssid = nm_setting_wireless_get_ssid(s_wireless); + ssid = nm_setting_wireless_get_ssid(s_wifi); g_assert(ssid); g_assert_cmpmem(g_bytes_get_data(ssid, NULL), g_bytes_get_size(ssid), expected_ssid, strlen(expected_ssid)); - g_assert(!nm_setting_wireless_get_bssid(s_wireless)); - g_assert_cmpstr(nm_setting_wireless_get_mode(s_wireless), ==, "infrastructure"); + g_assert(!nm_setting_wireless_get_bssid(s_wifi)); + g_assert_cmpstr(nm_setting_wireless_get_mode(s_wifi), ==, "infrastructure"); - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "owe"); g_assert(!nm_setting_wireless_security_get_psk(s_wsec)); g_assert(!nm_setting_wireless_security_get_auth_alg(s_wsec)); @@ -3391,71 +2964,47 @@ test_read_wifi_owe(void) static void test_read_wifi_wpa_psk_2(void) { - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWireless * s_wireless; - NMSettingWirelessSecurity *s_wsec; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWirelessSecurity * s_wsec; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-psk-2", NULL, TYPE_WIRELESS, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System ipsum (test-wifi-wpa-psk-2)"); - /* ===== WIRELESS SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); - - /* ===== WIRELESS SECURITY SETTING ===== */ - - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_assert_cmpstr(nm_setting_wireless_security_get_psk(s_wsec), ==, "They're really saying I love you. >>`<< '"); - - g_object_unref(connection); } static void test_read_wifi_wpa_psk_unquoted(void) { - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWireless * s_wireless; - NMSettingWirelessSecurity *s_wsec; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWirelessSecurity * s_wsec; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-psk-unquoted", NULL, TYPE_WIRELESS, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System blahblah (test-wifi-wpa-psk-unquoted)"); - /* ===== WIRELESS SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); - - /* ===== WIRELESS SECURITY SETTING ===== */ - - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_assert_cmpstr(nm_setting_wireless_security_get_psk(s_wsec), ==, "54336845e2f3f321c4c7"); - - g_object_unref(connection); } static void @@ -3472,36 +3021,27 @@ test_read_wifi_wpa_psk_unquoted2(void) static void test_read_wifi_wpa_psk_adhoc(void) { - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWireless * s_wireless; - NMSettingWirelessSecurity *s_wsec; - NMSettingIPConfig * s_ip4; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + NMSettingWirelessSecurity * s_wsec; + NMSettingIPConfig * s_ip4; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-psk-adhoc", NULL, TYPE_WIRELESS, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System blahblah (test-wifi-wpa-psk-adhoc)"); - /* ===== WIRELESS SETTING ===== */ + s_wifi = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); + g_assert_cmpstr(nm_setting_wireless_get_mode(s_wifi), ==, "adhoc"); - g_assert_cmpstr(nm_setting_wireless_get_mode(s_wireless), ==, "adhoc"); - - /* ===== WIRELESS SECURITY SETTING ===== */ - - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "wpa-psk"); g_assert_cmpstr(nm_setting_wireless_security_get_psk(s_wsec), ==, @@ -3516,64 +3056,45 @@ test_read_wifi_wpa_psk_adhoc(void) g_assert_cmpint(nm_setting_wireless_security_get_num_protos(s_wsec), ==, 1); g_assert_cmpstr(nm_setting_wireless_security_get_proto(s_wsec, 0), ==, "rsn"); - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); - - g_object_unref(connection); } static void test_read_wifi_wpa_psk_hex(void) { - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWireless * s_wireless; - NMSettingWirelessSecurity *s_wsec; - NMSettingIPConfig * s_ip4; - GBytes * ssid; - const char * expected_ssid = "blahblah"; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + NMSettingWirelessSecurity * s_wsec; + NMSettingIPConfig * s_ip4; + GBytes * ssid; + const char * expected_ssid = "blahblah"; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-psk-hex", NULL, TYPE_WIRELESS, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System blahblah (test-wifi-wpa-psk-hex)"); - /* ===== WIRELESS SETTING ===== */ + s_wifi = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); - - ssid = nm_setting_wireless_get_ssid(s_wireless); + ssid = nm_setting_wireless_get_ssid(s_wifi); g_assert(ssid); g_assert(nm_utils_gbytes_equal_mem(ssid, expected_ssid, strlen(expected_ssid))); - /* ===== WIRELESS SECURITY SETTING ===== */ - - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "wpa-psk"); g_assert_cmpstr(nm_setting_wireless_security_get_psk(s_wsec), ==, "1da190379817bc360dda52e85c388c439a21ea5c7bf819c64e9da051807deae6"); - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); - - g_object_unref(connection); } #define TEST_IFCFG_WIFI_WPA_EAP_TLS_CA_CERT TEST_IFCFG_DIR "/test_ca_cert.pem" @@ -3583,12 +3104,11 @@ test_read_wifi_wpa_psk_hex(void) static void test_read_wifi_wpa_eap_tls(void) { - NMConnection * connection; - NMSettingWireless *s_wireless; - NMSettingIPConfig *s_ip4; - NMSetting8021x * s_8021x; - char * unmanaged = NULL; - const char * expected_privkey_password = "test1"; + gs_unref_object NMConnection *connection = NULL; + NMSettingIPConfig * s_ip4; + NMSetting8021x * s_8021x; + char * unmanaged = NULL; + const char * expected_privkey_password = "test1"; NMTST_EXPECT_NM_WARN("*key ONBOOT is duplicated and the early occurrence ignored*"); connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-eap-tls", @@ -3598,20 +3118,12 @@ test_read_wifi_wpa_eap_tls(void) g_test_assert_expected_messages(); g_assert(!unmanaged); - /* ===== WIRELESS SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); - - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); - /* ===== 802.1x SETTING ===== */ - s_8021x = nm_connection_get_setting_802_1x(connection); - g_assert(s_8021x); + s_8021x = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_802_1X); g_assert_cmpint(nm_setting_802_1x_get_num_eap_methods(s_8021x), ==, 1); g_assert_cmpstr(nm_setting_802_1x_get_eap_method(s_8021x, 0), ==, "tls"); g_assert_cmpstr(nm_setting_802_1x_get_identity(s_8021x), ==, "Bill Smith"); @@ -3638,8 +3150,6 @@ test_read_wifi_wpa_eap_tls(void) TEST_IFCFG_WIFI_WPA_EAP_TLS_PRIVATE_KEY, expected_privkey_password, NM_SETTING_802_1X_PRIVATE_KEY); - - g_object_unref(connection); } /* Also use TLS defines from the previous test */ @@ -3647,12 +3157,11 @@ test_read_wifi_wpa_eap_tls(void) static void test_read_wifi_wpa_eap_ttls_tls(void) { - NMConnection * connection; - NMSettingWireless *s_wireless; - NMSettingIPConfig *s_ip4; - NMSetting8021x * s_8021x; - char * unmanaged = NULL; - const char * expected_privkey_password = "test1"; + gs_unref_object NMConnection *connection = NULL; + NMSettingIPConfig * s_ip4; + NMSetting8021x * s_8021x; + char * unmanaged = NULL; + const char * expected_privkey_password = "test1"; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-eap-ttls-tls", NULL, @@ -3660,20 +3169,12 @@ test_read_wifi_wpa_eap_ttls_tls(void) &unmanaged); g_assert(!unmanaged); - /* ===== WIRELESS SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); - - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); - /* ===== 802.1x SETTING ===== */ - s_8021x = nm_connection_get_setting_802_1x(connection); - g_assert(s_8021x); + s_8021x = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_802_1X); g_assert_cmpint(nm_setting_802_1x_get_num_eap_methods(s_8021x), ==, 1); g_assert_cmpstr(nm_setting_802_1x_get_eap_method(s_8021x, 0), ==, "ttls"); g_assert_cmpstr(nm_setting_802_1x_get_identity(s_8021x), ==, "Chuck Shumer"); @@ -3709,59 +3210,40 @@ test_read_wifi_wpa_eap_ttls_tls(void) TEST_IFCFG_WIFI_WPA_EAP_TLS_PRIVATE_KEY, expected_privkey_password, NM_SETTING_802_1X_PHASE2_PRIVATE_KEY); - - g_object_unref(connection); } static void test_read_wifi_wpa_eap_suite_b_192_tls(void) { - NMConnection * connection; - NMSettingWireless * s_wireless; - NMSettingWirelessSecurity *s_wireless_sec; + gs_unref_object NMConnection *connection = NULL; + NMSettingWirelessSecurity * s_wsec; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-eap-suite-b-192-tls", NULL, TYPE_WIRELESS, NULL); - /* ===== WIRELESS SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); - - /* ===== WIRELESS SECURITY SETTING ===== */ - - s_wireless_sec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wireless_sec); - g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wireless_sec), - ==, - "wpa-eap-suite-b-192"); - - g_object_unref(connection); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); + g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "wpa-eap-suite-b-192"); } static void test_read_wifi_dynamic_wep_leap(void) { - NMConnection * connection; - NMSettingWireless * s_wifi; - NMSettingWirelessSecurity *s_wsec; - NMSetting8021x * s_8021x; + gs_unref_object NMConnection *connection = NULL; + NMSettingWirelessSecurity * s_wsec; + NMSetting8021x * s_8021x; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-dynamic-wep-leap", NULL, TYPE_WIRELESS, NULL); - /* ===== WIRELESS SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - s_wifi = nm_connection_get_setting_wireless(connection); - g_assert(s_wifi); - - /* ===== Wi-Fi SECURITY SETTING ===== */ - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); /* Key management */ g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "ieee8021x"); @@ -3775,9 +3257,7 @@ test_read_wifi_dynamic_wep_leap(void) g_assert_cmpstr(nm_setting_wireless_security_get_leap_username(s_wsec), ==, NULL); g_assert_cmpstr(nm_setting_wireless_security_get_leap_password(s_wsec), ==, NULL); - /* ===== 802.1x SETTING ===== */ - s_8021x = nm_connection_get_setting_802_1x(connection); - g_assert(s_8021x); + s_8021x = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_802_1X); /* EAP method should be "leap" */ g_assert_cmpint(nm_setting_802_1x_get_num_eap_methods(s_8021x), ==, 1); @@ -3786,19 +3266,16 @@ test_read_wifi_dynamic_wep_leap(void) /* username & password */ g_assert_cmpstr(nm_setting_802_1x_get_identity(s_8021x), ==, "bill smith"); g_assert_cmpstr(nm_setting_802_1x_get_password(s_8021x), ==, "foobar baz"); - - g_object_unref(connection); } static void test_read_wifi_wep_eap_ttls_chap(void) { - NMConnection * connection; - NMSettingWireless * s_wireless; - NMSettingWirelessSecurity *s_wsec; - NMSettingIPConfig * s_ip4; - NMSetting8021x * s_8021x; - char * unmanaged = NULL; + gs_unref_object NMConnection *connection = NULL; + NMSettingWirelessSecurity * s_wsec; + NMSettingIPConfig * s_ip4; + NMSetting8021x * s_8021x; + char * unmanaged = NULL; NMTST_EXPECT_NM_WARN("*key ONBOOT is duplicated and the early occurrence ignored*"); connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wep-eap-ttls-chap", @@ -3808,25 +3285,15 @@ test_read_wifi_wep_eap_ttls_chap(void) g_test_assert_expected_messages(); g_assert(!unmanaged); - /* ===== WIRELESS SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); - - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); - /* ===== 802.1x SETTING ===== */ - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "ieee8021x"); - /* ===== 802.1x SETTING ===== */ - s_8021x = nm_connection_get_setting_802_1x(connection); - g_assert(s_8021x); + s_8021x = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_802_1X); /* EAP methods */ g_assert_cmpint(nm_setting_802_1x_get_num_eap_methods(s_8021x), ==, 1); @@ -3841,38 +3308,32 @@ test_read_wifi_wep_eap_ttls_chap(void) g_assert_cmpstr(nm_setting_802_1x_get_phase2_auth(s_8021x), ==, "chap"); g_assert_cmpstr(nm_setting_802_1x_get_identity(s_8021x), ==, "David Smith"); g_assert_cmpstr(nm_setting_802_1x_get_password(s_8021x), ==, "foobar baz"); - - g_object_unref(connection); } static void test_read_wired_wake_on_lan(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-wake-on-lan", NULL, TYPE_WIRELESS, NULL); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), ==, NM_SETTING_WIRED_SETTING_NAME); - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); + s_wired = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); g_assert_cmpint(nm_setting_wired_get_wake_on_lan(s_wired), ==, NM_SETTING_WIRED_WAKE_ON_LAN_ARP | NM_SETTING_WIRED_WAKE_ON_LAN_PHY | NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC); g_assert_cmpstr(nm_setting_wired_get_wake_on_lan_password(s_wired), ==, "00:11:22:33:44:55"); - - g_object_unref(connection); } static void @@ -3887,14 +3348,12 @@ test_read_wired_auto_negotiate_off(void) TYPE_ETHERNET, NULL); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), ==, NM_SETTING_WIRED_SETTING_NAME); - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); + s_wired = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); g_assert(!nm_setting_wired_get_auto_negotiate(s_wired)); g_assert_cmpint(nm_setting_wired_get_speed(s_wired), ==, 100); @@ -3913,14 +3372,12 @@ test_read_wired_auto_negotiate_on(void) TYPE_ETHERNET, NULL); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), ==, NM_SETTING_WIRED_SETTING_NAME); - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); + s_wired = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); g_assert(nm_setting_wired_get_auto_negotiate(s_wired)); g_assert_cmpint(nm_setting_wired_get_speed(s_wired), ==, 0); @@ -3939,14 +3396,12 @@ test_read_wired_unknown_ethtool_opt(void) TYPE_ETHERNET, NULL); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), ==, NM_SETTING_WIRED_SETTING_NAME); - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); + s_wired = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); g_assert(!nm_setting_wired_get_auto_negotiate(s_wired)); g_assert(!nm_setting_wired_get_speed(s_wired)); @@ -3980,8 +3435,8 @@ test_roundtrip_ethtool(void) NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); - s_ethtool = nm_setting_ethtool_new(); - nm_connection_add_setting(connection, s_ethtool); + + s_ethtool = _nm_connection_new_setting(connection, NM_TYPE_SETTING_ETHTOOL); _writer_new_connec_exp(connection, TEST_SCRATCH_DIR, TEST_IFCFG_DIR "/ifcfg-test_roundtrip_ethtool-2.cexpected", @@ -3992,7 +3447,7 @@ test_roundtrip_ethtool(void) NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); - s_wired = nm_connection_get_setting(connection, NM_TYPE_SETTING_WIRED); + s_wired = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); g_object_set(s_wired, NM_SETTING_WIRED_AUTO_NEGOTIATE, TRUE, NULL); _writer_new_connec_exp(connection, TEST_SCRATCH_DIR, @@ -4004,8 +3459,8 @@ test_roundtrip_ethtool(void) NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); - s_ethtool = nm_setting_ethtool_new(); - nm_connection_add_setting(connection, s_ethtool); + + s_ethtool = _nm_connection_new_setting(connection, NM_TYPE_SETTING_ETHTOOL); nm_setting_option_set_boolean(s_ethtool, NM_ETHTOOL_OPTNAME_FEATURE_RX, TRUE); _writer_new_connec_exp(connection, TEST_SCRATCH_DIR, @@ -4017,10 +3472,10 @@ test_roundtrip_ethtool(void) NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); - s_wired = nm_connection_get_setting(connection, NM_TYPE_SETTING_WIRED); + s_wired = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); g_object_set(s_wired, NM_SETTING_WIRED_AUTO_NEGOTIATE, TRUE, NULL); - s_ethtool = nm_setting_ethtool_new(); - nm_connection_add_setting(connection, s_ethtool); + + s_ethtool = _nm_connection_new_setting(connection, NM_TYPE_SETTING_ETHTOOL); nm_setting_option_set_boolean(s_ethtool, NM_ETHTOOL_OPTNAME_FEATURE_RX, TRUE); _writer_new_connec_exp(connection, TEST_SCRATCH_DIR, @@ -4032,24 +3487,20 @@ test_roundtrip_ethtool(void) static void test_read_wifi_hidden(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWireless * s_wifi; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-hidden", NULL, TYPE_WIRELESS, NULL); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), ==, NM_SETTING_WIRELESS_SETTING_NAME); - s_wifi = nm_connection_get_setting_wireless(connection); - g_assert(s_wifi); + s_wifi = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); g_assert(nm_setting_wireless_get_hidden(s_wifi) == TRUE); - - g_object_unref(connection); } static void @@ -4061,15 +3512,12 @@ test_write_wifi_hidden(void) NMSettingConnection * s_con; NMSettingWireless * s_wifi; shvarFile * f; - GBytes * ssid; - const unsigned char ssid_data[] = {0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44}; + gs_unref_bytes GBytes *ssid = + nmtst_gbytes_from_arr(0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44); connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wi-Fi Hidden", @@ -4079,16 +3527,9 @@ test_write_wifi_hidden(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, sizeof(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_HIDDEN, TRUE, NULL); - g_bytes_unref(ssid); - nmtst_assert_connection_verifies(connection); _writer_new_connec_exp(connection, @@ -4121,8 +3562,7 @@ test_read_wifi_mac_random(gconstpointer user_data) path = g_strdup_printf(TEST_IFCFG_DIR "/ifcfg-test-wifi-mac-random-%s", name); connection = _connection_from_file(path, NULL, TYPE_WIRELESS, NULL); - s_wifi = nm_connection_get_setting_wireless(connection); - g_assert(s_wifi); + s_wifi = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); g_assert_cmpint(nm_setting_wireless_get_mac_address_randomization(s_wifi), ==, value); } @@ -4134,10 +3574,10 @@ test_write_wifi_mac_random(gconstpointer user_data) gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; NMSettingWireless * s_wifi; - char * val; + gs_free char * val = NULL; shvarFile * f; - GBytes * ssid; - const unsigned char ssid_data[] = {0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44}; + gs_unref_bytes GBytes *ssid = + nmtst_gbytes_from_arr(0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44); const char * name, *write_expected; gpointer value_p; NMSettingMacRandomization value; @@ -4150,9 +3590,7 @@ test_write_wifi_mac_random(gconstpointer user_data) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); val = g_strdup_printf("Test Write Wi-Fi MAC %s", name); g_object_set(s_con, @@ -4163,13 +3601,8 @@ test_write_wifi_mac_random(gconstpointer user_data) NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free(val); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, sizeof(ssid_data)); + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -4178,7 +3611,6 @@ test_write_wifi_mac_random(gconstpointer user_data) NM_SETTING_WIRELESS_MAC_ADDRESS_RANDOMIZATION, value, NULL); - g_bytes_unref(ssid); nmtst_assert_connection_verifies(connection); @@ -4205,16 +3637,12 @@ test_write_wired_wake_on_lan(void) gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; NMSettingWired * s_wired; - NMSettingWiredWakeOnLan wol; - char * val; + gs_free char * val = NULL; shvarFile * f; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired Wake-on-LAN", @@ -4224,16 +3652,12 @@ test_write_wired_wake_on_lan(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - wol = NM_SETTING_WIRED_WAKE_ON_LAN_MULTICAST | NM_SETTING_WIRED_WAKE_ON_LAN_UNICAST - | NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC; - + s_wired = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); g_object_set(s_wired, NM_SETTING_WIRED_WAKE_ON_LAN, - wol, + (guint) (NM_SETTING_WIRED_WAKE_ON_LAN_MULTICAST + | NM_SETTING_WIRED_WAKE_ON_LAN_UNICAST + | NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC), NM_SETTING_WIRED_WAKE_ON_LAN_PASSWORD, "00:00:00:11:22:33", NULL); @@ -4250,7 +3674,6 @@ test_write_wired_wake_on_lan(void) g_assert(val); g_assert(strstr(val, "wol")); g_assert(strstr(val, "sopass 00:00:00:11:22:33")); - g_free(val); svCloseFile(f); reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); @@ -4265,14 +3688,14 @@ test_write_wired_auto_negotiate_off(void) gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; NMSettingWired * s_wired; - char * val; + gs_free char * val = NULL; shvarFile * f; connection = nmtst_create_minimal_connection("Test Write Wired Auto-Negotiate", NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); - s_wired = nm_connection_get_setting_wired(connection); + s_wired = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); g_object_set(s_wired, NM_SETTING_WIRED_AUTO_NEGOTIATE, FALSE, @@ -4293,7 +3716,6 @@ test_write_wired_auto_negotiate_off(void) g_assert(strstr(val, "autoneg off")); g_assert(strstr(val, "speed 10")); g_assert(strstr(val, "duplex half")); - g_free(val); svCloseFile(f); reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); @@ -4309,20 +3731,19 @@ test_write_wired_auto_negotiate_on(void) gs_unref_object NMConnection *reread = NULL; NMSettingWired * s_wired; NMSettingEthtool * s_ethtool; - char * val; + gs_free char * val = NULL; shvarFile * f; connection = nmtst_create_minimal_connection("Test Write Wired Auto-Negotiate", NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); - s_wired = nm_connection_get_setting_wired(connection); + s_wired = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); g_object_set(s_wired, NM_SETTING_WIRED_AUTO_NEGOTIATE, TRUE, NULL); - s_ethtool = NM_SETTING_ETHTOOL(nm_setting_ethtool_new()); + s_ethtool = _nm_connection_new_setting(connection, NM_TYPE_SETTING_ETHTOOL); nm_setting_ethtool_set_feature(s_ethtool, NM_ETHTOOL_OPTNAME_FEATURE_TX, NM_TERNARY_TRUE); nm_setting_ethtool_set_feature(s_ethtool, NM_ETHTOOL_OPTNAME_FEATURE_RXVLAN, NM_TERNARY_FALSE); - nm_connection_add_setting(connection, NM_SETTING(s_ethtool)); _writer_new_connec_exp(connection, TEST_SCRATCH_DIR, @@ -4335,7 +3756,6 @@ test_write_wired_auto_negotiate_on(void) g_assert(strstr(val, "autoneg on")); g_assert(!strstr(val, "speed")); g_assert(!strstr(val, "duplex")); - g_free(val); svCloseFile(f); reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); @@ -4344,8 +3764,7 @@ test_write_wired_auto_negotiate_on(void) nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); - s_ethtool = NM_SETTING_ETHTOOL(nm_connection_get_setting(reread, NM_TYPE_SETTING_ETHTOOL)); - g_assert(s_ethtool); + s_ethtool = nmtst_connection_assert_setting(reread, NM_TYPE_SETTING_ETHTOOL); g_assert_cmpint(nm_setting_ethtool_get_feature(s_ethtool, NM_ETHTOOL_OPTNAME_FEATURE_TX), ==, NM_TERNARY_TRUE); @@ -4360,24 +3779,20 @@ test_write_wired_auto_negotiate_on(void) static void test_read_wifi_band_a(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWireless * s_wifi; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-band-a", NULL, TYPE_WIRELESS, NULL); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), ==, NM_SETTING_WIRELESS_SETTING_NAME); - s_wifi = nm_connection_get_setting_wireless(connection); - g_assert(s_wifi); + s_wifi = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); g_assert_cmpstr(nm_setting_wireless_get_band(s_wifi), ==, "a"); - - g_object_unref(connection); } static void @@ -4389,15 +3804,12 @@ test_write_wifi_band_a(void) NMSettingConnection * s_con; NMSettingWireless * s_wifi; shvarFile * f; - GBytes * ssid; - const unsigned char ssid_data[] = {0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44}; + gs_unref_bytes GBytes *ssid = + nmtst_gbytes_from_arr(0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44); connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wi-Fi Band A", @@ -4407,12 +3819,7 @@ test_write_wifi_band_a(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, sizeof(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -4422,8 +3829,6 @@ test_write_wifi_band_a(void) "a", NULL); - g_bytes_unref(ssid); - nmtst_assert_connection_verifies(connection); _writer_new_connec_exp(connection, @@ -4448,14 +3853,11 @@ test_write_wifi_ap_mode(void) gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; NMSettingWireless * s_wifi; - gs_unref_bytes GBytes *ssid = NULL; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("MySSID"); connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wi-Fi AP Mode", @@ -4465,12 +3867,7 @@ test_write_wifi_ap_mode(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new("MySSID", NM_STRLEN("MySSID")); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -4523,12 +3920,12 @@ test_read_wifi_band_bg_channel_mismatch(void) static void test_read_wired_qeth_static(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - char * unmanaged = NULL; - const char *const * subchannels; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + char * unmanaged = NULL; + const char *const * subchannels; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-qeth-static", NULL, @@ -4536,16 +3933,10 @@ test_read_wired_qeth_static(void) &unmanaged); g_assert(!unmanaged); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-wired-qeth-static"); - /* ===== WIRED SETTING ===== */ - - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); + s_wired = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); g_assert(!nm_setting_wired_get_mac_address(s_wired)); @@ -4563,25 +3954,20 @@ test_read_wired_qeth_static(void) g_assert_cmpstr(nm_setting_wired_get_s390_option_by_key(s_wired, "portno"), ==, "0"); g_assert_cmpstr(nm_setting_wired_get_s390_option_by_key(s_wired, "layer2"), ==, "1"); - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL); - - g_object_unref(connection); } static void test_read_wired_ctc_static(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; - char * unmanaged = NULL; - const char *const * subchannels; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + char * unmanaged = NULL; + const char *const * subchannels; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-ctc-static", NULL, @@ -4589,14 +3975,10 @@ test_read_wired_ctc_static(void) &unmanaged); g_assert(unmanaged == NULL); - /* ===== CONNECTION SETTING ===== */ - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con != NULL); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-wired-ctc-static"); - /* ===== WIRED SETTING ===== */ - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired != NULL); + s_wired = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); g_assert(nm_setting_wired_get_mac_address(s_wired) == NULL); @@ -4610,28 +3992,22 @@ test_read_wired_ctc_static(void) g_assert_cmpstr(nm_setting_wired_get_s390_nettype(s_wired), ==, "ctc"); g_assert_cmpstr(nm_setting_wired_get_s390_option_by_key(s_wired, "ctcprot"), ==, "0"); - - g_object_unref(connection); } static void test_read_wifi_wep_no_keys(void) { - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWireless * s_wireless; - NMSettingWirelessSecurity *s_wsec; - NMWepKeyType key_type; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWirelessSecurity * s_wsec; + NMWepKeyType key_type; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wep-no-keys", NULL, TYPE_WIRELESS, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System foobar (test-wifi-wep-no-keys)"); @@ -4641,15 +4017,9 @@ test_read_wifi_wep_no_keys(void) * depending on where the tests are run. */ - /* ===== WIRELESS SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - s_wireless = nm_connection_get_setting_wireless(connection); - g_assert(s_wireless); - - /* ===== WIRELESS SECURITY SETTING ===== */ - - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); /* Key management */ g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "none"); @@ -4663,26 +4033,21 @@ test_read_wifi_wep_no_keys(void) /* WEP key index 0; we don't expect it to be filled */ g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 0)); - - g_object_unref(connection); } static void test_read_permissions(void) { - NMConnection * connection; - NMSettingConnection *s_con; - gboolean success; - guint32 num; - const char * tmp; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + gboolean success; + guint32 num; + const char * tmp; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-permissions", NULL, TYPE_ETHERNET, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); num = nm_setting_connection_get_num_permissions(s_con); g_assert_cmpint(num, ==, 3); @@ -4702,18 +4067,15 @@ test_read_permissions(void) success = nm_setting_connection_get_permission(s_con, 2, NULL, &tmp, NULL); g_assert(success); g_assert_cmpstr(tmp, ==, "johnny5"); - - g_object_unref(connection); } static void test_read_wifi_wep_agent_keys(void) { - NMConnection * connection; - NMSettingWireless * s_wifi; - NMSettingWirelessSecurity *s_wsec; - NMWepKeyType key_type; - NMSettingSecretFlags flags; + gs_unref_object NMConnection *connection = NULL; + NMSettingWirelessSecurity * s_wsec; + NMWepKeyType key_type; + NMSettingSecretFlags flags; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wep-agent-keys", NULL, @@ -4724,13 +4086,9 @@ test_read_wifi_wep_agent_keys(void) * we don't have any WEP keys because they are agent owned. */ - /* ===== WIRELESS SETTING ===== */ - s_wifi = nm_connection_get_setting_wireless(connection); - g_assert(s_wifi); + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS); - /* ===== WIRELESS SECURITY SETTING ===== */ - s_wsec = nm_connection_get_setting_wireless_security(connection); - g_assert(s_wsec); + s_wsec = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_assert(strcmp(nm_setting_wireless_security_get_key_mgmt(s_wsec), "none") == 0); g_assert(nm_setting_wireless_security_get_wep_tx_keyidx(s_wsec) == 0); @@ -4743,8 +4101,6 @@ test_read_wifi_wep_agent_keys(void) flags = nm_setting_wireless_security_get_wep_key_flags(s_wsec); g_assert(flags & NM_SETTING_SECRET_FLAG_AGENT_OWNED); - - g_object_unref(connection); } static void @@ -4765,10 +4121,7 @@ test_write_wired_static(void) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired Static", @@ -4782,10 +4135,7 @@ test_write_wired_static(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - + s_wired = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); g_object_set(s_wired, NM_SETTING_WIRED_MAC_ADDRESS, "31:33:33:37:be:cd", @@ -4793,10 +4143,7 @@ test_write_wired_static(void) (guint32) 1492, NULL); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, @@ -4824,10 +4171,7 @@ test_write_wired_static(void) nm_setting_ip_config_add_dns_search(s_ip4, "foobar.com"); nm_setting_ip_config_add_dns_search(s_ip4, "lab.foobar.com"); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL, @@ -4891,13 +4235,13 @@ test_write_wired_static(void) reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); - reread_s_ip4 = nm_connection_get_setting_ip4_config(reread); - reread_s_ip6 = nm_connection_get_setting_ip6_config(reread); + reread_s_ip4 = nmtst_connection_assert_setting(reread, NM_TYPE_SETTING_IP4_CONFIG); + reread_s_ip6 = nmtst_connection_assert_setting(reread, NM_TYPE_SETTING_IP6_CONFIG); g_assert_cmpint(nm_setting_ip_config_get_route_metric(reread_s_ip4), ==, 204); g_assert_cmpint(nm_setting_ip_config_get_route_metric(reread_s_ip6), ==, 206); - nm_connection_add_setting(connection, nm_setting_proxy_new()); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_PROXY); nmtst_assert_connection_equals(connection, FALSE, reread, FALSE); } @@ -4920,10 +4264,7 @@ test_write_wired_static_with_generic(void) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired Static", @@ -4937,10 +4278,7 @@ test_write_wired_static_with_generic(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - + s_wired = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); g_object_set(s_wired, NM_SETTING_WIRED_MAC_ADDRESS, "31:33:33:37:be:cd", @@ -4948,10 +4286,7 @@ test_write_wired_static_with_generic(void) (guint32) 1492, NULL); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, @@ -4979,10 +4314,7 @@ test_write_wired_static_with_generic(void) nm_setting_ip_config_add_dns_search(s_ip4, "foobar.com"); nm_setting_ip_config_add_dns_search(s_ip4, "lab.foobar.com"); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL, @@ -5039,21 +4371,22 @@ test_write_wired_static_with_generic(void) nm_setting_ip_config_add_dns_search(s_ip6, "foobar6.com"); nm_setting_ip_config_add_dns_search(s_ip6, "lab6.foobar.com"); - nm_connection_add_setting(connection, nm_setting_generic_new()); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_GENERIC); nmtst_assert_connection_verifies(connection); _writer_new_connection_FIXME(connection, TEST_SCRATCH_DIR, &testfile); route6file = utils_get_route6_path(testfile); - reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); - reread_s_ip4 = nm_connection_get_setting_ip4_config(reread); - reread_s_ip6 = nm_connection_get_setting_ip6_config(reread); + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + reread_s_ip4 = nmtst_connection_assert_setting(reread, NM_TYPE_SETTING_IP4_CONFIG); + reread_s_ip6 = nmtst_connection_assert_setting(reread, NM_TYPE_SETTING_IP6_CONFIG); g_assert_cmpint(nm_setting_ip_config_get_route_metric(reread_s_ip4), ==, 204); g_assert_cmpint(nm_setting_ip_config_get_route_metric(reread_s_ip6), ==, 206); - nm_connection_add_setting(connection, nm_setting_proxy_new()); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_PROXY); { gs_unref_hashtable GHashTable *diffs = NULL; @@ -5064,8 +4397,8 @@ test_write_wired_static_with_generic(void) g_assert(g_hash_table_lookup(diffs, "generic")); g_assert(!nm_connection_compare(connection, reread, NM_SETTING_COMPARE_FLAG_EXACT)); } - g_assert(!nm_connection_get_setting(reread, NM_TYPE_SETTING_GENERIC)); - nm_connection_add_setting(reread, nm_setting_generic_new()); + nmtst_connection_assert_no_setting(reread, NM_TYPE_SETTING_GENERIC); + _nm_connection_new_setting(reread, NM_TYPE_SETTING_GENERIC); { gs_unref_hashtable GHashTable *diffs = NULL; @@ -5082,16 +4415,12 @@ test_write_wired_dhcp(void) gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; - NMSettingWired * s_wired; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired DHCP", @@ -5103,14 +4432,9 @@ test_write_wired_dhcp(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, @@ -5130,10 +4454,7 @@ test_write_wired_dhcp(void) nmtst_assert_connection_verifies(connection); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_DHCP, @@ -5195,15 +4516,12 @@ test_write_routing_rules(void) gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; - NMSettingWired * s_wired; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; connection = nm_simple_connection_new(); - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Routing Rules", @@ -5215,17 +4533,12 @@ test_write_routing_rules(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL); _ip_routing_rule_add_to_setting(s_ip4, "pref 10 from 0.0.0.0/0 table 1"); @@ -5251,17 +4564,13 @@ test_write_wired_match(void) gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; - NMSettingWired * s_wired; NMSettingMatch * s_match; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired with Match setting", @@ -5273,20 +4582,12 @@ test_write_wired_match(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -5294,15 +4595,13 @@ test_write_wired_match(void) (int) NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64, NULL); - /* Match setting */ - s_match = (NMSettingMatch *) nm_setting_match_new(); + s_match = _nm_connection_new_setting(connection, NM_TYPE_SETTING_MATCH); nm_setting_match_add_interface_name(s_match, "ens*"); nm_setting_match_add_interface_name(s_match, "eth 1?"); nm_setting_match_add_interface_name(s_match, "!veth*"); nm_setting_match_add_driver(s_match, "!virtio"); nm_setting_match_add_driver(s_match, "e1000e"); nm_setting_match_add_kernel_command_line(s_match, "!ip="); - nm_connection_add_setting(connection, NM_SETTING(s_match)); nmtst_assert_connection_verifies(connection); _writer_new_connec_exp(connection, @@ -5348,10 +4647,8 @@ test_read_write_wired_dhcp_send_hostname(void) NULL); /* Check dhcp-hostname and dhcp-send-hostname */ - s_ip4 = nm_connection_get_setting_ip4_config(connection); - s_ip6 = nm_connection_get_setting_ip6_config(connection); - g_assert(s_ip4); - g_assert(s_ip6); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); + s_ip6 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_assert(nm_setting_ip_config_get_dhcp_send_hostname(s_ip4) == TRUE); g_assert_cmpstr(nm_setting_ip_config_get_dhcp_hostname(s_ip4), ==, "svata-pulec"); g_assert(!nm_setting_ip_config_get_dhcp_hostname(s_ip6)); @@ -5368,10 +4665,8 @@ test_read_write_wired_dhcp_send_hostname(void) nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); /* Check dhcp-hostname and dhcp-send-hostname from the re-read connection. */ - s_ip4 = nm_connection_get_setting_ip4_config(reread); - s_ip6 = nm_connection_get_setting_ip6_config(reread); - g_assert(s_ip4); - g_assert(s_ip6); + s_ip4 = nmtst_connection_assert_setting(reread, NM_TYPE_SETTING_IP4_CONFIG); + s_ip6 = nmtst_connection_assert_setting(reread, NM_TYPE_SETTING_IP6_CONFIG); g_assert(nm_setting_ip_config_get_dhcp_send_hostname(s_ip4) == FALSE); g_assert_cmpstr(nm_setting_ip_config_get_dhcp_hostname(s_ip4), ==, dhcp_hostname); g_assert_cmpstr(nm_setting_ip_config_get_dhcp_hostname(s_ip6), ==, dhcp_hostname); @@ -5388,8 +4683,7 @@ test_read_wired_dhcpv6_hostname_fallback(void) TYPE_ETHERNET, NULL); - s_ip6 = nm_connection_get_setting_ip6_config(connection); - g_assert(s_ip6); + s_ip6 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_assert(nm_setting_ip_config_get_dhcp_send_hostname(s_ip6) == TRUE); g_assert_cmpstr(nm_setting_ip_config_get_dhcp_hostname(s_ip6), ==, "fully.qualified.domain"); } @@ -5409,10 +4703,7 @@ test_write_wired_static_ip6_only(void) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired Static IP6 Only", @@ -5424,22 +4715,13 @@ test_write_wired_static_ip6_only(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - + s_wired = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); g_object_set(s_wired, NM_SETTING_WIRED_MAC_ADDRESS, "31:33:33:37:be:cd", NULL); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_DISABLED, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL, NULL); /* Add addresses */ @@ -5467,7 +4749,6 @@ test_write_ip6_disabled(void) gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; - NMSettingWired * s_wired; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; @@ -5476,15 +4757,12 @@ test_write_ip6_disabled(void) NM_SETTING_WIRED_SETTING_NAME, &s_con); - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_DISABLED, @@ -5523,16 +4801,14 @@ test_write_wired_static_ip6_only_gw(gconstpointer user_data) NMSettingIPConfig * s_ip6; NMIPAddress * addr6; GError * error = NULL; - char * id = NULL; + gs_free char * id = NULL; gs_free char * written_ifcfg_gateway = NULL; const char * gateway6 = user_data; shvarFile * ifcfg; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); id = g_strdup_printf("Test Write Wired Static IP6 Only With Gateway %s", gateway6 ?: "NULL"); g_object_set(s_con, @@ -5545,24 +4821,14 @@ test_write_wired_static_ip6_only_gw(gconstpointer user_data) NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free(id); - - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); + s_wired = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); g_object_set(s_wired, NM_SETTING_WIRED_MAC_ADDRESS, "31:33:33:37:be:cd", NULL); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_DISABLED, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL, @@ -5592,8 +4858,8 @@ test_write_wired_static_ip6_only_gw(gconstpointer user_data) svCloseFile(ifcfg); /* access the gateway from the loaded connection. */ - s_ip6 = nm_connection_get_setting_ip6_config(reread); - g_assert(s_ip6 && nm_setting_ip_config_get_num_addresses(s_ip6) == 1); + s_ip6 = nmtst_connection_assert_setting(reread, NM_TYPE_SETTING_IP6_CONFIG); + g_assert(nm_setting_ip_config_get_num_addresses(s_ip6) == 1); addr6 = nm_setting_ip_config_get_address(s_ip6, 0); g_assert(addr6); @@ -5617,7 +4883,6 @@ test_read_write_static_routes_legacy(void) gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; - NMSettingWired * s_wired; NMSettingIPConfig * s_ip4; const char * tmp; @@ -5626,10 +4891,7 @@ test_read_write_static_routes_legacy(void) TYPE_ETHERNET, NULL); - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); /* ID */ tmp = nm_setting_connection_get_id(s_con); @@ -5638,15 +4900,9 @@ test_read_write_static_routes_legacy(void) /* Autoconnect */ g_assert(nm_setting_connection_get_autoconnect(s_con)); - /* ===== WIRED SETTING ===== */ + nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); - - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config(connection); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); g_assert(!nm_setting_ip_config_get_never_default(s_ip4)); @@ -5686,10 +4942,7 @@ test_write_wired_static_routes(void) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired Static Routes", @@ -5701,10 +4954,7 @@ test_write_wired_static_routes(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - + s_wired = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); g_object_set(s_wired, NM_SETTING_WIRED_MAC_ADDRESS, "31:33:33:37:be:cd", @@ -5712,10 +4962,7 @@ test_write_wired_static_routes(void) (guint32) 1492, NULL); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, @@ -5756,10 +5003,7 @@ test_write_wired_static_routes(void) nm_setting_ip_config_add_dns_search(s_ip4, "foobar.com"); nm_setting_ip_config_add_dns_search(s_ip4, "lab.foobar.com"); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -5782,8 +5026,7 @@ test_write_wired_static_routes(void) * connection equals. */ g_assert(!reread_same); nmtst_assert_connection_verifies_without_normalization(reread); - s_ip4 = nm_connection_get_setting_ip4_config(reread); - g_assert(s_ip4); + s_ip4 = nmtst_connection_assert_setting(reread, NM_TYPE_SETTING_IP4_CONFIG); g_assert_cmpint(nm_setting_ip_config_get_num_routes(s_ip4), ==, 2); route = nm_setting_ip_config_get_route(s_ip4, 1); g_assert(route); @@ -5803,7 +5046,6 @@ test_write_wired_dhcp_8021x_peap_mschapv2(void) gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; - NMSettingWired * s_wired; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; NMSetting8021x * s_8021x; @@ -5812,10 +5054,7 @@ test_write_wired_dhcp_8021x_peap_mschapv2(void) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired DHCP 802.1x PEAP MSCHAPv2", @@ -5827,20 +5066,12 @@ test_write_wired_dhcp_8021x_peap_mschapv2(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -5850,10 +5081,7 @@ test_write_wired_dhcp_8021x_peap_mschapv2(void) (int) NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64, NULL); - /* 802.1x setting */ - s_8021x = (NMSetting8021x *) nm_setting_802_1x_new(); - nm_connection_add_setting(connection, NM_SETTING(s_8021x)); - + s_8021x = _nm_connection_new_setting(connection, NM_TYPE_SETTING_802_1X); g_object_set(s_8021x, NM_SETTING_802_1X_IDENTITY, "Bob Saget", @@ -5868,7 +5096,6 @@ test_write_wired_dhcp_8021x_peap_mschapv2(void) NM_SETTING_802_1X_PHASE2_AUTH, "mschapv2", NULL); - nm_setting_802_1x_add_eap_method(s_8021x, "peap"); success = nm_setting_802_1x_set_ca_cert(s_8021x, @@ -5897,7 +5124,6 @@ test_write_wired_8021x_tls(gconstpointer test_data) gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; - NMSettingWired * s_wired; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; NMSetting8021x * s_8021x; @@ -5905,7 +5131,9 @@ test_write_wired_8021x_tls(gconstpointer test_data) GError * error = NULL; NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; const char * pw; - char * tmp; + gs_free char * tmp1 = NULL; + gs_free char * tmp2 = NULL; + gs_free char * tmp3 = NULL; gpointer scheme_p, flags_p; NMSetting8021xCKScheme scheme; NMSettingSecretFlags flags; @@ -5916,10 +5144,7 @@ test_write_wired_8021x_tls(gconstpointer test_data) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired 802.1x TLS Blobs", @@ -5931,29 +5156,20 @@ test_write_wired_8021x_tls(gconstpointer test_data) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - - /* 802.1x setting */ - s_8021x = (NMSetting8021x *) nm_setting_802_1x_new(); - nm_connection_add_setting(connection, NM_SETTING(s_8021x)); + s_8021x = _nm_connection_new_setting(connection, NM_TYPE_SETTING_802_1X); g_object_set(s_8021x, NM_SETTING_802_1X_IDENTITY, "Bill Smith", NULL); nm_setting_802_1x_add_eap_method(s_8021x, "tls"); @@ -6006,8 +5222,7 @@ test_write_wired_8021x_tls(gconstpointer test_data) * matter what scheme was used in the original connection they will be read * back in as paths. */ - s_8021x = nm_connection_get_setting_802_1x(reread); - g_assert(s_8021x); + s_8021x = nmtst_connection_assert_setting(reread, NM_TYPE_SETTING_802_1X); g_assert_cmpint(nm_setting_802_1x_get_ca_cert_scheme(s_8021x), ==, NM_SETTING_802_1X_CK_SCHEME_PATH); @@ -6041,7 +5256,7 @@ test_write_wired_8021x_tls(gconstpointer test_data) * say it's not system-owned, and therefore it should not show up * in the re-read connection. */ - s_8021x = nm_connection_get_setting_802_1x(connection); + s_8021x = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_802_1X); g_object_set(s_8021x, NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD, NULL, NULL); } @@ -6049,17 +5264,14 @@ test_write_wired_8021x_tls(gconstpointer test_data) } /* Clean up created certs and keys */ - tmp = utils_cert_path(testfile, "ca-cert", "der"); - nmtst_file_unlink_if_exists(tmp); - g_free(tmp); + tmp1 = utils_cert_path(testfile, "ca-cert", "der"); + nmtst_file_unlink_if_exists(tmp1); - tmp = utils_cert_path(testfile, "client-cert", "der"); - nmtst_file_unlink_if_exists(tmp); - g_free(tmp); + tmp2 = utils_cert_path(testfile, "client-cert", "der"); + nmtst_file_unlink_if_exists(tmp2); - tmp = utils_cert_path(testfile, "private-key", "pem"); - nmtst_file_unlink_if_exists(tmp); - g_free(tmp); + tmp3 = utils_cert_path(testfile, "private-key", "pem"); + nmtst_file_unlink_if_exists(tmp3); } static void @@ -6069,7 +5281,6 @@ test_write_wired_aliases(void) gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; - NMSettingWired * s_wired; NMSettingIPConfig * s_ip4; int num_addresses = 4; const char * ip[] = {"1.1.1.1", "1.1.1.2", "1.1.1.3", "1.1.1.4"}; @@ -6086,10 +5297,7 @@ test_write_wired_aliases(void) connection = nm_simple_connection_new(); g_assert(connection); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "alias0", @@ -6099,14 +5307,9 @@ test_write_wired_aliases(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, @@ -6159,7 +5362,7 @@ test_write_wired_aliases(void) * aliases get read back in essentially random order. So just * verify the aliases manually. */ - s_ip4 = nm_connection_get_setting_ip4_config(connection); + s_ip4 = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_assert(nm_setting_ip_config_get_num_addresses(s_ip4) == num_addresses); /* Addresses */ @@ -6205,7 +5408,6 @@ test_write_gateway(void) gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; - NMSettingWired * s_wired; NMSettingIPConfig * s_ip4; GError * error = NULL; shvarFile * f; @@ -6213,10 +5415,7 @@ test_write_gateway(void) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Static Addresses Gateway", @@ -6226,14 +5425,9 @@ test_write_gateway(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, @@ -6284,16 +5478,13 @@ test_write_wifi_open(void) NMSettingWireless * s_wifi; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - GBytes * ssid; - const unsigned char ssid_data[] = {0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44}; - shvarFile * ifcfg; + gs_unref_bytes GBytes *ssid = + nmtst_gbytes_from_arr(0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44); + shvarFile *ifcfg; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi Open", @@ -6305,12 +5496,7 @@ test_write_wifi_open(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, sizeof(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -6328,18 +5514,10 @@ test_write_wifi_open(void) (guint32) 1345, NULL); - g_bytes_unref(ssid); - - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -6372,16 +5550,23 @@ test_write_wifi_open_hex_ssid(void) NMSettingWireless * s_wifi; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - GBytes * ssid; - const unsigned char ssid_data[] = - {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd}; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_arr(0x11, + 0x22, + 0x33, + 0x44, + 0x55, + 0x66, + 0x77, + 0x88, + 0x99, + 0xaa, + 0xbb, + 0xcc, + 0xdd); connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi Open Hex SSID", @@ -6393,12 +5578,7 @@ test_write_wifi_open_hex_ssid(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, sizeof(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -6406,18 +5586,10 @@ test_write_wifi_open_hex_ssid(void) "infrastructure", NULL); - g_bytes_unref(ssid); - - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -6446,16 +5618,12 @@ test_write_wifi_wep(void) NMSettingWirelessSecurity * s_wsec; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - GBytes * ssid; - const char * ssid_data = "blahblah"; - struct stat statbuf; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); + struct stat statbuf; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WEP", @@ -6467,12 +5635,7 @@ test_write_wifi_wep(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, strlen(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -6480,12 +5643,7 @@ test_write_wifi_wep(void) "infrastructure", NULL); - g_bytes_unref(ssid); - - /* Wireless security setting */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); - + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none", @@ -6499,16 +5657,10 @@ test_write_wifi_wep(void) nm_setting_wireless_security_set_wep_key(s_wsec, 2, "aaaaaaaaaaaaaaaaaaaaaaaaaa"); nm_setting_wireless_security_set_wep_key(s_wsec, 3, "BBBBBBBBBBBBBBBBBBBBBBBBBB"); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -6545,17 +5697,13 @@ test_write_wifi_wep_adhoc(void) NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; GError * error = NULL; - GBytes * ssid; - const char * ssid_data = "blahblah"; - struct stat statbuf; - NMIPAddress * addr; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); + struct stat statbuf; + NMIPAddress * addr; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WEP AdHoc", @@ -6567,27 +5715,14 @@ test_write_wifi_wep_adhoc(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, strlen(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_MODE, "adhoc", NULL); - g_bytes_unref(ssid); - - /* Wireless security setting */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); - + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none", NULL); nm_setting_wireless_security_set_wep_key(s_wsec, 0, "0123456789abcdef0123456789"); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, @@ -6603,10 +5738,7 @@ test_write_wifi_wep_adhoc(void) nm_setting_ip_config_add_dns(s_ip4, "4.2.2.1"); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -6640,16 +5772,12 @@ test_write_wifi_wep_passphrase(void) NMSettingWirelessSecurity * s_wsec; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - GBytes * ssid; - const char * ssid_data = "blahblah"; - struct stat statbuf; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); + struct stat statbuf; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WEP Passphrase", @@ -6661,12 +5789,7 @@ test_write_wifi_wep_passphrase(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, strlen(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -6674,12 +5797,7 @@ test_write_wifi_wep_passphrase(void) "infrastructure", NULL); - g_bytes_unref(ssid); - - /* Wireless security setting */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); - + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none", @@ -6692,16 +5810,10 @@ test_write_wifi_wep_passphrase(void) NULL); nm_setting_wireless_security_set_wep_key(s_wsec, 0, "asdfdjaslfjasd;flasjdfl;aksdf"); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -6735,16 +5847,12 @@ test_write_wifi_wep_40_ascii(void) NMSettingWirelessSecurity * s_wsec; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - GBytes * ssid; - const char * ssid_data = "blahblah40"; - struct stat statbuf; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah40"); + struct stat statbuf; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WEP 40 ASCII", @@ -6756,12 +5864,7 @@ test_write_wifi_wep_40_ascii(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, strlen(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -6769,12 +5872,7 @@ test_write_wifi_wep_40_ascii(void) "infrastructure", NULL); - g_bytes_unref(ssid); - - /* Wireless security setting */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); - + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none", @@ -6790,16 +5888,10 @@ test_write_wifi_wep_40_ascii(void) nm_setting_wireless_security_set_wep_key(s_wsec, 2, "dolor"); nm_setting_wireless_security_set_wep_key(s_wsec, 3, "donec"); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -6833,16 +5925,12 @@ test_write_wifi_wep_104_ascii(void) NMSettingWirelessSecurity * s_wsec; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - GBytes * ssid; - const char * ssid_data = "blahblah104"; - struct stat statbuf; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah104"); + struct stat statbuf; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WEP 104 ASCII", @@ -6854,12 +5942,7 @@ test_write_wifi_wep_104_ascii(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, strlen(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -6867,12 +5950,7 @@ test_write_wifi_wep_104_ascii(void) "infrastructure", NULL); - g_bytes_unref(ssid); - - /* Wireless security setting */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); - + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none", @@ -6888,16 +5966,10 @@ test_write_wifi_wep_104_ascii(void) nm_setting_wireless_security_set_wep_key(s_wsec, 2, "WEP-104 ASCII"); nm_setting_wireless_security_set_wep_key(s_wsec, 3, "thisismyascii"); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -6934,16 +6006,12 @@ test_write_wifi_leap(void) NMSettingWirelessSecurity * s_wsec; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - GBytes * ssid; - const char * ssid_data = "blahblah"; - struct stat statbuf; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); + struct stat statbuf; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi LEAP", @@ -6955,12 +6023,7 @@ test_write_wifi_leap(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, strlen(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -6968,12 +6031,7 @@ test_write_wifi_leap(void) "infrastructure", NULL); - g_bytes_unref(ssid); - - /* Wireless security setting */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); - + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x", @@ -6985,16 +6043,10 @@ test_write_wifi_leap(void) "foobar22", NULL); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -7031,17 +6083,13 @@ test_write_wifi_leap_secret_flags(gconstpointer data) NMSettingWirelessSecurity * s_wsec; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - GBytes * ssid; - const char * ssid_data = "blahblah"; - NMSettingSecretFlags flags = GPOINTER_TO_UINT(data); + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); + NMSettingSecretFlags flags = GPOINTER_TO_UINT(data); connection = nm_simple_connection_new(); g_assert(connection); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi LEAP Secret Flags", @@ -7051,23 +6099,15 @@ test_write_wifi_leap_secret_flags(gconstpointer data) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, strlen(ssid_data)); + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_MODE, "infrastructure", NULL); - g_bytes_unref(ssid); - - /* Wireless security setting */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x", @@ -7081,15 +6121,10 @@ test_write_wifi_leap_secret_flags(gconstpointer data) flags, NULL); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -7126,8 +6161,7 @@ test_write_wifi_wpa_psk(gconstpointer test_data) NMSettingWirelessSecurity * s_wsec; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - GBytes * ssid; - const char * ssid_data = "blahblah"; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); struct { const char *name, *psk; gpointer wep_group_p, wpa_p, wpa2_p; @@ -7144,10 +6178,7 @@ test_write_wifi_wpa_psk(gconstpointer test_data) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, args.name, @@ -7159,12 +6190,7 @@ test_write_wifi_wpa_psk(gconstpointer test_data) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, strlen(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -7172,12 +6198,7 @@ test_write_wifi_wpa_psk(gconstpointer test_data) "infrastructure", NULL); - g_bytes_unref(ssid); - - /* Wireless security setting */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); - + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-psk", @@ -7202,16 +6223,10 @@ test_write_wifi_wpa_psk(gconstpointer test_data) nm_setting_wireless_security_add_group(s_wsec, "ccmp"); } - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -7243,16 +6258,12 @@ test_write_wifi_wpa_psk_adhoc(void) NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; GError * error = NULL; - GBytes * ssid; - const char * ssid_data = "blahblah"; - NMIPAddress * addr; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); + NMIPAddress * addr; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WPA PSK", @@ -7264,12 +6275,7 @@ test_write_wifi_wpa_psk_adhoc(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, strlen(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -7281,12 +6287,7 @@ test_write_wifi_wpa_psk_adhoc(void) "bg", NULL); - g_bytes_unref(ssid); - - /* Wireless security setting */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); - + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-psk", @@ -7298,10 +6299,7 @@ test_write_wifi_wpa_psk_adhoc(void) nm_setting_wireless_security_add_pairwise(s_wsec, "ccmp"); nm_setting_wireless_security_add_group(s_wsec, "ccmp"); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, @@ -7317,10 +6315,7 @@ test_write_wifi_wpa_psk_adhoc(void) nm_setting_ip_config_add_dns(s_ip4, "4.2.2.1"); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -7354,15 +6349,11 @@ test_write_wifi_wpa_eap_tls(void) NMSettingIPConfig * s_ip6; gboolean success; GError * error = NULL; - GBytes * ssid; - const char * ssid_data = "blahblah"; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WPA EAP-TLS", @@ -7374,12 +6365,7 @@ test_write_wifi_wpa_eap_tls(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, strlen(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -7387,12 +6373,7 @@ test_write_wifi_wpa_eap_tls(void) "infrastructure", NULL); - g_bytes_unref(ssid); - - /* Wireless security setting */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); - + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-eap", @@ -7403,17 +6384,14 @@ test_write_wifi_wpa_eap_tls(void) nm_setting_wireless_security_add_pairwise(s_wsec, "tkip"); nm_setting_wireless_security_add_group(s_wsec, "tkip"); - /* Wireless security setting */ - s_8021x = (NMSetting8021x *) nm_setting_802_1x_new(); - nm_connection_add_setting(connection, NM_SETTING(s_8021x)); - - g_object_set(s_8021x, NM_SETTING_802_1X_IDENTITY, "Bill Smith", NULL); + s_8021x = _nm_connection_new_setting(connection, NM_TYPE_SETTING_802_1X); g_object_set(s_8021x, + NM_SETTING_802_1X_IDENTITY, + "Bill Smith", NM_SETTING_802_1X_PHASE1_AUTH_FLAGS, (guint) (NM_SETTING_802_1X_AUTH_FLAGS_TLS_1_0_DISABLE | NM_SETTING_802_1X_AUTH_FLAGS_TLS_1_1_DISABLE), NULL); - nm_setting_802_1x_add_eap_method(s_8021x, "tls"); success = nm_setting_802_1x_set_ca_cert(s_8021x, @@ -7438,16 +6416,10 @@ test_write_wifi_wpa_eap_tls(void) &error); nmtst_assert_success(success, error); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -7481,15 +6453,11 @@ test_write_wifi_wpa_eap_ttls_tls(void) NMSettingIPConfig * s_ip6; gboolean success; GError * error = NULL; - GBytes * ssid; - const char * ssid_data = "blahblah"; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WPA EAP-TTLS (TLS)", @@ -7501,12 +6469,7 @@ test_write_wifi_wpa_eap_ttls_tls(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, strlen(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -7514,23 +6477,14 @@ test_write_wifi_wpa_eap_ttls_tls(void) "infrastructure", NULL); - g_bytes_unref(ssid); - - /* Wireless security setting */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); - + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-eap", NULL); nm_setting_wireless_security_add_proto(s_wsec, "rsn"); nm_setting_wireless_security_add_pairwise(s_wsec, "ccmp"); nm_setting_wireless_security_add_group(s_wsec, "ccmp"); - /* Wireless security setting */ - s_8021x = (NMSetting8021x *) nm_setting_802_1x_new(); - nm_connection_add_setting(connection, NM_SETTING(s_8021x)); - + s_8021x = _nm_connection_new_setting(connection, NM_TYPE_SETTING_802_1X); nm_setting_802_1x_add_eap_method(s_8021x, "ttls"); - g_object_set(s_8021x, NM_SETTING_802_1X_IDENTITY, "Bill Smith", @@ -7574,16 +6528,10 @@ test_write_wifi_wpa_eap_ttls_tls(void) &error); nmtst_assert_success(success, error); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -7617,15 +6565,11 @@ test_write_wifi_wpa_eap_ttls_mschapv2(void) NMSettingIPConfig * s_ip6; gboolean success; GError * error = NULL; - GBytes * ssid; - const char * ssid_data = "blahblah"; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WPA EAP-TTLS (MSCHAPv2)", @@ -7637,12 +6581,7 @@ test_write_wifi_wpa_eap_ttls_mschapv2(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, strlen(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -7650,12 +6589,7 @@ test_write_wifi_wpa_eap_ttls_mschapv2(void) "infrastructure", NULL); - g_bytes_unref(ssid); - - /* Wireless security setting */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); - + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-eap", NULL); nm_setting_wireless_security_add_proto(s_wsec, "wpa"); nm_setting_wireless_security_add_proto(s_wsec, "rsn"); @@ -7664,12 +6598,8 @@ test_write_wifi_wpa_eap_ttls_mschapv2(void) nm_setting_wireless_security_add_group(s_wsec, "tkip"); nm_setting_wireless_security_add_group(s_wsec, "ccmp"); - /* Wireless security setting */ - s_8021x = (NMSetting8021x *) nm_setting_802_1x_new(); - nm_connection_add_setting(connection, NM_SETTING(s_8021x)); - + s_8021x = _nm_connection_new_setting(connection, NM_TYPE_SETTING_802_1X); nm_setting_802_1x_add_eap_method(s_8021x, "ttls"); - g_object_set(s_8021x, NM_SETTING_802_1X_IDENTITY, "Bill Smith", @@ -7688,16 +6618,10 @@ test_write_wifi_wpa_eap_ttls_mschapv2(void) &error); nmtst_assert_success(success, error); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -7722,14 +6646,14 @@ test_write_wifi_wpa_then_open(void) nmtst_auto_unlinkfile char *testfile = NULL; gs_free char * keyfile = NULL; gs_unref_object NMConnection *connection = NULL; - gs_unref_object NMConnection *reread = NULL; + gs_unref_object NMConnection *reread1 = NULL; + gs_unref_object NMConnection *reread2 = NULL; NMSettingConnection * s_con; NMSettingWireless * s_wifi; NMSettingWirelessSecurity * s_wsec; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - GBytes * ssid; - const char * ssid_data = "blahblah"; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); /* Test that writing out a WPA config then changing that to an open * config doesn't leave various WPA-related keys lying around in the ifcfg. @@ -7737,10 +6661,7 @@ test_write_wifi_wpa_then_open(void) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "random wifi connection", @@ -7752,12 +6673,7 @@ test_write_wifi_wpa_then_open(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, strlen(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -7765,12 +6681,7 @@ test_write_wifi_wpa_then_open(void) "infrastructure", NULL); - g_bytes_unref(ssid); - - /* Wireless security setting */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); - + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-psk", @@ -7786,14 +6697,10 @@ test_write_wifi_wpa_then_open(void) nm_setting_wireless_security_add_pairwise(s_wsec, "ccmp"); nm_setting_wireless_security_add_group(s_wsec, "ccmp"); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -7807,11 +6714,9 @@ test_write_wifi_wpa_then_open(void) _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); - reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); + reread1 = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); - nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); - - g_object_unref(reread); + nmtst_assert_connection_equals(connection, TRUE, reread1, FALSE); nmtst_connection_normalize(connection); @@ -7826,9 +6731,9 @@ test_write_wifi_wpa_then_open(void) keyfile = utils_get_keys_path(testfile); g_assert(!g_file_test(keyfile, G_FILE_TEST_EXISTS)); - reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); + reread2 = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); - nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); + nmtst_assert_connection_equals(connection, TRUE, reread2, FALSE); } static void @@ -7837,16 +6742,15 @@ test_write_wifi_wpa_then_wep_with_perms(void) nmtst_auto_unlinkfile char *testfile = NULL; nmtst_auto_unlinkfile char *keyfile = NULL; gs_unref_object NMConnection *connection = NULL; - gs_unref_object NMConnection *reread = NULL; + gs_unref_object NMConnection *reread1 = NULL; + gs_unref_object NMConnection *reread2 = NULL; NMSettingConnection * s_con; NMSettingWireless * s_wifi; NMSettingWirelessSecurity * s_wsec; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; gboolean success; - GBytes * ssid; - char ** perms; - const char * ssid_data = "SomeSSID"; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("SomeSSID"); /* Test that writing out a WPA config then changing that to a WEP * config works and doesn't cause infinite loop or other issues. @@ -7855,11 +6759,7 @@ test_write_wifi_wpa_then_wep_with_perms(void) connection = nm_simple_connection_new(); g_assert(connection); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - - perms = g_strsplit("user:superman:", ",", -1); + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "random wifi connection 2", @@ -7868,19 +6768,13 @@ test_write_wifi_wpa_then_wep_with_perms(void) NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_PERMISSIONS, - perms, + NM_MAKE_STRV("user:superman:"), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_strfreev(perms); g_assert_cmpint(nm_setting_connection_get_num_permissions(s_con), ==, 1); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, strlen(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -7888,12 +6782,7 @@ test_write_wifi_wpa_then_wep_with_perms(void) "infrastructure", NULL); - g_bytes_unref(ssid); - - /* Wireless security setting */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); - + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-psk", @@ -7909,16 +6798,10 @@ test_write_wifi_wpa_then_wep_with_perms(void) nm_setting_wireless_security_add_pairwise(s_wsec, "ccmp"); nm_setting_wireless_security_add_group(s_wsec, "ccmp"); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -7932,17 +6815,14 @@ test_write_wifi_wpa_then_wep_with_perms(void) _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); - reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); + reread1 = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); - nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); - - g_object_unref(reread); + nmtst_assert_connection_equals(connection, TRUE, reread1, FALSE); nmtst_connection_normalize(connection); /* Now change the connection to WEP and recheck */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none", NULL); nm_setting_wireless_security_set_wep_key(s_wsec, 0, "abraka dabra"); @@ -7953,11 +6833,11 @@ test_write_wifi_wpa_then_wep_with_perms(void) testfile, TEST_IFCFG_DIR "/ifcfg-random_wifi_connection_2.cexpected"); - reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); + reread2 = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); nmtst_connection_normalize(connection); success = nm_connection_compare(connection, - reread, + reread2, NM_SETTING_COMPARE_FLAG_IGNORE_AGENT_OWNED_SECRETS | NM_SETTING_COMPARE_FLAG_IGNORE_NOT_SAVED_SECRETS); g_assert(success); @@ -7978,15 +6858,12 @@ test_write_wifi_dynamic_wep_leap(void) NMSetting8021x * s_8021x; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - GBytes * ssid; - const char * ssid_data = "blahblah"; - shvarFile * ifcfg; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("blahblah"); + shvarFile * ifcfg; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi Dynamic WEP LEAP", @@ -7996,12 +6873,7 @@ test_write_wifi_dynamic_wep_leap(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(ssid_data, strlen(ssid_data)); - + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -8009,20 +6881,11 @@ test_write_wifi_dynamic_wep_leap(void) "infrastructure", NULL); - g_bytes_unref(ssid); - - /* Wireless security setting */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); - + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x", NULL); - /* Wireless security setting */ - s_8021x = (NMSetting8021x *) nm_setting_802_1x_new(); - nm_connection_add_setting(connection, NM_SETTING(s_8021x)); - + s_8021x = _nm_connection_new_setting(connection, NM_TYPE_SETTING_802_1X); nm_setting_802_1x_add_eap_method(s_8021x, "leap"); - g_object_set(s_8021x, NM_SETTING_802_1X_IDENTITY, "Bill Smith", @@ -8030,15 +6893,10 @@ test_write_wifi_dynamic_wep_leap(void) ";alkdfja;dslkfjsad;lkfjsadf", NULL); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -8076,14 +6934,10 @@ test_write_wired_qeth_dhcp(void) NMSettingWired * s_wired; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - char ** subchans; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired qeth Static", @@ -8095,34 +6949,23 @@ test_write_wired_qeth_dhcp(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - subchans = g_strsplit("0.0.600,0.0.601,0.0.602", ",", -1); + s_wired = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); g_object_set(s_wired, NM_SETTING_WIRED_S390_SUBCHANNELS, - subchans, + NM_MAKE_STRV("0.0.600", "0.0.601", "0.0.602"), NM_SETTING_WIRED_S390_NETTYPE, "qeth", NULL); - g_strfreev(subchans); nm_setting_wired_add_s390_option(s_wired, "portname", "FOOBAR"); nm_setting_wired_add_s390_option(s_wired, "portno", "1"); nm_setting_wired_add_s390_option(s_wired, "layer2", "0"); nm_setting_wired_add_s390_option(s_wired, "protocol", "blahbalh"); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -8149,15 +6992,11 @@ test_write_wired_ctc_dhcp(void) NMSettingWired * s_wired; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - char ** subchans; shvarFile * ifcfg; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired ctc Static", @@ -8167,29 +7006,19 @@ test_write_wired_ctc_dhcp(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - subchans = g_strsplit("0.0.600,0.0.601", ",", -1); + s_wired = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); g_object_set(s_wired, NM_SETTING_WIRED_S390_SUBCHANNELS, - subchans, + NM_MAKE_STRV("0.0.600", "0.0.601"), NM_SETTING_WIRED_S390_NETTYPE, "ctc", NULL); - g_strfreev(subchans); nm_setting_wired_add_s390_option(s_wired, "ctcprot", "0"); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -8223,16 +7052,12 @@ test_write_permissions(void) gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; - NMSettingWired * s_wired; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Permissions", @@ -8248,20 +7073,12 @@ test_write_permissions(void) nm_setting_connection_add_permission(s_con, "user", "foobar", NULL); nm_setting_connection_add_permission(s_con, "user", "asdfasdf", NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -8292,16 +7109,12 @@ test_write_wifi_wep_agent_keys(void) NMSettingWirelessSecurity * s_wsec; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - const char * str_ssid = "foobarbaz"; - GBytes * ssid; + gs_unref_bytes GBytes *ssid = nmtst_gbytes_from_str("foobarbaz"); connection = nm_simple_connection_new(); g_assert(connection != NULL); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WEP Agent Owned", @@ -8311,15 +7124,10 @@ test_write_wifi_wep_agent_keys(void) NM_SETTING_WIRELESS_SETTING_NAME, NULL); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, @@ -8329,23 +7137,15 @@ test_write_wifi_wep_agent_keys(void) (int) NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64, NULL); - /* Wifi setting */ - s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wifi)); - - ssid = g_bytes_new(str_ssid, strlen(str_ssid)); + s_wifi = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_MODE, "infrastructure", NULL); - g_bytes_unref(ssid); - - /* Wifi security setting */ - s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wsec)); + s_wsec = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none", @@ -8376,20 +7176,15 @@ test_write_wifi_wep_agent_keys(void) static void test_write_wired_pppoe(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingPppoe * s_pppoe; - NMSettingPpp * s_ppp; - GError * error = NULL; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + NMSettingPppoe * s_pppoe; + gs_free_error GError *error = NULL; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired PPPoE", @@ -8401,21 +7196,13 @@ test_write_wired_pppoe(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* PPPoE setting */ - s_pppoe = (NMSettingPppoe *) nm_setting_pppoe_new(); - nm_connection_add_setting(connection, NM_SETTING(s_pppoe)); - - g_object_set(G_OBJECT(s_pppoe), + s_pppoe = _nm_connection_new_setting(connection, NM_TYPE_SETTING_PPPOE); + g_object_set(s_pppoe, NM_SETTING_PPPOE_SERVICE, "stupid-service", NM_SETTING_PPPOE_USERNAME, @@ -8424,33 +7211,25 @@ test_write_wired_pppoe(void) "test1", NULL); - /* PPP setting */ - s_ppp = (NMSettingPpp *) nm_setting_ppp_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ppp)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_PPP); nmtst_assert_connection_verifies(connection); _writer_new_connection_fail(connection, TEST_SCRATCH_DIR, NULL); - - g_object_unref(connection); - g_clear_error(&error); } static void test_write_vpn(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingIPConfig * s_ip4; - NMSettingVpn * s_vpn; - GError * error = NULL; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + NMSettingVpn * s_vpn; + gs_free_error GError *error = NULL; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write VPN", @@ -8462,10 +7241,7 @@ test_write_vpn(void) NM_SETTING_VPN_SETTING_NAME, NULL); - /* VPN setting */ - s_vpn = (NMSettingVpn *) nm_setting_vpn_new(); - nm_connection_add_setting(connection, NM_SETTING(s_vpn)); - + s_vpn = _nm_connection_new_setting(connection, NM_TYPE_SETTING_VPN); g_object_set(s_vpn, NM_SETTING_VPN_SERVICE_TYPE, "awesomevpn", @@ -8476,39 +7252,28 @@ test_write_vpn(void) nm_setting_vpn_add_data_item(s_vpn, "server", "vpn.somewhere.com"); nm_setting_vpn_add_secret(s_vpn, "password", "sup3rs3cr3t"); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); nmtst_assert_connection_verifies(connection); _writer_new_connection_fail(connection, TEST_SCRATCH_DIR, NULL); - - g_object_unref(connection); - g_clear_error(&error); } static void test_write_mobile_broadband(gconstpointer data) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingIPConfig * s_ip4; - NMSettingGsm * s_gsm; - NMSettingCdma * s_cdma; - NMSettingPpp * s_ppp; - NMSettingSerial * s_serial; - GError * error = NULL; - gboolean gsm = GPOINTER_TO_UINT(data); + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + NMSettingCdma * s_cdma; + NMSettingSerial * s_serial; + gs_free_error GError *error = NULL; + gboolean gsm = GPOINTER_TO_UINT(data); connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, gsm ? "Test Write GSM" : "Test Write CDMA", @@ -8520,22 +7285,14 @@ test_write_mobile_broadband(gconstpointer data) gsm ? NM_SETTING_GSM_SETTING_NAME : NM_SETTING_CDMA_SETTING_NAME, NULL); - if (gsm) { - /* GSM setting */ - s_gsm = (NMSettingGsm *) nm_setting_gsm_new(); - nm_connection_add_setting(connection, NM_SETTING(s_gsm)); - } else { - /* CDMA setting */ - s_cdma = (NMSettingCdma *) nm_setting_cdma_new(); - nm_connection_add_setting(connection, NM_SETTING(s_cdma)); - + if (gsm) + _nm_connection_new_setting(connection, NM_TYPE_SETTING_GSM); + else { + s_cdma = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CDMA); g_object_set(s_cdma, NM_SETTING_CDMA_NUMBER, "#777", NULL); } - /* Serial setting */ - s_serial = (NMSettingSerial *) nm_setting_serial_new(); - nm_connection_add_setting(connection, NM_SETTING(s_serial)); - + s_serial = _nm_connection_new_setting(connection, NM_TYPE_SETTING_SERIAL); g_object_set(s_serial, NM_SETTING_SERIAL_BAUD, 115200, @@ -8547,42 +7304,31 @@ test_write_mobile_broadband(gconstpointer data) 1, NULL); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* PPP setting */ - s_ppp = (NMSettingPpp *) nm_setting_ppp_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ppp)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_PPP); nmtst_assert_connection_verifies(connection); _writer_new_connection_fail(connection, TEST_SCRATCH_DIR, NULL); - - g_object_unref(connection); - g_clear_error(&error); } static void test_read_bridge_main(void) { - NMConnection * connection; - NMSettingBridge *s_bridge; - NMSettingWired * s_wired; - const char * mac; - char expected_mac_address[ETH_ALEN] = {0x00, 0x16, 0x41, 0x11, 0x22, 0x33}; + gs_unref_object NMConnection *connection = NULL; + NMSettingBridge * s_bridge; + NMSettingWired * s_wired; + const char * mac; + char expected_mac_address[ETH_ALEN] = {0x00, 0x16, 0x41, 0x11, 0x22, 0x33}; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bridge-main", NULL, TYPE_ETHERNET, NULL); g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "br0"); - /* ===== Bridging SETTING ===== */ - - s_bridge = nm_connection_get_setting_bridge(connection); - g_assert(s_bridge); + s_bridge = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_BRIDGE); g_assert_cmpuint(nm_setting_bridge_get_forward_delay(s_bridge), ==, 2); g_assert(nm_setting_bridge_get_stp(s_bridge)); g_assert_cmpuint(nm_setting_bridge_get_priority(s_bridge), ==, 32744); @@ -8594,14 +7340,10 @@ test_read_bridge_main(void) g_assert_cmpint(nm_setting_bridge_get_vlan_filtering(s_bridge), ==, TRUE); g_assert_cmpint(nm_setting_bridge_get_vlan_default_pvid(s_bridge), ==, 99); - /* MAC address */ - s_wired = nm_connection_get_setting_wired(connection); - g_assert(s_wired); - mac = nm_setting_wired_get_cloned_mac_address(s_wired); + s_wired = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_WIRED); + mac = nm_setting_wired_get_cloned_mac_address(s_wired); g_assert(mac); g_assert(nm_utils_hwaddr_matches(mac, -1, expected_mac_address, ETH_ALEN)); - - g_object_unref(connection); } static void @@ -8612,8 +7354,8 @@ test_write_bridge_main(void) gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; NMSettingBridge * s_bridge; - NMSettingIPConfig * s_ip4, *s_ip6; - NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; NMIPAddress * addr; static const char * mac = "31:33:33:37:be:cd"; GError * error = NULL; @@ -8623,10 +7365,7 @@ test_write_bridge_main(void) connection = nm_simple_connection_new(); g_assert(connection); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Bridge Main", @@ -8640,9 +7379,7 @@ test_write_bridge_main(void) NM_SETTING_BRIDGE_SETTING_NAME, NULL); - /* bridge setting */ - s_bridge = (NMSettingBridge *) nm_setting_bridge_new(); - nm_connection_add_setting(connection, NM_SETTING(s_bridge)); + s_bridge = _nm_connection_new_setting(connection, NM_TYPE_SETTING_BRIDGE); vlans = g_ptr_array_new_with_free_func((GDestroyNotify) nm_bridge_vlan_unref); vlan = nm_bridge_vlan_new(10, 16); @@ -8668,10 +7405,7 @@ test_write_bridge_main(void) vlans, NULL); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, @@ -8686,17 +7420,12 @@ test_write_bridge_main(void) nm_setting_ip_config_add_address(s_ip4, addr); nm_ip_address_unref(addr); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); - nm_connection_add_setting(connection, nm_setting_proxy_new()); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_PROXY); nmtst_assert_connection_verifies_without_normalization(connection); @@ -8710,29 +7439,25 @@ test_write_bridge_main(void) static void test_read_bridge_component(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingBridgePort *s_port; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingBridgePort * s_port; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bridge-component", NULL, TYPE_ETHERNET, NULL); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_master(s_con), ==, "br0"); g_assert_cmpstr(nm_setting_connection_get_slave_type(s_con), ==, NM_SETTING_BRIDGE_SETTING_NAME); - s_port = nm_connection_get_setting_bridge_port(connection); - g_assert(s_port); + s_port = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_BRIDGE_PORT); g_assert(nm_setting_bridge_port_get_hairpin_mode(s_port)); g_assert_cmpuint(nm_setting_bridge_port_get_priority(s_port), ==, 28); g_assert_cmpuint(nm_setting_bridge_port_get_path_cost(s_port), ==, 100); - - g_object_unref(connection); } static void @@ -8752,10 +7477,7 @@ test_write_bridge_component(void) connection = nm_simple_connection_new(); g_assert(connection); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Bridge Component", @@ -8771,10 +7493,7 @@ test_write_bridge_component(void) NM_SETTING_BRIDGE_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - + s_wired = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); g_object_set(s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac, NM_SETTING_WIRED_MTU, mtu, NULL); /* Bridge port */ @@ -8789,8 +7508,7 @@ test_write_bridge_component(void) nm_bridge_vlan_set_pvid(vlan, TRUE); g_ptr_array_add(vlans, vlan); - s_port = nm_setting_bridge_port_new(); - nm_connection_add_setting(connection, s_port); + s_port = _nm_connection_new_setting(connection, NM_TYPE_SETTING_BRIDGE_PORT); g_object_set(s_port, NM_SETTING_BRIDGE_PORT_PRIORITY, 50, @@ -8815,8 +7533,8 @@ test_write_bridge_component(void) static void test_read_bridge_missing_stp(void) { - NMConnection * connection; - NMSettingBridge *s_bridge; + gs_unref_object NMConnection *connection = NULL; + NMSettingBridge * s_bridge; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bridge-missing-stp", NULL, @@ -8825,13 +7543,8 @@ test_read_bridge_missing_stp(void) g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "br0"); - /* ===== Bridging SETTING ===== */ - - s_bridge = nm_connection_get_setting_bridge(connection); - g_assert(s_bridge); + s_bridge = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_BRIDGE); g_assert(nm_setting_bridge_get_stp(s_bridge) == FALSE); - - g_object_unref(connection); } #define TEST_IFCFG_VLAN_INTERFACE TEST_IFCFG_DIR "/ifcfg-test-vlan-interface" @@ -8839,16 +7552,16 @@ test_read_bridge_missing_stp(void) static void test_read_vlan_interface(void) { - NMConnection * connection; - NMSettingVlan *s_vlan; - guint32 from = 0, to = 0; + gs_unref_object NMConnection *connection = NULL; + NMSettingVlan * s_vlan; + guint32 from = 0; + guint32 to = 0; connection = _connection_from_file(TEST_IFCFG_VLAN_INTERFACE, NULL, TYPE_ETHERNET, NULL); g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "vlan43"); - s_vlan = nm_connection_get_setting_vlan(connection); - g_assert(s_vlan); + s_vlan = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_VLAN); g_assert_cmpstr(nm_setting_vlan_get_parent(s_vlan), ==, "eth9"); g_assert_cmpint(nm_setting_vlan_get_id(s_vlan), ==, 43); @@ -8881,8 +7594,6 @@ test_read_vlan_interface(void) g_assert(nm_setting_vlan_get_priority(s_vlan, NM_VLAN_EGRESS_MAP, 2, &from, &to)); g_assert_cmpint(from, ==, 14); g_assert_cmpint(to, ==, 7); - - g_object_unref(connection); } #define TEST_IFCFG_VLAN_ONLY_VLANID TEST_IFCFG_DIR "/ifcfg-test-vlan-only-vlanid" @@ -8890,21 +7601,18 @@ test_read_vlan_interface(void) static void test_read_vlan_only_vlan_id(void) { - NMConnection * connection; - NMSettingVlan *s_vlan; + gs_unref_object NMConnection *connection = NULL; + NMSettingVlan * s_vlan; connection = _connection_from_file(TEST_IFCFG_VLAN_ONLY_VLANID, NULL, TYPE_ETHERNET, NULL); g_assert(nm_connection_get_interface_name(connection) == NULL); - s_vlan = nm_connection_get_setting_vlan(connection); - g_assert(s_vlan); + s_vlan = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_VLAN); g_assert_cmpstr(nm_setting_vlan_get_parent(s_vlan), ==, "eth9"); g_assert_cmpint(nm_setting_vlan_get_id(s_vlan), ==, 43); g_assert_cmpint(nm_setting_vlan_get_flags(s_vlan), ==, NM_VLAN_FLAG_REORDER_HEADERS); - - g_object_unref(connection); } static void @@ -8922,8 +7630,7 @@ test_read_vlan_vlanid_use(void) g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "eth0.9"); - s_vlan = nm_connection_get_setting_vlan(connection); - g_assert(s_vlan); + s_vlan = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_VLAN); g_assert_cmpstr(nm_setting_vlan_get_parent(s_vlan), ==, "eth0"); g_assert_cmpint(nm_setting_vlan_get_id(s_vlan), ==, 10); @@ -8942,8 +7649,8 @@ test_read_vlan_vlanid_use(void) static void test_read_vlan_only_device(void) { - NMConnection * connection; - NMSettingVlan *s_vlan; + gs_unref_object NMConnection *connection = NULL; + NMSettingVlan * s_vlan; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-vlan-only-device", NULL, @@ -8952,40 +7659,34 @@ test_read_vlan_only_device(void) g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "eth0.9"); - s_vlan = nm_connection_get_setting_vlan(connection); - g_assert(s_vlan); + s_vlan = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_VLAN); g_assert_cmpstr(nm_setting_vlan_get_parent(s_vlan), ==, "eth0"); g_assert_cmpint(nm_setting_vlan_get_id(s_vlan), ==, 9); - - g_object_unref(connection); } static void test_read_vlan_physdev(void) { - NMConnection * connection; - NMSettingVlan *s_vlan; + gs_unref_object NMConnection *connection = NULL; + NMSettingVlan * s_vlan; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-vlan-physdev", NULL, TYPE_ETHERNET, NULL); g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "vlan0.3"); - s_vlan = nm_connection_get_setting_vlan(connection); - g_assert(s_vlan); + s_vlan = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_VLAN); g_assert_cmpstr(nm_setting_vlan_get_parent(s_vlan), ==, "eth0"); g_assert_cmpint(nm_setting_vlan_get_id(s_vlan), ==, 3); - - g_object_unref(connection); } static void test_read_vlan_reorder_hdr_1(void) { - NMConnection * connection; - NMSettingVlan *s_vlan; + gs_unref_object NMConnection *connection = NULL; + NMSettingVlan * s_vlan; NMTST_EXPECT_NM_WARN("*REORDER_HDR key is deprecated, use VLAN_FLAGS*"); connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-vlan-reorder-hdr-1", @@ -8996,22 +7697,19 @@ test_read_vlan_reorder_hdr_1(void) g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "vlan0.3"); - s_vlan = nm_connection_get_setting_vlan(connection); - g_assert(s_vlan); + s_vlan = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_VLAN); g_assert_cmpstr(nm_setting_vlan_get_parent(s_vlan), ==, "eth0"); g_assert_cmpint(nm_setting_vlan_get_id(s_vlan), ==, 3); /* Check that REORDER_HDR=0 is ignored */ g_assert_cmpint(nm_setting_vlan_get_flags(s_vlan), ==, NM_VLAN_FLAG_REORDER_HEADERS); - - g_object_unref(connection); } static void test_read_vlan_reorder_hdr_2(void) { - NMConnection * connection; - NMSettingVlan *s_vlan; + gs_unref_object NMConnection *connection = NULL; + NMSettingVlan * s_vlan; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-vlan-reorder-hdr-2", NULL, @@ -9020,61 +7718,52 @@ test_read_vlan_reorder_hdr_2(void) g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "vlan0.3"); - s_vlan = nm_connection_get_setting_vlan(connection); - g_assert(s_vlan); + s_vlan = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_VLAN); g_assert_cmpstr(nm_setting_vlan_get_parent(s_vlan), ==, "eth0"); g_assert_cmpint(nm_setting_vlan_get_id(s_vlan), ==, 3); /* Check that VLAN_FLAGS=NO_REORDER_HDR works */ g_assert_cmpint(nm_setting_vlan_get_flags(s_vlan), ==, NM_VLAN_FLAG_LOOSE_BINDING); - - g_object_unref(connection); } static void test_read_vlan_flags_1(void) { - NMConnection * connection; - NMSettingVlan *s_vlan; + gs_unref_object NMConnection *connection = NULL; + NMSettingVlan * s_vlan; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-vlan-flags-1", NULL, TYPE_ETHERNET, NULL); g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "super-vlan"); - s_vlan = nm_connection_get_setting_vlan(connection); - g_assert(s_vlan); + s_vlan = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_VLAN); g_assert_cmpstr(nm_setting_vlan_get_parent(s_vlan), ==, "eth9"); g_assert_cmpint(nm_setting_vlan_get_id(s_vlan), ==, 44); g_assert_cmpint(nm_setting_vlan_get_flags(s_vlan), ==, NM_VLAN_FLAG_LOOSE_BINDING | NM_VLAN_FLAG_REORDER_HEADERS); - - g_object_unref(connection); } static void test_read_vlan_flags_2(void) { - NMConnection * connection; - NMSettingVlan *s_vlan; + gs_unref_object NMConnection *connection = NULL; + NMSettingVlan * s_vlan; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-vlan-flags-2", NULL, TYPE_ETHERNET, NULL); g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "super-vlan"); - s_vlan = nm_connection_get_setting_vlan(connection); - g_assert(s_vlan); + s_vlan = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_VLAN); g_assert_cmpstr(nm_setting_vlan_get_parent(s_vlan), ==, "eth9"); g_assert_cmpint(nm_setting_vlan_get_id(s_vlan), ==, 44); g_assert_cmpint(nm_setting_vlan_get_flags(s_vlan), ==, NM_VLAN_FLAG_GVRP | NM_VLAN_FLAG_LOOSE_BINDING | NM_VLAN_FLAG_REORDER_HEADERS); - - g_object_unref(connection); } static void @@ -9132,14 +7821,10 @@ test_write_vlan_reorder_hdr(void) gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; NMSettingVlan * s_vlan; - NMSettingWired * s_wired; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write VLAN reorder_hdr", @@ -9151,14 +7836,9 @@ test_write_vlan_reorder_hdr(void) NM_SETTING_VLAN_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - /* VLAN setting */ - s_vlan = (NMSettingVlan *) nm_setting_vlan_new(); - nm_connection_add_setting(connection, NM_SETTING(s_vlan)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); + s_vlan = _nm_connection_new_setting(connection, NM_TYPE_SETTING_VLAN); g_object_set(s_vlan, NM_SETTING_VLAN_PARENT, "eth0", @@ -9185,16 +7865,12 @@ test_write_ethernet_missing_ipv6(void) gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; - NMSettingWired * s_wired; NMSettingIPConfig * s_ip4; connection = nm_simple_connection_new(); g_assert(connection); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Ethernet Without IPv6 Setting", @@ -9206,13 +7882,9 @@ test_write_ethernet_missing_ipv6(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, @@ -9251,31 +7923,26 @@ test_read_ibft_ignored(void) static void test_read_bond_main(void) { - NMConnection * connection; - NMSettingBond *s_bond; + gs_unref_object NMConnection *connection = NULL; + NMSettingBond * s_bond; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bond-main", NULL, TYPE_ETHERNET, NULL); g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "bond0"); - /* ===== Bonding SETTING ===== */ - - s_bond = nm_connection_get_setting_bond(connection); - g_assert(s_bond); + s_bond = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_BOND); g_assert_cmpstr(nm_setting_bond_get_option_by_name(s_bond, NM_SETTING_BOND_OPTION_MIIMON), ==, "100"); - - g_object_unref(connection); } static void test_read_bond_eth_type(void) { - NMConnection * connection; - NMSettingBond *s_bond; + gs_unref_object NMConnection *connection = NULL; + NMSettingBond * s_bond; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bond-eth-type", NULL, @@ -9284,10 +7951,7 @@ test_read_bond_eth_type(void) g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "bond0"); - /* ===== Bonding SETTING ===== */ - - s_bond = nm_connection_get_setting_bond(connection); - g_assert(s_bond); + s_bond = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_BOND); g_assert_cmpstr(nm_setting_bond_get_option_by_name(s_bond, NM_SETTING_BOND_OPTION_MIIMON), ==, @@ -9295,8 +7959,6 @@ test_read_bond_eth_type(void) g_assert_cmpstr(nm_setting_bond_get_option_by_name(s_bond, NM_SETTING_BOND_OPTION_LACP_RATE), ==, "1"); - - g_object_unref(connection); } static void @@ -9309,16 +7971,12 @@ test_write_bond_main(void) NMSettingBond * s_bond; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - NMSettingWired * s_wired; NMIPAddress * addr; GError * error = NULL; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Bond Main", @@ -9332,22 +7990,14 @@ test_write_bond_main(void) NM_SETTING_BOND_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - /* bond setting */ - s_bond = (NMSettingBond *) nm_setting_bond_new(); - nm_connection_add_setting(connection, NM_SETTING(s_bond)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); + s_bond = _nm_connection_new_setting(connection, NM_TYPE_SETTING_BOND); nm_setting_bond_add_option(s_bond, NM_SETTING_BOND_OPTION_DOWNDELAY, "5"); nm_setting_bond_add_option(s_bond, NM_SETTING_BOND_OPTION_UPDELAY, "10"); nm_setting_bond_add_option(s_bond, NM_SETTING_BOND_OPTION_MIIMON, "100"); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, @@ -9362,13 +8012,10 @@ test_write_bond_main(void) nm_setting_ip_config_add_address(s_ip4, addr); nm_ip_address_unref(addr); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL); - nm_connection_add_setting(connection, nm_setting_proxy_new()); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_PROXY); nmtst_assert_connection_verifies_without_normalization(connection); @@ -9385,21 +8032,18 @@ test_write_bond_main(void) static void test_read_bond_slave(void) { - NMConnection * connection; - NMSettingConnection *s_con; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bond-slave", NULL, TYPE_ETHERNET, NULL); g_test_assert_expected_messages(); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_master(s_con), ==, "bond0"); g_assert_cmpstr(nm_setting_connection_get_slave_type(s_con), ==, NM_SETTING_BOND_SETTING_NAME); - - g_object_unref(connection); } static void @@ -9415,10 +8059,7 @@ test_write_bond_slave(void) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Bond Slave", @@ -9434,10 +8075,7 @@ test_write_bond_slave(void) NM_SETTING_BOND_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - + s_wired = _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); g_object_set(s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac, NM_SETTING_WIRED_MTU, mtu, NULL); nmtst_assert_connection_verifies(connection); @@ -9449,13 +8087,72 @@ test_write_bond_slave(void) nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); } +static void +test_read_bond_port(void) +{ + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con = NULL; + NMSettingBondPort * s_port = NULL; + + connection = + _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bond-port", NULL, TYPE_ETHERNET, NULL); + + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); + g_assert_cmpstr(nm_setting_connection_get_master(s_con), ==, "bond99"); + g_assert_cmpstr(nm_setting_connection_get_slave_type(s_con), ==, NM_SETTING_BOND_SETTING_NAME); + + s_port = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_BOND_PORT); + g_assert_cmpuint(nm_setting_bond_port_get_queue_id(s_port), ==, 1); +} + +static void +test_write_bond_port(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingBondPort * s_bond_port; + + connection = nm_simple_connection_new(); + + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Bond Port", + NM_SETTING_CONNECTION_UUID, + nm_uuid_generate_random_str_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRED_SETTING_NAME, + NM_SETTING_CONNECTION_MASTER, + "bond0", + NM_SETTING_CONNECTION_SLAVE_TYPE, + NM_SETTING_BOND_SETTING_NAME, + NULL); + + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); + + s_bond_port = _nm_connection_new_setting(connection, NM_TYPE_SETTING_BOND_PORT); + g_object_set(s_bond_port, NM_SETTING_BOND_PORT_QUEUE_ID, 1, NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + static void test_read_infiniband(void) { - NMConnection * connection; - NMSettingInfiniband *s_infiniband; - char * unmanaged = NULL; - const char * mac; + gs_unref_object NMConnection *connection = NULL; + NMSettingInfiniband * s_infiniband; + char * unmanaged = NULL; + const char * mac; char expected_mac_address[INFINIBAND_ALEN] = {0x80, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22}; @@ -9467,22 +8164,15 @@ test_read_infiniband(void) &unmanaged); g_assert(!unmanaged); - /* ===== INFINIBAND SETTING ===== */ + s_infiniband = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_INFINIBAND); - s_infiniband = nm_connection_get_setting_infiniband(connection); - g_assert(s_infiniband); - - /* MAC address */ mac = nm_setting_infiniband_get_mac_address(s_infiniband); g_assert(mac); g_assert(nm_utils_hwaddr_matches(mac, -1, expected_mac_address, sizeof(expected_mac_address))); - /* Transport mode */ transport_mode = nm_setting_infiniband_get_transport_mode(s_infiniband); g_assert(transport_mode); g_assert_cmpstr(transport_mode, ==, "connected"); - - g_object_unref(connection); } static void @@ -9502,10 +8192,7 @@ test_write_infiniband(void) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write InfiniBand", @@ -9517,10 +8204,7 @@ test_write_infiniband(void) NM_SETTING_INFINIBAND_SETTING_NAME, NULL); - /* InfiniBand setting */ - s_infiniband = (NMSettingInfiniband *) nm_setting_infiniband_new(); - nm_connection_add_setting(connection, NM_SETTING(s_infiniband)); - + s_infiniband = _nm_connection_new_setting(connection, NM_TYPE_SETTING_INFINIBAND); g_object_set(s_infiniband, NM_SETTING_INFINIBAND_MAC_ADDRESS, mac, @@ -9530,10 +8214,7 @@ test_write_infiniband(void) "connected", NULL); - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); - + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, @@ -9548,10 +8229,7 @@ test_write_infiniband(void) nm_setting_ip_config_add_address(s_ip4, addr); nm_ip_address_unref(addr); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL); nmtst_assert_connection_verifies(connection); @@ -9572,8 +8250,7 @@ test_read_bond_slave_ib(void) connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bond-slave-ib", NULL, NULL, NULL); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_master(s_con), ==, "bond0"); g_assert_cmpstr(nm_setting_connection_get_slave_type(s_con), ==, NM_SETTING_BOND_SETTING_NAME); @@ -9591,10 +8268,7 @@ test_write_bond_slave_ib(void) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Bond Slave InfiniBand", @@ -9610,10 +8284,7 @@ test_write_bond_slave_ib(void) NM_SETTING_BOND_SETTING_NAME, NULL); - /* InfiniBand setting */ - s_infiniband = (NMSettingInfiniband *) nm_setting_infiniband_new(); - nm_connection_add_setting(connection, NM_SETTING(s_infiniband)); - + s_infiniband = _nm_connection_new_setting(connection, NM_TYPE_SETTING_INFINIBAND); g_object_set(s_infiniband, NM_SETTING_INFINIBAND_MAC_ADDRESS, mac, @@ -9635,9 +8306,9 @@ test_write_bond_slave_ib(void) static void test_read_bond_opts_mode_numeric(void) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingBond * s_bond; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingBond * s_bond; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bond-mode-numeric", NULL, @@ -9646,19 +8317,15 @@ test_read_bond_opts_mode_numeric(void) g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "bond0"); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), ==, NM_SETTING_BOND_SETTING_NAME); - s_bond = nm_connection_get_setting_bond(connection); - g_assert(s_bond); + s_bond = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_BOND); g_assert_cmpstr(nm_setting_bond_get_option_by_name(s_bond, NM_SETTING_BOND_OPTION_MODE), ==, "802.3ad"); - - g_object_unref(connection); } #define DCB_ALL_FLAGS \ @@ -9667,20 +8334,19 @@ test_read_bond_opts_mode_numeric(void) static void test_read_dcb_basic(void) { - NMConnection *connection; - NMSettingDcb *s_dcb; - guint i; - guint expected_group_ids[8] = {0, 0, 0, 0, 1, 1, 1, 0xF}; - guint expected_group_bandwidths[8] = {25, 0, 0, 75, 0, 0, 0, 0}; - guint expected_bandwidths[8] = {5, 10, 30, 25, 10, 50, 5, 0}; - gboolean expected_strict[8] = {FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, FALSE, TRUE}; - guint expected_traffic_classes[8] = {7, 6, 5, 4, 3, 2, 1, 0}; - gboolean expected_pfcs[8] = {TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, FALSE}; + gs_unref_object NMConnection *connection = NULL; + NMSettingDcb * s_dcb; + guint i; + guint expected_group_ids[8] = {0, 0, 0, 0, 1, 1, 1, 0xF}; + guint expected_group_bandwidths[8] = {25, 0, 0, 75, 0, 0, 0, 0}; + guint expected_bandwidths[8] = {5, 10, 30, 25, 10, 50, 5, 0}; + gboolean expected_strict[8] = {FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, FALSE, TRUE}; + guint expected_traffic_classes[8] = {7, 6, 5, 4, 3, 2, 1, 0}; + gboolean expected_pfcs[8] = {TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, FALSE}; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-dcb", NULL, TYPE_ETHERNET, NULL); - s_dcb = nm_connection_get_setting_dcb(connection); - g_assert(s_dcb); + s_dcb = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_DCB); g_assert_cmpint(nm_setting_dcb_get_app_fcoe_flags(s_dcb), ==, DCB_ALL_FLAGS); g_assert_cmpint(nm_setting_dcb_get_app_fcoe_priority(s_dcb), ==, 7); @@ -9726,8 +8392,6 @@ test_read_dcb_basic(void) g_assert_cmpint(nm_setting_dcb_get_priority_traffic_class(s_dcb, i), ==, expected_traffic_classes[i]); - - g_object_unref(connection); } static void @@ -9737,7 +8401,6 @@ test_write_dcb_basic(void) gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; - NMSettingWired * s_wired; NMSettingDcb * s_dcb; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; @@ -9751,9 +8414,8 @@ test_write_dcb_basic(void) connection = nm_simple_connection_new(); - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - g_object_set(G_OBJECT(s_con), + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); + g_object_set(s_con, NM_SETTING_CONNECTION_ID, "dcb-test", NM_SETTING_CONNECTION_UUID, @@ -9764,30 +8426,16 @@ test_write_dcb_basic(void) "eth0", NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); - /* IP stuff */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - g_object_set(G_OBJECT(s_ip4), - NM_SETTING_IP_CONFIG_METHOD, - NM_SETTING_IP4_CONFIG_METHOD_AUTO, - NULL); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - g_object_set(G_OBJECT(s_ip6), - NM_SETTING_IP_CONFIG_METHOD, - NM_SETTING_IP6_CONFIG_METHOD_AUTO, - NULL); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); + g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL); - /* DCB */ - s_dcb = (NMSettingDcb *) nm_setting_dcb_new(); - nm_connection_add_setting(connection, NM_SETTING(s_dcb)); - - g_object_set(G_OBJECT(s_dcb), + s_dcb = _nm_connection_new_setting(connection, NM_TYPE_SETTING_DCB); + g_object_set(s_dcb, NM_SETTING_DCB_APP_FCOE_FLAGS, DCB_ALL_FLAGS, NM_SETTING_DCB_APP_FCOE_PRIORITY, @@ -9838,8 +8486,7 @@ test_read_dcb_default_app_priorities(void) TYPE_ETHERNET, NULL); - s_dcb = nm_connection_get_setting_dcb(connection); - g_assert(s_dcb); + s_dcb = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_DCB); g_assert_cmpint(nm_setting_dcb_get_app_fcoe_flags(s_dcb), ==, NM_SETTING_DCB_FLAG_ENABLE); g_assert_cmpint(nm_setting_dcb_get_app_fcoe_priority(s_dcb), ==, -1); @@ -9974,8 +8621,7 @@ test_read_fcoe_mode(gconstpointer user_data) file = g_strdup_printf(TEST_IFCFG_DIR "/ifcfg-test-fcoe-%s", expected_mode); connection = _connection_from_file(file, NULL, TYPE_ETHERNET, NULL); - s_dcb = nm_connection_get_setting_dcb(connection); - g_assert(s_dcb); + s_dcb = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_DCB); g_assert_cmpint(nm_setting_dcb_get_app_fcoe_flags(s_dcb), ==, NM_SETTING_DCB_FLAG_ENABLE); g_assert_cmpstr(nm_setting_dcb_get_app_fcoe_mode(s_dcb), ==, expected_mode); @@ -9989,7 +8635,6 @@ test_write_fcoe_mode(gconstpointer user_data) gs_unref_object NMConnection *reread = NULL; const char * expected_mode = user_data; NMSettingConnection * s_con; - NMSettingWired * s_wired; NMSettingDcb * s_dcb; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; @@ -9997,9 +8642,8 @@ test_write_fcoe_mode(gconstpointer user_data) connection = nm_simple_connection_new(); - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - g_object_set(G_OBJECT(s_con), + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); + g_object_set(s_con, NM_SETTING_CONNECTION_ID, "fcoe-test", NM_SETTING_CONNECTION_UUID, @@ -10010,30 +8654,16 @@ test_write_fcoe_mode(gconstpointer user_data) "eth0", NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); - /* IP stuff */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - g_object_set(G_OBJECT(s_ip4), - NM_SETTING_IP_CONFIG_METHOD, - NM_SETTING_IP4_CONFIG_METHOD_AUTO, - NULL); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - g_object_set(G_OBJECT(s_ip6), - NM_SETTING_IP_CONFIG_METHOD, - NM_SETTING_IP6_CONFIG_METHOD_AUTO, - NULL); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); + g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL); - /* DCB */ - s_dcb = (NMSettingDcb *) nm_setting_dcb_new(); - nm_connection_add_setting(connection, NM_SETTING(s_dcb)); - - g_object_set(G_OBJECT(s_dcb), + s_dcb = _nm_connection_new_setting(connection, NM_TYPE_SETTING_DCB); + g_object_set(s_dcb, NM_SETTING_DCB_APP_FCOE_FLAGS, NM_SETTING_DCB_FLAG_ENABLE, NM_SETTING_DCB_APP_FCOE_MODE, @@ -10056,28 +8686,24 @@ test_write_fcoe_mode(gconstpointer user_data) static void test_read_team_master(gconstpointer user_data) { - const char *const PATH_NAME = user_data; - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingTeam * s_team; - const char * expected_config = + const char *const PATH_NAME = user_data; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingTeam * s_team; + const char * expected_config = "{\"device\": \"team0\", \"link_watch\": {\"name\": \"ethtool\"}}"; connection = _connection_from_file(PATH_NAME, NULL, TYPE_ETHERNET, NULL); g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "team0"); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), ==, NM_SETTING_TEAM_SETTING_NAME); - s_team = nm_connection_get_setting_team(connection); - g_assert(s_team); + s_team = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_TEAM); g_assert_cmpstr(nm_setting_team_get_config(s_team), ==, expected_config); - - g_object_unref(connection); } static void @@ -10104,7 +8730,6 @@ test_write_team_master(void) gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; NMSettingTeam * s_team; - NMSettingWired * s_wired; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; const char * expected_config = @@ -10113,10 +8738,7 @@ test_write_team_master(void) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Team Master", @@ -10128,29 +8750,18 @@ test_write_team_master(void) NM_SETTING_TEAM_SETTING_NAME, NULL); - /* Team setting */ - s_team = (NMSettingTeam *) nm_setting_team_new(); - nm_connection_add_setting(connection, NM_SETTING(s_team)); - + s_team = _nm_connection_new_setting(connection, NM_TYPE_SETTING_TEAM); g_object_set(s_team, NM_SETTING_TEAM_CONFIG, expected_config, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL); - nm_connection_add_setting(connection, nm_setting_proxy_new()); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_PROXY); nmtst_assert_connection_verifies_without_normalization(connection); @@ -10169,26 +8780,22 @@ test_write_team_master(void) static void test_read_team_port(gconstpointer user_data) { - const char *const PATH_NAME = user_data; - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingTeamPort * s_team_port; - const char * expected_config = "{\"p4p1\": {\"prio\": -10, \"sticky\": true}}"; + const char *const PATH_NAME = user_data; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingTeamPort * s_team_port; + const char * expected_config = "{\"p4p1\": {\"prio\": -10, \"sticky\": true}}"; connection = _connection_from_file(PATH_NAME, NULL, TYPE_ETHERNET, NULL); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), ==, NM_SETTING_WIRED_SETTING_NAME); g_assert_cmpstr(nm_setting_connection_get_master(s_con), ==, "team0"); - s_team_port = nm_connection_get_setting_team_port(connection); - g_assert(s_team_port); + s_team_port = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_TEAM_PORT); g_assert_cmpstr(nm_setting_team_port_get_config(s_team_port), ==, expected_config); - - g_object_unref(connection); } static void @@ -10199,16 +8806,12 @@ test_write_team_port(void) gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; NMSettingTeamPort * s_team_port; - NMSettingWired * s_wired; const char * expected_config = "{\"p4p1\": {\"prio\": -10, \"sticky\": true}}"; shvarFile * f; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Team Port", @@ -10222,14 +8825,10 @@ test_write_team_port(void) NM_SETTING_TEAM_SETTING_NAME, NULL); - /* Team setting */ - s_team_port = (NMSettingTeamPort *) nm_setting_team_port_new(); - nm_connection_add_setting(connection, NM_SETTING(s_team_port)); + s_team_port = _nm_connection_new_setting(connection, NM_TYPE_SETTING_TEAM_PORT); g_object_set(s_team_port, NM_SETTING_TEAM_PORT_CONFIG, expected_config, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); nmtst_assert_connection_verifies(connection); @@ -10258,16 +8857,13 @@ test_write_team_infiniband_port(void) gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; NMSettingTeamPort * s_team_port; - NMSettingInfiniband * s_inf; + NMSettingInfiniband * s_infiniband; const char * expected_config = "{\"inf1\": {\"prio\": -10, \"sticky\": true}}"; shvarFile * f; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Team Infiniband Port", @@ -10283,15 +8879,11 @@ test_write_team_infiniband_port(void) "inf1", NULL); - /* Team setting */ - s_team_port = (NMSettingTeamPort *) nm_setting_team_port_new(); - nm_connection_add_setting(connection, NM_SETTING(s_team_port)); + s_team_port = _nm_connection_new_setting(connection, NM_TYPE_SETTING_TEAM_PORT); g_object_set(s_team_port, NM_SETTING_TEAM_PORT_CONFIG, expected_config, NULL); - /* Infiniband setting */ - s_inf = (NMSettingInfiniband *) nm_setting_infiniband_new(); - nm_connection_add_setting(connection, NM_SETTING(s_inf)); - g_object_set(s_inf, NM_SETTING_INFINIBAND_TRANSPORT_MODE, "datagram", NULL); + s_infiniband = _nm_connection_new_setting(connection, NM_TYPE_SETTING_INFINIBAND); + g_object_set(s_infiniband, NM_SETTING_INFINIBAND_TRANSPORT_MODE, "datagram", NULL); nmtst_assert_connection_verifies(connection); @@ -10315,28 +8907,26 @@ test_write_team_infiniband_port(void) static void test_read_team_port_empty_config(void) { - NMConnection * connection; - NMSettingConnection *s_con; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingTeamPort * s_team_port; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-team-port-empty-config", NULL, TYPE_ETHERNET, NULL); - s_con = nm_connection_get_setting_connection(connection); - g_assert(s_con); + s_con = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_CONNECTION); g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), ==, NM_SETTING_WIRED_SETTING_NAME); g_assert_cmpstr(nm_setting_connection_get_master(s_con), ==, "team0"); /* Normalization adds a team-port setting */ - g_assert(nm_connection_get_setting_team_port(connection)); + s_team_port = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_TEAM_PORT); /* empty/missing config */ - g_assert(!nm_setting_team_port_get_config(nm_connection_get_setting_team_port(connection))); - - g_object_unref(connection); + g_assert(!nm_setting_team_port_get_config(s_team_port)); } static void @@ -10383,7 +8973,7 @@ test_team_reread_slave(void) NM_SETTING_CONNECTION_SLAVE_TYPE, "team", NULL); - g_object_set(nm_connection_get_setting_vlan(connection_2), + g_object_set(nmtst_connection_assert_setting(connection_2, NM_TYPE_SETTING_VLAN), NM_SETTING_VLAN_FLAGS, 1, NM_SETTING_VLAN_ID, @@ -10391,7 +8981,9 @@ test_team_reread_slave(void) NM_SETTING_VLAN_PARENT, "enp31s0f1", NULL); - nm_connection_add_setting(connection_2, nm_setting_team_port_new()); + + _nm_connection_new_setting(connection_2, NM_TYPE_SETTING_TEAM_PORT); + nmtst_connection_normalize(connection_2); nmtst_assert_connection_equals(connection_1, FALSE, connection_2, FALSE); @@ -10416,8 +9008,8 @@ test_team_reread_slave(void) static void test_read_proxy_basic(void) { - NMConnection * connection; - NMSettingProxy *s_proxy; + gs_unref_object NMConnection *connection = NULL; + NMSettingProxy * s_proxy; /* Test basic proxy configuration */ @@ -10426,18 +9018,13 @@ test_read_proxy_basic(void) TYPE_ETHERNET, NULL); - /* ===== Proxy setting ===== */ - s_proxy = nm_connection_get_setting_proxy(connection); - g_assert(s_proxy); + s_proxy = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_PROXY); - /* Proxy method */ g_assert_cmpint(nm_setting_proxy_get_method(s_proxy), ==, NM_SETTING_PROXY_METHOD_AUTO); g_assert(nm_setting_proxy_get_browser_only(s_proxy)); g_assert_cmpstr(nm_setting_proxy_get_pac_url(s_proxy), ==, "http://wpad.mycompany.com/wpad.dat"); - - g_object_unref(connection); } static void @@ -10447,17 +9034,13 @@ test_write_proxy_basic(void) gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; NMSettingConnection * s_con; - NMSettingWired * s_wired; NMSettingProxy * s_proxy; const char * expected_url = "https://wpad.neverland.org/wpad.dat"; shvarFile * f; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write Proxy Basic", @@ -10467,15 +9050,11 @@ test_write_proxy_basic(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Proxy setting */ - s_proxy = (NMSettingProxy *) nm_setting_proxy_new(); - nm_connection_add_setting(connection, NM_SETTING(s_proxy)); + s_proxy = _nm_connection_new_setting(connection, NM_TYPE_SETTING_PROXY); g_object_set(s_proxy, NM_SETTING_PROXY_METHOD, NM_SETTING_PROXY_METHOD_AUTO, NULL); g_object_set(s_proxy, NM_SETTING_PROXY_PAC_URL, expected_url, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); nmtst_assert_connection_verifies(connection); @@ -10943,12 +9522,12 @@ test_write_unknown(gconstpointer test_data) static void test_read_vlan_trailing_spaces(void) { - const char * testfile = TEST_IFCFG_DIR "/ifcfg-test-vlan-trailing-spaces"; - NMConnection * connection; - gboolean success; - GError * error = NULL; - NMSettingVlan *s_vlan; - char * contents = NULL; + const char * testfile = TEST_IFCFG_DIR "/ifcfg-test-vlan-trailing-spaces"; + gs_unref_object NMConnection *connection = NULL; + gboolean success; + GError * error = NULL; + NMSettingVlan * s_vlan; + gs_free char * contents = NULL; /* Ensure there is whitespace at the end of the VLAN interface name, * to prevent the whitespace getting stripped off and committed mistakenly @@ -10959,19 +9538,15 @@ test_read_vlan_trailing_spaces(void) g_assert(success); g_assert(contents && contents[0]); g_assert(strstr(contents, "DEVICE=\"vlan201\" \n")); - g_free(contents); connection = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); - s_vlan = nm_connection_get_setting_vlan(connection); - g_assert(s_vlan); + s_vlan = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_VLAN); g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "vlan201"); g_assert_cmpstr(nm_setting_vlan_get_parent(s_vlan), ==, "enccw0.0.fb00"); g_assert_cmpint(nm_setting_vlan_get_id(s_vlan), ==, 201); g_assert_cmpint(nm_setting_vlan_get_flags(s_vlan), ==, NM_VLAN_FLAG_REORDER_HEADERS); - - g_object_unref(connection); } /*****************************************************************************/ @@ -11022,31 +9597,28 @@ test_utils_name(void) static void do_test_utils_path_ifcfg(const char *desc, const char *path, const char *expected) { - char *result; + gs_free char *result = NULL; result = utils_get_ifcfg_path(path); g_assert_cmpstr(result, ==, expected); - g_free(result); } static void do_test_utils_path_keys(const char *desc, const char *path, const char *expected) { - char *result; + gs_free char *result = NULL; result = utils_get_keys_path(path); g_assert_cmpstr(result, ==, expected); - g_free(result); } static void do_test_utils_path_route(const char *desc, const char *path, const char *expected) { - char *result; + gs_free char *result = NULL; result = utils_get_route_path(path); g_assert_cmpstr(result, ==, expected); - g_free(result); } static void @@ -11116,15 +9688,15 @@ test_sriov_read(void) NMSriovVF * vf; GVariant * variant; GError * error = NULL; - char * str; + gs_free char * str1 = NULL; + gs_free char * str2 = NULL; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-sriov", NULL, TYPE_ETHERNET, NULL); g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "eth0"); - s_sriov = NM_SETTING_SRIOV(nm_connection_get_setting(connection, NM_TYPE_SETTING_SRIOV)); - g_assert(s_sriov); + s_sriov = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_SRIOV); g_assert_cmpint(nm_setting_sriov_get_total_vfs(s_sriov), ==, 16); g_assert_cmpint(nm_setting_sriov_get_num_vfs(s_sriov), ==, 3); @@ -11146,18 +9718,16 @@ test_sriov_read(void) g_assert_cmpint(g_variant_get_boolean(variant), ==, TRUE); /* VF 12 */ - vf = nm_setting_sriov_get_vf(s_sriov, 1); - str = nm_utils_sriov_vf_to_str(vf, FALSE, &error); + vf = nm_setting_sriov_get_vf(s_sriov, 1); + str1 = nm_utils_sriov_vf_to_str(vf, FALSE, &error); g_assert_no_error(error); - g_assert_cmpstr(str, ==, "12 min-tx-rate=100 trust=false vlans=1.200.ad"); - g_free(str); + g_assert_cmpstr(str1, ==, "12 min-tx-rate=100 trust=false vlans=1.200.ad"); /* VF 15 */ - vf = nm_setting_sriov_get_vf(s_sriov, 2); - str = nm_utils_sriov_vf_to_str(vf, FALSE, &error); + vf = nm_setting_sriov_get_vf(s_sriov, 2); + str2 = nm_utils_sriov_vf_to_str(vf, FALSE, &error); g_assert_no_error(error); - g_assert_cmpstr(str, ==, "15 mac=01:23:45:67:89:ab max-tx-rate=200 vlans=2"); - g_free(str); + g_assert_cmpstr(str2, ==, "15 mac=01:23:45:67:89:ab max-tx-rate=200 vlans=2"); } static void @@ -11169,7 +9739,6 @@ test_sriov_write(void) NMSettingConnection * s_con; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - NMSettingWired * s_wired; NMSettingSriov * s_sriov; NMSriovVF * vf; gs_unref_ptrarray GPtrArray *vfs = NULL; @@ -11178,10 +9747,7 @@ test_sriov_write(void) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write SR-IOV config", @@ -11195,14 +9761,9 @@ test_sriov_write(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, @@ -11217,15 +9778,10 @@ test_sriov_write(void) nm_setting_ip_config_add_address(s_ip4, addr); nm_ip_address_unref(addr); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL); - /* SRIOV setting */ - s_sriov = (NMSettingSriov *) nm_setting_sriov_new(); - nm_connection_add_setting(connection, NM_SETTING(s_sriov)); + s_sriov = _nm_connection_new_setting(connection, NM_TYPE_SETTING_SRIOV); vfs = g_ptr_array_new_with_free_func((GDestroyNotify) nm_sriov_vf_unref); @@ -11246,7 +9802,7 @@ test_sriov_write(void) NM_TERNARY_TRUE, NULL); - nm_connection_add_setting(connection, nm_setting_proxy_new()); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_PROXY); nmtst_assert_connection_verifies_without_normalization(connection); @@ -11265,18 +9821,17 @@ test_sriov_write(void) static void test_tc_read(void) { - NMConnection * connection; - NMSettingTCConfig *s_tc; - NMTCQdisc * qdisc; - NMTCTfilter * filter; - char * str; + gs_unref_object NMConnection *connection = NULL; + NMSettingTCConfig * s_tc; + NMTCQdisc * qdisc; + NMTCTfilter * filter; + gs_free char * str = NULL; connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-tc", NULL, TYPE_ETHERNET, NULL); g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "eth0"); - s_tc = nm_connection_get_setting_tc_config(connection); - g_assert(s_tc); + s_tc = nmtst_connection_assert_setting(connection, NM_TYPE_SETTING_TC_CONFIG); g_assert_cmpint(nm_setting_tc_config_get_num_qdiscs(s_tc), ==, 1); qdisc = nm_setting_tc_config_get_qdisc(s_tc, 0); @@ -11290,9 +9845,6 @@ test_tc_read(void) g_assert(filter); str = nm_utils_tc_tfilter_to_str(filter, NULL); g_assert_cmpstr(str, ==, "parent 1234: matchall action simple sdata Hello"); - g_free(str); - - g_object_unref(connection); } static void @@ -11304,17 +9856,12 @@ test_tc_write_empty(void) NMSettingConnection * s_con; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - NMSettingWired * s_wired; - NMSettingTCConfig * s_tc; NMIPAddress * addr; GError * error = NULL; connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write TC config", @@ -11328,14 +9875,9 @@ test_tc_write_empty(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, @@ -11350,17 +9892,12 @@ test_tc_write_empty(void) nm_setting_ip_config_add_address(s_ip4, addr); nm_ip_address_unref(addr); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL); - /* TC setting */ - s_tc = (NMSettingTCConfig *) nm_setting_tc_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_tc)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_TC_CONFIG); - nm_connection_add_setting(connection, nm_setting_proxy_new()); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_PROXY); nmtst_assert_connection_verifies_without_normalization(connection); @@ -11383,7 +9920,6 @@ test_tc_write(void) NMSettingConnection * s_con; NMSettingIPConfig * s_ip4; NMSettingIPConfig * s_ip6; - NMSettingWired * s_wired; NMSettingTCConfig * s_tc; NMTCQdisc * qdisc; NMTCTfilter * tfilter; @@ -11392,10 +9928,7 @@ test_tc_write(void) connection = nm_simple_connection_new(); - /* Connection setting */ - s_con = (NMSettingConnection *) nm_setting_connection_new(); - nm_connection_add_setting(connection, NM_SETTING(s_con)); - + s_con = _nm_connection_new_setting(connection, NM_TYPE_SETTING_CONNECTION); g_object_set(s_con, NM_SETTING_CONNECTION_ID, "Test Write TC config", @@ -11409,14 +9942,9 @@ test_tc_write(void) NM_SETTING_WIRED_SETTING_NAME, NULL); - /* Wired setting */ - s_wired = (NMSettingWired *) nm_setting_wired_new(); - nm_connection_add_setting(connection, NM_SETTING(s_wired)); - - /* IP4 setting */ - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_WIRED); + s_ip4 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP4_CONFIG); g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, @@ -11431,15 +9959,10 @@ test_tc_write(void) nm_setting_ip_config_add_address(s_ip4, addr); nm_ip_address_unref(addr); - /* IP6 setting */ - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_ip6)); - + s_ip6 = _nm_connection_new_setting(connection, NM_TYPE_SETTING_IP6_CONFIG); g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL); - /* TC setting */ - s_tc = (NMSettingTCConfig *) nm_setting_tc_config_new(); - nm_connection_add_setting(connection, NM_SETTING(s_tc)); + s_tc = _nm_connection_new_setting(connection, NM_TYPE_SETTING_TC_CONFIG); qdisc = nm_tc_qdisc_new("pfifo_fast", TC_H_MAKE(0x2468 << 16, 0x2), &error); g_assert_no_error(error); @@ -11452,7 +9975,7 @@ test_tc_write(void) nm_setting_tc_config_add_tfilter(s_tc, tfilter); nm_tc_tfilter_unref(tfilter); - nm_connection_add_setting(connection, nm_setting_proxy_new()); + _nm_connection_new_setting(connection, NM_TYPE_SETTING_PROXY); nmtst_assert_connection_verifies_without_normalization(connection); @@ -12064,6 +10587,8 @@ main(int argc, char **argv) g_test_add_func(TPATH "bond/write-slave", test_write_bond_slave); g_test_add_func(TPATH "bond/write-slave-ib", test_write_bond_slave_ib); g_test_add_func(TPATH "bond/bonding-opts-numeric-mode", test_read_bond_opts_mode_numeric); + g_test_add_func(TPATH "bond/read-bond-port", test_read_bond_port); + g_test_add_func(TPATH "bond/write-bond-port", test_write_bond_port); g_test_add_func(TPATH "bridge/read-master", test_read_bridge_main); g_test_add_func(TPATH "bridge/write-master", test_write_bridge_main); diff --git a/src/core/supplicant/nm-supplicant-config.c b/src/core/supplicant/nm-supplicant-config.c index 1959a1619a..c486ba1dbc 100644 --- a/src/core/supplicant/nm-supplicant-config.c +++ b/src/core/supplicant/nm-supplicant-config.c @@ -417,7 +417,7 @@ nm_supplicant_config_add_setting_macsec(NMSupplicantConfig *self, port = nm_setting_macsec_get_port(setting); if (port > 0 && port < 65534) { - snprintf(buf, sizeof(buf), "%d", port); + g_snprintf(buf, sizeof(buf), "%d", port); if (!nm_supplicant_config_add_option(self, "macsec_port", buf, -1, NULL, error)) return FALSE; } diff --git a/src/libnm-base/nm-base.h b/src/libnm-base/nm-base.h index 3257b3f0a5..b3a57aa806 100644 --- a/src/libnm-base/nm-base.h +++ b/src/libnm-base/nm-base.h @@ -386,4 +386,6 @@ typedef struct { /****************************************************************************/ +#define NM_BOND_PORT_QUEUE_ID_DEF 0 + #endif /* __NM_LIBNM_BASE_H__ */ diff --git a/src/libnm-client-impl/libnm.ver b/src/libnm-client-impl/libnm.ver index f6836afb18..a7717ad65c 100644 --- a/src/libnm-client-impl/libnm.ver +++ b/src/libnm-client-impl/libnm.ver @@ -1803,4 +1803,7 @@ libnm_1_34_0 { global: nm_ip_routing_rule_get_uid_range; nm_ip_routing_rule_set_uid_range; + nm_setting_bond_port_get_queue_id; + nm_setting_bond_port_get_type; + nm_setting_bond_port_new; } libnm_1_32_4; diff --git a/src/libnm-client-public/NetworkManager.h b/src/libnm-client-public/NetworkManager.h index 97d3e649a1..3134562e61 100644 --- a/src/libnm-client-public/NetworkManager.h +++ b/src/libnm-client-public/NetworkManager.h @@ -55,6 +55,7 @@ #include "nm-setting-adsl.h" #include "nm-setting-bluetooth.h" #include "nm-setting-bond.h" +#include "nm-setting-bond-port.h" #include "nm-setting-bridge.h" #include "nm-setting-bridge-port.h" #include "nm-setting-cdma.h" diff --git a/src/libnm-client-public/nm-autoptr.h b/src/libnm-client-public/nm-autoptr.h index f37e2cfc44..6c34946ca7 100644 --- a/src/libnm-client-public/nm-autoptr.h +++ b/src/libnm-client-public/nm-autoptr.h @@ -67,6 +67,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(NMSetting8021x, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC(NMSettingAdsl, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC(NMSettingBluetooth, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC(NMSettingBond, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC(NMSettingBondPort, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC(NMSettingBridge, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC(NMSettingBridgePort, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC(NMSettingCdma, g_object_unref) diff --git a/src/libnm-core-aux-intern/nm-libnm-core-utils.c b/src/libnm-core-aux-intern/nm-libnm-core-utils.c index 53e452f0ff..e168885947 100644 --- a/src/libnm-core-aux-intern/nm-libnm-core-utils.c +++ b/src/libnm-core-aux-intern/nm-libnm-core-utils.c @@ -362,13 +362,19 @@ nm_settings_connection_validate_permission_user(const char *item, gssize len) gpointer _nm_connection_ensure_setting(NMConnection *connection, GType gtype) +{ + return nm_connection_get_setting(connection, gtype) + ?: _nm_connection_new_setting(connection, gtype); +} + +gpointer +_nm_connection_new_setting(NMConnection *connection, GType gtype) { NMSetting *setting; - setting = nm_connection_get_setting(connection, gtype); - if (!setting) { - setting = g_object_new(gtype, NULL); - nm_connection_add_setting(connection, setting); - } + nm_assert(g_type_is_a(gtype, NM_TYPE_SETTING)); + + setting = g_object_new(gtype, NULL); + nm_connection_add_setting(connection, setting); return setting; } diff --git a/src/libnm-core-aux-intern/nm-libnm-core-utils.h b/src/libnm-core-aux-intern/nm-libnm-core-utils.h index fc0bd9720f..f90e3984c1 100644 --- a/src/libnm-core-aux-intern/nm-libnm-core-utils.h +++ b/src/libnm-core-aux-intern/nm-libnm-core-utils.h @@ -166,6 +166,9 @@ gboolean nm_utils_validate_dhcp4_vendor_class_id(const char *vci, GError **error gboolean nm_settings_connection_validate_permission_user(const char *item, gssize len); +/*****************************************************************************/ + gpointer _nm_connection_ensure_setting(NMConnection *connection, GType gtype); +gpointer _nm_connection_new_setting(NMConnection *connection, GType gtype); #endif /* __NM_LIBNM_SHARED_UTILS_H__ */ diff --git a/src/libnm-core-impl/meson.build b/src/libnm-core-impl/meson.build index f175ea3b29..2e1f175177 100644 --- a/src/libnm-core-impl/meson.build +++ b/src/libnm-core-impl/meson.build @@ -37,6 +37,7 @@ libnm_core_settings_sources = files( 'nm-setting-adsl.c', 'nm-setting-bluetooth.c', 'nm-setting-bond.c', + 'nm-setting-bond-port.c', 'nm-setting-bridge-port.c', 'nm-setting-bridge.c', 'nm-setting-cdma.c', diff --git a/src/libnm-core-impl/nm-connection.c b/src/libnm-core-impl/nm-connection.c index 03fde1f9cf..9bc8df3f9b 100644 --- a/src/libnm-core-impl/nm-connection.c +++ b/src/libnm-core-impl/nm-connection.c @@ -1074,6 +1074,7 @@ _nm_connection_detect_slave_type(NMConnection *connection, NMSetting **out_s_por const char * controller_type_name; } infos[] = { {NM_META_SETTING_TYPE_BRIDGE_PORT, NM_SETTING_BRIDGE_SETTING_NAME}, + {NM_META_SETTING_TYPE_BOND_PORT, NM_SETTING_BOND_SETTING_NAME}, {NM_META_SETTING_TYPE_TEAM_PORT, NM_SETTING_TEAM_SETTING_NAME}, {NM_META_SETTING_TYPE_OVS_PORT, NM_SETTING_OVS_BRIDGE_SETTING_NAME}, {NM_META_SETTING_TYPE_OVS_INTERFACE, NM_SETTING_OVS_PORT_SETTING_NAME}, @@ -1679,6 +1680,10 @@ _normalize_invalid_slave_port_settings(NMConnection *self) && _nm_connection_remove_setting(self, NM_TYPE_SETTING_BRIDGE_PORT)) changed = TRUE; + if (!nm_streq0(slave_type, NM_SETTING_BOND_SETTING_NAME) + && _nm_connection_remove_setting(self, NM_TYPE_SETTING_BOND_PORT)) + changed = TRUE; + if (!nm_streq0(slave_type, NM_SETTING_TEAM_SETTING_NAME) && _nm_connection_remove_setting(self, NM_TYPE_SETTING_TEAM_PORT)) changed = TRUE; diff --git a/src/libnm-core-impl/nm-meta-setting-base-impl.c b/src/libnm-core-impl/nm-meta-setting-base-impl.c index d79f2529cb..8c1ad10ea8 100644 --- a/src/libnm-core-impl/nm-meta-setting-base-impl.c +++ b/src/libnm-core-impl/nm-meta-setting-base-impl.c @@ -16,6 +16,7 @@ #include "nm-setting-adsl.h" #include "nm-setting-bluetooth.h" #include "nm-setting-bond.h" +#include "nm-setting-bond-port.h" #include "nm-setting-bridge-port.h" #include "nm-setting-bridge.h" #include "nm-setting-cdma.h" @@ -190,6 +191,13 @@ const NMMetaSettingInfo nm_meta_setting_infos[] = { .setting_name = NM_SETTING_BOND_SETTING_NAME, .get_setting_gtype = nm_setting_bond_get_type, }, + [NM_META_SETTING_TYPE_BOND_PORT] = + { + .meta_type = NM_META_SETTING_TYPE_BOND_PORT, + .setting_priority = NM_SETTING_PRIORITY_AUX, + .setting_name = NM_SETTING_BOND_PORT_SETTING_NAME, + .get_setting_gtype = nm_setting_bond_port_get_type, + }, [NM_META_SETTING_TYPE_BRIDGE] = { .meta_type = NM_META_SETTING_TYPE_BRIDGE, @@ -568,6 +576,7 @@ const NMMetaSettingType nm_meta_setting_types_by_priority[] = { NM_META_SETTING_TYPE_SRIOV, /* NM_SETTING_PRIORITY_AUX */ + NM_META_SETTING_TYPE_BOND_PORT, NM_META_SETTING_TYPE_BRIDGE_PORT, NM_META_SETTING_TYPE_ETHTOOL, NM_META_SETTING_TYPE_MATCH, diff --git a/src/libnm-core-impl/nm-setting-bond-port.c b/src/libnm-core-impl/nm-setting-bond-port.c new file mode 100644 index 0000000000..5eb1bfd07f --- /dev/null +++ b/src/libnm-core-impl/nm-setting-bond-port.c @@ -0,0 +1,174 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021 Red Hat, Inc. + */ + +#include "libnm-core-impl/nm-default-libnm-core.h" + +#include "nm-connection-private.h" +#include "nm-setting-bond-port.h" +#include "nm-setting-bond.h" +#include "nm-setting-connection.h" +#include "nm-utils-private.h" +#include "nm-utils.h" + +/** + * SECTION:nm-setting-bond-port + * @short_description: Describes connection properties for bond ports + * + * The #NMSettingBondPort object is a #NMSetting subclass that describes + * optional properties that apply to bond ports. + **/ + +/*****************************************************************************/ + +NM_GOBJECT_PROPERTIES_DEFINE(NMSettingBondPort, PROP_QUEUE_ID, ); + +typedef struct { + guint32 queue_id; +} NMSettingBondPortPrivate; + +/** + * NMSettingBondPort: + * + * Bond Port Settings + */ +struct _NMSettingBondPort { + NMSetting parent; + NMSettingBondPortPrivate _priv; +}; + +struct _NMSettingBondPortClass { + NMSettingClass parent; +}; + +G_DEFINE_TYPE(NMSettingBondPort, nm_setting_bond_port, NM_TYPE_SETTING) + +#define NM_SETTING_BOND_PORT_GET_PRIVATE(self) \ + _NM_GET_PRIVATE(self, NMSettingBondPort, NM_IS_SETTING_BOND_PORT, NMSetting) + +/*****************************************************************************/ + +/** + * nm_setting_bond_port_get_queue_id: + * @setting: the #NMSettingBondPort + * + * Returns: the #NMSettingBondPort:queue_id property of the setting + * + * Since: 1.34 + **/ +guint32 +nm_setting_bond_port_get_queue_id(NMSettingBondPort *setting) +{ + g_return_val_if_fail(NM_IS_SETTING_BOND_PORT(setting), 0); + + return NM_SETTING_BOND_PORT_GET_PRIVATE(setting)->queue_id; +} + +/*****************************************************************************/ + +static gboolean +verify(NMSetting *setting, NMConnection *connection, GError **error) +{ + if (connection) { + NMSettingConnection *s_con; + const char * slave_type; + + s_con = nm_connection_get_setting_connection(connection); + if (!s_con) { + g_set_error(error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_MISSING_SETTING, + _("missing setting")); + g_prefix_error(error, "%s: ", NM_SETTING_CONNECTION_SETTING_NAME); + return FALSE; + } + + slave_type = nm_setting_connection_get_slave_type(s_con); + if (!nm_streq0(slave_type, NM_SETTING_BOND_SETTING_NAME)) { + g_set_error(error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_INVALID_PROPERTY, + _("A connection with a '%s' setting must have the slave-type set to '%s'"), + NM_SETTING_BOND_PORT_SETTING_NAME, + NM_SETTING_BOND_SETTING_NAME); + g_prefix_error(error, + "%s.%s: ", + NM_SETTING_CONNECTION_SETTING_NAME, + NM_SETTING_CONNECTION_SLAVE_TYPE); + return FALSE; + } + } + + return TRUE; +} + +/*****************************************************************************/ + +static void +nm_setting_bond_port_init(NMSettingBondPort *setting) +{} + +/** + * nm_setting_bond_port_new: + * + * Creates a new #NMSettingBondPort object with default values. + * + * Returns: (transfer full): the new empty #NMSettingBondPort object + * + * Since: 1.34 + **/ +NMSetting * +nm_setting_bond_port_new(void) +{ + return g_object_new(NM_TYPE_SETTING_BOND_PORT, NULL); +} + +static void +nm_setting_bond_port_class_init(NMSettingBondPortClass *klass) +{ + GObjectClass * object_class = G_OBJECT_CLASS(klass); + NMSettingClass *setting_class = NM_SETTING_CLASS(klass); + GArray * properties_override = _nm_sett_info_property_override_create_array(); + + object_class->get_property = _nm_setting_property_get_property_direct; + object_class->set_property = _nm_setting_property_set_property_direct; + + setting_class->verify = verify; + setting_class->finalize_direct = TRUE; + + /** + * NMSettingBondPort:queue-id: + * + * The queue ID of this bond port. The maximum value of queue ID is + * the number of TX queues currently active in device. + * + * Since: 1.34 + **/ + /* ---ifcfg-rh--- + * property: queue-id + * variable: BONDING_OPTS: queue-id= + * values: 0 - 65535 + * default: 0 + * description: Queue ID. + * ---end--- + */ + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_BOND_PORT_QUEUE_ID, + PROP_QUEUE_ID, + 0, + G_MAXUINT16, + NM_BOND_PORT_QUEUE_ID_DEF, + NM_SETTING_PARAM_INFERRABLE, + NMSettingBondPort, + _priv.queue_id); + + g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); + + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_BOND_PORT, + NULL, + properties_override, + 0); +} diff --git a/src/libnm-core-impl/nm-utils.c b/src/libnm-core-impl/nm-utils.c index aece39a5c9..ccdd4b92a6 100644 --- a/src/libnm-core-impl/nm-utils.c +++ b/src/libnm-core-impl/nm-utils.c @@ -29,6 +29,7 @@ #include "nm-setting-private.h" #include "nm-crypto.h" #include "nm-setting-bond.h" +#include "nm-setting-bond-port.h" #include "nm-setting-bridge.h" #include "nm-setting-bridge-port.h" #include "nm-setting-infiniband.h" diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index 02eb89666d..c84bee19d2 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -121,7 +121,7 @@ test_nm_meta_setting_types_by_priority(void) G_STATIC_ASSERT_EXPR(_NM_META_SETTING_TYPE_NUM == G_N_ELEMENTS(nm_meta_setting_types_by_priority)); - G_STATIC_ASSERT_EXPR(_NM_META_SETTING_TYPE_NUM == 51); + G_STATIC_ASSERT_EXPR(_NM_META_SETTING_TYPE_NUM == 52); arr = g_ptr_array_new_with_free_func(g_object_unref); diff --git a/src/libnm-core-intern/nm-core-internal.h b/src/libnm-core-intern/nm-core-internal.h index 3fed38d552..c50eaf41ee 100644 --- a/src/libnm-core-intern/nm-core-internal.h +++ b/src/libnm-core-intern/nm-core-internal.h @@ -29,6 +29,7 @@ #include "nm-setting-adsl.h" #include "nm-setting-bluetooth.h" #include "nm-setting-bond.h" +#include "nm-setting-bond-port.h" #include "nm-setting-bridge-port.h" #include "nm-setting-bridge.h" #include "nm-setting-cdma.h" diff --git a/src/libnm-core-intern/nm-meta-setting-base-impl.h b/src/libnm-core-intern/nm-meta-setting-base-impl.h index 8aec1e8756..eba1fb96f4 100644 --- a/src/libnm-core-intern/nm-meta-setting-base-impl.h +++ b/src/libnm-core-intern/nm-meta-setting-base-impl.h @@ -110,6 +110,7 @@ typedef enum _nm_packed { NM_META_SETTING_TYPE_ADSL, NM_META_SETTING_TYPE_BLUETOOTH, NM_META_SETTING_TYPE_BOND, + NM_META_SETTING_TYPE_BOND_PORT, NM_META_SETTING_TYPE_BRIDGE, NM_META_SETTING_TYPE_BRIDGE_PORT, NM_META_SETTING_TYPE_CDMA, diff --git a/src/libnm-core-public/meson.build b/src/libnm-core-public/meson.build index 6b8dad0f28..f1da4d023d 100644 --- a/src/libnm-core-public/meson.build +++ b/src/libnm-core-public/meson.build @@ -13,6 +13,7 @@ libnm_core_headers = files( 'nm-setting-adsl.h', 'nm-setting-bluetooth.h', 'nm-setting-bond.h', + 'nm-setting-bond-port.h', 'nm-setting-bridge-port.h', 'nm-setting-bridge.h', 'nm-setting-cdma.h', diff --git a/src/libnm-core-public/nm-core-types.h b/src/libnm-core-public/nm-core-types.h index bf0c2a9966..c86c28fa47 100644 --- a/src/libnm-core-public/nm-core-types.h +++ b/src/libnm-core-public/nm-core-types.h @@ -19,6 +19,7 @@ typedef struct _NMSetting8021x NMSetting8021x; typedef struct _NMSettingAdsl NMSettingAdsl; typedef struct _NMSettingBluetooth NMSettingBluetooth; typedef struct _NMSettingBond NMSettingBond; +typedef struct _NMSettingBondPort NMSettingBondPort; typedef struct _NMSettingBridge NMSettingBridge; typedef struct _NMSettingBridgePort NMSettingBridgePort; typedef struct _NMSettingCdma NMSettingCdma; diff --git a/src/libnm-core-public/nm-setting-bond-port.h b/src/libnm-core-public/nm-setting-bond-port.h new file mode 100644 index 0000000000..0b20e4a8cb --- /dev/null +++ b/src/libnm-core-public/nm-setting-bond-port.h @@ -0,0 +1,46 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2012 Red Hat, Inc. + */ + +#ifndef __NM_SETTING_BOND_PORT_H__ +#define __NM_SETTING_BOND_PORT_H__ + +#if !defined(__NETWORKMANAGER_H_INSIDE__) && !defined(NETWORKMANAGER_COMPILATION) +#error "Only can be included directly." +#endif + +#include "nm-setting.h" +#include "nm-setting-bond.h" + +G_BEGIN_DECLS + +#define NM_TYPE_SETTING_BOND_PORT (nm_setting_bond_port_get_type()) +#define NM_SETTING_BOND_PORT(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_SETTING_BOND_PORT, NMSettingBondPort)) +#define NM_SETTING_BOND_PORT_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), NM_TYPE_SETTING_BOND_PORT, NMSettingBondPortClass)) +#define NM_IS_SETTING_BOND_PORT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NM_TYPE_SETTING_BOND_PORT)) +#define NM_IS_SETTING_BOND_PORT_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), NM_TYPE_SETTING_BOND_PORT)) +#define NM_SETTING_BOND_PORT_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS((obj), NM_TYPE_SETTING_BOND_PORT, NMSettingBondPortClass)) + +#define NM_SETTING_BOND_PORT_SETTING_NAME "bond-port" + +#define NM_SETTING_BOND_PORT_QUEUE_ID "queue-id" + +typedef struct _NMSettingBondPortClass NMSettingBondPortClass; + +NM_AVAILABLE_IN_1_34 +GType nm_setting_bond_port_get_type(void); + +NM_AVAILABLE_IN_1_34 +NMSetting *nm_setting_bond_port_new(void); + +NM_AVAILABLE_IN_1_34 +guint32 nm_setting_bond_port_get_queue_id(NMSettingBondPort *setting); + +G_END_DECLS + +#endif /* __NM_SETTING_BOND_PORT_H__ */ diff --git a/src/libnm-glib-aux/nm-test-utils.h b/src/libnm-glib-aux/nm-test-utils.h index b759151508..2e01f3e810 100644 --- a/src/libnm-glib-aux/nm-test-utils.h +++ b/src/libnm-glib-aux/nm-test-utils.h @@ -1982,6 +1982,28 @@ nmtst_assert_route_attribute_boolean(NMIPRoute *route, const char *name, gboolea #if (defined(__NM_SIMPLE_CONNECTION_H__) && defined(__NM_SETTING_CONNECTION_H__)) \ || (defined(NM_CONNECTION_H)) +#define nmtst_connection_assert_setting(connection, gtype) \ + ({ \ + const GType _gtype = (gtype); \ + gpointer _ptr; \ + \ + _ptr = nm_connection_get_setting((connection), (_gtype)); \ + g_assert(NM_IS_SETTING(_ptr)); \ + g_assert(G_OBJECT_TYPE(_ptr) == _gtype); \ + _ptr; \ + }) + +#define nmtst_connection_assert_no_setting(connection, gtype) \ + G_STMT_START \ + { \ + const GType _gtype = (gtype); \ + gpointer _ptr; \ + \ + _ptr = nm_connection_get_setting((connection), (_gtype)); \ + g_assert(!_ptr); \ + } \ + G_STMT_END + static inline NMConnection * nmtst_clone_connection(NMConnection *connection) { @@ -2854,4 +2876,20 @@ nmtst_ip_address_new(int addr_family, const char *str) /*****************************************************************************/ +#define nmtst_gbytes_from_arr(...) \ + ({ \ + const guint8 _arr[] = {__VA_ARGS__}; \ + \ + g_bytes_new(_arr, sizeof(_arr)); \ + }) + +#define nmtst_gbytes_from_str(str) \ + ({ \ + const char *const _str = (str); \ + \ + g_bytes_new(_str, strlen(_str)); \ + }) + +/*****************************************************************************/ + #endif /* __NM_TEST_UTILS_H__ */ diff --git a/src/libnm-platform/nm-platform.c b/src/libnm-platform/nm-platform.c index ae9ee04e97..1301121f4c 100644 --- a/src/libnm-platform/nm-platform.c +++ b/src/libnm-platform/nm-platform.c @@ -2563,6 +2563,8 @@ slave_category(NMPlatform *self, int slave) switch (nm_platform_link_get_type(self, master)) { case NM_LINK_TYPE_BRIDGE: return "brport"; + case NM_LINK_TYPE_BOND: + return "bonding_slave"; default: return NULL; } diff --git a/src/libnmc-setting/nm-meta-setting-base-impl.c b/src/libnmc-setting/nm-meta-setting-base-impl.c index d79f2529cb..8c1ad10ea8 100644 --- a/src/libnmc-setting/nm-meta-setting-base-impl.c +++ b/src/libnmc-setting/nm-meta-setting-base-impl.c @@ -16,6 +16,7 @@ #include "nm-setting-adsl.h" #include "nm-setting-bluetooth.h" #include "nm-setting-bond.h" +#include "nm-setting-bond-port.h" #include "nm-setting-bridge-port.h" #include "nm-setting-bridge.h" #include "nm-setting-cdma.h" @@ -190,6 +191,13 @@ const NMMetaSettingInfo nm_meta_setting_infos[] = { .setting_name = NM_SETTING_BOND_SETTING_NAME, .get_setting_gtype = nm_setting_bond_get_type, }, + [NM_META_SETTING_TYPE_BOND_PORT] = + { + .meta_type = NM_META_SETTING_TYPE_BOND_PORT, + .setting_priority = NM_SETTING_PRIORITY_AUX, + .setting_name = NM_SETTING_BOND_PORT_SETTING_NAME, + .get_setting_gtype = nm_setting_bond_port_get_type, + }, [NM_META_SETTING_TYPE_BRIDGE] = { .meta_type = NM_META_SETTING_TYPE_BRIDGE, @@ -568,6 +576,7 @@ const NMMetaSettingType nm_meta_setting_types_by_priority[] = { NM_META_SETTING_TYPE_SRIOV, /* NM_SETTING_PRIORITY_AUX */ + NM_META_SETTING_TYPE_BOND_PORT, NM_META_SETTING_TYPE_BRIDGE_PORT, NM_META_SETTING_TYPE_ETHTOOL, NM_META_SETTING_TYPE_MATCH, diff --git a/src/libnmc-setting/nm-meta-setting-base-impl.h b/src/libnmc-setting/nm-meta-setting-base-impl.h index 8aec1e8756..eba1fb96f4 100644 --- a/src/libnmc-setting/nm-meta-setting-base-impl.h +++ b/src/libnmc-setting/nm-meta-setting-base-impl.h @@ -110,6 +110,7 @@ typedef enum _nm_packed { NM_META_SETTING_TYPE_ADSL, NM_META_SETTING_TYPE_BLUETOOTH, NM_META_SETTING_TYPE_BOND, + NM_META_SETTING_TYPE_BOND_PORT, NM_META_SETTING_TYPE_BRIDGE, NM_META_SETTING_TYPE_BRIDGE_PORT, NM_META_SETTING_TYPE_CDMA, diff --git a/src/libnmc-setting/nm-meta-setting-desc.c b/src/libnmc-setting/nm-meta-setting-desc.c index 812ec3f044..ea260b4e9b 100644 --- a/src/libnmc-setting/nm-meta-setting-desc.c +++ b/src/libnmc-setting/nm-meta-setting-desc.c @@ -5048,6 +5048,18 @@ static const NMMetaPropertyInfo *const property_infos_BOND[] = { NULL }; +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_BOND_PORT +static const NMMetaPropertyInfo *const property_infos_BOND_PORT[] = { + PROPERTY_INFO_WITH_DESC (NM_SETTING_BOND_PORT_QUEUE_ID, + .is_cli_option = TRUE, + .property_alias = "queue-id", + .prompt = N_("Queue ID [0]"), + .property_type = &_pt_gobject_int, + ), + NULL +}; + #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_BRIDGE static const NMMetaPropertyInfo *const property_infos_BRIDGE[] = { @@ -8113,6 +8125,7 @@ _setting_init_fcn_wireless (ARGS_SETTING_INIT_FCN) #define SETTING_PRETTY_NAME_ADSL N_("ADSL connection") #define SETTING_PRETTY_NAME_BLUETOOTH N_("bluetooth connection") #define SETTING_PRETTY_NAME_BOND N_("Bond device") +#define SETTING_PRETTY_NAME_BOND_PORT N_("Bond port") #define SETTING_PRETTY_NAME_BRIDGE N_("Bridge device") #define SETTING_PRETTY_NAME_BRIDGE_PORT N_("Bridge port") #define SETTING_PRETTY_NAME_CDMA N_("CDMA mobile broadband connection") @@ -8217,6 +8230,7 @@ const NMMetaSettingInfoEditor nm_meta_setting_infos_editor[] = { NM_META_SETTING_VALID_PART_ITEM (ETHTOOL, FALSE), ), ), + SETTING_INFO (BOND_PORT), SETTING_INFO (BRIDGE, .valid_parts = NM_META_SETTING_VALID_PARTS ( NM_META_SETTING_VALID_PART_ITEM (CONNECTION, TRUE), @@ -8497,6 +8511,11 @@ static const NMMetaSettingValidPartItem *const valid_settings_noslave[] = { NULL, }; +static const NMMetaSettingValidPartItem *const valid_settings_slave_bond[] = { + NM_META_SETTING_VALID_PART_ITEM(BOND_PORT, TRUE), + NULL, +}; + static const NMMetaSettingValidPartItem *const valid_settings_slave_bridge[] = { NM_META_SETTING_VALID_PART_ITEM(BRIDGE_PORT, TRUE), NULL, @@ -8526,7 +8545,7 @@ nm_meta_setting_info_valid_parts_for_slave_type(const char *slave_type, const ch } if (nm_streq(slave_type, NM_SETTING_BOND_SETTING_NAME)) { NM_SET_OUT(out_slave_name, "bond-slave"); - return NM_PTRARRAY_EMPTY(const NMMetaSettingValidPartItem *); + return valid_settings_slave_bond; } if (nm_streq(slave_type, NM_SETTING_BRIDGE_SETTING_NAME)) { NM_SET_OUT(out_slave_name, "bridge-slave"); diff --git a/src/libnmc-setting/settings-docs.h.in b/src/libnmc-setting/settings-docs.h.in index b7e2c1f7b2..3bad7cf810 100644 --- a/src/libnmc-setting/settings-docs.h.in +++ b/src/libnmc-setting/settings-docs.h.in @@ -114,6 +114,7 @@ #define DESCRIBE_DOC_NM_SETTING_BLUETOOTH_BDADDR N_("The Bluetooth address of the device.") #define DESCRIBE_DOC_NM_SETTING_BLUETOOTH_TYPE N_("Either \"dun\" for Dial-Up Networking connections or \"panu\" for Personal Area Networking connections to devices supporting the NAP profile.") #define DESCRIBE_DOC_NM_SETTING_BOND_OPTIONS N_("Dictionary of key/value pairs of bonding options. Both keys and values must be strings. Option names must contain only alphanumeric characters (ie, [a-zA-Z0-9]).") +#define DESCRIBE_DOC_NM_SETTING_BOND_PORT_QUEUE_ID N_("The queue ID of this bond port. The maximum value of queue ID is the number of TX queues currently active in device.") #define DESCRIBE_DOC_NM_SETTING_BRIDGE_AGEING_TIME N_("The Ethernet MAC address aging time, in seconds.") #define DESCRIBE_DOC_NM_SETTING_BRIDGE_FORWARD_DELAY N_("The Spanning Tree Protocol (STP) forwarding delay, in seconds.") #define DESCRIBE_DOC_NM_SETTING_BRIDGE_GROUP_ADDRESS N_("If specified, The MAC address of the multicast group this bridge uses for STP. The address must be a link-local address in standard Ethernet MAC address format, ie an address of the form 01:80:C2:00:00:0X, with X in [0, 4..F]. If not specified the default value is 01:80:C2:00:00:00.") diff --git a/src/nmcli/connections.c b/src/nmcli/connections.c index 10bc224c19..e8e607ec5e 100644 --- a/src/nmcli/connections.c +++ b/src/nmcli/connections.c @@ -874,18 +874,19 @@ const NmcMetaGenericInfo "," NM_SETTING_CDMA_SETTING_NAME "," NM_SETTING_BLUETOOTH_SETTING_NAME \ "," NM_SETTING_OLPC_MESH_SETTING_NAME "," NM_SETTING_VPN_SETTING_NAME \ "," NM_SETTING_INFINIBAND_SETTING_NAME "," NM_SETTING_BOND_SETTING_NAME \ - "," NM_SETTING_VLAN_SETTING_NAME "," NM_SETTING_BRIDGE_SETTING_NAME \ - "," NM_SETTING_BRIDGE_PORT_SETTING_NAME "," NM_SETTING_TEAM_SETTING_NAME \ - "," NM_SETTING_TEAM_PORT_SETTING_NAME "," NM_SETTING_OVS_BRIDGE_SETTING_NAME \ - "," NM_SETTING_OVS_INTERFACE_SETTING_NAME "," NM_SETTING_OVS_PATCH_SETTING_NAME \ - "," NM_SETTING_OVS_PORT_SETTING_NAME "," NM_SETTING_DCB_SETTING_NAME \ - "," NM_SETTING_TUN_SETTING_NAME "," NM_SETTING_IP_TUNNEL_SETTING_NAME \ - "," NM_SETTING_MACSEC_SETTING_NAME "," NM_SETTING_MACVLAN_SETTING_NAME \ - "," NM_SETTING_VXLAN_SETTING_NAME "," NM_SETTING_VRF_SETTING_NAME \ - "," NM_SETTING_WPAN_SETTING_NAME "," NM_SETTING_6LOWPAN_SETTING_NAME \ - "," NM_SETTING_WIREGUARD_SETTING_NAME "," NM_SETTING_PROXY_SETTING_NAME \ - "," NM_SETTING_TC_CONFIG_SETTING_NAME "," NM_SETTING_SRIOV_SETTING_NAME \ - "," NM_SETTING_ETHTOOL_SETTING_NAME "," NM_SETTING_OVS_DPDK_SETTING_NAME \ + "," NM_SETTING_BOND_PORT_SETTING_NAME "," NM_SETTING_VLAN_SETTING_NAME \ + "," NM_SETTING_BRIDGE_SETTING_NAME "," NM_SETTING_BRIDGE_PORT_SETTING_NAME \ + "," NM_SETTING_TEAM_SETTING_NAME "," NM_SETTING_TEAM_PORT_SETTING_NAME \ + "," NM_SETTING_OVS_BRIDGE_SETTING_NAME "," NM_SETTING_OVS_INTERFACE_SETTING_NAME \ + "," NM_SETTING_OVS_PATCH_SETTING_NAME "," NM_SETTING_OVS_PORT_SETTING_NAME \ + "," NM_SETTING_DCB_SETTING_NAME "," NM_SETTING_TUN_SETTING_NAME \ + "," NM_SETTING_IP_TUNNEL_SETTING_NAME "," NM_SETTING_MACSEC_SETTING_NAME \ + "," NM_SETTING_MACVLAN_SETTING_NAME "," NM_SETTING_VXLAN_SETTING_NAME \ + "," NM_SETTING_VRF_SETTING_NAME "," NM_SETTING_WPAN_SETTING_NAME \ + "," NM_SETTING_6LOWPAN_SETTING_NAME "," NM_SETTING_WIREGUARD_SETTING_NAME \ + "," NM_SETTING_PROXY_SETTING_NAME "," NM_SETTING_TC_CONFIG_SETTING_NAME \ + "," NM_SETTING_SRIOV_SETTING_NAME "," NM_SETTING_ETHTOOL_SETTING_NAME \ + "," NM_SETTING_OVS_DPDK_SETTING_NAME \ "," NM_SETTING_HOSTNAME_SETTING_NAME /* NM_SETTING_DUMMY_SETTING_NAME NM_SETTING_WIMAX_SETTING_NAME */ const NmcMetaGenericInfo *const nmc_fields_con_active_details_groups[] = { @@ -1062,7 +1063,8 @@ usage_connection_add(void) " [arp-interval ]\n" " [arp-ip-target ]\n" " [lacp-rate slow (0) | fast (1)]\n\n" - " bond-slave: master \n\n" + " bond-slave: master \n" + " [queue-id <0-65535>]\n\n" " team: [config |]\n\n" " team-slave: master \n" " [config |]\n\n" @@ -1125,6 +1127,7 @@ usage_connection_add(void) " [path-cost <1-65535>]\n" " [hairpin yes|no]\n\n" " team: [config |]\n\n" + " bond: [queue-id <0-65535>]\n\n" " IP_OPTIONS:\n" " [ip4 ] [gw4 ]\n" " [ip6 ] [gw6 ]\n\n")); @@ -3791,13 +3794,13 @@ prompt_yes_no(gboolean default_yes, char *delim) if (!delim) delim = ""; - snprintf(prompt, - sizeof(prompt), - "(%s/%s) [%s]%s ", - WORD_YES, - WORD_NO, - default_yes ? WORD_YES : WORD_NO, - delim); + g_snprintf(prompt, + sizeof(prompt), + "(%s/%s) [%s]%s ", + WORD_YES, + WORD_NO, + default_yes ? WORD_YES : WORD_NO, + delim); return prompt; } @@ -6007,6 +6010,8 @@ gen_property_names(const char *text, int state) slv_type = NM_SETTING_TEAM_SETTING_NAME; else if (nm_streq0(strv[0], NM_SETTING_BRIDGE_PORT_SETTING_NAME)) slv_type = NM_SETTING_BRIDGE_SETTING_NAME; + else if (nm_streq0(strv[0], NM_SETTING_BOND_PORT_SETTING_NAME)) + slv_type = NM_SETTING_BOND_SETTING_NAME; else slv_type = NULL; valid_settings_slave = nm_meta_setting_info_valid_parts_for_slave_type(slv_type, NULL); diff --git a/src/nmcli/generate-docs-nm-settings-nmcli.xml.in b/src/nmcli/generate-docs-nm-settings-nmcli.xml.in index b07e238290..a4f412f551 100644 --- a/src/nmcli/generate-docs-nm-settings-nmcli.xml.in +++ b/src/nmcli/generate-docs-nm-settings-nmcli.xml.in @@ -267,6 +267,11 @@ + + + edit_connection)); else if (!strcmp(slave_type, NM_SETTING_TEAM_SETTING_NAME)) add_sections_for_page(editor, grid, nmt_page_team_port_new(priv->edit_connection)); + else if (nm_streq(slave_type, NM_SETTING_BOND_SETTING_NAME)) + add_sections_for_page(editor, grid, nmt_page_bond_port_new(priv->edit_connection)); } else { NmtNewtWidget *section; diff --git a/src/nmtui/nmt-editor.h b/src/nmtui/nmt-editor.h index 49fe89d38f..602a61aeaf 100644 --- a/src/nmtui/nmt-editor.h +++ b/src/nmtui/nmt-editor.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2013 Red Hat, Inc. */ diff --git a/src/nmtui/nmt-page-bond-port.c b/src/nmtui/nmt-page-bond-port.c new file mode 100644 index 0000000000..156553c257 --- /dev/null +++ b/src/nmtui/nmt-page-bond-port.c @@ -0,0 +1,64 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021 Red Hat, Inc. + */ + +/** + * SECTION:nmt-page-bond-port + * @short_description: The editor page for Bond ports + */ + +#include "libnm-client-aux-extern/nm-default-client.h" + +#include "nmt-page-bond-port.h" + +#include "libnm-core-aux-intern/nm-libnm-core-utils.h" + +G_DEFINE_TYPE(NmtPageBondPort, nmt_page_bond_port, NMT_TYPE_EDITOR_PAGE) + +static void +nmt_page_bond_port_init(NmtPageBondPort *bond) +{} + +NmtEditorPage * +nmt_page_bond_port_new(NMConnection *conn) +{ + return g_object_new(NMT_TYPE_PAGE_BOND_PORT, "connection", conn, NULL); +} + +static void +nmt_page_bond_port_constructed(GObject *object) +{ + NmtPageBondPort * bond = NMT_PAGE_BOND_PORT(object); + NmtEditorSection * section; + NmtEditorGrid * grid; + NMSettingBondPort *s_port; + NmtNewtWidget * widget; + NMConnection * conn; + + conn = nmt_editor_page_get_connection(NMT_EDITOR_PAGE(bond)); + s_port = _nm_connection_ensure_setting(conn, NM_TYPE_SETTING_BOND_PORT); + + section = nmt_editor_section_new(_("BOND PORT"), NULL, TRUE); + grid = nmt_editor_section_get_body(section); + + widget = nmt_newt_entry_numeric_new(10, 0, 63); + g_object_bind_property(s_port, + NM_SETTING_BOND_PORT_QUEUE_ID, + widget, + "text", + G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); + nmt_editor_grid_append(grid, _("Queue ID"), widget, NULL); + + nmt_editor_page_add_section(NMT_EDITOR_PAGE(bond), section); + + G_OBJECT_CLASS(nmt_page_bond_port_parent_class)->constructed(object); +} + +static void +nmt_page_bond_port_class_init(NmtPageBondPortClass *bond_class) +{ + GObjectClass *object_class = G_OBJECT_CLASS(bond_class); + + object_class->constructed = nmt_page_bond_port_constructed; +} diff --git a/src/nmtui/nmt-page-bond-port.h b/src/nmtui/nmt-page-bond-port.h new file mode 100644 index 0000000000..387acf4cba --- /dev/null +++ b/src/nmtui/nmt-page-bond-port.h @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021 Red Hat, Inc. + */ + +#ifndef NMT_PAGE_BOND_PORT_H +#define NMT_PAGE_BOND_PORT_H + +#include "nmt-editor-page-device.h" + +#define NMT_TYPE_PAGE_BOND_PORT (nmt_page_bond_port_get_type()) +#define NMT_PAGE_BOND_PORT(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), NMT_TYPE_PAGE_BOND_PORT, NmtPageBondPort)) +#define NMT_PAGE_BOND_PORT_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), NMT_TYPE_PAGE_BOND_PORT, NmtPageBondPortClass)) +#define NMT_IS_PAGE_BOND_PORT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NMT_TYPE_PAGE_BOND_PORT)) +#define NMT_IS_PAGE_BOND_PORT_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), NMT_TYPE_PAGE_BOND_PORT)) +#define NMT_PAGE_BOND_PORT_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS((obj), NMT_TYPE_PAGE_BOND_PORT, NmtPageBondPortClass)) + +typedef struct { + NmtEditorPage parent; + +} NmtPageBondPort; + +typedef struct { + NmtEditorPageClass parent; + +} NmtPageBondPortClass; + +GType nmt_page_bond_port_get_type(void); + +NmtEditorPage *nmt_page_bond_port_new(NMConnection *conn); + +#endif /* NMT_PAGE_BOND_PORT_H */