winhttp: tests/winhttp.c[new]: Add test for WinHttpOpenRequest
Zac Brown
zac at zacbrown.org
Thu Jul 10 17:40:38 CDT 2008
Zac Brown wrote:
> Add test for WinHttpOpenRequest. This test is modeled after
> wininet/tests/http.c's InternetOpenRequest_test function.
>
> This is the first of many tests for getting Bug 14381
> (http://bugs.winehq.org/show_bug.cgi?id=14381) fixed with regard to
> WinHTTP.
>
>
> ------------------------------------------------------------------------
>
> ---
> Makefile.in | 2 +
> configure | 3 +
> dlls/Makefile.in | 1 +
> dlls/winhttp/tests/Makefile.in | 13 +++++
> dlls/winhttp/tests/winhttp.c | 105 ++++++++++++++++++++++++++++++++++++++++
> 5 files changed, 124 insertions(+), 0 deletions(-)
> create mode 100644 dlls/winhttp/tests/Makefile.in
> create mode 100644 dlls/winhttp/tests/winhttp.c
>
> diff --git a/Makefile.in b/Makefile.in
> index 1b35079..6a56e44 100644
> --- a/Makefile.in
> +++ b/Makefile.in
> @@ -495,6 +495,7 @@ ALL_MAKEFILES = \
> dlls/winex11.drv/Makefile \
> dlls/wing32/Makefile \
> dlls/winhttp/Makefile \
> + dlls/winhttp/tests/Makefile \
> dlls/wininet/Makefile \
> dlls/wininet/tests/Makefile \
> dlls/winmm/Makefile \
> @@ -924,6 +925,7 @@ dlls/winequartz.drv/Makefile: dlls/winequartz.drv/Makefile.in dlls/Makedll.rules
> dlls/winex11.drv/Makefile: dlls/winex11.drv/Makefile.in dlls/Makedll.rules
> dlls/wing32/Makefile: dlls/wing32/Makefile.in dlls/Makedll.rules
> dlls/winhttp/Makefile: dlls/winhttp/Makefile.in dlls/Makedll.rules
> +dlls/winhttp/tests/Makefile: dlls/winhttp/tests/Makefile.in dlls/Maketest.rules
> dlls/wininet/Makefile: dlls/wininet/Makefile.in dlls/Makedll.rules
> dlls/wininet/tests/Makefile: dlls/wininet/tests/Makefile.in dlls/Maketest.rules
> dlls/winmm/Makefile: dlls/winmm/Makefile.in dlls/Makedll.rules
> diff --git a/configure b/configure
> index d9f9b65..a276261 100755
> --- a/configure
> +++ b/configure
> @@ -22416,6 +22416,8 @@ ac_config_files="$ac_config_files dlls/wing32/Makefile"
>
> ac_config_files="$ac_config_files dlls/winhttp/Makefile"
>
> +ac_config_files="$ac_config_files dlls/winhttp/tests/Makefile"
> +
> ac_config_files="$ac_config_files dlls/wininet/Makefile"
>
> ac_config_files="$ac_config_files dlls/wininet/tests/Makefile"
> @@ -23481,6 +23483,7 @@ do
> "dlls/winex11.drv/Makefile") CONFIG_FILES="$CONFIG_FILES dlls/winex11.drv/Makefile" ;;
> "dlls/wing32/Makefile") CONFIG_FILES="$CONFIG_FILES dlls/wing32/Makefile" ;;
> "dlls/winhttp/Makefile") CONFIG_FILES="$CONFIG_FILES dlls/winhttp/Makefile" ;;
> + "dlls/winhttp/tests/Makefile") CONFIG_FILES="$CONFIG_FILES dlls/winhttp/tests/Makefile" ;;
> "dlls/wininet/Makefile") CONFIG_FILES="$CONFIG_FILES dlls/wininet/Makefile" ;;
> "dlls/wininet/tests/Makefile") CONFIG_FILES="$CONFIG_FILES dlls/wininet/tests/Makefile" ;;
> "dlls/winmm/Makefile") CONFIG_FILES="$CONFIG_FILES dlls/winmm/Makefile" ;;
> diff --git a/dlls/Makefile.in b/dlls/Makefile.in
> index d130f35..1a77dc0 100644
> --- a/dlls/Makefile.in
> +++ b/dlls/Makefile.in
> @@ -362,6 +362,7 @@ TESTSUBDIRS = \
> usp10/tests \
> uxtheme/tests \
> version/tests \
> + winhttp/tests \
> wininet/tests \
> winmm/tests \
> winspool.drv/tests \
> diff --git a/dlls/winhttp/tests/Makefile.in b/dlls/winhttp/tests/Makefile.in
> new file mode 100644
> index 0000000..3f35e08
> --- /dev/null
> +++ b/dlls/winhttp/tests/Makefile.in
> @@ -0,0 +1,13 @@
> +TOPSRCDIR = @top_srcdir@
> +TOPOBJDIR = ../../..
> +SRCDIR = @srcdir@
> +VPATH = @srcdir@
> +TESTDLL = winhttp.dll
> +IMPORTS = winhttp ws2_32 kernel32
> +
> +CTESTS = \
> + winhttp.c
> +
> + at MAKE_TEST_RULES@
> +
> + at DEPENDENCIES@ # everything below this line is overwritten by make depend
> diff --git a/dlls/winhttp/tests/winhttp.c b/dlls/winhttp/tests/winhttp.c
> new file mode 100644
> index 0000000..afc9d97
> --- /dev/null
> +++ b/dlls/winhttp/tests/winhttp.c
> @@ -0,0 +1,105 @@
> +/*
> + * WinHTTP - tests
> + *
> + * Copyright 2008 Google (Zac Brown)
> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * This library is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
> + * 02110-1301, USA
> + */
> +
> +#define COBJMACROS
> +
> +#include <stdarg.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +
> +#include <windef.h>
> +#include <winbase.h>
> +#include <winhttp.h>
> +
> +#include "wine/test.h"
> +
> +/* Function pointer declarations for functions being used */
> +static HINTERNET (WINAPI *pWinHttpOpen) (LPCWSTR pwszUserAgent, DWORD dwAccessType,
> + LPCWSTR pwszProxyName, LPCWSTR pwszProxyBypass, DWORD dwFlags);
> +static HINTERNET (WINAPI *pWinHttpConnect) (HINTERNET hSession, LPCWSTR pwszServerName,
> + INTERNET_PORT nServerPort, DWORD dwReserved);
> +static HINTERNET (WINAPI *pWinHttpOpenRequest) (HINTERNET hConnect, LPCWSTR pwszVerb,
> + LPCWSTR pwszObjectName, LPCWSTR pwszVersion, LPCWSTR pwszReferrer,
> + LPCWSTR* ppwszAcceptTypes, DWORD dwFlags);
> +static BOOL (WINAPI *pWinHttpSendRequest) (HINTERNET hRequest, LPCWSTR pwszHeaders,
> + DWORD dwHeadersLength, LPVOID lpOptional, DWORD dwOptionalLength,
> + DWORD dwTotalLength, DWORD_PTR dwContext);
> +static BOOL (WINAPI *pWinHttpCloseHandle) (HINTERNET hInternet);
> +
> +static const WCHAR test_useragent[] = {'W','i','n','e',' ','R','e','g','r','e','s','s','i','o','n',' ','T','e','s','t',0};
> +static const WCHAR test_server[] = {'w','i','n','e','h','q','.','o','r','g',0};
> +
> +/* BEGIN TESTS */
> +
> +static void test_OpenRequest (void)
> +{
> + BOOL ret;
> + HINTERNET session, request, connection;
> + session = request = connection = NULL;
> +
> + session = pWinHttpOpen (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");
> +
> + /* Test with a bad server name */
> + SetLastError (0xdeadbeef);
> + connection = pWinHttpConnect (session, NULL, INTERNET_DEFAULT_HTTP_PORT, 0);
> + ok (connection == NULL, "WinHttpConnect succeeded in opening connection to NULL server argument.\n");
> + todo_wine ok (GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %u.\n", GetLastError());
> +
> + /* Test with a valid server name */
> + connection = pWinHttpConnect (session, test_server, INTERNET_DEFAULT_HTTP_PORT, 0);
> + todo_wine ok (connection != NULL, "WinHttpConnect failed to open a connection, error: %u.\n", GetLastError());
> +
> + request = pWinHttpOpenRequest (connection, NULL, NULL, NULL, WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES, 0);
> + 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 = pWinHttpSendRequest (request, WINHTTP_NO_ADDITIONAL_HEADERS, 0, NULL, 0, 0, 0);
> + todo_wine
> + {
> + ok (ret == TRUE, "WinHttpSendRequest failed: %u\n", GetLastError());
> + ok (WinHttpCloseHandle (request), "WinHttpCloseHandle failed on closing request.\n");
> + }
> +
> + done:
> + todo_wine
> + {
> + ok (WinHttpCloseHandle (connection), "WinHttpCloseHandle failed on closing connection.\n");
> + ok (WinHttpCloseHandle (session), "WinHttpCloseHandle failed on closing session.\n");
> + }
> +}
> +
> +START_TEST (winhttp)
> +{
> + HMODULE hmod = LoadLibraryA ("winhttp.dll");
> +
> + pWinHttpOpen = (void *) GetProcAddress (hmod, "WinHttpOpen");
> + pWinHttpConnect = (void *) GetProcAddress (hmod, "WinHttpConnect");
> + pWinHttpOpenRequest = (void *) GetProcAddress (hmod, "WinHttpOpenRequest");
> + pWinHttpSendRequest = (void *) GetProcAddress (hmod, "WinHttpSendRequest");
> + pWinHttpCloseHandle = (void *) GetProcAddress (hmod, "WinHttpCloseHandle");
> +
> + test_OpenRequest();
> +}
>
>
> ------------------------------------------------------------------------
>
>
Ignore this patch, comments from James warrant a revision.
More information about the wine-devel
mailing list