2 * PROJECT: ws2_32.dll API tests
3 * LICENSE: GPLv2 or any later version
4 * FILE: apitests/ws2_32/tests/recv.c
5 * PURPOSE: Tests for the recv function
6 * COPYRIGHT: Copyright 2008 Colin Finck <mail@colinfinck.de>
13 /* For valid test results, the ReactOS Website needs to return at least 8 bytes on a "GET / HTTP/1.0" request.
14 Also the first 4 bytes and the last 4 bytes need to be different.
15 Both factors usually apply on standard HTTP responses. */
17 Test_recv(PTESTINFO pti
)
19 const char szDummyBytes
[RECV_BUF
] = {0xFF, 0x00, 0xFF, 0x00};
21 char szBuf1
[RECV_BUF
];
22 char szBuf2
[RECV_BUF
];
27 /* Start up Winsock */
28 TEST(WSAStartup(MAKEWORD(2, 2), &wdata
) == 0);
30 /* If we call recv without a socket, it should return with an error and do nothing. */
31 memcpy(szBuf1
, szDummyBytes
, RECV_BUF
);
32 TEST(recv(0, szBuf1
, RECV_BUF
, 0) == SOCKET_ERROR
);
33 TEST(!memcmp(szBuf1
, szDummyBytes
, RECV_BUF
));
35 /* Create the socket */
36 iResult
= CreateSocket(pti
, &sck
);
37 if(iResult
!= APISTATUS_NORMAL
)
40 /* Now we can pass at least a socket, but we have no connection yet. Should return with an error and do nothing. */
41 memcpy(szBuf1
, szDummyBytes
, RECV_BUF
);
42 TEST(recv(sck
, szBuf1
, RECV_BUF
, 0) == SOCKET_ERROR
);
43 TEST(!memcmp(szBuf1
, szDummyBytes
, RECV_BUF
));
45 /* Connect to "www.reactos.org" */
46 iResult
= ConnectToReactOSWebsite(pti
, sck
);
47 if(iResult
!= APISTATUS_NORMAL
)
50 /* Send the GET request */
51 iResult
= GetRequestAndWait(pti
, sck
);
52 if(iResult
!= APISTATUS_NORMAL
)
56 MSG_PEEK will not change the internal number of bytes read, so that a subsequent request should return the same bytes again. */
57 SCKTEST(recv(sck
, szBuf1
, RECV_BUF
, MSG_PEEK
));
58 SCKTEST(recv(sck
, szBuf2
, RECV_BUF
, 0));
59 TEST(!memcmp(szBuf1
, szBuf2
, RECV_BUF
));
61 /* The last recv() call moved the internal file pointer, so that the next request should return different data. */
62 SCKTEST(recv(sck
, szBuf1
, RECV_BUF
, 0));
63 TEST(memcmp(szBuf1
, szBuf2
, RECV_BUF
));
68 return APISTATUS_NORMAL
;