summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2014-09-05 14:40:37 -0400
committerDan Winship <danw@gnome.org>2014-09-18 11:51:09 -0400
commit16871ebc388f81fd811e9f7d85965ba86236005c (patch)
treeee4db7083067f8d198c2f8d3db55cf10003a4d66
parent58f278fbfb88a7369e4668968e26ebea7302891c (diff)
downloadNetworkManager-16871ebc388f81fd811e9f7d85965ba86236005c.tar.gz
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.
-rw-r--r--libnm-core/tests/Makefile.am4
-rw-r--r--libnm-core/tests/test-general.c33
-rw-r--r--libnm-core/tests/test-secrets.c24
3 files changed, 23 insertions, 38 deletions
diff --git a/libnm-core/tests/Makefile.am b/libnm-core/tests/Makefile.am
index 9966688689..eea0fc198e 100644
--- a/libnm-core/tests/Makefile.am
+++ b/libnm-core/tests/Makefile.am
@@ -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)
diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c
index a098fc452a..af1a6fb549 100644
--- a/libnm-core/tests/test-general.c
+++ b/libnm-core/tests/test-general.c
@@ -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
diff --git a/libnm-core/tests/test-secrets.c b/libnm-core/tests/test-secrets.c
index 544af6bca0..738441ad47 100644
--- a/libnm-core/tests/test-secrets.c
+++ b/libnm-core/tests/test-secrets.c
@@ -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);