ReactOS  0.4.13-dev-651-g5dbc677
ignorefreelib.c File Reference
#include <ntstatus.h>
#include <windows.h>
#include "wine/test.h"
#include "appshim_apitest.h"
Include dependency graph for ignorefreelib.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 

Typedefs

typedef BOOL(WINAPIFREELIBRARYPROC) (HMODULE)
 

Functions

static void test_IgnoreFreeLibrary (VOID)
 
 START_TEST (ignorefreelib)
 

Variables

static tGETHOOKAPIS pGetHookAPIs
 

Macro Definition Documentation

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 9 of file ignorefreelib.c.

Typedef Documentation

◆ FREELIBRARYPROC

typedef BOOL(WINAPI* FREELIBRARYPROC) (HMODULE)

Definition at line 17 of file ignorefreelib.c.

Function Documentation

◆ START_TEST()

START_TEST ( ignorefreelib  )

Definition at line 77 of file ignorefreelib.c.

78 {
79  HMODULE avifil32, esent, msi;
80  LONG initial;
81 
82  pGetHookAPIs = LoadShimDLL2(L"acgenral.dll");
83 
84  if (!pGetHookAPIs)
85  return;
86 
87  /* Ensure that we can freely load / unload avifil32, esent and msi */
88 
89  initial = winetest_get_failures();
90 
91  avifil32 = GetModuleHandleA("avifil32.dll");
92  ok_ptr(avifil32, NULL);
93  esent = GetModuleHandleA("esent.dll");
94  ok_ptr(esent, NULL);
95  msi = GetModuleHandleA("msi.dll");
96  ok_ptr(msi, NULL);
97 
98  avifil32 = LoadLibraryA("avifil32.dll");
99  ok(avifil32 != NULL, "Unable to load avifil32\n");
100  esent = GetModuleHandleA("esent.dll");
101  ok_ptr(esent, NULL);
102  msi = GetModuleHandleA("msi.dll");
103  ok_ptr(msi, NULL);
104 
105  ok(FreeLibrary(avifil32), "Unable to unload avifil32\n");
106  avifil32 = GetModuleHandleA("avifil32.dll");
107  ok_ptr(avifil32, NULL);
108 
109  esent = LoadLibraryA("esent.dll");
110  ok(esent != NULL, "Unable to load esent\n");
111  avifil32 = GetModuleHandleA("avifil32.dll");
112  ok_ptr(avifil32, NULL);
113  msi = GetModuleHandleA("msi.dll");
114  ok_ptr(msi, NULL);
115 
116  ok(FreeLibrary(esent), "Unable to unload esent\n");
117  esent = GetModuleHandleA("esent.dll");
118  ok_ptr(esent, NULL);
119 
120  msi = LoadLibraryA("msi.dll");
121  ok(msi != NULL, "Unable to load msi\n");
122  avifil32 = GetModuleHandleA("avifil32.dll");
123  ok_ptr(avifil32, NULL);
124  esent = GetModuleHandleA("esent.dll");
125  ok_ptr(esent, NULL);
126 
127  ok(FreeLibrary(msi), "Unable to unload msi\n");
128  msi = GetModuleHandleA("msi.dll");
129  ok_ptr(msi, NULL);
130 
131  if (initial != winetest_get_failures())
132  {
133  // We cannot continue, one or more of our target dll's does not behave as expected
134  return;
135  }
136 
138 }
LONG winetest_get_failures(void)
static tGETHOOKAPIS pGetHookAPIs
Definition: ignorefreelib.c:15
long LONG
Definition: pedump.c:60
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
#define ok(value,...)
static void test_IgnoreFreeLibrary(VOID)
Definition: ignorefreelib.c:20
smooth NULL
Definition: ftsmooth.c:416
tGETHOOKAPIS LoadShimDLL2(PCWSTR ShimDll)
Definition: versionlie.c:365
#define ok_ptr(expression, result)
Definition: test.h:773
static const WCHAR L[]
Definition: oid.c:1250
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:819
BOOL WINAPI SHIM_OBJ_NAME() FreeLibrary(HMODULE hModule)
Definition: ignorefreelib.c:23

◆ test_IgnoreFreeLibrary()

static void test_IgnoreFreeLibrary ( VOID  )
static

Definition at line 20 of file ignorefreelib.c.

21 {
22  DWORD num_shims = 0;
23  PHOOKAPI hook;
24  HMODULE avifil32, esent, msi;
25  FREELIBRARYPROC freeProc;
26 
27  // Show that:
28  // * partial names (both start + end) do not work.
29  // * wildcards do not work
30  // * comparison is case insensitive
31  // * multiple dlls can be specified
32  hook = pGetHookAPIs("AvIFiL32.Dll;esent;esent*;ent.dll;msi.dll", L"IgnoreFreeLibrary", &num_shims);
33 
34  ok(hook != NULL, "Expected hook to be a valid pointer\n");
35  ok(num_shims == 1, "Expected num_shims to be 1, was: %u\n", num_shims);
36 
37  if (!hook || !num_shims)
38  return;
39 
40  ok_str(hook->LibraryName, "KERNEL32.DLL");
41  ok_str(hook->FunctionName, "FreeLibrary");
42 
43  avifil32 = LoadLibraryA("avifil32.dll");
44  ok(avifil32 != NULL, "Unable to load avifil32\n");
45 
46  esent = LoadLibraryA("esent.dll");
47  ok(esent != NULL, "Unable to load esent\n");
48 
49  msi = LoadLibraryA("msi.dll");
50  ok(msi != NULL, "Unable to load msi\n");
51 
52  hook->OriginalFunction = FreeLibrary;
53  freeProc = hook->ReplacementFunction;
54 
55  ok(freeProc != NULL, "\n");
56 
57  if (!freeProc)
58  return;
59 
60  // Not unloading
61  ok(freeProc(avifil32), "Unable to unload avifil32\n");
62  avifil32 = GetModuleHandleA("avifil32.dll");
63  ok(avifil32 != NULL, "avifil32 should not unload\n");
64 
65  // Unloading
66  ok(freeProc(esent), "Unable to unload esent\n");
67  esent = GetModuleHandleA("esent.dll");
68  ok(esent == NULL, "esent should be unloaded\n");
69 
70  // Not unloading
71  ok(freeProc(msi), "Unable to unload msi\n");
72  msi = GetModuleHandleA("msi.dll");
73  ok(msi != NULL, "msi should not unload\n");
74 }
#define ok_str(x, y)
Definition: sprintf.c:18
BOOL(WINAPI * FREELIBRARYPROC)(HMODULE)
Definition: ignorefreelib.c:18
static tGETHOOKAPIS pGetHookAPIs
Definition: ignorefreelib.c:15
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
Definition: msg.h:42
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:819
BOOL WINAPI SHIM_OBJ_NAME() FreeLibrary(HMODULE hModule)
Definition: ignorefreelib.c:23

Referenced by START_TEST().

Variable Documentation

◆ pGetHookAPIs

tGETHOOKAPIS pGetHookAPIs
static

Definition at line 15 of file ignorefreelib.c.

Referenced by START_TEST(), and test_IgnoreFreeLibrary().