From 8ead5566485aa3b4fcbad9ea16facce31b73ccdc Mon Sep 17 00:00:00 2001 From: Zac Brown Date: Wed, 30 Jul 2008 13:20:40 -0700 Subject: [PATCH] winhttp/tests: Add test for sending request. --- dlls/winhttp/tests/winhttp.c | 73 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/dlls/winhttp/tests/winhttp.c b/dlls/winhttp/tests/winhttp.c index d417a564087..3b43550104d 100644 --- a/dlls/winhttp/tests/winhttp.c +++ b/dlls/winhttp/tests/winhttp.c @@ -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(); } -- 2.11.4.GIT