summary refs log tree commit diff
path: root/libnm-util/tests/test-general.c
diff options
context:
space:
mode:
Diffstat (limited to 'libnm-util/tests/test-general.c')
-rw-r--r--libnm-util/tests/test-general.c78
1 files changed, 75 insertions, 3 deletions
diff --git a/libnm-util/tests/test-general.c b/libnm-util/tests/test-general.c
index f2f7e8ff..1eed8887 100644
--- a/libnm-util/tests/test-general.c
+++ b/libnm-util/tests/test-general.c
@@ -22,6 +22,8 @@
 #include <glib.h>
 #include <dbus/dbus-glib.h>
 #include <string.h>
+#include <netinet/ether.h>
+#include <linux/if_infiniband.h>
 
 #include "nm-test-helpers.h"
 #include <nm-utils.h>
@@ -442,6 +444,26 @@ test_setting_gsm_apn_underscore (void)
 	g_assert (success == TRUE);
 }
 
+static void
+test_setting_gsm_without_number (void)
+{
+	NMSettingGsm *s_gsm;
+	GError *error = NULL;
+	gboolean success;
+
+	s_gsm = (NMSettingGsm *) nm_setting_gsm_new ();
+	g_assert (s_gsm);
+
+	g_object_set (s_gsm, NM_SETTING_GSM_NUMBER, NULL, NULL);
+	success = nm_setting_verify (NM_SETTING (s_gsm), NULL, &error);
+	g_assert_no_error (error);
+	g_assert (success == TRUE);
+
+	g_object_set (s_gsm, NM_SETTING_GSM_NUMBER, "", NULL);
+	success = nm_setting_verify (NM_SETTING (s_gsm), NULL, &error);
+	g_assert_error (error, NM_SETTING_GSM_ERROR, NM_SETTING_GSM_ERROR_INVALID_PROPERTY);
+}
+
 static NMSettingWirelessSecurity *
 make_test_wsec_setting (const char *detail)
 {
@@ -849,6 +871,9 @@ test_connection_diff_a_only (void)
 			{ NM_SETTING_CONNECTION_AUTOCONNECT, NM_SETTING_DIFF_RESULT_IN_A },
 			{ NM_SETTING_CONNECTION_READ_ONLY,   NM_SETTING_DIFF_RESULT_IN_A },
 			{ NM_SETTING_CONNECTION_PERMISSIONS, NM_SETTING_DIFF_RESULT_IN_A },
+			{ NM_SETTING_CONNECTION_ZONE,        NM_SETTING_DIFF_RESULT_IN_A },
+			{ NM_SETTING_CONNECTION_MASTER,      NM_SETTING_DIFF_RESULT_IN_A },
+			{ NM_SETTING_CONNECTION_SLAVE_TYPE,  NM_SETTING_DIFF_RESULT_IN_A },
 			{ NULL, NM_SETTING_DIFF_RESULT_UNKNOWN }
 		} },
 		{ NM_SETTING_WIRED_SETTING_NAME, {
@@ -916,7 +941,7 @@ test_connection_diff_different (void)
 {
 	NMConnection *a, *b;
 	GHashTable *out_diffs = NULL;
-	NMSetting *s_ip4;
+	NMSettingIP4Config *s_ip4;
 	gboolean same;
 	const DiffSetting settings[] = {
 		{ NM_SETTING_IP4_CONFIG_SETTING_NAME, {
@@ -927,7 +952,7 @@ test_connection_diff_different (void)
 
 	a = new_test_connection ();
 	b = nm_connection_duplicate (a);
-	s_ip4 = nm_connection_get_setting (a, NM_TYPE_SETTING_IP4_CONFIG);
+	s_ip4 = nm_connection_get_setting_ip4_config (a);
 	g_assert (s_ip4);
 	g_object_set (G_OBJECT (s_ip4),
 	              NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
@@ -968,7 +993,7 @@ test_connection_diff_no_secrets (void)
 	b = nm_connection_duplicate (a);
 
 	/* Add a secret to B */
-	s_pppoe = nm_connection_get_setting (b, NM_TYPE_SETTING_PPPOE);
+	s_pppoe = NM_SETTING (nm_connection_get_setting_pppoe (b));
 	g_assert (s_pppoe);
 	g_object_set (G_OBJECT (s_pppoe),
 	              NM_SETTING_PPPOE_PASSWORD, "secretpassword",
@@ -1295,6 +1320,47 @@ test_setting_compare_vpn_secrets (NMSettingSecretFlags secret_flags,
 	g_assert (success);
 }
 
+static void
+test_hwaddr_aton_ether_normal (void)
+{
+	guint8 buf[100];
+	guint8 expected[ETH_ALEN] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 };
+
+	g_assert (nm_utils_hwaddr_aton ("00:11:22:33:44:55", ARPHRD_ETHER, buf) != NULL);
+	g_assert (memcmp (buf, expected, sizeof (expected)) == 0);
+}
+
+static void
+test_hwaddr_aton_ib_normal (void)
+{
+	guint8 buf[100];
+	const char *source = "00:11:22:33:44:55:66:77:88:99:01:12:23:34:45:56:67:78:89:90";
+	guint8 expected[INFINIBAND_ALEN] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66,
+		0x77, 0x88, 0x99, 0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, 0x89,
+		0x90 };
+
+	g_assert (nm_utils_hwaddr_aton (source, ARPHRD_INFINIBAND, buf) != NULL);
+	g_assert (memcmp (buf, expected, sizeof (expected)) == 0);
+}
+
+static void
+test_hwaddr_aton_no_leading_zeros (void)
+{
+	guint8 buf[100];
+	guint8 expected[ETH_ALEN] = { 0x00, 0x1A, 0x2B, 0x03, 0x44, 0x05 };
+
+	g_assert (nm_utils_hwaddr_aton ("0:1a:2B:3:44:5", ARPHRD_ETHER, buf) != NULL);
+	g_assert (memcmp (buf, expected, sizeof (expected)) == 0);
+}
+
+static void
+test_hwaddr_aton_malformed (void)
+{
+	guint8 buf[100];
+
+	g_assert (nm_utils_hwaddr_aton ("0:1a:2B:3:a@%%", ARPHRD_ETHER, buf) == NULL);
+}
+
 int main (int argc, char **argv)
 {
 	GError *error = NULL;
@@ -1313,6 +1379,7 @@ int main (int argc, char **argv)
 	test_setting_gsm_apn_spaces ();
 	test_setting_gsm_apn_bad_chars ();
 	test_setting_gsm_apn_underscore ();
+	test_setting_gsm_without_number ();
 	test_setting_to_hash_all ();
 	test_setting_to_hash_no_secrets ();
 	test_setting_to_hash_only_secrets ();
@@ -1336,6 +1403,11 @@ int main (int argc, char **argv)
 	test_connection_good_base_types ();
 	test_connection_bad_base_types ();
 
+	test_hwaddr_aton_ether_normal ();
+	test_hwaddr_aton_ib_normal ();
+	test_hwaddr_aton_no_leading_zeros ();
+	test_hwaddr_aton_malformed ();
+
 	base = g_path_get_basename (argv[0]);
 	fprintf (stdout, "%s: SUCCESS\n", base);
 	g_free (base);