[APITESTS]
[reactos.git] / rostests / apitests / ws2_32 / helpers.c
1 /*
2 * PROJECT: ws2_32.dll API tests
3 * LICENSE: GPLv2 or any later version
4 * FILE: apitests/ws2_32/helpers.c
5 * PURPOSE: Helper functions for the socket tests
6 * COPYRIGHT: Copyright 2008 Colin Finck <mail@colinfinck.de>
7 */
8
9 #include <stdio.h>
10 #include <wine/test.h>
11 #include "ws2_32.h"
12
13 int CreateSocket(SOCKET* psck)
14 {
15 /* Create the socket */
16 *psck = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
17 ok(*psck != INVALID_SOCKET, "*psck = %d\n", *psck);
18
19 if(*psck == INVALID_SOCKET)
20 {
21 printf("Winsock error code is %u\n", WSAGetLastError());
22 WSACleanup();
23 return 0;
24 }
25
26 return 1;
27 }
28
29 int ConnectToReactOSWebsite(SOCKET sck)
30 {
31 int iResult;
32 struct hostent* host;
33 struct sockaddr_in sa;
34
35 /* Connect to "www.reactos.org" */
36 host = gethostbyname("www.reactos.org");
37
38 sa.sin_family = AF_INET;
39 sa.sin_addr.s_addr = *(u_long*)host->h_addr_list[0];
40 sa.sin_port = htons(80);
41
42 SCKTEST(connect(sck, (struct sockaddr *)&sa, sizeof(sa)));
43
44 return 1;
45 }
46
47 int GetRequestAndWait(SOCKET sck)
48 {
49 const char szGetRequest[] = "GET / HTTP/1.0\r\n\r\n";
50 int iResult;
51 struct fd_set readable;
52
53 /* Send the GET request */
54 SCKTEST(send(sck, szGetRequest, strlen(szGetRequest), 0));
55 ok(iResult == strlen(szGetRequest), "iResult = %d\n", iResult);
56
57 /* Shutdown the SEND connection */
58 SCKTEST(shutdown(sck, SD_SEND));
59
60 /* Wait until we're ready to read */
61 FD_ZERO(&readable);
62 FD_SET(sck, &readable);
63
64 SCKTEST(select(0, &readable, NULL, NULL, NULL));
65
66 return 1;
67 }