ReactOS 0.4.15-dev-8222-g9164419
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#include <pseh/pseh2.h>
13
14static void execute_test(LPCWSTR DllFile)
15{
16 WCHAR DllBuffer[MAX_PATH + 20];
17 WCHAR Buffer[MAX_PATH * 2] = {0};
18 HRESULT hr;
20 DWORD dwRet;
22
23 hEvent = CreateEventA(NULL, TRUE, FALSE, "Local\\shlwapi_apitest_evt");
24
25 // Show that it is not signaled
26 dwRet = WaitForSingleObject(hEvent, 1);
27 ok_hex(dwRet, WAIT_TIMEOUT);
28
29 // Ensure the module is not loaded yet...
30 mod = GetModuleHandleW(DllFile);
31 if (mod != NULL)
32 {
34 skip("%S loaded, cannot continue\n", DllFile);
35 return;
36 }
37
38 wsprintfW(DllBuffer, L"@%s,-3", DllFile);
39
40 // Load a string from the dll
42 ok_hex(hr, S_OK);
43 if (SUCCEEDED(hr))
44 {
45 // Module should still not be loaded
46 mod = GetModuleHandleW(DllFile);
47 ok_ptr(mod, 0);
48
49 ok_wstr(Buffer, L"Test string one.");
50
51 // DllMain not called..
52 dwRet = WaitForSingleObject(hEvent, 1);
53 ok_hex(dwRet, WAIT_TIMEOUT);
54
55 // Show that calling DllMain will set the event
56 mod = LoadLibraryW(DllFile);
57 ok(mod != NULL, "Failed to load %S\n", DllFile);
58
59 if (mod)
60 {
61 dwRet = WaitForSingleObject(hEvent, 1);
62 ok_hex(dwRet, WAIT_OBJECT_0);
64 }
65 }
67}
68
69
71{
73 DWORD dwWritten, Size;
74 HGLOBAL hGlobal;
77 HRSRC hRsrc = FindResourceW(GetModuleHandleW(NULL), ResourceName, (LPCWSTR)10);
78 ok(!!hRsrc, "Unable to find %s\n", wine_dbgstr_w(ResourceName));
79 if (!hRsrc)
80 return FALSE;
81
82 hGlobal = LoadResource(GetModuleHandleW(NULL), hRsrc);
84 pData = LockResource(hGlobal);
85
86 ok(Size && !!pData, "Unable to load %s\n", wine_dbgstr_w(ResourceName));
87 if (!Size || !pData)
88 return FALSE;
89
91
93 {
94 skip("Failed to create temp file %ls, error %lu\n", Filename, GetLastError());
95 return FALSE;
96 }
97 Success = WriteFile(Handle, pData, Size, &dwWritten, NULL);
98 ok(Success == TRUE, "WriteFile failed with %lu\n", GetLastError());
99 ok(dwWritten == Size, "WriteFile wrote %lu bytes instead of %lu\n", dwWritten, Size);
101 Success = Success && (dwWritten == Size);
102
104 return Success;
105}
106
108{
110 BOOL ret;
111 UINT Length;
112
114 ok(ret, "GetTempPathW error: %lu\n", GetLastError());
115
116 Length = GetTempFileNameW(workdir, L"ntdll", 0, dllpath);
117 ok(Length != 0, "GetTempFileNameW failed with %lu\n", GetLastError());
118
120 {
122 {
124 }
126 {
127 ok(0, "Ldr didnt handle exception\n");
128 }
129 _SEH2_END;
130 }
131 else
132 {
133 ok(0, "Failed to extract resource\n");
134 }
135
137}
BOOL extract_resource(const WCHAR *Filename, LPCWSTR ResourceName)
#define ok_hex(expression, result)
Definition: atltest.h:94
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define ok_wstr(x, y)
Definition: atltest.h:130
#define START_TEST(x)
Definition: atltest.h:75
#define ok_ptr(expression, result)
Definition: atltest.h:108
Definition: bufpool.h:45
#define WAIT_TIMEOUT
Definition: dderror.h:14
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define FreeLibrary(x)
Definition: compat.h:748
#define MAX_PATH
Definition: compat.h:34
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define LoadLibraryW(x)
Definition: compat.h:747
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
DWORD WINAPI GetTempPathW(IN DWORD count, OUT LPWSTR path)
Definition: path.c:2080
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
DWORD WINAPI SizeofResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:568
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
HRESULT WINAPI SHLoadIndirectString(LPCWSTR src, LPWSTR dst, UINT dst_len, void **reserved)
Definition: string.c:2884
@ Success
Definition: eventcreate.c:712
IN PVCB IN PBCB OUT PDIRENT IN USHORT IN POEM_STRING Filename
Definition: fatprocs.h:939
UINT WINAPI GetTempFileNameW(IN LPCWSTR lpPathName, IN LPCWSTR lpPrefixString, IN UINT uUnique, OUT LPWSTR lpTempFileName)
Definition: filename.c:84
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
ULONG Handle
Definition: gdb_input.c:15
static int mod
Definition: i386-dis.c:1288
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define wine_dbgstr_w
Definition: kernel32.h:34
static void execute_test(void)
WCHAR dllpath[MAX_PATH]
#define CREATE_ALWAYS
Definition: disk.h:72
static char workdir[MAX_PATH]
Definition: batch.c:26
static HANDLE hEvent
Definition: comm.c:54
unsigned int UINT
Definition: ndis.h:50
#define GENERIC_WRITE
Definition: nt_native.h:90
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define L(x)
Definition: ntvdm.h:50
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
HRESULT hr
Definition: shlfolder.c:183
#define _countof(array)
Definition: sndvol32.h:70
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventA(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCSTR lpName OPTIONAL)
Definition: synch.c:637
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1830
int ret
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define WAIT_OBJECT_0
Definition: winbase.h:406
#define UnlockResource(handle)
Definition: winbase.h:3372
int WINAPIV wsprintfW(_Out_ LPWSTR, _In_ _Printf_format_string_ LPCWSTR,...)
__wchar_t WCHAR
Definition: xmlstorage.h:180
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185