tester: fix crash when using both --verbose and --log-file

parent 1f193f7f
mediastreamer2 @ 160ed0a5
Subproject commit 8b1481dfe5d5faede84598e977ec62afd943bd2f
Subproject commit 160ed0a5c49e9067eda87544523a8d1bdb2b5155
......@@ -115,7 +115,7 @@ int bc_tester_nb_tests(const char *suite_name) {
void bc_tester_list_suites() {
int j;
for(j=0;j<nb_test_suites;j++) {
tester_printf(verbosity_info, "%s\n", bc_tester_suite_name(j));
tester_printf(verbosity_info, "%s", bc_tester_suite_name(j));
}
}
......@@ -123,7 +123,7 @@ void bc_tester_list_tests(const char *suite_name) {
int j;
for( j = 0; j < bc_tester_nb_tests(suite_name); j++) {
const char *test_name = bc_tester_test_name(suite_name, j);
tester_printf(verbosity_info, "%s\n", test_name);
tester_printf(verbosity_info, "%s", test_name);
}
}
......@@ -136,19 +136,19 @@ static void all_complete_message_handler(const CU_pFailureRecord pFailure) {
}
static void suite_init_failure_message_handler(const CU_pSuite pSuite) {
tester_printf(verbosity_error,"Suite initialization failed for [%s].", pSuite->pName);
tester_printf(verbosity_error,"Suite initialization failed for [%s]", pSuite->pName);
}
static void suite_cleanup_failure_message_handler(const CU_pSuite pSuite) {
tester_printf(verbosity_error,"Suite cleanup failed for [%s].", pSuite->pName);
tester_printf(verbosity_error,"Suite cleanup failed for [%s]", pSuite->pName);
}
#ifdef HAVE_CU_GET_SUITE
static void suite_start_message_handler(const CU_pSuite pSuite) {
tester_printf(verbosity_info,"Suite [%s] started\n", pSuite->pName);
tester_printf(verbosity_info,"Suite [%s] started", pSuite->pName);
}
static void suite_complete_message_handler(const CU_pSuite pSuite, const CU_pFailureRecord pFailure) {
tester_printf(verbosity_info,"Suite [%s] ended\n", pSuite->pName);
tester_printf(verbosity_info,"Suite [%s] ended", pSuite->pName);
}
static void test_start_message_handler(const CU_pTest pTest, const CU_pSuite pSuite) {
......@@ -163,11 +163,11 @@ static void test_complete_message_handler(const CU_pTest pTest,
char result[2048];
char buffer[2048];
CU_pFailureRecord pFailure = pFailureList;
snprintf(result, 2048, "Suite [%s] Test [%s]", pSuite->pName, pTest->pName);
snprintf(result, sizeof(result), "Suite [%s] Test [%s]", pSuite->pName, pTest->pName);
if (pFailure) {
strncat(result, " failed:", strlen(" failed:"));
for (i = 1 ; (NULL != pFailure) ; pFailure = pFailure->pNext, i++) {
snprintf(buffer, 2048, "\n %d. %s:%u - %s", i,
snprintf(buffer, sizeof(buffer), "\n %d. %s:%u - %s", i,
(NULL != pFailure->strFileName) ? pFailure->strFileName : "",
pFailure->uiLineNumber,
(NULL != pFailure->strCondition) ? pFailure->strCondition : "");
......@@ -346,7 +346,7 @@ void bc_tester_uninit() {
}
CU_cleanup_registry();
/*add missing final newline*/
tester_printf(verbosity_info,"\n");
tester_printf(verbosity_info,"");
if( xml_enabled ){
/*create real xml file only if tester did not crash*/
......
......@@ -30,7 +30,6 @@
static FILE * log_file = NULL;
static OrtpLogFunc ortp_log_handler;
#ifdef ANDROID
......@@ -132,28 +131,35 @@ static void liblinphone_tester_qnx_log_handler(OrtpLogLevel lev, const char *fmt
#endif /* __QNX__ */
static void log_handler(int lev, const char *fmt, va_list args) {
#ifdef WIN32
vfprintf(lev == ORTP_ERROR ? stderr : stdout, fmt, args);
fprintf(lev == ORTP_ERROR ? stderr : stdout, "\n");
#else
va_list cap;
va_copy(cap,args);
#ifdef ANDROID
/* IMPORTANT: needed by liblinphone tester to retrieve suite list...*/
cunit_android_trace_handler(lev == ORTP_ERROR, fmt, args);
cunit_android_trace_handler(lev == ORTP_ERROR, fmt, cap);
#else
/* Otherwise, we must use stdio to avoid log formatting (for autocompletion etc.) */
vfprintf(lev == ORTP_ERROR ? stderr : stdout, fmt, args);
vfprintf(lev == ORTP_ERROR ? stderr : stdout, fmt, cap);
fprintf(lev == ORTP_ERROR ? stderr : stdout, "\n");
#endif
va_end(cap);
#endif
if (log_file){
ortp_set_log_file(log_file);
ortp_log_handler(lev, fmt, args);
ortp_logv_out(lev, fmt, args);
}
}
void liblinphone_tester_init(void) {
if (! log_file) {
#if defined(ANDROID)
linphone_core_set_log_handler(liblinphone_android_ortp_log_handler);
linphone_core_set_log_handler(liblinphone_android_ortp_log_handler);
#elif defined(__QNX__)
linphone_core_set_log_handler(liblinphone_tester_qnx_log_handler);
#else
linphone_core_set_log_handler(ortp_logv_out);
linphone_core_set_log_handler(liblinphone_tester_qnx_log_handler);
#endif
ortp_log_handler = ortp_get_log_handler();
}
bc_tester_init(log_handler, ORTP_MESSAGE, ORTP_ERROR);
liblinphone_tester_add_suites();
......@@ -202,6 +208,7 @@ int main (int argc, char *argv[])
return -2;
} else {
ms_message("Redirecting traces to file [%s]",argv[i]);
ortp_set_log_file(log_file);
}
} else if (strcmp(argv[i],"--domain")==0){
CHECK_ARG("--domain", ++i, argc);
......
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