Skip to content

Commit d5845d4

Browse files
committed
Add test for emscripten_websocket_get_url_length().
1 parent 51881cd commit d5845d4

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

tests/websocket/test_websocket_send.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <stdio.h>
22
#include <stdlib.h>
33
#include <emscripten/websocket.h>
4+
#include <assert.h>
45

56
EM_BOOL WebSocketOpen(int eventType, const EmscriptenWebSocketOpenEvent *e, void *userData)
67
{
@@ -73,7 +74,8 @@ int main()
7374
EmscriptenWebSocketCreateAttributes attr;
7475
emscripten_websocket_init_create_attributes(&attr);
7576

76-
attr.url = "ws://localhost:8088";
77+
const char *url = "ws://localhost:8088/";
78+
attr.url = url;
7779

7880
EMSCRIPTEN_WEBSOCKET_T socket = emscripten_websocket_new(&attr);
7981
if (socket <= 0)
@@ -82,6 +84,11 @@ int main()
8284
exit(1);
8385
}
8486

87+
int urlLength = 0;
88+
EMSCRIPTEN_RESULT res = emscripten_websocket_get_url_length(socket, &urlLength);
89+
assert(res == EMSCRIPTEN_RESULT_SUCCESS);
90+
assert(urlLength == strlen(url));
91+
8592
emscripten_websocket_set_onopen_callback(socket, (void*)42, WebSocketOpen);
8693
emscripten_websocket_set_onclose_callback(socket, (void*)43, WebSocketClose);
8794
emscripten_websocket_set_onerror_callback(socket, (void*)44, WebSocketError);

0 commit comments

Comments
 (0)