reactos/rostests/winetests/ws2_32/protocol.c
Amine Khaldi e81e634203 [WS2_32_WINETEST]
* Sync with Wine 1.7.1.
CORE-7469

svn path=/trunk/; revision=61243
2013-12-07 20:26:32 +00:00

150 lines
4.9 KiB
C

/*
* Unit test suite for protocol functions
*
* Copyright 2004 Hans Leidekker
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
#include <winsock2.h>
#include "wine/test.h"
/* TCP and UDP over IP fixed set of service flags */
#define TCPIP_SERVICE_FLAGS (XP1_GUARANTEED_DELIVERY \
| XP1_GUARANTEED_ORDER \
| XP1_GRACEFUL_CLOSE \
| XP1_EXPEDITED_DATA \
| XP1_IFS_HANDLES)
#define UDPIP_SERVICE_FLAGS (XP1_CONNECTIONLESS \
| XP1_MESSAGE_ORIENTED \
| XP1_SUPPORT_BROADCAST \
| XP1_SUPPORT_MULTIPOINT \
| XP1_IFS_HANDLES)
static void test_service_flags(int family, int version, int socktype, int protocol, DWORD testflags)
{
DWORD expectedflags = 0;
if (socktype == SOCK_STREAM && protocol == IPPROTO_TCP)
expectedflags = TCPIP_SERVICE_FLAGS;
if (socktype == SOCK_DGRAM && protocol == IPPROTO_UDP)
expectedflags = UDPIP_SERVICE_FLAGS;
/* check if standard TCP and UDP protocols are offering the correct service flags */
if ((family == AF_INET || family == AF_INET6) && version == 2 && expectedflags)
{
/* QOS may or may not be installed */
testflags &= ~XP1_QOS_SUPPORTED;
ok(expectedflags == testflags,
"Incorrect flags, expected 0x%x, received 0x%x\n",
expectedflags, testflags);
}
}
static void test_WSAEnumProtocolsA(void)
{
INT ret;
DWORD len = 0, error;
WSAPROTOCOL_INFOA info, *buffer;
ret = WSAEnumProtocolsA( NULL, NULL, &len );
ok( ret == SOCKET_ERROR, "WSAEnumProtocolsA() succeeded unexpectedly\n");
error = WSAGetLastError();
ok( error == WSAENOBUFS, "Expected 10055, received %d\n", error);
len = 0;
ret = WSAEnumProtocolsA( NULL, &info, &len );
ok( ret == SOCKET_ERROR, "WSAEnumProtocolsA() succeeded unexpectedly\n");
error = WSAGetLastError();
ok( error == WSAENOBUFS, "Expected 10055, received %d\n", error);
buffer = HeapAlloc( GetProcessHeap(), 0, len );
if (buffer)
{
INT i;
ret = WSAEnumProtocolsA( NULL, buffer, &len );
ok( ret != SOCKET_ERROR, "WSAEnumProtocolsA() failed unexpectedly: %d\n",
WSAGetLastError() );
for (i = 0; i < ret; i++)
{
ok( strlen( buffer[i].szProtocol ), "No protocol name found\n" );
test_service_flags( buffer[i].iAddressFamily, buffer[i].iVersion,
buffer[i].iSocketType, buffer[i].iProtocol,
buffer[i].dwServiceFlags1);
}
HeapFree( GetProcessHeap(), 0, buffer );
}
}
static void test_WSAEnumProtocolsW(void)
{
INT ret;
DWORD len = 0, error;
WSAPROTOCOL_INFOW info, *buffer;
ret = WSAEnumProtocolsW( NULL, NULL, &len );
ok( ret == SOCKET_ERROR, "WSAEnumProtocolsW() succeeded unexpectedly\n");
error = WSAGetLastError();
ok( error == WSAENOBUFS, "Expected 10055, received %d\n", error);
len = 0;
ret = WSAEnumProtocolsW( NULL, &info, &len );
ok( ret == SOCKET_ERROR, "WSAEnumProtocolsW() succeeded unexpectedly\n");
error = WSAGetLastError();
ok( error == WSAENOBUFS, "Expected 10055, received %d\n", error);
buffer = HeapAlloc( GetProcessHeap(), 0, len );
if (buffer)
{
INT i;
ret = WSAEnumProtocolsW( NULL, buffer, &len );
ok( ret != SOCKET_ERROR, "WSAEnumProtocolsW() failed unexpectedly: %d\n",
WSAGetLastError() );
for (i = 0; i < ret; i++)
{
ok( lstrlenW( buffer[i].szProtocol ), "No protocol name found\n" );
test_service_flags( buffer[i].iAddressFamily, buffer[i].iVersion,
buffer[i].iSocketType, buffer[i].iProtocol,
buffer[i].dwServiceFlags1);
}
HeapFree( GetProcessHeap(), 0, buffer );
}
}
START_TEST( protocol )
{
WSADATA data;
WORD version = MAKEWORD( 2, 2 );
if (WSAStartup( version, &data )) return;
test_WSAEnumProtocolsA();
test_WSAEnumProtocolsW();
}