2 * PROJECT: ReactOS API tests
3 * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Test for getservbyport
5 * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
10 #define WIN32_NO_STATUS
12 #define COM_NO_WINDOWS_H
18 START_TEST(getservbyport
)
35 { 80, { { "tcp", "http", { "www", "www-http" } },
38 { 65536 + 80, { { "tcp", "http", { "www", "www-http" } } } },
39 { 0xffff0050, { { "tcp", "http", { "www", "www-http" } } } },
40 { 25, { { "tcp", "smtp", { "mail" } } } },
41 { 445, { { "tcp", "microsoft-ds" },
42 { "udp", "microsoft-ds" } } },
43 { 514, { { "tcp", "cmd", { "shell" } },
44 { "udp", "syslog" } } },
45 { 47624, { { "tcp", "directplaysrvr" },
46 { "udp", "directplaysrvr" } } },
48 ULONG i
, Proto
, Alias
;
52 /* not yet initialized */
53 Serv
= getservbyport(0, NULL
);
54 Error
= WSAGetLastError();
55 ok(Serv
== NULL
, "Serv = %p\n", Serv
);
56 ok(Error
== WSANOTINITIALISED
, "Error = %d\n", Error
);
58 Error
= WSAStartup(MAKEWORD(2, 2), &WsaData
);
61 for (i
= 0; i
< RTL_NUMBER_OF(Tests
); i
++)
66 Serv
= getservbyport(htons(Tests
[i
].Port
), Tests
[i
].Protos
[Proto
].Proto
);
67 Error
= WSAGetLastError();
69 /* For a NULL proto we expect the same as the first array entry */
71 if (Tests
[i
].Protos
[Proto
].Proto
== NULL
)
76 if (Tests
[i
].Protos
[ExpectProto
].Name
== NULL
)
78 ok(Serv
== NULL
, "[%d, %s] getservbyport succeeded unexpectedly\n",
79 Tests
[i
].Port
, Tests
[i
].Protos
[Proto
].Proto
);
80 ok(Error
== WSANO_DATA
, "[%d, %s] getservbyport returned error %d\n",
81 Tests
[i
].Port
, Tests
[i
].Protos
[Proto
].Proto
, Error
);
86 ok(Serv
!= NULL
, "[%d, %s] getservbyport failed with %d\n",
87 Tests
[i
].Port
, Tests
[i
].Protos
[Proto
].Proto
, Error
);
96 ok(!strcmp(Serv
->s_name
, Tests
[i
].Protos
[ExpectProto
].Name
),
97 "[%d, %s] s_name = '%s', expected '%s'\n",
98 Tests
[i
].Port
, Tests
[i
].Protos
[Proto
].Proto
, Serv
->s_name
, Tests
[i
].Protos
[ExpectProto
].Name
);
101 ok(Serv
->s_aliases
!= NULL
, "[%d, %s] s_aliases = NULL\n",
102 Tests
[i
].Port
, Tests
[i
].Protos
[Proto
].Proto
);
103 for (Alias
= 0; Serv
->s_aliases
; Alias
++)
105 if (Alias
>= RTL_NUMBER_OF(Tests
[i
].Protos
[ExpectProto
].Aliases
))
107 ok(0, "[%d, %s] Too many aliases\n",
108 Tests
[i
].Port
, Tests
[i
].Protos
[Proto
].Proto
);
111 if (Serv
->s_aliases
[Alias
] == NULL
)
113 ok(Tests
[i
].Protos
[ExpectProto
].Aliases
[Alias
] == NULL
,
114 "[%d, %s] getservbyport did not return expected alias '%s'\n",
115 Tests
[i
].Port
, Tests
[i
].Protos
[Proto
].Proto
, Tests
[i
].Protos
[ExpectProto
].Aliases
[Alias
]);
118 if (Tests
[i
].Protos
[ExpectProto
].Aliases
[Alias
] == NULL
)
120 ok(Serv
->s_aliases
[Alias
] == NULL
,
121 "[%d, %s] getservbyport returned additional alias '%s'\n",
122 Tests
[i
].Port
, Tests
[i
].Protos
[Proto
].Proto
, Serv
->s_aliases
[Alias
]);
126 ok(!strcmp(Serv
->s_aliases
[Alias
], Tests
[i
].Protos
[ExpectProto
].Aliases
[Alias
]),
127 "[%d, %s] Got alias '%s', expected '%s'\n",
128 Tests
[i
].Port
, Tests
[i
].Protos
[Proto
].Proto
, Serv
->s_aliases
[Alias
],Tests
[i
].Protos
[ExpectProto
].Aliases
[Alias
]);
131 /* Port should be equal (upper bits are ignored) */
132 ok(ntohs(Serv
->s_port
) == (Tests
[i
].Port
& 0xffff), "[%d, %s] s_port = %d\n",
133 Tests
[i
].Port
, Tests
[i
].Protos
[Proto
].Proto
, ntohs(Serv
->s_port
));
136 ok(Serv
->s_proto
!= NULL
, "[%d, %s] s_proto = NULL\n",
137 Tests
[i
].Port
, Tests
[i
].Protos
[Proto
].Proto
);
138 /* We want to include one NULL past the last proto in the array */
139 } while (Tests
[i
].Protos
[Proto
++].Proto
!= NULL
);
142 Error
= WSACleanup();