41 #define CATEGORY "/res/websocket/"
42 #define REMOTE_URL "ws://127.0.0.1:8088/ws"
49 const char write_buf[] =
"this is only a test";
50 RAII_VAR(
char *, read_buf, NULL, ast_free);
54 info->name = __func__;
55 info->explicit_only = 1;
57 info->summary =
"test creation and connection of a client websocket";
58 info->description =
"test creation and connection of a client websocket";
59 return AST_TEST_NOT_RUN;
64 ast_test_validate(
test, (client = ast_websocket_client_create(
65 REMOTE_URL,
"echo", NULL, &result)));
67 ast_test_validate(
test, !ast_websocket_write_string(client, write_buf));
68 ast_test_validate(
test, ast_websocket_read_string(client, &read_buf) > 0);
69 ast_test_validate(
test, !strcmp(write_buf, read_buf));
81 info->name = __func__;
83 info->summary =
"websocket client - test bad url";
84 info->description =
"pass a bad url and make sure it fails";
85 return AST_TEST_NOT_RUN;
90 ast_test_validate(
test, !(client = ast_websocket_client_create(
91 "invalid", NULL, NULL, &result)));
102 info->name = __func__;
104 info->summary =
"websocket client - unsupported protocol";
105 info->description =
"fails on an unsupported protocol";
106 return AST_TEST_NOT_RUN;
111 ast_test_validate(
test, !(client = ast_websocket_client_create(
112 REMOTE_URL,
"unsupported", NULL, &result)));
113 return AST_TEST_PASS;
119 const char *accept_protocol;
124 info->name = __func__;
126 info->summary =
"websocket client - test multiple protocols";
127 info->description =
"test multi-protocol client";
128 return AST_TEST_NOT_RUN;
133 ast_test_validate(
test, (client = ast_websocket_client_create(
134 REMOTE_URL,
"echo,unsupported", NULL, &result)));
136 accept_protocol = ast_websocket_client_accept_protocol(client);
137 ast_test_validate(
test, accept_protocol && !strcmp(accept_protocol,
"echo"));
139 return AST_TEST_PASS;
142 static int load_module(
void)
144 AST_TEST_REGISTER(websocket_client_create_and_connect);
145 AST_TEST_REGISTER(websocket_client_bad_url);
146 AST_TEST_REGISTER(websocket_client_unsupported_protocol);
147 AST_TEST_REGISTER(websocket_client_multiple_protocols);
151 static int unload_module(
void)
153 AST_TEST_UNREGISTER(websocket_client_multiple_protocols);
154 AST_TEST_UNREGISTER(websocket_client_unsupported_protocol);
155 AST_TEST_UNREGISTER(websocket_client_bad_url);
156 AST_TEST_UNREGISTER(websocket_client_create_and_connect);
160 AST_MODULE_INFO(
ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT,
"Websocket client test module",
161 .support_level = AST_MODULE_SUPPORT_CORE,
163 .unload = unload_module,
164 .requires =
"res_http_websocket",
Asterisk main include file. File version handling, generic pbx functions.
ast_websocket_result
Result code for a websocket client.
Support for WebSocket connections within the Asterisk HTTP server and client WebSocket connections to...
Core PBX routines and definitions.
Structure definition for session.
#define AST_TEST_DEFINE(hdr)
#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.