Asterisk - The Open Source Telephony Project GIT-master-f36a736
Functions | Variables
test_xml_escape.c File Reference

Test ast_xml_escape. More...

#include "asterisk.h"
#include "asterisk/utils.h"
#include "asterisk/module.h"
#include "asterisk/test.h"
Include dependency graph for test_xml_escape.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
 AST_TEST_DEFINE (xml_escape_test)
 
static int load_module (void)
 
static void test_xml (struct ast_test *test, const char *input, const char *expected, int max_len, int expected_res)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Skeleton (sample) Test" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static enum ast_test_result_state test_res = AST_TEST_PASS
 

Detailed Description

Test ast_xml_escape.

Author
David M. Lee, II <dlee@digium.com> 

Definition in file test_xml_escape.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 116 of file test_xml_escape.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 116 of file test_xml_escape.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 116 of file test_xml_escape.c.

◆ AST_TEST_DEFINE()

AST_TEST_DEFINE ( xml_escape_test  )

Definition at line 62 of file test_xml_escape.c.

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
80
81 /* happy path */
82 input = "encode me: <&>'\"";
83 expected = "encode me: &lt;&amp;&gt;&apos;&quot;";
84 test_xml(test, input, expected, -1, 0);
85
86 /* size 0 should fail without changing anything */
87 input = "foo";
88 expected = "";
89 test_xml(test, input, expected, 0, -1);
90
91 /* truncate chars */
92 input = "<truncated>";
93 expected = "&lt;trunc";
94 test_xml(test, input, expected, 10, -1);
95
96 /* truncate entity */
97 input = "trunc<";
98 expected = "trunc";
99 test_xml(test, input, expected, 9, -1);
100
101 return test_res;
102}
static int input(yyscan_t yyscanner)
Definition: ast_expr2f.c:1570
def info(msg)
@ TEST_INIT
Definition: test.h:200
@ TEST_EXECUTE
Definition: test.h:201
@ AST_TEST_PASS
Definition: test.h:195
@ AST_TEST_NOT_RUN
Definition: test.h:194
static void test_xml(struct ast_test *test, const char *input, const char *expected, int max_len, int expected_res)
static enum ast_test_result_state test_res

References AST_TEST_NOT_RUN, AST_TEST_PASS, sip_to_pjsip::info(), input(), TEST_EXECUTE, TEST_INIT, test_res, and test_xml().

◆ load_module()

static int load_module ( void  )
static

Definition at line 110 of file test_xml_escape.c.

111{
112 AST_TEST_REGISTER(xml_escape_test);
114}
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
#define AST_TEST_REGISTER(cb)
Definition: test.h:127

References AST_MODULE_LOAD_SUCCESS, and AST_TEST_REGISTER.

◆ test_xml()

static void test_xml ( struct ast_test *  test,
const char *  input,
const char *  expected,
int  max_len,
int  expected_res 
)
static

Definition at line 41 of file test_xml_escape.c.

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);
54 }
55
56 if (strcmp(expected, actual) != 0) {
57 ast_test_status_update(test, "Expected output '%s', got '%s'\n", expected, actual);
59 }
60}
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
@ AST_TEST_FAIL
Definition: test.h:196
int ast_xml_escape(const char *string, char *outbuf, size_t buflen)
Escape reserved characters for use in XML.
Definition: utils.c:864

References AST_TEST_FAIL, ast_test_status_update, ast_xml_escape(), input(), and test_res.

Referenced by AST_TEST_DEFINE().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 104 of file test_xml_escape.c.

105{
106 AST_TEST_UNREGISTER(xml_escape_test);
107 return 0;
108}
#define AST_TEST_UNREGISTER(cb)
Definition: test.h:128

References AST_TEST_UNREGISTER.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Skeleton (sample) Test" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 116 of file test_xml_escape.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 116 of file test_xml_escape.c.

◆ test_res

enum ast_test_result_state test_res = AST_TEST_PASS
static

Definition at line 39 of file test_xml_escape.c.

Referenced by AST_TEST_DEFINE(), and test_xml().