Commit 7d78bf4b authored by Jeff Latimer's avatar Jeff Latimer Committed by Alexandre Julliard

ws2_32/tests: IPv6 tests for WSAAddressToStringA.

parent 9f6bd09e
......@@ -1272,6 +1272,7 @@ static void test_WSASocket(void)
static void test_WSAAddressToStringA(void)
{
SOCKET v6 = INVALID_SOCKET;
INT ret;
DWORD len;
int GLE;
......@@ -1283,6 +1284,19 @@ static void test_WSAAddressToStringA(void)
CHAR expect3[] = "0.0.0.0:65535";
CHAR expect4[] = "255.255.255.255:65535";
SOCKADDR_IN6 sockaddr6;
CHAR address6[54]; /* 32 digits + 7':' + '[' + '%" + 5 digits + ']:' + 5 digits + '\0' */
CHAR addr6_1[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01};
CHAR addr6_2[] = {0x20,0xab,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01};
CHAR addr6_3[] = {0x20,0xab,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x01};
CHAR expect6_1[] = "::1";
CHAR expect6_2[] = "20ab::1";
CHAR expect6_3[] = "[20ab::2001]:33274";
CHAR expect6_3_2[] = "[20ab::2001%4660]:33274";
CHAR expect6_3_3[] = "20ab::2001%4660";
len = 0;
sockaddr.sin_family = AF_INET;
......@@ -1340,6 +1354,97 @@ static void test_WSAAddressToStringA(void)
ok( !strcmp( address, expect4 ), "Expected: %s, got: %s\n", expect4, address );
ok( len == sizeof( expect4 ), "Got size %d\n", len);
/*check to see it IPv6 is available */
v6 = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
if (v6 == INVALID_SOCKET) {
skip("Could not create IPv6 socket (LastError: %d; %d expected if IPv6 not available).\n",
WSAGetLastError(), WSAEAFNOSUPPORT);
goto end;
}
/* Test a short IPv6 address */
len = sizeof(address6);
sockaddr6.sin6_family = AF_INET6;
sockaddr6.sin6_port = 0x0000;
sockaddr6.sin6_scope_id = 0;
memcpy (sockaddr6.sin6_addr.s6_addr, addr6_1, sizeof(addr6_1));
ret = WSAAddressToStringA( (SOCKADDR*)&sockaddr6, sizeof(sockaddr6), NULL, address6, &len );
todo_wine
{
ok( !ret, "WSAAddressToStringA() failed unexpectedly: %d\n", WSAGetLastError() );
ok( !strcmp( address6, expect6_1 ), "Expected: %s, got: %s\n", expect6_1, address6 );
ok( len == sizeof(expect6_1), "Got size %d\n", len);
}
/* Test a longer IPv6 address */
len = sizeof(address6);
sockaddr6.sin6_family = AF_INET6;
sockaddr6.sin6_port = 0x0000;
sockaddr6.sin6_scope_id = 0;
memcpy (sockaddr6.sin6_addr.s6_addr, addr6_2, sizeof(addr6_2));
ret = WSAAddressToStringA( (SOCKADDR*)&sockaddr6, sizeof(sockaddr6), NULL, address6, &len );
todo_wine
{
ok( !ret, "WSAAddressToStringA() failed unexpectedly: %d\n", WSAGetLastError() );
ok( !strcmp( address6, expect6_2 ), "Expected: %s, got: %s\n", expect6_2, address6 );
ok( len == sizeof(expect6_2), "Got size %d\n", len);
}
/* Test IPv6 address and port number */
len = sizeof(address6);
sockaddr6.sin6_family = AF_INET6;
sockaddr6.sin6_port = 0xfa81;
sockaddr6.sin6_scope_id = 0;
memcpy (sockaddr6.sin6_addr.s6_addr, addr6_3, sizeof(addr6_3));
ret = WSAAddressToStringA( (SOCKADDR*)&sockaddr6, sizeof(sockaddr6), NULL, address6, &len );
todo_wine
{
ok( !ret, "WSAAddressToStringA() failed unexpectedly: %d\n", WSAGetLastError() );
ok( !strcmp( address6, expect6_3 ), "Expected: %s, got: %s\n", expect6_3, address6 );
ok( len == sizeof(expect6_3), "Got size %d\n", len);
}
/* Test IPv6 address, port number and scope_id */
len = sizeof(address6);
sockaddr6.sin6_family = AF_INET6;
sockaddr6.sin6_port = 0xfa81;
sockaddr6.sin6_scope_id = 0x1234;
memcpy (sockaddr6.sin6_addr.s6_addr, addr6_3, sizeof(addr6_3));
ret = WSAAddressToStringA( (SOCKADDR*)&sockaddr6, sizeof(sockaddr6), NULL, address6, &len );
todo_wine
{
ok( !ret, "WSAAddressToStringA() failed unexpectedly: %d\n", WSAGetLastError() );
ok( !strcmp( address6, expect6_3_2 ), "Expected: %s, got: %s\n", expect6_3_2, address6 );
ok( len == sizeof(expect6_3_2), "Got size %d\n", len);
}
/* Test IPv6 address and scope_id */
len = sizeof(address6);
sockaddr6.sin6_family = AF_INET6;
sockaddr6.sin6_port = 0x0000;
sockaddr6.sin6_scope_id = 0x1234;
memcpy (sockaddr6.sin6_addr.s6_addr, addr6_3, sizeof(addr6_3));
ret = WSAAddressToStringA( (SOCKADDR*)&sockaddr6, sizeof(sockaddr6), NULL, address6, &len );
todo_wine
{
ok( !ret, "WSAAddressToStringA() failed unexpectedly: %d\n", WSAGetLastError() );
ok( !strcmp( address6, expect6_3_3 ), "Expected: %s, got: %s\n", expect6_3_3, address6 );
ok( len == sizeof(expect6_3_3), "Got size %d\n", len);
}
end:
if (v6 != INVALID_SOCKET)
closesocket(v6);
}
static void test_WSAAddressToStringW(void)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment