ReactOS 0.4.17-dev-966-gf06eace
sxs.c
Go to the documentation of this file.
1/*
2 * Copyright 2018 Fabian Maurer
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19#include <stdio.h>
20
21#define COBJMACROS
22
23#include <windows.h>
24#include <winsxs.h>
25#include <corerror.h>
26#include "shlwapi.h"
27
28#include "wine/test.h"
29
30#include "initguid.h"
31#include "interfaces.h"
32
33#define SXS_LOOKUP_CLR_GUID_USE_ACTCTX 0x00000001
34#define SXS_LOOKUP_CLR_GUID_FIND_SURROGATE 0x00010000
35#define SXS_LOOKUP_CLR_GUID_FIND_CLR_CLASS 0x00020000
36#define SXS_LOOKUP_CLR_GUID_FIND_ANY (SXS_LOOKUP_CLR_GUID_FIND_SURROGATE | SXS_LOOKUP_CLR_GUID_FIND_CLR_CLASS)
37
38#define SXS_GUID_INFORMATION_CLR_FLAG_IS_SURROGATE 0x00000001
39#define SXS_GUID_INFORMATION_CLR_FLAG_IS_CLASS 0x00000002
40
41typedef struct _SXS_GUID_INFORMATION_CLR
42{
49
50/* Defined in sxs.dll, but not found in any header */
51BOOL WINAPI SxsLookupClrGuid(DWORD flags, GUID *clsid, HANDLE actctx, void *buffer, SIZE_T buffer_len, SIZE_T *buffer_len_required);
52
53static BOOL write_resource_file(const char *path_tmp, const char *name_res, const char *name_file, char *path_file)
54{
55 HRSRC rsrc;
56 void *rsrc_data;
57 DWORD rsrc_size;
58 BOOL ret;
59 HANDLE hfile;
60
61 path_file[0] = 0;
63 if (!rsrc) return FALSE;
64
66 if (!rsrc_data) return FALSE;
67
68 rsrc_size = SizeofResource(GetModuleHandleA(NULL), rsrc);
69 if (!rsrc_size) return FALSE;
70
71 strcpy(path_file, path_tmp);
72 PathAppendA(path_file, name_file);
74 if (hfile == INVALID_HANDLE_VALUE) return FALSE;
75
76 ret = WriteFile(hfile, rsrc_data, rsrc_size, &rsrc_size, NULL);
77
78 CloseHandle(hfile);
79 return ret;
80}
81
82static void run_test(void)
83{
85 BOOL ret;
87
88 SetLastError(0xdeadbeef);
90 NULL, NULL, 0, &buffer_size);
91 ok(!ret, "Unexpected return value %d.\n", ret);
92 ok(GetLastError() == ERROR_NOT_FOUND, "Unexpected error %ld.\n", GetLastError());
93
94 SetLastError(0xdeadbeef);
96 NULL, NULL, 0, &buffer_size);
97 ok(!ret, "Unexpected return value %d.\n", ret);
98 ok(GetLastError() == ERROR_NOT_FOUND, "Unexpected error %ld.\n", GetLastError());
99
100 SetLastError(0xdeadbeef);
102 ok(!ret, "Unexpected return value %d.\n", ret);
104
105 SetLastError(0xdeadbeef);
107 ok(ret == FALSE, "Got %d\n", ret);
109
111 SetLastError(0xdeadbeef);
113 ok(ret == TRUE, "Got %d\n", ret);
114 ok(GetLastError() == 0, "Got %ld\n", GetLastError());
115
116 ok(info->dwFlags == SXS_GUID_INFORMATION_CLR_FLAG_IS_CLASS, "Got %ld\n", info->dwFlags);
117 ok(!lstrcmpW(info->pcwszTypeName, L"DLL.Test"), "Unexpected typename %s.\n", wine_dbgstr_w(info->pcwszTypeName));
118 ok(!lstrcmpW(info->pcwszAssemblyIdentity, L"comtest,type=\"win32\",version=\"1.0.0.0\""),
119 "Unexpected assembly identity %s.\n", wine_dbgstr_w(info->pcwszAssemblyIdentity));
120 ok(!lstrcmpW(info->pcwszRuntimeVersion, L"v4.0.0.0"), "Unexpected runtime version %s.\n",
121 wine_dbgstr_w(info->pcwszRuntimeVersion));
122
123 free(info);
124
125 SetLastError(0xdeadbeef);
127 ok(!ret, "Unexpected return value %d.\n", ret);
129
131 SetLastError(0xdeadbeef);
134 ok(ret, "Unexpected return value %d.\n", ret);
135 ok(GetLastError() == 0, "Got %ld\n", GetLastError());
136
137 ok(info->dwFlags == SXS_GUID_INFORMATION_CLR_FLAG_IS_SURROGATE, "Unexpected flags %#lx.\n", info->dwFlags);
138 ok(!lstrcmpW(info->pcwszTypeName, L"Surrogate.Test"), "Unexpected typename %s.\n", wine_dbgstr_w(info->pcwszTypeName));
139 ok(!lstrcmpW(info->pcwszAssemblyIdentity, L"comtest,type=\"win32\",version=\"1.0.0.0\""),
140 "Unexpected assembly identity %s.\n", wine_dbgstr_w(info->pcwszAssemblyIdentity));
141 ok(!lstrcmpW(info->pcwszRuntimeVersion, L"v4.0.0.1"), "Unexpected runtime version %s.\n",
142 wine_dbgstr_w(info->pcwszRuntimeVersion));
143
144 free(info);
145
146 SetLastError(0xdeadbeef);
147 ret = SxsLookupClrGuid(SXS_LOOKUP_CLR_GUID_FIND_ANY, (GUID *)&CLSID_SurrogateTest, NULL, NULL, 0, &buffer_size);
148 ok(!ret, "Unexpected return value %d.\n", ret);
150}
151
152static void prepare_and_run_test(void)
153{
154 char path_tmp[MAX_PATH];
155 char path_manifest_dll[MAX_PATH];
156 char path_manifest_exe[MAX_PATH];
158 ACTCTXA context = {0};
160 HANDLE handle_context = INVALID_HANDLE_VALUE;
161
162 GetTempPathA(MAX_PATH, path_tmp);
163
164 if (!write_resource_file(path_tmp, "comtest_exe.manifest", "exe.manifest", path_manifest_exe))
165 {
166 ok(0, "Failed to create file for testing\n");
167 goto cleanup;
168 }
169
170 if (!write_resource_file(path_tmp, "comtest_dll.manifest", "comtest.manifest", path_manifest_dll))
171 {
172 ok(0, "Failed to create file for testing\n");
173 goto cleanup;
174 }
175
176 context.cbSize = sizeof(ACTCTXA);
177 context.lpSource = path_manifest_exe;
178 context.lpAssemblyDirectory = path_tmp;
179 context.dwFlags = ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID;
180
181 handle_context = CreateActCtxA(&context);
182 ok(handle_context != INVALID_HANDLE_VALUE, "CreateActCtxA failed: %ld\n", GetLastError());
183
184 if (handle_context == INVALID_HANDLE_VALUE)
185 {
186 ok(0, "Failed to create activation context\n");
187 goto cleanup;
188 }
189
190 success = ActivateActCtx(handle_context, &cookie);
191 ok(success, "ActivateActCtx failed: %ld\n", GetLastError());
192
193 run_test();
194
195cleanup:
196 if (handle_context != INVALID_HANDLE_VALUE)
197 {
199 ok(success, "DeactivateActCtx failed: %ld\n", GetLastError());
200 ReleaseActCtx(handle_context);
201 }
202 if (*path_manifest_exe)
203 {
204 success = DeleteFileA(path_manifest_exe);
205 ok(success, "DeleteFileA failed: %ld\n", GetLastError());
206 }
207 if(*path_manifest_dll)
208 {
209 success = DeleteFileA(path_manifest_dll);
210 ok(success, "DeleteFileA failed: %ld\n", GetLastError());
211 }
212}
213
214static void run_child_process(void)
215{
216 char cmdline[MAX_PATH];
217 char exe[MAX_PATH];
218 char **argv;
220 STARTUPINFOA si = { 0 };
221 BOOL ret;
222
224
225 if (strstr(argv[0], ".exe"))
226 sprintf(exe, "%s", argv[0]);
227 else
228 sprintf(exe, "%s.exe", argv[0]);
229 sprintf(cmdline, "\"%s\" %s %s", argv[0], argv[1], "subtest");
230
231 si.cb = sizeof(si);
232 ret = CreateProcessA(exe, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
233 ok(ret, "Could not create process: %lu\n", GetLastError());
234
236
239}
240
241static void test_SxsLookupClrGuid(void)
242{
244 BOOL ret;
245
246 SetLastError(0xdeadbeef);
248 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
249 ok(GetLastError() == ERROR_NOT_FOUND, "Expected ERROR_NOT_FOUND, got %ld\n", GetLastError());
250
251 SetLastError(0xdeadbeef);
253 NULL, NULL, 0, &buffer_size);
254 ok(!ret, "Unexpected return value %d.\n", ret);
255 ok(GetLastError() == ERROR_NOT_FOUND, "Expected ERROR_NOT_FOUND, got %ld\n", GetLastError());
256
257 SetLastError(0xdeadbeef);
259 ok(!ret, "Unexpected return value %d.\n", ret);
260 ok(GetLastError() == ERROR_NOT_FOUND, "Expected ERROR_NOT_FOUND, got %ld\n", GetLastError());
261
263}
264
266{
267 char **argv;
269 if (argc > 2)
270 {
272 return;
273 }
274
276}
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#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 SetLastError(x)
Definition: compat.h:752
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:740
#define MAX_PATH
Definition: compat.h:34
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
static void cleanup(void)
Definition: main.c:1335
VOID WINAPI ReleaseActCtx(IN HANDLE hActCtx)
Definition: actctx.c:208
BOOL WINAPI DeactivateActCtx(IN DWORD dwFlags, IN ULONG_PTR ulCookie)
Definition: actctx.c:268
BOOL WINAPI ActivateActCtx(IN HANDLE hActCtx, OUT PULONG_PTR ulCookie)
Definition: actctx.c:237
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
BOOL WINAPI WriteFile(_In_ HANDLE hFile, _In_reads_bytes_opt_(nNumberOfBytesToWrite) LPCVOID lpBuffer, _In_ DWORD nNumberOfBytesToWrite, _Out_opt_ LPDWORD lpNumberOfBytesWritten, _Inout_opt_ LPOVERLAPPED lpOverlapped)
Definition: rw.c:25
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
DWORD WINAPI GetTempPathA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2072
HANDLE WINAPI CreateActCtxA(PCACTCTXA pActCtx)
Definition: actctx.c:26
HRSRC WINAPI FindResourceA(HMODULE hModule, LPCSTR name, LPCSTR type)
Definition: res.c:155
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
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4152
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessA(const char *app_name, char *cmd_line, SECURITY_ATTRIBUTES *process_attr, SECURITY_ATTRIBUTES *thread_attr, BOOL inherit, DWORD flags, void *env, const char *cur_dir, STARTUPINFOA *startup_info, PROCESS_INFORMATION *info)
Definition: process.c:686
MonoAssembly int argc
Definition: metahost.c:107
_ACRTIMP char *__cdecl strstr(const char *, const char *)
Definition: string.c:3420
#define SXS_LOOKUP_CLR_GUID_USE_ACTCTX
Definition: sxs.c:43
#define SXS_GUID_INFORMATION_CLR_FLAG_IS_CLASS
Definition: sxs.c:41
#define SXS_LOOKUP_CLR_GUID_FIND_CLR_CLASS
Definition: sxs.c:45
#define SXS_GUID_INFORMATION_CLR_FLAG_IS_SURROGATE
Definition: sxs.c:40
BOOL WINAPI SxsLookupClrGuid(DWORD flags, GUID *clsid, HANDLE actctx, void *buffer, SIZE_T buffer_len, SIZE_T *buffer_len_required)
Definition: sxs.c:94
struct _SXS_GUID_INFORMATION_CLR SXS_GUID_INFORMATION_CLR
#define SXS_LOOKUP_CLR_GUID_FIND_SURROGATE
Definition: sxs.c:44
return ret
Definition: mutex.c:147
#define L(x)
Definition: resources.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint buffer
Definition: glext.h:5915
GLbitfield flags
Definition: glext.h:7161
#define actctx
Definition: kernel32.h:8
#define wine_dbgstr_w
Definition: kernel32.h:34
#define CREATE_ALWAYS
Definition: disk.h:72
#define sprintf
Definition: sprintf.c:45
static const GUID CLSID_Test
Definition: atl.c:35
static PROCESS_INFORMATION pi
Definition: debugger.c:2303
static SYSTEM_INFO si
Definition: virtual.c:39
static void prepare_and_run_test(void)
Definition: sxs.c:152
static void run_test(void)
Definition: sxs.c:82
static void run_child_process(void)
Definition: sxs.c:214
static void test_SxsLookupClrGuid(void)
Definition: sxs.c:241
static BOOL write_resource_file(const char *path_tmp, const char *name_res, const char *name_file, char *path_file)
Definition: sxs.c:53
#define SXS_LOOKUP_CLR_GUID_FIND_ANY
Definition: sxs.c:36
#define argv
Definition: mplay32.c:18
const CLSID * clsid
Definition: msctf.cpp:50
#define GENERIC_WRITE
Definition: nt_native.h:90
#define PathAppendA
Definition: pathcch.h:309
#define RT_RCDATA
Definition: pedump.c:372
strcpy
Definition: string.h:131
int winetest_get_mainargs(char ***pargv)
#define wait_child_process
Definition: test.h:161
wchar_t const *const size_t const buffer_size
Definition: stat.cpp:95
TCHAR * cmdline
Definition: stretchblt.cpp:32
PCWSTR pcwszRuntimeVersion
Definition: sxs.c:35
PCWSTR pcwszTypeName
Definition: sxs.c:36
PCWSTR pcwszAssemblyIdentity
Definition: sxs.c:37
Definition: http.c:7252
Definition: cookie.c:34
const char * LPCSTR
Definition: typedefs.h:52
const uint16_t * PCWSTR
Definition: typedefs.h:57
ULONG_PTR SIZE_T
Definition: typedefs.h:80
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define success(from, fromstr, to, tostr)
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define WINAPI
Definition: msvc.h:6
#define ERROR_NOT_FOUND
Definition: winerror.h:1014