ws2_32/tests: Use winetest_push_context() in test_WSAStringToAddress().

Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2022-02-10 21:29:42 -06:00 committed by Alexandre Julliard
parent 1a9e8c1a2e
commit 8648ab248c
1 changed files with 33 additions and 53 deletions

View File

@ -1403,12 +1403,11 @@ static void test_WSAStringToAddress(void)
{ "", { 0, 0, 0, 0, 0, 0, 0, 0 }, 0, WSAEINVAL }, { "", { 0, 0, 0, 0, 0, 0, 0, 0 }, 0, WSAEINVAL },
}; };
int len, ret, expected_len;
WCHAR inputW[64]; WCHAR inputW[64];
INT len, ret, expected_len, expected_ret;
short expected_family;
SOCKADDR_IN sockaddr; SOCKADDR_IN sockaddr;
SOCKADDR_IN6 sockaddr6; SOCKADDR_IN6 sockaddr6;
int i, j; unsigned int i, j;
len = 0; len = 0;
WSASetLastError( 0 ); WSASetLastError( 0 );
@ -1420,12 +1419,16 @@ static void test_WSAStringToAddress(void)
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
{ {
winetest_push_context( i ? "unicode" : "ascii" );
for (j = 0; j < ARRAY_SIZE(ipv4_tests); j++) for (j = 0; j < ARRAY_SIZE(ipv4_tests); j++)
{ {
len = sizeof(sockaddr) + 10; len = sizeof(sockaddr) + 10;
expected_len = ipv4_tests[j].error ? len : sizeof(sockaddr); expected_len = ipv4_tests[j].error ? len : sizeof(sockaddr);
memset( &sockaddr, 0xab, sizeof(sockaddr) ); memset( &sockaddr, 0xab, sizeof(sockaddr) );
winetest_push_context( "addr %s", debugstr_a(ipv4_tests[j].input) );
WSASetLastError( 0 ); WSASetLastError( 0 );
if (i == 0) if (i == 0)
{ {
@ -1436,26 +1439,16 @@ static void test_WSAStringToAddress(void)
MultiByteToWideChar( CP_ACP, 0, ipv4_tests[j].input, -1, inputW, ARRAY_SIZE(inputW) ); MultiByteToWideChar( CP_ACP, 0, ipv4_tests[j].input, -1, inputW, ARRAY_SIZE(inputW) );
ret = WSAStringToAddressW( inputW, AF_INET, NULL, (SOCKADDR *)&sockaddr, &len ); ret = WSAStringToAddressW( inputW, AF_INET, NULL, (SOCKADDR *)&sockaddr, &len );
} }
expected_ret = ipv4_tests[j].error ? SOCKET_ERROR : 0; ok( ret == (ipv4_tests[j].error ? SOCKET_ERROR : 0), "got %d\n", ret );
expected_family = ipv4_tests[j].error ? 0 : AF_INET; ok( WSAGetLastError() == ipv4_tests[j].error, "got error %d\n", WSAGetLastError() );
ok( ret == expected_ret, ok( sockaddr.sin_family == (ipv4_tests[j].error ? 0 : AF_INET),
"WSAStringToAddress(%s) returned %d, expected %d\n", "got family %#x\n", sockaddr.sin_family );
wine_dbgstr_a( ipv4_tests[j].input ), ret, expected_ret );
ok( WSAGetLastError() == ipv4_tests[j].error,
"WSAStringToAddress(%s) gave error %d, expected %d\n",
wine_dbgstr_a( ipv4_tests[j].input ), WSAGetLastError(), ipv4_tests[j].error );
ok( sockaddr.sin_family == expected_family,
"WSAStringToAddress(%s) gave family %d, expected %d\n",
wine_dbgstr_a( ipv4_tests[j].input ), sockaddr.sin_family, expected_family );
ok( sockaddr.sin_addr.s_addr == htonl( ipv4_tests[j].address ), ok( sockaddr.sin_addr.s_addr == htonl( ipv4_tests[j].address ),
"WSAStringToAddress(%s) gave address %08x, expected %08x\n", "got addr %08x\n", sockaddr.sin_addr.s_addr );
wine_dbgstr_a( ipv4_tests[j].input ), sockaddr.sin_addr.s_addr, htonl( ipv4_tests[j].address) ); ok( sockaddr.sin_port == htons( ipv4_tests[j].port ), "got port %u\n", sockaddr.sin_port );
ok( sockaddr.sin_port == htons( ipv4_tests[j].port ), ok( len == expected_len, "got len %d\n", len );
"WSAStringToAddress(%s) gave port %04x, expected %04x\n",
wine_dbgstr_a( ipv4_tests[j].input ), sockaddr.sin_port, htons( ipv4_tests[j].port ) ); winetest_pop_context();
ok( len == expected_len,
"WSAStringToAddress(%s) gave length %d, expected %d\n",
wine_dbgstr_a( ipv4_tests[j].input ), len, expected_len );
} }
for (j = 0; j < ARRAY_SIZE(ipv6_tests); j++) for (j = 0; j < ARRAY_SIZE(ipv6_tests); j++)
@ -1479,41 +1472,28 @@ static void test_WSAStringToAddress(void)
win_skip("IPv6 not supported\n"); win_skip("IPv6 not supported\n");
break; break;
} }
expected_ret = ipv6_tests[j].error ? SOCKET_ERROR : 0;
expected_family = ipv6_tests[j].error ? 0 : AF_INET6; winetest_push_context( "addr %s", debugstr_a(ipv6_tests[j].input) );
ok( ret == expected_ret,
"WSAStringToAddress(%s) returned %d, expected %d\n", ok( ret == (ipv6_tests[j].error ? SOCKET_ERROR : 0), "got %d\n", ret );
wine_dbgstr_a( ipv6_tests[j].input ), ret, expected_ret ); ok( WSAGetLastError() == ipv6_tests[j].error, "got error %d\n", WSAGetLastError() );
ok( WSAGetLastError() == ipv6_tests[j].error, ok( sockaddr6.sin6_family == (ipv6_tests[j].error ? 0 : AF_INET6),
"WSAStringToAddress(%s) gave error %d, expected %d\n", "got family %#x\n", sockaddr6.sin6_family );
wine_dbgstr_a( ipv6_tests[j].input ), WSAGetLastError(), ipv6_tests[j].error ); ok( !memcmp( &sockaddr6.sin6_addr, ipv6_tests[j].address, sizeof(sockaddr6.sin6_addr) ),
ok( sockaddr6.sin6_family == expected_family, "got addr %x:%x:%x:%x:%x:%x:%x:%x\n",
"WSAStringToAddress(%s) gave family %d, expected %d\n",
wine_dbgstr_a( ipv4_tests[j].input ), sockaddr6.sin6_family, expected_family );
ok( memcmp(&sockaddr6.sin6_addr, ipv6_tests[j].address, sizeof(sockaddr6.sin6_addr)) == 0,
"WSAStringToAddress(%s) gave address %x:%x:%x:%x:%x:%x:%x:%x, expected %x:%x:%x:%x:%x:%x:%x:%x\n",
wine_dbgstr_a( ipv6_tests[j].input ),
sockaddr6.sin6_addr.s6_words[0], sockaddr6.sin6_addr.s6_words[1], sockaddr6.sin6_addr.s6_words[0], sockaddr6.sin6_addr.s6_words[1],
sockaddr6.sin6_addr.s6_words[2], sockaddr6.sin6_addr.s6_words[3], sockaddr6.sin6_addr.s6_words[2], sockaddr6.sin6_addr.s6_words[3],
sockaddr6.sin6_addr.s6_words[4], sockaddr6.sin6_addr.s6_words[5], sockaddr6.sin6_addr.s6_words[4], sockaddr6.sin6_addr.s6_words[5],
sockaddr6.sin6_addr.s6_words[6], sockaddr6.sin6_addr.s6_words[7], sockaddr6.sin6_addr.s6_words[6], sockaddr6.sin6_addr.s6_words[7] );
ipv6_tests[j].address[0], ipv6_tests[j].address[1], ok( !sockaddr6.sin6_scope_id, "got scope id %u\n", sockaddr6.sin6_scope_id );
ipv6_tests[j].address[2], ipv6_tests[j].address[3], ok( sockaddr6.sin6_port == ipv6_tests[j].port, "got port %u\n", sockaddr6.sin6_port );
ipv6_tests[j].address[4], ipv6_tests[j].address[5], ok( !sockaddr6.sin6_flowinfo, "got flowinfo %u\n", sockaddr6.sin6_flowinfo );
ipv6_tests[j].address[6], ipv6_tests[j].address[7] ); ok( len == expected_len, "got len %d\n", len );
ok( sockaddr6.sin6_scope_id == 0,
"WSAStringToAddress(%s) gave scope %d, expected 0\n", winetest_pop_context();
wine_dbgstr_a( ipv6_tests[j].input ), sockaddr6.sin6_scope_id );
ok( sockaddr6.sin6_port == ipv6_tests[j].port,
"WSAStringToAddress(%s) gave port %04x, expected %04x\n",
wine_dbgstr_a( ipv6_tests[j].input ), sockaddr6.sin6_port, ipv6_tests[j].port );
ok( sockaddr6.sin6_flowinfo == 0,
"WSAStringToAddress(%s) gave flowinfo %d, expected 0\n",
wine_dbgstr_a( ipv6_tests[j].input ), sockaddr6.sin6_flowinfo );
ok( len == expected_len,
"WSAStringToAddress(%s) gave length %d, expected %d\n",
wine_dbgstr_a( ipv6_tests[j].input ), len, expected_len );
} }
winetest_pop_context();
} }
} }