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

URI Unit Tests. More...

#include "asterisk.h"
#include "asterisk/test.h"
#include "asterisk/module.h"
#include "asterisk/uri.h"
Include dependency graph for test_uri.c:

Go to the source code of this file.

Macros

#define CATEGORY   "/main/uri/"
 
#define VALIDATE(value, expected_value)
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
 AST_TEST_DEFINE (uri_default_http)
 
 AST_TEST_DEFINE (uri_default_http_secure)
 
 AST_TEST_DEFINE (uri_parse)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "URI test module" , .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 const char * scenarios [][7]
 

Detailed Description

URI Unit Tests.

Author
Kevin Harwell kharw.nosp@m.ell@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

Definition in file test_uri.c.

Macro Definition Documentation

◆ CATEGORY

#define CATEGORY   "/main/uri/"

Definition at line 38 of file test_uri.c.

◆ VALIDATE

#define VALIDATE (   value,
  expected_value 
)
Value:
do { ast_test_validate(test, \
(value == expected_value) || \
(value && expected_value && \
!strcmp(value, expected_value))); \
} while (0)
int value
Definition: syslog.c:37

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 152 of file test_uri.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 152 of file test_uri.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 152 of file test_uri.c.

◆ AST_TEST_DEFINE() [1/3]

AST_TEST_DEFINE ( uri_default_http  )

Definition at line 88 of file test_uri.c.

89{
90 RAII_VAR(struct ast_uri *, uri, NULL, ao2_cleanup);
91
92 switch (cmd) {
93 case TEST_INIT:
94 info->name = __func__;
95 info->category = CATEGORY;
96 info->summary = "parse an http uri with host only";
97 info->description = info->summary;
98 return AST_TEST_NOT_RUN;
99 case TEST_EXECUTE:
100 break;
101 }
102
103 ast_test_validate(test, (uri = ast_uri_parse_http("localhost")));
104 ast_test_validate(test, !strcmp(ast_uri_scheme(uri), "http"));
105 ast_test_validate(test, !strcmp(ast_uri_host(uri), "localhost"));
106 ast_test_validate(test, !strcmp(ast_uri_port(uri), "80"));
107 ast_test_validate(test, !ast_uri_is_secure(uri));
108
109 return AST_TEST_PASS;
110}
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
def info(msg)
#define NULL
Definition: resample.c:96
Stores parsed uri information.
Definition: uri.c:30
@ 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
#define CATEGORY
Definition: test_uri.c:38
const char * ast_uri_scheme(const struct ast_uri *uri)
Retrieve the uri scheme.
Definition: uri.c:115
struct ast_uri * ast_uri_parse_http(const char *uri)
Parse the given http uri into a structure.
Definition: uri.c:290
const char * ast_uri_port(const struct ast_uri *uri)
Retrieve the uri port.
Definition: uri.c:130
int attribute_pure ast_uri_is_secure(const struct ast_uri *uri)
Retrieve if the uri is of a secure type.
Definition: uri.c:145
const char * ast_uri_host(const struct ast_uri *uri)
Retrieve the uri host.
Definition: uri.c:125
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941

References ao2_cleanup, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_uri_host(), ast_uri_is_secure(), ast_uri_parse_http(), ast_uri_port(), ast_uri_scheme(), CATEGORY, sip_to_pjsip::info(), NULL, RAII_VAR, TEST_EXECUTE, and TEST_INIT.

◆ AST_TEST_DEFINE() [2/3]

AST_TEST_DEFINE ( uri_default_http_secure  )

Definition at line 112 of file test_uri.c.

113{
114 RAII_VAR(struct ast_uri *, uri, NULL, ao2_cleanup);
115
116 switch (cmd) {
117 case TEST_INIT:
118 info->name = __func__;
119 info->category = CATEGORY;
120 info->summary = "parse an https uri with host only";
121 info->description = info->summary;
122 return AST_TEST_NOT_RUN;
123 case TEST_EXECUTE:
124 break;
125 }
126
127 ast_test_validate(test, (uri = ast_uri_parse_http("https://localhost")));
128 ast_test_validate(test, !strcmp(ast_uri_scheme(uri), "https"));
129 ast_test_validate(test, !strcmp(ast_uri_host(uri), "localhost"));
130 ast_test_validate(test, !strcmp(ast_uri_port(uri), "443"));
131 ast_test_validate(test, ast_uri_is_secure(uri));
132
133 return AST_TEST_PASS;
134}

References ao2_cleanup, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_uri_host(), ast_uri_is_secure(), ast_uri_parse_http(), ast_uri_port(), ast_uri_scheme(), CATEGORY, sip_to_pjsip::info(), NULL, RAII_VAR, TEST_EXECUTE, and TEST_INIT.

◆ AST_TEST_DEFINE() [3/3]

AST_TEST_DEFINE ( uri_parse  )

Definition at line 51 of file test_uri.c.

52{
53#define VALIDATE(value, expected_value) \
54 do { ast_test_validate(test, \
55 (value == expected_value) || \
56 (value && expected_value && \
57 !strcmp(value, expected_value))); \
58 } while (0)
59
60 int i;
61
62 switch (cmd) {
63 case TEST_INIT:
64 info->name = __func__;
65 info->category = CATEGORY;
66 info->summary = "Uri parsing scenarios";
67 info->description = "For each scenario validate result(s)";
68 return AST_TEST_NOT_RUN;
69 case TEST_EXECUTE:
70 break;
71 }
72 for (i = 0; i < ARRAY_LEN(scenarios); ++i) {
73 RAII_VAR(struct ast_uri *, uri, NULL, ao2_cleanup);
74 const char **scenario = scenarios[i];
75
76 ast_test_validate(test, (uri = ast_uri_parse(scenario[0])));
77 VALIDATE(ast_uri_scheme(uri), scenario[1]);
78 VALIDATE(ast_uri_user_info(uri), scenario[2]);
79 VALIDATE(ast_uri_host(uri), scenario[3]);
80 VALIDATE(ast_uri_port(uri), scenario[4]);
81 VALIDATE(ast_uri_path(uri), scenario[5]);
82 VALIDATE(ast_uri_query(uri), scenario[6]);
83 }
84
85 return AST_TEST_PASS;
86}
#define VALIDATE(value, expected_value)
static const char * scenarios[][7]
Definition: test_uri.c:40
const char * ast_uri_path(const struct ast_uri *uri)
Retrieve the uri path.
Definition: uri.c:135
const char * ast_uri_query(const struct ast_uri *uri)
Retrieve the uri query parameters.
Definition: uri.c:140
const char * ast_uri_user_info(const struct ast_uri *uri)
Retrieve the uri user information.
Definition: uri.c:120
struct ast_uri * ast_uri_parse(const char *uri)
Parse the given uri into a structure.
Definition: uri.c:195
#define ARRAY_LEN(a)
Definition: utils.h:666

References ao2_cleanup, ARRAY_LEN, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_uri_host(), ast_uri_parse(), ast_uri_path(), ast_uri_port(), ast_uri_query(), ast_uri_scheme(), ast_uri_user_info(), CATEGORY, sip_to_pjsip::info(), NULL, RAII_VAR, scenarios, TEST_EXECUTE, TEST_INIT, and VALIDATE.

◆ load_module()

static int load_module ( void  )
static

Definition at line 136 of file test_uri.c.

137{
138 AST_TEST_REGISTER(uri_parse);
139 AST_TEST_REGISTER(uri_default_http);
140 AST_TEST_REGISTER(uri_default_http_secure);
142}
@ 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.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 144 of file test_uri.c.

145{
146 AST_TEST_UNREGISTER(uri_default_http_secure);
147 AST_TEST_UNREGISTER(uri_default_http);
148 AST_TEST_UNREGISTER(uri_parse);
149 return 0;
150}
#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 = "URI test module" , .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 152 of file test_uri.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 152 of file test_uri.c.

◆ scenarios

const char* scenarios[][7]
static

Definition at line 40 of file test_uri.c.

Referenced by AST_TEST_DEFINE().