ReactOS  0.4.14-dev-49-gfb4591c
WinHttpOpen.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS api tests
3  * LICENSE: GPLv2+ - See COPYING in the top level directory
4  * PURPOSE: Test for WinHttpOpen
5  * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
6  */
7 
8 #include <apitest.h>
9 
10 #define WIN32_NO_STATUS
11 #define _INC_WINDOWS
12 #define COM_NO_WINDOWS_H
13 #include <windef.h>
14 #include <winsock2.h>
15 #include <winhttp.h>
16 
17 struct hostent *(WINAPI *pgethostbyname)(const char *);
20 
22 BOOL (WINAPI *pWinHttpCloseHandle)(HINTERNET);
23 
24 static
25 PVOID
28 {
29  HMODULE ModuleHandle;
30 
31  ModuleHandle = GetModuleHandleW(L"ws2_32");
32  if (!ModuleHandle)
33  return NULL;
34  return GetProcAddress(ModuleHandle, FunctionName);
35 }
36 
37 #define PROC(name) (p##name = GetProc(#name))
38 
39 static
40 BOOLEAN
42 {
43  return GetModuleHandleW(L"ws2_32") != NULL;
44 }
45 
46 static
47 BOOLEAN
49 {
50  return GetModuleHandleW(L"wininet") != NULL;
51 }
52 
53 static
54 BOOLEAN
56 {
57  struct hostent *Hostent;
58 
60  return FALSE;
61 
62  Hostent = pgethostbyname("localhost");
63  if (!Hostent)
65  return Hostent != NULL;
66 }
67 
68 static
69 BOOLEAN
71 {
72  int Error;
73 
75  return FALSE;
76 
78  ok(Error == SOCKET_ERROR, "Error = %d\n", Error);
80  pWSAGetLastError() == WSAEINVAL, "WSAGetLastError = %d\n", pWSAGetLastError());
81 
82  return pWSAGetLastError() != WSAEOPNOTSUPP;
83 }
84 
86 {
87  HMODULE ModuleHandle;
88  HINTERNET InternetHandle;
89  BOOL Success;
90 
91  ok(!IsWinsockLoaded(), "Winsock loaded on startup\n");
92  ok(!IsWinsockInitialized(), "Winsock initialized on startup\n");
93  ok(!IsWininetLoaded(), "Wininet loaded on startup\n");
94 
95  ModuleHandle = GetModuleHandleW(L"winhttp");
96  ok_ptr(ModuleHandle, NULL);
97  ModuleHandle = LoadLibraryW(L"winhttp");
98  ok(ModuleHandle != NULL, "LoadLibrary failed, error %lu\n", GetLastError());
99 
100  pWinHttpOpen = (PVOID)GetProcAddress(ModuleHandle, "WinHttpOpen");
101  pWinHttpCloseHandle = (PVOID)GetProcAddress(ModuleHandle, "WinHttpCloseHandle");
102 
103  ok(!IsWinsockLoaded(), "Winsock loaded after winhttp load\n");
104  ok(!IsWinsockInitialized(), "Winsock initialized after winhttp load\n");
105  ok(!IsWininetLoaded(), "Wininet loaded after winhttp load\n");
106 
107  InternetHandle = pWinHttpOpen(NULL, WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0);
108  ok(InternetHandle != NULL, "InternetHandle = NULL\n");
109 
110  if (InternetHandle != NULL)
111  {
112  ok(IsWinsockLoaded(), "Winsock not loaded after WinHttpOpen\n");
113  ok(IsWinsockInitialized(), "Winsock not initialized after WinHttpOpen\n");
114  ok(!IsWininetLoaded(), "Wininet loaded after WinHttpOpen\n");
115  ok(AreLegacyFunctionsSupported(), "Winsock initialized with version 2\n");
116  Success = pWinHttpCloseHandle(InternetHandle);
117  ok(Success, "WinHttpCloseHandle failed, error %lu\n", GetLastError());
118  }
119 
120  ok(IsWinsockLoaded(), "Winsock unloaded after handle close\n");
121  ok(IsWinsockInitialized(), "Winsock uninitialized after handle close\n");
122 
123  FreeLibrary(ModuleHandle);
124 
125  ok(IsWinsockLoaded(), "Winsock unloaded after winhttp unload\n");
126  trace("Winsock %sinitialized after winhttp unload (should be uninitialized in 2003, still initialized in 7)\n",
127  IsWinsockInitialized() ? "" : "un");
128 }
#define SOCKET_ERROR
Definition: winsock.h:333
LPFN_WSACANCELBLOCKINGCALL pWSACancelBlockingCall
Definition: handle.c:30
static PVOID GetProc(PCSTR FunctionName)
Definition: WinHttpOpen.c:26
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define WINHTTP_ACCESS_TYPE_NO_PROXY
Definition: winhttp.h:63
LPCWSTR
Definition: WinHttpOpen.c:21
#define WSAEINVAL
Definition: winerror.h:1946
static BOOLEAN IsWinsockInitialized(VOID)
Definition: WinHttpOpen.c:55
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ok_ptr(expression, result)
Definition: atltest.h:108
#define WSAEOPNOTSUPP
Definition: winerror.h:1958
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned char BOOLEAN
#define LoadLibraryW(x)
Definition: compat.h:404
smooth NULL
Definition: ftsmooth.c:416
void * PVOID
Definition: retypes.h:9
static BOOLEAN IsWinsockLoaded(VOID)
Definition: WinHttpOpen.c:41
#define WSANOTINITIALISED
Definition: winerror.h:1987
PHOSTENT WSAAPI gethostbyname(IN const char FAR *name)
Definition: getxbyxx.c:221
#define FreeLibrary(x)
Definition: compat.h:405
INT WSAAPI WSAGetLastError(VOID)
Definition: dllmain.c:112
#define trace
Definition: atltest.h:70
INT WSAAPI WSACancelBlockingCall(VOID)
Definition: bhook.c:23
#define WINAPI
Definition: msvc.h:8
BOOL Error
Definition: chkdsk.c:66
struct hostent *WINAPI * pgethostbyname(const char *)
static const WCHAR L[]
Definition: oid.c:1250
HINTERNET(WINAPI *pWinHttpOpen)(LPCWSTR
#define ok(value,...)
Definition: atltest.h:57
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char * FunctionName
Definition: acpixf.h:1264
HINTERNET WINAPI WinHttpOpen(LPCWSTR agent, DWORD access, LPCWSTR proxy, LPCWSTR bypass, DWORD flags)
Definition: session.c:246
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:847
static BOOLEAN AreLegacyFunctionsSupported(VOID)
Definition: WinHttpOpen.c:70
#define GetProcAddress(x, y)
Definition: compat.h:410
static BOOLEAN IsWininetLoaded(VOID)
Definition: WinHttpOpen.c:48
START_TEST(WinHttpOpen)
Definition: WinHttpOpen.c:85
const char * PCSTR
Definition: typedefs.h:51
BOOL(WINAPI *pWinHttpCloseHandle)(HINTERNET)
#define PROC(name)
Definition: WinHttpOpen.c:37
#define ok_dec(expression, result)
Definition: atltest.h:101
LPFN_WSAGETLASTERROR pWSAGetLastError
Definition: handle.c:29
int(WINAPI *pWSACancelBlockingCall)(void)
DWORD
Definition: WinHttpOpen.c:21