Author: tfaber
Date: Tue Apr 5 12:20:47 2016
New Revision: 71100
URL:
http://svn.reactos.org/svn/reactos?rev=71100&view=rev
Log:
[WS2_32_APITEST]
- Add test for getservbyport
CORE-10440
Added:
trunk/rostests/apitests/ws2_32/getservbyport.c (with props)
Modified:
trunk/rostests/apitests/ws2_32/CMakeLists.txt
trunk/rostests/apitests/ws2_32/testlist.c
Modified: trunk/rostests/apitests/ws2_32/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ws2_32/CMakeList…
==============================================================================
--- trunk/rostests/apitests/ws2_32/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/rostests/apitests/ws2_32/CMakeLists.txt [iso-8859-1] Tue Apr 5 12:20:47 2016
@@ -1,6 +1,7 @@
list(APPEND SOURCE
getaddrinfo.c
+ getservbyport.c
helpers.c
ioctlsocket.c
nostartup.c
Added: trunk/rostests/apitests/ws2_32/getservbyport.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ws2_32/getservby…
==============================================================================
--- trunk/rostests/apitests/ws2_32/getservbyport.c (added)
+++ trunk/rostests/apitests/ws2_32/getservbyport.c [iso-8859-1] Tue Apr 5 12:20:47 2016
@@ -0,0 +1,144 @@
+/*
+ * PROJECT: ReactOS API tests
+ * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
+ * PURPOSE: Test for getservbyport
+ * PROGRAMMER: Thomas Faber <thomas.faber(a)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(getservbyport)
+{
+ WSADATA WsaData;
+ struct servent *Serv;
+ const struct
+ {
+ int Port;
+ struct
+ {
+ PCSTR Proto;
+ PCSTR Name;
+ PCSTR Aliases[5+1];
+ } Protos[3+1];
+ } Tests[] =
+ {
+ { 0, },
+ { -1, },
+ { 80, { { "tcp", "http", { "www",
"www-http" } },
+ { "udp", NULL },
+ { "xyz", NULL } } },
+ { 65536 + 80, { { "tcp", "http", { "www",
"www-http" } } } },
+ { 0xffff0050, { { "tcp", "http", { "www",
"www-http" } } } },
+ { 25, { { "tcp", "smtp", { "mail" }
} } },
+ { 445, { { "tcp", "microsoft-ds" },
+ { "udp", "microsoft-ds" } }
},
+ { 514, { { "tcp", "cmd", { "shell" }
},
+ { "udp", "syslog" } }
},
+ { 47624, { { "tcp", "directplaysrvr" },
+ { "udp", "directplaysrvr" } }
},
+ };
+ ULONG i, Proto, Alias;
+ int Error;
+ ULONG ExpectProto;
+
+ /* not yet initialized */
+ Serv = getservbyport(0, 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 = getservbyport(htons(Tests[i].Port), 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].Name == NULL)
+ {
+ ok(Serv == NULL, "[%d, %s] getservbyport succeeded
unexpectedly\n",
+ Tests[i].Port, Tests[i].Protos[Proto].Proto);
+ ok(Error == WSANO_DATA, "[%d, %s] getservbyport returned error
%d\n",
+ Tests[i].Port, Tests[i].Protos[Proto].Proto, Error);
+ continue;
+ }
+ else
+ {
+ ok(Serv != NULL, "[%d, %s] getservbyport failed with %d\n",
+ Tests[i].Port, Tests[i].Protos[Proto].Proto, Error);
+ }
+
+ if (Serv == NULL)
+ {
+ continue;
+ }
+
+ /* Check name */
+ ok(!strcmp(Serv->s_name, Tests[i].Protos[ExpectProto].Name),
+ "[%d, %s] s_name = '%s', expected '%s'\n",
+ Tests[i].Port, Tests[i].Protos[Proto].Proto, Serv->s_name,
Tests[i].Protos[ExpectProto].Name);
+
+ /* Check aliases */
+ ok(Serv->s_aliases != NULL, "[%d, %s] s_aliases = NULL\n",
+ Tests[i].Port, Tests[i].Protos[Proto].Proto);
+ for (Alias = 0; Serv->s_aliases; Alias++)
+ {
+ if (Alias >= RTL_NUMBER_OF(Tests[i].Protos[ExpectProto].Aliases))
+ {
+ ok(0, "[%d, %s] Too many aliases\n",
+ Tests[i].Port, Tests[i].Protos[Proto].Proto);
+ break;
+ }
+ if (Serv->s_aliases[Alias] == NULL)
+ {
+ ok(Tests[i].Protos[ExpectProto].Aliases[Alias] == NULL,
+ "[%d, %s] getservbyport did not return expected alias
'%s'\n",
+ Tests[i].Port, 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,
+ "[%d, %s] getservbyport returned additional alias
'%s'\n",
+ Tests[i].Port, Tests[i].Protos[Proto].Proto,
Serv->s_aliases[Alias]);
+ break;
+ }
+
+ ok(!strcmp(Serv->s_aliases[Alias],
Tests[i].Protos[ExpectProto].Aliases[Alias]),
+ "[%d, %s] Got alias '%s', expected
'%s'\n",
+ Tests[i].Port, Tests[i].Protos[Proto].Proto,
Serv->s_aliases[Alias],Tests[i].Protos[ExpectProto].Aliases[Alias]);
+ }
+
+ /* Port should be equal (upper bits are ignored) */
+ ok(ntohs(Serv->s_port) == (Tests[i].Port & 0xffff), "[%d, %s]
s_port = %d\n",
+ Tests[i].Port, Tests[i].Protos[Proto].Proto, ntohs(Serv->s_port));
+
+ /* Check proto */
+ ok(Serv->s_proto != NULL, "[%d, %s] s_proto = NULL\n",
+ Tests[i].Port, Tests[i].Protos[Proto].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);
+}
Propchange: trunk/rostests/apitests/ws2_32/getservbyport.c
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/rostests/apitests/ws2_32/testlist.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ws2_32/testlist.…
==============================================================================
--- trunk/rostests/apitests/ws2_32/testlist.c [iso-8859-1] (original)
+++ trunk/rostests/apitests/ws2_32/testlist.c [iso-8859-1] Tue Apr 5 12:20:47 2016
@@ -4,6 +4,7 @@
#include <apitest.h>
extern void func_getaddrinfo(void);
+extern void func_getservbyport(void);
extern void func_ioctlsocket(void);
extern void func_recv(void);
extern void func_send(void);
@@ -13,6 +14,7 @@
const struct test winetest_testlist[] =
{
{ "getaddrinfo", func_getaddrinfo },
+ { "getservbyport", func_getservbyport },
{ "ioctlsocket", func_ioctlsocket },
{ "nostartup", func_nostartup },
{ "recv", func_recv },