[PATCH] winhttp/tests: (do not commit) Test receving web socket buffer fragments.

Paul Gofman pgofman at codeweavers.com
Thu Feb 24 12:14:40 CST 2022


---
 dlls/winhttp/tests/winhttp.c | 101 +++++++++++++++++++++++++++++++++++
 1 file changed, 101 insertions(+)

diff --git a/dlls/winhttp/tests/winhttp.c b/dlls/winhttp/tests/winhttp.c
index 23ae6167c68..3b1c39988e5 100644
--- a/dlls/winhttp/tests/winhttp.c
+++ b/dlls/winhttp/tests/winhttp.c
@@ -5531,6 +5531,104 @@ static void test_client_cert_authentication(void)
     WinHttpCloseHandle( ses );
 }
 
+static void test_websocket_fragment(void)
+{
+    HINTERNET session, connection, request, socket;
+    DWORD size, len, status, error, count;
+    WINHTTP_WEB_SOCKET_BUFFER_TYPE type;
+    USHORT close_status;
+    char buf[128];
+    BOOL ret;
+
+    session = WinHttpOpen(L"winetest", 0, NULL, NULL, 0);
+    ok(session != NULL, "got %lu\n", GetLastError());
+
+    connection = WinHttpConnect(session, L"192.168.1.3", 12345, 0);
+    ok(connection != NULL, "got %lu\n", GetLastError());
+
+    request = WinHttpOpenRequest(connection, L"GET", L"/", NULL, NULL, NULL, 0);
+    ok(request != NULL, "got %lu\n", GetLastError());
+
+    ret = WinHttpSetOption(request, WINHTTP_OPTION_UPGRADE_TO_WEB_SOCKET, NULL, 0);
+    ok(ret, "got %lu\n", GetLastError());
+
+    ret = WinHttpSendRequest(request, NULL, 0, NULL, 0, 0, 0);
+    ok(ret, "got %lu\n", GetLastError());
+
+    ret = WinHttpReceiveResponse(request, NULL);
+    ok(ret, "got %lu\n", GetLastError());
+
+    status = 0xdeadbeef;
+    size = sizeof(status);
+    ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER, NULL, &status,
+                              &size, NULL);
+    ok(ret, "got %lu\n", GetLastError());
+    ok(status == HTTP_STATUS_SWITCH_PROTOCOLS, "got %lu\n", status);
+
+    socket = pWinHttpWebSocketCompleteUpgrade(request, 0);
+    ok(socket != NULL, "got %lu\n", GetLastError());
+
+    buf[0] = 0;
+    count = 0;
+    type = 0xdeadbeef;
+    error = pWinHttpWebSocketReceive(socket, buf, sizeof(buf), &count, &type);
+    ok(!error, "got %lu\n", error);
+    ok(count == 9, "got %lu\n", count);
+    ok(!strncmp(buf, "fragment1", 9), "got %s\n", buf);
+    ok(type == WINHTTP_WEB_SOCKET_UTF8_FRAGMENT_BUFFER_TYPE, "got %u\n", type);
+
+    buf[0] = 0;
+    count = 0;
+    type = 0xdeadbeef;
+    error = pWinHttpWebSocketReceive(socket, buf, sizeof(buf), &count, &type);
+    ok(!error, "got %lu\n", error);
+    ok(count == 9, "got %lu\n", count);
+    ok(!strncmp(buf, "fragment2", 9), "got %s\n", buf);
+    ok(type == WINHTTP_WEB_SOCKET_UTF8_FRAGMENT_BUFFER_TYPE, "got %u\n", type);
+
+    buf[0] = 0;
+    count = 0;
+    type = 0xdeadbeef;
+    error = pWinHttpWebSocketReceive(socket, buf, sizeof(buf), &count, &type);
+    ok(!error, "got %lu\n", error);
+    ok(count == 9, "got %lu\n", count);
+    ok(!strncmp(buf, "fragment3", 9), "got %s\n", buf);
+    ok(type == WINHTTP_WEB_SOCKET_UTF8_FRAGMENT_BUFFER_TYPE, "got %u\n", type);
+
+    buf[0] = 0;
+    count = 0;
+    type = 0xdeadbeef;
+    error = pWinHttpWebSocketReceive(socket, buf, sizeof(buf), &count, &type);
+    ok(!error, "got %lu\n", error);
+    ok(count == 0, "got %lu\n", count);
+    ok(type == WINHTTP_WEB_SOCKET_UTF8_MESSAGE_BUFFER_TYPE, "got %u\n", type);
+
+    buf[0] = 0;
+    count = 0;
+    type = 0xdeadbeef;
+    error = pWinHttpWebSocketReceive(socket, buf, sizeof(buf), &count, &type);
+    ok(!error, "got %lu\n", error);
+    ok(count == 0, "got %lu\n", count);
+    ok(type == WINHTTP_WEB_SOCKET_CLOSE_BUFFER_TYPE, "got %u\n", type);
+
+    error = pWinHttpWebSocketClose(socket, WINHTTP_WEB_SOCKET_SUCCESS_CLOSE_STATUS, (void *)"success2",
+                                   sizeof("success2"));
+    ok(!error, "got %lu\n", error);
+
+    close_status = 0xdead;
+    len = 0xdeadbeef;
+    memset(buf, 0, sizeof(buf));
+    error = pWinHttpWebSocketQueryCloseStatus(socket, &close_status, buf, sizeof(buf), &len);
+    ok(!error, "got %lu\n", error);
+    ok(close_status == 1000, "got %d\n", close_status);
+    ok(!len, "got %lu\n", len);
+
+    WinHttpCloseHandle(socket);
+    WinHttpCloseHandle(request);
+    WinHttpCloseHandle(connection);
+    WinHttpCloseHandle(session);
+}
+
 START_TEST (winhttp)
 {
     struct server_info si;
@@ -5545,6 +5643,7 @@ START_TEST (winhttp)
     pWinHttpWebSocketShutdown = (void *)GetProcAddress(mod, "WinHttpWebSocketShutdown");
     pWinHttpWebSocketReceive = (void *)GetProcAddress(mod, "WinHttpWebSocketReceive");
 
+if(0){
     test_WinHttpOpenRequest();
     test_WinHttpSendRequest();
     test_WinHttpTimeFromSystemTime();
@@ -5603,4 +5702,6 @@ START_TEST (winhttp)
 
     WaitForSingleObject(thread, 3000);
     CloseHandle(thread);
+}
+    test_websocket_fragment();
 }
-- 
2.35.1




More information about the wine-devel mailing list