| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
#include "asterisk.h" |
| 34 |
|
| 35 |
#include "asterisk/utils.h" |
| 36 |
#include "asterisk/module.h" |
| 37 |
#include "asterisk/test.h" |
| 38 |
|
| 39 |
static enum ast_test_result_state test_res = AST_TEST_PASS; |
| 40 |
|
| 41 |
static void test_xml(struct ast_test *test, const char *input, const char *expected, int max_len, int expected_res) |
| 42 |
{ |
| 43 |
char actual[256] = ""; |
| 44 |
int res; |
| 45 |
|
| 46 |
if (max_len == -1) { |
| 47 |
max_len = sizeof(actual); |
| 48 |
} |
| 49 |
|
| 50 |
res = ast_xml_escape(input, actual, max_len); |
| 51 |
if (res != expected_res) { |
| 52 |
ast_test_status_update(test, "Expected result '%d', got '%d'\n", expected_res, res); |
| 53 |
test_res = AST_TEST_FAIL; |
| 54 |
} |
| 55 |
|
| 56 |
if (strcmp(expected, actual) != 0) { |
| 57 |
ast_test_status_update(test, "Expected output '%s', got '%s'\n", expected, actual); |
| 58 |
test_res = AST_TEST_FAIL; |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
AST_TEST_DEFINE(xml_escape_test) |
| 63 |
{ |
| 64 |
char *input; |
| 65 |
char *expected; |
| 66 |
|
| 67 |
switch (cmd) { |
| 68 |
case TEST_INIT: |
| 69 |
info->name = "xml_escape_test"; |
| 70 |
info->category = "/main/xml_escape/"; |
| 71 |
info->summary = "Test XML escaping"; |
| 72 |
info->description = |
| 73 |
"Test XML escaping"; |
| 74 |
return AST_TEST_NOT_RUN; |
| 75 |
case TEST_EXECUTE: |
| 76 |
break; |
| 77 |
} |
| 78 |
|
| 79 |
test_res = AST_TEST_PASS; |
| 80 |
|
| 81 |
|
| 82 |
input = "encode me: <&>'\""; |
| 83 |
expected = "encode me: <&>'""; |
| 84 |
test_xml(test, input, expected, -1, 0); |
| 85 |
|
| 86 |
|
| 87 |
input = "foo"; |
| 88 |
expected = ""; |
| 89 |
test_xml(test, input, expected, 0, -1); |
| 90 |
|
| 91 |
|
| 92 |
input = "<truncated>"; |
| 93 |
expected = "<trunc"; |
| 94 |
test_xml(test, input, expected, 10, -1); |
| 95 |
|
| 96 |
|
| 97 |
input = "trunc<"; |
| 98 |
expected = "trunc"; |
| 99 |
test_xml(test, input, expected, 9, -1); |
| 100 |
|
| 101 |
return test_res; |
| 102 |
} |
| 103 |
|
| 104 |
static int unload_module(void) |
| 105 |
{ |
| 106 |
AST_TEST_UNREGISTER(xml_escape_test); |
| 107 |
return 0; |
| 108 |
} |
| 109 |
|
| 110 |
static int load_module(void) |
| 111 |
{ |
| 112 |
AST_TEST_REGISTER(xml_escape_test); |
| 113 |
return AST_MODULE_LOAD_SUCCESS; |
| 114 |
} |
| 115 |
|
| 116 |
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Skeleton (sample) Test"); |