From d9bc65287c1e77de3f2d27db46e683bfec43aa6e Mon Sep 17 00:00:00 2001 From: Guillaume BIENKOWSKI Date: Mon, 15 Dec 2014 11:10:44 +0100 Subject: [PATCH] Enable XML output for liblinphone tester --- tester/liblinphone_tester.c | 20 ++++++++ tester/liblinphone_tester.h | 5 ++ tester/tester.c | 96 +++++++++++++++++++++++-------------- 3 files changed, 86 insertions(+), 35 deletions(-) diff --git a/tester/liblinphone_tester.c b/tester/liblinphone_tester.c index addf99566..aa4f78f29 100644 --- a/tester/liblinphone_tester.c +++ b/tester/liblinphone_tester.c @@ -135,6 +135,8 @@ void helper(const char *name) { #if HAVE_CU_CURSES "\t\t\t--curses\n" #endif + "\t\t\t--xml\n" + "\t\t\t--xml-file \n" , name); } @@ -153,6 +155,8 @@ int main (int argc, char *argv[]) int ret; const char *suite_name=NULL; const char *test_name=NULL; + const char *xml_file=NULL; + int xml = 0; FILE* log_file=NULL; #if defined(ANDROID) linphone_core_set_log_handler(linphone_android_ortp_log_handler); @@ -198,6 +202,11 @@ int main (int argc, char *argv[]) suite_name = argv[i]; liblinphone_tester_list_suite_tests(suite_name); return 0; + } else if (strcmp(argv[i], "--xml-file") == 0){ + CHECK_ARG("--xml-file", ++i, argc); + xml_file = argv[i]; + } else if (strcmp(argv[i], "--xml") == 0){ + xml = 1; } else if (strcmp(argv[i],"--log-file")==0){ CHECK_ARG("--log-file", ++i, argc); log_file=fopen(argv[i],"w"); @@ -216,6 +225,17 @@ int main (int argc, char *argv[]) } } + if( xml && (suite_name || test_name) ){ + printf("Cannot use both xml and specific test suite\n"); + return -1; + } + + if( xml_file != NULL ){ + liblinphone_tester_set_xml_output(xml_file); + } + liblinphone_tester_enable_xml(xml); + + ret = liblinphone_tester_run_tests(suite_name, test_name); liblinphone_tester_uninit(); return ret; diff --git a/tester/liblinphone_tester.h b/tester/liblinphone_tester.h index d7bbb64e9..0ae708b70 100644 --- a/tester/liblinphone_tester.h +++ b/tester/liblinphone_tester.h @@ -79,6 +79,11 @@ extern void liblinphone_tester_set_fileprefix(const char* file_prefix); extern void liblinphone_tester_set_writable_dir_prefix(const char* writable_dir_prefix); extern int liblinphone_tester_ipv6_available(void); + +extern void liblinphone_tester_enable_xml( bool_t enable ); +extern void liblinphone_tester_set_xml_output(const char *xml_path ); +extern const char* liblinphone_tester_get_xml_output(void); + /** * @brief Tells the tester whether or not to clean the accounts it has created between runs. * @details Setting this to 1 will not clear the list of created accounts between successive diff --git a/tester/tester.c b/tester/tester.c index 2d39e7e67..125ebd5df 100644 --- a/tester/tester.c +++ b/tester/tester.c @@ -18,6 +18,7 @@ #include #include "CUnit/TestRun.h" +#include "CUnit/Automated.h" #include "linphonecore.h" #include "private.h" #include "liblinphone_tester.h" @@ -42,6 +43,9 @@ int liblinphone_tester_use_log_file=0; static int liblinphone_tester_keep_accounts_flag = 0; static int manager_count = 0; +static const char* liblinphone_tester_xml_file = NULL; +static int liblinphone_tester_xml_enabled = FALSE; + #if WINAPI_FAMILY_PHONE_APP const char *liblinphone_tester_file_prefix="Assets"; #elif defined(__QNX__) @@ -500,49 +504,57 @@ int liblinphone_tester_run_tests(const char *suite_name, const char *test_name) CU_set_suite_start_handler(test_suite_start_message_handler); + if( liblinphone_tester_xml_file != NULL ){ + CU_set_output_filename(liblinphone_tester_xml_file); + } + if( liblinphone_tester_xml_enabled != 0 ){ + CU_automated_run_tests(); + } else { + #if !HAVE_CU_GET_SUITE - if( suite_name ){ - ms_warning("Tester compiled without CU_get_suite() function, running all tests instead of suite '%s'\n", suite_name); - } -#else - if (suite_name){ - CU_pSuite suite; - suite=CU_get_suite(suite_name); - if (!suite) { - ms_error("Could not find suite '%s'. Available suites are:", suite_name); - liblinphone_tester_list_suites(); - return -1; - } else if (test_name) { - CU_pTest test=CU_get_test_by_name(test_name, suite); - if (!test) { - ms_error("Could not find test '%s' in suite '%s'. Available tests are:", test_name, suite_name); - // do not use suite_name here, since this method is case sentisitive - liblinphone_tester_list_suite_tests(suite->pName); - return -2; - } else { - CU_ErrorCode err= CU_run_test(suite, test); - if (err != CUE_SUCCESS) ms_error("CU_basic_run_test error %d", err); - } - } else { - CU_run_suite(suite); + if( suite_name ){ + ms_warning("Tester compiled without CU_get_suite() function, running all tests instead of suite '%s'\n", suite_name); } - } - else -#endif - { -#if HAVE_CU_CURSES - if (curses) { - /* Run tests using the CUnit curses interface */ - CU_curses_run_tests(); +#else + if (suite_name){ + CU_pSuite suite; + suite=CU_get_suite(suite_name); + if (!suite) { + ms_error("Could not find suite '%s'. Available suites are:", suite_name); + liblinphone_tester_list_suites(); + return -1; + } else if (test_name) { + CU_pTest test=CU_get_test_by_name(test_name, suite); + if (!test) { + ms_error("Could not find test '%s' in suite '%s'. Available tests are:", test_name, suite_name); + // do not use suite_name here, since this method is case sentisitive + liblinphone_tester_list_suite_tests(suite->pName); + return -2; + } else { + CU_ErrorCode err= CU_run_test(suite, test); + if (err != CUE_SUCCESS) ms_error("CU_basic_run_test error %d", err); + } + } else { + CU_run_suite(suite); + } } else #endif { - /* Run all tests using the CUnit Basic interface */ - CU_run_all_tests(); +#if HAVE_CU_CURSES + if (curses) { + /* Run tests using the CUnit curses interface */ + CU_curses_run_tests(); + } + else +#endif + { + /* Run all tests using the CUnit Basic interface */ + CU_run_all_tests(); + } } - } + } ret=CU_get_number_of_tests_failed()!=0; /* Redisplay list of failed tests on end */ @@ -601,4 +613,18 @@ void liblinphone_tester_clear_accounts(void){ account_manager_destroy(); } +void liblinphone_tester_enable_xml( bool_t enable ){ + liblinphone_tester_xml_enabled = enable; +} + +void liblinphone_tester_set_xml_output(const char *xml_path ) { + liblinphone_tester_xml_file = xml_path; +} + +const char* liblinphone_tester_get_xml_output( void ) { + return liblinphone_tester_xml_file; +} + + +