[KERNEL32_WINETEST] Sync with Wine Staging 1.7.55. CORE-10536
[reactos.git] / rostests / winetests / kernel32 / actctx.c
1 /*
2 * Copyright 2007 Jacek Caban for CodeWeavers
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 <ntstatus.h>
20 #define WIN32_NO_STATUS
21 #include <wine/test.h>
22 #include <winbase.h>
23 #include <windef.h>
24 #include <winnt.h>
25 #include <wine/winternl.h>
26 #include <winnls.h>
27 #include <stdio.h>
28
29 #include <oaidl.h>
30 #include <initguid.h>
31
32 static BOOL (WINAPI *pActivateActCtx)(HANDLE,ULONG_PTR*);
33 static HANDLE (WINAPI *pCreateActCtxA)(PCACTCTXA);
34 static HANDLE (WINAPI *pCreateActCtxW)(PCACTCTXW);
35 static BOOL (WINAPI *pDeactivateActCtx)(DWORD,ULONG_PTR);
36 static BOOL (WINAPI *pFindActCtxSectionStringA)(DWORD,const GUID *,ULONG,LPCSTR,PACTCTX_SECTION_KEYED_DATA);
37 static BOOL (WINAPI *pFindActCtxSectionStringW)(DWORD,const GUID *,ULONG,LPCWSTR,PACTCTX_SECTION_KEYED_DATA);
38 static BOOL (WINAPI *pGetCurrentActCtx)(HANDLE *);
39 static BOOL (WINAPI *pIsDebuggerPresent)(void);
40 static BOOL (WINAPI *pQueryActCtxW)(DWORD,HANDLE,PVOID,ULONG,PVOID,SIZE_T,SIZE_T*);
41 static VOID (WINAPI *pReleaseActCtx)(HANDLE);
42 static BOOL (WINAPI *pFindActCtxSectionGuid)(DWORD,const GUID*,ULONG,const GUID*,PACTCTX_SECTION_KEYED_DATA);
43
44 static NTSTATUS(NTAPI *pRtlFindActivationContextSectionString)(DWORD,const GUID *,ULONG,PUNICODE_STRING,PACTCTX_SECTION_KEYED_DATA);
45 static BOOLEAN (NTAPI *pRtlCreateUnicodeStringFromAsciiz)(PUNICODE_STRING, PCSZ);
46 static VOID (NTAPI *pRtlFreeUnicodeString)(PUNICODE_STRING);
47
48 static const char* strw(LPCWSTR x)
49 {
50 static char buffer[1024];
51 char* p = buffer;
52
53 if (!x) return "(nil)";
54 else while ((*p++ = *x++));
55 return buffer;
56 }
57
58 #ifdef __i386__
59 #define ARCH "x86"
60 #elif defined __x86_64__
61 #define ARCH "amd64"
62 #elif defined __arm__
63 #define ARCH "arm"
64 #elif defined __aarch64__
65 #define ARCH "arm64"
66 #else
67 #define ARCH "none"
68 #endif
69
70 static const char manifest1[] =
71 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
72 "<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
73 "</assembly>";
74
75 static const char manifest1_1[] =
76 "<assembly xmlns = \"urn:schemas-microsoft-com:asm.v1\" manifestVersion = \"1.0\">"
77 "<assemblyIdentity version = \"1.0.0.0\" name = \"Wine.Test\" type = \"win32\"></assemblyIdentity>"
78 "</assembly>";
79
80 static const char manifest2[] =
81 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
82 "<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\">"
83 "</assemblyIdentity>"
84 "<dependency>"
85 "<dependentAssembly>"
86 "<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"" ARCH "\">"
87 "</assemblyIdentity>"
88 "</dependentAssembly>"
89 "</dependency>"
90 "</assembly>";
91
92 DEFINE_GUID(IID_CoTest, 0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x11, 0x11, 0x22, 0x22, 0x33, 0x33);
93 DEFINE_GUID(IID_CoTest2, 0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x11, 0x11, 0x22, 0x22, 0x33, 0x34);
94 DEFINE_GUID(CLSID_clrclass,0x22345678, 0x1234, 0x5678, 0x12, 0x34, 0x11, 0x11, 0x22, 0x22, 0x33, 0x33);
95 DEFINE_GUID(IID_TlibTest, 0x99999999, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55);
96 DEFINE_GUID(IID_TlibTest2, 0x99999999, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x56);
97 DEFINE_GUID(IID_TlibTest3, 0x99999999, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x57);
98 DEFINE_GUID(IID_TlibTest4, 0x99999999, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x58);
99 DEFINE_GUID(IID_Iifaceps, 0x66666666, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55);
100 DEFINE_GUID(IID_Ibifaceps, 0x66666666, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x57);
101 DEFINE_GUID(IID_Iifaceps2, 0x76666666, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55);
102 DEFINE_GUID(IID_Iifaceps3, 0x86666666, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55);
103 DEFINE_GUID(IID_Iiface, 0x96666666, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55);
104 DEFINE_GUID(IID_PS32, 0x66666666, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x56);
105
106 static const char manifest3[] =
107 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
108 "<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\""
109 " publicKeyToken=\"6595b6414666f1df\" />"
110 "<description />"
111 "<file name=\"testlib.dll\">"
112 "<windowClass>wndClass</windowClass>"
113 " <comClass description=\"Test com class\""
114 " clsid=\"{12345678-1234-5678-1234-111122223333}\""
115 " tlbid=\"{99999999-8888-7777-6666-555555555555}\""
116 " threadingModel=\"Neutral\""
117 " progid=\"ProgId.ProgId\""
118 " miscStatus=\"cantlinkinside\""
119 " miscStatusIcon=\"recomposeonresize\""
120 " miscStatusContent=\"insideout\""
121 " miscStatusThumbnail=\"alignable\""
122 " miscStatusDocPrint=\"simpleframe,setclientsitefirst\""
123 " >"
124 " <progid>ProgId.ProgId.1</progid>"
125 " <progid>ProgId.ProgId.2</progid>"
126 " <progid>ProgId.ProgId.3</progid>"
127 " <progid>ProgId.ProgId.4</progid>"
128 " <progid>ProgId.ProgId.5</progid>"
129 " <progid>ProgId.ProgId.6</progid>"
130 " </comClass>"
131 " <comClass clsid=\"{12345678-1234-5678-1234-111122223334}\" threadingModel=\"Neutral\" >"
132 " <progid>ProgId.ProgId.7</progid>"
133 " </comClass>"
134 " <comInterfaceProxyStub "
135 " name=\"Iifaceps\""
136 " tlbid=\"{99999999-8888-7777-6666-555555555558}\""
137 " iid=\"{66666666-8888-7777-6666-555555555555}\""
138 " proxyStubClsid32=\"{66666666-8888-7777-6666-555555555556}\""
139 " threadingModel=\"Free\""
140 " numMethods=\"10\""
141 " baseInterface=\"{66666666-8888-7777-6666-555555555557}\""
142 " />"
143 "</file>"
144 " <comInterfaceExternalProxyStub "
145 " name=\"Iifaceps2\""
146 " tlbid=\"{99999999-8888-7777-6666-555555555558}\""
147 " iid=\"{76666666-8888-7777-6666-555555555555}\""
148 " proxyStubClsid32=\"{66666666-8888-7777-6666-555555555556}\""
149 " numMethods=\"10\""
150 " baseInterface=\"{66666666-8888-7777-6666-555555555557}\""
151 " />"
152 " <comInterfaceExternalProxyStub "
153 " name=\"Iifaceps3\""
154 " tlbid=\"{99999999-8888-7777-6666-555555555558}\""
155 " iid=\"{86666666-8888-7777-6666-555555555555}\""
156 " numMethods=\"10\""
157 " baseInterface=\"{66666666-8888-7777-6666-555555555557}\""
158 " />"
159 " <clrSurrogate "
160 " clsid=\"{96666666-8888-7777-6666-555555555555}\""
161 " name=\"testsurrogate\""
162 " runtimeVersion=\"v2.0.50727\""
163 " />"
164 " <clrClass "
165 " clsid=\"{22345678-1234-5678-1234-111122223333}\""
166 " name=\"clrclass\""
167 " progid=\"clrprogid\""
168 " description=\"test description\""
169 " tlbid=\"{99999999-8888-7777-6666-555555555555}\""
170 " runtimeVersion=\"1.2.3.4\""
171 " threadingModel=\"Neutral\""
172 " >"
173 " <progid>clrprogid.1</progid>"
174 " <progid>clrprogid.2</progid>"
175 " <progid>clrprogid.3</progid>"
176 " <progid>clrprogid.4</progid>"
177 " <progid>clrprogid.5</progid>"
178 " <progid>clrprogid.6</progid>"
179 " </clrClass>"
180 "</assembly>";
181
182 static const char manifest_wndcls1[] =
183 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
184 "<assemblyIdentity version=\"1.2.3.4\" name=\"testdep1\" type=\"win32\" processorArchitecture=\"" ARCH "\"/>"
185 "<file name=\"testlib1.dll\">"
186 "<windowClass versioned=\"yes\">wndClass1</windowClass>"
187 "<windowClass>wndClass2</windowClass>"
188 " <typelib tlbid=\"{99999999-8888-7777-6666-555555555558}\" version=\"1.0\" helpdir=\"\" />"
189 "</file>"
190 "<file name=\"testlib1_2.dll\" />"
191 "</assembly>";
192
193 static const char manifest_wndcls2[] =
194 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
195 "<assemblyIdentity version=\"4.3.2.1\" name=\"testdep2\" type=\"win32\" processorArchitecture=\"" ARCH "\" />"
196 "<file name=\"testlib2.dll\">"
197 " <windowClass versioned=\"no\">wndClass3</windowClass>"
198 " <windowClass>wndClass4</windowClass>"
199 " <typelib tlbid=\"{99999999-8888-7777-6666-555555555555}\" version=\"1.0\" helpdir=\"help\" resourceid=\"409\""
200 " flags=\"HiddeN,CoNTROL,rESTRICTED\" />"
201 " <typelib tlbid=\"{99999999-8888-7777-6666-555555555556}\" version=\"1.0\" helpdir=\"help1\" resourceid=\"409\" />"
202 " <typelib tlbid=\"{99999999-8888-7777-6666-555555555557}\" version=\"1.0\" helpdir=\"\" />"
203 "</file>"
204 "<file name=\"testlib2_2.dll\" />"
205 "</assembly>";
206
207 static const char manifest_wndcls_main[] =
208 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
209 "<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\" />"
210 "<dependency>"
211 " <dependentAssembly>"
212 " <assemblyIdentity type=\"win32\" name=\"testdep1\" version=\"1.2.3.4\" processorArchitecture=\"" ARCH "\" />"
213 " </dependentAssembly>"
214 "</dependency>"
215 "<dependency>"
216 " <dependentAssembly>"
217 " <assemblyIdentity type=\"win32\" name=\"testdep2\" version=\"4.3.2.1\" processorArchitecture=\"" ARCH "\" />"
218 " </dependentAssembly>"
219 "</dependency>"
220 "</assembly>";
221
222 static const char manifest4[] =
223 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
224 "<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\">"
225 "</assemblyIdentity>"
226 "<dependency>"
227 "<dependentAssembly>"
228 "<assemblyIdentity type=\"win32\" name=\"Microsoft.Windows.Common-Controls\" "
229 "version=\"6.0.1.0\" processorArchitecture=\"" ARCH "\" publicKeyToken=\"6595b64144ccf1df\">"
230 "</assemblyIdentity>"
231 "</dependentAssembly>"
232 "</dependency>"
233 "</assembly>";
234
235 static const char manifest5[] =
236 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
237 "<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\">"
238 "</assemblyIdentity>"
239 "<dependency>"
240 " <dependentAssembly dependencyType=\"preRequisite\" allowDelayedBinding=\"true\">"
241 " <assemblyIdentity name=\"Missing.Assembly\" version=\"1.0.0.0\" />"
242 " </dependentAssembly>"
243 "</dependency>"
244 "</assembly>";
245
246 static const char testdep_manifest1[] =
247 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
248 "<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"" ARCH "\"/>"
249 "</assembly>";
250
251 static const char testdep_manifest2[] =
252 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
253 "<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"" ARCH "\" />"
254 "<file name=\"testlib.dll\"></file>"
255 "<file name=\"testlib2.dll\" hash=\"63c978c2b53d6cf72b42fb7308f9af12ab19ec53\" hashalg=\"SHA1\" />"
256 "</assembly>";
257
258 static const char testdep_manifest3[] =
259 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\"> "
260 "<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"" ARCH "\"/>"
261 "<file name=\"testlib.dll\"/>"
262 "<file name=\"testlib2.dll\" hash=\"63c978c2b53d6cf72b42fb7308f9af12ab19ec53\" hashalg=\"SHA1\">"
263 "<windowClass>wndClass</windowClass>"
264 "<windowClass>wndClass2</windowClass>"
265 "</file>"
266 "</assembly>";
267
268 static const char wrong_manifest1[] =
269 "<assembly manifestVersion=\"1.0\">"
270 "<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
271 "</assembly>";
272
273 static const char wrong_manifest2[] =
274 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\">"
275 "<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
276 "</assembly>";
277
278 static const char wrong_manifest3[] =
279 "<assembly test=\"test\" xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
280 "<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
281 "</assembly>";
282
283 static const char wrong_manifest4[] =
284 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
285 "<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
286 "<test></test>"
287 "</assembly>";
288
289 static const char wrong_manifest5[] =
290 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
291 "<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
292 "</assembly>"
293 "<test></test>";
294
295 static const char wrong_manifest6[] =
296 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v5\" manifestVersion=\"1.0\">"
297 "<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
298 "</assembly>";
299
300 static const char wrong_manifest7[] =
301 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
302 "<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"" ARCH "\" />"
303 "<file name=\"testlib.dll\" hash=\"63c978c2b53d6cf72b42fb7308f9af12ab19ec5\" hashalg=\"SHA1\" />"
304 "</assembly>";
305
306 static const char wrong_manifest8[] =
307 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
308 "<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
309 "<file></file>"
310 "</assembly>";
311
312 static const char wrong_depmanifest1[] =
313 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
314 "<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.4\" processorArchitecture=\"" ARCH "\" />"
315 "</assembly>";
316
317 static const WCHAR testlib_dll[] =
318 {'t','e','s','t','l','i','b','.','d','l','l',0};
319 static const WCHAR testlib2_dll[] =
320 {'t','e','s','t','l','i','b','2','.','d','l','l',0};
321 static const WCHAR wndClassW[] =
322 {'w','n','d','C','l','a','s','s',0};
323 static const WCHAR wndClass1W[] =
324 {'w','n','d','C','l','a','s','s','1',0};
325 static const WCHAR wndClass2W[] =
326 {'w','n','d','C','l','a','s','s','2',0};
327 static const WCHAR wndClass3W[] =
328 {'w','n','d','C','l','a','s','s','3',0};
329
330 static WCHAR app_dir[MAX_PATH], exe_path[MAX_PATH], work_dir[MAX_PATH], work_dir_subdir[MAX_PATH];
331 static WCHAR app_manifest_path[MAX_PATH], manifest_path[MAX_PATH], depmanifest_path[MAX_PATH];
332
333 static int strcmp_aw(LPCWSTR strw, const char *stra)
334 {
335 WCHAR buf[1024];
336
337 if (!stra) return 1;
338 MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(WCHAR));
339 return lstrcmpW(strw, buf);
340 }
341
342 static DWORD strlen_aw(const char *str)
343 {
344 return MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0) - 1;
345 }
346
347 static BOOL create_manifest_file(const char *filename, const char *manifest, int manifest_len,
348 const char *depfile, const char *depmanifest)
349 {
350 DWORD size;
351 HANDLE file;
352 WCHAR path[MAX_PATH];
353
354 MultiByteToWideChar( CP_ACP, 0, filename, -1, path, MAX_PATH );
355 GetFullPathNameW(path, sizeof(manifest_path)/sizeof(WCHAR), manifest_path, NULL);
356
357 if (manifest_len == -1)
358 manifest_len = strlen(manifest);
359
360 file = CreateFileW(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
361 FILE_ATTRIBUTE_NORMAL, NULL);
362 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %u\n", GetLastError());
363 if(file == INVALID_HANDLE_VALUE)
364 return FALSE;
365 WriteFile(file, manifest, manifest_len, &size, NULL);
366 CloseHandle(file);
367
368 if (depmanifest)
369 {
370 MultiByteToWideChar( CP_ACP, 0, depfile, -1, path, MAX_PATH );
371 GetFullPathNameW(path, sizeof(depmanifest_path)/sizeof(WCHAR), depmanifest_path, NULL);
372 file = CreateFileW(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
373 FILE_ATTRIBUTE_NORMAL, NULL);
374 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %u\n", GetLastError());
375 if(file == INVALID_HANDLE_VALUE)
376 return FALSE;
377 WriteFile(file, depmanifest, strlen(depmanifest), &size, NULL);
378 CloseHandle(file);
379 }
380 return TRUE;
381 }
382
383 static BOOL create_wide_manifest(const char *filename, const char *manifest, BOOL fBOM, BOOL fReverse)
384 {
385 WCHAR *wmanifest = HeapAlloc(GetProcessHeap(), 0, (strlen(manifest)+2) * sizeof(WCHAR));
386 BOOL ret;
387 int offset = (fBOM ? 0 : 1);
388
389 MultiByteToWideChar(CP_ACP, 0, manifest, -1, &wmanifest[1], (strlen(manifest)+1));
390 wmanifest[0] = 0xfeff;
391 if (fReverse)
392 {
393 size_t i;
394 for (i = 0; i < strlen(manifest)+1; i++)
395 wmanifest[i] = (wmanifest[i] << 8) | ((wmanifest[i] >> 8) & 0xff);
396 }
397 ret = create_manifest_file(filename, (char *)&wmanifest[offset], (strlen(manifest)+1-offset) * sizeof(WCHAR), NULL, NULL);
398 HeapFree(GetProcessHeap(), 0, wmanifest);
399 return ret;
400 }
401
402 typedef struct {
403 ULONG format_version;
404 ULONG assembly_cnt_min;
405 ULONG assembly_cnt_max;
406 ULONG root_manifest_type;
407 LPWSTR root_manifest_path;
408 ULONG root_config_type;
409 ULONG app_dir_type;
410 LPCWSTR app_dir;
411 } detailed_info_t;
412
413 static const detailed_info_t detailed_info0 = {
414 0, 0, 0, 0, NULL, 0, 0, NULL
415 };
416
417 static const detailed_info_t detailed_info1 = {
418 1, 1, 1, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE, manifest_path,
419 ACTIVATION_CONTEXT_PATH_TYPE_NONE, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE,
420 work_dir,
421 };
422
423 static const detailed_info_t detailed_info1_child = {
424 1, 1, 1, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE, app_manifest_path,
425 ACTIVATION_CONTEXT_PATH_TYPE_NONE, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE,
426 app_dir,
427 };
428
429 /* On Vista+, there's an extra assembly for Microsoft.Windows.Common-Controls.Resources */
430 static const detailed_info_t detailed_info2 = {
431 1, 2, 3, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE, manifest_path,
432 ACTIVATION_CONTEXT_PATH_TYPE_NONE, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE,
433 work_dir,
434 };
435
436 static void test_detailed_info(HANDLE handle, const detailed_info_t *exinfo, int line)
437 {
438 ACTIVATION_CONTEXT_DETAILED_INFORMATION detailed_info_tmp, *detailed_info;
439 SIZE_T size, exsize, retsize;
440 BOOL b;
441
442 exsize = sizeof(ACTIVATION_CONTEXT_DETAILED_INFORMATION)
443 + (exinfo->root_manifest_path ? (lstrlenW(exinfo->root_manifest_path)+1)*sizeof(WCHAR):0)
444 + (exinfo->app_dir ? (lstrlenW(exinfo->app_dir)+1)*sizeof(WCHAR) : 0);
445
446 if(exsize != sizeof(ACTIVATION_CONTEXT_DETAILED_INFORMATION)) {
447 size = 0xdeadbeef;
448 b = pQueryActCtxW(0, handle, NULL,
449 ActivationContextDetailedInformation, &detailed_info_tmp,
450 sizeof(detailed_info_tmp), &size);
451 ok_(__FILE__, line)(!b, "QueryActCtx succeeded\n");
452 ok_(__FILE__, line)(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetLastError() = %u\n", GetLastError());
453 ok_(__FILE__, line)(size == exsize, "size=%ld, expected %ld\n", size, exsize);
454 }else {
455 size = sizeof(ACTIVATION_CONTEXT_DETAILED_INFORMATION);
456 }
457
458 detailed_info = HeapAlloc(GetProcessHeap(), 0, size);
459 memset(detailed_info, 0xfe, size);
460 b = pQueryActCtxW(0, handle, NULL,
461 ActivationContextDetailedInformation, detailed_info,
462 size, &retsize);
463 ok_(__FILE__, line)(b, "QueryActCtx failed: %u\n", GetLastError());
464 ok_(__FILE__, line)(retsize == exsize, "size=%ld, expected %ld\n", retsize, exsize);
465
466 ok_(__FILE__, line)(detailed_info->dwFlags == 0, "detailed_info->dwFlags=%x\n", detailed_info->dwFlags);
467 ok_(__FILE__, line)(detailed_info->ulFormatVersion == exinfo->format_version,
468 "detailed_info->ulFormatVersion=%u, expected %u\n", detailed_info->ulFormatVersion,
469 exinfo->format_version);
470 ok_(__FILE__, line)(exinfo->assembly_cnt_min <= detailed_info->ulAssemblyCount &&
471 detailed_info->ulAssemblyCount <= exinfo->assembly_cnt_max,
472 "detailed_info->ulAssemblyCount=%u, expected between %u and %u\n", detailed_info->ulAssemblyCount,
473 exinfo->assembly_cnt_min, exinfo->assembly_cnt_max);
474 ok_(__FILE__, line)(detailed_info->ulRootManifestPathType == exinfo->root_manifest_type,
475 "detailed_info->ulRootManifestPathType=%u, expected %u\n",
476 detailed_info->ulRootManifestPathType, exinfo->root_manifest_type);
477 ok_(__FILE__, line)(detailed_info->ulRootManifestPathChars ==
478 (exinfo->root_manifest_path ? lstrlenW(exinfo->root_manifest_path) : 0),
479 "detailed_info->ulRootManifestPathChars=%u, expected %u\n",
480 detailed_info->ulRootManifestPathChars,
481 exinfo->root_manifest_path ?lstrlenW(exinfo->root_manifest_path) : 0);
482 ok_(__FILE__, line)(detailed_info->ulRootConfigurationPathType == exinfo->root_config_type,
483 "detailed_info->ulRootConfigurationPathType=%u, expected %u\n",
484 detailed_info->ulRootConfigurationPathType, exinfo->root_config_type);
485 ok_(__FILE__, line)(detailed_info->ulRootConfigurationPathChars == 0,
486 "detailed_info->ulRootConfigurationPathChars=%d\n", detailed_info->ulRootConfigurationPathChars);
487 ok_(__FILE__, line)(detailed_info->ulAppDirPathType == exinfo->app_dir_type,
488 "detailed_info->ulAppDirPathType=%u, expected %u\n", detailed_info->ulAppDirPathType,
489 exinfo->app_dir_type);
490 ok_(__FILE__, line)(detailed_info->ulAppDirPathChars == (exinfo->app_dir ? lstrlenW(exinfo->app_dir) : 0),
491 "detailed_info->ulAppDirPathChars=%u, expected %u\n",
492 detailed_info->ulAppDirPathChars, exinfo->app_dir ? lstrlenW(exinfo->app_dir) : 0);
493 if(exinfo->root_manifest_path) {
494 ok_(__FILE__, line)(detailed_info->lpRootManifestPath != NULL, "detailed_info->lpRootManifestPath == NULL\n");
495 if(detailed_info->lpRootManifestPath)
496 ok_(__FILE__, line)(!lstrcmpiW(detailed_info->lpRootManifestPath, exinfo->root_manifest_path),
497 "unexpected detailed_info->lpRootManifestPath\n");
498 }else {
499 ok_(__FILE__, line)(detailed_info->lpRootManifestPath == NULL, "detailed_info->lpRootManifestPath != NULL\n");
500 }
501 ok_(__FILE__, line)(detailed_info->lpRootConfigurationPath == NULL,
502 "detailed_info->lpRootConfigurationPath=%p\n", detailed_info->lpRootConfigurationPath);
503 if(exinfo->app_dir) {
504 ok_(__FILE__, line)(detailed_info->lpAppDirPath != NULL, "detailed_info->lpAppDirPath == NULL\n");
505 if(detailed_info->lpAppDirPath)
506 ok_(__FILE__, line)(!lstrcmpiW(exinfo->app_dir, detailed_info->lpAppDirPath),
507 "unexpected detailed_info->lpAppDirPath\n%s\n",strw(detailed_info->lpAppDirPath));
508 }else {
509 ok_(__FILE__, line)(detailed_info->lpAppDirPath == NULL, "detailed_info->lpAppDirPath != NULL\n");
510 }
511
512 HeapFree(GetProcessHeap(), 0, detailed_info);
513 }
514
515 typedef struct {
516 ULONG flags;
517 /* ULONG manifest_path_type; FIXME */
518 LPCWSTR manifest_path;
519 LPCSTR encoded_assembly_id;
520 BOOL has_assembly_dir;
521 } info_in_assembly;
522
523 static const info_in_assembly manifest1_info = {
524 1, manifest_path,
525 "Wine.Test,type=\"win32\",version=\"1.0.0.0\"",
526 FALSE
527 };
528
529 static const info_in_assembly manifest1_child_info = {
530 1, app_manifest_path,
531 "Wine.Test,type=\"win32\",version=\"1.0.0.0\"",
532 FALSE
533 };
534
535 static const info_in_assembly manifest2_info = {
536 1, manifest_path,
537 "Wine.Test,type=\"win32\",version=\"1.2.3.4\"",
538 FALSE
539 };
540
541 static const info_in_assembly manifest3_info = {
542 1, manifest_path,
543 "Wine.Test,publicKeyToken=\"6595b6414666f1df\",type=\"win32\",version=\"1.2.3.4\"",
544 FALSE
545 };
546
547 static const info_in_assembly manifest4_info = {
548 1, manifest_path,
549 "Wine.Test,type=\"win32\",version=\"1.2.3.4\"",
550 FALSE
551 };
552
553 static const info_in_assembly depmanifest1_info = {
554 0x10, depmanifest_path,
555 "testdep,processorArchitecture=\"" ARCH "\","
556 "type=\"win32\",version=\"6.5.4.3\"",
557 TRUE
558 };
559
560 static const info_in_assembly depmanifest2_info = {
561 0x10, depmanifest_path,
562 "testdep,processorArchitecture=\"" ARCH "\","
563 "type=\"win32\",version=\"6.5.4.3\"",
564 TRUE
565 };
566
567 static const info_in_assembly depmanifest3_info = {
568 0x10, depmanifest_path,
569 "testdep,processorArchitecture=\"" ARCH "\",type=\"win32\",version=\"6.5.4.3\"",
570 TRUE
571 };
572
573 static const info_in_assembly manifest_comctrl_info = {
574 0, NULL, NULL, TRUE /* These values may differ between Windows installations */
575 };
576
577 static void test_info_in_assembly(HANDLE handle, DWORD id, const info_in_assembly *exinfo, int line)
578 {
579 ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION *info, info_tmp;
580 SIZE_T size, exsize;
581 ULONG len;
582 BOOL b;
583
584 exsize = sizeof(ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION);
585 if (exinfo->manifest_path) exsize += (lstrlenW(exinfo->manifest_path)+1) * sizeof(WCHAR);
586 if (exinfo->encoded_assembly_id) exsize += (strlen_aw(exinfo->encoded_assembly_id) + 1) * sizeof(WCHAR);
587
588 size = 0xdeadbeef;
589 b = pQueryActCtxW(0, handle, &id,
590 AssemblyDetailedInformationInActivationContext, &info_tmp,
591 sizeof(info_tmp), &size);
592 ok_(__FILE__, line)(!b, "QueryActCtx succeeded\n");
593 ok_(__FILE__, line)(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetLastError() = %u\n", GetLastError());
594
595 ok_(__FILE__, line)(size >= exsize, "size=%lu, expected %lu\n", size, exsize);
596
597 if (size == 0xdeadbeef)
598 {
599 skip("bad size\n");
600 return;
601 }
602
603 info = HeapAlloc(GetProcessHeap(), 0, size);
604 memset(info, 0xfe, size);
605
606 size = 0xdeadbeef;
607 b = pQueryActCtxW(0, handle, &id,
608 AssemblyDetailedInformationInActivationContext, info, size, &size);
609 ok_(__FILE__, line)(b, "QueryActCtx failed: %u\n", GetLastError());
610 if (!exinfo->manifest_path)
611 exsize += info->ulManifestPathLength + sizeof(WCHAR);
612 if (!exinfo->encoded_assembly_id)
613 exsize += info->ulEncodedAssemblyIdentityLength + sizeof(WCHAR);
614 if (exinfo->has_assembly_dir)
615 exsize += info->ulAssemblyDirectoryNameLength + sizeof(WCHAR);
616 ok_(__FILE__, line)(size == exsize, "size=%lu, expected %lu\n", size, exsize);
617
618 if (0) /* FIXME: flags meaning unknown */
619 {
620 ok_(__FILE__, line)((info->ulFlags) == exinfo->flags, "info->ulFlags = %x, expected %x\n",
621 info->ulFlags, exinfo->flags);
622 }
623 if(exinfo->encoded_assembly_id) {
624 len = strlen_aw(exinfo->encoded_assembly_id)*sizeof(WCHAR);
625 ok_(__FILE__, line)(info->ulEncodedAssemblyIdentityLength == len,
626 "info->ulEncodedAssemblyIdentityLength = %u, expected %u\n",
627 info->ulEncodedAssemblyIdentityLength, len);
628 } else {
629 ok_(__FILE__, line)(info->ulEncodedAssemblyIdentityLength != 0,
630 "info->ulEncodedAssemblyIdentityLength == 0\n");
631 }
632 ok_(__FILE__, line)(info->ulManifestPathType == ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE,
633 "info->ulManifestPathType = %x\n", info->ulManifestPathType);
634 if(exinfo->manifest_path) {
635 len = lstrlenW(exinfo->manifest_path)*sizeof(WCHAR);
636 ok_(__FILE__, line)(info->ulManifestPathLength == len, "info->ulManifestPathLength = %u, expected %u\n",
637 info->ulManifestPathLength, len);
638 } else {
639 ok_(__FILE__, line)(info->ulManifestPathLength != 0, "info->ulManifestPathLength == 0\n");
640 }
641
642 ok_(__FILE__, line)(info->ulPolicyPathType == ACTIVATION_CONTEXT_PATH_TYPE_NONE,
643 "info->ulPolicyPathType = %x\n", info->ulPolicyPathType);
644 ok_(__FILE__, line)(info->ulPolicyPathLength == 0,
645 "info->ulPolicyPathLength = %u, expected 0\n", info->ulPolicyPathLength);
646 ok_(__FILE__, line)(info->ulMetadataSatelliteRosterIndex == 0, "info->ulMetadataSatelliteRosterIndex = %x\n",
647 info->ulMetadataSatelliteRosterIndex);
648 ok_(__FILE__, line)(info->ulManifestVersionMajor == 1,"info->ulManifestVersionMajor = %x\n",
649 info->ulManifestVersionMajor);
650 ok_(__FILE__, line)(info->ulManifestVersionMinor == 0, "info->ulManifestVersionMinor = %x\n",
651 info->ulManifestVersionMinor);
652 ok_(__FILE__, line)(info->ulPolicyVersionMajor == 0, "info->ulPolicyVersionMajor = %x\n",
653 info->ulPolicyVersionMajor);
654 ok_(__FILE__, line)(info->ulPolicyVersionMinor == 0, "info->ulPolicyVersionMinor = %x\n",
655 info->ulPolicyVersionMinor);
656 if(exinfo->has_assembly_dir)
657 ok_(__FILE__, line)(info->ulAssemblyDirectoryNameLength != 0,
658 "info->ulAssemblyDirectoryNameLength == 0\n");
659 else
660 ok_(__FILE__, line)(info->ulAssemblyDirectoryNameLength == 0,
661 "info->ulAssemblyDirectoryNameLength != 0\n");
662
663 ok_(__FILE__, line)(info->lpAssemblyEncodedAssemblyIdentity != NULL,
664 "info->lpAssemblyEncodedAssemblyIdentity == NULL\n");
665 if(info->lpAssemblyEncodedAssemblyIdentity && exinfo->encoded_assembly_id) {
666 ok_(__FILE__, line)(!strcmp_aw(info->lpAssemblyEncodedAssemblyIdentity, exinfo->encoded_assembly_id),
667 "unexpected info->lpAssemblyEncodedAssemblyIdentity %s / %s\n",
668 strw(info->lpAssemblyEncodedAssemblyIdentity), exinfo->encoded_assembly_id);
669 }
670 if(exinfo->manifest_path) {
671 ok_(__FILE__, line)(info->lpAssemblyManifestPath != NULL, "info->lpAssemblyManifestPath == NULL\n");
672 if(info->lpAssemblyManifestPath)
673 ok_(__FILE__, line)(!lstrcmpiW(info->lpAssemblyManifestPath, exinfo->manifest_path),
674 "unexpected info->lpAssemblyManifestPath\n");
675 }else {
676 ok_(__FILE__, line)(info->lpAssemblyManifestPath != NULL, "info->lpAssemblyManifestPath == NULL\n");
677 }
678
679 ok_(__FILE__, line)(info->lpAssemblyPolicyPath == NULL, "info->lpAssemblyPolicyPath != NULL\n");
680 if(info->lpAssemblyPolicyPath)
681 ok_(__FILE__, line)(*(WORD*)info->lpAssemblyPolicyPath == 0, "info->lpAssemblyPolicyPath is not empty\n");
682 if(exinfo->has_assembly_dir)
683 ok_(__FILE__, line)(info->lpAssemblyDirectoryName != NULL, "info->lpAssemblyDirectoryName == NULL\n");
684 else
685 ok_(__FILE__, line)(info->lpAssemblyDirectoryName == NULL, "info->lpAssemblyDirectoryName = %s\n",
686 strw(info->lpAssemblyDirectoryName));
687 HeapFree(GetProcessHeap(), 0, info);
688 }
689
690 static void test_file_info(HANDLE handle, ULONG assid, ULONG fileid, LPCWSTR filename, int line)
691 {
692 ASSEMBLY_FILE_DETAILED_INFORMATION *info, info_tmp;
693 ACTIVATION_CONTEXT_QUERY_INDEX index = {assid, fileid};
694 SIZE_T size, exsize;
695 BOOL b;
696
697 exsize = sizeof(ASSEMBLY_FILE_DETAILED_INFORMATION)
698 +(lstrlenW(filename)+1)*sizeof(WCHAR);
699
700 size = 0xdeadbeef;
701 b = pQueryActCtxW(0, handle, &index,
702 FileInformationInAssemblyOfAssemblyInActivationContext, &info_tmp,
703 sizeof(info_tmp), &size);
704 ok_(__FILE__, line)(!b, "QueryActCtx succeeded\n");
705 ok_(__FILE__, line)(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetLastError() = %u\n", GetLastError());
706 ok_(__FILE__, line)(size == exsize, "size=%lu, expected %lu\n", size, exsize);
707
708 if(size == 0xdeadbeef)
709 {
710 skip("bad size\n");
711 return;
712 }
713
714 info = HeapAlloc(GetProcessHeap(), 0, size);
715 memset(info, 0xfe, size);
716
717 b = pQueryActCtxW(0, handle, &index,
718 FileInformationInAssemblyOfAssemblyInActivationContext, info, size, &size);
719 ok_(__FILE__, line)(b, "QueryActCtx failed: %u\n", GetLastError());
720 ok_(__FILE__, line)(!size, "size=%lu, expected 0\n", size);
721
722 ok_(__FILE__, line)(info->ulFlags == 2, "info->ulFlags=%x, expected 2\n", info->ulFlags);
723 ok_(__FILE__, line)(info->ulFilenameLength == lstrlenW(filename)*sizeof(WCHAR),
724 "info->ulFilenameLength=%u, expected %u*sizeof(WCHAR)\n",
725 info->ulFilenameLength, lstrlenW(filename));
726 ok_(__FILE__, line)(info->ulPathLength == 0, "info->ulPathLength=%u\n", info->ulPathLength);
727 ok_(__FILE__, line)(info->lpFileName != NULL, "info->lpFileName == NULL\n");
728 if(info->lpFileName)
729 ok_(__FILE__, line)(!lstrcmpiW(info->lpFileName, filename), "unexpected info->lpFileName\n");
730 ok_(__FILE__, line)(info->lpFilePath == NULL, "info->lpFilePath != NULL\n");
731 HeapFree(GetProcessHeap(), 0, info);
732 }
733
734 static HANDLE test_create(const char *file)
735 {
736 ACTCTXW actctx;
737 HANDLE handle;
738 WCHAR path[MAX_PATH];
739
740 MultiByteToWideChar( CP_ACP, 0, file, -1, path, MAX_PATH );
741 memset(&actctx, 0, sizeof(ACTCTXW));
742 actctx.cbSize = sizeof(ACTCTXW);
743 actctx.lpSource = path;
744
745 handle = pCreateActCtxW(&actctx);
746 /* to be tested outside of this helper, including last error */
747 if (handle == INVALID_HANDLE_VALUE) return handle;
748
749 ok(actctx.cbSize == sizeof(actctx), "actctx.cbSize=%d\n", actctx.cbSize);
750 ok(actctx.dwFlags == 0, "actctx.dwFlags=%d\n", actctx.dwFlags);
751 ok(actctx.lpSource == path, "actctx.lpSource=%p\n", actctx.lpSource);
752 ok(actctx.wProcessorArchitecture == 0,
753 "actctx.wProcessorArchitecture=%d\n", actctx.wProcessorArchitecture);
754 ok(actctx.wLangId == 0, "actctx.wLangId=%d\n", actctx.wLangId);
755 ok(actctx.lpAssemblyDirectory == NULL,
756 "actctx.lpAssemblyDirectory=%p\n", actctx.lpAssemblyDirectory);
757 ok(actctx.lpResourceName == NULL, "actctx.lpResourceName=%p\n", actctx.lpResourceName);
758 ok(actctx.lpApplicationName == NULL, "actctx.lpApplicationName=%p\n",
759 actctx.lpApplicationName);
760 ok(actctx.hModule == NULL, "actctx.hModule=%p\n", actctx.hModule);
761
762 return handle;
763 }
764
765 static void test_create_and_fail(const char *manifest, const char *depmanifest, int todo)
766 {
767 ACTCTXW actctx;
768 HANDLE handle;
769 WCHAR path[MAX_PATH];
770
771 MultiByteToWideChar( CP_ACP, 0, "bad.manifest", -1, path, MAX_PATH );
772 memset(&actctx, 0, sizeof(ACTCTXW));
773 actctx.cbSize = sizeof(ACTCTXW);
774 actctx.lpSource = path;
775
776 create_manifest_file("bad.manifest", manifest, -1, "testdep.manifest", depmanifest);
777 handle = pCreateActCtxW(&actctx);
778 if (todo) todo_wine
779 {
780 ok(handle == INVALID_HANDLE_VALUE, "handle != INVALID_HANDLE_VALUE\n");
781 ok(GetLastError() == ERROR_SXS_CANT_GEN_ACTCTX, "GetLastError == %u\n", GetLastError());
782 }
783 else
784 {
785 ok(handle == INVALID_HANDLE_VALUE, "handle != INVALID_HANDLE_VALUE\n");
786 ok(GetLastError() == ERROR_SXS_CANT_GEN_ACTCTX, "GetLastError == %u\n", GetLastError());
787 }
788 if (handle != INVALID_HANDLE_VALUE) pReleaseActCtx( handle );
789 DeleteFileA("bad.manifest");
790 DeleteFileA("testdep.manifest");
791 }
792
793 static void test_create_wide_and_fail(const char *manifest, BOOL fBOM)
794 {
795 ACTCTXW actctx;
796 HANDLE handle;
797 WCHAR path[MAX_PATH];
798
799 MultiByteToWideChar( CP_ACP, 0, "bad.manifest", -1, path, MAX_PATH );
800 memset(&actctx, 0, sizeof(ACTCTXW));
801 actctx.cbSize = sizeof(ACTCTXW);
802 actctx.lpSource = path;
803
804 create_wide_manifest("bad.manifest", manifest, fBOM, FALSE);
805 handle = pCreateActCtxW(&actctx);
806 ok(handle == INVALID_HANDLE_VALUE, "handle != INVALID_HANDLE_VALUE\n");
807 ok(GetLastError() == ERROR_SXS_CANT_GEN_ACTCTX, "GetLastError == %u\n", GetLastError());
808
809 if (handle != INVALID_HANDLE_VALUE) pReleaseActCtx( handle );
810 DeleteFileA("bad.manifest");
811 }
812
813 static void test_create_fail(void)
814 {
815 ACTCTXW actctx;
816 HANDLE handle;
817 WCHAR path[MAX_PATH];
818
819 MultiByteToWideChar( CP_ACP, 0, "nonexistent.manifest", -1, path, MAX_PATH );
820 memset(&actctx, 0, sizeof(ACTCTXW));
821 actctx.cbSize = sizeof(ACTCTXW);
822 actctx.lpSource = path;
823
824 handle = pCreateActCtxW(&actctx);
825 ok(handle == INVALID_HANDLE_VALUE, "handle != INVALID_HANDLE_VALUE\n");
826 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "GetLastError == %u\n", GetLastError());
827
828 trace("wrong_manifest1\n");
829 test_create_and_fail(wrong_manifest1, NULL, 0 );
830 trace("wrong_manifest2\n");
831 test_create_and_fail(wrong_manifest2, NULL, 0 );
832 trace("wrong_manifest3\n");
833 test_create_and_fail(wrong_manifest3, NULL, 1 );
834 trace("wrong_manifest4\n");
835 test_create_and_fail(wrong_manifest4, NULL, 1 );
836 trace("wrong_manifest5\n");
837 test_create_and_fail(wrong_manifest5, NULL, 0 );
838 trace("wrong_manifest6\n");
839 test_create_and_fail(wrong_manifest6, NULL, 0 );
840 trace("wrong_manifest7\n");
841 test_create_and_fail(wrong_manifest7, NULL, 1 );
842 trace("wrong_manifest8\n");
843 test_create_and_fail(wrong_manifest8, NULL, 0 );
844 trace("UTF-16 manifest1 without BOM\n");
845 test_create_wide_and_fail(manifest1, FALSE );
846 trace("manifest2\n");
847 test_create_and_fail(manifest2, NULL, 0 );
848 trace("manifest2+depmanifest1\n");
849 test_create_and_fail(manifest2, wrong_depmanifest1, 0 );
850 }
851
852 struct strsection_header
853 {
854 DWORD magic;
855 ULONG size;
856 DWORD unk1[3];
857 ULONG count;
858 ULONG index_offset;
859 DWORD unk2[2];
860 ULONG global_offset;
861 ULONG global_len;
862 };
863
864 struct string_index
865 {
866 ULONG hash;
867 ULONG name_offset;
868 ULONG name_len;
869 ULONG data_offset;
870 ULONG data_len;
871 ULONG rosterindex;
872 };
873
874 struct guidsection_header
875 {
876 DWORD magic;
877 ULONG size;
878 DWORD unk[3];
879 ULONG count;
880 ULONG index_offset;
881 DWORD unk2;
882 ULONG names_offset;
883 ULONG names_len;
884 };
885
886 struct guid_index
887 {
888 GUID guid;
889 ULONG data_offset;
890 ULONG data_len;
891 ULONG rosterindex;
892 };
893
894 struct wndclass_redirect_data
895 {
896 ULONG size;
897 DWORD res;
898 ULONG name_len;
899 ULONG name_offset; /* versioned name offset */
900 ULONG module_len;
901 ULONG module_offset;/* container name offset */
902 };
903
904 struct dllredirect_data
905 {
906 ULONG size;
907 ULONG unk;
908 DWORD res[3];
909 };
910
911 struct tlibredirect_data
912 {
913 ULONG size;
914 DWORD res;
915 ULONG name_len;
916 ULONG name_offset;
917 LANGID langid;
918 WORD flags;
919 ULONG help_len;
920 ULONG help_offset;
921 WORD major_version;
922 WORD minor_version;
923 };
924
925 struct progidredirect_data
926 {
927 ULONG size;
928 DWORD reserved;
929 ULONG clsid_offset;
930 };
931
932 static void test_find_dll_redirection(HANDLE handle, LPCWSTR libname, ULONG exid, int line)
933 {
934 ACTCTX_SECTION_KEYED_DATA data;
935 BOOL ret;
936
937 memset(&data, 0xfe, sizeof(data));
938 data.cbSize = sizeof(data);
939
940 ret = pFindActCtxSectionStringW(0, NULL,
941 ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
942 libname, &data);
943 ok_(__FILE__, line)(ret, "FindActCtxSectionStringW failed: %u\n", GetLastError());
944 if (!ret) return;
945
946 ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
947 ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
948 ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
949 ok_(__FILE__, line)(data.ulLength == 20, "data.ulLength=%u\n", data.ulLength);
950
951 if (data.lpData)
952 {
953 struct dllredirect_data *dlldata = (struct dllredirect_data*)data.lpData;
954 ok_(__FILE__, line)(dlldata->size == data.ulLength, "got wrong size %d\n", dlldata->size);
955 ok_(__FILE__, line)(dlldata->unk == 2, "got wrong field value %d\n", dlldata->unk);
956 ok_(__FILE__, line)(dlldata->res[0] == 0, "got wrong res[0] value %d\n", dlldata->res[0]);
957 ok_(__FILE__, line)(dlldata->res[1] == 0, "got wrong res[1] value %d\n", dlldata->res[1]);
958 ok_(__FILE__, line)(dlldata->res[2] == 0, "got wrong res[2] value %d\n", dlldata->res[2]);
959 }
960
961 ok_(__FILE__, line)(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
962 ok_(__FILE__, line)(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%u\n",
963 data.ulSectionGlobalDataLength);
964 ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
965 ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%u\n",
966 data.ulSectionTotalLength);
967 ok_(__FILE__, line)(data.hActCtx == NULL, "data.hActCtx=%p\n", data.hActCtx);
968 ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
969 data.ulAssemblyRosterIndex, exid);
970
971 memset(&data, 0xfe, sizeof(data));
972 data.cbSize = sizeof(data);
973
974 ret = pFindActCtxSectionStringW(FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX, NULL,
975 ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
976 libname, &data);
977 ok_(__FILE__, line)(ret, "FindActCtxSectionStringW failed: %u\n", GetLastError());
978 if (!ret) return;
979
980 ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
981 ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
982 ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
983 ok_(__FILE__, line)(data.ulLength == 20, "data.ulLength=%u\n", data.ulLength);
984 ok_(__FILE__, line)(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
985 ok_(__FILE__, line)(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%u\n",
986 data.ulSectionGlobalDataLength);
987 ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
988 ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%u\n",
989 data.ulSectionTotalLength);
990 ok_(__FILE__, line)(data.hActCtx == handle, "data.hActCtx=%p\n", data.hActCtx);
991 ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
992 data.ulAssemblyRosterIndex, exid);
993
994 pReleaseActCtx(handle);
995 }
996
997 static void test_find_window_class(HANDLE handle, LPCWSTR clsname, ULONG exid, int line)
998 {
999 struct wndclass_redirect_data *wnddata;
1000 struct strsection_header *header;
1001 ACTCTX_SECTION_KEYED_DATA data;
1002 BOOL ret;
1003
1004 memset(&data, 0xfe, sizeof(data));
1005 data.cbSize = sizeof(data);
1006
1007 ret = pFindActCtxSectionStringW(0, NULL,
1008 ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION,
1009 clsname, &data);
1010 ok_(__FILE__, line)(ret, "FindActCtxSectionStringW failed: %u, class %s\n", GetLastError(),
1011 wine_dbgstr_w(clsname));
1012 if (!ret) return;
1013
1014 header = (struct strsection_header*)data.lpSectionBase;
1015 wnddata = (struct wndclass_redirect_data*)data.lpData;
1016
1017 ok_(__FILE__, line)(header->magic == 0x64487353, "got wrong magic 0x%08x\n", header->magic);
1018 ok_(__FILE__, line)(header->count > 0, "got count %d\n", header->count);
1019 ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
1020 ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
1021 ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
1022 ok_(__FILE__, line)(wnddata->size == sizeof(*wnddata), "got %d for header size\n", wnddata->size);
1023 if (data.lpData && wnddata->size == sizeof(*wnddata))
1024 {
1025 static const WCHAR verW[] = {'6','.','5','.','4','.','3','!',0};
1026 WCHAR buff[50];
1027 WCHAR *ptr;
1028 ULONG len;
1029
1030 ok_(__FILE__, line)(wnddata->res == 0, "got reserved as %d\n", wnddata->res);
1031 /* redirect class name (versioned or not) is stored just after header data */
1032 ok_(__FILE__, line)(wnddata->name_offset == wnddata->size, "got name offset as %d\n", wnddata->name_offset);
1033 ok_(__FILE__, line)(wnddata->module_len > 0, "got module name length as %d\n", wnddata->module_len);
1034
1035 /* expected versioned name */
1036 lstrcpyW(buff, verW);
1037 lstrcatW(buff, clsname);
1038 ptr = (WCHAR*)((BYTE*)wnddata + wnddata->name_offset);
1039 ok_(__FILE__, line)(!lstrcmpW(ptr, buff), "got wrong class name %s, expected %s\n", wine_dbgstr_w(ptr), wine_dbgstr_w(buff));
1040 ok_(__FILE__, line)(lstrlenW(ptr)*sizeof(WCHAR) == wnddata->name_len,
1041 "got wrong class name length %d, expected %d\n", wnddata->name_len, lstrlenW(ptr));
1042
1043 /* data length is simply header length + string data length including nulls */
1044 len = wnddata->size + wnddata->name_len + wnddata->module_len + 2*sizeof(WCHAR);
1045 ok_(__FILE__, line)(data.ulLength == len, "got wrong data length %d, expected %d\n", data.ulLength, len);
1046
1047 if (data.ulSectionTotalLength > wnddata->module_offset)
1048 {
1049 WCHAR *modulename, *sectionptr;
1050
1051 /* just compare pointers */
1052 modulename = (WCHAR*)((BYTE*)wnddata + wnddata->size + wnddata->name_len + sizeof(WCHAR));
1053 sectionptr = (WCHAR*)((BYTE*)data.lpSectionBase + wnddata->module_offset);
1054 ok_(__FILE__, line)(modulename == sectionptr, "got wrong name offset %p, expected %p\n", sectionptr, modulename);
1055 }
1056 }
1057
1058 ok_(__FILE__, line)(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
1059 ok_(__FILE__, line)(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%u\n",
1060 data.ulSectionGlobalDataLength);
1061 ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
1062 ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%u\n",
1063 data.ulSectionTotalLength);
1064 ok_(__FILE__, line)(data.hActCtx == NULL, "data.hActCtx=%p\n", data.hActCtx);
1065 ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
1066 data.ulAssemblyRosterIndex, exid);
1067
1068 memset(&data, 0xfe, sizeof(data));
1069 data.cbSize = sizeof(data);
1070
1071 ret = pFindActCtxSectionStringW(FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX, NULL,
1072 ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION,
1073 clsname, &data);
1074 ok_(__FILE__, line)(ret, "FindActCtxSectionStringW failed: %u, class %s\n", GetLastError(),
1075 wine_dbgstr_w(clsname));
1076 if (!ret) return;
1077
1078 ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
1079 ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
1080 ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
1081 ok_(__FILE__, line)(data.ulLength > 0, "data.ulLength=%u\n", data.ulLength);
1082 ok_(__FILE__, line)(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
1083 ok_(__FILE__, line)(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%u\n",
1084 data.ulSectionGlobalDataLength);
1085 ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
1086 ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%u\n", data.ulSectionTotalLength);
1087 ok_(__FILE__, line)(data.hActCtx == handle, "data.hActCtx=%p\n", data.hActCtx);
1088 ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
1089 data.ulAssemblyRosterIndex, exid);
1090
1091 pReleaseActCtx(handle);
1092 }
1093
1094 static void test_find_string_fail(void)
1095 {
1096 ACTCTX_SECTION_KEYED_DATA data = {sizeof(data)};
1097 BOOL ret;
1098
1099 ret = pFindActCtxSectionStringW(0, NULL, 100, testlib_dll, &data);
1100 ok(!ret, "FindActCtxSectionStringW succeeded\n");
1101 ok(GetLastError() == ERROR_SXS_SECTION_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
1102
1103 ret = pFindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
1104 testlib2_dll, &data);
1105 ok(!ret, "FindActCtxSectionStringW succeeded\n");
1106 ok(GetLastError() == ERROR_SXS_KEY_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
1107
1108 ret = pFindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
1109 testlib_dll, NULL);
1110 ok(!ret, "FindActCtxSectionStringW succeeded\n");
1111 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError()=%u\n", GetLastError());
1112
1113 ret = pFindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
1114 NULL, &data);
1115 ok(!ret, "FindActCtxSectionStringW succeeded\n");
1116 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError()=%u\n", GetLastError());
1117
1118 data.cbSize = 0;
1119 ret = pFindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
1120 testlib_dll, &data);
1121 ok(!ret, "FindActCtxSectionStringW succeeded\n");
1122 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError()=%u\n", GetLastError());
1123
1124 data.cbSize = 35;
1125 ret = pFindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
1126 testlib_dll, &data);
1127 ok(!ret, "FindActCtxSectionStringW succeeded\n");
1128 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError()=%u\n", GetLastError());
1129 }
1130
1131
1132 static void test_basic_info(HANDLE handle, int line)
1133 {
1134 ACTIVATION_CONTEXT_BASIC_INFORMATION basic;
1135 SIZE_T size;
1136 BOOL b;
1137
1138 b = pQueryActCtxW(QUERY_ACTCTX_FLAG_NO_ADDREF, handle, NULL,
1139 ActivationContextBasicInformation, &basic,
1140 sizeof(basic), &size);
1141
1142 ok_(__FILE__, line) (b,"ActivationContextBasicInformation failed\n");
1143 ok_(__FILE__, line) (size == sizeof(ACTIVATION_CONTEXT_BASIC_INFORMATION),"size mismatch\n");
1144 ok_(__FILE__, line) (basic.dwFlags == 0, "unexpected flags %x\n",basic.dwFlags);
1145 ok_(__FILE__, line) (basic.hActCtx == handle, "unexpected handle\n");
1146
1147 b = pQueryActCtxW(QUERY_ACTCTX_FLAG_USE_ACTIVE_ACTCTX |
1148 QUERY_ACTCTX_FLAG_NO_ADDREF, handle, NULL,
1149 ActivationContextBasicInformation, &basic,
1150 sizeof(basic), &size);
1151 if (handle)
1152 {
1153 ok_(__FILE__, line) (!b,"ActivationContextBasicInformation succeeded\n");
1154 ok_(__FILE__, line) (size == 0,"size mismatch\n");
1155 ok_(__FILE__, line) (GetLastError() == ERROR_INVALID_PARAMETER, "Wrong last error\n");
1156 ok_(__FILE__, line) (basic.dwFlags == 0, "unexpected flags %x\n",basic.dwFlags);
1157 ok_(__FILE__, line) (basic.hActCtx == handle, "unexpected handle\n");
1158 }
1159 else
1160 {
1161 ok_(__FILE__, line) (b,"ActivationContextBasicInformation failed\n");
1162 ok_(__FILE__, line) (size == sizeof(ACTIVATION_CONTEXT_BASIC_INFORMATION),"size mismatch\n");
1163 ok_(__FILE__, line) (basic.dwFlags == 0, "unexpected flags %x\n",basic.dwFlags);
1164 ok_(__FILE__, line) (basic.hActCtx == handle, "unexpected handle\n");
1165 }
1166 }
1167
1168 enum comclass_threadingmodel {
1169 ThreadingModel_Apartment = 1,
1170 ThreadingModel_Free = 2,
1171 ThreadingModel_No = 3,
1172 ThreadingModel_Both = 4,
1173 ThreadingModel_Neutral = 5
1174 };
1175
1176 enum comclass_miscfields {
1177 MiscStatus = 1,
1178 MiscStatusIcon = 2,
1179 MiscStatusContent = 4,
1180 MiscStatusThumbnail = 8,
1181 MiscStatusDocPrint = 16
1182 };
1183
1184 struct comclassredirect_data {
1185 ULONG size;
1186 BYTE res;
1187 BYTE miscmask;
1188 BYTE res1[2];
1189 DWORD model;
1190 GUID clsid;
1191 GUID alias;
1192 GUID clsid2;
1193 GUID tlid;
1194 ULONG name_len;
1195 ULONG name_offset;
1196 ULONG progid_len;
1197 ULONG progid_offset;
1198 ULONG clrdata_len;
1199 ULONG clrdata_offset;
1200 DWORD miscstatus;
1201 DWORD miscstatuscontent;
1202 DWORD miscstatusthumbnail;
1203 DWORD miscstatusicon;
1204 DWORD miscstatusdocprint;
1205 };
1206
1207 struct clrclass_data {
1208 ULONG size;
1209 DWORD res[2];
1210 ULONG module_len;
1211 ULONG module_offset;
1212 ULONG name_len;
1213 ULONG name_offset;
1214 ULONG version_len;
1215 ULONG version_offset;
1216 DWORD res2[2];
1217 };
1218
1219 static void test_find_com_redirection(HANDLE handle, const GUID *clsid, const GUID *tlid, const WCHAR *progid, ULONG exid, int line)
1220 {
1221 struct comclassredirect_data *comclass, *comclass2;
1222 ACTCTX_SECTION_KEYED_DATA data, data2;
1223 struct guidsection_header *header;
1224 BOOL ret;
1225
1226 memset(&data, 0xfe, sizeof(data));
1227 data.cbSize = sizeof(data);
1228
1229 ret = pFindActCtxSectionGuid(0, NULL,
1230 ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION,
1231 clsid, &data);
1232 if (!ret)
1233 {
1234 skip("failed for guid %s\n", wine_dbgstr_guid(clsid));
1235 return;
1236 }
1237 ok_(__FILE__, line)(ret, "FindActCtxSectionGuid failed: %u\n", GetLastError());
1238
1239 comclass = (struct comclassredirect_data*)data.lpData;
1240
1241 ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
1242 ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
1243 ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
1244 ok_(__FILE__, line)(comclass->size == sizeof(*comclass), "got %d for header size\n", comclass->size);
1245 if (data.lpData && comclass->size == sizeof(*comclass))
1246 {
1247 WCHAR *ptr;
1248 ULONG len;
1249
1250 ok_(__FILE__, line)(comclass->res == 0, "got res as %d\n", comclass->res);
1251 ok_(__FILE__, line)(comclass->res1[0] == 0, "got res1[0] as %02x\n", comclass->res1[0]);
1252 ok_(__FILE__, line)(comclass->res1[1] == 0, "got res1[1] as %02x\n", comclass->res1[1]);
1253 ok_(__FILE__, line)(comclass->model == ThreadingModel_Neutral, "got model %d\n", comclass->model);
1254 ok_(__FILE__, line)(IsEqualGUID(&comclass->clsid, clsid), "got wrong clsid %s\n", wine_dbgstr_guid(&comclass->clsid));
1255 ok_(__FILE__, line)(IsEqualGUID(&comclass->clsid2, clsid), "got wrong clsid2 %s\n", wine_dbgstr_guid(&comclass->clsid2));
1256 if (tlid)
1257 ok_(__FILE__, line)(IsEqualGUID(&comclass->tlid, tlid), "got wrong tlid %s\n", wine_dbgstr_guid(&comclass->tlid));
1258 ok_(__FILE__, line)(comclass->name_len > 0, "got modulename len %d\n", comclass->name_len);
1259
1260 if (progid)
1261 {
1262 len = comclass->size + comclass->clrdata_len;
1263 ok_(__FILE__, line)(comclass->progid_offset == len, "got progid offset %d, expected %d\n", comclass->progid_offset, len);
1264 }
1265 else
1266 ok_(__FILE__, line)(comclass->progid_offset == 0, "got progid offset %d, expected 0\n", comclass->progid_offset);
1267
1268 if (comclass->progid_offset)
1269 {
1270 ptr = (WCHAR*)((BYTE*)comclass + comclass->progid_offset);
1271 ok_(__FILE__, line)(!lstrcmpW(ptr, progid), "got wrong progid %s, expected %s\n", wine_dbgstr_w(ptr), wine_dbgstr_w(progid));
1272 ok_(__FILE__, line)(lstrlenW(progid)*sizeof(WCHAR) == comclass->progid_len,
1273 "got progid name length %d\n", comclass->progid_len);
1274 }
1275
1276 /* data length is simply header length + string data length including nulls */
1277 len = comclass->size + comclass->clrdata_len;
1278 if (comclass->progid_len) len += comclass->progid_len + sizeof(WCHAR);
1279 ok_(__FILE__, line)(data.ulLength == len, "got wrong data length %d, expected %d\n", data.ulLength, len);
1280
1281 /* keyed data structure doesn't include module name, it's available from section data */
1282 ok_(__FILE__, line)(data.ulSectionTotalLength > comclass->name_offset, "got wrong offset %d\n", comclass->name_offset);
1283
1284 /* check misc fields are set */
1285 if (comclass->miscmask)
1286 {
1287 if (comclass->miscmask & MiscStatus)
1288 ok_(__FILE__, line)(comclass->miscstatus != 0, "got miscstatus 0x%08x\n", comclass->miscstatus);
1289 if (comclass->miscmask & MiscStatusIcon)
1290 ok_(__FILE__, line)(comclass->miscstatusicon != 0, "got miscstatusicon 0x%08x\n", comclass->miscstatusicon);
1291 if (comclass->miscmask & MiscStatusContent)
1292 ok_(__FILE__, line)(comclass->miscstatuscontent != 0, "got miscstatuscontent 0x%08x\n", comclass->miscstatuscontent);
1293 if (comclass->miscmask & MiscStatusThumbnail)
1294 ok_(__FILE__, line)(comclass->miscstatusthumbnail != 0, "got miscstatusthumbnail 0x%08x\n", comclass->miscstatusthumbnail);
1295 if (comclass->miscmask & MiscStatusDocPrint)
1296 ok_(__FILE__, line)(comclass->miscstatusdocprint != 0, "got miscstatusdocprint 0x%08x\n", comclass->miscstatusdocprint);
1297 }
1298
1299 /* part used for clrClass only */
1300 if (comclass->clrdata_len)
1301 {
1302 static const WCHAR mscoreeW[] = {'M','S','C','O','R','E','E','.','D','L','L',0};
1303 static const WCHAR mscoree2W[] = {'m','s','c','o','r','e','e','.','d','l','l',0};
1304 struct clrclass_data *clrclass;
1305 WCHAR *ptrW;
1306
1307 clrclass = (struct clrclass_data*)((BYTE*)data.lpData + comclass->clrdata_offset);
1308 ok_(__FILE__, line)(clrclass->size == sizeof(*clrclass), "clrclass: got size %d\n", clrclass->size);
1309 ok_(__FILE__, line)(clrclass->res[0] == 0, "clrclass: got res[0]=0x%08x\n", clrclass->res[0]);
1310 ok_(__FILE__, line)(clrclass->res[1] == 2, "clrclass: got res[1]=0x%08x\n", clrclass->res[1]);
1311 ok_(__FILE__, line)(clrclass->module_len == lstrlenW(mscoreeW)*sizeof(WCHAR), "clrclass: got module len %d\n", clrclass->module_len);
1312 ok_(__FILE__, line)(clrclass->module_offset > 0, "clrclass: got module offset %d\n", clrclass->module_offset);
1313
1314 ok_(__FILE__, line)(clrclass->name_len > 0, "clrclass: got name len %d\n", clrclass->name_len);
1315 ok_(__FILE__, line)(clrclass->name_offset == clrclass->size, "clrclass: got name offset %d\n", clrclass->name_offset);
1316 ok_(__FILE__, line)(clrclass->version_len > 0, "clrclass: got version len %d\n", clrclass->version_len);
1317 ok_(__FILE__, line)(clrclass->version_offset > 0, "clrclass: got version offset %d\n", clrclass->version_offset);
1318
1319 ok_(__FILE__, line)(clrclass->res2[0] == 0, "clrclass: got res2[0]=0x%08x\n", clrclass->res2[0]);
1320 ok_(__FILE__, line)(clrclass->res2[1] == 0, "clrclass: got res2[1]=0x%08x\n", clrclass->res2[1]);
1321
1322 /* clrClass uses mscoree.dll as module name, but in two variants - comclass data points to module name
1323 in lower case, clsclass subsection - in upper case */
1324 ok_(__FILE__, line)(comclass->name_len == lstrlenW(mscoree2W)*sizeof(WCHAR), "clrclass: got com name len %d\n", comclass->name_len);
1325 ok_(__FILE__, line)(comclass->name_offset > 0, "clrclass: got name offset %d\n", clrclass->name_offset);
1326
1327 ptrW = (WCHAR*)((BYTE*)data.lpSectionBase + comclass->name_offset);
1328 ok_(__FILE__, line)(!lstrcmpW(ptrW, mscoreeW), "clrclass: module name %s\n", wine_dbgstr_w(ptrW));
1329
1330 ptrW = (WCHAR*)((BYTE*)data.lpSectionBase + clrclass->module_offset);
1331 ok_(__FILE__, line)(!lstrcmpW(ptrW, mscoree2W), "clrclass: module name2 %s\n", wine_dbgstr_w(ptrW));
1332 }
1333 }
1334
1335 header = (struct guidsection_header*)data.lpSectionBase;
1336 ok_(__FILE__, line)(data.lpSectionGlobalData == ((BYTE*)header + header->names_offset), "data.lpSectionGlobalData == NULL\n");
1337 ok_(__FILE__, line)(data.ulSectionGlobalDataLength == header->names_len, "data.ulSectionGlobalDataLength=%u\n",
1338 data.ulSectionGlobalDataLength);
1339 ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
1340 ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%u\n",
1341 data.ulSectionTotalLength);
1342 ok_(__FILE__, line)(data.hActCtx == NULL, "data.hActCtx=%p\n", data.hActCtx);
1343 ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
1344 data.ulAssemblyRosterIndex, exid);
1345
1346 /* generated guid for this class works as key guid in search */
1347 memset(&data2, 0xfe, sizeof(data2));
1348 data2.cbSize = sizeof(data2);
1349 ret = pFindActCtxSectionGuid(0, NULL,
1350 ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION,
1351 &comclass->alias, &data2);
1352 ok_(__FILE__, line)(ret, "FindActCtxSectionGuid failed: %u\n", GetLastError());
1353
1354 comclass2 = (struct comclassredirect_data*)data2.lpData;
1355 ok_(__FILE__, line)(comclass->size == comclass2->size, "got wrong data length %d, expected %d\n", comclass2->size, comclass->size);
1356 ok_(__FILE__, line)(!memcmp(comclass, comclass2, comclass->size), "got wrong data\n");
1357 }
1358
1359 enum ifaceps_mask
1360 {
1361 NumMethods = 1,
1362 BaseIface = 2
1363 };
1364
1365 struct ifacepsredirect_data
1366 {
1367 ULONG size;
1368 DWORD mask;
1369 GUID iid;
1370 ULONG nummethods;
1371 GUID tlbid;
1372 GUID base;
1373 ULONG name_len;
1374 ULONG name_offset;
1375 };
1376
1377 static void test_find_ifaceps_redirection(HANDLE handle, const GUID *iid, const GUID *tlbid, const GUID *base,
1378 const GUID *ps32, ULONG exid, int line)
1379 {
1380 struct ifacepsredirect_data *ifaceps;
1381 ACTCTX_SECTION_KEYED_DATA data;
1382 BOOL ret;
1383
1384 memset(&data, 0xfe, sizeof(data));
1385 data.cbSize = sizeof(data);
1386
1387 ret = pFindActCtxSectionGuid(0, NULL,
1388 ACTIVATION_CONTEXT_SECTION_COM_INTERFACE_REDIRECTION,
1389 iid, &data);
1390 ok_(__FILE__, line)(ret, "FindActCtxSectionGuid failed: %u\n", GetLastError());
1391
1392 ifaceps = (struct ifacepsredirect_data*)data.lpData;
1393
1394 ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
1395 ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
1396 ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
1397 ok_(__FILE__, line)(ifaceps->size == sizeof(*ifaceps), "got %d for header size\n", ifaceps->size);
1398 if (data.lpData && ifaceps->size == sizeof(*ifaceps))
1399 {
1400 ULONG len;
1401
1402 /* for external proxy stubs it contains a value from 'proxyStubClsid32' */
1403 if (ps32)
1404 {
1405 ok_(__FILE__, line)(IsEqualGUID(&ifaceps->iid, ps32), "got wrong iid %s\n", wine_dbgstr_guid(&ifaceps->iid));
1406 }
1407 else
1408 ok_(__FILE__, line)(IsEqualGUID(&ifaceps->iid, iid), "got wrong iid %s\n", wine_dbgstr_guid(&ifaceps->iid));
1409
1410 ok_(__FILE__, line)(IsEqualGUID(&ifaceps->tlbid, tlbid), "got wrong tlid %s\n", wine_dbgstr_guid(&ifaceps->tlbid));
1411 ok_(__FILE__, line)(ifaceps->name_len > 0, "got modulename len %d\n", ifaceps->name_len);
1412 ok_(__FILE__, line)(ifaceps->name_offset == ifaceps->size, "got progid offset %d\n", ifaceps->name_offset);
1413
1414 /* data length is simply header length + string data length including nulls */
1415 len = ifaceps->size + ifaceps->name_len + sizeof(WCHAR);
1416 ok_(__FILE__, line)(data.ulLength == len, "got wrong data length %d, expected %d\n", data.ulLength, len);
1417
1418 /* mask purpose is to indicate if attribute was specified, for testing purposes assume that manifest
1419 always has non-zero value for it */
1420 if (ifaceps->mask & NumMethods)
1421 ok_(__FILE__, line)(ifaceps->nummethods != 0, "got nummethods %d\n", ifaceps->nummethods);
1422 if (ifaceps->mask & BaseIface)
1423 ok_(__FILE__, line)(IsEqualGUID(&ifaceps->base, base), "got base %s\n", wine_dbgstr_guid(&ifaceps->base));
1424 }
1425
1426 ok_(__FILE__, line)(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
1427 ok_(__FILE__, line)(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%u\n",
1428 data.ulSectionGlobalDataLength);
1429 ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
1430 ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%u\n",
1431 data.ulSectionTotalLength);
1432 ok_(__FILE__, line)(data.hActCtx == NULL, "data.hActCtx=%p\n", data.hActCtx);
1433 ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
1434 data.ulAssemblyRosterIndex, exid);
1435 }
1436
1437 struct clrsurrogate_data
1438 {
1439 ULONG size;
1440 DWORD res;
1441 GUID clsid;
1442 ULONG version_offset;
1443 ULONG version_len;
1444 ULONG name_offset;
1445 ULONG name_len;
1446 };
1447
1448 static void test_find_surrogate(HANDLE handle, const GUID *clsid, const WCHAR *name, const WCHAR *version,
1449 ULONG exid, int line)
1450 {
1451 struct clrsurrogate_data *surrogate;
1452 ACTCTX_SECTION_KEYED_DATA data;
1453 BOOL ret;
1454
1455 memset(&data, 0xfe, sizeof(data));
1456 data.cbSize = sizeof(data);
1457
1458 ret = pFindActCtxSectionGuid(0, NULL,
1459 ACTIVATION_CONTEXT_SECTION_CLR_SURROGATES,
1460 clsid, &data);
1461 if (!ret)
1462 {
1463 skip("surrogate sections are not supported\n");
1464 return;
1465 }
1466 ok_(__FILE__, line)(ret, "FindActCtxSectionGuid failed: %u\n", GetLastError());
1467
1468 surrogate = (struct clrsurrogate_data*)data.lpData;
1469
1470 ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
1471 ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
1472 ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
1473 ok_(__FILE__, line)(surrogate->size == sizeof(*surrogate), "got %d for header size\n", surrogate->size);
1474 if (data.lpData && surrogate->size == sizeof(*surrogate))
1475 {
1476 WCHAR *ptrW;
1477 ULONG len;
1478
1479 ok_(__FILE__, line)(surrogate->res == 0, "invalid res value %d\n", surrogate->res);
1480 ok_(__FILE__, line)(IsEqualGUID(&surrogate->clsid, clsid), "got wrong clsid %s\n", wine_dbgstr_guid(&surrogate->clsid));
1481
1482 ok_(__FILE__, line)(surrogate->version_len == lstrlenW(version)*sizeof(WCHAR), "got version len %d\n", surrogate->version_len);
1483 ok_(__FILE__, line)(surrogate->version_offset == surrogate->size, "got version offset %d\n", surrogate->version_offset);
1484
1485 ok_(__FILE__, line)(surrogate->name_len == lstrlenW(name)*sizeof(WCHAR), "got name len %d\n", surrogate->name_len);
1486 ok_(__FILE__, line)(surrogate->name_offset > surrogate->version_offset, "got name offset %d\n", surrogate->name_offset);
1487
1488 len = surrogate->size + surrogate->name_len + surrogate->version_len + 2*sizeof(WCHAR);
1489 ok_(__FILE__, line)(data.ulLength == len, "got wrong data length %d, expected %d\n", data.ulLength, len);
1490
1491 ptrW = (WCHAR*)((BYTE*)surrogate + surrogate->name_offset);
1492 ok(!lstrcmpW(ptrW, name), "got wrong name %s\n", wine_dbgstr_w(ptrW));
1493
1494 ptrW = (WCHAR*)((BYTE*)surrogate + surrogate->version_offset);
1495 ok(!lstrcmpW(ptrW, version), "got wrong name %s\n", wine_dbgstr_w(ptrW));
1496 }
1497
1498 ok_(__FILE__, line)(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
1499 ok_(__FILE__, line)(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%u\n",
1500 data.ulSectionGlobalDataLength);
1501 ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
1502 ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%u\n",
1503 data.ulSectionTotalLength);
1504 ok_(__FILE__, line)(data.hActCtx == NULL, "data.hActCtx=%p\n", data.hActCtx);
1505 ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
1506 data.ulAssemblyRosterIndex, exid);
1507 }
1508
1509 static void test_find_progid_redirection(HANDLE handle, const GUID *clsid, const char *progid, ULONG exid, int line)
1510 {
1511 struct progidredirect_data *progiddata;
1512 struct comclassredirect_data *comclass;
1513 ACTCTX_SECTION_KEYED_DATA data, data2;
1514 struct strsection_header *header;
1515 BOOL ret;
1516
1517 memset(&data, 0xfe, sizeof(data));
1518 data.cbSize = sizeof(data);
1519
1520 ret = pFindActCtxSectionStringA(0, NULL,
1521 ACTIVATION_CONTEXT_SECTION_COM_PROGID_REDIRECTION,
1522 progid, &data);
1523 ok_(__FILE__, line)(ret, "FindActCtxSectionStringA failed: %u\n", GetLastError());
1524
1525 progiddata = (struct progidredirect_data*)data.lpData;
1526
1527 ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
1528 ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
1529 ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
1530 ok_(__FILE__, line)(progiddata->size == sizeof(*progiddata), "got %d for header size\n", progiddata->size);
1531 if (data.lpData && progiddata->size == sizeof(*progiddata))
1532 {
1533 GUID *guid;
1534
1535 ok_(__FILE__, line)(progiddata->reserved == 0, "got reserved as %d\n", progiddata->reserved);
1536 ok_(__FILE__, line)(progiddata->clsid_offset > 0, "got clsid_offset as %d\n", progiddata->clsid_offset);
1537
1538 /* progid data points to generated alias guid */
1539 guid = (GUID*)((BYTE*)data.lpSectionBase + progiddata->clsid_offset);
1540
1541 memset(&data2, 0, sizeof(data2));
1542 data2.cbSize = sizeof(data2);
1543 ret = pFindActCtxSectionGuid(0, NULL,
1544 ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION,
1545 guid, &data2);
1546 ok_(__FILE__, line)(ret, "FindActCtxSectionGuid failed: %u\n", GetLastError());
1547
1548 comclass = (struct comclassredirect_data*)data2.lpData;
1549 ok_(__FILE__, line)(IsEqualGUID(guid, &comclass->alias), "got wrong alias referenced from progid %s, %s\n", progid, wine_dbgstr_guid(guid));
1550 ok_(__FILE__, line)(IsEqualGUID(clsid, &comclass->clsid), "got wrong class referenced from progid %s, %s\n", progid, wine_dbgstr_guid(clsid));
1551 }
1552
1553 header = (struct strsection_header*)data.lpSectionBase;
1554 ok_(__FILE__, line)(data.lpSectionGlobalData == (BYTE*)header + header->global_offset, "data.lpSectionGlobalData == NULL\n");
1555 ok_(__FILE__, line)(data.ulSectionGlobalDataLength == header->global_len, "data.ulSectionGlobalDataLength=%u\n", data.ulSectionGlobalDataLength);
1556 ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
1557 ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%u\n", data.ulSectionTotalLength);
1558 ok_(__FILE__, line)(data.hActCtx == NULL, "data.hActCtx=%p\n", data.hActCtx);
1559 ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
1560 data.ulAssemblyRosterIndex, exid);
1561 }
1562
1563 static void test_wndclass_section(void)
1564 {
1565 static const WCHAR cls1W[] = {'1','.','2','.','3','.','4','!','w','n','d','C','l','a','s','s','1',0};
1566 ACTCTX_SECTION_KEYED_DATA data, data2;
1567 struct wndclass_redirect_data *classdata;
1568 struct strsection_header *section;
1569 ULONG_PTR cookie;
1570 HANDLE handle;
1571 WCHAR *ptrW;
1572 BOOL ret;
1573
1574 /* use two dependent manifests, each defines 2 window class redirects */
1575 create_manifest_file("testdep1.manifest", manifest_wndcls1, -1, NULL, NULL);
1576 create_manifest_file("testdep2.manifest", manifest_wndcls2, -1, NULL, NULL);
1577 create_manifest_file("main_wndcls.manifest", manifest_wndcls_main, -1, NULL, NULL);
1578
1579 handle = test_create("main_wndcls.manifest");
1580 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
1581
1582 DeleteFileA("testdep1.manifest");
1583 DeleteFileA("testdep2.manifest");
1584 DeleteFileA("main_wndcls.manifest");
1585
1586 ret = pActivateActCtx(handle, &cookie);
1587 ok(ret, "ActivateActCtx failed: %u\n", GetLastError());
1588
1589 memset(&data, 0, sizeof(data));
1590 memset(&data2, 0, sizeof(data2));
1591 data.cbSize = sizeof(data);
1592 data2.cbSize = sizeof(data2);
1593
1594 /* get data for two classes from different assemblies */
1595 ret = pFindActCtxSectionStringW(0, NULL,
1596 ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION,
1597 wndClass1W, &data);
1598 ok(ret, "got %d\n", ret);
1599 ret = pFindActCtxSectionStringW(0, NULL,
1600 ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION,
1601 wndClass3W, &data2);
1602 ok(ret, "got %d\n", ret);
1603
1604 section = (struct strsection_header*)data.lpSectionBase;
1605 ok(section->count == 4, "got %d\n", section->count);
1606 ok(section->size == sizeof(*section), "got %d\n", section->size);
1607
1608 /* For both string same section is returned, meaning it's one wndclass section per context */
1609 ok(data.lpSectionBase == data2.lpSectionBase, "got %p, %p\n", data.lpSectionBase, data2.lpSectionBase);
1610 ok(data.ulSectionTotalLength == data2.ulSectionTotalLength, "got %u, %u\n", data.ulSectionTotalLength,
1611 data2.ulSectionTotalLength);
1612
1613 /* wndClass1 is versioned, wndClass3 is not */
1614 classdata = (struct wndclass_redirect_data*)data.lpData;
1615 ptrW = (WCHAR*)((BYTE*)data.lpData + classdata->name_offset);
1616 ok(!lstrcmpW(ptrW, cls1W), "got %s\n", wine_dbgstr_w(ptrW));
1617
1618 classdata = (struct wndclass_redirect_data*)data2.lpData;
1619 ptrW = (WCHAR*)((BYTE*)data2.lpData + classdata->name_offset);
1620 ok(!lstrcmpW(ptrW, wndClass3W), "got %s\n", wine_dbgstr_w(ptrW));
1621
1622 ret = pDeactivateActCtx(0, cookie);
1623 ok(ret, "DeactivateActCtx failed: %u\n", GetLastError());
1624
1625 pReleaseActCtx(handle);
1626 }
1627
1628 static void test_dllredirect_section(void)
1629 {
1630 static const WCHAR testlib1W[] = {'t','e','s','t','l','i','b','1','.','d','l','l',0};
1631 static const WCHAR testlib2W[] = {'t','e','s','t','l','i','b','2','.','d','l','l',0};
1632 ACTCTX_SECTION_KEYED_DATA data, data2;
1633 struct strsection_header *section;
1634 ULONG_PTR cookie;
1635 HANDLE handle;
1636 BOOL ret;
1637
1638 /* use two dependent manifests, 4 'files' total */
1639 create_manifest_file("testdep1.manifest", manifest_wndcls1, -1, NULL, NULL);
1640 create_manifest_file("testdep2.manifest", manifest_wndcls2, -1, NULL, NULL);
1641 create_manifest_file("main_wndcls.manifest", manifest_wndcls_main, -1, NULL, NULL);
1642
1643 handle = test_create("main_wndcls.manifest");
1644 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
1645
1646 DeleteFileA("testdep1.manifest");
1647 DeleteFileA("testdep2.manifest");
1648 DeleteFileA("main_wndcls.manifest");
1649
1650 ret = pActivateActCtx(handle, &cookie);
1651 ok(ret, "ActivateActCtx failed: %u\n", GetLastError());
1652
1653 memset(&data, 0, sizeof(data));
1654 memset(&data2, 0, sizeof(data2));
1655 data.cbSize = sizeof(data);
1656 data2.cbSize = sizeof(data2);
1657
1658 /* get data for two files from different assemblies */
1659 ret = pFindActCtxSectionStringW(0, NULL,
1660 ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
1661 testlib1W, &data);
1662 ok(ret, "got %d\n", ret);
1663 ret = pFindActCtxSectionStringW(0, NULL,
1664 ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
1665 testlib2W, &data2);
1666 ok(ret, "got %d\n", ret);
1667
1668 section = (struct strsection_header*)data.lpSectionBase;
1669 ok(section->count == 4, "got %d\n", section->count);
1670 ok(section->size == sizeof(*section), "got %d\n", section->size);
1671
1672 /* For both string same section is returned, meaning it's one dll redirect section per context */
1673 ok(data.lpSectionBase == data2.lpSectionBase, "got %p, %p\n", data.lpSectionBase, data2.lpSectionBase);
1674 ok(data.ulSectionTotalLength == data2.ulSectionTotalLength, "got %u, %u\n", data.ulSectionTotalLength,
1675 data2.ulSectionTotalLength);
1676
1677 ret = pDeactivateActCtx(0, cookie);
1678 ok(ret, "DeactivateActCtx failed: %u\n", GetLastError());
1679
1680 pReleaseActCtx(handle);
1681 }
1682
1683 static void test_typelib_section(void)
1684 {
1685 static const WCHAR helpW[] = {'h','e','l','p'};
1686 ACTCTX_SECTION_KEYED_DATA data, data2;
1687 struct guidsection_header *section;
1688 struct tlibredirect_data *tlib;
1689 ULONG_PTR cookie;
1690 HANDLE handle;
1691 BOOL ret;
1692
1693 /* use two dependent manifests, 4 'files' total */
1694 create_manifest_file("testdep1.manifest", manifest_wndcls1, -1, NULL, NULL);
1695 create_manifest_file("testdep2.manifest", manifest_wndcls2, -1, NULL, NULL);
1696 create_manifest_file("main_wndcls.manifest", manifest_wndcls_main, -1, NULL, NULL);
1697
1698 handle = test_create("main_wndcls.manifest");
1699 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
1700
1701 DeleteFileA("testdep1.manifest");
1702 DeleteFileA("testdep2.manifest");
1703 DeleteFileA("main_wndcls.manifest");
1704
1705 ret = pActivateActCtx(handle, &cookie);
1706 ok(ret, "ActivateActCtx failed: %u\n", GetLastError());
1707
1708 memset(&data, 0, sizeof(data));
1709 memset(&data2, 0, sizeof(data2));
1710 data.cbSize = sizeof(data);
1711 data2.cbSize = sizeof(data2);
1712
1713 /* get data for two typelibs from different assemblies */
1714 ret = pFindActCtxSectionGuid(0, NULL,
1715 ACTIVATION_CONTEXT_SECTION_COM_TYPE_LIBRARY_REDIRECTION,
1716 &IID_TlibTest, &data);
1717 ok(ret, "got %d\n", ret);
1718
1719 ret = pFindActCtxSectionGuid(0, NULL,
1720 ACTIVATION_CONTEXT_SECTION_COM_TYPE_LIBRARY_REDIRECTION,
1721 &IID_TlibTest4, &data2);
1722 ok(ret, "got %d\n", ret);
1723
1724 section = (struct guidsection_header*)data.lpSectionBase;
1725 ok(section->count == 4, "got %d\n", section->count);
1726 ok(section->size == sizeof(*section), "got %d\n", section->size);
1727
1728 /* For both GUIDs same section is returned */
1729 ok(data.lpSectionBase == data2.lpSectionBase, "got %p, %p\n", data.lpSectionBase, data2.lpSectionBase);
1730 ok(data.ulSectionTotalLength == data2.ulSectionTotalLength, "got %u, %u\n", data.ulSectionTotalLength,
1731 data2.ulSectionTotalLength);
1732
1733 ok(data.lpSectionGlobalData == ((BYTE*)section + section->names_offset), "data.lpSectionGlobalData == NULL\n");
1734 ok(data.ulSectionGlobalDataLength == section->names_len, "data.ulSectionGlobalDataLength=%u\n",
1735 data.ulSectionGlobalDataLength);
1736
1737 /* test some actual data */
1738 tlib = (struct tlibredirect_data*)data.lpData;
1739 ok(tlib->size == sizeof(*tlib), "got %d\n", tlib->size);
1740 ok(tlib->major_version == 1, "got %d\n", tlib->major_version);
1741 ok(tlib->minor_version == 0, "got %d\n", tlib->minor_version);
1742 ok(tlib->help_offset > 0, "got %d\n", tlib->help_offset);
1743 ok(tlib->help_len == sizeof(helpW), "got %d\n", tlib->help_len);
1744 ok(tlib->flags == (LIBFLAG_FHIDDEN|LIBFLAG_FCONTROL|LIBFLAG_FRESTRICTED), "got %x\n", tlib->flags);
1745
1746 ret = pDeactivateActCtx(0, cookie);
1747 ok(ret, "DeactivateActCtx failed: %u\n", GetLastError());
1748
1749 pReleaseActCtx(handle);
1750 }
1751
1752 static void test_allowDelayedBinding(void)
1753 {
1754 HANDLE handle;
1755
1756 if (!create_manifest_file("test5.manifest", manifest5, -1, NULL, NULL)) {
1757 skip("Could not create manifest file\n");
1758 return;
1759 }
1760
1761 handle = test_create("test5.manifest");
1762 if (handle == INVALID_HANDLE_VALUE) {
1763 win_skip("allowDelayedBinding attribute is not supported.\n");
1764 return;
1765 }
1766
1767 DeleteFileA("test5.manifest");
1768 DeleteFileA("testdep.manifest");
1769 if (handle != INVALID_HANDLE_VALUE) {
1770 test_basic_info(handle, __LINE__);
1771 pReleaseActCtx(handle);
1772 }
1773 }
1774
1775 static void test_actctx(void)
1776 {
1777 ULONG_PTR cookie;
1778 HANDLE handle;
1779 BOOL b;
1780
1781 test_create_fail();
1782
1783 trace("default actctx\n");
1784
1785 b = pGetCurrentActCtx(&handle);
1786 ok(handle == NULL, "handle = %p, expected NULL\n", handle);
1787 ok(b, "GetCurrentActCtx failed: %u\n", GetLastError());
1788 if(b) {
1789 test_basic_info(handle, __LINE__);
1790 test_detailed_info(handle, &detailed_info0, __LINE__);
1791 pReleaseActCtx(handle);
1792 }
1793
1794 /* test for whitespace handling in Eq ::= S? '=' S? */
1795 create_manifest_file("test1_1.manifest", manifest1_1, -1, NULL, NULL);
1796 handle = test_create("test1_1.manifest");
1797 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
1798 DeleteFileA("test1_1.manifest");
1799 pReleaseActCtx(handle);
1800
1801 if(!create_manifest_file("test1.manifest", manifest1, -1, NULL, NULL)) {
1802 skip("Could not create manifest file\n");
1803 return;
1804 }
1805
1806 trace("manifest1\n");
1807
1808 handle = test_create("test1.manifest");
1809 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
1810 DeleteFileA("test1.manifest");
1811 if(handle != INVALID_HANDLE_VALUE) {
1812 test_basic_info(handle, __LINE__);
1813 test_detailed_info(handle, &detailed_info1, __LINE__);
1814 test_info_in_assembly(handle, 1, &manifest1_info, __LINE__);
1815
1816 if (pIsDebuggerPresent && !pIsDebuggerPresent())
1817 {
1818 /* CloseHandle will generate an exception if a debugger is present */
1819 b = CloseHandle(handle);
1820 ok(!b, "CloseHandle succeeded\n");
1821 ok(GetLastError() == ERROR_INVALID_HANDLE, "GetLastError() == %u\n", GetLastError());
1822 }
1823
1824 pReleaseActCtx(handle);
1825 }
1826
1827 if(!create_manifest_file("test2.manifest", manifest2, -1, "testdep.manifest", testdep_manifest1)) {
1828 skip("Could not create manifest file\n");
1829 return;
1830 }
1831
1832 trace("manifest2 depmanifest1\n");
1833
1834 handle = test_create("test2.manifest");
1835 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
1836 DeleteFileA("test2.manifest");
1837 DeleteFileA("testdep.manifest");
1838 if(handle != INVALID_HANDLE_VALUE) {
1839 test_basic_info(handle, __LINE__);
1840 test_detailed_info(handle, &detailed_info2, __LINE__);
1841 test_info_in_assembly(handle, 1, &manifest2_info, __LINE__);
1842 test_info_in_assembly(handle, 2, &depmanifest1_info, __LINE__);
1843 pReleaseActCtx(handle);
1844 }
1845
1846 if(!create_manifest_file("test2-2.manifest", manifest2, -1, "testdep.manifest", testdep_manifest2)) {
1847 skip("Could not create manifest file\n");
1848 return;
1849 }
1850
1851 trace("manifest2 depmanifest2\n");
1852
1853 handle = test_create("test2-2.manifest");
1854 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
1855 DeleteFileA("test2-2.manifest");
1856 DeleteFileA("testdep.manifest");
1857 if(handle != INVALID_HANDLE_VALUE) {
1858 test_basic_info(handle, __LINE__);
1859 test_detailed_info(handle, &detailed_info2, __LINE__);
1860 test_info_in_assembly(handle, 1, &manifest2_info, __LINE__);
1861 test_info_in_assembly(handle, 2, &depmanifest2_info, __LINE__);
1862 test_file_info(handle, 1, 0, testlib_dll, __LINE__);
1863 test_file_info(handle, 1, 1, testlib2_dll, __LINE__);
1864
1865 b = pActivateActCtx(handle, &cookie);
1866 ok(b, "ActivateActCtx failed: %u\n", GetLastError());
1867 test_find_dll_redirection(handle, testlib_dll, 2, __LINE__);
1868 test_find_dll_redirection(handle, testlib2_dll, 2, __LINE__);
1869 b = pDeactivateActCtx(0, cookie);
1870 ok(b, "DeactivateActCtx failed: %u\n", GetLastError());
1871
1872 pReleaseActCtx(handle);
1873 }
1874
1875 trace("manifest2 depmanifest3\n");
1876
1877 if(!create_manifest_file("test2-3.manifest", manifest2, -1, "testdep.manifest", testdep_manifest3)) {
1878 skip("Could not create manifest file\n");
1879 return;
1880 }
1881
1882 handle = test_create("test2-3.manifest");
1883 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
1884 DeleteFileA("test2-3.manifest");
1885 DeleteFileA("testdep.manifest");
1886 if(handle != INVALID_HANDLE_VALUE) {
1887 test_basic_info(handle, __LINE__);
1888 test_detailed_info(handle, &detailed_info2, __LINE__);
1889 test_info_in_assembly(handle, 1, &manifest2_info, __LINE__);
1890 test_info_in_assembly(handle, 2, &depmanifest3_info, __LINE__);
1891 test_file_info(handle, 1, 0, testlib_dll, __LINE__);
1892 test_file_info(handle, 1, 1, testlib2_dll, __LINE__);
1893
1894 b = pActivateActCtx(handle, &cookie);
1895 ok(b, "ActivateActCtx failed: %u\n", GetLastError());
1896 test_find_dll_redirection(handle, testlib_dll, 2, __LINE__);
1897 test_find_dll_redirection(handle, testlib2_dll, 2, __LINE__);
1898 test_find_window_class(handle, wndClassW, 2, __LINE__);
1899 test_find_window_class(handle, wndClass2W, 2, __LINE__);
1900 b = pDeactivateActCtx(0, cookie);
1901 ok(b, "DeactivateActCtx failed: %u\n", GetLastError());
1902
1903 pReleaseActCtx(handle);
1904 }
1905
1906 trace("manifest3\n");
1907
1908 if(!create_manifest_file("test3.manifest", manifest3, -1, NULL, NULL)) {
1909 skip("Could not create manifest file\n");
1910 return;
1911 }
1912
1913 handle = test_create("test3.manifest");
1914 ok(handle != INVALID_HANDLE_VALUE || broken(handle == INVALID_HANDLE_VALUE) /* XP pre-SP2, win2k3 w/o SP */,
1915 "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
1916 if (handle == INVALID_HANDLE_VALUE)
1917 win_skip("Some activation context features not supported, skipping a test (possibly old XP/Win2k3 system\n");
1918 DeleteFileA("test3.manifest");
1919 if(handle != INVALID_HANDLE_VALUE) {
1920 static const WCHAR nameW[] = {'t','e','s','t','s','u','r','r','o','g','a','t','e',0};
1921 static const WCHAR versionW[] = {'v','2','.','0','.','5','0','7','2','7',0};
1922 static const WCHAR progidW[] = {'P','r','o','g','I','d','.','P','r','o','g','I','d',0};
1923 static const WCHAR clrprogidW[] = {'c','l','r','p','r','o','g','i','d',0};
1924
1925 test_basic_info(handle, __LINE__);
1926 test_detailed_info(handle, &detailed_info1, __LINE__);
1927 test_info_in_assembly(handle, 1, &manifest3_info, __LINE__);
1928 test_file_info(handle, 0, 0, testlib_dll, __LINE__);
1929
1930 b = pActivateActCtx(handle, &cookie);
1931 ok(b, "ActivateActCtx failed: %u\n", GetLastError());
1932 test_find_dll_redirection(handle, testlib_dll, 1, __LINE__);
1933 test_find_dll_redirection(handle, testlib_dll, 1, __LINE__);
1934 test_find_com_redirection(handle, &IID_CoTest, &IID_TlibTest, progidW, 1, __LINE__);
1935 test_find_com_redirection(handle, &IID_CoTest2, NULL, NULL, 1, __LINE__);
1936 test_find_com_redirection(handle, &CLSID_clrclass, &IID_TlibTest, clrprogidW, 1, __LINE__);
1937 test_find_progid_redirection(handle, &IID_CoTest, "ProgId.ProgId", 1, __LINE__);
1938 test_find_progid_redirection(handle, &IID_CoTest, "ProgId.ProgId.1", 1, __LINE__);
1939 test_find_progid_redirection(handle, &IID_CoTest, "ProgId.ProgId.2", 1, __LINE__);
1940 test_find_progid_redirection(handle, &IID_CoTest, "ProgId.ProgId.3", 1, __LINE__);
1941 test_find_progid_redirection(handle, &IID_CoTest, "ProgId.ProgId.4", 1, __LINE__);
1942 test_find_progid_redirection(handle, &IID_CoTest, "ProgId.ProgId.5", 1, __LINE__);
1943 test_find_progid_redirection(handle, &IID_CoTest, "ProgId.ProgId.6", 1, __LINE__);
1944 test_find_progid_redirection(handle, &CLSID_clrclass, "clrprogid", 1, __LINE__);
1945 test_find_progid_redirection(handle, &CLSID_clrclass, "clrprogid.1", 1, __LINE__);
1946 test_find_progid_redirection(handle, &CLSID_clrclass, "clrprogid.2", 1, __LINE__);
1947 test_find_progid_redirection(handle, &CLSID_clrclass, "clrprogid.3", 1, __LINE__);
1948 test_find_progid_redirection(handle, &CLSID_clrclass, "clrprogid.4", 1, __LINE__);
1949 test_find_progid_redirection(handle, &CLSID_clrclass, "clrprogid.5", 1, __LINE__);
1950 test_find_progid_redirection(handle, &CLSID_clrclass, "clrprogid.6", 1, __LINE__);
1951 test_find_surrogate(handle, &IID_Iiface, nameW, versionW, 1, __LINE__);
1952 test_find_ifaceps_redirection(handle, &IID_Iifaceps, &IID_TlibTest4, &IID_Ibifaceps, NULL, 1, __LINE__);
1953 test_find_ifaceps_redirection(handle, &IID_Iifaceps2, &IID_TlibTest4, &IID_Ibifaceps, &IID_PS32, 1, __LINE__);
1954 test_find_ifaceps_redirection(handle, &IID_Iifaceps3, &IID_TlibTest4, &IID_Ibifaceps, NULL, 1, __LINE__);
1955 test_find_string_fail();
1956
1957 b = pDeactivateActCtx(0, cookie);
1958 ok(b, "DeactivateActCtx failed: %u\n", GetLastError());
1959 pReleaseActCtx(handle);
1960 }
1961
1962 trace("manifest4\n");
1963
1964 if(!create_manifest_file("test4.manifest", manifest4, -1, NULL, NULL)) {
1965 skip("Could not create manifest file\n");
1966 return;
1967 }
1968
1969 handle = test_create("test4.manifest");
1970 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
1971 DeleteFileA("test4.manifest");
1972 DeleteFileA("testdep.manifest");
1973 if(handle != INVALID_HANDLE_VALUE) {
1974 test_basic_info(handle, __LINE__);
1975 test_detailed_info(handle, &detailed_info2, __LINE__);
1976 test_info_in_assembly(handle, 1, &manifest4_info, __LINE__);
1977 test_info_in_assembly(handle, 2, &manifest_comctrl_info, __LINE__);
1978 pReleaseActCtx(handle);
1979 }
1980
1981 trace("manifest1 in subdir\n");
1982
1983 CreateDirectoryW(work_dir_subdir, NULL);
1984 if (SetCurrentDirectoryW(work_dir_subdir))
1985 {
1986 if(!create_manifest_file("..\\test1.manifest", manifest1, -1, NULL, NULL)) {
1987 skip("Could not create manifest file\n");
1988 return;
1989 }
1990 handle = test_create("..\\test1.manifest");
1991 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
1992 DeleteFileA("..\\test1.manifest");
1993 if(handle != INVALID_HANDLE_VALUE) {
1994 test_basic_info(handle, __LINE__);
1995 test_detailed_info(handle, &detailed_info1, __LINE__);
1996 test_info_in_assembly(handle, 1, &manifest1_info, __LINE__);
1997 pReleaseActCtx(handle);
1998 }
1999 SetCurrentDirectoryW(work_dir);
2000 }
2001 else
2002 skip("Couldn't change directory\n");
2003 RemoveDirectoryW(work_dir_subdir);
2004
2005 trace("UTF-16 manifest1, with BOM\n");
2006 if(!create_wide_manifest("test1.manifest", manifest1, TRUE, FALSE)) {
2007 skip("Could not create manifest file\n");
2008 return;
2009 }
2010
2011 handle = test_create("test1.manifest");
2012 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
2013 DeleteFileA("test1.manifest");
2014 if (handle != INVALID_HANDLE_VALUE) {
2015 test_basic_info(handle, __LINE__);
2016 test_detailed_info(handle, &detailed_info1, __LINE__);
2017 test_info_in_assembly(handle, 1, &manifest1_info, __LINE__);
2018 pReleaseActCtx(handle);
2019 }
2020
2021 trace("UTF-16 manifest1, reverse endian, with BOM\n");
2022 if(!create_wide_manifest("test1.manifest", manifest1, TRUE, TRUE)) {
2023 skip("Could not create manifest file\n");
2024 return;
2025 }
2026
2027 handle = test_create("test1.manifest");
2028 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
2029 DeleteFileA("test1.manifest");
2030 if (handle != INVALID_HANDLE_VALUE) {
2031 test_basic_info(handle, __LINE__);
2032 test_detailed_info(handle, &detailed_info1, __LINE__);
2033 test_info_in_assembly(handle, 1, &manifest1_info, __LINE__);
2034 pReleaseActCtx(handle);
2035 }
2036
2037 test_wndclass_section();
2038 test_dllredirect_section();
2039 test_typelib_section();
2040 test_allowDelayedBinding();
2041 }
2042
2043 static void test_app_manifest(void)
2044 {
2045 HANDLE handle;
2046 BOOL b;
2047
2048 trace("child process manifest1\n");
2049
2050 b = pGetCurrentActCtx(&handle);
2051 ok(handle == NULL, "handle != NULL\n");
2052 ok(b, "GetCurrentActCtx failed: %u\n", GetLastError());
2053 if(b) {
2054 test_basic_info(handle, __LINE__);
2055 test_detailed_info(handle, &detailed_info1_child, __LINE__);
2056 test_info_in_assembly(handle, 1, &manifest1_child_info, __LINE__);
2057 pReleaseActCtx(handle);
2058 }
2059 }
2060
2061 static HANDLE create_manifest(const char *filename, const char *data, int line)
2062 {
2063 HANDLE handle;
2064 create_manifest_file(filename, data, -1, NULL, NULL);
2065
2066 handle = test_create(filename);
2067 ok_(__FILE__, line)(handle != INVALID_HANDLE_VALUE,
2068 "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
2069
2070 DeleteFileA(filename);
2071 return handle;
2072 }
2073
2074 static void kernel32_find(ULONG section, const char *string_to_find, BOOL should_find, int line)
2075 {
2076 UNICODE_STRING string_to_findW;
2077 ACTCTX_SECTION_KEYED_DATA data;
2078 BOOL ret;
2079 DWORD err;
2080
2081 pRtlCreateUnicodeStringFromAsciiz(&string_to_findW, string_to_find);
2082
2083 memset(&data, 0xfe, sizeof(data));
2084 data.cbSize = sizeof(data);
2085
2086 SetLastError(0);
2087 ret = pFindActCtxSectionStringA(0, NULL, section, string_to_find, &data);
2088 err = GetLastError();
2089 ok_(__FILE__, line)(ret == should_find,
2090 "FindActCtxSectionStringA: expected ret = %u, got %u\n", should_find, ret);
2091 ok_(__FILE__, line)(err == (should_find ? ERROR_SUCCESS : ERROR_SXS_KEY_NOT_FOUND),
2092 "FindActCtxSectionStringA: unexpected error %u\n", err);
2093
2094 memset(&data, 0xfe, sizeof(data));
2095 data.cbSize = sizeof(data);
2096
2097 SetLastError(0);
2098 ret = pFindActCtxSectionStringW(0, NULL, section, string_to_findW.Buffer, &data);
2099 err = GetLastError();
2100 ok_(__FILE__, line)(ret == should_find,
2101 "FindActCtxSectionStringW: expected ret = %u, got %u\n", should_find, ret);
2102 ok_(__FILE__, line)(err == (should_find ? ERROR_SUCCESS : ERROR_SXS_KEY_NOT_FOUND),
2103 "FindActCtxSectionStringW: unexpected error %u\n", err);
2104
2105 SetLastError(0);
2106 ret = pFindActCtxSectionStringA(0, NULL, section, string_to_find, NULL);
2107 err = GetLastError();
2108 ok_(__FILE__, line)(!ret,
2109 "FindActCtxSectionStringA: expected failure, got %u\n", ret);
2110 ok_(__FILE__, line)(err == ERROR_INVALID_PARAMETER,
2111 "FindActCtxSectionStringA: unexpected error %u\n", err);
2112
2113 SetLastError(0);
2114 ret = pFindActCtxSectionStringW(0, NULL, section, string_to_findW.Buffer, NULL);
2115 err = GetLastError();
2116 ok_(__FILE__, line)(!ret,
2117 "FindActCtxSectionStringW: expected failure, got %u\n", ret);
2118 ok_(__FILE__, line)(err == ERROR_INVALID_PARAMETER,
2119 "FindActCtxSectionStringW: unexpected error %u\n", err);
2120
2121 pRtlFreeUnicodeString(&string_to_findW);
2122 }
2123
2124 static void ntdll_find(ULONG section, const char *string_to_find, BOOL should_find, int line)
2125 {
2126 UNICODE_STRING string_to_findW;
2127 ACTCTX_SECTION_KEYED_DATA data;
2128 NTSTATUS ret;
2129
2130 pRtlCreateUnicodeStringFromAsciiz(&string_to_findW, string_to_find);
2131
2132 memset(&data, 0xfe, sizeof(data));
2133 data.cbSize = sizeof(data);
2134
2135 ret = pRtlFindActivationContextSectionString(0, NULL, section, &string_to_findW, &data);
2136 ok_(__FILE__, line)(ret == (should_find ? STATUS_SUCCESS : STATUS_SXS_KEY_NOT_FOUND),
2137 "RtlFindActivationContextSectionString: unexpected status 0x%x\n", ret);
2138
2139 ret = pRtlFindActivationContextSectionString(0, NULL, section, &string_to_findW, NULL);
2140 ok_(__FILE__, line)(ret == (should_find ? STATUS_SUCCESS : STATUS_SXS_KEY_NOT_FOUND),
2141 "RtlFindActivationContextSectionString: unexpected status 0x%x\n", ret);
2142
2143 pRtlFreeUnicodeString(&string_to_findW);
2144 }
2145
2146 static void test_findsectionstring(void)
2147 {
2148 HANDLE handle;
2149 BOOL ret;
2150 ULONG_PTR cookie;
2151
2152 handle = create_manifest("test.manifest", testdep_manifest3, __LINE__);
2153 ret = pActivateActCtx(handle, &cookie);
2154 ok(ret, "ActivateActCtx failed: %u\n", GetLastError());
2155
2156 /* first we show the parameter validation from kernel32 */
2157 kernel32_find(ACTIVATION_CONTEXT_SECTION_ASSEMBLY_INFORMATION, "testdep", FALSE, __LINE__);
2158 kernel32_find(ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION, "testlib.dll", TRUE, __LINE__);
2159 kernel32_find(ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION, "testlib2.dll", TRUE, __LINE__);
2160 kernel32_find(ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION, "testlib3.dll", FALSE, __LINE__);
2161 kernel32_find(ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION, "wndClass", TRUE, __LINE__);
2162 kernel32_find(ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION, "wndClass2", TRUE, __LINE__);
2163 kernel32_find(ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION, "wndClass3", FALSE, __LINE__);
2164
2165 /* then we show that ntdll plays by different rules */
2166 ntdll_find(ACTIVATION_CONTEXT_SECTION_ASSEMBLY_INFORMATION, "testdep", FALSE, __LINE__);
2167 ntdll_find(ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION, "testlib.dll", TRUE, __LINE__);
2168 ntdll_find(ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION, "testlib2.dll", TRUE, __LINE__);
2169 ntdll_find(ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION, "testlib3.dll", FALSE, __LINE__);
2170 ntdll_find(ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION, "wndClass", TRUE, __LINE__);
2171 ntdll_find(ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION, "wndClass2", TRUE, __LINE__);
2172 ntdll_find(ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION, "wndClass3", FALSE, __LINE__);
2173
2174 ret = pDeactivateActCtx(0, cookie);
2175 ok(ret, "DeactivateActCtx failed: %u\n", GetLastError());
2176 pReleaseActCtx(handle);
2177 }
2178
2179 static void run_child_process(void)
2180 {
2181 char cmdline[MAX_PATH];
2182 char path[MAX_PATH];
2183 char **argv;
2184 PROCESS_INFORMATION pi;
2185 STARTUPINFOA si = { 0 };
2186 HANDLE file;
2187 FILETIME now;
2188 BOOL ret;
2189
2190 GetModuleFileNameA(NULL, path, MAX_PATH);
2191 strcat(path, ".manifest");
2192 if(!create_manifest_file(path, manifest1, -1, NULL, NULL)) {
2193 skip("Could not create manifest file\n");
2194 return;
2195 }
2196
2197 si.cb = sizeof(si);
2198 winetest_get_mainargs( &argv );
2199 /* Vista+ seems to cache presence of .manifest files. Change last modified
2200 date to defeat the cache */
2201 file = CreateFileA(argv[0], FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE,
2202 NULL, OPEN_EXISTING, 0, NULL);
2203 if (file != INVALID_HANDLE_VALUE) {
2204 GetSystemTimeAsFileTime(&now);
2205 SetFileTime(file, NULL, NULL, &now);
2206 CloseHandle(file);
2207 }
2208 sprintf(cmdline, "\"%s\" %s manifest1", argv[0], argv[1]);
2209 ret = CreateProcessA(argv[0], cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
2210 ok(ret, "Could not create process: %u\n", GetLastError());
2211 winetest_wait_child_process( pi.hProcess );
2212 CloseHandle(pi.hThread);
2213 CloseHandle(pi.hProcess);
2214 DeleteFileA(path);
2215 }
2216
2217 static void init_paths(void)
2218 {
2219 LPWSTR ptr;
2220
2221 static const WCHAR dot_manifest[] = {'.','M','a','n','i','f','e','s','t',0};
2222 static const WCHAR backslash[] = {'\\',0};
2223 static const WCHAR subdir[] = {'T','e','s','t','S','u','b','d','i','r','\\',0};
2224
2225 GetModuleFileNameW(NULL, exe_path, sizeof(exe_path)/sizeof(WCHAR));
2226 lstrcpyW(app_dir, exe_path);
2227 for(ptr=app_dir+lstrlenW(app_dir); *ptr != '\\' && *ptr != '/'; ptr--);
2228 ptr[1] = 0;
2229
2230 GetCurrentDirectoryW(MAX_PATH, work_dir);
2231 ptr = work_dir + lstrlenW( work_dir ) - 1;
2232 if (*ptr != '\\' && *ptr != '/')
2233 lstrcatW(work_dir, backslash);
2234 lstrcpyW(work_dir_subdir, work_dir);
2235 lstrcatW(work_dir_subdir, subdir);
2236
2237 GetModuleFileNameW(NULL, app_manifest_path, sizeof(app_manifest_path)/sizeof(WCHAR));
2238 lstrcpyW(app_manifest_path+lstrlenW(app_manifest_path), dot_manifest);
2239 }
2240
2241 static void write_manifest(const char *filename, const char *manifest)
2242 {
2243 HANDLE file;
2244 DWORD size;
2245 CHAR path[MAX_PATH];
2246
2247 GetTempPathA(sizeof(path)/sizeof(CHAR), path);
2248 strcat(path, filename);
2249
2250 file = CreateFileA(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
2251 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %u\n", GetLastError());
2252 WriteFile(file, manifest, strlen(manifest), &size, NULL);
2253 CloseHandle(file);
2254 }
2255
2256 static void delete_manifest_file(const char *filename)
2257 {
2258 CHAR path[MAX_PATH];
2259
2260 GetTempPathA(sizeof(path)/sizeof(CHAR), path);
2261 strcat(path, filename);
2262 DeleteFileA(path);
2263 }
2264
2265 static void test_CreateActCtx(void)
2266 {
2267 CHAR path[MAX_PATH], dir[MAX_PATH];
2268 ACTCTXA actctx;
2269 HANDLE handle;
2270
2271 GetTempPathA(sizeof(path)/sizeof(CHAR), path);
2272 strcat(path, "main_wndcls.manifest");
2273
2274 write_manifest("testdep1.manifest", manifest_wndcls1);
2275 write_manifest("testdep2.manifest", manifest_wndcls2);
2276 write_manifest("main_wndcls.manifest", manifest_wndcls_main);
2277
2278 memset(&actctx, 0, sizeof(ACTCTXA));
2279 actctx.cbSize = sizeof(ACTCTXA);
2280 actctx.lpSource = path;
2281
2282 /* create using lpSource without specified directory */
2283 handle = pCreateActCtxA(&actctx);
2284 ok(handle != INVALID_HANDLE_VALUE, "failed to generate context, error %u\n", GetLastError());
2285 pReleaseActCtx(handle);
2286
2287 /* with specified directory, that doesn't contain dependent assembly */
2288 GetWindowsDirectoryA(dir, sizeof(dir)/sizeof(CHAR));
2289
2290 memset(&actctx, 0, sizeof(ACTCTXA));
2291 actctx.cbSize = sizeof(ACTCTXA);
2292 actctx.dwFlags = ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID;
2293 actctx.lpAssemblyDirectory = dir;
2294 actctx.lpSource = path;
2295
2296 SetLastError(0xdeadbeef);
2297 handle = pCreateActCtxA(&actctx);
2298 todo_wine {
2299 ok(handle == INVALID_HANDLE_VALUE, "got handle %p\n", handle);
2300 ok(GetLastError() == ERROR_SXS_CANT_GEN_ACTCTX, "got error %d\n", GetLastError());
2301 }
2302 if (handle != INVALID_HANDLE_VALUE) pReleaseActCtx(handle);
2303
2304 delete_manifest_file("main_wndcls.manifest");
2305 delete_manifest_file("testdep1.manifest");
2306 delete_manifest_file("testdep2.manifest");
2307
2308 /* ACTCTX_FLAG_HMODULE_VALID but hModule is not set */
2309 memset(&actctx, 0, sizeof(ACTCTXA));
2310 actctx.cbSize = sizeof(ACTCTXA);
2311 actctx.dwFlags = ACTCTX_FLAG_HMODULE_VALID;
2312 SetLastError(0xdeadbeef);
2313 handle = pCreateActCtxA(&actctx);
2314 ok(handle == INVALID_HANDLE_VALUE, "got handle %p\n", handle);
2315 todo_wine
2316 ok(GetLastError() == ERROR_SXS_CANT_GEN_ACTCTX || broken(GetLastError() == ERROR_NOT_ENOUGH_MEMORY) /* XP, win2k3 */,
2317 "got error %d\n", GetLastError());
2318
2319 /* create from HMODULE - resource doesn't exist, lpSource is set */
2320 memset(&actctx, 0, sizeof(ACTCTXA));
2321 actctx.cbSize = sizeof(ACTCTXA);
2322 actctx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID | ACTCTX_FLAG_HMODULE_VALID;
2323 actctx.lpSource = "dummyfile.dll";
2324 actctx.lpResourceName = MAKEINTRESOURCEA(20);
2325 actctx.hModule = GetModuleHandleA(NULL);
2326
2327 SetLastError(0xdeadbeef);
2328 handle = pCreateActCtxA(&actctx);
2329 ok(handle == INVALID_HANDLE_VALUE, "got handle %p\n", handle);
2330 ok(GetLastError() == ERROR_RESOURCE_TYPE_NOT_FOUND, "got error %d\n", GetLastError());
2331
2332 /* load manifest from lpAssemblyDirectory directory */
2333 write_manifest("testdir.manifest", manifest1);
2334 GetTempPathA(sizeof(path)/sizeof(path[0]), path);
2335 SetCurrentDirectoryA(path);
2336 strcat(path, "assembly_dir");
2337 strcpy(dir, path);
2338 strcat(path, "\\testdir.manifest");
2339
2340 memset(&actctx, 0, sizeof(actctx));
2341 actctx.cbSize = sizeof(actctx);
2342 actctx.dwFlags = ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID;
2343 actctx.lpSource = "testdir.manifest";
2344 actctx.lpAssemblyDirectory = dir;
2345
2346 SetLastError(0xdeadbeef);
2347 handle = pCreateActCtxA(&actctx);
2348 ok(handle == INVALID_HANDLE_VALUE, "got handle %p\n", handle);
2349 ok(GetLastError()==ERROR_PATH_NOT_FOUND ||
2350 broken(GetLastError()==ERROR_FILE_NOT_FOUND) /* WinXP */,
2351 "got error %d\n", GetLastError());
2352
2353 CreateDirectoryA(dir, NULL);
2354 memset(&actctx, 0, sizeof(actctx));
2355 actctx.cbSize = sizeof(actctx);
2356 actctx.dwFlags = ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID;
2357 actctx.lpSource = "testdir.manifest";
2358 actctx.lpAssemblyDirectory = dir;
2359
2360 SetLastError(0xdeadbeef);
2361 handle = pCreateActCtxA(&actctx);
2362 ok(handle == INVALID_HANDLE_VALUE, "got handle %p\n", handle);
2363 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "got error %d\n", GetLastError());
2364 SetCurrentDirectoryW(work_dir);
2365
2366 write_manifest("assembly_dir\\testdir.manifest", manifest1);
2367 memset(&actctx, 0, sizeof(actctx));
2368 actctx.cbSize = sizeof(actctx);
2369 actctx.dwFlags = ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID;
2370 actctx.lpSource = "testdir.manifest";
2371 actctx.lpAssemblyDirectory = dir;
2372
2373 handle = pCreateActCtxA(&actctx);
2374 ok(handle != INVALID_HANDLE_VALUE, "got handle %p\n", handle);
2375 pReleaseActCtx(handle);
2376
2377 memset(&actctx, 0, sizeof(actctx));
2378 actctx.cbSize = sizeof(actctx);
2379 actctx.dwFlags = ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID;
2380 actctx.lpSource = path;
2381 actctx.lpAssemblyDirectory = dir;
2382
2383 handle = pCreateActCtxA(&actctx);
2384 ok(handle != INVALID_HANDLE_VALUE, "got handle %p\n", handle);
2385 pReleaseActCtx(handle);
2386
2387 delete_manifest_file("testdir.manifest");
2388 delete_manifest_file("assembly_dir\\testdir.manifest");
2389 RemoveDirectoryA(dir);
2390 }
2391
2392 static BOOL init_funcs(void)
2393 {
2394 HMODULE hLibrary = GetModuleHandleA("kernel32.dll");
2395
2396 #define X(f) if (!(p##f = (void*)GetProcAddress(hLibrary, #f))) return FALSE;
2397 X(ActivateActCtx);
2398 X(CreateActCtxA);
2399 X(CreateActCtxW);
2400 X(DeactivateActCtx);
2401 X(FindActCtxSectionStringA);
2402 X(FindActCtxSectionStringW);
2403 X(GetCurrentActCtx);
2404 X(IsDebuggerPresent);
2405 X(QueryActCtxW);
2406 X(ReleaseActCtx);
2407 X(FindActCtxSectionGuid);
2408
2409 hLibrary = GetModuleHandleA("ntdll.dll");
2410 X(RtlFindActivationContextSectionString);
2411 X(RtlCreateUnicodeStringFromAsciiz);
2412 X(RtlFreeUnicodeString);
2413 #undef X
2414
2415 return TRUE;
2416 }
2417
2418 START_TEST(actctx)
2419 {
2420 int argc;
2421 char **argv;
2422
2423 argc = winetest_get_mainargs(&argv);
2424
2425 if (!init_funcs())
2426 {
2427 win_skip("Needed functions are not available\n");
2428 return;
2429 }
2430 init_paths();
2431
2432 if(argc > 2 && !strcmp(argv[2], "manifest1")) {
2433 test_app_manifest();
2434 return;
2435 }
2436
2437 test_actctx();
2438 test_CreateActCtx();
2439 test_findsectionstring();
2440 run_child_process();
2441 }