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.
This commit is contained in:
Dan Winship
2014-09-05 14:40:37 -04:00
parent 58f278fbfb
commit 16871ebc38
3 changed files with 23 additions and 38 deletions

View File

@@ -9,7 +9,6 @@ AM_CPPFLAGS = \
-DNETWORKMANAGER_COMPILATION \ -DNETWORKMANAGER_COMPILATION \
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
$(GLIB_CFLAGS) \ $(GLIB_CFLAGS) \
$(DBUS_CFLAGS) \
-DTEST_CERT_DIR=\"$(certsdir)\" -DTEST_CERT_DIR=\"$(certsdir)\"
noinst_PROGRAMS = \ noinst_PROGRAMS = \
@@ -23,8 +22,7 @@ noinst_PROGRAMS = \
LDADD = \ LDADD = \
$(top_builddir)/libnm-core/libnm-core.la \ $(top_builddir)/libnm-core/libnm-core.la \
$(GLIB_LIBS) \ $(GLIB_LIBS)
$(DBUS_LIBS)
TESTS = $(noinst_PROGRAMS) TESTS = $(noinst_PROGRAMS)

View File

@@ -2652,8 +2652,6 @@ test_connection_normalize_virtual_iface_name (void)
NMSettingConnection *s_con; NMSettingConnection *s_con;
NMSettingVlan *s_vlan; NMSettingVlan *s_vlan;
GVariant *connection_dict, *setting_dict, *var; GVariant *connection_dict, *setting_dict, *var;
GHashTable *connection_hash, *setting_hash;
GValue *value;
GError *error = NULL; GError *error = NULL;
const char *IFACE_NAME = "iface"; const char *IFACE_NAME = "iface";
const char *IFACE_VIRT = "iface-X"; const char *IFACE_VIRT = "iface-X";
@@ -2698,21 +2696,24 @@ test_connection_normalize_virtual_iface_name (void)
g_variant_unref (var); g_variant_unref (var);
/* If vlan.interface-name is invalid, deserialization will fail. */ /* If vlan.interface-name is invalid, deserialization will fail. */
connection_hash = _nm_utils_connection_dict_to_hash (connection_dict); NMTST_VARIANT_EDITOR (connection_dict,
setting_hash = g_hash_table_lookup (connection_hash, NM_SETTING_VLAN_SETTING_NAME); NMTST_VARIANT_CHANGE_PROPERTY (NM_SETTING_VLAN_SETTING_NAME,
value = g_hash_table_lookup (setting_hash, "interface-name"); "interface-name",
g_value_set_string (value, ":::this-is-not-a-valid-interface-name:::"); "s",
g_variant_unref (connection_dict); ":::this-is-not-a-valid-interface-name:::");
connection_dict = _nm_utils_connection_hash_to_dict (connection_hash); );
con = nm_simple_connection_new_from_dbus (connection_dict, &error); 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_assert_error (error, NM_SETTING_CONNECTION_ERROR, NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY);
g_clear_error (&error); g_clear_error (&error);
/* If vlan.interface-name is valid, but doesn't match, it will be ignored. */ /* If vlan.interface-name is valid, but doesn't match, it will be ignored. */
g_value_set_string (value, IFACE_VIRT); NMTST_VARIANT_EDITOR (connection_dict,
g_variant_unref (connection_dict); NMTST_VARIANT_CHANGE_PROPERTY (NM_SETTING_VLAN_SETTING_NAME,
connection_dict = _nm_utils_connection_hash_to_dict (connection_hash); "interface-name",
"s",
IFACE_VIRT);
);
con = nm_simple_connection_new_from_dbus (connection_dict, &error); con = nm_simple_connection_new_from_dbus (connection_dict, &error);
g_assert_no_error (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 /* But removing connection.interface-name should result in vlan.connection-name
* being "promoted". * being "promoted".
*/ */
setting_hash = g_hash_table_lookup (connection_hash, NM_SETTING_CONNECTION_SETTING_NAME); NMTST_VARIANT_EDITOR (connection_dict,
g_assert (setting_hash != NULL); NMTST_VARIANT_DROP_PROPERTY (NM_SETTING_CONNECTION_SETTING_NAME,
g_hash_table_remove (setting_hash, NM_SETTING_CONNECTION_INTERFACE_NAME); NM_SETTING_CONNECTION_INTERFACE_NAME);
g_variant_unref (connection_dict); );
connection_dict = _nm_utils_connection_hash_to_dict (connection_hash);
con = nm_simple_connection_new_from_dbus (connection_dict, &error); con = nm_simple_connection_new_from_dbus (connection_dict, &error);
g_assert_no_error (error); g_assert_no_error (error);
@@ -2740,7 +2740,6 @@ test_connection_normalize_virtual_iface_name (void)
g_object_unref (con); g_object_unref (con);
g_variant_unref (connection_dict); g_variant_unref (connection_dict);
g_hash_table_unref (connection_hash);
} }
static void static void

View File

@@ -34,7 +34,6 @@
#include "nm-setting-pppoe.h" #include "nm-setting-pppoe.h"
#include "nm-setting-vpn.h" #include "nm-setting-vpn.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "nm-utils-private.h"
#include "nm-test-utils.h" #include "nm-test-utils.h"
@@ -441,16 +440,6 @@ wifi_connection_new (void)
return connection; 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 * static GVariant *
build_wep_secrets (const char *wepkey) build_wep_secrets (const char *wepkey)
{ {
@@ -578,7 +567,6 @@ test_update_secrets_whole_connection (void)
NMConnection *connection; NMConnection *connection;
NMSettingWirelessSecurity *s_wsec; NMSettingWirelessSecurity *s_wsec;
GVariant *secrets; GVariant *secrets;
GHashTable *secrets_hash, *wsec_hash;
GError *error = NULL; GError *error = NULL;
gboolean success; gboolean success;
const char *wepkey = "11111111111111111111111111"; const char *wepkey = "11111111111111111111111111";
@@ -591,12 +579,12 @@ test_update_secrets_whole_connection (void)
/* Build up the secrets dictionary */ /* Build up the secrets dictionary */
secrets = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL); secrets = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL);
secrets_hash = _nm_utils_connection_dict_to_hash (secrets); NMTST_VARIANT_EDITOR (secrets,
wsec_hash = g_hash_table_lookup (secrets_hash, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME); NMTST_VARIANT_ADD_PROPERTY (NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
g_assert (wsec_hash); NM_SETTING_WIRELESS_SECURITY_WEP_KEY0,
g_hash_table_insert (wsec_hash, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, string_to_gvalue (wepkey)); "s",
g_variant_unref (secrets); wepkey);
secrets = _nm_utils_connection_hash_to_dict (secrets_hash); );
success = nm_connection_update_secrets (connection, NULL, secrets, &error); success = nm_connection_update_secrets (connection, NULL, secrets, &error);
g_assert_no_error (error); g_assert_no_error (error);