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

parent c33ad7af
......@@ -38,7 +38,6 @@ extern const char *auth_domain;
static const char *belle_sip_tester_root_ca_path = NULL;
static FILE * log_file = NULL;
static belle_sip_log_function_t belle_sip_log_handler;
static belle_sip_object_pool_t *pool;
......@@ -76,19 +75,23 @@ void belle_sip_tester_set_root_ca_path(const char *root_ca_path) {
static void log_handler(int lev, const char *fmt, va_list args) {
#ifdef WIN32
/* We must use stdio to avoid log formatting (for autocompletion etc.) */
vfprintf(lev == BELLE_SIP_LOG_ERROR ? stderr : stdout, fmt, args);
fprintf(lev == BELLE_SIP_LOG_ERROR ? stderr : stdout, "\n");
#else
va_list cap;
va_copy(cap,args);
vfprintf(lev == BELLE_SIP_LOG_ERROR ? stderr : stdout, fmt, args);
fprintf(lev == BELLE_SIP_LOG_ERROR ? stderr : stdout, "\n");
va_end(cap);
#endif
if (log_file){
belle_sip_set_log_file(log_file);
belle_sip_log_handler(lev, fmt, args);
belle_sip_logv(lev, fmt, args);
}
}
void belle_sip_tester_init() {
belle_sip_log_handler = belle_sip_get_log_handler();
belle_sip_set_log_handler(belle_sip_logv_out);
bc_tester_init(log_handler, BELLE_SIP_LOG_MESSAGE, BELLE_SIP_LOG_ERROR);
belle_sip_init_sockets();
belle_sip_object_enable_marshal_check(TRUE);
......@@ -149,6 +152,7 @@ int main (int argc, char *argv[]) {
return -2;
} else {
belle_sip_message("Redirecting traces to file [%s]",argv[i]);
belle_sip_set_log_file(log_file);
}
} else if (strcmp(argv[i],"--domain")==0){
CHECK_ARG("--domain", ++i, argc);
......
......@@ -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*/
......
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