diff options
Diffstat (limited to 'src/settings/plugins/ifupdown/tests/test-ifupdown.c')
| -rw-r--r-- | src/settings/plugins/ifupdown/tests/test-ifupdown.c | 255 |
1 files changed, 144 insertions, 111 deletions
diff --git a/src/settings/plugins/ifupdown/tests/test-ifupdown.c b/src/settings/plugins/ifupdown/tests/test-ifupdown.c index e96350c0..18bad65e 100644 --- a/src/settings/plugins/ifupdown/tests/test-ifupdown.c +++ b/src/settings/plugins/ifupdown/tests/test-ifupdown.c @@ -130,15 +130,16 @@ expected_free (Expected *e) } static void -compare_expected_to_ifparser (if_parser *parser, Expected *e) +compare_expected_to_ifparser (Expected *e) { if_block *n; GSList *biter, *kiter; - g_assert_cmpint (g_slist_length (e->blocks), ==, ifparser_get_num_blocks (parser)); + g_assert_cmpint (g_slist_length (e->blocks), ==, ifparser_get_num_blocks ()); - biter = e->blocks; - c_list_for_each_entry (n, &parser->block_lst_head, block_lst) { + for (n = ifparser_getfirst (), biter = e->blocks; + n && biter; + n = n->next, biter = g_slist_next (biter)) { if_data *m; ExpectedBlock *b = biter->data; @@ -149,31 +150,26 @@ compare_expected_to_ifparser (if_parser *parser, Expected *e) g_assert_cmpint (g_slist_length (b->keys), ==, ifparser_get_num_info (n)); - kiter = b->keys; - c_list_for_each_entry (m, &n->data_lst_head, data_lst) { + for (m = n->info, kiter = b->keys; + m && kiter; + m = m->next, kiter = g_slist_next (kiter)) { ExpectedKey *k = kiter->data; g_assert (k->key && m->key); g_assert_cmpstr (k->key, ==, m->key); g_assert (k->data && m->data); g_assert_cmpstr (k->data, ==, m->data); - - kiter = g_slist_next (kiter); } - g_assert (!kiter); - - biter = g_slist_next (biter); } - g_assert (!biter); } static void -dump_blocks (if_parser *parser) +dump_blocks (void) { if_block *n; g_message ("\n***************************************************"); - c_list_for_each_entry (n, &parser->block_lst_head, block_lst) { + for (n = ifparser_getfirst (); n != NULL; n = n->next) { if_data *m; // each block start with its type & name @@ -182,8 +178,8 @@ dump_blocks (if_parser *parser) // each key-value pair within a block is indented & separated by a tab // (single quotes used to show typ & name baoundaries) - c_list_for_each_entry (m, &n->data_lst_head, data_lst) - g_print("\t'%s'\t'%s'\n", m->key, m->data); + for (m = n->info; m != NULL; m = m->next) + g_print("\t'%s'\t'%s'\n", m->key, m->data); // blocks are separated by an empty line g_print("\n"); @@ -191,24 +187,21 @@ dump_blocks (if_parser *parser) g_message ("##################################################\n"); } -static if_parser * -init_ifparser_with_file (const char *file) +static void +init_ifparser_with_file (const char *path, const char *file) { - if_parser *parser; - gs_free char *tmp = NULL; + char *tmp; - tmp = g_strdup_printf ("%s/%s", TEST_DIR, file); - parser = ifparser_parse (tmp, 1); - g_assert (parser); - return parser; + tmp = g_strdup_printf ("%s/%s", path, file); + ifparser_init (tmp, 1); + g_free (tmp); } static void -test1_ignore_line_before_first_block (void) +test1_ignore_line_before_first_block (const char *path) { Expected *e; ExpectedBlock *b; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file ("test1"); e = expected_new (); b = expected_block_new ("auto", "eth0"); @@ -217,33 +210,35 @@ test1_ignore_line_before_first_block (void) expected_add_block (e, b); expected_block_add_key (b, expected_key_new ("inet", "dhcp")); - compare_expected_to_ifparser (parser, e); + init_ifparser_with_file (path, "test1"); + compare_expected_to_ifparser (e); + ifparser_destroy (); expected_free (e); } static void -test2_wrapped_line (void) +test2_wrapped_line (const char *path) { Expected *e; ExpectedBlock *b; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file ("test2"); e = expected_new (); b = expected_block_new ("auto", "lo"); expected_add_block (e, b); - compare_expected_to_ifparser (parser, e); + init_ifparser_with_file (path, "test2"); + compare_expected_to_ifparser (e); + ifparser_destroy (); expected_free (e); } static void -test3_wrapped_multiline_multiarg (void) +test3_wrapped_multiline_multiarg (const char *path) { Expected *e; ExpectedBlock *b; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file ("test3"); e = expected_new (); b = expected_block_new ("allow-hotplug", "eth0"); @@ -253,33 +248,35 @@ test3_wrapped_multiline_multiarg (void) b = expected_block_new ("allow-hotplug", "bnep0"); expected_add_block (e, b); - compare_expected_to_ifparser (parser, e); + init_ifparser_with_file (path, "test3"); + compare_expected_to_ifparser (e); + ifparser_destroy (); expected_free (e); } static void -test4_allow_auto_is_auto (void) +test4_allow_auto_is_auto (const char *path) { Expected *e; ExpectedBlock *b; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file ("test4"); e = expected_new (); b = expected_block_new ("auto", "eth0"); expected_add_block (e, b); - compare_expected_to_ifparser (parser, e); + init_ifparser_with_file (path, "test4"); + compare_expected_to_ifparser (e); + ifparser_destroy (); expected_free (e); } static void -test5_allow_auto_multiarg (void) +test5_allow_auto_multiarg (const char *path) { Expected *e; ExpectedBlock *b; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file ("test5"); e = expected_new (); b = expected_block_new ("allow-hotplug", "eth0"); @@ -287,50 +284,52 @@ test5_allow_auto_multiarg (void) b = expected_block_new ("allow-hotplug", "wlan0"); expected_add_block (e, b); - compare_expected_to_ifparser (parser, e); + init_ifparser_with_file (path, "test5"); + compare_expected_to_ifparser (e); + ifparser_destroy (); expected_free (e); } static void -test6_mixed_whitespace (void) +test6_mixed_whitespace (const char *path) { Expected *e; ExpectedBlock *b; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file ("test6"); e = expected_new (); b = expected_block_new ("iface", "lo"); expected_block_add_key (b, expected_key_new ("inet", "loopback")); expected_add_block (e, b); - compare_expected_to_ifparser (parser, e); + init_ifparser_with_file (path, "test6"); + compare_expected_to_ifparser (e); + ifparser_destroy (); expected_free (e); } static void -test7_long_line (void) +test7_long_line (const char *path) { - nm_auto_ifparser if_parser *parser = init_ifparser_with_file ("test7"); - - g_assert_cmpint (ifparser_get_num_blocks (parser), ==, 0); + init_ifparser_with_file (path, "test7"); + g_assert_cmpint (ifparser_get_num_blocks (), ==, 0); + ifparser_destroy (); } static void -test8_long_line_wrapped (void) +test8_long_line_wrapped (const char *path) { - nm_auto_ifparser if_parser *parser = init_ifparser_with_file ("test8"); - - g_assert_cmpint (ifparser_get_num_blocks (parser), ==, 0); + init_ifparser_with_file (path, "test8"); + g_assert_cmpint (ifparser_get_num_blocks (), ==, 0); + ifparser_destroy (); } static void -test9_wrapped_lines_in_block (void) +test9_wrapped_lines_in_block (const char *path) { Expected *e; ExpectedBlock *b; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file ("test9"); e = expected_new (); b = expected_block_new ("iface", "eth0"); @@ -341,17 +340,18 @@ test9_wrapped_lines_in_block (void) expected_block_add_key (b, expected_key_new ("broadcast", "10.250.2.63")); expected_block_add_key (b, expected_key_new ("gateway", "10.250.2.50")); - compare_expected_to_ifparser (parser, e); + init_ifparser_with_file (path, "test9"); + compare_expected_to_ifparser (e); + ifparser_destroy (); expected_free (e); } static void -test11_complex_wrap (void) +test11_complex_wrap (const char *path) { Expected *e; ExpectedBlock *b; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file ("test11"); e = expected_new (); b = expected_block_new ("iface", "pppoe"); @@ -359,17 +359,18 @@ test11_complex_wrap (void) expected_block_add_key (b, expected_key_new ("inet", "manual")); expected_block_add_key (b, expected_key_new ("pre-up", "/sbin/ifconfig eth0 up")); - compare_expected_to_ifparser (parser, e); + init_ifparser_with_file (path, "test11"); + compare_expected_to_ifparser (e); + ifparser_destroy (); expected_free (e); } static void -test12_complex_wrap_split_word (void) +test12_complex_wrap_split_word (const char *path) { Expected *e; ExpectedBlock *b; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file ("test12"); e = expected_new (); b = expected_block_new ("iface", "pppoe"); @@ -377,34 +378,36 @@ test12_complex_wrap_split_word (void) expected_block_add_key (b, expected_key_new ("inet", "manual")); expected_block_add_key (b, expected_key_new ("up", "ifup ppp0=dsl")); - compare_expected_to_ifparser (parser, e); + init_ifparser_with_file (path, "test12"); + compare_expected_to_ifparser (e); + ifparser_destroy (); expected_free (e); } static void -test13_more_mixed_whitespace (void) +test13_more_mixed_whitespace (const char *path) { Expected *e; ExpectedBlock *b; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file ("test13"); e = expected_new (); b = expected_block_new ("iface", "dsl"); expected_block_add_key (b, expected_key_new ("inet", "ppp")); expected_add_block (e, b); - compare_expected_to_ifparser (parser, e); + init_ifparser_with_file (path, "test13"); + compare_expected_to_ifparser (e); + ifparser_destroy (); expected_free (e); } static void -test14_mixed_whitespace_block_start (void) +test14_mixed_whitespace_block_start (const char *path) { Expected *e; ExpectedBlock *b; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file ("test14"); e = expected_new (); b = expected_block_new ("iface", "wlan0"); @@ -417,43 +420,47 @@ test14_mixed_whitespace_block_start (void) expected_block_add_key (b, expected_key_new ("inet", "dhcp")); expected_add_block (e, b); - compare_expected_to_ifparser (parser, e); + init_ifparser_with_file (path, "test14"); + compare_expected_to_ifparser (e); + ifparser_destroy (); expected_free (e); } static void -test15_trailing_space (void) +test15_trailing_space (const char *path) { Expected *e; ExpectedBlock *b; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file ("test15"); e = expected_new (); b = expected_block_new ("iface", "bnep0"); expected_block_add_key (b, expected_key_new ("inet", "static")); expected_add_block (e, b); - compare_expected_to_ifparser (parser, e); + init_ifparser_with_file (path, "test15"); + compare_expected_to_ifparser (e); + ifparser_destroy (); expected_free (e); } static void -test16_missing_newline (void) +test16_missing_newline (const char *path) { Expected *e; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file ("test16"); e = expected_new (); expected_add_block (e, expected_block_new ("mapping", "eth0")); - compare_expected_to_ifparser (parser, e); + init_ifparser_with_file (path, "test16"); + compare_expected_to_ifparser (e); + ifparser_destroy (); expected_free (e); } static void -test17_read_static_ipv4 (void) +test17_read_static_ipv4 (const char *path) { NMConnection *connection; NMSettingConnection *s_con; @@ -463,13 +470,13 @@ test17_read_static_ipv4 (void) gboolean success; NMIPAddress *ip4_addr; if_block *block = NULL; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file ("test17-wired-static-verify-ip4"); - block = ifparser_getfirst (parser); + init_ifparser_with_file (path, "test17-wired-static-verify-ip4"); + block = ifparser_getfirst (); connection = nm_simple_connection_new(); g_assert (connection); - ifupdown_update_connection_from_if_block (connection, block, &error); + ifupdown_update_connection_from_if_block(connection, block, &error); g_assert_no_error (error); success = nm_connection_verify (connection, &error); @@ -504,11 +511,12 @@ test17_read_static_ipv4 (void) g_assert_cmpstr (nm_setting_ip_config_get_dns_search (s_ip4, 0), ==, "example.com"); g_assert_cmpstr (nm_setting_ip_config_get_dns_search (s_ip4, 1), ==, "foo.example.com"); + ifparser_destroy (); g_object_unref (connection); } static void -test18_read_static_ipv6 (void) +test18_read_static_ipv6 (const char *path) { NMConnection *connection; NMSettingConnection *s_con; @@ -518,12 +526,12 @@ test18_read_static_ipv6 (void) gboolean success; NMIPAddress *ip6_addr; if_block *block = NULL; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file ("test18-wired-static-verify-ip6"); - block = ifparser_getfirst (parser); + init_ifparser_with_file (path, "test18-wired-static-verify-ip6"); + block = ifparser_getfirst (); connection = nm_simple_connection_new(); g_assert (connection); - ifupdown_update_connection_from_if_block (connection, block, &error); + ifupdown_update_connection_from_if_block(connection, block, &error); g_assert_no_error (error); success = nm_connection_verify (connection, &error); @@ -558,11 +566,12 @@ test18_read_static_ipv6 (void) g_assert_cmpstr (nm_setting_ip_config_get_dns_search (s_ip6, 0), ==, "example.com"); g_assert_cmpstr (nm_setting_ip_config_get_dns_search (s_ip6, 1), ==, "foo.example.com"); + ifparser_destroy (); g_object_unref (connection); } static void -test19_read_static_ipv4_plen (void) +test19_read_static_ipv4_plen (const char *path) { NMConnection *connection; NMSettingIPConfig *s_ip4; @@ -570,12 +579,12 @@ test19_read_static_ipv4_plen (void) NMIPAddress *ip4_addr; if_block *block = NULL; gboolean success; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file ("test19-wired-static-verify-ip4-plen"); - block = ifparser_getfirst (parser); + init_ifparser_with_file (path, "test19-wired-static-verify-ip4-plen"); + block = ifparser_getfirst (); connection = nm_simple_connection_new(); g_assert (connection); - ifupdown_update_connection_from_if_block (connection, block, &error); + ifupdown_update_connection_from_if_block(connection, block, &error); g_assert_no_error (error); success = nm_connection_verify (connection, &error); @@ -592,15 +601,15 @@ test19_read_static_ipv4_plen (void) g_assert_cmpstr (nm_ip_address_get_address (ip4_addr), ==, "10.0.0.3"); g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, 8); + ifparser_destroy (); g_object_unref (connection); } static void -test20_source_stanza (void) +test20_source_stanza (const char *path) { Expected *e; ExpectedBlock *b; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file ("test20-source-stanza"); e = expected_new (); @@ -616,17 +625,18 @@ test20_source_stanza (void) expected_add_block (e, b); expected_block_add_key (b, expected_key_new ("inet", "dhcp")); - compare_expected_to_ifparser (parser, e); + init_ifparser_with_file (path, "test20-source-stanza"); + compare_expected_to_ifparser (e); + ifparser_destroy (); expected_free (e); } static void -test21_source_dir_stanza (void) +test21_source_dir_stanza (const char *path) { Expected *e; ExpectedBlock *b; - nm_auto_ifparser if_parser *parser = init_ifparser_with_file ("test21-source-dir-stanza"); e = expected_new (); @@ -636,8 +646,10 @@ test21_source_dir_stanza (void) expected_add_block (e, b); expected_block_add_key (b, expected_key_new ("inet", "dhcp")); - compare_expected_to_ifparser (parser, e); + init_ifparser_with_file (path, "test21-source-dir-stanza"); + compare_expected_to_ifparser (e); + ifparser_destroy (); expected_free (e); } @@ -648,28 +660,49 @@ main (int argc, char **argv) { nmtst_init_assert_logging (&argc, &argv, "WARN", "DEFAULT"); - (void) dump_blocks; - - g_test_add_func ("/ifupdate/ignore_line_before_first_block", test1_ignore_line_before_first_block); - g_test_add_func ("/ifupdate/wrapped_line", test2_wrapped_line); - g_test_add_func ("/ifupdate/wrapped_multiline_multiarg", test3_wrapped_multiline_multiarg); - g_test_add_func ("/ifupdate/allow_auto_is_auto", test4_allow_auto_is_auto); - g_test_add_func ("/ifupdate/allow_auto_multiarg", test5_allow_auto_multiarg); - g_test_add_func ("/ifupdate/mixed_whitespace", test6_mixed_whitespace); - g_test_add_func ("/ifupdate/long_line", test7_long_line); - g_test_add_func ("/ifupdate/long_line_wrapped", test8_long_line_wrapped); - g_test_add_func ("/ifupdate/wrapped_lines_in_block", test9_wrapped_lines_in_block); - g_test_add_func ("/ifupdate/complex_wrap", test11_complex_wrap); - g_test_add_func ("/ifupdate/complex_wrap_split_word", test12_complex_wrap_split_word); - g_test_add_func ("/ifupdate/more_mixed_whitespace", test13_more_mixed_whitespace); - g_test_add_func ("/ifupdate/mixed_whitespace_block_start", test14_mixed_whitespace_block_start); - g_test_add_func ("/ifupdate/trailing_space", test15_trailing_space); - g_test_add_func ("/ifupdate/missing_newline", test16_missing_newline); - g_test_add_func ("/ifupdate/read_static_ipv4", test17_read_static_ipv4); - g_test_add_func ("/ifupdate/read_static_ipv6", test18_read_static_ipv6); - g_test_add_func ("/ifupdate/read_static_ipv4_plen", test19_read_static_ipv4_plen); - g_test_add_func ("/ifupdate/source_stanza", test20_source_stanza); - g_test_add_func ("/ifupdate/source_dir_stanza", test21_source_dir_stanza); + if (0) + dump_blocks (); + + g_test_add_data_func ("/ifupdate/ignore_line_before_first_block", TEST_DIR, + (GTestDataFunc) test1_ignore_line_before_first_block); + g_test_add_data_func ("/ifupdate/wrapped_line", TEST_DIR, + (GTestDataFunc) test2_wrapped_line); + g_test_add_data_func ("/ifupdate/wrapped_multiline_multiarg", TEST_DIR, + (GTestDataFunc) test3_wrapped_multiline_multiarg); + g_test_add_data_func ("/ifupdate/allow_auto_is_auto", TEST_DIR, + (GTestDataFunc) test4_allow_auto_is_auto); + g_test_add_data_func ("/ifupdate/allow_auto_multiarg", TEST_DIR, + (GTestDataFunc) test5_allow_auto_multiarg); + g_test_add_data_func ("/ifupdate/mixed_whitespace", TEST_DIR, + (GTestDataFunc) test6_mixed_whitespace); + g_test_add_data_func ("/ifupdate/long_line", TEST_DIR, + (GTestDataFunc) test7_long_line); + g_test_add_data_func ("/ifupdate/long_line_wrapped", TEST_DIR, + (GTestDataFunc) test8_long_line_wrapped); + g_test_add_data_func ("/ifupdate/wrapped_lines_in_block", TEST_DIR, + (GTestDataFunc) test9_wrapped_lines_in_block); + g_test_add_data_func ("/ifupdate/complex_wrap", TEST_DIR, + (GTestDataFunc) test11_complex_wrap); + g_test_add_data_func ("/ifupdate/complex_wrap_split_word", TEST_DIR, + (GTestDataFunc) test12_complex_wrap_split_word); + g_test_add_data_func ("/ifupdate/more_mixed_whitespace", TEST_DIR, + (GTestDataFunc) test13_more_mixed_whitespace); + g_test_add_data_func ("/ifupdate/mixed_whitespace_block_start", TEST_DIR, + (GTestDataFunc) test14_mixed_whitespace_block_start); + g_test_add_data_func ("/ifupdate/trailing_space", TEST_DIR, + (GTestDataFunc) test15_trailing_space); + g_test_add_data_func ("/ifupdate/missing_newline", TEST_DIR, + (GTestDataFunc) test16_missing_newline); + g_test_add_data_func ("/ifupdate/read_static_ipv4", TEST_DIR, + (GTestDataFunc) test17_read_static_ipv4); + g_test_add_data_func ("/ifupdate/read_static_ipv6", TEST_DIR, + (GTestDataFunc) test18_read_static_ipv6); + g_test_add_data_func ("/ifupdate/read_static_ipv4_plen", TEST_DIR, + (GTestDataFunc) test19_read_static_ipv4_plen); + g_test_add_data_func ("/ifupdate/source_stanza", TEST_DIR, + (GTestDataFunc) test20_source_stanza); + g_test_add_data_func ("/ifupdate/source_dir_stanza", TEST_DIR, + (GTestDataFunc) test21_source_dir_stanza); return g_test_run (); } |