ReactOS  0.4.15-dev-1618-g9c8ed68
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  HMODULE mod;
20 
21  hEvent = CreateEventA(NULL, TRUE, FALSE, "Local\\shlwapi_apitest_evt");
22 
23  // Show that it is not signaled
24  dwRet = WaitForSingleObject(hEvent, 1);
25  ok_hex(dwRet, WAIT_TIMEOUT);
26 
27  // Ensure the module is not loaded yet...
28  mod = GetModuleHandleW(DllFile);
29  if (mod != NULL)
30  {
32  skip("%S loaded, cannot continue\n", DllFile);
33  return;
34  }
35 
36  wsprintfW(DllBuffer, L"@%s,-3", DllFile);
37 
38  // Load a string from the dll
40  ok_hex(hr, S_OK);
41  if (SUCCEEDED(hr))
42  {
43  // Module should still not be loaded
44  mod = GetModuleHandleW(DllFile);
45  ok_ptr(mod, 0);
46 
47  ok_wstr(Buffer, L"Test string one.");
48 
49  // DllMain not called..
50  dwRet = WaitForSingleObject(hEvent, 1);
51  ok_hex(dwRet, WAIT_TIMEOUT);
52 
53  // Show that calling DllMain will set the event
54  mod = LoadLibraryW(DllFile);
55  ok(mod != NULL, "Failed to load %S\n", DllFile);
56 
57  if (mod)
58  {
59  dwRet = WaitForSingleObject(hEvent, 1);
60  ok_hex(dwRet, WAIT_OBJECT_0);
62  }
63  }
65 }
66 
67 
69 {
70  BOOL Success;
71  DWORD dwWritten, Size;
72  HGLOBAL hGlobal;
73  LPVOID pData;
74  HANDLE Handle;
75  HRSRC hRsrc = FindResourceW(GetModuleHandleW(NULL), ResourceName, (LPCWSTR)10);
76  ok(!!hRsrc, "Unable to find %s\n", wine_dbgstr_w(ResourceName));
77  if (!hRsrc)
78  return FALSE;
79 
80  hGlobal = LoadResource(GetModuleHandleW(NULL), hRsrc);
82  pData = LockResource(hGlobal);
83 
84  ok(Size && !!pData, "Unable to load %s\n", wine_dbgstr_w(ResourceName));
85  if (!Size || !pData)
86  return FALSE;
87 
89 
91  {
92  skip("Failed to create temp file %ls, error %lu\n", Filename, GetLastError());
93  return FALSE;
94  }
95  Success = WriteFile(Handle, pData, Size, &dwWritten, NULL);
96  ok(Success == TRUE, "WriteFile failed with %lu\n", GetLastError());
97  ok(dwWritten == Size, "WriteFile wrote %lu bytes instead of %lu\n", dwWritten, Size);
99  Success = Success && (dwWritten == Size);
100 
102  return Success;
103 }
104 
106 {
108  BOOL ret;
109  UINT Length;
110 
112  ok(ret, "GetTempPathW error: %lu\n", GetLastError());
113 
114  Length = GetTempFileNameW(workdir, L"ntdll", 0, dllpath);
115  ok(Length != 0, "GetTempFileNameW failed with %lu\n", GetLastError());
116 
117  if (extract_resource(dllpath, (LPCWSTR)101))
118  {
119  _SEH2_TRY
120  {
122  }
124  {
125  ok(0, "Ldr didnt handle exception\n");
126  }
127  _SEH2_END;
128  }
129  else
130  {
131  ok(0, "Failed to extract resource\n");
132  }
133 
135 }
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
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
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
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
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
if SUCCEEDED(hr)
#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
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)
#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
#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
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
#define NULL
Definition: types.h:112
DWORD WINAPI SizeofResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:568
#define CreateFileW
Definition: compat.h:600
#define skip(...)
Definition: atltest.h:64
_In_ HANDLE Handle
Definition: extypes.h:390
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
static int mod
Definition: i386-dis.c:1281
static void execute_test(LPCWSTR DllFile)