]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-11455 #resolve add originate test for state handlers
authorSeven Du <dujinfang@gmail.com>
Fri, 12 Oct 2018 01:07:58 +0000 (09:07 +0800)
committerChris Rienzo <chris@signalwire.com>
Thu, 20 Dec 2018 15:18:21 +0000 (10:18 -0500)
configure.ac
tests/fst/.gitignore [new file with mode: 0644]
tests/fst/Makefile.am [new file with mode: 0644]
tests/fst/conf/freeswitch.xml [new file with mode: 0644]
tests/fst/originate_test.c [new file with mode: 0644]

index 377eea25ec3884cc72cd153c4d2f93bfa97ee302..8ca3d168908d44d0168278560a99e1deebfb9b1d 100644 (file)
@@ -1998,6 +1998,7 @@ AC_CONFIG_FILES([Makefile
                libs/xmlrpc-c/config.mk
                libs/xmlrpc-c/srcdir.mk
                libs/xmlrpc-c/stamp-h
+               tests/fst/Makefile
                scripts/gentls_cert])
 
 AM_CONDITIONAL(ISLINUX, [test `uname -s` = Linux])
diff --git a/tests/fst/.gitignore b/tests/fst/.gitignore
new file mode 100644 (file)
index 0000000..18574c0
--- /dev/null
@@ -0,0 +1,4 @@
+Makefile
+Makefile.in
+freeswitch.xml.fsxml
+originate_test
diff --git a/tests/fst/Makefile.am b/tests/fst/Makefile.am
new file mode 100644 (file)
index 0000000..db33a19
--- /dev/null
@@ -0,0 +1,8 @@
+include $(top_srcdir)/build/modmake.rulesam
+
+bin_PROGRAMS = originate_test
+AM_LDFLAGS  = -avoid-version -no-undefined $(SWITCH_AM_LDFLAGS) $(openssl_LIBS) $(FREESWITCH_LIBS) $(switch_builddir)/libfreeswitch.la $(CORE_LIBS) $(APR_LIBS)
+AM_CFLAGS   = $(SWITCH_AM_CPPFLAGS)
+AM_CPPFLAGS = $(SWITCH_AM_CPPFLAGS)
+
+TESTS = $(bin_PROGRAMS)
diff --git a/tests/fst/conf/freeswitch.xml b/tests/fst/conf/freeswitch.xml
new file mode 100644 (file)
index 0000000..2341258
--- /dev/null
@@ -0,0 +1,37 @@
+<?xml version="1.0"?>
+<document type="freeswitch/xml">
+  <section name="configuration" description="Various Configuration">
+    <configuration name="modules.conf" description="Modules">
+      <modules>
+        <load module="mod_console"/>
+        <load module="mod_loopback"/>
+      </modules>
+    </configuration>
+
+    <configuration name="console.conf" description="Console Logger">
+      <mappings>
+        <map name="all" value="console,debug,info,notice,warning,err,crit,alert"/>
+      </mappings>
+      <settings>
+        <param name="colorize" value="true"/>
+        <param name="loglevel" value="debug"/>
+      </settings>
+    </configuration>
+
+    <configuration name="timezones.conf" description="Timezones">
+      <timezones>
+          <zone name="GMT" value="GMT0" />
+      </timezones>
+    </configuration>
+  </section>
+
+  <section name="dialplan" description="Regex/XML Dialplan">
+    <context name="default">
+      <extension name="sample">
+        <condition>
+          <action application="info"/>
+        </condition>
+      </extension>
+    </context>
+  </section>
+</document>
diff --git a/tests/fst/originate_test.c b/tests/fst/originate_test.c
new file mode 100644 (file)
index 0000000..e7063b8
--- /dev/null
@@ -0,0 +1,139 @@
+/*
+ * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ * Copyright (C) 2005-2018, Anthony Minessale II <anthm@freeswitch.org>
+ *
+ * Version: MPL 1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ *
+ * The Initial Developer of the Original Code is
+ * Anthony Minessale II <anthm@freeswitch.org>
+ * Portions created by the Initial Developer are Copyright (C)
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Chris Rienzo <chris@signalwire.com>
+ * Seven Du <dujinfang@gmail.com>
+ *
+ *
+ * originate_test.c -- tests originate
+ *
+ */
+#include <switch.h>
+#include <stdlib.h>
+
+#include <test/switch_test.h>
+
+int reporting = 0;
+int destroy = 0;
+
+static switch_status_t my_on_reporting(switch_core_session_t *session)
+{
+       switch_assert(session);
+       reporting++;
+       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "session reporting %d\n", reporting);
+}
+
+static switch_status_t my_on_destroy(switch_core_session_t *session)
+{
+       switch_assert(session);
+       destroy++;
+       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "session destroy %d\n", destroy);
+}
+
+static switch_state_handler_table_t state_handlers = {
+       /*.on_init */ NULL,
+       /*.on_routing */ NULL,
+       /*.on_execute */ NULL,
+       /*.on_hangup */ NULL,
+       /*.on_exchange_media */ NULL,
+       /*.on_soft_execute */ NULL,
+       /*.on_consume_media */ NULL,
+       /*.on_hibernate */ NULL,
+       /*.on_reset */ NULL,
+       /*.on_park */ NULL,
+       /*.on_reporting */ my_on_reporting,
+    /*.on_destroy */ my_on_destroy,
+    SSH_FLAG_STICKY
+};
+
+FST_CORE_BEGIN("./conf")
+{
+       FST_SUITE_BEGIN(originate)
+       {
+               FST_SETUP_BEGIN()
+               {
+                       fst_requires_module("mod_loopback");
+               }
+               FST_SETUP_END()
+
+               FST_TEARDOWN_BEGIN()
+               {
+               }
+               FST_TEARDOWN_END()
+
+               FST_TEST_BEGIN(originate_test_early_state_handler)
+               {
+                       switch_core_session_t *session = NULL;
+                       switch_channel_t *channel = NULL;
+                       switch_status_t status;
+                       switch_call_cause_t cause;
+
+                       status = switch_ivr_originate(NULL, &session, &cause, "null/+15553334444", 2, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL);
+                       fst_requires(session);
+                       fst_check(status == SWITCH_STATUS_SUCCESS);
+
+                       channel = switch_core_session_get_channel(session);
+                       fst_requires(channel);
+
+                       switch_channel_add_state_handler(channel, &state_handlers);
+                       switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
+                       fst_check(!switch_channel_ready(channel));
+
+                       switch_core_session_rwunlock(session);
+
+                       switch_sleep(1000000);
+                       fst_check(reporting == 1);
+                       fst_check(destroy == 1);
+               }
+               FST_TEST_END()
+
+               FST_TEST_BEGIN(originate_test_late_state_handler)
+               {
+                       switch_core_session_t *session = NULL;
+                       switch_channel_t *channel = NULL;
+                       switch_status_t status;
+                       switch_call_cause_t cause;
+
+                       status = switch_ivr_originate(NULL, &session, &cause, "null/+15553334444", 2, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL);
+                       fst_requires(session);
+                       fst_check(status == SWITCH_STATUS_SUCCESS);
+
+                       channel = switch_core_session_get_channel(session);
+                       fst_requires(channel);
+
+                       switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
+                       switch_sleep(1000000);
+                       switch_channel_add_state_handler(channel, &state_handlers);
+
+                       switch_core_session_rwunlock(session);
+
+                       switch_sleep(1000000);
+                       fst_check(reporting == 1);
+                       fst_check(destroy == 2);
+               }
+               FST_TEST_END()
+       }
+       FST_SUITE_END()
+}
+FST_CORE_END()