mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-02 11:06:31 +00:00
Geolocation: Base Asterisk Prereqs
* Added ast_variable_list_from_quoted_string() Parse a quoted string into an ast_variable list. * Added ast_str_substitute_variables_full2() Perform variable/function/expression substitution on an ast_str. * Added ast_strsep_quoted() Like ast_strsep except you can specify a specific quote character. Also added unit test. * Added ast_xml_find_child_element() Find a direct child element by name. * Added ast_xml_doc_dump_memory() Dump the specified document to a buffer * ast_datastore_free() now checks for a NULL datastore before attempting to destroy it. Change-Id: I5dcefed2f5f93a109e8b489e18d80d42e45244ec
This commit is contained in:
committed by
Friendly Automation
parent
740c773781
commit
5fe9887701
@@ -1952,7 +1952,7 @@ AST_TEST_DEFINE(variable_list_from_string)
|
||||
|
||||
switch (cmd) {
|
||||
case TEST_INIT:
|
||||
info->name = "variable_list_from_string";
|
||||
info->name = "variable_list_from_quoted_string";
|
||||
info->category = "/main/config/";
|
||||
info->summary = "Test parsing a string into a variable list";
|
||||
info->description = info->summary;
|
||||
@@ -1962,7 +1962,7 @@ AST_TEST_DEFINE(variable_list_from_string)
|
||||
}
|
||||
|
||||
parse_string = "abc = 'def', ghi = 'j,kl', mno='pq=r', stu = 'vwx=\"yz\", ABC = \"DEF\"'";
|
||||
list = ast_variable_list_from_string(parse_string, ",", "=");
|
||||
list = ast_variable_list_from_quoted_string(parse_string, ",", "=", "'");
|
||||
ast_test_validate(test, list != NULL);
|
||||
str = ast_variable_list_join(list, "|", "^", "@", NULL);
|
||||
|
||||
|
@@ -385,6 +385,143 @@ AST_TEST_DEFINE(strsep_test)
|
||||
return AST_TEST_PASS;
|
||||
}
|
||||
|
||||
AST_TEST_DEFINE(strsep_quoted_test)
|
||||
{
|
||||
char *test1, *test2, *test3;
|
||||
|
||||
switch (cmd) {
|
||||
case TEST_INIT:
|
||||
info->name = "strsep_quoted";
|
||||
info->category = "/main/strings/";
|
||||
info->summary = "Test ast_strsep_quoted";
|
||||
info->description = "Test ast_strsep_quoted";
|
||||
return AST_TEST_NOT_RUN;
|
||||
case TEST_EXECUTE:
|
||||
break;
|
||||
}
|
||||
|
||||
test1 = ast_strdupa("ghi=jkl,mno=\"pqr,stu\",abc=def, vwx = yz1 , vwx = yz1 , "
|
||||
"\" vwx = yz1 \" , \" vwx , yz1 \",v'w'x, \"'x,v','x'\" , \" i\\'m a test\""
|
||||
", \" i\\'m a, test\", \" i\\'m a, test\", e\\,nd, end\\");
|
||||
|
||||
test2 = ast_strsep_quoted(&test1, ',', '"', 0);
|
||||
ast_test_validate(test, 0 == strcmp("ghi=jkl", test2));
|
||||
|
||||
test3 = ast_strsep_quoted(&test2, '=', '"', 0);
|
||||
ast_test_validate(test, 0 == strcmp("ghi", test3));
|
||||
|
||||
test3 = ast_strsep_quoted(&test2, '=', '"', 0);
|
||||
ast_test_validate(test, 0 == strcmp("jkl", test3));
|
||||
|
||||
test2 = ast_strsep_quoted(&test1, ',', '"', 0);
|
||||
ast_test_validate(test, 0 == strcmp("mno=\"pqr,stu\"", test2));
|
||||
|
||||
test3 = ast_strsep_quoted(&test2, '=', '"', 0);
|
||||
ast_test_validate(test, 0 == strcmp("mno", test3));
|
||||
|
||||
test3 = ast_strsep_quoted(&test2, '=', '"', 0);
|
||||
ast_test_validate(test, 0 == strcmp("\"pqr,stu\"", test3));
|
||||
|
||||
test2 = ast_strsep_quoted(&test1, ',', '"', 0);
|
||||
ast_test_validate(test, 0 == strcmp("abc=def", test2));
|
||||
|
||||
test2 = ast_strsep_quoted(&test1, ',', '"', 0);
|
||||
ast_test_validate(test, 0 == strcmp(" vwx = yz1 ", test2));
|
||||
|
||||
test2 = ast_strsep_quoted(&test1, ',', '"', AST_STRSEP_TRIM);
|
||||
ast_test_validate(test, 0 == strcmp("vwx = yz1", test2));
|
||||
|
||||
test2 = ast_strsep_quoted(&test1, ',', '"', AST_STRSEP_STRIP);
|
||||
ast_test_validate(test, 0 == strcmp(" vwx = yz1 ", test2));
|
||||
|
||||
test2 = ast_strsep_quoted(&test1, ',', '"', AST_STRSEP_STRIP | AST_STRSEP_TRIM);
|
||||
ast_test_validate(test, 0 == strcmp("vwx , yz1", test2));
|
||||
|
||||
test2 = ast_strsep_quoted(&test1, ',', '"', AST_STRSEP_STRIP | AST_STRSEP_TRIM);
|
||||
ast_test_validate(test, 0 == strcmp("v'w'x", test2));
|
||||
|
||||
test2 = ast_strsep_quoted(&test1, ',', '"', AST_STRSEP_TRIM);
|
||||
ast_test_validate(test, 0 == strcmp("\"'x,v','x'\"", test2));
|
||||
|
||||
test2 = ast_strsep_quoted(&test1, ',', '"', AST_STRSEP_TRIM);
|
||||
ast_test_validate(test, 0 == strcmp("\" i\\'m a test\"", test2));
|
||||
|
||||
test2 = ast_strsep_quoted(&test1, ',', '"', AST_STRSEP_TRIM | AST_STRSEP_UNESCAPE);
|
||||
ast_test_validate(test, 0 == strcmp("\" i'm a, test\"", test2));
|
||||
|
||||
test2 = ast_strsep_quoted(&test1, ',', '"', AST_STRSEP_ALL);
|
||||
ast_test_validate(test, 0 == strcmp("i'm a, test", test2));
|
||||
|
||||
test2 = ast_strsep_quoted(&test1, ',', '"', AST_STRSEP_TRIM | AST_STRSEP_UNESCAPE);
|
||||
ast_test_validate(test, 0 == strcmp("e,nd", test2));
|
||||
|
||||
test2 = ast_strsep_quoted(&test1, ',', '"', AST_STRSEP_TRIM | AST_STRSEP_UNESCAPE);
|
||||
ast_test_validate(test, 0 == strcmp("end", test2));
|
||||
|
||||
// Now use '|' as the quote character
|
||||
test1 = ast_strdupa("ghi=jkl,mno=|pqr,stu|,abc=def, vwx = yz1 , vwx = yz1 , "
|
||||
"| vwx = yz1 | , | vwx , yz1 |,v'w'x, |'x,v','x'| , | i\\'m a test|"
|
||||
", | i\\'m a, test|, | i\\'m a, test|, e\\,nd, end\\");
|
||||
|
||||
test2 = ast_strsep_quoted(&test1, ',', '|', 0);
|
||||
ast_test_validate(test, 0 == strcmp("ghi=jkl", test2));
|
||||
|
||||
test3 = ast_strsep_quoted(&test2, '=', '|', 0);
|
||||
ast_test_validate(test, 0 == strcmp("ghi", test3));
|
||||
|
||||
test3 = ast_strsep_quoted(&test2, '=', '|', 0);
|
||||
ast_test_validate(test, 0 == strcmp("jkl", test3));
|
||||
|
||||
test2 = ast_strsep_quoted(&test1, ',', '|', 0);
|
||||
ast_test_validate(test, 0 == strcmp("mno=|pqr,stu|", test2));
|
||||
|
||||
test3 = ast_strsep_quoted(&test2, '=', '|', 0);
|
||||
ast_test_validate(test, 0 == strcmp("mno", test3));
|
||||
|
||||
test3 = ast_strsep_quoted(&test2, '=', '|', 0);
|
||||
ast_test_validate(test, 0 == strcmp("|pqr,stu|", test3));
|
||||
|
||||
test2 = ast_strsep_quoted(&test1, ',', '|', 0);
|
||||
ast_test_validate(test, 0 == strcmp("abc=def", test2));
|
||||
|
||||
test2 = ast_strsep_quoted(&test1, ',', '|', 0);
|
||||
ast_test_validate(test, 0 == strcmp(" vwx = yz1 ", test2));
|
||||
|
||||
test2 = ast_strsep_quoted(&test1, ',', '|', AST_STRSEP_TRIM);
|
||||
ast_test_validate(test, 0 == strcmp("vwx = yz1", test2));
|
||||
|
||||
test2 = ast_strsep_quoted(&test1, ',', '|', AST_STRSEP_STRIP);
|
||||
ast_test_validate(test, 0 == strcmp(" vwx = yz1 ", test2));
|
||||
|
||||
test2 = ast_strsep_quoted(&test1, ',', '|', AST_STRSEP_STRIP | AST_STRSEP_TRIM);
|
||||
ast_test_validate(test, 0 == strcmp("vwx , yz1", test2));
|
||||
|
||||
test2 = ast_strsep_quoted(&test1, ',', '|', AST_STRSEP_STRIP | AST_STRSEP_TRIM);
|
||||
ast_test_validate(test, 0 == strcmp("v'w'x", test2));
|
||||
|
||||
test2 = ast_strsep_quoted(&test1, ',', '|', AST_STRSEP_TRIM);
|
||||
ast_test_validate(test, 0 == strcmp("|'x,v','x'|", test2));
|
||||
|
||||
test2 = ast_strsep_quoted(&test1, ',', '|', AST_STRSEP_TRIM);
|
||||
ast_test_validate(test, 0 == strcmp("| i\\'m a test|", test2));
|
||||
|
||||
test2 = ast_strsep_quoted(&test1, ',', '|', AST_STRSEP_TRIM | AST_STRSEP_UNESCAPE);
|
||||
ast_test_validate(test, 0 == strcmp("| i'm a, test|", test2));
|
||||
|
||||
test2 = ast_strsep_quoted(&test1, ',', '|', AST_STRSEP_ALL);
|
||||
ast_test_validate(test, 0 == strcmp("i'm a, test", test2));
|
||||
|
||||
test2 = ast_strsep_quoted(&test1, ',', '|', AST_STRSEP_TRIM | AST_STRSEP_UNESCAPE);
|
||||
ast_test_validate(test, 0 == strcmp("e,nd", test2));
|
||||
|
||||
test2 = ast_strsep_quoted(&test1, ',', '|', AST_STRSEP_TRIM | AST_STRSEP_UNESCAPE);
|
||||
ast_test_validate(test, 0 == strcmp("end", test2));
|
||||
|
||||
|
||||
// nothing failed; we're all good!
|
||||
return AST_TEST_PASS;
|
||||
}
|
||||
|
||||
static int test_semi(char *string1, char *string2, int test_len)
|
||||
{
|
||||
char *test2 = NULL;
|
||||
@@ -740,6 +877,7 @@ static int unload_module(void)
|
||||
AST_TEST_UNREGISTER(begins_with_test);
|
||||
AST_TEST_UNREGISTER(ends_with_test);
|
||||
AST_TEST_UNREGISTER(strsep_test);
|
||||
AST_TEST_UNREGISTER(strsep_quoted_test);
|
||||
AST_TEST_UNREGISTER(escape_semicolons_test);
|
||||
AST_TEST_UNREGISTER(escape_test);
|
||||
AST_TEST_UNREGISTER(strings_match);
|
||||
@@ -754,6 +892,7 @@ static int load_module(void)
|
||||
AST_TEST_REGISTER(begins_with_test);
|
||||
AST_TEST_REGISTER(ends_with_test);
|
||||
AST_TEST_REGISTER(strsep_test);
|
||||
AST_TEST_REGISTER(strsep_quoted_test);
|
||||
AST_TEST_REGISTER(escape_semicolons_test);
|
||||
AST_TEST_REGISTER(escape_test);
|
||||
AST_TEST_REGISTER(strings_match);
|
||||
|
Reference in New Issue
Block a user