summary refs log tree commit diff
path: root/src/settings/plugins/ifnet/tests/test_all.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2014-07-06 02:16:10 +0200
committerMichael Biebl <biebl@debian.org>2014-07-06 02:16:10 +0200
commit33491bc4279481db8ae47213e34a6d695a0e8830 (patch)
tree097d2b0fdff3fae6885381ae5e57a182cd8cbbba /src/settings/plugins/ifnet/tests/test_all.c
parent59c3714a494c3b3765657c0551ad82842d98a7d2 (diff)
Imported Upstream version 0.9.10.0 upstream/0.9.10.0
Diffstat (limited to 'src/settings/plugins/ifnet/tests/test_all.c')
-rw-r--r--src/settings/plugins/ifnet/tests/test_all.c61
1 files changed, 48 insertions, 13 deletions
diff --git a/src/settings/plugins/ifnet/tests/test_all.c b/src/settings/plugins/ifnet/tests/test_all.c
index 4c312601..c320ed5f 100644
--- a/src/settings/plugins/ifnet/tests/test_all.c
+++ b/src/settings/plugins/ifnet/tests/test_all.c
@@ -28,21 +28,31 @@
 #include <unistd.h>
 #include <nm-utils.h>
 
+#include "nm-linux-platform.h"
+#include "nm-logging.h"
+
 #include "net_parser.h"
-#include "nm-test-helpers.h"
 #include "net_utils.h"
 #include "wpa_parser.h"
 #include "connection_parser.h"
+#include "nm-config.h"
 
-/* Fake config file function to make the linker happy */
-const char *ifnet_plugin_get_conf_file (void);
+#include "nm-test-utils.h"
 
-const char *
-ifnet_plugin_get_conf_file (void)
+/* Fake NMConfig handling; the values it returns don't matter, so this
+ * is easier than forcing it to read our own config file, etc.
+ */
+NMConfig *
+nm_config_get (void)
 {
-	return "/etc/foo/barasdfasdfasdfasdf";
+	return NULL;
 }
 
+const char *
+nm_config_get_dhcp_client (NMConfig *config)
+{
+	return "dhclient";
+}
 
 static void
 test_getdata ()
@@ -153,18 +163,18 @@ static void
 check_ip_block (ip_block * iblock, gchar * ip, gchar * netmask, gchar * gateway)
 {
 	char *str;
-	struct in_addr tmp_ip4_addr;
+	guint32 tmp_ip4_addr;
 
 	str = malloc (INET_ADDRSTRLEN);
-	tmp_ip4_addr.s_addr = iblock->ip;
+	tmp_ip4_addr = iblock->ip;
 	inet_ntop (AF_INET, &tmp_ip4_addr, str, INET_ADDRSTRLEN);
 	ASSERT (strcmp (ip, str) == 0, "check ip",
 		"ip expected:%s, find:%s", ip, str);
-	tmp_ip4_addr.s_addr = iblock->netmask;
+	tmp_ip4_addr = iblock->netmask;
 	inet_ntop (AF_INET, &tmp_ip4_addr, str, INET_ADDRSTRLEN);
 	ASSERT (strcmp (netmask, str) == 0, "check netmask",
 		"netmask expected:%s, find:%s", netmask, str);
-	tmp_ip4_addr.s_addr = iblock->gateway;
+	tmp_ip4_addr = iblock->gateway;
 	inet_ntop (AF_INET, &tmp_ip4_addr, str, INET_ADDRSTRLEN);
 	ASSERT (strcmp (gateway, str) == 0, "check gateway",
 		"gateway expected:%s, find:%s", gateway, str);
@@ -188,12 +198,19 @@ test_convert_ipv4_config_block ()
 	check_ip_block (iblock, "192.168.4.121", "255.255.255.0",
 			"202.117.16.1");
 	destroy_ip_block (iblock);
+
+	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING,
+	                       "*Can't handle IPv4 address*202.117.16.1211*");
 	iblock = convert_ip4_config_block ("eth2");
+	g_test_assert_expected_messages ();
 	ASSERT (iblock != NULL
 		&& iblock->next == NULL,
 		"convert error IPv4 address", "should only get one address");
 	check_ip_block (iblock, "192.168.4.121", "255.255.255.0", "0.0.0.0");
 	destroy_ip_block (iblock);
+
+	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING,
+	                       "*missing netmask or prefix*");
 	iblock = convert_ip4_config_block ("eth3");
 	ASSERT (iblock == NULL, "convert config_block",
 		"convert error configuration");
@@ -274,7 +291,12 @@ test_new_connection ()
 	GError *error = NULL;
 	NMConnection *connection;
 
+	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING,
+	                       "*Can't handle IPv4 address*202.117.16.1211*");
+	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING,
+	                       "*Can't handle IPv6 address*202.117.16.1211*");
 	connection = ifnet_update_connection_from_config_block ("eth2", NULL, &error);
+	g_test_assert_expected_messages ();
 	ASSERT (connection != NULL, "new connection",
 		"new connection failed: %s",
 		error ? error->message : "None");
@@ -366,13 +388,18 @@ test_add_connection (const char *basepath)
 	char *backup = NULL;
 
 	connection = ifnet_update_connection_from_config_block ("eth0", basepath, NULL);
-	ASSERT (ifnet_add_new_connection (connection, NET_GEN_NAME, SUP_GEN_NAME, &backup, NULL),
+	ASSERT (ifnet_add_new_connection (connection, NET_GEN_NAME, SUP_GEN_NAME, NULL, &backup, NULL),
 	        "add connection", "add connection failed: %s", "eth0");
 	kill_backup (&backup);
 	g_object_unref (connection);
 
+	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING,
+	                       "*Can't handle ipv4 address: brd, missing netmask or prefix*");
+	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING,
+	                       "*Can't handle ipv4 address: 202.117.16.255, missing netmask or prefix*");
 	connection = ifnet_update_connection_from_config_block ("myxjtu2", basepath, NULL);
-	ASSERT (ifnet_add_new_connection (connection, NET_GEN_NAME, SUP_GEN_NAME, &backup, NULL),
+	g_test_assert_expected_messages ();
+	ASSERT (ifnet_add_new_connection (connection, NET_GEN_NAME, SUP_GEN_NAME, NULL, &backup, NULL),
 	        "add connection", "add connection failed: %s", "myxjtu2");
 	kill_backup (&backup);
 	g_object_unref (connection);
@@ -416,17 +443,25 @@ test_missing_config ()
 	GError *error = NULL;
 	NMConnection *connection;
 
+	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING,
+	                       "*Unknown config for eth8*");
 	connection = ifnet_update_connection_from_config_block ("eth8", NULL, &error);
+	g_test_assert_expected_messages ();
 	ASSERT (connection == NULL && error != NULL, "get connection",
 	        "get connection should fail with 'Unknown config for eth8'");
 }
 
+NMTST_DEFINE ();
+
 int
 main (int argc, char **argv)
 {
 	char *f;
 
-	g_type_init ();
+	nm_linux_platform_setup ();
+
+	nmtst_init_assert_logging (&argc, &argv);
+	nm_logging_setup ("WARN", "DEFAULT", NULL, NULL);
 
 	f = g_build_filename (argv[1], "net", NULL);
 	ifnet_init (f);