40 #define BASE_GROUP "a group"
44 enum test_option_flags {
49 enum test_option_args {
52 OPT_ARG_WITHBACKSLASH,
62 char *opt_args[OPT_ARG_ARRAY_SIZE];
67 {
"a(simple)b(\"quoted\")c(back\\slash)", {
"simple",
"quoted",
"backslash", }, },
68 {
"b(\"((())))\")a(simple)c(back\\)slash)", {
"simple",
"((())))",
"back)slash", }, },
69 {
"b(\"((\\\"\\)\\(\")a(simple)c(back\\\"\\)\\(\\\"slash)", {
"simple",
"((\"\\)\\(",
"back\")(\"slash", }, },
71 int i, j, res = AST_TEST_PASS;
76 info->name =
"options_parsing";
77 info->category =
"/main/app/";
78 info->summary =
"App options unit test";
80 "This tests the options parsing code to ensure that it behaves as expected";
81 return AST_TEST_NOT_RUN;
86 for (i = 0; i < ARRAY_LEN(options); i++) {
90 ast_test_status_update(
test,
"ast_app_parse_options() of '%s' failed\n", options[i].
string);
94 for (j = 0; j < 3; j++) {
95 if (strcmp(opt_args[j], options[i].parse[j])) {
96 ast_test_status_update(
test,
"Parse of option %c from '%s' produced '%s', "
97 "but it should have produced '%s'\n",
98 'a' + j, options[i].
string, opt_args[j], options[i].parse[j]);
106 ast_test_status_update(
test,
"ast_app_parse_options64() of '%s' failed\n", options[i].
string);
110 for (j = 0; j < 3; j++) {
111 if (strcmp(opt_args[j], options[i].parse[j])) {
112 ast_test_status_update(
test,
"Parse of option %c from '%s' produced '%s', "
113 "but it should have produced '%s'\n",
114 'a' + j, options[i].
string, opt_args[j], options[i].parse[j]);
131 static const char group1_full[] = BASE_GROUP
"groupgroup";
132 static const char group2_full[] = BASE_GROUP
"Groupgroup";
133 static const char regex1[] =
"gr";
134 static const char regex2[] =
"(group){2}$";
135 static const char regex3[] =
"[:ascii:]";
136 static const char regex4[] =
"^(NOMATCH)";
137 static const char category1_full[] = BASE_GROUP
"@a_category";
138 static const char category2_full[] = BASE_GROUP
"@another!Category";
139 static const char regex5[] =
"(gory)$";
140 static const char regex6[] =
"[A-Z]+";
141 static const char regex7[] =
"[[";
142 static enum ast_test_result_state res = AST_TEST_PASS;
143 static const struct group_test_params {
144 const char *groupmatch;
145 const char *category;
152 { BASE_GROUP, regex5, 2 },
153 { BASE_GROUP, regex6, 1 },
155 { BASE_GROUP, regex7, 0 }
162 info->name =
"app_group";
163 info->category =
"/main/app/";
164 info->summary =
"App group unit test";
166 "This tests various app group functionality";
167 return AST_TEST_NOT_RUN;
172 ast_test_status_update(
test,
"Creating test channels with the following groups:\n"
173 "'%s', '%s', '%s', '%s'\n", group1_full, group2_full, category1_full, category2_full);
176 NULL, NULL, NULL, NULL, 0,
"TestChannel1"))) {
177 goto exit_group_test;
179 ast_channel_unlock(test_channel1);
181 NULL, NULL, NULL, NULL, 0,
"TestChannel2"))) {
182 goto exit_group_test;
184 ast_channel_unlock(test_channel2);
186 NULL, NULL, NULL, NULL, 0,
"TestChannel3"))) {
187 goto exit_group_test;
189 ast_channel_unlock(test_channel3);
191 NULL, NULL, NULL, NULL, 0,
"TestChannel4"))) {
192 goto exit_group_test;
194 ast_channel_unlock(test_channel4);
201 for (i = 0; i < ARRAY_LEN(subtests); i++) {
202 ast_assert(subtests[i].groupmatch != NULL || subtests[i].category != NULL);
205 if (subtests[i].expected != returned_count) {
206 ast_test_status_update(
test,
"(Subtest %d) Expected %d matches but found %d when examining group:'%s' category:'%s'\n",
207 i + 1, subtests[i].expected, returned_count, subtests[i].groupmatch, subtests[i].category);
209 goto exit_group_test;
211 ast_test_status_update(
test,
"(Subtest %d) Found %d matches as expected when examining group:'%s' category:'%s'\n",
212 i + 1, subtests[i].expected, subtests[i].groupmatch, subtests[i].category);
224 static int unload_module(
void)
226 AST_TEST_UNREGISTER(app_group);
227 AST_TEST_UNREGISTER(options_parsing);
231 static int load_module(
void)
233 AST_TEST_REGISTER(app_group);
234 AST_TEST_REGISTER(options_parsing);
Main Channel structure associated with a channel.
Asterisk main include file. File version handling, generic pbx functions.
Structure used to handle a large number of boolean flags == used only in app_dial?
#define AST_APP_OPTIONS(holder, options...)
Declares an array of options for an application.
General Asterisk PBX channel definitions.
int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
int ast_app_parse_options64(const struct ast_app_option *options, struct ast_flags64 *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
#define AST_APP_OPTION_ARG(option, flagno, argno)
Declares an application option that accepts an argument.
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
int ast_app_group_match_get_count(const char *groupmatch, const char *category)
Get the current channel count of all groups that match the specified pattern and category.
Structure used to handle boolean flags.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
#define AST_TEST_DEFINE(hdr)
#define ASTERISK_GPL_KEY
The text the key() function should return.
#define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, assignedids, requestor, amaflag,...)
Create a channel structure.
Asterisk module definitions.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
int ast_app_group_set_channel(struct ast_channel *chan, const char *data)
Set the group for a channel, splitting the provided data into group and category, if specified...