Commit 8ead5566 authored by Zac Brown's avatar Zac Brown Committed by Alexandre Julliard

winhttp/tests: Add test for sending request.

parent dc6fc6ad
......@@ -74,7 +74,80 @@ static void test_OpenRequest (void)
}
static void test_SendRequest (void)
{
HINTERNET session, request, connection;
DWORD header_len, optional_len, total_len;
DWORD bytes_rw;
BOOL ret;
CHAR buffer[256];
int i;
static const WCHAR test_site[] = {'c','r','o','s','s','o','v','e','r','.',
'c','o','d','e','w','e','a','v','e','r','s','.','c','o','m',0};
static const WCHAR content_type[] =
{'C','o','n','t','e','n','t','-','T','y','p','e',':',' ','a','p','p','l','i','c','a','t','i','o','n',
'/','x','-','w','w','w','-','f','o','r','m','-','u','r','l','e','n','c','o','d','e','d',0};
static const WCHAR test_file[] = {'/','p','o','s','t','t','e','s','t','.','p','h','p',0};
static const WCHAR test_verb[] = {'P','O','S','T',0};
static CHAR post_data[] = "mode=Test";
static CHAR test_post[] = "mode => Test\\0\n";
header_len = -1L;
total_len = optional_len = sizeof(post_data);
memset(buffer, 0xff, sizeof(buffer));
session = WinHttpOpen(test_useragent, WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0);
todo_wine ok(session != NULL, "WinHttpOpen failed to open session.\n");
connection = WinHttpConnect (session, test_site, INTERNET_DEFAULT_HTTP_PORT, 0);
todo_wine ok(connection != NULL,
"WinHttpConnect failed to open a connection, error: %u.\n", GetLastError());
request = WinHttpOpenRequest(connection, test_verb, test_file, NULL, WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES, WINHTTP_FLAG_BYPASS_PROXY_CACHE);
if (request == NULL && GetLastError() == ERROR_WINHTTP_NAME_NOT_RESOLVED)
{
skip("Network unreachable, skipping.\n");
goto done;
}
todo_wine ok(request != NULL, "WinHttpOpenrequest failed to open a request, error: %u.\n", GetLastError());
ret = WinHttpSendRequest(request, content_type, header_len, post_data, optional_len, total_len, 0);
todo_wine ok(ret == TRUE, "WinHttpSendRequest failed: %u\n", GetLastError());
for (i = 3; post_data[i]; i++)
{
bytes_rw = -1;
ret = WinHttpWriteData(request, &post_data[i], 1, &bytes_rw);
todo_wine ok(ret == TRUE, "WinHttpWriteData failed: %u.\n", GetLastError());
todo_wine ok(bytes_rw == 1, "WinHttpWriteData failed, wrote %u bytes instead of 1 byte.\n", bytes_rw);
}
ret = WinHttpReceiveResponse(request, NULL);
todo_wine ok(ret == TRUE, "WinHttpReceiveResponse failed: %u.\n", GetLastError());
bytes_rw = -1;
ret = WinHttpReadData(request, buffer, sizeof(buffer) - 1, &bytes_rw);
todo_wine ok(ret == TRUE, "WinHttpReadData failed: %u.\n", GetLastError());
todo_wine ok(bytes_rw == strlen(test_post), "Read %u bytes instead of %d.\n",
bytes_rw, strlen(test_post));
todo_wine ok(strncmp(buffer, test_post, bytes_rw) == 0,
"Data read did not match, got '%s'.\n", buffer);
ret = WinHttpCloseHandle(request);
todo_wine ok(ret == TRUE, "WinHttpCloseHandle failed on closing request, got %d.\n", ret);
done:
ret = WinHttpCloseHandle(connection);
todo_wine ok(ret == TRUE, "WinHttpCloseHandle failed on closing connection, got %d.\n", ret);
ret = WinHttpCloseHandle(session);
todo_wine ok(ret == TRUE, "WinHttpCloseHandle failed on closing session, got %d.\n", ret);
}
START_TEST (winhttp)
{
test_OpenRequest();
test_SendRequest();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment