diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_strings.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/test_strings.c b/tests/test_strings.c index 127ee789d..05cc8df84 100644 --- a/tests/test_strings.c +++ b/tests/test_strings.c @@ -387,6 +387,74 @@ AST_TEST_DEFINE(strsep_test) return AST_TEST_PASS; } +static int test_semi(char *string1, char *string2, int test_len) +{ + char *test2 = NULL; + if (test_len >= 0) { + test2 = ast_alloca(test_len); + *test2 = '\0'; + } + ast_escape_semicolons(string1, test2, test_len); + if (test2 != NULL && strcmp(string2, test2) == 0) { + return 1; + } else { + return 0; + } +} + +AST_TEST_DEFINE(escape_semicolons_test) +{ + switch (cmd) { + case TEST_INIT: + info->name = "escape_semicolons"; + info->category = "/main/strings/"; + info->summary = "Test ast_escape_semicolons"; + info->description = "Test ast_escape_semicolons"; + return AST_TEST_NOT_RUN; + case TEST_EXECUTE: + break; + } + + + ast_test_validate(test, test_semi("this is a ;test", "this is a \\;test", 18)); + ast_test_validate(test, test_semi(";", "\\;", 3)); + + /* The following tests should return empty because there's not enough room to output + * an escaped ; or even a single character. + */ + ast_test_validate(test, test_semi(";", "", 0)); + ast_test_validate(test, test_semi(";", "", 1)); + ast_test_validate(test, test_semi(";", "", 2)); + ast_test_validate(test, test_semi("x", "", 0)); + ast_test_validate(test, test_semi("x", "", 1)); + + /* At least some output should be produced now. */ + ast_test_validate(test, test_semi("xx;xx", "x", 2)); + ast_test_validate(test, test_semi("xx;xx", "xx", 3)); + + /* There's still not enough room to output \; so + * don't even print the \ + */ + ast_test_validate(test, test_semi("xx;xx", "xx", 4)); + + ast_test_validate(test, test_semi("xx;xx", "xx\\;", 5)); + ast_test_validate(test, test_semi("xx;xx", "xx\\;x", 6)); + ast_test_validate(test, test_semi("xx;xx", "xx\\;xx", 7)); + ast_test_validate(test, test_semi("xx;xx", "xx\\;xx", 8)); + + /* Random stuff */ + ast_test_validate(test, test_semi("xx;xx;this is a test", "xx\\;xx\\;this is a test", 32)); + ast_test_validate(test, test_semi(";;;;;", "\\;\\;\\;\\;\\;", 32)); + ast_test_validate(test, test_semi(";;;;;", "\\;\\;\\;\\;", 10)); + ast_test_validate(test, test_semi(";;;;;", "\\;\\;\\;\\;\\;", 11)); + ast_test_validate(test, test_semi(";;\\;;;", "\\;\\;\\\\;\\;\\;", 32)); + + ast_test_status_update(test, "This test should produce 2 'ast_escape_semicolons: FRACK!, Failed assertion' messages.\n"); + ast_test_validate(test, !test_semi(NULL, "xx\\;xx", 8)); + ast_test_validate(test, !test_semi("xx;xx", "xx\\;xx", -1)); + + return AST_TEST_PASS; +} static int unload_module(void) { @@ -394,6 +462,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(escape_semicolons_test); return 0; } @@ -403,6 +472,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(escape_semicolons_test); return AST_MODULE_LOAD_SUCCESS; } |