Asterisk - The Open Source Telephony Project GIT-master-f36a736
Macros | Functions | Variables
test_substitution.c File Reference

Substitution Test. More...

#include "asterisk.h"
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/lock.h"
#include "asterisk/app.h"
#include "asterisk/strings.h"
#include "asterisk/stringfields.h"
#include "asterisk/threadstorage.h"
#include "asterisk/test.h"
#include "asterisk/vector.h"
Include dependency graph for test_substitution.c:

Go to the source code of this file.

Macros

#define TEST(t)   if (t == AST_TEST_FAIL) { res = AST_TEST_FAIL; }
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
 AST_TEST_DEFINE (test_substitution)
 
static int load_module (void)
 
static enum ast_test_result_state test_2way_function (struct ast_test *test, struct ast_channel *c, const char *encode1, const char *encode2, const char *decode1, const char *decode2)
 
static enum ast_test_result_state test_chan_function (struct ast_test *test, struct ast_channel *c, const char *expression)
 
static enum ast_test_result_state test_chan_integer (struct ast_test *test, struct ast_channel *c, int *ifield, const char *expression)
 
static enum ast_test_result_state test_chan_integer_accessor (struct ast_test *test, struct ast_channel *c, void(*setter)(struct ast_channel *, int), const char *expression)
 
static enum ast_test_result_state test_chan_string (struct ast_test *test, struct ast_channel *c, void(*setter)(struct ast_channel *, const char *), const char *(*getter)(const struct ast_channel *), const char *expression)
 
static enum ast_test_result_state test_chan_variable (struct ast_test *test, struct ast_channel *c, const char *varname)
 
static enum ast_test_result_state test_expected_result (struct ast_test *test, struct ast_channel *c, const char *expression, const char *result)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Substitution tests" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 

Detailed Description

Substitution Test.

Author
Tilghman Lesher <tlesher AT digium DOT com> 

Definition in file test_substitution.c.

Macro Definition Documentation

◆ TEST

#define TEST (   t)    if (t == AST_TEST_FAIL) { res = AST_TEST_FAIL; }

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 350 of file test_substitution.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 350 of file test_substitution.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 350 of file test_substitution.c.

◆ AST_TEST_DEFINE()

AST_TEST_DEFINE ( test_substitution  )

Definition at line 224 of file test_substitution.c.

225{
226 struct ast_channel *c;
227 int i;
229 struct ast_vector_string *funcs;
230
231 switch (cmd) {
232 case TEST_INIT:
233 info->name = "test_substitution";
234 info->category = "/main/pbx/";
235 info->summary = "Test variable and function substitution";
236 info->description =
237 "This test executes a variety of variable and function substitutions "
238 "and ensures that the expected results are received.";
239 return AST_TEST_NOT_RUN;
240 case TEST_EXECUTE:
241 break;
242 }
243
244 ast_test_status_update(test, "Testing variable substitution ...\n");
245
246 c = ast_channel_alloc(0, 0, "", "", "", "", "", NULL, NULL, 0, "Test/substitution");
248
249#define TEST(t) if (t == AST_TEST_FAIL) { res = AST_TEST_FAIL; }
250#if 0
251 /*
252 * We can no longer test the CALLINGPRES value this way because it is now
253 * a calculated value from the name and number presentation information to
254 * get a combined presentation value.
255 */
256 TEST(test_chan_integer(test, c, &c->caller.id.number.presentation, "${CALLINGPRES}"));
257#endif
258 TEST(test_chan_integer(test, c, &ast_channel_caller(c)->ani2, "${CALLINGANI2}"));
259 TEST(test_chan_integer(test, c, &ast_channel_caller(c)->id.number.plan, "${CALLINGTON}"));
260 TEST(test_chan_integer(test, c, &ast_channel_dialed(c)->transit_network_select, "${CALLINGTNS}"));
265 TEST(test_chan_variable(test, c, "CHANNEL(language)"));
266 TEST(test_chan_variable(test, c, "CHANNEL(musicclass)"));
267 TEST(test_chan_variable(test, c, "CHANNEL(parkinglot)"));
268 TEST(test_chan_variable(test, c, "CALLERID(name)"));
269 TEST(test_chan_variable(test, c, "CURLOPT(proxyuserpwd)"));
270 TEST(test_chan_variable(test, c, "CDR(foo)"));
271 TEST(test_chan_variable(test, c, "ENV(foo)"));
272 TEST(test_chan_variable(test, c, "GLOBAL(foo)"));
273 TEST(test_chan_variable(test, c, "GROUP()"));
274 TEST(test_2way_function(test, c, "${AES_ENCRYPT(abcdefghijklmnop,", ")}", "${AES_DECRYPT(abcdefghijklmnop,", ")}"));
275 TEST(test_2way_function(test, c, "${BASE64_ENCODE(", ")}", "${BASE64_DECODE(", ")}"));
276 pbx_builtin_setvar_helper(c, "foo", "123");
277 pbx_builtin_setvar_helper(c, "bar", "foo");
278 pbx_builtin_setvar_helper(c, "baz", "fo");
279 TEST(test_expected_result(test, c, "${foo}${foo}", "123123"));
280 TEST(test_expected_result(test, c, "A${foo}A${foo}A", "A123A123A"));
281 TEST(test_expected_result(test, c, "A${${bar}}A", "A123A"));
282 TEST(test_expected_result(test, c, "A${${baz}o}A", "A123A"));
283 TEST(test_expected_result(test, c, "A${${baz}o:1}A", "A23A"));
284 TEST(test_expected_result(test, c, "A${${baz}o:1:1}A", "A2A"));
285 TEST(test_expected_result(test, c, "A${${baz}o:1:-1}A", "A2A"));
286 TEST(test_expected_result(test, c, "A${${baz}o:-1:1}A", "A3A"));
287 TEST(test_expected_result(test, c, "A${${baz}o:-2:1}A", "A2A"));
288 TEST(test_expected_result(test, c, "A${${baz}o:-2:-1}A", "A2A"));
289 pbx_builtin_setvar_helper(c, "list1", "ab&cd&ef");
290 TEST(test_expected_result(test, c, "${LISTFILTER(list1,&,ab)}", "cd&ef"));
291 TEST(test_expected_result(test, c, "${LISTFILTER(list1,&,cd)}", "ab&ef"));
292 TEST(test_expected_result(test, c, "${LISTFILTER(list1,&,ef)}", "ab&cd"));
293 TEST(test_expected_result(test, c, "${LISTFILTER(list1,&,gh)}", "ab&cd&ef"));
294 TEST(test_expected_result(test, c, "${LISTFILTER(list1,&,c)}", "ab&cd&ef"));
295 TEST(test_expected_result(test, c, "${LISTFILTER(list1,&,d)}", "ab&cd&ef"));
296 pbx_builtin_setvar_helper(c, "list2", "ab");
297 TEST(test_expected_result(test, c, "${LISTFILTER(list2,&,ab)}", ""));
298 pbx_builtin_setvar_helper(c, "list_empty", "");
299 TEST(test_expected_result(test, c, "${LISTFILTER(list_empty,&,ab)}", ""));
300 TEST(test_expected_result(test, c, "${SHELL(printf '%d' 123)},${SHELL(printf '%d' 456)}", "123,456"));
301 TEST(test_expected_result(test, c, "${foo},${CDR(answer)},${SHELL(printf '%d' 456)}", "123,,456"));
302 TEST(test_expected_result(test, c, "${foo},${CDR(answer,u)},${SHELL(printf '%d' 456)}", "123,0.000000,456"));
303 TEST(test_expected_result(test, c, "${foo},${this_does_not_exist},${THIS_DOES_NOT_EXIST(either)}", "123,,"));
304#undef TEST
305
306 /* For testing dialplan functions */
307 funcs = ast_cli_completion_vector("core show function", "");
308
309 /* Skip "best match" element 0 */
310 for (i = 1; funcs && i < AST_VECTOR_SIZE(funcs); i++) {
311 char *cmd = AST_VECTOR_GET(funcs, i);
312
313 if (strcmp(cmd, "CHANNEL") && strcmp(cmd, "CALLERID") && strncmp(cmd, "CURL", 4) &&
314 strncmp(cmd, "AES", 3) && strncmp(cmd, "BASE64", 6) &&
315 strcmp(cmd, "CDR") && strcmp(cmd, "ENV") && strcmp(cmd, "GLOBAL") &&
316 strcmp(cmd, "GROUP") && strcmp(cmd, "CUT") && strcmp(cmd, "LISTFILTER") &&
317 strcmp(cmd, "PP_EACH_EXTENSION") && strcmp(cmd, "SET")) {
319 if (acf->read && acf->read2) {
320 char expression[80];
321 snprintf(expression, sizeof(expression), "${%s(foo)}", cmd);
322 if (AST_TEST_FAIL == test_chan_function(test, c, expression)) {
323 res = AST_TEST_FAIL;
324 }
325 }
326 }
327 }
328
329 if (funcs) {
331 AST_VECTOR_PTR_FREE(funcs);
332 }
333 ast_hangup(c);
334
335 return res;
336}
#define ast_free(a)
Definition: astmm.h:180
void ast_channel_exten_set(struct ast_channel *chan, const char *value)
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2560
#define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, assignedids, requestor, amaflag,...)
Create a channel structure.
Definition: channel.h:1299
const char * ast_channel_context(const struct ast_channel *chan)
struct ast_party_dialed * ast_channel_dialed(struct ast_channel *chan)
void ast_channel_context_set(struct ast_channel *chan, const char *value)
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
void ast_channel_priority_set(struct ast_channel *chan, int value)
void ast_channel_hangupcause_set(struct ast_channel *chan, int value)
const char * ast_channel_exten(const struct ast_channel *chan)
#define ast_channel_unlock(chan)
Definition: channel.h:2969
struct ast_vector_string * ast_cli_completion_vector(const char *text, const char *word)
Generates a vector of strings for CLI completion.
Definition: main/cli.c:2773
def info(msg)
struct ast_custom_function * ast_custom_function_find(const char *name)
Definition: ael_main.c:173
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name.
#define NULL
Definition: resample.c:96
Main Channel structure associated with a channel.
Data structure associated with a custom dialplan function.
Definition: pbx.h:118
ast_acf_read_fn_t read
Definition: pbx.h:129
ast_acf_read2_fn_t read2
Definition: pbx.h:137
String vector definitions.
Definition: vector.h:55
Number structure.
Definition: app_followme.c:154
@ TEST_INIT
Definition: test.h:200
@ TEST_EXECUTE
Definition: test.h:201
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
ast_test_result_state
Definition: test.h:193
@ AST_TEST_PASS
Definition: test.h:195
@ AST_TEST_FAIL
Definition: test.h:196
@ AST_TEST_NOT_RUN
Definition: test.h:194
static struct test_val c
static enum ast_test_result_state test_chan_integer(struct ast_test *test, struct ast_channel *c, int *ifield, const char *expression)
static enum ast_test_result_state test_chan_function(struct ast_test *test, struct ast_channel *c, const char *expression)
static enum ast_test_result_state test_2way_function(struct ast_test *test, struct ast_channel *c, const char *encode1, const char *encode2, const char *decode1, const char *decode2)
static enum ast_test_result_state test_chan_string(struct ast_test *test, struct ast_channel *c, void(*setter)(struct ast_channel *, const char *), const char *(*getter)(const struct ast_channel *), const char *expression)
static enum ast_test_result_state test_chan_variable(struct ast_test *test, struct ast_channel *c, const char *varname)
#define TEST(t)
static enum ast_test_result_state test_chan_integer_accessor(struct ast_test *test, struct ast_channel *c, void(*setter)(struct ast_channel *, int), const char *expression)
static enum ast_test_result_state test_expected_result(struct ast_test *test, struct ast_channel *c, const char *expression, const char *result)
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
#define AST_VECTOR_PTR_FREE(vec)
Deallocates this vector pointer.
Definition: vector.h:189
#define AST_VECTOR_CALLBACK_VOID(vec, callback,...)
Execute a callback on every element in a vector disregarding callback return.
Definition: vector.h:862
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:680

References ast_channel_alloc, ast_channel_caller(), ast_channel_context(), ast_channel_context_set(), ast_channel_dialed(), ast_channel_exten(), ast_channel_exten_set(), ast_channel_hangupcause_set(), ast_channel_priority_set(), ast_channel_unlock, ast_cli_completion_vector(), ast_custom_function_find(), ast_free, ast_hangup(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, AST_VECTOR_CALLBACK_VOID, AST_VECTOR_GET, AST_VECTOR_PTR_FREE, AST_VECTOR_SIZE, c, sip_to_pjsip::info(), NULL, pbx_builtin_setvar_helper(), ast_custom_function::read, ast_custom_function::read2, TEST, test_2way_function(), test_chan_function(), test_chan_integer(), test_chan_integer_accessor(), test_chan_string(), test_chan_variable(), TEST_EXECUTE, test_expected_result(), and TEST_INIT.

◆ load_module()

static int load_module ( void  )
static

Definition at line 344 of file test_substitution.c.

345{
346 AST_TEST_REGISTER(test_substitution);
348}
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
#define AST_TEST_REGISTER(cb)
Definition: test.h:127

References AST_MODULE_LOAD_SUCCESS, and AST_TEST_REGISTER.

◆ test_2way_function()

static enum ast_test_result_state test_2way_function ( struct ast_test *  test,
struct ast_channel c,
const char *  encode1,
const char *  encode2,
const char *  decode1,
const char *  decode2 
)
static

Definition at line 176 of file test_substitution.c.

179{
180 struct ast_str *str = ast_str_create(16), *expression = ast_str_alloca(120);
181 int okay;
182
183 ast_str_set(&expression, 0, "%s%s%s", encode1, "foobarbaz", encode2);
185 ast_str_set(&expression, 0, "%s%s%s", decode1, ast_str_buffer(str), decode2);
187
188 okay = !strcmp(ast_str_buffer(str), "foobarbaz");
189 if (!okay) {
190 ast_test_status_update(test, "'%s' != 'foobarbaz'\n",
192 }
193 ast_test_status_update(test, "Tested '%s%s' and '%s%s' . . . . . %s\n",
194 encode1, encode2, decode1, decode2,
195 okay ? "passed" : "FAILED");
196
197 ast_free(str);
198
199 return okay ? AST_TEST_PASS : AST_TEST_FAIL;
200}
const char * str
Definition: app_jack.c:147
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:761
#define ast_str_alloca(init_len)
Definition: strings.h:848
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:659
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1113
Support for dynamic strings.
Definition: strings.h:623

References ast_free, ast_str_alloca, ast_str_buffer(), ast_str_create, ast_str_set(), ast_str_substitute_variables(), AST_TEST_FAIL, AST_TEST_PASS, ast_test_status_update, c, and str.

Referenced by AST_TEST_DEFINE().

◆ test_chan_function()

static enum ast_test_result_state test_chan_function ( struct ast_test *  test,
struct ast_channel c,
const char *  expression 
)
static

Definition at line 153 of file test_substitution.c.

155{
156 int okay = 1;
157 char workspace[4096];
158 struct ast_str *str = ast_str_create(16);
159
160 ast_str_substitute_variables(&str, 0, c, expression);
161 pbx_substitute_variables_helper(c, expression, workspace, sizeof(workspace));
162
163 if (strcmp(workspace, ast_str_buffer(str)) != 0) {
164 ast_test_status_update(test, "expr: '%s' ... %s != %s\n",
165 expression, ast_str_buffer(str), workspace);
166 okay = 0;
167 }
168 ast_test_status_update(test, "Tested '%s' . . . . . %s\n",
169 expression, okay ? "passed" : "FAILED");
170
171 ast_free(str);
172
173 return okay ? AST_TEST_PASS : AST_TEST_FAIL;
174}
void pbx_substitute_variables_helper(struct ast_channel *c, const char *cp1, char *cp2, int count)
Definition: ael_main.c:211

References ast_free, ast_str_buffer(), ast_str_create, ast_str_substitute_variables(), AST_TEST_FAIL, AST_TEST_PASS, ast_test_status_update, c, pbx_substitute_variables_helper(), and str.

Referenced by AST_TEST_DEFINE().

◆ test_chan_integer()

static enum ast_test_result_state test_chan_integer ( struct ast_test *  test,
struct ast_channel c,
int *  ifield,
const char *  expression 
)
static

Definition at line 48 of file test_substitution.c.

50{
51 int i, okay = 1, value1 = -1, value2 = -1;
52 char workspace[4096];
53 struct ast_str *str = ast_str_create(16);
54
55 for (i = 0; i < 256; i++) {
56 *ifield = i;
57 ast_str_substitute_variables(&str, 0, c, expression);
58 pbx_substitute_variables_helper(c, expression, workspace, sizeof(workspace));
59
60 if (sscanf(workspace, "%d", &value1) != 1 || value1 != i || sscanf(ast_str_buffer(str), "%d", &value2) != 1 || value2 != i) {
61 ast_test_status_update(test, "%s != %s and/or %d != %d != %d\n", ast_str_buffer(str), workspace, value1, value2, i);
62 okay = 0;
63 }
64 }
65 ast_test_status_update(test, "Tested '%s' . . . . . %s\n", expression, okay ? "passed" : "FAILED");
66
68
69 return okay ? AST_TEST_PASS : AST_TEST_FAIL;
70}

References ast_free, ast_str_buffer(), ast_str_create, ast_str_substitute_variables(), AST_TEST_FAIL, AST_TEST_PASS, ast_test_status_update, c, pbx_substitute_variables_helper(), and str.

Referenced by AST_TEST_DEFINE().

◆ test_chan_integer_accessor()

static enum ast_test_result_state test_chan_integer_accessor ( struct ast_test *  test,
struct ast_channel c,
void(*)(struct ast_channel *, int)  setter,
const char *  expression 
)
static

Definition at line 72 of file test_substitution.c.

74{
75 int i, okay = 1, value1 = -1, value2 = -1;
76 char workspace[4096];
77 struct ast_str *str = ast_str_create(16);
78
79 for (i = 0; i < 256; i++) {
80 setter(c, i);
81 ast_str_substitute_variables(&str, 0, c, expression);
82 pbx_substitute_variables_helper(c, expression, workspace, sizeof(workspace));
83
84 if (sscanf(workspace, "%d", &value1) != 1 || value1 != i || sscanf(ast_str_buffer(str), "%d", &value2) != 1 || value2 != i) {
85 ast_test_status_update(test, "%s != %s and/or %d != %d != %d\n", ast_str_buffer(str), workspace, value1, value2, i);
86 okay = 0;
87 }
88 }
89 ast_test_status_update(test, "Tested '%s' . . . . . %s\n", expression, okay ? "passed" : "FAILED");
90
92
93 return okay ? AST_TEST_PASS : AST_TEST_FAIL;
94}

References ast_free, ast_str_buffer(), ast_str_create, ast_str_substitute_variables(), AST_TEST_FAIL, AST_TEST_PASS, ast_test_status_update, c, pbx_substitute_variables_helper(), and str.

Referenced by AST_TEST_DEFINE().

◆ test_chan_string()

static enum ast_test_result_state test_chan_string ( struct ast_test *  test,
struct ast_channel c,
void(*)(struct ast_channel *, const char *)  setter,
const char *(*)(const struct ast_channel *)  getter,
const char *  expression 
)
static

Definition at line 96 of file test_substitution.c.

99{
100 const char *values[] = { "one", "three", "reallylongdinosaursoundingthingwithwordsinit" };
101 int i, okay = 1;
102 char workspace[4096];
103 struct ast_str *str = ast_str_create(16);
104
105 for (i = 0; i < ARRAY_LEN(values); i++) {
106 setter(c, values[i]);
107 ast_str_substitute_variables(&str, 0, c, expression);
108 pbx_substitute_variables_helper(c, expression, workspace, sizeof(workspace));
109
110 if (strcmp(getter(c), ast_str_buffer(str)) != 0 || strcmp(getter(c), workspace) != 0) {
111 ast_test_status_update(test, "%s != %s != %s\n", getter(c), ast_str_buffer(str), workspace);
112 okay = 0;
113 }
114 }
115 ast_test_status_update(test, "Tested '%s' . . . . . %s\n",
116 expression, okay ? "passed" : "FAILED");
117
118 ast_free(str);
119
120 return okay ? AST_TEST_PASS : AST_TEST_FAIL;
121}
#define ARRAY_LEN(a)
Definition: utils.h:666

References ARRAY_LEN, ast_free, ast_str_buffer(), ast_str_create, ast_str_substitute_variables(), AST_TEST_FAIL, AST_TEST_PASS, ast_test_status_update, c, pbx_substitute_variables_helper(), and str.

Referenced by AST_TEST_DEFINE().

◆ test_chan_variable()

static enum ast_test_result_state test_chan_variable ( struct ast_test *  test,
struct ast_channel c,
const char *  varname 
)
static

Definition at line 123 of file test_substitution.c.

125{
126 const char *values[] = { "one", "three", "reallylongdinosaursoundingthingwithwordsinit" };
127 int i, okay = 1;
128 char workspace[4096];
129 struct ast_str *str = ast_str_create(16);
130 struct ast_str *var = ast_str_create(16);
131
132 ast_str_set(&var, 0, "${%s}", varname);
133 for (i = 0; i < ARRAY_LEN(values); i++) {
134 pbx_builtin_setvar_helper(c, varname, values[i]);
136 pbx_substitute_variables_helper(c, ast_str_buffer(var), workspace, sizeof(workspace));
137
138 if (strcmp(values[i], ast_str_buffer(str)) != 0 || strcmp(values[i], workspace) != 0) {
139 ast_test_status_update(test, "%s != %s != %s\n",
140 values[i], ast_str_buffer(str), workspace);
141 okay = 0;
142 }
143 }
144 ast_test_status_update(test, "Tested '%s' . . . . . %s\n",
145 ast_str_buffer(var), okay ? "passed" : "FAILED");
146
147 ast_free(str);
148 ast_free(var);
149
150 return okay ? AST_TEST_PASS : AST_TEST_FAIL;
151}
#define var
Definition: ast_expr2f.c:605

References ARRAY_LEN, ast_free, ast_str_buffer(), ast_str_create, ast_str_set(), ast_str_substitute_variables(), AST_TEST_FAIL, AST_TEST_PASS, ast_test_status_update, c, pbx_builtin_setvar_helper(), pbx_substitute_variables_helper(), str, and var.

Referenced by AST_TEST_DEFINE().

◆ test_expected_result()

static enum ast_test_result_state test_expected_result ( struct ast_test *  test,
struct ast_channel c,
const char *  expression,
const char *  result 
)
static

Definition at line 202 of file test_substitution.c.

204{
205 struct ast_str *str = ast_str_create(16);
206 int okay;
207
208 ast_str_substitute_variables(&str, 0, c, expression);
209
210 okay = !strcmp(ast_str_buffer(str), result);
211 if (!okay) {
212 ast_test_status_update(test, "'%s' != '%s'\n",
214 }
215 ast_test_status_update(test, "Tested '%s' ('%s') == '%s' . . . . . %s\n",
216 ast_str_buffer(str), expression, result,
217 okay ? "passed" : "FAILED");
218
219 ast_free(str);
220
221 return okay ? AST_TEST_PASS : AST_TEST_FAIL;
222}
static PGresult * result
Definition: cel_pgsql.c:84

References ast_free, ast_str_buffer(), ast_str_create, ast_str_substitute_variables(), AST_TEST_FAIL, AST_TEST_PASS, ast_test_status_update, c, result, and str.

Referenced by AST_TEST_DEFINE().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 338 of file test_substitution.c.

339{
340 AST_TEST_UNREGISTER(test_substitution);
341 return 0;
342}
#define AST_TEST_UNREGISTER(cb)
Definition: test.h:128

References AST_TEST_UNREGISTER.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Substitution tests" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 350 of file test_substitution.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 350 of file test_substitution.c.