From 2a54e08019b6bbe48e5f0836f61ea0186fea4271 Mon Sep 17 00:00:00 2001 From: Seven Du Date: Mon, 11 Nov 2019 23:35:29 +0800 Subject: [PATCH] [core, mod_loopback] Add test case for group confirm over loopback endpoints --- src/mod/endpoints/mod_loopback/mod_loopback.c | 1 + tests/unit/conf/freeswitch.xml | 8 +++ tests/unit/switch_ivr_originate.c | 49 +++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/src/mod/endpoints/mod_loopback/mod_loopback.c b/src/mod/endpoints/mod_loopback/mod_loopback.c index 83f6e0a1b5..67cfd8c13f 100644 --- a/src/mod/endpoints/mod_loopback/mod_loopback.c +++ b/src/mod/endpoints/mod_loopback/mod_loopback.c @@ -1521,6 +1521,7 @@ static switch_status_t null_channel_read_frame(switch_core_session_t *session, s samples = tech_pvt->read_codec.implementation->samples_per_packet; tech_pvt->read_frame.codec = &tech_pvt->read_codec; tech_pvt->read_frame.datalen = samples * sizeof(int16_t); + tech_pvt->read_frame.buflen = samples * sizeof(int16_t); tech_pvt->read_frame.samples = samples; tech_pvt->read_frame.data = tech_pvt->null_buf; switch_generate_sln_silence((int16_t *)tech_pvt->read_frame.data, tech_pvt->read_frame.samples, tech_pvt->read_codec.implementation->number_of_channels, 10000); diff --git a/tests/unit/conf/freeswitch.xml b/tests/unit/conf/freeswitch.xml index cd9ba2131c..90600975e4 100644 --- a/tests/unit/conf/freeswitch.xml +++ b/tests/unit/conf/freeswitch.xml @@ -14,6 +14,8 @@ + + @@ -38,6 +40,12 @@
+ + + + + + diff --git a/tests/unit/switch_ivr_originate.c b/tests/unit/switch_ivr_originate.c index 701f1bfc44..983f26d0a7 100644 --- a/tests/unit/switch_ivr_originate.c +++ b/tests/unit/switch_ivr_originate.c @@ -71,6 +71,16 @@ static switch_state_handler_table_t state_handlers = { SSH_FLAG_STICKY }; +static int application_hit = 0; + +static void loopback_group_confirm_event_handler(switch_event_t *event) // general event handler +{ + if (event->event_id == SWITCH_EVENT_CHANNEL_APPLICATION) { + application_hit++; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "application_hit = %d\n", application_hit); + } +} + FST_CORE_BEGIN("./conf") { FST_SUITE_BEGIN(switch_ivr_originate) @@ -78,6 +88,7 @@ FST_CORE_BEGIN("./conf") FST_SETUP_BEGIN() { fst_requires_module("mod_loopback"); + application_hit = 0; } FST_SETUP_END() @@ -437,6 +448,44 @@ FST_CORE_BEGIN("./conf") switch_core_session_rwunlock(session); } FST_TEST_END() + + FST_TEST_BEGIN(originate_test_group_confirm_loopback_endpoint_originate) + { + switch_core_session_t *session = NULL; + switch_channel_t *channel = NULL; + switch_status_t status; + switch_call_cause_t cause; + const char *dialstring = "[group_confirm_key=exec,group_confirm_file='event a=1']loopback/loopback"; + + switch_event_bind("test", SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, loopback_group_confirm_event_handler, NULL); + status = switch_ivr_originate(NULL, &session, &cause, dialstring, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL); + fst_requires(status == SWITCH_STATUS_SUCCESS); + fst_requires(session); + switch_yield(1000000); + switch_channel_hangup(switch_core_session_get_channel(session), SWITCH_CAUSE_NORMAL_CLEARING); + switch_yield(1000000); + switch_core_session_rwunlock(session); + switch_event_unbind_callback(loopback_group_confirm_event_handler); + fst_check(application_hit == 1); + } + FST_TEST_END() + + FST_SESSION_BEGIN(originate_test_group_confirm_loopback_endpoint_bridge) + { + switch_core_session_t *session = NULL; + switch_channel_t *channel = NULL; + switch_status_t status; + switch_call_cause_t cause; + const char *dialstring = "[group_confirm_key=exec,group_confirm_file='event a=1']loopback/loopback"; + + switch_event_bind("test", SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, loopback_group_confirm_event_handler, NULL); + + switch_core_session_execute_application(fst_session, "bridge", dialstring); + switch_yield(2000000); + switch_channel_hangup(fst_channel, SWITCH_CAUSE_NORMAL_CLEARING); + fst_check(application_hit == 1); + } + FST_SESSION_END() } FST_SUITE_END() } -- 2.47.2