36 #define CATEGORY "/res/aeap/"
38 #define ADDR "127.0.0.1:8088"
39 #define AEAP_TRANSPORT_TYPE "ws"
40 #define AEAP_REMOTE_URL "ws://" ADDR "/ws"
41 #define AEAP_REMOTE_PROTOCOL "echo"
42 #define AEAP_MESSAGE_ID "foo"
43 #define AEAP_CONNECTION_TIMEOUT 2000
51 info->name = __func__;
52 info->explicit_only = 0;
54 info->summary =
"test creating and connecting to an AEAP application";
55 info->description = info->summary;
56 return AST_TEST_NOT_RUN;
62 NULL, AEAP_REMOTE_URL, AEAP_REMOTE_PROTOCOL, AEAP_CONNECTION_TIMEOUT)));
67 static void handle_string(
struct ast_aeap *aeap,
const char *buf, intmax_t size)
71 if (strstr(buf, AEAP_MESSAGE_ID)) {
94 info->name = __func__;
95 info->explicit_only = 0;
97 info->summary =
"test an AEAP application string handler";
98 info->description = info->summary;
99 return AST_TEST_NOT_RUN;
109 &aeap_params, AEAP_REMOTE_URL, AEAP_REMOTE_PROTOCOL, AEAP_CONNECTION_TIMEOUT)));
117 return passed == 2 ? AST_TEST_PASS : AST_TEST_FAIL;
128 ast_log(LOG_ERROR,
"Name '%s' did not equal '%s' for message '%s'",
136 {
"foo", handle_msg },
146 .response_handlers_size = ARRAY_LEN(handlers),
152 info->name = __func__;
153 info->explicit_only = 0;
155 info->summary =
"test an AEAP application response handler";
156 info->description = info->summary;
157 return AST_TEST_NOT_RUN;
166 tsx_params.
obj = name;
169 &aeap_params, AEAP_REMOTE_URL, AEAP_REMOTE_PROTOCOL, AEAP_CONNECTION_TIMEOUT)));
176 return passed ? AST_TEST_PASS : AST_TEST_FAIL;
186 .request_handlers_size = ARRAY_LEN(handlers),
192 info->name = __func__;
193 info->explicit_only = 0;
195 info->summary =
"test an AEAP application request handler";
196 info->description = info->summary;
197 return AST_TEST_NOT_RUN;
206 tsx_params.
obj = name;
209 &aeap_params, AEAP_REMOTE_URL, AEAP_REMOTE_PROTOCOL, AEAP_CONNECTION_TIMEOUT)));
216 return passed ? AST_TEST_PASS : AST_TEST_FAIL;
221 static int load_module(
void)
223 if (!(http_server = ast_http_test_server_get(
"aeap transport http server", NULL))) {
227 AST_TEST_REGISTER(create_and_connect);
228 AST_TEST_REGISTER(send_msg_handle_string);
229 AST_TEST_REGISTER(send_msg_handle_response);
230 AST_TEST_REGISTER(send_msg_handle_request);
235 static int unload_module(
void)
237 AST_TEST_UNREGISTER(send_msg_handle_request);
238 AST_TEST_UNREGISTER(send_msg_handle_response);
239 AST_TEST_UNREGISTER(send_msg_handle_string);
240 AST_TEST_UNREGISTER(create_and_connect);
242 ast_http_test_server_discard(http_server);
247 AST_MODULE_INFO(
ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT,
"Asterisk External Application Protocol Object Tests",
248 .support_level = AST_MODULE_SUPPORT_CORE,
250 .unload = unload_module,
251 .requires =
"res_aeap",
Asterisk External Application Protocol API.
Callbacks and other parameters used by an Asterisk external application object.
void ast_aeap_user_data_unregister(struct ast_aeap *aeap, const char *id)
Un-register a user data object.
Asterisk main include file. File version handling, generic pbx functions.
void(* on_string)(struct ast_aeap *aeap, const char *buf, intmax_t size)
Raised when string data is received.
Asterisk External Application Protocol Message API.
const struct ast_aeap_message_handler * request_handlers
int ast_aeap_message_is_named(const struct ast_aeap_message *message, const char *name)
Check whether or not a message's name matches the given one.
const struct ast_aeap_message_type * msg_type
int ast_aeap_send_msg_tsx(struct ast_aeap *aeap, struct ast_aeap_tsx_params *params)
Send a transaction based message to an external application using the given parameters.
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
void * ast_aeap_user_data_object_by_id(struct ast_aeap *aeap, const char *id)
Retrieve a registered user data object by its id.
Parameters to be used when sending a transaction based message.
const char * ast_aeap_message_id(const struct ast_aeap_message *message)
Retrieve a message id.
Asterisk JSON abstraction layer.
ast_aeap_on_timeout on_timeout
const char * ast_aeap_message_name(const struct ast_aeap_message *message)
Retrieve a message name.
Support for WebSocket connections within the Asterisk HTTP server and client WebSocket connections to...
struct ast_aeap * ast_aeap_create_and_connect(const char *type, const struct ast_aeap_params *params, const char *url, const char *protocol, int timeout)
Create and connect to an Asterisk external application.
int ast_aeap_user_data_register(struct ast_aeap *aeap, const char *id, void *obj, ast_aeap_user_obj_cleanup cleanup)
Register a user data object.
struct ast_aeap_message * ast_aeap_message_create_response(const struct ast_aeap_message_type *type, const char *name, const char *id, const void *params)
Create an Asterisk external application response object.
Asterisk external application base message.
An Asterisk external application message handler.
Module has failed to load, may be in an inconsistent state.
struct ast_aeap_message * msg
#define AST_TEST_DEFINE(hdr)
const struct ast_aeap_message_handler * response_handlers
struct ast_aeap_message * ast_aeap_message_create_request(const struct ast_aeap_message_type *type, const char *name, const char *id, const void *params)
Create an Asterisk external application request object.
const struct ast_aeap_message_type * ast_aeap_message_type_json
Asterisk external application JSON message type.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.