From 24ff01518fb678e350f3621f4231e72b50b5a5cd Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Sat, 23 Oct 2021 01:24:17 +0300 Subject: [PATCH] [Unit-tests] Fix build of various unit-tests. --- tests/unit/switch_core_session.c | 3 ++- tests/unit/switch_ivr_async.c | 13 +++++++++---- tests/unit/switch_ivr_play_say.c | 14 ++++++-------- tests/unit/switch_log.c | 8 ++++---- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/tests/unit/switch_core_session.c b/tests/unit/switch_core_session.c index 57beea3bee..f5f6f51ba7 100644 --- a/tests/unit/switch_core_session.c +++ b/tests/unit/switch_core_session.c @@ -48,10 +48,11 @@ FST_CORE_BEGIN("./conf") FST_SESSION_BEGIN(session_external_id) { + switch_core_session_t *session; fst_check(switch_core_session_set_external_id(fst_session, switch_core_session_get_uuid(fst_session)) == SWITCH_STATUS_SUCCESS); fst_check_string_equals(switch_core_session_get_external_id(fst_session), switch_core_session_get_uuid(fst_session)); fst_check(switch_core_session_set_external_id(fst_session, "foo") == SWITCH_STATUS_SUCCESS); - switch_core_session_t *session = switch_core_session_locate("foo"); + session = switch_core_session_locate("foo"); fst_requires(session); fst_check_string_equals(switch_core_session_get_uuid(session), switch_core_session_get_uuid(fst_session)); fst_check_string_equals(switch_core_session_get_external_id(session), "foo"); diff --git a/tests/unit/switch_ivr_async.c b/tests/unit/switch_ivr_async.c index dedf026dd5..7b6a5e86c8 100644 --- a/tests/unit/switch_ivr_async.c +++ b/tests/unit/switch_ivr_async.c @@ -43,6 +43,7 @@ static switch_status_t partial_play_and_collect_input_callback(switch_core_sessi if (event->event_id == SWITCH_EVENT_DETECTED_SPEECH) { const char *speech_type = switch_event_get_header(event, "Speech-Type"); + char *body; if (zstr(speech_type) || strcmp(speech_type, "detected-partial-speech")) { return status; @@ -51,7 +52,7 @@ static switch_status_t partial_play_and_collect_input_callback(switch_core_sessi (*count)++; switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "partial events count: %d\n", *count); - char *body = switch_event_get_body(event); + body = switch_event_get_body(event); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "body=[%s]\n", body); } } else if (input_type == SWITCH_INPUT_TYPE_DTMF) { @@ -67,6 +68,9 @@ FST_CORE_BEGIN("./conf_async") { FST_SETUP_BEGIN() { + if (0) { + partial_play_and_collect_input_callback(NULL, NULL, 0, NULL, 0); + } fst_requires_module("mod_tone_stream"); fst_requires_module("mod_sndfile"); fst_requires_module("mod_dptools"); @@ -82,7 +86,8 @@ FST_CORE_BEGIN("./conf_async") FST_SESSION_BEGIN(session_record_pause) { const char *record_filename = switch_core_session_sprintf(fst_session, "%s%s%s.wav", SWITCH_GLOBAL_dirs.temp_dir, SWITCH_PATH_SEPARATOR, switch_core_session_get_uuid(fst_session)); - + const char *duration_ms_str; + int duration_ms; switch_status_t status; status = switch_ivr_record_session_event(fst_session, record_filename, 0, NULL, NULL); fst_xcheck(status == SWITCH_STATUS_SUCCESS, "Expect switch_ivr_record_session() to return SWITCH_STATUS_SUCCESS"); @@ -110,9 +115,9 @@ FST_CORE_BEGIN("./conf_async") unlink(record_filename); - const char *duration_ms_str = switch_channel_get_variable(fst_channel, "record_ms"); + duration_ms_str = switch_channel_get_variable(fst_channel, "record_ms"); fst_requires(duration_ms_str != NULL); - int duration_ms = atoi(duration_ms_str); + duration_ms = atoi(duration_ms_str); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fst_session), SWITCH_LOG_NOTICE, "Recording duration is %s ms\n", duration_ms_str); fst_xcheck(duration_ms > 3500 && duration_ms < 3700, "Expect recording to be between 3500 and 3700 ms"); } diff --git a/tests/unit/switch_ivr_play_say.c b/tests/unit/switch_ivr_play_say.c index 3e2ded6aff..c23a2d3332 100644 --- a/tests/unit/switch_ivr_play_say.c +++ b/tests/unit/switch_ivr_play_say.c @@ -36,10 +36,10 @@ static void on_record_start(switch_event_t *event) { char *str = NULL; + const char *uuid = switch_event_get_header(event, "Unique-ID"); switch_event_serialize(event, &str, SWITCH_FALSE); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s", str); switch_safe_free(str); - const char *uuid = switch_event_get_header(event, "Unique-ID"); if (uuid) { switch_core_session_t *session = switch_core_session_locate(uuid); if (session) { @@ -56,10 +56,10 @@ static void on_record_start(switch_event_t *event) static void on_record_stop(switch_event_t *event) { char *str = NULL; + const char *uuid = switch_event_get_header(event, "Unique-ID"); switch_event_serialize(event, &str, SWITCH_FALSE); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s", str); switch_safe_free(str); - const char *uuid = switch_event_get_header(event, "Unique-ID"); if (uuid) { switch_core_session_t *session = switch_core_session_locate(uuid); if (session) { @@ -83,6 +83,7 @@ static switch_status_t partial_play_and_collect_input_callback(switch_core_sessi if (event->event_id == SWITCH_EVENT_DETECTED_SPEECH) { const char *speech_type = switch_event_get_header(event, "Speech-Type"); + char *body = switch_event_get_body(event); if (zstr(speech_type) || strcmp(speech_type, "detected-partial-speech")) { return status; @@ -90,8 +91,6 @@ static switch_status_t partial_play_and_collect_input_callback(switch_core_sessi (*count)++; switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "partial events count: %d\n", *count); - - char *body = switch_event_get_body(event); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "body=[%s]\n", body); } } else if (input_type == SWITCH_INPUT_TYPE_DTMF) { @@ -354,6 +353,9 @@ FST_CORE_BEGIN("./conf_playsay") char *speech_grammar_args = switch_core_session_sprintf(fst_session, "{start-input-timers=false,no-input-timeout=%d,vad-silence-ms=%d,speech-timeout=%d,language=en-US,partial=true}default", no_input_timeout, speech_complete_timeout, speech_recognition_timeout); switch_status_t status; + switch_input_args_t collect_input_args = { 0 }; + switch_input_args_t *args = NULL; + int count = 0; switch_ivr_displace_session(fst_session, "file_string://silence_stream://500,0!tone_stream://%%(2000,0,350,440)", 0, "r"); terminator_collected = 0; @@ -377,10 +379,6 @@ FST_CORE_BEGIN("./conf_playsay") if (recognition_result) cJSON_Delete(recognition_result); recognition_result = NULL; - switch_input_args_t collect_input_args = { 0 }; - switch_input_args_t *args = NULL; - int count = 0; - args = &collect_input_args; args->input_callback = partial_play_and_collect_input_callback; args->buf = &count; diff --git a/tests/unit/switch_log.c b/tests/unit/switch_log.c index a56612fc28..ee4783f283 100644 --- a/tests/unit/switch_log.c +++ b/tests/unit/switch_log.c @@ -90,12 +90,12 @@ static char *wait_for_log(switch_interval_time_t timeout_ms) FST_CORE_BEGIN("./conf") { - switch_core_new_memory_pool(&pool); - switch_mutex_init(&mutex, SWITCH_MUTEX_NESTED, pool); - switch_thread_cond_create(&cond, pool); - FST_SUITE_BEGIN(switch_log) { + switch_core_new_memory_pool(&pool); + switch_mutex_init(&mutex, SWITCH_MUTEX_NESTED, pool); + switch_thread_cond_create(&cond, pool); + FST_SETUP_BEGIN() { json_format.custom_field_prefix = NULL;