From a787321d622c4920e362310d825726c67d66a217 Mon Sep 17 00:00:00 2001 From: Bruno Jesus <00cpxxx@gmail.com> Date: Thu, 26 Nov 2015 13:22:12 +0800 Subject: [PATCH] ws2_32/tests: Ensure we have more than one IP to test gethostbyname. Sebastian called my attention about his machine that has a single IP and make test fails. In such cases it is safe to assume that the IP returned is the default route so the test is meaningless in this situation. Signed-off-by: Bruno Jesus <00cpxxx@gmail.com> Signed-off-by: Sebastian Lackner Signed-off-by: Alexandre Julliard --- dlls/ws2_32/tests/sock.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c index 3c66f7ddf6d..f4831979b44 100644 --- a/dlls/ws2_32/tests/sock.c +++ b/dlls/ws2_32/tests/sock.c @@ -4468,7 +4468,7 @@ static void test_gethostbyname(void) struct hostent *he; struct in_addr **addr_list; char name[256], first_ip[16]; - int ret, i; + int ret, i, count; PMIB_IPFORWARDTABLE routes = NULL; PIP_ADAPTER_INFO adapters = NULL, k; DWORD adap_size = 0, route_size = 0; @@ -4484,9 +4484,9 @@ static void test_gethostbyname(void) strcpy(first_ip, inet_ntoa(*addr_list[0])); trace("List of local IPs:\n"); - for(i = 0; addr_list[i] != NULL; i++) + for(count = 0; addr_list[count] != NULL; count++) { - char *ip = inet_ntoa(*addr_list[i]); + char *ip = inet_ntoa(*addr_list[count]); if (!strcmp(ip, "127.0.0.1")) local_ip = TRUE; trace("%s\n", ip); @@ -4494,7 +4494,7 @@ static void test_gethostbyname(void) if (local_ip) { - ok (i == 1, "expected 127.0.0.1 to be the only IP returned\n"); + ok (count == 1, "expected 127.0.0.1 to be the only IP returned\n"); skip("Only the loopback address is present, skipping tests\n"); return; } @@ -4518,6 +4518,13 @@ static void test_gethostbyname(void) ret = pGetIpForwardTable(routes, &route_size, FALSE); ok (ret == NO_ERROR, "GetIpForwardTable failed, error: %d\n", ret); + /* This test only has meaning if there is more than one IP configured */ + if (adapters->Next == NULL && count == 1) + { + skip("Only one IP is present, skipping tests\n"); + goto cleanup; + } + for (i = 0; !found_default && i < routes->dwNumEntries; i++) { /* default route (ip 0.0.0.0) ? */ @@ -4541,6 +4548,7 @@ static void test_gethostbyname(void) todo_wine ok (found_default, "failed to find the first IP from gethostbyname!\n"); +cleanup: HeapFree(GetProcessHeap(), 0, adapters); HeapFree(GetProcessHeap(), 0, routes); }