43 #define CONTEXT_NAME "tests_test_gosub_virtual_context"
44 int res = AST_TEST_PASS, i;
50 const char *expected_value;
52 { NULL,
"${STACK_PEEK(1,e,1)}",
"" },
53 {
"Gosub",
"tests_test_gosub_virtual_context,s,1" },
54 { NULL,
"${PRIORITY}",
"1" },
55 { NULL,
"${EXTEN}",
"s" },
56 { NULL,
"${STACK_PEEK(1,e,1)}",
"" },
57 {
"Gosub",
"test,dne,1", (
const char *) -1 },
58 { NULL,
"${PRIORITY}",
"1" },
59 { NULL,
"${EXTEN}",
"s" },
60 {
"Gosub",
"tests_test_gosub_virtual_context,s,1(5,5,5,5,5)" },
61 { NULL,
"${PRIORITY}",
"1" },
62 { NULL,
"$[0${ARG1} + 0${ARG5}]",
"10" },
63 { NULL,
"${STACK_PEEK(1,e)}",
"s" },
64 { NULL,
"${STACK_PEEK(1,c)}",
"tests_test_gosub_virtual_context" },
65 { NULL,
"${STACK_PEEK(1,p)}",
"1" },
66 { NULL,
"${STACK_PEEK(1,l)}",
"tests_test_gosub_virtual_context,s,1" },
68 { NULL,
"${STACK_PEEK(1,e,1)}",
"" },
69 {
"Gosub",
"tests_test_gosub_virtual_context,s,1(5,5,5,5,5)" },
70 {
"Gosub",
"tests_test_gosub_virtual_context,s,1(4,4,4,4)" },
71 { NULL,
"$[0${ARG1} + 0${ARG5}]",
"4" },
72 { NULL,
"$[0${ARG1} + 0${ARG4}]",
"8" },
73 {
"Gosub",
"tests_test_gosub_virtual_context,s,1(3,3,3)" },
74 { NULL,
"$[0${ARG1} + 0${ARG4}]",
"3" },
75 { NULL,
"$[0${ARG1} + 0${ARG3}]",
"6" },
76 {
"Gosub",
"tests_test_gosub_virtual_context,s,1(2,2)" },
77 { NULL,
"$[0${ARG1} + 0${ARG3}]",
"2" },
78 { NULL,
"$[0${ARG1} + 0${ARG2}]",
"4" },
79 {
"Gosub",
"tests_test_gosub_virtual_context,s,1(1)" },
80 { NULL,
"$[0${ARG1} + 0${ARG2}]",
"1" },
81 { NULL,
"$[0${ARG1} + 0${ARG1}]",
"2" },
82 {
"Gosub",
"tests_test_gosub_virtual_context,s,1" },
83 { NULL,
"$[0${ARG1} + 0${ARG1}]",
"0" },
84 {
"Set",
"LOCAL(foo)=5" },
85 { NULL,
"${foo}",
"5" },
86 { NULL,
"${LOCAL_PEEK(0,ARG1)}",
"" },
87 { NULL,
"${LOCAL_PEEK(4,ARG1)}",
"4" },
88 { NULL,
"$[0${LOCAL_PEEK(3,ARG1)} + 0${LOCAL_PEEK(5,ARG1)}]",
"8" },
90 { NULL,
"${foo}",
"" },
92 { NULL,
"${GOSUB_RETVAL}",
"7" },
93 { NULL,
"$[0${GOSUB_RETVAL} + 0${ARG1}]",
"9" },
98 info->name =
"gosub application";
99 info->category =
"/apps/app_gosub/";
100 info->summary =
"Verify functionality of gosub application";
102 "Verify functionality of gosub application";
103 return AST_TEST_NOT_RUN;
109 ast_test_status_update(
test,
"Unable to allocate dummy channel\n");
110 return AST_TEST_FAIL;
114 ast_test_status_update(
test,
"Unable to allocate dynamic string buffer\n");
116 return AST_TEST_FAIL;
121 ast_test_status_update(
test,
"Unable to create test dialplan context");
124 return AST_TEST_FAIL;
129 for (i = 0; i < ARRAY_LEN(testplan); i++) {
130 if (testplan[i].app == NULL) {
134 ast_test_status_update(
test,
"Evaluation of '%s' returned '%s' instead of the expected value '%s'\n",
135 testplan[i].args,
ast_str_buffer(str), testplan[i].expected_value);
143 ast_test_status_update(
test,
"Could not find '%s' in application listing!\n", testplan[i].app);
148 if ((exec_res =
pbx_exec(chan, app, testplan[i].args)) && ((
const char *) exec_res != testplan[i].expected_value)) {
149 ast_test_status_update(
test,
"Application '%s' exited abnormally (with code %d)\n", testplan[i].app, (
int) exec_res);
164 static int unload_module(
void)
166 AST_TEST_UNREGISTER(test_gosub);
170 static int load_module(
void)
172 AST_TEST_REGISTER(test_gosub);
Main Channel structure associated with a channel.
Asterisk main include file. File version handling, generic pbx functions.
int pbx_exec(struct ast_channel *c, struct ast_app *app, const char *data)
Execute an application.
#define ast_channel_unref(c)
Decrease channel reference count.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
#define ast_strdup(str)
A wrapper for strdup()
void ast_free_ptr(void *ptr)
free() wrapper
int ast_context_remove_extension(const char *context, const char *extension, int priority, const char *registrar)
Simply remove extension from context.
General Asterisk PBX channel definitions.
#define ast_dummy_channel_alloc()
Create a fake channel structure.
Core PBX routines and definitions.
Support for dynamic strings.
int ast_add_extension(const char *context, int replace, const char *extension, int priority, const char *label, const char *callerid, const char *application, void *data, void(*datad)(void *), const char *registrar)
Add and extension to an extension context.
ast_app: A registered application
void ast_context_destroy(struct ast_context *con, const char *registrar)
Destroy a context (matches the specified context or ANY context if NULL)
#define AST_TEST_DEFINE(hdr)
struct ast_context * ast_context_find_or_create(struct ast_context **extcontexts, struct ast_hashtab *exttable, const char *name, const char *registrar)
Register a new context or find an existing one.
struct ast_app * pbx_findapp(const char *app)
Look up an application.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.