Enable XML output for liblinphone tester

This commit is contained in:
Guillaume BIENKOWSKI 2014-12-15 11:10:44 +01:00
parent 1ac1cd5fe8
commit d9bc65287c
3 changed files with 86 additions and 35 deletions

View file

@ -135,6 +135,8 @@ void helper(const char *name) {
#if HAVE_CU_CURSES #if HAVE_CU_CURSES
"\t\t\t--curses\n" "\t\t\t--curses\n"
#endif #endif
"\t\t\t--xml\n"
"\t\t\t--xml-file <xml file prefix (will be suffixed by '-Results.xml')>\n"
, name); , name);
} }
@ -153,6 +155,8 @@ int main (int argc, char *argv[])
int ret; int ret;
const char *suite_name=NULL; const char *suite_name=NULL;
const char *test_name=NULL; const char *test_name=NULL;
const char *xml_file=NULL;
int xml = 0;
FILE* log_file=NULL; FILE* log_file=NULL;
#if defined(ANDROID) #if defined(ANDROID)
linphone_core_set_log_handler(linphone_android_ortp_log_handler); linphone_core_set_log_handler(linphone_android_ortp_log_handler);
@ -198,6 +202,11 @@ int main (int argc, char *argv[])
suite_name = argv[i]; suite_name = argv[i];
liblinphone_tester_list_suite_tests(suite_name); liblinphone_tester_list_suite_tests(suite_name);
return 0; 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){ } else if (strcmp(argv[i],"--log-file")==0){
CHECK_ARG("--log-file", ++i, argc); CHECK_ARG("--log-file", ++i, argc);
log_file=fopen(argv[i],"w"); 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); ret = liblinphone_tester_run_tests(suite_name, test_name);
liblinphone_tester_uninit(); liblinphone_tester_uninit();
return ret; return ret;

View file

@ -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 void liblinphone_tester_set_writable_dir_prefix(const char* writable_dir_prefix);
extern int liblinphone_tester_ipv6_available(void); 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. * @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 * @details Setting this to 1 will not clear the list of created accounts between successive

View file

@ -18,6 +18,7 @@
#include <stdio.h> #include <stdio.h>
#include "CUnit/TestRun.h" #include "CUnit/TestRun.h"
#include "CUnit/Automated.h"
#include "linphonecore.h" #include "linphonecore.h"
#include "private.h" #include "private.h"
#include "liblinphone_tester.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 liblinphone_tester_keep_accounts_flag = 0;
static int manager_count = 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 #if WINAPI_FAMILY_PHONE_APP
const char *liblinphone_tester_file_prefix="Assets"; const char *liblinphone_tester_file_prefix="Assets";
#elif defined(__QNX__) #elif defined(__QNX__)
@ -500,6 +504,13 @@ int liblinphone_tester_run_tests(const char *suite_name, const char *test_name)
CU_set_suite_start_handler(test_suite_start_message_handler); 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 !HAVE_CU_GET_SUITE
if( suite_name ){ if( suite_name ){
ms_warning("Tester compiled without CU_get_suite() function, running all tests instead of suite '%s'\n", suite_name); ms_warning("Tester compiled without CU_get_suite() function, running all tests instead of suite '%s'\n", suite_name);
@ -543,6 +554,7 @@ int liblinphone_tester_run_tests(const char *suite_name, const char *test_name)
} }
} }
}
ret=CU_get_number_of_tests_failed()!=0; ret=CU_get_number_of_tests_failed()!=0;
/* Redisplay list of failed tests on end */ /* Redisplay list of failed tests on end */
@ -601,4 +613,18 @@ void liblinphone_tester_clear_accounts(void){
account_manager_destroy(); 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;
}