diff options
Diffstat (limited to 'src/supplicant-manager/tests/test-supplicant-config.c')
-rw-r--r-- | src/supplicant-manager/tests/test-supplicant-config.c | 117 |
1 files changed, 58 insertions, 59 deletions
diff --git a/src/supplicant-manager/tests/test-supplicant-config.c b/src/supplicant-manager/tests/test-supplicant-config.c index d92fb0d17..ce884a8dd 100644 --- a/src/supplicant-manager/tests/test-supplicant-config.c +++ b/src/supplicant-manager/tests/test-supplicant-config.c @@ -39,11 +39,11 @@ #include <nm-setting-ip4-config.h> #include <nm-setting-8021x.h> -#include "nm-test-helpers.h" - #include "nm-supplicant-config.h" #include "nm-supplicant-settings-verify.h" +#include "nm-test-utils.h" + static gboolean validate_opt (const char *detail, GHashTable *hash, @@ -128,14 +128,9 @@ test_wifi_open (void) const char *bssid_str = "11:22:33:44:55:66"; connection = nm_connection_new (); - ASSERT (connection != NULL, - "wifi-open", "failed to allocate new connection"); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - ASSERT (s_con != NULL, - "wifi-open", "failed to allocate new %s setting", - NM_SETTING_CONNECTION_SETTING_NAME); nm_connection_add_setting (connection, NM_SETTING (s_con)); uuid = nm_utils_uuid_generate (); @@ -149,9 +144,6 @@ test_wifi_open (void) /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); - ASSERT (s_wifi != NULL, - "wifi-open", "failed to allocate new %s setting", - NM_SETTING_WIRELESS_SETTING_NAME); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); ssid = g_byte_array_sized_new (sizeof (ssid_data)); @@ -171,9 +163,6 @@ test_wifi_open (void) /* IP4 setting */ s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); - ASSERT (s_ip4 != NULL, - "wifi-open", "failed to allocate new %s setting", - NM_SETTING_IP4_CONFIG_SETTING_NAME); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); @@ -183,16 +172,26 @@ test_wifi_open (void) (error && error->message) ? error->message : "(unknown)"); config = nm_supplicant_config_new (); - ASSERT (config != NULL, - "wifi-open", "failed to create new supplicant config"); - success = nm_supplicant_config_add_setting_wireless (config, s_wifi, TRUE, 0, TRUE); + g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, + "*added 'ssid' value 'Test SSID'*"); + g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, + "*added 'scan_ssid' value '1'*"); + g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, + "*added 'bssid' value '11:22:33:44:55:66'*"); + g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, + "*added 'freq_list' value *"); + success = nm_supplicant_config_add_setting_wireless (config, s_wifi, 0); ASSERT (success == TRUE, "wifi-open", "failed to add wireless setting to supplicant config."); + g_test_assert_expected_messages (); + g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, + "*added 'key_mgmt' value 'NONE'"); success = nm_supplicant_config_add_no_security (config); ASSERT (success == TRUE, "wifi-open", "failed to add wireless security to supplicant config."); + g_test_assert_expected_messages (); hash = nm_supplicant_config_get_hash (config); ASSERT (hash != NULL, @@ -230,14 +229,9 @@ test_wifi_wep_key (const char *detail, const char *bssid_str = "11:22:33:44:55:66"; connection = nm_connection_new (); - ASSERT (connection != NULL, - detail, "failed to allocate new connection"); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - ASSERT (s_con != NULL, - detail, "failed to allocate new %s setting", - NM_SETTING_CONNECTION_SETTING_NAME); nm_connection_add_setting (connection, NM_SETTING (s_con)); uuid = nm_utils_uuid_generate (); @@ -251,9 +245,6 @@ test_wifi_wep_key (const char *detail, /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); - ASSERT (s_wifi != NULL, - detail, "failed to allocate new %s setting", - NM_SETTING_WIRELESS_SETTING_NAME); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); ssid = g_byte_array_sized_new (sizeof (ssid_data)); @@ -266,7 +257,6 @@ test_wifi_wep_key (const char *detail, NM_SETTING_WIRELESS_BSSID, bssid, NM_SETTING_WIRELESS_MODE, "infrastructure", NM_SETTING_WIRELESS_BAND, "bg", - NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NULL); g_byte_array_free (ssid, TRUE); @@ -274,9 +264,6 @@ test_wifi_wep_key (const char *detail, /* Wifi Security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); - ASSERT (s_wsec != NULL, - detail, "failed to allocate new %s setting", - NM_SETTING_WIRELESS_SECURITY_SETTING_NAME); nm_connection_add_setting (connection, NM_SETTING (s_wsec)); g_object_set (s_wsec, @@ -287,9 +274,6 @@ test_wifi_wep_key (const char *detail, /* IP4 setting */ s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); - ASSERT (s_ip4 != NULL, - detail, "failed to allocate new %s setting", - NM_SETTING_IP4_CONFIG_SETTING_NAME); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); @@ -299,19 +283,33 @@ test_wifi_wep_key (const char *detail, (error && error->message) ? error->message : "(unknown)"); config = nm_supplicant_config_new (); - ASSERT (config != NULL, - detail, "failed to create new supplicant config"); - success = nm_supplicant_config_add_setting_wireless (config, s_wifi, TRUE, 0, TRUE); + g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, + "*added 'ssid' value 'Test SSID'*"); + g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, + "*added 'scan_ssid' value '1'*"); + g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, + "*added 'bssid' value '11:22:33:44:55:66'*"); + g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, + "*added 'freq_list' value *"); + success = nm_supplicant_config_add_setting_wireless (config, s_wifi, 0); ASSERT (success == TRUE, detail, "failed to add wireless setting to supplicant config."); - + g_test_assert_expected_messages (); + + g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, + "*added 'key_mgmt' value 'NONE'"); + g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, + "*added 'wep_key0' value *"); + g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, + "*added 'wep_tx_keyidx' value '0'"); success = nm_supplicant_config_add_setting_wireless_security (config, s_wsec, NULL, "376aced7-b28c-46be-9a62-fcdf072571da"); ASSERT (success == TRUE, detail, "failed to add wireless security to supplicant config."); + g_test_assert_expected_messages (); hash = nm_supplicant_config_get_hash (config); ASSERT (hash != NULL, @@ -374,14 +372,9 @@ test_wifi_wpa_psk (const char *detail, const char *bssid_str = "11:22:33:44:55:66"; connection = nm_connection_new (); - ASSERT (connection != NULL, - detail, "failed to allocate new connection"); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - ASSERT (s_con != NULL, - detail, "failed to allocate new %s setting", - NM_SETTING_CONNECTION_SETTING_NAME); nm_connection_add_setting (connection, NM_SETTING (s_con)); uuid = nm_utils_uuid_generate (); @@ -395,9 +388,6 @@ test_wifi_wpa_psk (const char *detail, /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); - ASSERT (s_wifi != NULL, - detail, "failed to allocate new %s setting", - NM_SETTING_WIRELESS_SETTING_NAME); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); ssid = g_byte_array_sized_new (sizeof (ssid_data)); @@ -410,7 +400,6 @@ test_wifi_wpa_psk (const char *detail, NM_SETTING_WIRELESS_BSSID, bssid, NM_SETTING_WIRELESS_MODE, "infrastructure", NM_SETTING_WIRELESS_BAND, "bg", - NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NULL); g_byte_array_free (ssid, TRUE); @@ -418,9 +407,6 @@ test_wifi_wpa_psk (const char *detail, /* Wifi Security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); - ASSERT (s_wsec != NULL, - detail, "failed to allocate new %s setting", - NM_SETTING_WIRELESS_SECURITY_SETTING_NAME); nm_connection_add_setting (connection, NM_SETTING (s_wsec)); g_object_set (s_wsec, @@ -437,9 +423,6 @@ test_wifi_wpa_psk (const char *detail, /* IP4 setting */ s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); - ASSERT (s_ip4 != NULL, - detail, "failed to allocate new %s setting", - NM_SETTING_IP4_CONFIG_SETTING_NAME); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); @@ -449,19 +432,37 @@ test_wifi_wpa_psk (const char *detail, (error && error->message) ? error->message : "(unknown)"); config = nm_supplicant_config_new (); - ASSERT (config != NULL, - detail, "failed to create new supplicant config"); - success = nm_supplicant_config_add_setting_wireless (config, s_wifi, TRUE, 0, TRUE); + g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, + "*added 'ssid' value 'Test SSID'*"); + g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, + "*added 'scan_ssid' value '1'*"); + g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, + "*added 'bssid' value '11:22:33:44:55:66'*"); + g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, + "*added 'freq_list' value *"); + success = nm_supplicant_config_add_setting_wireless (config, s_wifi, 0); ASSERT (success == TRUE, detail, "failed to add wireless setting to supplicant config."); - + g_test_assert_expected_messages (); + + g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, + "*added 'key_mgmt' value 'WPA-PSK'"); + g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, + "*added 'psk' value *"); + g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, + "*added 'proto' value 'WPA RSN'"); + g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, + "*added 'pairwise' value 'TKIP CCMP'"); + g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, + "*added 'group' value 'TKIP CCMP'"); success = nm_supplicant_config_add_setting_wireless_security (config, s_wsec, NULL, "376aced7-b28c-46be-9a62-fcdf072571da"); ASSERT (success == TRUE, detail, "failed to add wireless security to supplicant config."); + g_test_assert_expected_messages (); hash = nm_supplicant_config_get_hash (config); ASSERT (hash != NULL, @@ -493,15 +494,13 @@ test_wifi_wpa_psk_types (void) test_wifi_wpa_psk ("wifi-wep-psk-passphrase", TYPE_STRING, key2, (gconstpointer) key2, strlen (key2)); } +NMTST_DEFINE (); + int main (int argc, char **argv) { - GError *error = NULL; char *base; - g_type_init (); - - if (!nm_utils_init (&error)) - FAIL ("nm-utils-init", "failed to initialize libnm-util: %s", error->message); + nmtst_init (&argc, &argv, TRUE); /* The tests */ test_wifi_open (); |