]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[core, mod_loopback] Add test case for group confirm over loopback endpoints
authorSeven Du <dujinfang@gmail.com>
Mon, 11 Nov 2019 15:35:29 +0000 (23:35 +0800)
committerAndrey Volk <andywolk@gmail.com>
Thu, 7 May 2020 21:12:17 +0000 (01:12 +0400)
src/mod/endpoints/mod_loopback/mod_loopback.c
tests/unit/conf/freeswitch.xml
tests/unit/switch_ivr_originate.c

index 83f6e0a1b5884c3f69cc9412dd96bb2dacf22c7a..67cfd8c13f64e7829bb6cb6d7b5a17cabe782935 100644 (file)
@@ -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);
index cd9ba2131c2525f34875878b124fc3c82d4a6c7d..90600975e459e9d4effdec4e3affb7ea18b57f6d 100644 (file)
@@ -14,6 +14,8 @@
                <load module="mod_tone_stream"/>
                <load module="mod_dptools"/>
                <load module="mod_sndfile"/>
+               <load module="mod_dialplan_xml"/>
+               <load module="mod_sndfile"/>
       </modules>
     </configuration>
 
 
   <section name="dialplan" description="Regex/XML Dialplan">
     <context name="default">
+      <extension name="loopback">
+        <condition field="destination_number" expression="^loopback$">
+          <action application="bridge" data="null/+1234"/>
+        </condition>
+      </extension>
+
       <extension name="sample">
         <condition>
           <action application="info"/>
index 701f1bfc449bf445c78a84124cc44a540049cf80..983f26d0a70f37ff467ecae4c93341051bcc0592 100644 (file)
@@ -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()
 }