mirror of
https://github.com/reactos/reactos.git
synced 2024-07-07 13:15:07 +00:00
[WS2_32_APITEST]
- Add test for getservbyname CORE-10440 svn path=/trunk/; revision=71101
This commit is contained in:
parent
8726fc984a
commit
edc42192c4
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
list(APPEND SOURCE
|
list(APPEND SOURCE
|
||||||
getaddrinfo.c
|
getaddrinfo.c
|
||||||
|
getservbyname.c
|
||||||
getservbyport.c
|
getservbyport.c
|
||||||
helpers.c
|
helpers.c
|
||||||
ioctlsocket.c
|
ioctlsocket.c
|
||||||
|
|
146
rostests/apitests/ws2_32/getservbyname.c
Normal file
146
rostests/apitests/ws2_32/getservbyname.c
Normal file
|
@ -0,0 +1,146 @@
|
||||||
|
/*
|
||||||
|
* PROJECT: ReactOS API tests
|
||||||
|
* LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
|
||||||
|
* PURPOSE: Test for getservbyname
|
||||||
|
* PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <apitest.h>
|
||||||
|
|
||||||
|
#define WIN32_NO_STATUS
|
||||||
|
#define _INC_WINDOWS
|
||||||
|
#define COM_NO_WINDOWS_H
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <windef.h>
|
||||||
|
#include <winbase.h>
|
||||||
|
#include <ws2tcpip.h>
|
||||||
|
|
||||||
|
START_TEST(getservbyname)
|
||||||
|
{
|
||||||
|
WSADATA WsaData;
|
||||||
|
struct servent *Serv;
|
||||||
|
const struct
|
||||||
|
{
|
||||||
|
PCSTR Name;
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
PCSTR Proto;
|
||||||
|
int Port;
|
||||||
|
PCSTR Name;
|
||||||
|
PCSTR Aliases[5+1];
|
||||||
|
} Protos[3+1];
|
||||||
|
} Tests[] =
|
||||||
|
{
|
||||||
|
{ "" },
|
||||||
|
{ "xyzzy" },
|
||||||
|
{ "http", { { "tcp", 80, "http", { "www", "www-http" } },
|
||||||
|
{ "udp", 0 },
|
||||||
|
{ "xyz", 0 } } },
|
||||||
|
{ "smtp", { { "tcp", 25, "smtp", { "mail" } } } },
|
||||||
|
{ "mail", { { "tcp", 25, "smtp", { "mail" } } } },
|
||||||
|
{ "microsoft-ds", { { "tcp", 445, "microsoft-ds", },
|
||||||
|
{ "udp", 445, "microsoft-ds", } } },
|
||||||
|
{ "cmd", { { "tcp", 514, "cmd", { "shell" } },
|
||||||
|
{ "udp", 0 } } },
|
||||||
|
{ "syslog", { { "udp", 514, "syslog" },
|
||||||
|
{ "tcp", 0 } } },
|
||||||
|
{ "directplaysrvr", { { "tcp", 47624, "directplaysrvr" },
|
||||||
|
{ "udp", 47624, "directplaysrvr" } } },
|
||||||
|
};
|
||||||
|
ULONG i, Proto, Alias;
|
||||||
|
int Error;
|
||||||
|
ULONG ExpectProto;
|
||||||
|
|
||||||
|
/* not yet initialized */
|
||||||
|
Serv = getservbyname(NULL, NULL);
|
||||||
|
Error = WSAGetLastError();
|
||||||
|
ok(Serv == NULL, "Serv = %p\n", Serv);
|
||||||
|
ok(Error == WSANOTINITIALISED, "Error = %d\n", Error);
|
||||||
|
|
||||||
|
Error = WSAStartup(MAKEWORD(2, 2), &WsaData);
|
||||||
|
ok_dec(Error, 0);
|
||||||
|
|
||||||
|
for (i = 0; i < RTL_NUMBER_OF(Tests); i++)
|
||||||
|
{
|
||||||
|
Proto = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
Serv = getservbyname(Tests[i].Name, Tests[i].Protos[Proto].Proto);
|
||||||
|
Error = WSAGetLastError();
|
||||||
|
|
||||||
|
/* For a NULL proto we expect the same as the first array entry */
|
||||||
|
ExpectProto = Proto;
|
||||||
|
if (Tests[i].Protos[Proto].Proto == NULL)
|
||||||
|
{
|
||||||
|
ExpectProto = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Tests[i].Protos[ExpectProto].Port == 0)
|
||||||
|
{
|
||||||
|
ok(Serv == NULL, "[%s, %s] getservbyname succeeded unexpectedly\n",
|
||||||
|
Tests[i].Name, Tests[i].Protos[Proto].Proto);
|
||||||
|
ok(Error == WSANO_DATA, "[%s, %s] getservbyname returned error %d\n",
|
||||||
|
Tests[i].Name, Tests[i].Protos[Proto].Proto, Error);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ok(Serv != NULL, "[%s, %s] getservbyname failed with %d\n",
|
||||||
|
Tests[i].Name, Tests[i].Protos[Proto].Proto, Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Serv == NULL)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check name */
|
||||||
|
ok(!strcmp(Serv->s_name, Tests[i].Protos[ExpectProto].Name),
|
||||||
|
"[%s, %s] s_name = '%s', expected '%s'\n",
|
||||||
|
Tests[i].Name, Tests[i].Protos[Proto].Proto, Serv->s_name, Tests[i].Protos[ExpectProto].Name);
|
||||||
|
|
||||||
|
/* Check aliases */
|
||||||
|
ok(Serv->s_aliases != NULL, "[%s, %s] s_aliases = NULL\n",
|
||||||
|
Tests[i].Name, Tests[i].Protos[Proto].Proto);
|
||||||
|
for (Alias = 0; Serv->s_aliases; Alias++)
|
||||||
|
{
|
||||||
|
if (Alias >= RTL_NUMBER_OF(Tests[i].Protos[ExpectProto].Aliases))
|
||||||
|
{
|
||||||
|
ok(0, "[%s, %s] Too many aliases\n",
|
||||||
|
Tests[i].Name, Tests[i].Protos[Proto].Proto);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (Serv->s_aliases[Alias] == NULL)
|
||||||
|
{
|
||||||
|
ok(Tests[i].Protos[ExpectProto].Aliases[Alias] == NULL,
|
||||||
|
"[%s, %s] getservbyname did not return expected alias '%s'\n",
|
||||||
|
Tests[i].Name, Tests[i].Protos[Proto].Proto, Tests[i].Protos[ExpectProto].Aliases[Alias]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (Tests[i].Protos[ExpectProto].Aliases[Alias] == NULL)
|
||||||
|
{
|
||||||
|
ok(Serv->s_aliases[Alias] == NULL,
|
||||||
|
"[%s, %s] getservbyname returned additional alias '%s'\n",
|
||||||
|
Tests[i].Name, Tests[i].Protos[Proto].Proto, Serv->s_aliases[Alias]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ok(!strcmp(Serv->s_aliases[Alias], Tests[i].Protos[ExpectProto].Aliases[Alias]),
|
||||||
|
"[%s, %s] Got alias '%s', expected '%s'\n",
|
||||||
|
Tests[i].Name, Tests[i].Protos[Proto].Proto, Serv->s_aliases[Alias],Tests[i].Protos[ExpectProto].Aliases[Alias]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check port */
|
||||||
|
ok(ntohs(Serv->s_port) == Tests[i].Protos[ExpectProto].Port, "[%s, %s] s_port = %d\n",
|
||||||
|
Tests[i].Name, Tests[i].Protos[Proto].Proto, ntohs(Serv->s_port));
|
||||||
|
|
||||||
|
/* Check proto */
|
||||||
|
ok(!strcmp(Serv->s_proto, Tests[i].Protos[ExpectProto].Proto), "[%s, %s] s_proto = '%s', expected '%s'\n",
|
||||||
|
Tests[i].Name, Tests[i].Protos[Proto].Proto, Serv->s_proto, Tests[i].Protos[ExpectProto].Proto);
|
||||||
|
/* We want to include one NULL past the last proto in the array */
|
||||||
|
} while (Tests[i].Protos[Proto++].Proto != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
Error = WSACleanup();
|
||||||
|
ok_dec(Error, 0);
|
||||||
|
}
|
|
@ -133,8 +133,8 @@ START_TEST(getservbyport)
|
||||||
Tests[i].Port, Tests[i].Protos[Proto].Proto, ntohs(Serv->s_port));
|
Tests[i].Port, Tests[i].Protos[Proto].Proto, ntohs(Serv->s_port));
|
||||||
|
|
||||||
/* Check proto */
|
/* Check proto */
|
||||||
ok(Serv->s_proto != NULL, "[%d, %s] s_proto = NULL\n",
|
ok(!strcmp(Serv->s_proto, Tests[i].Protos[ExpectProto].Proto), "[%d, %s] s_proto = '%s', expected '%s'\n",
|
||||||
Tests[i].Port, Tests[i].Protos[Proto].Proto);
|
Tests[i].Port, Tests[i].Protos[Proto].Proto, Serv->s_proto, Tests[i].Protos[ExpectProto].Proto);
|
||||||
/* We want to include one NULL past the last proto in the array */
|
/* We want to include one NULL past the last proto in the array */
|
||||||
} while (Tests[i].Protos[Proto++].Proto != NULL);
|
} while (Tests[i].Protos[Proto++].Proto != NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <apitest.h>
|
#include <apitest.h>
|
||||||
|
|
||||||
extern void func_getaddrinfo(void);
|
extern void func_getaddrinfo(void);
|
||||||
|
extern void func_getservbyname(void);
|
||||||
extern void func_getservbyport(void);
|
extern void func_getservbyport(void);
|
||||||
extern void func_ioctlsocket(void);
|
extern void func_ioctlsocket(void);
|
||||||
extern void func_recv(void);
|
extern void func_recv(void);
|
||||||
|
@ -14,6 +15,7 @@ extern void func_nostartup(void);
|
||||||
const struct test winetest_testlist[] =
|
const struct test winetest_testlist[] =
|
||||||
{
|
{
|
||||||
{ "getaddrinfo", func_getaddrinfo },
|
{ "getaddrinfo", func_getaddrinfo },
|
||||||
|
{ "getservbyname", func_getservbyname },
|
||||||
{ "getservbyport", func_getservbyport },
|
{ "getservbyport", func_getservbyport },
|
||||||
{ "ioctlsocket", func_ioctlsocket },
|
{ "ioctlsocket", func_ioctlsocket },
|
||||||
{ "nostartup", func_nostartup },
|
{ "nostartup", func_nostartup },
|
||||||
|
|
Loading…
Reference in a new issue