From 35dd05cc4336cf91f511f95469f61c57747b1622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20=C5=A0imerda?= Date: Fri, 21 Jun 2013 04:01:44 +0200 Subject: [PATCH] platform: share main function among tests --- src/platform/tests/test-address.c | 23 ++--------------------- src/platform/tests/test-common.c | 24 ++++++++++++++++++++++++ src/platform/tests/test-common.h | 3 +++ src/platform/tests/test-link.c | 24 ++---------------------- src/platform/tests/test-route.c | 23 ++--------------------- 5 files changed, 33 insertions(+), 64 deletions(-) diff --git a/src/platform/tests/test-address.c b/src/platform/tests/test-address.c index 861cabb50b..9d38083218 100644 --- a/src/platform/tests/test-address.c +++ b/src/platform/tests/test-address.c @@ -218,22 +218,9 @@ test_ip6_address_external (void) free_signal (address_removed); } -int -main (int argc, char **argv) +void +setup_tests (void) { - int result; - - openlog (G_LOG_DOMAIN, LOG_CONS | LOG_PERROR, LOG_DAEMON); - g_type_init (); - g_test_init (&argc, &argv, NULL); - /* Enable debug messages if called with --debug */ - for (; *argv; argv++) - if (!g_strcmp0 (*argv, "--debug")) - nm_logging_setup ("debug", NULL, NULL); - - SETUP (); - - /* Clean up */ nm_platform_link_delete_by_name (DEVICE_NAME); g_assert (!nm_platform_link_exists (DEVICE_NAME)); nm_platform_dummy_add (DEVICE_NAME); @@ -245,10 +232,4 @@ main (int argc, char **argv) g_test_add_func ("/address/external/ip4", test_ip4_address_external); g_test_add_func ("/address/external/ip6", test_ip6_address_external); } - - result = g_test_run (); - - nm_platform_link_delete_by_name (DEVICE_NAME); - nm_platform_free (); - return result; } diff --git a/src/platform/tests/test-common.c b/src/platform/tests/test-common.c index b4d415b2dc..6cd8eb3123 100644 --- a/src/platform/tests/test-common.c +++ b/src/platform/tests/test-common.c @@ -59,3 +59,27 @@ run_command (const char *format, ...) g_free (command); } +int +main (int argc, char **argv) +{ + int result; + + openlog (G_LOG_DOMAIN, LOG_CONS | LOG_PERROR, LOG_DAEMON); + g_type_init (); + g_test_init (&argc, &argv, NULL); + /* Enable debug messages if called with --debug */ + for (; *argv; argv++) { + if (!g_strcmp0 (*argv, "--debug")) { + nm_logging_setup ("debug", NULL, NULL); + } + } + + SETUP (); + + setup_tests (); + + result = g_test_run (); + + nm_platform_free (); + return result; +} diff --git a/src/platform/tests/test-common.h b/src/platform/tests/test-common.h index b6ce50f9dc..09b41c7ed3 100644 --- a/src/platform/tests/test-common.h +++ b/src/platform/tests/test-common.h @@ -29,3 +29,6 @@ void wait_signal (SignalData *data); void free_signal (SignalData *data); void run_command (const char *format, ...); + +void setup_tests (void); + diff --git a/src/platform/tests/test-link.c b/src/platform/tests/test-link.c index b0afe5e6e5..8f39216087 100644 --- a/src/platform/tests/test-link.c +++ b/src/platform/tests/test-link.c @@ -561,24 +561,9 @@ test_external (void) free_signal (link_removed); } -int -main (int argc, char **argv) +void +setup_tests (void) { - int result; - - openlog (G_LOG_DOMAIN, LOG_CONS | LOG_PERROR, LOG_DAEMON); - g_type_init (); - g_test_init (&argc, &argv, NULL); - /* Enable debug messages if called with --debug */ - for (; *argv; argv++) { - if (!g_strcmp0 (*argv, "--debug")) { - nm_logging_setup ("debug", NULL, NULL); - } - } - - SETUP (); - - /* Clean up */ nm_platform_link_delete_by_name (DEVICE_NAME); nm_platform_link_delete_by_name (SLAVE_NAME); nm_platform_link_delete_by_name (PARENT_NAME); @@ -596,9 +581,4 @@ main (int argc, char **argv) if (strcmp (g_type_name (G_TYPE_FROM_INSTANCE (nm_platform_get ())), "NMFakePlatform")) g_test_add_func ("/link/external", test_external); - - result = g_test_run (); - - nm_platform_free (); - return result; } diff --git a/src/platform/tests/test-route.c b/src/platform/tests/test-route.c index 42a93e75be..f69a3c5fb9 100644 --- a/src/platform/tests/test-route.c +++ b/src/platform/tests/test-route.c @@ -196,22 +196,9 @@ test_ip6_route () free_signal (route_removed); } -int -main (int argc, char **argv) +void +setup_tests (void) { - int result; - - openlog (G_LOG_DOMAIN, LOG_CONS | LOG_PERROR, LOG_DAEMON); - g_type_init (); - g_test_init (&argc, &argv, NULL); - /* Enable debug messages if called with --debug */ - for (; *argv; argv++) - if (!g_strcmp0 (*argv, "--debug")) - nm_logging_setup ("debug", NULL, NULL); - - SETUP (); - - /* Clean up */ nm_platform_link_delete_by_name (DEVICE_NAME); g_assert (!nm_platform_link_exists (DEVICE_NAME)); g_assert (nm_platform_dummy_add (DEVICE_NAME)); @@ -219,10 +206,4 @@ main (int argc, char **argv) g_test_add_func ("/route/ip4", test_ip4_route); g_test_add_func ("/route/ip6", test_ip6_route); - - result = g_test_run (); - - nm_platform_link_delete_by_name (DEVICE_NAME); - nm_platform_free (); - return result; }