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