ReactOS  0.4.15-dev-1206-g731eddf
SHLoadIndirectString.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS api tests
3  * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE: Tests for SHLoadIndirectString
5  * COPYRIGHT: Copyright 2020 Mark Jansen (mark.jansen@reactos.org)
6  */
7 
8 #include <apitest.h>
9 #include <shlwapi.h>
10 #include "resource.h"
11 
12 static void execute_test(LPCWSTR DllFile)
13 {
14  WCHAR DllBuffer[MAX_PATH + 20];
15  WCHAR Buffer[MAX_PATH * 2] = {0};
16  HRESULT hr;
17  HANDLE hEvent;
18  DWORD dwRet;
19 
20  hEvent = CreateEventA(NULL, TRUE, FALSE, "Local\\shlwapi_apitest_evt");
21 
22  // Show that it is not signaled
23  dwRet = WaitForSingleObject(hEvent, 1);
24  ok_hex(dwRet, WAIT_TIMEOUT);
25 
26  // Ensure the module is not loaded yet...
27  HMODULE mod = GetModuleHandleW(DllFile);
28  if (mod != NULL)
29  {
31  skip("%S loaded, cannot continue\n", DllFile);
32  return;
33  }
34 
35  wsprintfW(DllBuffer, L"@%s,-3", DllFile);
36 
37  // Load a string from the dll
39  ok_hex(hr, S_OK);
40  if (SUCCEEDED(hr))
41  {
42  // Module should still not be loaded
43  mod = GetModuleHandleW(DllFile);
44  ok_ptr(mod, 0);
45 
46  ok_wstr(Buffer, L"Test string one.");
47 
48  // DllMain not called..
49  dwRet = WaitForSingleObject(hEvent, 1);
50  ok_hex(dwRet, WAIT_TIMEOUT);
51 
52  // Show that calling DllMain will set the event
53  mod = LoadLibraryW(DllFile);
54  ok(mod != NULL, "Failed to load %S\n", DllFile);
55 
56  if (mod)
57  {
58  dwRet = WaitForSingleObject(hEvent, 1);
59  ok_hex(dwRet, WAIT_OBJECT_0);
61  }
62  }
64 }
65 
66 
68 {
69  BOOL Success;
70  DWORD dwWritten, Size;
71  HGLOBAL hGlobal;
72  LPVOID pData;
73  HANDLE Handle;
74  HRSRC hRsrc = FindResourceW(GetModuleHandleW(NULL), ResourceName, (LPCWSTR)10);
75  ok(!!hRsrc, "Unable to find %s\n", wine_dbgstr_w(ResourceName));
76  if (!hRsrc)
77  return FALSE;
78 
79  hGlobal = LoadResource(GetModuleHandleW(NULL), hRsrc);
81  pData = LockResource(hGlobal);
82 
83  ok(Size && !!pData, "Unable to load %s\n", wine_dbgstr_w(ResourceName));
84  if (!Size || !pData)
85  return FALSE;
86 
88 
90  {
91  skip("Failed to create temp file %ls, error %lu\n", Filename, GetLastError());
92  return FALSE;
93  }
94  Success = WriteFile(Handle, pData, Size, &dwWritten, NULL);
95  ok(Success == TRUE, "WriteFile failed with %lu\n", GetLastError());
96  ok(dwWritten == Size, "WriteFile wrote %lu bytes instead of %lu\n", dwWritten, Size);
98  Success = Success && (dwWritten == Size);
99 
101  return Success;
102 }
103 
105 {
107  BOOL ret;
108  UINT Length;
109 
111  ok(ret, "GetTempPathW error: %lu\n", GetLastError());
112 
113  Length = GetTempFileNameW(workdir, L"ntdll", 0, dllpath);
114  ok(Length != 0, "GetTempFileNameW failed with %lu\n", GetLastError());
115 
116  if (extract_resource(dllpath, (LPCWSTR)101))
117  {
118  _SEH2_TRY
119  {
121  }
123  {
124  ok(0, "Ldr didnt handle exception\n");
125  }
126  _SEH2_END;
127  }
128  else
129  {
130  ok(0, "Failed to extract resource\n");
131  }
132 
134 }
int WINAPIV wsprintfW(_Out_ LPWSTR, _In_ _Printf_format_string_ LPCWSTR,...)
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define CloseHandle
Definition: compat.h:598
HRESULT hr
Definition: shlfolder.c:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define TRUE
Definition: types.h:120
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
#define ok_ptr(expression, result)
Definition: atltest.h:108
#define ok_hex(expression, result)
Definition: atltest.h:94
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
IN PVCB IN PBCB OUT PDIRENT IN USHORT IN POEM_STRING Filename
Definition: fatprocs.h:934
_SEH2_TRY
Definition: create.c:4226
static HANDLE hEvent
Definition: comm.c:54
#define UnlockResource(h)
Definition: winbase.h:3212
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
DWORD WINAPI GetTempPathW(IN DWORD count, OUT LPWSTR path)
Definition: path.c:2079
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
#define LoadLibraryW(x)
Definition: compat.h:606
smooth NULL
Definition: ftsmooth.c:416
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventA(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCSTR lpName OPTIONAL)
Definition: synch.c:637
Definition: bufpool.h:45
BOOL extract_resource(const WCHAR *Filename, LPCWSTR ResourceName)
_In_ HANDLE Handle
Definition: extypes.h:390
#define FreeLibrary(x)
Definition: compat.h:607
#define WAIT_OBJECT_0
Definition: winbase.h:387
WCHAR dllpath[MAX_PATH]
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:79
#define _countof(array)
Definition: sndvol32.h:68
static char workdir[MAX_PATH]
Definition: batch.c:26
#define MAX_PATH
Definition: compat.h:34
UINT WINAPI GetTempFileNameW(IN LPCWSTR lpPathName, IN LPCWSTR lpPrefixString, IN UINT uUnique, OUT LPWSTR lpTempFileName)
Definition: filename.c:84
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define WAIT_TIMEOUT
Definition: dderror.h:14
int ret
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
static const WCHAR L[]
Definition: oid.c:1250
#define ok_wstr(x, y)
Definition: atltest.h:130
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
START_TEST(SHLoadIndirectString)
HRESULT WINAPI SHLoadIndirectString(LPCWSTR src, LPWSTR dst, UINT dst_len, void **reserved)
Definition: string.c:2876
#define S_OK
Definition: intsafe.h:51
#define CREATE_ALWAYS
Definition: disk.h:72
_SEH2_END
Definition: create.c:4400
#define ok(value,...)
Definition: atltest.h:57
unsigned int UINT
Definition: ndis.h:50
DWORD WINAPI SizeofResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:568
#define CreateFileW
Definition: compat.h:600
#define skip(...)
Definition: atltest.h:64
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827
#define SUCCEEDED(hr)
Definition: intsafe.h:49
static int mod
Definition: i386-dis.c:1273
static void execute_test(LPCWSTR DllFile)