Signed-off-by: Alex Henrie alexhenrie24@gmail.com --- Changes from previous attempt: - Align table columns - Skip setsockopt tests if getsockopt is expected to fail - Rebase on top of getsockopt and setsockopt fixes, removing the need for multiple TODO flags --- dlls/ws2_32/tests/sock.c | 239 ++++++++++++++++++++++++++++++++++----- 1 file changed, 210 insertions(+), 29 deletions(-)
diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c index 7605a172fef..f44252d3b41 100644 --- a/dlls/ws2_32/tests/sock.c +++ b/dlls/ws2_32/tests/sock.c @@ -11431,47 +11431,228 @@ static void test_so_debug(void) closesocket(s); }
-static void test_set_only_options(void) +enum sockopt_validity_flags { - unsigned int i; - int ret, len; - int value; - SOCKET s; + BROKEN = 1, + TODO = 2 +};
- static const struct - { - int level; - int option; - } - tests[] = - { - {IPPROTO_IP, IP_ADD_MEMBERSHIP}, - {IPPROTO_IP, IP_DROP_MEMBERSHIP}, - {IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP}, - {IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP}, - }; +struct sockopt_validity_test +{ + int opt; + int get_error; + enum sockopt_validity_flags get_flags; + int set_error; + enum sockopt_validity_flags set_flags; +};
- for (i = 0; i < ARRAY_SIZE(tests); ++i) +static void do_sockopt_validity_tests(const char *type, SOCKET sock, int level, + const struct sockopt_validity_test *tests) +{ + static const struct sockopt_validity_test default_test = {0, WSAENOPROTOOPT, 0}; + const struct sockopt_validity_test *test; + char value[256]; + int opt, count, rc, expected_rc, i = 0; + + for (opt = 0; opt < 100; opt++) { - if (tests[i].level == IPPROTO_IPV6) + if (tests[i].opt && opt == tests[i].opt) { - s = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP); - if (s == INVALID_SOCKET) continue; + test = &tests[i]; + i++; } else { - s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + test = &default_test; }
- len = sizeof(value); - ret = getsockopt(s, tests[i].level, tests[i].option, (char *)&value, &len); - ok(ret == -1, "expected failure\n"); - ok(WSAGetLastError() == WSAENOPROTOOPT, "got error %u\n", WSAGetLastError()); - - closesocket(s); + memset(value, 0, sizeof(value)); + count = sizeof(value); + + WSASetLastError(0); + rc = getsockopt(sock, level, opt, value, &count); + expected_rc = test->get_error ? SOCKET_ERROR : 0; +todo_wine_if(!test->get_error && test->get_flags & TODO) + ok(rc == expected_rc || broken(rc == SOCKET_ERROR && test->get_flags & BROKEN), + "expected getting %s option %i to return %i, got %i\n", type, opt, expected_rc, rc); +todo_wine_if(test->get_flags & TODO) + ok(WSAGetLastError() == test->get_error || broken(rc == SOCKET_ERROR && test->get_flags & BROKEN), + "expected getting %s option %i to cause error %i, got %i\n", type, opt, test->get_error, WSAGetLastError()); + + if (test->get_error) + continue; + + WSASetLastError(0); + rc = setsockopt(sock, level, opt, value, count); + expected_rc = test->set_error ? SOCKET_ERROR : 0; +todo_wine_if(!test->set_error && test->set_flags & TODO) + ok(rc == expected_rc || broken(rc == SOCKET_ERROR && test->set_flags & BROKEN), + "expected setting %s option %i to return %i, got %i\n", type, opt, expected_rc, rc); +todo_wine_if(test->set_flags & TODO) + ok(WSAGetLastError() == test->set_error || broken(rc == SOCKET_ERROR && test->set_flags & BROKEN), + "expected setting %s option %i to cause error %i, got %i\n", type, opt, test->set_error, WSAGetLastError()); } }
+static void test_sockopt_validity(void) +{ + static const struct sockopt_validity_test ipv4_tcp_tests[] = + { + { IP_OPTIONS }, + { IP_HDRINCL, WSAEINVAL, TODO }, + { IP_TOS }, + { IP_TTL }, + { IP_MULTICAST_IF, WSAEINVAL }, + { IP_MULTICAST_TTL, WSAEINVAL }, + { IP_MULTICAST_LOOP, WSAEINVAL }, + { IP_DONTFRAGMENT }, + { IP_PKTINFO, WSAEINVAL }, + { IP_RECVTTL, WSAEINVAL, TODO }, + { IP_RECEIVE_BROADCAST, WSAEINVAL, TODO }, + { 23, 0, TODO, 0, TODO }, + { IP_RECVIF, WSAEINVAL, TODO }, + { IP_RECVDSTADDR, WSAEINVAL, TODO }, + { IP_IFLIST, 0, TODO, 0, TODO }, + { IP_UNICAST_IF }, + { IP_RTHDR, 0, TODO, 0, TODO }, + { IP_GET_IFLIST, WSAEINVAL, BROKEN /* win8 */ | TODO }, + { IP_RECVRTHDR, WSAEINVAL, TODO }, + { IP_RECVTCLASS, WSAEINVAL, TODO }, + { IP_ORIGINAL_ARRIVAL_IF, WSAEINVAL, BROKEN /* vista */ | TODO }, + { IP_ECN, WSAEINVAL, BROKEN /* win7 */ | TODO }, + { IP_PKTINFO_EX, WSAEINVAL, BROKEN /* win7 */ | TODO }, + { IP_WFP_REDIRECT_RECORDS, WSAEINVAL, BROKEN /* win7 */ | TODO }, + { IP_WFP_REDIRECT_CONTEXT, WSAEINVAL, BROKEN /* win7 */ | TODO }, + { IP_MTU_DISCOVER, 0, BROKEN /* win8 */ | TODO, WSAEINVAL, BROKEN /* win8 */ | TODO }, + { IP_MTU, WSAENOTCONN, BROKEN /* win8 */ | TODO }, + { IP_RECVERR, WSAEINVAL, BROKEN /* win8 */ | TODO }, + { IP_USER_MTU, 0, BROKEN /* win8 */ | TODO, 0, BROKEN /* win8 */ | TODO }, + {} + }; + static const struct sockopt_validity_test ipv4_udp_tests[] = + { + { IP_OPTIONS }, + { IP_HDRINCL, WSAEINVAL, TODO }, + { IP_TOS }, + { IP_TTL }, + { IP_MULTICAST_IF }, + { IP_MULTICAST_TTL }, + { IP_MULTICAST_LOOP }, + { IP_DONTFRAGMENT }, + { IP_PKTINFO }, + { IP_RECVTTL, 0, TODO, 0, TODO }, + { IP_RECEIVE_BROADCAST, 0, TODO, 0, TODO }, + { 23, 0, TODO, 0, TODO }, + { IP_RECVIF, 0, TODO, 0, TODO }, + { IP_RECVDSTADDR, 0, TODO, 0, TODO }, + { IP_IFLIST, 0, TODO, 0, TODO }, + { IP_UNICAST_IF }, + { IP_RTHDR, 0, TODO, 0, TODO }, + { IP_GET_IFLIST, WSAEINVAL, BROKEN /* win8 */ | TODO }, + { IP_RECVRTHDR, 0, TODO, 0, BROKEN /* win8 */ | TODO }, + { IP_RECVTCLASS, 0, TODO, 0, TODO }, + { IP_ORIGINAL_ARRIVAL_IF, 0, BROKEN /* vista */ | TODO, 0, BROKEN /* vista */ | TODO }, + { IP_ECN, 0, BROKEN /* win7 */ | TODO, 0, BROKEN /* win7 */ | TODO }, + { IP_PKTINFO_EX, 0, BROKEN /* win7 */ | TODO, 0, BROKEN /* win7 */ | TODO }, + { IP_WFP_REDIRECT_RECORDS, 0, BROKEN /* win7 */ | TODO, 0, BROKEN /* win7 */ | TODO }, + { IP_WFP_REDIRECT_CONTEXT, 0, BROKEN /* win7 */ | TODO, 0, BROKEN /* win7 */ | TODO }, + { IP_MTU_DISCOVER, 0, BROKEN /* win8 */ | TODO, WSAEINVAL, BROKEN /* win8 */ | TODO }, + { IP_MTU, WSAENOTCONN, BROKEN /* win8 */ | TODO }, + { IP_RECVERR, 0, BROKEN /* win8 */ | TODO, 0, BROKEN /* win8 */ | TODO }, + { IP_USER_MTU, 0, BROKEN /* win8 */ | TODO, 0, BROKEN /* win8 */ | TODO }, + {} + }; + static const struct sockopt_validity_test ipv6_tcp_tests[] = + { + { IPV6_HOPOPTS, 0, TODO, 0, TODO }, + { 2, WSAEINVAL, TODO }, + { 3, 0, TODO, 0, TODO }, + { IPV6_UNICAST_HOPS }, + { IPV6_MULTICAST_IF, WSAEINVAL }, + { IPV6_MULTICAST_HOPS, WSAEINVAL }, + { IPV6_MULTICAST_LOOP, WSAEINVAL }, + { IPV6_DONTFRAG }, + { IPV6_PKTINFO, WSAEINVAL }, + { IPV6_HOPLIMIT, WSAEINVAL }, + { 22, WSAEINVAL, TODO }, + { IPV6_PROTECTION_LEVEL, 0, TODO, 0, 0 }, + { IPV6_RECVIF, WSAEINVAL, TODO }, + { IPV6_RECVDSTADDR, WSAEINVAL, TODO }, + { IPV6_V6ONLY }, + { IPV6_IFLIST, 0, TODO, 0, TODO }, + { IPV6_UNICAST_IF }, + { IPV6_RTHDR, 0, TODO, 0, TODO }, + { IPV6_GET_IFLIST, WSAEINVAL, BROKEN /* win8 */ | TODO }, + { IPV6_RECVRTHDR, WSAEINVAL, TODO }, + { IPV6_RECVTCLASS, WSAEINVAL }, + { 47, WSAEINVAL, BROKEN /* vista */ | TODO }, + { IPV6_ECN, WSAEINVAL, BROKEN /* win7 */ | TODO }, + { IPV6_PKTINFO_EX, WSAEINVAL, BROKEN /* win7 */ | TODO }, + { IPV6_WFP_REDIRECT_RECORDS, WSAEINVAL, BROKEN /* win7 */ | TODO }, + { IPV6_WFP_REDIRECT_CONTEXT, WSAEINVAL, BROKEN /* win7 */ | TODO }, + { IPV6_MTU_DISCOVER, 0, BROKEN /* win8 */ | TODO, WSAEINVAL, BROKEN /* win8 */ | TODO }, + { IPV6_MTU, WSAENOTCONN, BROKEN /* win8 */ | TODO }, + { IPV6_RECVERR, WSAEINVAL, BROKEN /* win8 */ | TODO }, + { IPV6_USER_MTU, 0, BROKEN /* win8 */ | TODO, 0, BROKEN /* win8 */ | TODO }, + {} + }; + static const struct sockopt_validity_test ipv6_udp_tests[] = + { + { IPV6_HOPOPTS, 0, TODO, 0, TODO }, + { 2, WSAEINVAL, TODO }, + { 3, 0, TODO, 0, TODO }, + { IPV6_UNICAST_HOPS }, + { IPV6_MULTICAST_IF }, + { IPV6_MULTICAST_HOPS }, + { IPV6_MULTICAST_LOOP }, + { IPV6_DONTFRAG }, + { IPV6_PKTINFO }, + { IPV6_HOPLIMIT }, + { 22, 0, TODO, 0, TODO }, + { IPV6_PROTECTION_LEVEL, 0, TODO, 0, 0 }, + { IPV6_RECVIF, 0, TODO, 0, TODO }, + { IPV6_RECVDSTADDR, 0, TODO, 0, TODO }, + { IPV6_V6ONLY }, + { IPV6_IFLIST, 0, TODO, 0, TODO }, + { IPV6_UNICAST_IF }, + { IPV6_RTHDR, 0, TODO, 0, TODO }, + { IPV6_GET_IFLIST, WSAEINVAL, BROKEN /* win8 */ | TODO }, + { IPV6_RECVRTHDR, 0, TODO, 0, BROKEN /* win8 */ | TODO }, + { IPV6_RECVTCLASS }, + { 47, 0, BROKEN /* vista */ | TODO, 0, BROKEN /* vista */ | TODO }, + { IPV6_ECN, 0, BROKEN /* win7 */ | TODO, 0, BROKEN /* win7 */ | TODO }, + { IPV6_PKTINFO_EX, 0, BROKEN /* win7 */ | TODO, 0, BROKEN /* win7 */ | TODO }, + { IPV6_WFP_REDIRECT_RECORDS, 0, BROKEN /* win7 */ | TODO, 0, BROKEN /* win7 */ | TODO }, + { IPV6_WFP_REDIRECT_CONTEXT, 0, BROKEN /* win7 */ | TODO, 0, BROKEN /* win7 */ | TODO }, + { IPV6_MTU_DISCOVER, 0, BROKEN /* win8 */ | TODO, WSAEINVAL, BROKEN /* win8 */ | TODO }, + { IPV6_MTU, WSAENOTCONN, BROKEN /* win8 */ | TODO }, + { IPV6_RECVERR, 0, BROKEN /* win8 */ | TODO, 0, BROKEN /* win8 */ | TODO }, + { IPV6_USER_MTU, 0, BROKEN /* win8 */ | TODO, 0, BROKEN /* win8 */ | TODO }, + {} + }; + SOCKET sock; + + sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + ok(sock != INVALID_SOCKET, "failed to create socket, error %u\n", WSAGetLastError()); + do_sockopt_validity_tests("IPv4 TCP", sock, IPPROTO_IP, ipv4_tcp_tests); + closesocket(sock); + + sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + ok(sock != INVALID_SOCKET, "failed to create socket, error %u\n", WSAGetLastError()); + do_sockopt_validity_tests("IPv4 UDP", sock, IPPROTO_IP, ipv4_udp_tests); + closesocket(sock); + + sock = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP); + ok(sock != INVALID_SOCKET, "failed to create socket, error %u\n", WSAGetLastError()); + do_sockopt_validity_tests("IPv6 TCP", sock, IPPROTO_IPV6, ipv6_tcp_tests); + closesocket(sock); + + sock = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); + ok(sock != INVALID_SOCKET, "failed to create socket, error %u\n", WSAGetLastError()); + do_sockopt_validity_tests("IPv6 UDP", sock, IPPROTO_IPV6, ipv6_udp_tests); + closesocket(sock); +} + START_TEST( sock ) { int i; @@ -11489,7 +11670,7 @@ START_TEST( sock ) test_ipv6_cmsg(); test_extendedSocketOptions(); test_so_debug(); - test_set_only_options(); + test_sockopt_validity();
for (i = 0; i < ARRAY_SIZE(tests); i++) do_test(&tests[i]);