RTS API Documentation  1.10.11
Macros | Functions | Variables
switch_test.h File Reference
#include <switch.h>
#include <test/switch_fct.h>
+ Include dependency graph for switch_test.h:

Go to the source code of this file.

Macros

#define fst_getenv(env, default_value)   char *env = fst_getenv_default(#env, (char *)default_value, SWITCH_FALSE);
 
#define fst_getenv_required(env)   char *env = fst_getenv_default(#env, NULL, SWITCH_TRUE);
 
#define SWITCH_TEST_BASE_DIR_OVERRIDE   "."
 
#define fst_session_park(session)
 
#define fst_requires   fct_req
 
#define fst_requires_module(modname)   fct_req(switch_loadable_module_exists(modname) == SWITCH_STATUS_SUCCESS)
 
#define fst_check   fct_chk
 
#define fst_check_int_equals   fct_chk_eq_int
 
#define fst_check_string_equals   fct_chk_eq_str
 
#define fst_check_string_not_equals   fct_chk_neq_str
 
#define fst_check_string_starts_with   fct_chk_startswith_str
 
#define fst_check_string_ends_with   fct_chk_endswith_str
 
#define fst_check_string_has   fct_chk_incl_str
 
#define fst_check_string_does_not_have   fct_chk_excl_str
 
#define fst_time_mark()   fst_time_start = switch_time_now();
 
#define fst_xcheck(expr, error_msg)   (fct_xchk(expr, "%s", error_msg))
 
#define fst_fail(error_msg)   (fct_xchk(0, "%s", error_msg))
 
#define fst_check_duration(duration_ms, precision_ms)
 
#define fst_check_int_range(actual, expected, precision)
 
#define fst_check_double_range(actual, expected, precision)
 
#define FST_BEGIN()
 
#define FST_END()
 
#define FST_CORE_EX_BEGIN(confdir, flags)
 
#define FST_CORE_END()
 
#define FST_CORE_BEGIN(confdir)   FST_CORE_EX_BEGIN(confdir, 0)
 
#define FST_CORE_DB_BEGIN(confdir)   FST_CORE_EX_BEGIN(confdir, SCF_USE_SQL)
 
#define FST_MINCORE_BEGIN(confdir)
 
#define FST_MINCORE_END   FST_CORE_END
 
#define FST_MODULE_BEGIN(modname, suite)
 
#define FST_MODULE_END()
 
#define FST_SUITE_BEGIN(suite)
 
#define FST_SUITE_END   FCT_FIXTURE_SUITE_END
 
#define FST_SETUP_BEGIN()
 
#define FST_SETUP_END   FCT_SETUP_END
 
#define FST_TEARDOWN_BEGIN()
 
#define FST_TEARDOWN_END   FCT_TEARDOWN_END
 
#define FST_TEST_BEGIN(name)
 
#define FST_TEST_END
 
#define FST_SESSION_BEGIN_RATE_VIDEO(name, rate, video_codec)
 
#define FST_SESSION_BEGIN(name)   FST_SESSION_BEGIN_RATE(name, 8000)
 
#define FST_SESSION_BEGIN_RATE(name, rate)   FST_SESSION_BEGIN_RATE_VIDEO(name, rate, "")
 
#define FST_SESSION_END()
 
#define fst_test_core_asr_open(recognizer)
 
#define fst_test_core_asr(grammar, input_filename)
 
#define fst_test_core_asr_pause()
 
#define fst_test_core_asr_resume()
 
#define fst_test_core_asr_close()
 
#define fst_play_and_detect_speech_test_begin()
 
#define fst_play_and_detect_speech_app_test(recognizer, grammar, prompt_filename, input_filename)
 
#define fst_play_and_detect_speech_test(recognizer, grammar, prompt_filename, input_filename, input_args)
 
#define fst_play_and_detect_speech_test_end()   }
 
#define fst_check_extension_apps(expected, extension)
 
#define fst_sched_recv_dtmf(when, digits)
 
#define fst_xml_start()
 
#define fst_xml_open_tag(tag_name)
 
#define fst_xml_attr(attr)   if (!zstr(attr)) fst_xml_stream.write_function(&fst_xml_stream, " %s=\"%s\"", #attr, attr);
 
#define fst_xml_close_tag(tag_name)
 
#define fst_xml_body(body)
 
#define fst_xml_end()   switch_xml_parse_str_dynamic((char *)fst_xml_stream.data, SWITCH_FALSE);
 
#define fst_parse_json_file(varname, file)
 

Functions

static char * fst_getenv_default (const char *env, char *default_value, switch_bool_t required)
 
static switch_status_t fst_init_core_and_modload (const char *confdir, const char *basedir, int minimal, switch_core_flag_t flags)
 

Variables

int fst_tag_children = 0
 
int fst_tag_body = 0
 

Macro Definition Documentation

◆ FST_BEGIN

#define FST_BEGIN ( )
Value:
{ \
int fst_core = 0; \
switch_time_t fst_time_start = 0; \
switch_timer_t fst_timer = { 0 }; \
switch_memory_pool_t *fst_pool = NULL; \
int fst_timer_started = 0; \
fst_getenv_default("FST_SUPPRESS_UNUSED_STATIC_WARNING", NULL, SWITCH_FALSE); \
if (fst_core) { \
fst_init_core_and_modload(NULL, NULL, 0, 0); /* shuts up compiler */ \
} \
{ \
#define FCT_BGN()
Definition: switch_fct.h:3318

Run test without loading FS core

Definition at line 256 of file switch_test.h.

◆ fst_check

#define fst_check   fct_chk

test boolean expression - continue test execution on failure

Definition at line 159 of file switch_test.h.

◆ fst_check_double_range

#define fst_check_double_range (   actual,
  expected,
  precision 
)
Value:
fabs((actual - expected)) <= precision, \
"fst_check_double_range: %f != %f +/- %f", \
(actual), \
(expected), \
(precision) \
)
#define fct_xchk
Definition: switch_fct.h:3643

Check if double-precision number is in range

Definition at line 244 of file switch_test.h.

◆ fst_check_duration

#define fst_check_duration (   duration_ms,
  precision_ms 
)
Value:
{ \
int actual_duration_ms = (int)((switch_time_now() - fst_time_start) / 1000); \
fct_xchk( \
abs((actual_duration_ms - duration_ms)) <= precision_ms, \
"fst_check_duration: %d != %d +/- %d", \
(actual_duration_ms), \
(duration_ms), \
(precision_ms) \
); \
}
switch_time_t switch_time_now(void)
Definition: switch_apr.c:325

Check duration relative to test start, last marked time, or last check.

Definition at line 217 of file switch_test.h.

◆ fst_check_extension_apps

#define fst_check_extension_apps (   expected,
  extension 
)
Value:
{ \
fst_xcheck(extension != NULL, "Missing extension\n"); \
if (extension) { \
int i; \
switch_caller_application_t *cur_app = extension->applications; \
for (i = 0; ; i += 2, cur_app = cur_app->next) { \
int cur_app_num = i / 2 + 1; \
if (!expected[i]) { \
if (cur_app != NULL) { \
fst_fail(switch_core_sprintf(fst_pool, "Unexpected application #%d \"%s\"\n", cur_app_num, cur_app->application_name)); \
} \
break; \
} \
fst_xcheck(cur_app != NULL, switch_core_sprintf(fst_pool, "Extension application #%d \"%s\" is missing", cur_app_num, expected[i])); \
if (!cur_app) { \
break; \
} \
fst_xcheck(cur_app->application_name && !strcmp(expected[i], cur_app->application_name), switch_core_sprintf(fst_pool, "Expected application #%d name is \"%s\", but is \"%s\"\n", cur_app_num, expected[i], cur_app->application_name)); \
fst_xcheck(cur_app->application_data && !strcmp(expected[i + 1], cur_app->application_data), switch_core_sprintf(fst_pool, "Expected application #%d %s data is \"%s\", but is \"%s\"\n", cur_app_num, expected[i], expected[i + 1], cur_app->application_data)); \
} \
} \
}
char * switch_core_sprintf(_In_ switch_memory_pool_t *pool, _In_z_ _Printf_format_string_ const char *fmt,...)
printf-style style printing routine. The data is output to a string allocated from the pool ...

Compare extension dialplan apps and args with expected apps and args

Parameters
expectedNULL terminated string array of app arg and names. const char *expected[] = { "playback", "https://example.com/foo.wav", "park", "", NULL };
extensionthe switch_caller_extension_t to check

Definition at line 780 of file switch_test.h.

◆ fst_check_int_equals

#define fst_check_int_equals   fct_chk_eq_int

test integers for equality - continue test execution on failure

Definition at line 164 of file switch_test.h.

◆ fst_check_int_range

#define fst_check_int_range (   actual,
  expected,
  precision 
)
Value:
abs((actual - expected)) <= precision, \
"fst_check_int_range: %d != %d +/- %d", \
(actual), \
(expected), \
(precision) \
)
#define fct_xchk
Definition: switch_fct.h:3643

Check if integer is in range

Definition at line 232 of file switch_test.h.

◆ fst_check_string_does_not_have

#define fst_check_string_does_not_have   fct_chk_excl_str

Test string for exclusion of substring

Definition at line 194 of file switch_test.h.

◆ fst_check_string_ends_with

#define fst_check_string_ends_with   fct_chk_endswith_str

Test string for matching suffix

Definition at line 184 of file switch_test.h.

◆ fst_check_string_equals

#define fst_check_string_equals   fct_chk_eq_str

test string for equality - continue test execution on failure

Definition at line 169 of file switch_test.h.

◆ fst_check_string_has

#define fst_check_string_has   fct_chk_incl_str

Test string for substring

Definition at line 189 of file switch_test.h.

◆ fst_check_string_not_equals

#define fst_check_string_not_equals   fct_chk_neq_str

test string for inequality - continue test execution on failure

Definition at line 174 of file switch_test.h.

◆ fst_check_string_starts_with

#define fst_check_string_starts_with   fct_chk_startswith_str

Test string for matching prefix

Definition at line 179 of file switch_test.h.

◆ FST_CORE_BEGIN

#define FST_CORE_BEGIN (   confdir)    FST_CORE_EX_BEGIN(confdir, 0)

Definition at line 315 of file switch_test.h.

◆ FST_CORE_DB_BEGIN

#define FST_CORE_DB_BEGIN (   confdir)    FST_CORE_EX_BEGIN(confdir, SCF_USE_SQL)

Definition at line 316 of file switch_test.h.

◆ FST_CORE_END

#define FST_CORE_END ( )
Value:
} \
if (fst_time_start) { \
/* shut up compiler */ \
fst_time_start = 0; \
} \
} \
FCT_END()
switch_status_t switch_core_destroy(void)
Destroy the core.
Definition: switch_core.c:3020

Define the end of a freeswitch core test driver.

Definition at line 305 of file switch_test.h.

◆ FST_CORE_EX_BEGIN

#define FST_CORE_EX_BEGIN (   confdir,
  flags 
)
Value:
{ \
int fst_core = 0; \
switch_time_t fst_time_start = 0; \
switch_timer_t fst_timer = { 0 }; \
switch_memory_pool_t *fst_pool = NULL; \
int fst_timer_started = 0; \
fst_getenv_default("FST_SUPPRESS_UNUSED_STATIC_WARNING", NULL, SWITCH_FALSE); \
fst_core = 2; \
} else { \
fprintf(stderr, "Failed to load FS core\n"); \
exit(1); \
} \
{
#define FCT_BGN()
Definition: switch_fct.h:3318
static switch_status_t fst_init_core_and_modload(const char *confdir, const char *basedir, int minimal, switch_core_flag_t flags)
Definition: switch_test.h:69
unsigned int flags
Definition: switch_speex.c:106

Define the beginning of a freeswitch core test driver. Only one per test application allowed.

Parameters
confdirdirectory containing freeswitch.xml configuration

Definition at line 284 of file switch_test.h.

◆ FST_END

#define FST_END ( )
Value:
} \
if (fst_time_start) { \
/* shut up compiler */ \
fst_time_start = 0; \
} \
} \
FCT_END()

Definition at line 271 of file switch_test.h.

◆ fst_fail

#define fst_fail (   error_msg)    (fct_xchk(0, "%s", error_msg))

Fail a test

Definition at line 211 of file switch_test.h.

◆ fst_getenv

#define fst_getenv (   env,
  default_value 
)    char *env = fst_getenv_default(#env, (char *)default_value, SWITCH_FALSE);

Get environment variable and save to var

Definition at line 57 of file switch_test.h.

◆ fst_getenv_required

#define fst_getenv_required (   env)    char *env = fst_getenv_default(#env, NULL, SWITCH_TRUE);

Get mandatory environment variable and save to var. Exit with error if missing.

Definition at line 63 of file switch_test.h.

◆ FST_MINCORE_BEGIN

#define FST_MINCORE_BEGIN (   confdir)
Value:
{ \
int fst_core = 0; \
switch_time_t fst_time_start = 0; \
switch_timer_t fst_timer = { 0 }; \
switch_memory_pool_t *fst_pool = NULL; \
int fst_timer_started = 0; \
fst_getenv_default("FST_SUPPRESS_UNUSED_STATIC_WARNING", NULL, SWITCH_FALSE); \
if (fst_init_core_and_modload(confdir, NULL, 1, 0 | SCF_LOG_DISABLE) == SWITCH_STATUS_SUCCESS) { /* minimal load */ \
fst_core = 1; \
} else { \
fprintf(stderr, "Failed to load FS core\n"); \
exit(1); \
} \
{
#define FCT_BGN()
Definition: switch_fct.h:3318
static switch_status_t fst_init_core_and_modload(const char *confdir, const char *basedir, int minimal, switch_core_flag_t flags)
Definition: switch_test.h:69

Minimal FS core load

Definition at line 321 of file switch_test.h.

◆ FST_MINCORE_END

#define FST_MINCORE_END   FST_CORE_END

Definition at line 338 of file switch_test.h.

◆ FST_MODULE_BEGIN

#define FST_MODULE_BEGIN (   modname,
  suite 
)
Value:
{ \
const char *fst_test_module = #modname; \
if (fst_core && !zstr(fst_test_module)) { \
const char *err; \
char path[1024]; \
sprintf(path, "%s%s%s", SWITCH_TEST_BASE_DIR_OVERRIDE, SWITCH_PATH_SEPARATOR, "../.libs/"); \
switch_loadable_module_load_module((char *)path, (char *)fst_test_module, SWITCH_TRUE, &err); \
} \
FCT_FIXTURE_SUITE_BGN(suite);
#define zstr(x)
Definition: switch_utils.h:314
#define SWITCH_TEST_BASE_DIR_OVERRIDE
#define SWITCH_PATH_SEPARATOR
Definition: switch_types.h:124
const char *const const char *const path

Define the beginning of a FreeSWITCH module test suite. Loads the module for test.

Parameters
modnamename of module to load.
suitethe name of this test suite

Definition at line 355 of file switch_test.h.

◆ FST_MODULE_END

#define FST_MODULE_END ( )
Value:
if (!zstr(fst_test_module) && switch_loadable_module_exists(fst_test_module) == SWITCH_STATUS_SUCCESS) { \
const char *err; \
char path[1024]; \
sprintf(path, "%s%s%s", SWITCH_TEST_BASE_DIR_OVERRIDE, SWITCH_PATH_SEPARATOR, "../.libs/"); \
switch_loadable_module_unload_module((char*)path, (char *)fst_test_module, SWITCH_FALSE, &err); \
} \
}
#define FCT_FIXTURE_SUITE_END()
Definition: switch_fct.h:3418
#define zstr(x)
Definition: switch_utils.h:314
#define SWITCH_TEST_BASE_DIR_OVERRIDE
#define SWITCH_PATH_SEPARATOR
Definition: switch_types.h:124
switch_status_t switch_loadable_module_exists(const char *mod)
Check if a module is loaded.
const char *const const char *const path

Define the end of a FreeSWITCH module test suite.

Definition at line 379 of file switch_test.h.

◆ fst_parse_json_file

#define fst_parse_json_file (   varname,
  file 
)
Value:
cJSON *varname = NULL; \
{ \
char *buf; \
struct stat s; \
int size; \
int fd = open(file, O_RDONLY); \
fst_requires(fd >= 0); \
fstat(fd, &s); \
switch_zmalloc(buf, s.st_size + 1); \
fst_requires(buf); \
size = read(fd, buf, s.st_size); \
fst_requires(size == s.st_size); \
close(fd); \
varname = cJSON_Parse(buf); \
free(buf); \
fst_requires(varname); \
}
switch_byte_t switch_byte_t * buf

Parse JSON file and save to varname

Test Requires: JSON file can be opened and parsed

Test Output: varname points at cJSON object

Parameters
varnamename of var to store the resulting cJSON object
filename of file to parse

Definition at line 874 of file switch_test.h.

◆ fst_play_and_detect_speech_app_test

#define fst_play_and_detect_speech_app_test (   recognizer,
  grammar,
  prompt_filename,
  input_filename 
)
Value:
{ \
char *args = NULL; \
fst_requires(fst_core > 1); \
fst_requires_module("mod_dptools"); \
switch_channel_set_variable(fst_channel, "detect_speech_result", ""); \
fst_requires(switch_ivr_displace_session(fst_session, input_filename, 0, "mrf") == SWITCH_STATUS_SUCCESS); \
args = switch_core_session_sprintf(fst_session, "%s detect:%s %s", prompt_filename, recognizer, grammar); \
fst_requires(switch_core_session_execute_application(fst_session, "play_and_detect_speech", args) == SWITCH_STATUS_SUCCESS); \
fst_asr_result = switch_channel_get_variable(fst_channel, "detect_speech_result"); \
fst_check(fst_asr_result != NULL); \
}
char * switch_core_session_sprintf(_In_ switch_core_session_t *session, _In_z_ _Printf_format_string_ const char *fmt,...)
printf-style style printing routine. The data is output to a string allocated from the session ...
#define switch_core_session_execute_application(_a, _b, _c)
Execute an application on a session.
Definition: switch_core.h:1129
#define switch_channel_get_variable(_c, _v)
switch_status_t switch_ivr_displace_session(switch_core_session_t *session, const char *file, uint32_t limit, const char *flags)
displace the media for a session with the audio from a file

Use play_and_detect_speech APP to test recognizer

Test Requires: switch_ivr_displace_session(input_filename) == SWITCH_STATUS_SUCCESS switch_core_session_execute_application(play_and_detect_speech) == SWITCH_STATUS_SUCCESS mod_dptools is loaded

Test Checks: fst_asr_result != NULL after recognition completes

Test Output: fst_asr_result has the result from detect_speech_result channel variable.

Parameters
recognizername of recognizer
grammarrecognizer grammar
prompt_filenamename of prompt to play
input_filenamename of file containing input audio for the recognizer

Definition at line 726 of file switch_test.h.

◆ fst_play_and_detect_speech_test

#define fst_play_and_detect_speech_test (   recognizer,
  grammar,
  prompt_filename,
  input_filename,
  input_args 
)
Value:
{ \
char *args = NULL; \
fst_asr_result = NULL; \
fst_requires(fst_core > 1); \
fst_requires(switch_ivr_displace_session(fst_session, input_filename, 0, "mrf") == SWITCH_STATUS_SUCCESS); \
switch_status_t status = switch_ivr_play_and_detect_speech(fst_session, prompt_filename, recognizer, grammar, (char **)&fst_asr_result, 0, input_args); \
fst_check(fst_asr_result != NULL); \
}
switch_status_t switch_ivr_play_and_detect_speech(switch_core_session_t *session, const char *file, const char *mod_name, const char *grammar, char **result, uint32_t input_timeout, switch_input_args_t *args)
play a file to the session while doing speech recognition.
switch_status_t switch_ivr_displace_session(switch_core_session_t *session, const char *file, uint32_t limit, const char *flags)
displace the media for a session with the audio from a file

Use play_and_detect_speech core function to test recognizer

Test Requires: switch_ivr_displace_session(input_filename) == SWITCH_STATUS_SUCCESS

Test Checks: fst_asr_result != NULL after recognition completes

Test Output: fst_asr_result has the result from detect_speech_result channel variable.

Parameters
recognizername of recognizer
grammarrecognizer grammar
prompt_filenamename of prompt to play
input_filenamename of file containing input audio for the recognizer
input_argsinput callback args

Definition at line 757 of file switch_test.h.

◆ fst_play_and_detect_speech_test_begin

#define fst_play_and_detect_speech_test_begin ( )
Value:
{ \
const char *fst_asr_result = NULL; \
fst_requires(fst_core > 1);

Define beginning of play_and_detect_speech recognizer test

Defined vars: const char *fst_asr_result; Result of last recognition. Allocated from test memory pool.

Definition at line 702 of file switch_test.h.

◆ fst_play_and_detect_speech_test_end

#define fst_play_and_detect_speech_test_end ( )    }

Define end of play_and_detect_speech recognizer test

Definition at line 770 of file switch_test.h.

◆ fst_requires

#define fst_requires   fct_req

check for test requirement - execute teardown on failure

Definition at line 149 of file switch_test.h.

◆ fst_requires_module

#define fst_requires_module (   modname)    fct_req(switch_loadable_module_exists(modname) == SWITCH_STATUS_SUCCESS)

check for required module - execute teardown on failure

Definition at line 154 of file switch_test.h.

◆ fst_sched_recv_dtmf

#define fst_sched_recv_dtmf (   when,
  digits 
)
Value:
{ \
switch_status_t api_result; \
switch_stream_handle_t stream = { 0 }; \
SWITCH_STANDARD_STREAM(stream); \
fst_requires(fst_core > 1); \
fst_requires_module("mod_commands"); \
api_result = switch_api_execute("sched_api", switch_core_session_sprintf(fst_session, "%s none uuid_recv_dtmf %s %s", when, switch_core_session_get_uuid(fst_session), digits), NULL, &stream); \
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fst_session), SWITCH_LOG_INFO, "Injecting DTMF %s at %s\n", digits, when); \
fst_requires(api_result == SWITCH_STATUS_SUCCESS); \
switch_safe_free(stream.data); \
}
char * switch_core_session_sprintf(_In_ switch_core_session_t *session, _In_z_ _Printf_format_string_ const char *fmt,...)
printf-style style printing routine. The data is output to a string allocated from the session ...
#define SWITCH_CHANNEL_SESSION_LOG(x)
switch_status_t switch_api_execute(const char *cmd, const char *arg, switch_core_session_t *session, switch_stream_handle_t *stream)
Execute a registered API command.
char * switch_core_session_get_uuid(_In_ switch_core_session_t *session)
Retrieve the unique identifier from a session.

Inject DTMF into the session to be detected.

Test Requires: switch_api_execute(sched_api) == SWITCH_STATUS_SUCCESS mod_commands is loaded

Parameters
whenstring describing when to send dtmf
digitsto send

Definition at line 815 of file switch_test.h.

◆ FST_SESSION_BEGIN

#define FST_SESSION_BEGIN (   name)    FST_SESSION_BEGIN_RATE(name, 8000)

Define a session test in a test suite. This can be used to test IVR functions. See FST_SESSION_BEGIN_RATE_VIDEO

Definition at line 533 of file switch_test.h.

◆ FST_SESSION_BEGIN_RATE

#define FST_SESSION_BEGIN_RATE (   name,
  rate 
)    FST_SESSION_BEGIN_RATE_VIDEO(name, rate, "")

Definition at line 534 of file switch_test.h.

◆ FST_SESSION_BEGIN_RATE_VIDEO

#define FST_SESSION_BEGIN_RATE_VIDEO (   name,
  rate,
  video_codec 
)

Define a session test in a test suite. This can be used to test IVR functions.

Records session audio to /tmp/name.wav where name is the name of the test.

Required modules: mod_loopback - for null endpoint mod_sndfile - for wav file support

Defined vars: switch_memory_pool_t *fst_pool; A memory pool that is torn down on test completion switch_core_timer_t *fst_timer; A 8kHz, 20ms soft timer (160 samples per frame) switch_core_session_t *fst_session; The outbound null session. L16, 1 channel, 8kHz. switch_core_session_t *fst_session_pool; The outbound null session's pool. switch_channel_t *fst_channel; The outbound null session's channel.

Parameters
namethe name of this test
ratethe rate of the channel
video_codecthe rate of the channel

Definition at line 490 of file switch_test.h.

◆ FST_SESSION_END

#define FST_SESSION_END ( )
Value:
break; \
} \
if (switch_channel_ready(fst_channel)) { \
switch_channel_hangup(fst_channel, SWITCH_CAUSE_NORMAL_CLEARING); \
} \
if (fst_originate_vars) { \
switch_event_destroy(&fst_originate_vars); \
} \
if (fst_session_pool) { \
fst_session_pool = NULL; \
} \
switch_core_session_rwunlock(fst_session); \
if (fst_core) { \
switch_log_level_t level = SWITCH_LOG_DISABLE; \
switch_core_session_ctl(SCSC_LOGLEVEL, &level); \
} \
switch_sleep(1000000); \
} \
} \
FCT_TEST_END()
#define switch_channel_ready(_channel)

Define the end of a session test in a test suite. Hangs up session under test.

Definition at line 542 of file switch_test.h.

◆ fst_session_park

#define fst_session_park (   session)
Value:
switch_channel_wait_for_flag(switch_core_session_get_channel(session), CF_PARK, SWITCH_TRUE, 10000, NULL);
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
void switch_ivr_park_session(switch_core_session_t *session)
Definition: switch_ivr.c:3571

Park FreeSWITCH session. This is handy when wanting to use switch_core_session_execute_async() on the test session.

Parameters
sessionto park

Definition at line 142 of file switch_test.h.

◆ FST_SETUP_BEGIN

#define FST_SETUP_BEGIN ( )
Value:
if (fst_core) { \
switch_core_new_memory_pool(&fst_pool); \
if (fst_core > 1) { \
fst_timer_started = (switch_core_timer_init(&fst_timer, "soft", 20, 160, fst_pool) == SWITCH_STATUS_SUCCESS); \
} \
}
switch_status_t switch_core_timer_init(switch_timer_t *timer, const char *timer_name, int interval, int samples, switch_memory_pool_t *pool)
Request a timer handle using given time module.
#define FCT_SETUP_BGN()
Definition: switch_fct.h:3444

Define the test suite setup. This is run before each test or session test.

Definition at line 407 of file switch_test.h.

◆ FST_SETUP_END

#define FST_SETUP_END   FCT_SETUP_END

Define the end of test suite setup.

Definition at line 419 of file switch_test.h.

◆ FST_SUITE_BEGIN

#define FST_SUITE_BEGIN (   suite)
Value:
const char *fst_test_module = NULL; \
FCT_FIXTURE_SUITE_BGN(suite)

Define the beginning of a test suite not associated with a module.

Parameters
suitethe name of this test suite

Definition at line 394 of file switch_test.h.

◆ FST_SUITE_END

#define FST_SUITE_END   FCT_FIXTURE_SUITE_END

Define the end of a test suite.

Definition at line 401 of file switch_test.h.

◆ FST_TEARDOWN_BEGIN

#define FST_TEARDOWN_BEGIN ( )
Value:
if (fst_core) { \
if (fst_pool) switch_core_destroy_memory_pool(&fst_pool); \
if (fst_core > 1) { \
if (fst_timer_started) switch_core_timer_destroy(&fst_timer); \
} \
}
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
Definition: switch_core.h:642
switch_status_t switch_core_timer_destroy(switch_timer_t *timer)
Destroy an allocated timer.
#define FCT_TEARDOWN_BGN()
Definition: switch_fct.h:3450

Define the test suite teardown. This is run after each test or session test.

Definition at line 425 of file switch_test.h.

◆ FST_TEARDOWN_END

#define FST_TEARDOWN_END   FCT_TEARDOWN_END

Define the test suite teardown end.

Definition at line 437 of file switch_test.h.

◆ FST_TEST_BEGIN

#define FST_TEST_BEGIN (   name)
Value:
if (fst_core) { \
switch_log_level_t level = SWITCH_LOG_DEBUG; \
switch_core_session_ctl(SCSC_LOGLEVEL, &level); \
fst_requires(fst_pool != NULL); \
if (fst_core > 1) { \
fst_requires(fst_timer_started); \
} \
fst_time_mark(); \
} \
if (fst_test_module) { \
fst_requires_module(fst_test_module); \
}
#define FCT_TEST_BGN(_NAME_)
Definition: switch_fct.h:3499
const char *const name
Definition: switch_cJSON.h:250

Define a test in a test suite. Defined vars: switch_memory_pool_t *fst_pool; A memory pool that is torn down on test completion switch_core_timer_t *fst_timer; A 8kHz, 20ms soft timer (160 samples per frame)

Parameters
namethe name of this test

Definition at line 446 of file switch_test.h.

◆ fst_test_core_asr

#define fst_test_core_asr (   grammar,
  input_filename 
)

Execute test on opened recognizer. Reads audio from input file and passes it to the recognizer.

Test Requires: switch_core_asr_load_grammar(grammar) == SWITCH_STATUS_SUCCESS switch_core_file_open(input_filename) == SWITCH_STATUS_SUCCESS switch_core_file_close() == SWITCH_STATUS_SUCCESS

Test Checks: Got result from recognizer.

Test Output: fst_asr_result has the xmlstr from switch_core_file_get_results()

Parameters
grammarrecognizer grammar
input_filenamename of file containing audio to send to recognizer.

Definition at line 608 of file switch_test.h.

◆ fst_test_core_asr_close

#define fst_test_core_asr_close ( )
Value:
fst_requires(fst_core > 1); \
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Close recognizer\n"); \
}
#define SWITCH_CHANNEL_LOG
#define fst_requires
Definition: switch_test.h:149
switch_status_t switch_core_asr_close(switch_asr_handle_t *ah, switch_asr_flag_t *flags)
Close an asr handle.
unsigned int flags
Definition: switch_speex.c:106

Close an open recognizer

Test Requires: switch_core_asr_close(&ah, flags) == SWITCH_STATUS_SUCCESS

Definition at line 685 of file switch_test.h.

◆ fst_test_core_asr_open

#define fst_test_core_asr_open (   recognizer)
Value:
{\
char *fst_asr_result = NULL; \
switch_asr_handle_t ah = { 0 }; \
switch_asr_flag_t flags = SWITCH_ASR_FLAG_NONE; \
fst_requires(fst_core > 1); \
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Open recognizer: %s\n", recognizer); \
/* open ASR interface and feed recorded audio into it and collect result */ \
fst_requires(switch_core_asr_open(&ah, recognizer, "L16", 8000, "", &flags, fst_pool) == SWITCH_STATUS_SUCCESS); \
#define SWITCH_CHANNEL_LOG
switch_status_t switch_core_asr_open(switch_asr_handle_t *ah, const char *module_name, const char *codec, int rate, const char *dest, switch_asr_flag_t *flags, switch_memory_pool_t *pool)
Open an asr handle.
unsigned int flags
Definition: switch_speex.c:106

Open core ASR for a recognizer module. Opens for L16, 1 channel, 8KHz.

Test Requires: switch_core_asr_open() == SWITCH_STATUS_SUCCESS

Defined vars: switch_asr_handle_t ah; Core ASR handle switch_asr_flag_t flags; Core ASR flags used to open recognizer. char *fst_asr_result; Result of last recognition. Allocated from test memory pool.

Parameters
recognizername of recognizer to open (like gcloud_dialogflow)

Definition at line 581 of file switch_test.h.

◆ fst_test_core_asr_pause

#define fst_test_core_asr_pause ( )
Value:
fst_requires(fst_core > 1); \
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Pause recognizer\n"); \
#define SWITCH_CHANNEL_LOG
#define fst_requires
Definition: switch_test.h:149
switch_status_t switch_core_asr_pause(switch_asr_handle_t *ah)
Pause detection on an asr handle.

Pause an open recognizer.

Test Requires: switch_core_asr_pause(&ah) == SWITCH_STATUS_SUCCESS

Definition at line 661 of file switch_test.h.

◆ fst_test_core_asr_resume

#define fst_test_core_asr_resume ( )
Value:
fst_requires(fst_core > 1); \
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Resume recognizer\n"); \
#define SWITCH_CHANNEL_LOG
#define fst_requires
Definition: switch_test.h:149
switch_status_t switch_core_asr_resume(switch_asr_handle_t *ah)
Resume detection on an asr handle.

Resumes an open recognizer

Test Requires: switch_core_asr_resume(&ah) == SWITCH_STATUS_SUCCESS

Definition at line 673 of file switch_test.h.

◆ FST_TEST_END

#define FST_TEST_END
Value:
if (fst_core) { \
switch_log_level_t level = SWITCH_LOG_DISABLE; \
switch_core_session_ctl(SCSC_LOGLEVEL, &level); \
} \
FCT_TEST_END

Definition at line 461 of file switch_test.h.

◆ fst_time_mark

#define fst_time_mark ( )    fst_time_start = switch_time_now();

Mark reference for time measure

Definition at line 199 of file switch_test.h.

◆ fst_xcheck

#define fst_xcheck (   expr,
  error_msg 
)    (fct_xchk(expr, "%s", error_msg))

Check a test /w error message

Definition at line 205 of file switch_test.h.

◆ fst_xml_attr

#define fst_xml_attr (   attr)    if (!zstr(attr)) fst_xml_stream.write_function(&fst_xml_stream, " %s=\"%s\"", #attr, attr);

Definition at line 838 of file switch_test.h.

◆ fst_xml_body

#define fst_xml_body (   body)
Value:
if (fst_tag_body) { \
fst_xml_stream.write_function(&fst_xml_stream, "%s", body); \
} else { \
fst_tag_body = 1; \
fst_xml_stream.write_function(&fst_xml_stream, ">%s", body); \
}
int fst_tag_body
Definition: switch_test.h:832

Definition at line 850 of file switch_test.h.

◆ fst_xml_close_tag

#define fst_xml_close_tag (   tag_name)
Value:
fst_xml_stream.write_function(&fst_xml_stream, "</%s>", #tag_name); \
} else { \
fst_xml_stream.write_function(&fst_xml_stream, "/>"); \
} \
fst_tag_body = 0;
int fst_tag_body
Definition: switch_test.h:832
int fst_tag_children
Definition: switch_test.h:831

Definition at line 841 of file switch_test.h.

◆ fst_xml_end

#define fst_xml_end ( )    switch_xml_parse_str_dynamic((char *)fst_xml_stream.data, SWITCH_FALSE);

Definition at line 858 of file switch_test.h.

◆ fst_xml_open_tag

#define fst_xml_open_tag (   tag_name)
Value:
fst_xml_stream.write_function(&fst_xml_stream, "<%s", #tag_name); \
fst_tag_children++;

Definition at line 834 of file switch_test.h.

◆ fst_xml_start

#define fst_xml_start ( )
Value:
switch_stream_handle_t fst_xml_stream = { 0 }; \
SWITCH_STANDARD_STREAM(fst_xml_stream);

Definition at line 828 of file switch_test.h.

◆ SWITCH_TEST_BASE_DIR_OVERRIDE

#define SWITCH_TEST_BASE_DIR_OVERRIDE   "."

Function Documentation

◆ fst_getenv_default()

static char* fst_getenv_default ( const char *  env,
char *  default_value,
switch_bool_t  required 
)
static

Get environment variable and save to var

Definition at line 41 of file switch_test.h.

42 {
43  char *val = getenv(env);
44  if (!val) {
45  if (required) {
46  fprintf(stderr, "Failed to start test: environment variable \"%s\" is not set!\n", env);
47  exit(1);
48  }
49  return default_value;
50  }
51  return val;
52 }

◆ fst_init_core_and_modload()

static switch_status_t fst_init_core_and_modload ( const char *  confdir,
const char *  basedir,
int  minimal,
switch_core_flag_t  flags 
)
static

initialize FS core from optional configuration dir

Definition at line 69 of file switch_test.h.

References switch_directories::cache_dir, switch_directories::conf_dir, switch_directories::data_dir, switch_directories::db_dir, switch_directories::fonts_dir, switch_directories::grammar_dir, switch_directories::htdocs_dir, switch_directories::images_dir, switch_directories::localstate_dir, switch_directories::log_dir, switch_directories::recordings_dir, switch_directories::run_dir, SCF_MINIMAL, switch_directories::script_dir, switch_directories::sounds_dir, switch_directories::storage_dir, switch_core_init(), switch_core_init_and_modload(), switch_core_set_globals(), switch_core_set_variable(), switch_getpid(), SWITCH_GLOBAL_dirs, switch_mprintf(), SWITCH_PATH_SEPARATOR, switch_sleep(), SWITCH_STATUS_SUCCESS, SWITCH_TEST_BASE_DIR_OVERRIDE, SWITCH_TRUE, and zstr.

70 {
71  switch_status_t status;
72  const char *err;
73  unsigned long pid = switch_getpid();
74  // Let FreeSWITCH core pick these
75  //SWITCH_GLOBAL_dirs.base_dir = strdup("/usr/local/freeswitch");
76  //SWITCH_GLOBAL_dirs.mod_dir = strdup("/usr/local/freeswitch/mod");
77  //SWITCH_GLOBAL_dirs.lib_dir = strdup("/usr/local/freeswitch/lib");
78  //SWITCH_GLOBAL_dirs.temp_dir = strdup("/tmp");
79 
80 #ifdef SWITCH_TEST_BASE_DIR_OVERRIDE
82 #else
83 #define SWITCH_TEST_BASE_DIR_OVERRIDE "."
84 #endif
85 
86  if (zstr(basedir)) {
87  basedir = ".";
88  }
89 
90  // Allow test to define the runtime dir
91  if (!zstr(confdir)) {
92 #ifdef SWITCH_TEST_BASE_DIR_FOR_CONF
93  SWITCH_GLOBAL_dirs.conf_dir = switch_mprintf("%s%s%s", SWITCH_TEST_BASE_DIR_FOR_CONF, SWITCH_PATH_SEPARATOR, confdir);
94 #else
95  if (confdir[0] != '/') {
97  } else {
98  SWITCH_GLOBAL_dirs.conf_dir = strdup(confdir);
99  }
100 #endif
101  } else {
103  }
104 
119 
121 
122  if (!minimal) {
124  switch_sleep(1 * 1000000);
125  switch_core_set_variable("sound_prefix", "." SWITCH_PATH_SEPARATOR);
126  if (status != SWITCH_STATUS_SUCCESS && err) {
127  fprintf(stderr, "%s", err);
128  }
129  return status;
130  }
131  status = switch_core_init(SCF_MINIMAL, SWITCH_TRUE, &err);
132  if (status != SWITCH_STATUS_SUCCESS && err) {
133  fprintf(stderr, "%s", err);
134  }
135  return status;
136 }
switch_status_t switch_core_init(_In_ switch_core_flag_t flags, _In_ switch_bool_t console, _Out_ const char **err)
Initilize the core.
void switch_sleep(switch_interval_time_t t)
Definition: switch_time.c:640
void switch_core_set_variable(_In_z_ const char *varname, _In_opt_z_ const char *value)
Add a global variable to the core.
void switch_core_set_globals(void)
Initiate Globals.
Definition: switch_core.c:633
#define zstr(x)
Definition: switch_utils.h:314
#define SWITCH_TEST_BASE_DIR_OVERRIDE
#define SWITCH_PATH_SEPARATOR
Definition: switch_types.h:124
switch_status_t switch_core_init_and_modload(_In_ switch_core_flag_t flags, _In_ switch_bool_t console, _Out_ const char **err)
Initilize the core and load modules.
unsigned int flags
Definition: switch_speex.c:106
switch_directories SWITCH_GLOBAL_dirs
Definition: switch_core.c:82
switch_status_t
Common return values.
unsigned long switch_getpid(void)
SWITCH_BEGIN_EXTERN_C char * switch_mprintf(const char *zFormat,...)

Variable Documentation

◆ fst_tag_body

int fst_tag_body = 0

Definition at line 832 of file switch_test.h.

◆ fst_tag_children

int fst_tag_children = 0

Definition at line 831 of file switch_test.h.