summaryrefslogtreecommitdiff
path: root/tests/test_utils.c
diff options
context:
space:
mode:
authorKinsey Moore <kmoore@digium.com>2014-08-27 15:39:35 +0000
committerKinsey Moore <kmoore@digium.com>2014-08-27 15:39:35 +0000
commitbf850181076c786d2c9e5e7f23e205547c7140cb (patch)
tree3a384bb94539e77298c351ae79dcff9453bc0b25 /tests/test_utils.c
parentd199536a04690e3034d02243e197071d70fc4f9c (diff)
CallerID: Fix parsing of malformed callerid
This allows the callerid parsing function to handle malformed input strings and strings containing escaped and unescaped double quotes. This also adds a unittest to cover many of the cases where the parsing algorithm previously failed. Review: https://reviewboard.asterisk.org/r/3923/ Review: https://reviewboard.asterisk.org/r/3933/ ........ Merged revisions 422112 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 422113 from http://svn.asterisk.org/svn/asterisk/branches/11 ........ Merged revisions 422114 from http://svn.asterisk.org/svn/asterisk/branches/12 ........ Merged revisions 422154 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@422158 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'tests/test_utils.c')
-rw-r--r--tests/test_utils.c98
1 files changed, 98 insertions, 0 deletions
diff --git a/tests/test_utils.c b/tests/test_utils.c
index 9150fccf4..e4f6e0a52 100644
--- a/tests/test_utils.c
+++ b/tests/test_utils.c
@@ -546,6 +546,100 @@ AST_TEST_DEFINE(crypt_test)
}
+struct quote_set {
+ char *input;
+ char *output;
+};
+
+AST_TEST_DEFINE(quote_mutation)
+{
+ char escaped[64];
+ static const struct quote_set escape_sets[] = {
+ {"\"string\"", "\\\"string\\\""},
+ {"\"string", "\\\"string"},
+ {"string\"", "string\\\""},
+ {"string", "string"},
+ {"str\"ing", "str\\\"ing"},
+ {"\"", "\\\""},
+ {"\\\"", "\\\\\\\""},
+ };
+ int i;
+
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = "quote_mutation";
+ info->category = "/main/utils/";
+ info->summary = "Test mutation of quotes in strings";
+ info->description =
+ "This tests escaping and unescaping of quotes in strings to "
+ "verify that the original string is recovered.";
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+
+ for (i = 0; i < ARRAY_LEN(escape_sets); i++) {
+ ast_escape_quoted(escape_sets[i].input, escaped, sizeof(escaped));
+
+ if (strcmp(escaped, escape_sets[i].output)) {
+ ast_test_status_update(test,
+ "Expected escaped string '%s' instead of '%s'\n",
+ escape_sets[i].output, escaped);
+ return AST_TEST_FAIL;
+ }
+
+ ast_unescape_quoted(escaped);
+ if (strcmp(escaped, escape_sets[i].input)) {
+ ast_test_status_update(test,
+ "Expected unescaped string '%s' instead of '%s'\n",
+ escape_sets[i].input, escaped);
+ return AST_TEST_FAIL;
+ }
+ }
+
+ return AST_TEST_PASS;
+}
+
+AST_TEST_DEFINE(quote_unescaping)
+{
+ static const struct quote_set escape_sets[] = {
+ {"\"string\"", "\"string\""},
+ {"\\\"string\"", "\"string\""},
+ {"\"string\\\"", "\"string\""},
+ {"str\\ing", "string"},
+ {"string\\", "string"},
+ {"\\string", "string"},
+ };
+ int i;
+
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = "quote_unescaping";
+ info->category = "/main/utils/";
+ info->summary = "Test unescaping of off-nominal strings";
+ info->description =
+ "This tests unescaping of strings which contain a mix of "
+ "escaped and unescaped sequences.";
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+
+ for (i = 0; i < ARRAY_LEN(escape_sets); i++) {
+ RAII_VAR(char *, escaped, ast_strdup(escape_sets[i].input), ast_free);
+
+ ast_unescape_quoted(escaped);
+ if (strcmp(escaped, escape_sets[i].output)) {
+ ast_test_status_update(test,
+ "Expected unescaped string '%s' instead of '%s'\n",
+ escape_sets[i].output, escaped);
+ return AST_TEST_FAIL;
+ }
+ }
+
+ return AST_TEST_PASS;
+}
+
static int unload_module(void)
{
AST_TEST_UNREGISTER(uri_encode_decode_test);
@@ -558,6 +652,8 @@ static int unload_module(void)
AST_TEST_UNREGISTER(agi_loaded_test);
AST_TEST_UNREGISTER(safe_mkdir_test);
AST_TEST_UNREGISTER(crypt_test);
+ AST_TEST_UNREGISTER(quote_mutation);
+ AST_TEST_UNREGISTER(quote_unescaping);
return 0;
}
@@ -573,6 +669,8 @@ static int load_module(void)
AST_TEST_REGISTER(agi_loaded_test);
AST_TEST_REGISTER(safe_mkdir_test);
AST_TEST_REGISTER(crypt_test);
+ AST_TEST_REGISTER(quote_mutation);
+ AST_TEST_REGISTER(quote_unescaping);
return AST_MODULE_LOAD_SUCCESS;
}