Asterisk - The Open Source Telephony Project GIT-master-7e7a603
Macros | Functions | Variables
test_aeap_transport.c File Reference
#include "asterisk.h"
#include "asterisk/http.h"
#include "asterisk/test.h"
#include "asterisk/module.h"
#include "../res/res_aeap/transport.h"
Include dependency graph for test_aeap_transport.c:

Go to the source code of this file.

Macros

#define ADDR   "127.0.0.1:8088"
 
#define CATEGORY   "/res/aeap/transport/"
 
#define TRANSPORT_PROTOCOL   "echo"
 
#define TRANSPORT_PROTOCOL_INVALID   "invalid"
 
#define TRANSPORT_TIMEOUT   2000
 
#define TRANSPORT_URL   "ws://" ADDR "/ws"
 
#define TRANSPORT_URL_INVALID   "ws://" ADDR "/invalid"
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
 AST_TEST_DEFINE (transport_binary)
 
 AST_TEST_DEFINE (transport_connect)
 
 AST_TEST_DEFINE (transport_connect_fail)
 
 AST_TEST_DEFINE (transport_create)
 
 AST_TEST_DEFINE (transport_create_invalid)
 
 AST_TEST_DEFINE (transport_string)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Asterisk External Application Protocol Transport Tests" , .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, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .requires = "res_aeap", }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_http_serverhttp_server
 

Macro Definition Documentation

◆ ADDR

#define ADDR   "127.0.0.1:8088"

Definition at line 35 of file test_aeap_transport.c.

◆ CATEGORY

#define CATEGORY   "/res/aeap/transport/"

Definition at line 33 of file test_aeap_transport.c.

◆ TRANSPORT_PROTOCOL

#define TRANSPORT_PROTOCOL   "echo"

Definition at line 38 of file test_aeap_transport.c.

◆ TRANSPORT_PROTOCOL_INVALID

#define TRANSPORT_PROTOCOL_INVALID   "invalid"

Definition at line 39 of file test_aeap_transport.c.

◆ TRANSPORT_TIMEOUT

#define TRANSPORT_TIMEOUT   2000

Definition at line 40 of file test_aeap_transport.c.

◆ TRANSPORT_URL

#define TRANSPORT_URL   "ws://" ADDR "/ws"

Definition at line 36 of file test_aeap_transport.c.

◆ TRANSPORT_URL_INVALID

#define TRANSPORT_URL_INVALID   "ws://" ADDR "/invalid"

Definition at line 37 of file test_aeap_transport.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 249 of file test_aeap_transport.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 249 of file test_aeap_transport.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 249 of file test_aeap_transport.c.

◆ AST_TEST_DEFINE() [1/6]

AST_TEST_DEFINE ( transport_binary  )

Definition at line 150 of file test_aeap_transport.c.

151{
152 RAII_VAR(struct aeap_transport *, transport, NULL, aeap_transport_destroy);
153 int num = 38;
154 enum AST_AEAP_DATA_TYPE rtype;
155
156 switch (cmd) {
157 case TEST_INIT:
158 info->name = __func__;
159 info->explicit_only = 0;
160 info->category = CATEGORY;
161 info->summary = "test binary I/O from an AEAP transport";
162 info->description = info->summary;
163 return AST_TEST_NOT_RUN;
164 case TEST_EXECUTE:
165 break;
166 }
167
168 ast_test_validate(test, (transport = aeap_transport_create_and_connect(
170
171 ast_test_validate(test, aeap_transport_write(transport, &num, sizeof(num),
172 AST_AEAP_DATA_TYPE_BINARY) == sizeof(num));
173 ast_test_validate(test, aeap_transport_read(transport, &num,
174 sizeof(num), &rtype) == sizeof(num));
175 ast_test_validate(test, rtype == AST_AEAP_DATA_TYPE_BINARY);
176 ast_test_validate(test, num == 38);
177
178 return AST_TEST_PASS;
179}
def info(msg)
AST_AEAP_DATA_TYPE
Supported Asterisk external application data types.
Definition: res_aeap.h:135
@ AST_AEAP_DATA_TYPE_BINARY
Definition: res_aeap.h:137
#define NULL
Definition: resample.c:96
Asterisk external application transport structure to be "derived" by specific transport implementatio...
Definition: transport.h:98
@ 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 TRANSPORT_URL
#define CATEGORY
#define TRANSPORT_TIMEOUT
#define TRANSPORT_PROTOCOL
intmax_t aeap_transport_write(struct aeap_transport *transport, const void *buf, intmax_t size, enum AST_AEAP_DATA_TYPE wtype)
Write data to the transport.
Definition: transport.c:146
void aeap_transport_destroy(struct aeap_transport *transport)
Destroy a transport.
Definition: transport.c:117
intmax_t aeap_transport_read(struct aeap_transport *transport, void *buf, intmax_t size, enum AST_AEAP_DATA_TYPE *rtype)
Read data from the transport.
Definition: transport.c:134
struct aeap_transport * aeap_transport_create_and_connect(const char *type, const char *url, const char *protocol, int timeout)
Create an Asterisk external application transport, and connect it.
Definition: transport.c:68
#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 aeap_transport_create_and_connect(), aeap_transport_destroy(), aeap_transport_read(), aeap_transport_write(), AST_AEAP_DATA_TYPE_BINARY, AST_TEST_NOT_RUN, AST_TEST_PASS, CATEGORY, sip_to_pjsip::info(), NULL, RAII_VAR, TEST_EXECUTE, TEST_INIT, TRANSPORT_PROTOCOL, TRANSPORT_TIMEOUT, and TRANSPORT_URL.

◆ AST_TEST_DEFINE() [2/6]

AST_TEST_DEFINE ( transport_connect  )

Definition at line 86 of file test_aeap_transport.c.

87{
89
90 switch (cmd) {
91 case TEST_INIT:
92 info->name = __func__;
93 info->explicit_only = 0;
94 info->category = CATEGORY;
95 info->summary = "test connecting to an AEAP transport";
96 info->description = info->summary;
97 return AST_TEST_NOT_RUN;
98 case TEST_EXECUTE:
99 break;
100 }
101
102 /* Type is based off the scheme, so just pass in the URL for the type */
103 ast_test_validate(test, (transport = aeap_transport_create_and_connect(
105
106 ast_test_validate(test, aeap_transport_is_connected(transport));
107 ast_test_validate(test, !aeap_transport_disconnect(transport));
108 ast_test_validate(test, !aeap_transport_is_connected(transport));
109
110 return AST_TEST_PASS;
111}
int aeap_transport_is_connected(struct aeap_transport *transport)
Whether or not the transport is in a connected state.
Definition: transport.c:85
int aeap_transport_disconnect(struct aeap_transport *transport)
Disconnect a transport.
Definition: transport.c:94

References aeap_transport_create_and_connect(), aeap_transport_destroy(), aeap_transport_disconnect(), aeap_transport_is_connected(), AST_TEST_NOT_RUN, AST_TEST_PASS, CATEGORY, sip_to_pjsip::info(), NULL, RAII_VAR, TEST_EXECUTE, TEST_INIT, TRANSPORT_PROTOCOL, TRANSPORT_TIMEOUT, and TRANSPORT_URL.

◆ AST_TEST_DEFINE() [3/6]

AST_TEST_DEFINE ( transport_connect_fail  )

Definition at line 113 of file test_aeap_transport.c.

114{
115 RAII_VAR(struct aeap_transport *, transport, NULL, aeap_transport_destroy);
116
117 switch (cmd) {
118 case TEST_INIT:
119 info->name = __func__;
120 info->explicit_only = 0;
121 info->category = CATEGORY;
122 info->summary = "test connecting failure for an AEAP transport";
123 info->description = info->summary;
124 return AST_TEST_NOT_RUN;
125 case TEST_EXECUTE:
126 break;
127 }
128
129 /* Test invalid address */
130 ast_test_validate(test, (transport = aeap_transport_create(TRANSPORT_URL)));
131
132 ast_test_validate(test, aeap_transport_connect(transport,
134
135 ast_test_validate(test, !aeap_transport_is_connected(transport));
136
137 aeap_transport_destroy(transport);
138
139 /* /\* Test invalid protocol *\/ */
140 ast_test_validate(test, (transport = aeap_transport_create(TRANSPORT_URL)));
141
142 ast_test_validate(test, aeap_transport_connect(transport,
144
145 ast_test_validate(test, !aeap_transport_is_connected(transport));
146
147 return AST_TEST_PASS;
148}
#define TRANSPORT_PROTOCOL_INVALID
#define TRANSPORT_URL_INVALID
int aeap_transport_connect(struct aeap_transport *transport, const char *url, const char *protocol, int timeout)
Connect a transport.
Definition: transport.c:48
struct aeap_transport * aeap_transport_create(const char *type)
Create an Asterisk external application transport.
Definition: transport.c:27

References aeap_transport_connect(), aeap_transport_create(), aeap_transport_destroy(), aeap_transport_is_connected(), AST_TEST_NOT_RUN, AST_TEST_PASS, CATEGORY, sip_to_pjsip::info(), NULL, RAII_VAR, TEST_EXECUTE, TEST_INIT, TRANSPORT_PROTOCOL, TRANSPORT_PROTOCOL_INVALID, TRANSPORT_TIMEOUT, TRANSPORT_URL, and TRANSPORT_URL_INVALID.

◆ AST_TEST_DEFINE() [4/6]

AST_TEST_DEFINE ( transport_create  )

Definition at line 64 of file test_aeap_transport.c.

65{
67
68 switch (cmd) {
69 case TEST_INIT:
70 info->name = __func__;
71 info->explicit_only = 0;
72 info->category = CATEGORY;
73 info->summary = "test creating an AEAP transport";
74 info->description = info->summary;
75 return AST_TEST_NOT_RUN;
76 case TEST_EXECUTE:
77 break;
78 }
79
80 /* Type is based off the scheme, so just pass in the URL here */
81 ast_test_validate(test, (transport = aeap_transport_create(TRANSPORT_URL)));
82
83 return AST_TEST_PASS;
84}

References aeap_transport_create(), aeap_transport_destroy(), AST_TEST_NOT_RUN, AST_TEST_PASS, CATEGORY, sip_to_pjsip::info(), NULL, RAII_VAR, TEST_EXECUTE, TEST_INIT, and TRANSPORT_URL.

◆ AST_TEST_DEFINE() [5/6]

AST_TEST_DEFINE ( transport_create_invalid  )

Definition at line 42 of file test_aeap_transport.c.

43{
45
46 switch (cmd) {
47 case TEST_INIT:
48 info->name = __func__;
49 info->explicit_only = 0;
50 info->category = CATEGORY;
51 info->summary = "test creating an AEAP invalid transport type";
52 info->description = info->summary;
53 return AST_TEST_NOT_RUN;
54 case TEST_EXECUTE:
55 break;
56 }
57
58 /* Transport is expected to be NULL here */
59 ast_test_validate(test, !(transport = aeap_transport_create("invalid")));
60
61 return AST_TEST_PASS;
62}

References aeap_transport_create(), aeap_transport_destroy(), AST_TEST_NOT_RUN, AST_TEST_PASS, CATEGORY, sip_to_pjsip::info(), NULL, RAII_VAR, TEST_EXECUTE, and TEST_INIT.

◆ AST_TEST_DEFINE() [6/6]

AST_TEST_DEFINE ( transport_string  )

Definition at line 181 of file test_aeap_transport.c.

182{
183 RAII_VAR(struct aeap_transport *, transport, NULL, aeap_transport_destroy);
184 char buf[16];
185 enum AST_AEAP_DATA_TYPE rtype;
186
187 switch (cmd) {
188 case TEST_INIT:
189 info->name = __func__;
190 info->explicit_only = 0;
191 info->category = CATEGORY;
192 info->summary = "test string I/O from an AEAP transport";
193 info->description = info->summary;
194 return AST_TEST_NOT_RUN;
195 case TEST_EXECUTE:
196 break;
197 }
198
199 ast_test_validate(test, (transport = aeap_transport_create_and_connect(
201
202 ast_test_validate(test, aeap_transport_write(transport, "foo bar baz", 11,
204 ast_test_validate(test, aeap_transport_read(transport, buf,
205 sizeof(buf) / sizeof(char), &rtype) == 11);
206 ast_test_validate(test, rtype == AST_AEAP_DATA_TYPE_STRING);
207 ast_test_validate(test, !strcmp(buf, "foo bar baz"));
208
209 return AST_TEST_PASS;
210}
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
@ AST_AEAP_DATA_TYPE_STRING
Definition: res_aeap.h:138

References aeap_transport_create_and_connect(), aeap_transport_destroy(), aeap_transport_read(), aeap_transport_write(), AST_AEAP_DATA_TYPE_STRING, AST_TEST_NOT_RUN, AST_TEST_PASS, buf, CATEGORY, sip_to_pjsip::info(), NULL, RAII_VAR, TEST_EXECUTE, TEST_INIT, TRANSPORT_PROTOCOL, TRANSPORT_TIMEOUT, and TRANSPORT_URL.

◆ load_module()

static int load_module ( void  )
static

Definition at line 214 of file test_aeap_transport.c.

215{
216 if (!(http_server = ast_http_test_server_get("aeap transport http server", NULL))) {
218 }
219
220 AST_TEST_REGISTER(transport_string);
221 AST_TEST_REGISTER(transport_binary);
222 AST_TEST_REGISTER(transport_connect_fail);
223 AST_TEST_REGISTER(transport_connect);
225 AST_TEST_REGISTER(transport_create_invalid);
226
228}
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
static int transport_create(void *data)
Create a pjsip transport.
#define AST_TEST_REGISTER(cb)
Definition: test.h:127
static struct ast_http_server * http_server

References AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, AST_TEST_REGISTER, http_server, NULL, and transport_create().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 230 of file test_aeap_transport.c.

231{
232 AST_TEST_UNREGISTER(transport_string);
233 AST_TEST_UNREGISTER(transport_binary);
234 AST_TEST_UNREGISTER(transport_connect_fail);
235 AST_TEST_UNREGISTER(transport_connect);
237 AST_TEST_UNREGISTER(transport_create_invalid);
238
239 ast_http_test_server_discard(http_server);
240
241 return 0;
242}
#define AST_TEST_UNREGISTER(cb)
Definition: test.h:128

References AST_TEST_UNREGISTER, http_server, and transport_create().

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Asterisk External Application Protocol Transport Tests" , .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, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .requires = "res_aeap", }
static

Definition at line 249 of file test_aeap_transport.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 249 of file test_aeap_transport.c.

◆ http_server

struct ast_http_server* http_server
static

Definition at line 212 of file test_aeap_transport.c.

Referenced by load_module(), and unload_module().