From: Ally Sommers dropbear.sh@gmail.com
--- dlls/ws2_32/tests/sock.c | 68 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+)
diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c index cddc4c125ff..092bce75d74 100644 --- a/dlls/ws2_32/tests/sock.c +++ b/dlls/ws2_32/tests/sock.c @@ -29,6 +29,7 @@ #include <iphlpapi.h> #include <ws2tcpip.h> #include <wsipx.h> +#include <afunix.h> #include <wsnwlink.h> #include <mswsock.h> #include <mstcpip.h> @@ -13706,6 +13707,72 @@ static void test_connect_udp(void) closesocket(client); }
+struct afunix_thread_param +{ + int sockfd; + SOCKADDR_UN addr; +}; + +static DWORD WINAPI test_afunix_client_connect_thread(void *param) +{ + struct afunix_thread_param *in = param; + ok(!connect(in->sockfd, (SOCKADDR *)&in->addr, sizeof(in->addr)), "Could not connect to Unix socket: %lu\n", + GetLastError()); + return 0; +} + +static void test_afunix(void) +{ + SOCKET server, client, conn; + const SOCKADDR_UN addr = { AF_UNIX, "test_afunix.sock" }; + HANDLE clientThread; + const char serverMsg[] = "ws2_32/AF_UNIX socket test"; + char clientBuf[sizeof(serverMsg)] = { 0 }; + int ret; + + server = socket(AF_UNIX, SOCK_STREAM, 0); + ok(server != INVALID_SOCKET, "Could not create Unix socket: %lu\n", + GetLastError()); + + ok(!bind(server, (SOCKADDR *)&addr, sizeof(SOCKADDR_UN)), "Could not bind Unix socket: %lu\n", + GetLastError()); + ok(!listen(server, 1), "Could not listen on Unix socket: %lu\n", + GetLastError()); + + client = socket(AF_UNIX, SOCK_STREAM, 0); + ok(client != INVALID_SOCKET, "Failed to create second Unix socket: %lu\n", + GetLastError()); + + clientThread = CreateThread(NULL, 0, test_afunix_client_connect_thread, + &(struct afunix_thread_param){ client, addr }, 0, NULL); + ok(clientThread != NULL, "CreateThread failed unexpectedly: %ld\n", GetLastError()); + conn = accept(server, NULL, NULL); + ok(conn != INVALID_SOCKET, "Could not accept Unix socket connection: %lu\n", + GetLastError()); + + ret = send(conn, serverMsg, sizeof(serverMsg), 0); + ok(ret == sizeof(serverMsg), + ret >= 0 + ? "Incorrect amount of bytes written to Unix socket: %lu\n" + : "Could not send data over Unix socket: %lu\n", + ret >= 0 ? ret : GetLastError()); + + ret = recv(client, clientBuf, sizeof(serverMsg), 0); + ok(ret == sizeof(serverMsg), + ret >= 0 + ? "Incorrect amount of bytes read from Unix socket: %lu\n" + : "Could not receive data over Unix socket: %lu\n", + ret >= 0 ? ret : GetLastError()); + + ok(!memcmp(serverMsg, clientBuf, sizeof(serverMsg)), "Data mismatch over Unix socket\n"); + + DeleteFileA("test_afunix.sock"); + ok(GetFileAttributesA("test_afunix.sock") == INVALID_FILE_ATTRIBUTES && + GetLastError() == ERROR_FILE_NOT_FOUND, + "Failed to delete socket file at path '%s'\n", + addr.sun_path); +} + START_TEST( sock ) { int i; @@ -13787,6 +13854,7 @@ START_TEST( sock ) test_tcp_reset(); test_icmp(); test_connect_udp(); + test_afunix();
/* this is an io heavy test, do it at the end so the kernel doesn't start dropping packets */ test_send();