Commit 16871ebc authored by Dan Winship's avatar Dan Winship

libnm-core: update tests to be fully variant-based

Use nmtst_variant_editor() to rewrite the libnm-core tests to work
entirely in connection dictionaries, not connection hash tables.
parent 58f278fb
......@@ -9,7 +9,6 @@ AM_CPPFLAGS = \
-DNETWORKMANAGER_COMPILATION \
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
$(GLIB_CFLAGS) \
$(DBUS_CFLAGS) \
-DTEST_CERT_DIR=\"$(certsdir)\"
noinst_PROGRAMS = \
......@@ -23,8 +22,7 @@ noinst_PROGRAMS = \
LDADD = \
$(top_builddir)/libnm-core/libnm-core.la \
$(GLIB_LIBS) \
$(DBUS_LIBS)
$(GLIB_LIBS)
TESTS = $(noinst_PROGRAMS)
......
......@@ -2652,8 +2652,6 @@ test_connection_normalize_virtual_iface_name (void)
NMSettingConnection *s_con;
NMSettingVlan *s_vlan;
GVariant *connection_dict, *setting_dict, *var;
GHashTable *connection_hash, *setting_hash;
GValue *value;
GError *error = NULL;
const char *IFACE_NAME = "iface";
const char *IFACE_VIRT = "iface-X";
......@@ -2698,21 +2696,24 @@ test_connection_normalize_virtual_iface_name (void)
g_variant_unref (var);
/* If vlan.interface-name is invalid, deserialization will fail. */
connection_hash = _nm_utils_connection_dict_to_hash (connection_dict);
setting_hash = g_hash_table_lookup (connection_hash, NM_SETTING_VLAN_SETTING_NAME);
value = g_hash_table_lookup (setting_hash, "interface-name");
g_value_set_string (value, ":::this-is-not-a-valid-interface-name:::");
g_variant_unref (connection_dict);
connection_dict = _nm_utils_connection_hash_to_dict (connection_hash);
NMTST_VARIANT_EDITOR (connection_dict,
NMTST_VARIANT_CHANGE_PROPERTY (NM_SETTING_VLAN_SETTING_NAME,
"interface-name",
"s",
":::this-is-not-a-valid-interface-name:::");
);
con = nm_simple_connection_new_from_dbus (connection_dict, &error);
g_assert_error (error, NM_SETTING_CONNECTION_ERROR, NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY);
g_clear_error (&error);
/* If vlan.interface-name is valid, but doesn't match, it will be ignored. */
g_value_set_string (value, IFACE_VIRT);
g_variant_unref (connection_dict);
connection_dict = _nm_utils_connection_hash_to_dict (connection_hash);
NMTST_VARIANT_EDITOR (connection_dict,
NMTST_VARIANT_CHANGE_PROPERTY (NM_SETTING_VLAN_SETTING_NAME,
"interface-name",
"s",
IFACE_VIRT);
);
con = nm_simple_connection_new_from_dbus (connection_dict, &error);
g_assert_no_error (error);
......@@ -2725,11 +2726,10 @@ test_connection_normalize_virtual_iface_name (void)
/* But removing connection.interface-name should result in vlan.connection-name
* being "promoted".
*/
setting_hash = g_hash_table_lookup (connection_hash, NM_SETTING_CONNECTION_SETTING_NAME);
g_assert (setting_hash != NULL);
g_hash_table_remove (setting_hash, NM_SETTING_CONNECTION_INTERFACE_NAME);
g_variant_unref (connection_dict);
connection_dict = _nm_utils_connection_hash_to_dict (connection_hash);
NMTST_VARIANT_EDITOR (connection_dict,
NMTST_VARIANT_DROP_PROPERTY (NM_SETTING_CONNECTION_SETTING_NAME,
NM_SETTING_CONNECTION_INTERFACE_NAME);
);
con = nm_simple_connection_new_from_dbus (connection_dict, &error);
g_assert_no_error (error);
......@@ -2740,7 +2740,6 @@ test_connection_normalize_virtual_iface_name (void)
g_object_unref (con);
g_variant_unref (connection_dict);
g_hash_table_unref (connection_hash);
}
static void
......
......@@ -34,7 +34,6 @@
#include "nm-setting-pppoe.h"
#include "nm-setting-vpn.h"
#include "nm-utils.h"
#include "nm-utils-private.h"
#include "nm-test-utils.h"
......@@ -441,16 +440,6 @@ wifi_connection_new (void)
return connection;
}
static GValue *
string_to_gvalue (const char *str)
{
GValue *val = g_slice_new0 (GValue);
g_value_init (val, G_TYPE_STRING);
g_value_set_string (val, str);
return val;
}
static GVariant *
build_wep_secrets (const char *wepkey)
{
......@@ -578,7 +567,6 @@ test_update_secrets_whole_connection (void)
NMConnection *connection;
NMSettingWirelessSecurity *s_wsec;
GVariant *secrets;
GHashTable *secrets_hash, *wsec_hash;
GError *error = NULL;
gboolean success;
const char *wepkey = "11111111111111111111111111";
......@@ -591,12 +579,12 @@ test_update_secrets_whole_connection (void)
/* Build up the secrets dictionary */
secrets = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL);
secrets_hash = _nm_utils_connection_dict_to_hash (secrets);
wsec_hash = g_hash_table_lookup (secrets_hash, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME);
g_assert (wsec_hash);
g_hash_table_insert (wsec_hash, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, string_to_gvalue (wepkey));
g_variant_unref (secrets);
secrets = _nm_utils_connection_hash_to_dict (secrets_hash);
NMTST_VARIANT_EDITOR (secrets,
NMTST_VARIANT_ADD_PROPERTY (NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
NM_SETTING_WIRELESS_SECURITY_WEP_KEY0,
"s",
wepkey);
);
success = nm_connection_update_secrets (connection, NULL, secrets, &error);
g_assert_no_error (error);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment