Commit f936400c authored by Dan Winship's avatar Dan Winship

tests: clean up gtester usage

Use g_test_add_func() and g_test_add_data_func() to simplify the test
cases, getting rid of the GLIB_CHECK_VERSION calls in the process.
parent ed9e2d83
......@@ -630,31 +630,20 @@ test_up_empty_vpn_iface (const char *path)
/*******************************************/
#if GLIB_CHECK_VERSION(2,25,12)
typedef GTestFixtureFunc TCFunc;
#else
typedef void (*TCFunc)(void);
#endif
#define TESTCASE(t, d) g_test_create_case (#t, 0, d, NULL, (TCFunc) t, NULL)
int main (int argc, char **argv)
int
main (int argc, char **argv)
{
GTestSuite *suite;
g_assert (argc > 1);
g_test_init (&argc, &argv, NULL);
g_type_init ();
suite = g_test_get_root ();
g_test_suite_add (suite, TESTCASE (test_old_up, argv[1]));
g_test_suite_add (suite, TESTCASE (test_old_down, argv[1]));
g_test_suite_add (suite, TESTCASE (test_old_vpn_up, argv[1]));
g_test_suite_add (suite, TESTCASE (test_old_vpn_down, argv[1]));
g_test_add_data_func ("/dispatcher/old_up", argv[1], (GTestDataFunc) test_old_up);
g_test_add_data_func ("/dispatcher/old_down", argv[1], (GTestDataFunc) test_old_down);
g_test_add_data_func ("/dispatcher/old_vpn_up", argv[1], (GTestDataFunc) test_old_vpn_up);
g_test_add_data_func ("/dispatcher/old_vpn_down", argv[1], (GTestDataFunc) test_old_vpn_down);
g_test_suite_add (suite, TESTCASE (test_up_empty_vpn_iface, argv[1]));
g_test_add_data_func ("/dispatcher/up_empty_vpn_iface", argv[1], (GTestDataFunc) test_up_empty_vpn_iface);
return g_test_run ();
}
......
......@@ -342,17 +342,9 @@ test_remove_connection (void)
/*******************************************************************/
#if GLIB_CHECK_VERSION(2,25,12)
typedef GTestFixtureFunc TCFunc;
#else
typedef void (*TCFunc)(void);
#endif
#define TESTCASE(t, d) g_test_create_case (#t, 0, d, NULL, (TCFunc) t, NULL)
int main (int argc, char **argv)
int
main (int argc, char **argv)
{
GTestSuite *suite;
char *service_argv[3] = { NULL, NULL, NULL };
int ret;
GError *error = NULL;
......@@ -390,12 +382,10 @@ int main (int argc, char **argv)
settings = nm_remote_settings_new (bus);
test_assert (settings != NULL);
suite = g_test_get_root ();
g_test_suite_add (suite, TESTCASE (test_add_connection, NULL));
g_test_suite_add (suite, TESTCASE (test_make_invisible, NULL));
g_test_suite_add (suite, TESTCASE (test_make_visible, NULL));
g_test_suite_add (suite, TESTCASE (test_remove_connection, NULL));
g_test_add_func ("/remote_settings/add_connection", test_add_connection);
g_test_add_func ("/remote_settings/make_invisible", test_make_invisible);
g_test_add_func ("/remote_settings/make_visible", test_make_visible);
g_test_add_func ("/remote_settings/remove_connection", test_remove_connection);
ret = g_test_run ();
......
......@@ -393,37 +393,26 @@ test_write_existing_commented_duid (void)
/*******************************************/
#if GLIB_CHECK_VERSION(2,25,12)
typedef GTestFixtureFunc TCFunc;
#else
typedef void (*TCFunc)(void);
#endif
#define TESTCASE(t, d) g_test_create_case (#t, 0, d, NULL, (TCFunc) t, NULL)
int main (int argc, char **argv)
int
main (int argc, char **argv)
{
GTestSuite *suite;
g_test_init (&argc, &argv, NULL);
g_type_init ();
suite = g_test_get_root ();
g_test_suite_add (suite, TESTCASE (test_orig_missing, NULL));
g_test_suite_add (suite, TESTCASE (test_override_client_id, NULL));
g_test_suite_add (suite, TESTCASE (test_override_hostname, NULL));
g_test_suite_add (suite, TESTCASE (test_existing_alsoreq, NULL));
g_test_suite_add (suite, TESTCASE (test_existing_multiline_alsoreq, NULL));
g_test_suite_add (suite, TESTCASE (test_duids, NULL));
g_test_add_func ("/dhcp/dhclient/orig_missing", test_orig_missing);
g_test_add_func ("/dhcp/dhclient/override_client_id", test_override_client_id);
g_test_add_func ("/dhcp/dhclient/override_hostname", test_override_hostname);
g_test_add_func ("/dhcp/dhclient/existing_alsoreq", test_existing_alsoreq);
g_test_add_func ("/dhcp/dhclient/existing_multiline_alsoreq", test_existing_multiline_alsoreq);
g_test_add_func ("/dhcp/dhclient/duids", test_duids);
g_test_suite_add (suite, TESTCASE (test_read_duid_from_leasefile, NULL));
g_test_suite_add (suite, TESTCASE (test_read_commented_duid_from_leasefile, NULL));
g_test_add_func ("/dhcp/dhclient/read_duid_from_leasefile", test_read_duid_from_leasefile);
g_test_add_func ("/dhcp/dhclient/read_commented_duid_from_leasefile", test_read_commented_duid_from_leasefile);
g_test_suite_add (suite, TESTCASE (test_write_duid, NULL));
g_test_suite_add (suite, TESTCASE (test_write_existing_duid, NULL));
g_test_suite_add (suite, TESTCASE (test_write_existing_commented_duid, NULL));
g_test_add_func ("/dhcp/dhclient/write_duid", test_write_duid);
g_test_add_func ("/dhcp/dhclient/write_existing_duid", test_write_existing_duid);
g_test_add_func ("/dhcp/dhclient/write_existing_commented_duid", test_write_existing_commented_duid);
return g_test_run ();
}
......
......@@ -904,17 +904,9 @@ test19_read_static_ipv4_plen (const char *path)
}
#if GLIB_CHECK_VERSION(2,25,12)
typedef GTestFixtureFunc TCFunc;
#else
typedef void (*TCFunc)(void);
#endif
#define TESTCASE(t, d) g_test_create_case (#t, 0, d, NULL, (TCFunc) t, NULL)
int main (int argc, char **argv)
int
main (int argc, char **argv)
{
GTestSuite *suite;
GError *error = NULL;
g_type_init ();
......@@ -924,29 +916,45 @@ int main (int argc, char **argv)
g_test_init (&argc, &argv, NULL);
suite = g_test_get_root ();
if (0)
dump_blocks ();
g_test_suite_add (suite, TESTCASE (test1_ignore_line_before_first_block, TEST_ENI_DIR));
g_test_suite_add (suite, TESTCASE (test2_wrapped_line, TEST_ENI_DIR));
g_test_suite_add (suite, TESTCASE (test3_wrapped_multiline_multiarg, TEST_ENI_DIR));
g_test_suite_add (suite, TESTCASE (test4_allow_auto_is_auto, TEST_ENI_DIR));
g_test_suite_add (suite, TESTCASE (test5_allow_auto_multiarg, TEST_ENI_DIR));
g_test_suite_add (suite, TESTCASE (test6_mixed_whitespace, TEST_ENI_DIR));
g_test_suite_add (suite, TESTCASE (test7_long_line, TEST_ENI_DIR));
g_test_suite_add (suite, TESTCASE (test8_long_line_wrapped, TEST_ENI_DIR));
g_test_suite_add (suite, TESTCASE (test9_wrapped_lines_in_block, TEST_ENI_DIR));
g_test_suite_add (suite, TESTCASE (test11_complex_wrap, TEST_ENI_DIR));
g_test_suite_add (suite, TESTCASE (test12_complex_wrap_split_word, TEST_ENI_DIR));
g_test_suite_add (suite, TESTCASE (test13_more_mixed_whitespace, TEST_ENI_DIR));
g_test_suite_add (suite, TESTCASE (test14_mixed_whitespace_block_start, TEST_ENI_DIR));
g_test_suite_add (suite, TESTCASE (test15_trailing_space, TEST_ENI_DIR));
g_test_suite_add (suite, TESTCASE (test16_missing_newline, TEST_ENI_DIR));
g_test_suite_add (suite, TESTCASE (test17_read_static_ipv4, TEST_ENI_DIR));
g_test_suite_add (suite, TESTCASE (test18_read_static_ipv6, TEST_ENI_DIR));
g_test_suite_add (suite, TESTCASE (test19_read_static_ipv4_plen, TEST_ENI_DIR));
g_test_add_data_func ("/ifupdate/ignore_line_before_first_block", TEST_ENI_DIR,
(GTestDataFunc) test1_ignore_line_before_first_block);
g_test_add_data_func ("/ifupdate/wrapped_line", TEST_ENI_DIR,
(GTestDataFunc) test2_wrapped_line);
g_test_add_data_func ("/ifupdate/wrapped_multiline_multiarg", TEST_ENI_DIR,
(GTestDataFunc) test3_wrapped_multiline_multiarg);
g_test_add_data_func ("/ifupdate/allow_auto_is_auto", TEST_ENI_DIR,
(GTestDataFunc) test4_allow_auto_is_auto);
g_test_add_data_func ("/ifupdate/allow_auto_multiarg", TEST_ENI_DIR,
(GTestDataFunc) test5_allow_auto_multiarg);
g_test_add_data_func ("/ifupdate/mixed_whitespace", TEST_ENI_DIR,
(GTestDataFunc) test6_mixed_whitespace);
g_test_add_data_func ("/ifupdate/long_line", TEST_ENI_DIR,
(GTestDataFunc) test7_long_line);
g_test_add_data_func ("/ifupdate/long_line_wrapped", TEST_ENI_DIR,
(GTestDataFunc) test8_long_line_wrapped);
g_test_add_data_func ("/ifupdate/wrapped_lines_in_block", TEST_ENI_DIR,
(GTestDataFunc) test9_wrapped_lines_in_block);
g_test_add_data_func ("/ifupdate/complex_wrap", TEST_ENI_DIR,
(GTestDataFunc) test11_complex_wrap);
g_test_add_data_func ("/ifupdate/complex_wrap_split_word", TEST_ENI_DIR,
(GTestDataFunc) test12_complex_wrap_split_word);
g_test_add_data_func ("/ifupdate/more_mixed_whitespace", TEST_ENI_DIR,
(GTestDataFunc) test13_more_mixed_whitespace);
g_test_add_data_func ("/ifupdate/mixed_whitespace_block_start", TEST_ENI_DIR,
(GTestDataFunc) test14_mixed_whitespace_block_start);
g_test_add_data_func ("/ifupdate/trailing_space", TEST_ENI_DIR,
(GTestDataFunc) test15_trailing_space);
g_test_add_data_func ("/ifupdate/missing_newline", TEST_ENI_DIR,
(GTestDataFunc) test16_missing_newline);
g_test_add_data_func ("/ifupdate/read_static_ipv4", TEST_ENI_DIR,
(GTestDataFunc) test17_read_static_ipv4);
g_test_add_data_func ("/ifupdate/read_static_ipv6", TEST_ENI_DIR,
(GTestDataFunc) test18_read_static_ipv6);
g_test_add_data_func ("/ifupdate/read_static_ipv4_plen", TEST_ENI_DIR,
(GTestDataFunc) test19_read_static_ipv4_plen);
return g_test_run ();
}
......
......@@ -120,27 +120,16 @@ test_defname_multiple_conflicts (void)
/*******************************************/
#if GLIB_CHECK_VERSION(2,25,12)
typedef GTestFixtureFunc TCFunc;
#else
typedef void (*TCFunc)(void);
#endif
#define TESTCASE(t, d) g_test_create_case (#t, 0, d, NULL, (TCFunc) t, NULL)
int main (int argc, char **argv)
int
main (int argc, char **argv)
{
GTestSuite *suite;
g_type_init ();
g_test_init (&argc, &argv, NULL);
suite = g_test_get_root ();
g_test_suite_add (suite, TESTCASE (test_defname_no_connections, NULL));
g_test_suite_add (suite, TESTCASE (test_defname_no_conflict, NULL));
g_test_suite_add (suite, TESTCASE (test_defname_conflict, NULL));
g_test_suite_add (suite, TESTCASE (test_defname_multiple_conflicts, NULL));
g_test_add_func ("/defname/no_connections", test_defname_no_connections);
g_test_add_func ("/defname/no_conflict", test_defname_no_conflict);
g_test_add_func ("/defname/conflict", test_defname_conflict);
g_test_add_func ("/defname/multiple_conflicts", test_defname_multiple_conflicts);
return g_test_run ();
}
......
......@@ -150,26 +150,15 @@ test_hosts_leftover_double_newline (void)
/*******************************************/
#if GLIB_CHECK_VERSION(2,25,12)
typedef GTestFixtureFunc TCFunc;
#else
typedef void (*TCFunc)(void);
#endif
#define TESTCASE(t, d) g_test_create_case (#t, 0, d, NULL, (TCFunc) t, NULL)
int main (int argc, char **argv)
int
main (int argc, char **argv)
{
GTestSuite *suite;
g_test_init (&argc, &argv, NULL);
suite = g_test_get_root ();
g_test_suite_add (suite, TESTCASE (test_hosts_generic, NULL));
g_test_suite_add (suite, TESTCASE (test_hosts_generic_no_boilerplate, NULL));
g_test_suite_add (suite, TESTCASE (test_hosts_leftover, NULL));
g_test_suite_add (suite, TESTCASE (test_hosts_leftover_double_newline, NULL));
g_test_add_func ("/hosts/generic", test_hosts_generic);
g_test_add_func ("/hosts/generic_no_boilerplate", test_hosts_generic_no_boilerplate);
g_test_add_func ("/hosts/leftover", test_hosts_leftover);
g_test_add_func ("/hosts/leftover_double_newline", test_hosts_leftover_double_newline);
return g_test_run ();
}
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment