Reactos
1/*
2 * Copyright 2007 Jacek Caban for CodeWeavers
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19#include "ntstatus.h"
20#define WIN32_NO_STATUS
21#include "wine/test.h"
22#include <winbase.h>
23#include <windef.h>
24#include <winnt.h>
25#include <winternl.h>
26#include <winnls.h>
27#include <stdio.h>
28
29#include "oaidl.h"
30#include "initguid.h"
31
32static BOOL (WINAPI *pQueryActCtxSettingsW)(DWORD,HANDLE,LPCWSTR,LPCWSTR,LPWSTR,SIZE_T,SIZE_T*);
33
34static NTSTATUS(NTAPI *pRtlFindActivationContextSectionString)(DWORD,const GUID *,ULONG,PUNICODE_STRING,PACTCTX_SECTION_KEYED_DATA);
35static BOOLEAN (NTAPI *pRtlCreateUnicodeStringFromAsciiz)(PUNICODE_STRING, PCSZ);
36static VOID (NTAPI *pRtlFreeUnicodeString)(PUNICODE_STRING);
37
38#ifdef __i386__
39#define ARCH "x86"
40#elif defined __aarch64__ || defined__arm64ec__
41#define ARCH "arm64"
42#elif defined __x86_64__
43#define ARCH "amd64"
44#elif defined __arm__
45#define ARCH "arm"
46#else
47#define ARCH "none"
48#endif
49
50static const char manifest1[] =
51"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
52"<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
53"</assembly>";
54
55static const char manifest1_1[] =
56"<assembly xmlns = \"urn:schemas-microsoft-com:asm.v1\" manifestVersion = \"1.0\">"
57"<assemblyIdentity version = \"1.0.0.0\" name = \"Wine.Test\" type = \"win32\"></assemblyIdentity>"
58"</assembly>";
59
60static const char manifest2[] =
61"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
62"<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\">"
63"</assemblyIdentity>"
64"<dependency>"
65"<dependentAssembly>"
66"<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"" ARCH "\">"
67"</assemblyIdentity>"
68"</dependentAssembly>"
69"</dependency>"
70"</assembly>";
71
72DEFINE_GUID(IID_CoTest, 0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x11, 0x11, 0x22, 0x22, 0x33, 0x33);
73DEFINE_GUID(IID_CoTest2, 0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x11, 0x11, 0x22, 0x22, 0x33, 0x34);
74DEFINE_GUID(CLSID_clrclass,0x22345678, 0x1234, 0x5678, 0x12, 0x34, 0x11, 0x11, 0x22, 0x22, 0x33, 0x33);
75DEFINE_GUID(IID_TlibTest, 0x99999999, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55);
76DEFINE_GUID(IID_TlibTest2, 0x99999999, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x56);
77DEFINE_GUID(IID_TlibTest3, 0x99999999, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x57);
78DEFINE_GUID(IID_TlibTest4, 0x99999999, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x58);
79DEFINE_GUID(IID_Iifaceps, 0x66666666, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55);
80DEFINE_GUID(IID_Ibifaceps, 0x66666666, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x57);
81DEFINE_GUID(IID_Iifaceps2, 0x76666666, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55);
82DEFINE_GUID(IID_Iifaceps3, 0x86666666, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55);
83DEFINE_GUID(IID_Iiface, 0x96666666, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55);
84DEFINE_GUID(IID_PS32, 0x66666666, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x56);
85
86static const char manifest3[] =
87"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
88"<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\""
89" publicKeyToken=\"6595b6414666f1df\" />"
90"<description />"
91"<file name=\"testlib.dll\">"
92"<windowClass>wndClass</windowClass>"
93" <comClass description=\"Test com class\""
94" clsid=\"{12345678-1234-5678-1234-111122223333}\""
95" tlbid=\"{99999999-8888-7777-6666-555555555555}\""
96" threadingModel=\"Neutral\""
97" progid=\"ProgId.ProgId\""
98" miscStatus=\"cantlinkinside\""
99" miscStatusIcon=\"recomposeonresize\""
100" miscStatusContent=\"insideout\""
101" miscStatusThumbnail=\"alignable\""
102" miscStatusDocPrint=\"simpleframe,setclientsitefirst\""
103" >"
104" <progid>ProgId.ProgId.1</progid>"
105" <progid>ProgId.ProgId.2</progid>"
106" <progid>ProgId.ProgId.3</progid>"
107" <progid>ProgId.ProgId.4</progid>"
108" <progid>ProgId.ProgId.5</progid>"
109" <progid>ProgId.ProgId.6</progid>"
110" </comClass>"
111" <comClass clsid=\"{12345678-1234-5678-1234-111122223334}\" threadingModel=\"Neutral\" >"
112" <progid>ProgId.ProgId.7</progid>"
113" </comClass>"
114" <comInterfaceProxyStub "
115" name=\"Iifaceps\""
116" tlbid=\"{99999999-8888-7777-6666-555555555558}\""
117" iid=\"{66666666-8888-7777-6666-555555555555}\""
118" proxyStubClsid32=\"{66666666-8888-7777-6666-555555555556}\""
119" threadingModel=\"Free\""
120" numMethods=\"10\""
121" baseInterface=\"{66666666-8888-7777-6666-555555555557}\""
122" />"
123" <activatableClass name=\"Wine.Test.Class1\" threadingModel=\"mta\" xmlns=\"urn:schemas-microsoft-com:winrt.v1\"/>"
124" <activatableClass name=\"Wine.Test.Class2\" threadingModel=\"both\" xmlns=\"urn:schemas-microsoft-com:winrt.v1\"/>"
125" <activatableClass name=\"Wine.Test.Class3\" threadingModel=\"sta\" xmlns=\"urn:schemas-microsoft-com:winrt.v1\"/>"
126"</file>"
127"<file name=\"Wine.Test.dll\">"
128" <activatableClass name=\"Wine.Test.Class4\" threadingModel=\"sta\" xmlns=\"urn:schemas-microsoft-com:winrt.v1\"/>"
129"</file>"
130" <comInterfaceExternalProxyStub "
131" name=\"Iifaceps2\""
132" tlbid=\"{99999999-8888-7777-6666-555555555558}\""
133" iid=\"{76666666-8888-7777-6666-555555555555}\""
134" proxyStubClsid32=\"{66666666-8888-7777-6666-555555555556}\""
135" numMethods=\"10\""
136" baseInterface=\"{66666666-8888-7777-6666-555555555557}\""
137" />"
138" <comInterfaceExternalProxyStub "
139" name=\"Iifaceps3\""
140" tlbid=\"{99999999-8888-7777-6666-555555555558}\""
141" iid=\"{86666666-8888-7777-6666-555555555555}\""
142" numMethods=\"10\""
143" baseInterface=\"{66666666-8888-7777-6666-555555555557}\""
144" />"
145" <clrSurrogate "
146" clsid=\"{96666666-8888-7777-6666-555555555555}\""
147" name=\"testsurrogate\""
148" runtimeVersion=\"v2.0.50727\""
149" />"
150" <clrSurrogate "
151" clsid=\"{96666666-8888-7777-6666-555555555556}\""
152" name=\"testsurrogate\""
153" runtimeVersion=\"v2.0.50728\""
154" />"
155" <clrClass "
156" clsid=\"{22345678-1234-5678-1234-111122223333}\""
157" name=\"clrclass\""
158" progid=\"clrprogid\""
159" description=\"test description\""
160" tlbid=\"{99999999-8888-7777-6666-555555555555}\""
161" runtimeVersion=\"1.2.3.4\""
162" threadingModel=\"Neutral\""
163" >"
164" <progid>clrprogid.1</progid>"
165" <progid>clrprogid.2</progid>"
166" <progid>clrprogid.3</progid>"
167" <progid>clrprogid.4</progid>"
168" <progid>clrprogid.5</progid>"
169" <progid>clrprogid.6</progid>"
170" </clrClass>"
171"</assembly>";
172
173static const char manifest_wndcls1[] =
174"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
175"<assemblyIdentity version=\"1.2.3.4\" name=\"testdep1\" type=\"win32\" processorArchitecture=\"" ARCH "\"/>"
176"<file name=\"testlib1.dll\">"
177"<windowClass versioned=\"yes\">wndClass1</windowClass>"
178"<windowClass>wndClass2</windowClass>"
179" <typelib tlbid=\"{99999999-8888-7777-6666-555555555558}\" version=\"1.0\" helpdir=\"\" />"
180"</file>"
181"<file name=\"testlib1_2.dll\" />"
182"</assembly>";
183
184static const char manifest_wndcls2[] =
185"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
186"<assemblyIdentity version=\"4.3.2.1\" name=\"testdep2\" type=\"win32\" processorArchitecture=\"" ARCH "\" />"
187"<file name=\"testlib2.dll\">"
188" <windowClass versioned=\"no\">wndClass3</windowClass>"
189" <windowClass>wndClass4</windowClass>"
190" <typelib tlbid=\"{99999999-8888-7777-6666-555555555555}\" version=\"1.0\" helpdir=\"help\" resourceid=\"409\""
191" flags=\"HiddeN,CoNTROL,rESTRICTED\" />"
192" <typelib tlbid=\"{99999999-8888-7777-6666-555555555556}\" version=\"1.0\" helpdir=\"help1\" resourceid=\"409\" />"
193" <typelib tlbid=\"{99999999-8888-7777-6666-555555555557}\" version=\"1.0\" helpdir=\"\" />"
194"</file>"
195"<file name=\"testlib2_2.dll\" />"
196"</assembly>";
197
198static const char manifest_wndcls_main[] =
199"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
200"<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\" />"
201"<dependency>"
202" <dependentAssembly>"
203" <assemblyIdentity type=\"win32\" name=\"testdep1\" version=\"1.2.3.4\" processorArchitecture=\"" ARCH "\" />"
204" </dependentAssembly>"
205"</dependency>"
206"<dependency>"
207" <dependentAssembly>"
208" <assemblyIdentity type=\"win32\" name=\"testdep2\" version=\"4.3.2.1\" processorArchitecture=\"" ARCH "\" />"
209" </dependentAssembly>"
210"</dependency>"
211"</assembly>";
212
213static const char manifest4[] =
214"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
215"<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\">"
216"</assemblyIdentity>"
217"<dependency>"
218"<dependentAssembly>"
219"<assemblyIdentity type=\"win32\" name=\"Microsoft.Windows.Common-Controls\" "
220 "version=\"6.0.1.0\" processorArchitecture=\"" ARCH "\" publicKeyToken=\"6595b64144ccf1df\">"
221"</assemblyIdentity>"
222"</dependentAssembly>"
223"</dependency>"
224"</assembly>";
225
226static const char manifest5[] =
227"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
228"<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\">"
229"</assemblyIdentity>"
230"<dependency>"
231" <dependentAssembly dependencyType=\"preRequisite\" allowDelayedBinding=\"true\">"
232" <assemblyIdentity name=\"Missing.Assembly\" version=\"1.0.0.0\" />"
233" </dependentAssembly>"
234"</dependency>"
235"</assembly>";
236
237static const char manifest6[] =
238"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
239"<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
240"<trustInfo xmlns=\"urn:schemas-microsoft-com:asm.v1\">"
241" <security>"
242" <requestedPrivileges>"
243" <requestedExecutionLevel level=\"ASINVOKER\" uiAccess=\"false\"/>"
244" </requestedPrivileges>"
245" </security>"
246"</trustInfo>"
247"</assembly>";
248
249static const char manifest7[] =
250"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
251"<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
252"<trustInfo xmlns=\"urn:schemas-microsoft-com:asm.v2\">"
253" <security>"
254" <requestedPrivileges>"
255" <requestedExecutionLevel level=\"requireAdministrator\" uiAccess=\"TRUE\"/>"
256" </requestedPrivileges>"
257" </security>"
258"</trustInfo>"
259"</assembly>";
260
261static const char manifest8[] =
262"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
263"<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
264"<trustInfo xmlns=\"urn:schemas-microsoft-com:asm.v2\">"
265" <security>"
266" <requestedPrivileges>"
267" <requestedExecutionLevel level=\"requireAdministrator\" uiAccess=\"true\">"
268" </requestedExecutionLevel>"
269" </requestedPrivileges>"
270" </security>"
271"</trustInfo>"
272"</assembly>";
273
274static const char manifest9[] =
275"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
276"<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
277"<trustInfo xmlns=\"urn:schemas-microsoft-com:asm.v2\">"
278" <security>"
279" <requestedPrivileges>"
280" <requestedExecutionLevel level=\"requireAdministrator\"/>"
281" </requestedPrivileges>"
282" </security>"
283"</trustInfo>"
284"<trustInfo xmlns=\"urn:schemas-microsoft-com:asm.v2\">"
285" <security>"
286" <requestedPrivileges>"
287" </requestedPrivileges>"
288" </security>"
289"</trustInfo>"
290"</assembly>";
291
292static const char manifest10[] =
293"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" xmlns:asmv2=\"urn:schemas-microsoft-com:asm.v2\" manifestVersion=\"1.0\">"
294"<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
295"<asmv2:trustInfo>"
296" <asmv2:security>"
297" <asmv2:requestedPrivileges>"
298" <asmv2:requestedExecutionLevel level=\"requireAdministrator\" uiAccess=\"true\"></asmv2:requestedExecutionLevel>"
299" </asmv2:requestedPrivileges>"
300" </asmv2:security>"
301"</asmv2:trustInfo>"
302"</assembly>";
303
304/* Empty <dependency> element */
305static const char manifest11[] =
306"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" xmlns:asmv2=\"urn:schemas-microsoft-com:asm.v2\" manifestVersion=\"1.0\">"
307"<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
308"<dependency />"
309"</assembly>";
310
311static const char testdep_manifest1[] =
312"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
313"<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"" ARCH "\"/>"
314"</assembly>";
315
316static const char testdep_manifest2[] =
317"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
318"<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"" ARCH "\" />"
319"<file name=\"testlib.dll\"></file>"
320"<file name=\"testlib2.dll\" hash=\"63c978c2b53d6cf72b42fb7308f9af12ab19ec53\" hashalg=\"SHA1\" />"
321"</assembly>";
322
323static const char testdep_manifest3[] =
324"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\"> "
325"<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"" ARCH "\"/>"
326"<file name=\"testlib.dll\"/>"
327"<file name=\"testlib2.dll\" hash=\"63c978c2b53d6cf72b42fb7308f9af12ab19ec53\" hashalg=\"SHA1\">"
328"<windowClass>wndClass</windowClass>"
329"<windowClass>wndClass2</windowClass>"
330"</file>"
331"</assembly>";
332
333static const char wrong_manifest1[] =
334"<assembly manifestVersion=\"1.0\">"
335"<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
336"</assembly>";
337
338static const char wrong_manifest2[] =
339"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\">"
340"<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
341"</assembly>";
342
343static const char wrong_manifest3[] =
344"<assembly test=\"test\" xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
345"<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
346"</assembly>";
347
348static const char wrong_manifest4[] =
349"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
350"<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
351"<test></test>"
352"</assembly>";
353
354static const char wrong_manifest5[] =
355"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
356"<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
357"</assembly>"
358"<test></test>";
359
360static const char wrong_manifest6[] =
361"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v5\" manifestVersion=\"1.0\">"
362"<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
363"</assembly>";
364
365static const char wrong_manifest7[] =
366"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
367"<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"" ARCH "\" />"
368"<file name=\"testlib.dll\" hash=\"63c978c2b53d6cf72b42fb7308f9af12ab19ec5\" hashalg=\"SHA1\" />"
369"</assembly>";
370
371static const char wrong_manifest8[] =
372"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
373"<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
374"<file></file>"
375"</assembly>";
376
377static const char wrong_manifest9[] =
378"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
379"<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
380"<trustInfo xmlns=\"urn:schemas-microsoft-com:asm.v2\">"
381" <security>"
382" <requestedPrivileges>"
383" <requestedExecutionLevel level=\"requireAdministrator\"/>"
384" <requestedExecutionLevel uiAccess=\"true\"/>"
385" </requestedPrivileges>"
386" </security>"
387"</trustInfo>"
388"</assembly>";
389
390static const char wrong_manifest10[] =
391"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
392"<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
393"<trustInfo xmlns=\"urn:schemas-microsoft-com:asm.v2\">"
394" <security>"
395" <requestedPrivileges>"
396" <requestedExecutionLevel level=\"requireAdministrator\"/>"
397" </requestedPrivileges>"
398" </security>"
399"</trustInfo>"
400"<trustInfo xmlns=\"urn:schemas-microsoft-com:asm.v2\">"
401" <security>"
402" <requestedPrivileges>"
403" <requestedExecutionLevel uiAccess=\"true\"/>"
404" </requestedPrivileges>"
405" </security>"
406"</trustInfo>"
407"</assembly>";
408
409/* activatableClass with the wrong xmlns is invalid */
410static const char wrong_manifest11[] =
411"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
412"<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\" />"
413"<file name=\"testlib.dll\">"
414" <activatableClass name=\"Wine.Test.Class1\" threadingModel=\"both\" />"
415"</file>"
416"</assembly>";
417
418static const char wrong_depmanifest1[] =
419"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
420"<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.4\" processorArchitecture=\"" ARCH "\" />"
421"</assembly>";
422
423static const char compat_manifest_no_supportedOs[] =
424"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
425" <assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
426" <compatibility xmlns=\"urn:schemas-microsoft-com:compatibility.v1\">"
427" <application>"
428" </application>"
429" </compatibility>"
430"</assembly>";
431
432static const char compat_manifest_vista[] =
433"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
434" <assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
435" <compatibility xmlns=\"urn:schemas-microsoft-com:compatibility.v1\">"
436" <application>"
437" <supportedOS Id=\"{e2011457-1546-43c5-a5fe-008deee3d3f0}\" />" /* Windows Vista */
438" </application>"
439" </compatibility>"
440"</assembly>";
441
442static const char compat_manifest_vista_7_8_10_81[] =
443"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
444" <assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
445" <compatibility xmlns=\"urn:schemas-microsoft-com:compatibility.v1\">"
446" <application>"
447" <supportedOS Id=\"{e2011457-1546-43c5-a5fe-008deee3d3f0}\" ></supportedOS>" /* Windows Vista */
448" <supportedOS Id=\"{35138b9a-5d96-4fbd-8e2d-a2440225f93a}\" />" /* Windows 7 */
449" <supportedOS Id=\"{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}\" ></supportedOS>" /* Windows 8 */
450" <supportedOS Id=\"{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}\" />" /* Windows 10 */
451" <supportedOS Id=\"{1f676c76-80e1-4239-95bb-83d0f6d0da78}\" />" /* Windows 8.1 */
452" <maxversiontested Id=\"10.0.18358\" />"
453" <maxversiontested Id=\"2.3.4.5\" />"
454" </application>"
455" </compatibility>"
456"</assembly>";
457
458static const char compat_manifest_other_guid[] =
459"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
460" <assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
461" <compatibility xmlns=\"urn:schemas-microsoft-com:compatibility.v1\">"
462" <application>"
463" <supportedOS Id=\"{12345566-1111-2222-3333-444444444444}\" />"
464" </application>"
465" </compatibility>"
466"</assembly>";
467
468static const char settings_manifest[] =
469"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
470" <assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
471" <application xmlns=\"urn:schemas-microsoft-com:asm.v3\">"
472" <windowsSettings>"
473" <dpiAware xmlns=\"http://schemas.microsoft.com/SMI/2005/WindowsSettings\">true</dpiAware>"
474" <dpiAwareness xmlns=\"http://schemas.microsoft.com/SMI/2016/WindowsSettings\">true</dpiAwareness>"
475" </windowsSettings>"
476" </application>"
477"</assembly>";
478
479static const char settings_manifest2[] =
480"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
481" <assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
482" <application xmlns=\"urn:schemas-microsoft-com:asm.v3\""
483" xmlns:ws05=\"http://schemas.microsoft.com/SMI/2005/WindowsSettings\""
484" xmlns:ws11=\"http://schemas.microsoft.com/SMI/2011/WindowsSettings\""
485" xmlns:ws16=\"http://schemas.microsoft.com/SMI/2016/WindowsSettings\""
486" xmlns:ws17=\"http://schemas.microsoft.com/SMI/2017/WindowsSettings\">"
487" <windowsSettings>"
488" <ws05:autoElevate>true</ws05:autoElevate>"
489" <ws05:disableTheming>true</ws05:disableTheming>"
490" <ws11:disableWindowFiltering>true</ws11:disableWindowFiltering>"
491" <ws05:dpiAware>true</ws05:dpiAware>"
492" <ws16:dpiAwareness>true</ws16:dpiAwareness>"
493" <ws17:gdiScaling>true</ws17:gdiScaling>"
494" <ws17:highResolutionScrollingAware>true</ws17:highResolutionScrollingAware>"
495" <ws16:longPathAware>true</ws16:longPathAware>"
496" <ws17:magicFutureSetting>true</ws17:magicFutureSetting>"
497" <ws11:printerDriverIsolation>true</ws11:printerDriverIsolation>"
498" <ws17:ultraHighResolutionScrollingAware>true</ws17:ultraHighResolutionScrollingAware>"
499" </windowsSettings>"
500" </application>"
501"</assembly>";
502
503/* broken manifest found in some binaries: asmv3 namespace is used but not declared */
504static const char settings_manifest3[] =
505"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
506" <assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
507" <asmv3:application>"
508" <asmv3:windowsSettings xmlns=\"http://schemas.microsoft.com/SMI/2005/WindowsSettings\">"
509" <dpiAware>true</dpiAware>"
510" </asmv3:windowsSettings>"
511" </asmv3:application>"
512"</assembly>";
513
514static const char settings_manifest4[] =
515"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
516" <assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
517" <application/>"
518" <application xmlns=\"urn:schemas-microsoft-com:asm.v3\">"
519" <windowsSettings>"
520" <dpiAware xmlns=\"http://schemas.microsoft.com/SMI/2005/WindowsSettings\">true</dpiAware>"
521" </windowsSettings>"
522" </application>"
523" <application/>"
524" <application xmlns=\"urn:schemas-microsoft-com:asm.v3\">"
525" <windowsSettings>"
526" <dpiAwareness xmlns=\"http://schemas.microsoft.com/SMI/2016/WindowsSettings\">true</dpiAwareness>"
527" </windowsSettings>"
528" </application>"
529"</assembly>";
530
531static const char two_dll_manifest_dll[] =
532"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersion=\"1.0\">"
533" <assemblyIdentity type=\"win32\" name=\"sxs_dll\" version=\"1.0.0.0\" processorArchitecture=\"x86\" publicKeyToken=\"0000000000000000\"/>"
534" <file name=\"sxs_dll.dll\"></file>"
535"</assembly>";
536
537static const char two_dll_manifest_exe[] =
538"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
539" <dependency>"
540" <dependentAssembly>"
541" <assemblyIdentity type=\"win32\" name=\"sxs_dll\" version=\"1.0.0.0\" processorArchitecture=\"x86\" publicKeyToken=\"0000000000000000\" language=\"*\"/>"
542" </dependentAssembly>"
543" </dependency>"
544"</assembly>";
545
546static const char builtin_dll_manifest[] =
547"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
548" <dependency>"
549" <dependentAssembly>"
550" <assemblyIdentity"
551" type=\"win32\""
552" name=\"microsoft.vc90.crt\""
553" version=\"9.0.20718.0\""
554" processorArchitecture=\"*\""
555" publicKeyToken=\"1fc8b3b9a1e18e3b\""
556" language=\"*\""
557" />"
558" </dependentAssembly>"
559" </dependency>"
560"</assembly>";
561
562static const char empty_assembly_manifest[] =
563"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\" />";
564
565DEFINE_GUID(VISTA_COMPAT_GUID, 0xe2011457, 0x1546, 0x43c5, 0xa5, 0xfe, 0x00, 0x8d, 0xee, 0xe3, 0xd3, 0xf0);
566DEFINE_GUID(WIN7_COMPAT_GUID, 0x35138b9a, 0x5d96, 0x4fbd, 0x8e, 0x2d, 0xa2, 0x44, 0x02, 0x25, 0xf9, 0x3a);
567DEFINE_GUID(WIN8_COMPAT_GUID, 0x4a2f28e3, 0x53b9, 0x4441, 0xba, 0x9c, 0xd6, 0x9d, 0x4a, 0x4a, 0x6e, 0x38);
568DEFINE_GUID(WIN81_COMPAT_GUID, 0x1f676c76, 0x80e1, 0x4239, 0x95, 0xbb, 0x83, 0xd0, 0xf6, 0xd0, 0xda, 0x78);
569DEFINE_GUID(WIN10_COMPAT_GUID, 0x8e0f7a12, 0xbfb3, 0x4fe8, 0xb9, 0xa5, 0x48, 0xfd, 0x50, 0xa1, 0x5a, 0x9a);
570DEFINE_GUID(OTHER_COMPAT_GUID, 0x12345566, 0x1111, 0x2222, 0x33, 0x33, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44);
571
572
573static const WCHAR testlib_dll[] =
574 {'t','e','s','t','l','i','b','.','d','l','l',0};
575static const WCHAR testlib2_dll[] =
576 {'t','e','s','t','l','i','b','2','.','d','l','l',0};
577static const WCHAR wndClassW[] =
578 {'w','n','d','C','l','a','s','s',0};
579static const WCHAR wndClass1W[] =
580 {'w','n','d','C','l','a','s','s','1',0};
581static const WCHAR wndClass2W[] =
582 {'w','n','d','C','l','a','s','s','2',0};
583static const WCHAR wndClass3W[] =
584 {'w','n','d','C','l','a','s','s','3',0};
585
586static WCHAR app_dir[MAX_PATH], exe_path[MAX_PATH], work_dir[MAX_PATH], work_dir_subdir[MAX_PATH];
587static WCHAR app_manifest_path[MAX_PATH], manifest_path[MAX_PATH], depmanifest_path[MAX_PATH];
588
589static BOOL create_manifest_file(const char *filename, const char *manifest, int manifest_len,
590 const char *depfile, const char *depmanifest)
591{
592 DWORD size;
593 HANDLE file;
594 WCHAR path[MAX_PATH];
595
596 MultiByteToWideChar( CP_ACP, 0, filename, -1, path, MAX_PATH );
597 GetFullPathNameW(path, ARRAY_SIZE(manifest_path), manifest_path, NULL);
598
599 if (manifest_len == -1)
600 manifest_len = strlen(manifest);
601
602 file = CreateFileW(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
603 FILE_ATTRIBUTE_NORMAL, NULL);
604 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %lu\n", GetLastError());
605 if(file == INVALID_HANDLE_VALUE)
606 return FALSE;
607 WriteFile(file, manifest, manifest_len, &size, NULL);
608 CloseHandle(file);
609
610 if (depmanifest)
611 {
612 MultiByteToWideChar( CP_ACP, 0, depfile, -1, path, MAX_PATH );
613 GetFullPathNameW(path, ARRAY_SIZE(depmanifest_path), depmanifest_path, NULL);
614 file = CreateFileW(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
615 FILE_ATTRIBUTE_NORMAL, NULL);
616 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %lu\n", GetLastError());
617 if(file == INVALID_HANDLE_VALUE)
618 return FALSE;
619 WriteFile(file, depmanifest, strlen(depmanifest), &size, NULL);
620 CloseHandle(file);
621 }
622 return TRUE;
623}
624
625static BOOL create_wide_manifest(const char *filename, const char *manifest, BOOL fBOM, BOOL fReverse)
626{
627 WCHAR *wmanifest = HeapAlloc(GetProcessHeap(), 0, (strlen(manifest)+2) * sizeof(WCHAR));
628 BOOL ret;
629 int offset = (fBOM ? 0 : 1);
630
631 MultiByteToWideChar(CP_ACP, 0, manifest, -1, &wmanifest[1], (strlen(manifest)+1));
632 wmanifest[0] = 0xfeff;
633 if (fReverse)
634 {
635 size_t i;
636 for (i = 0; i < strlen(manifest)+1; i++)
637 wmanifest[i] = (wmanifest[i] << 8) | ((wmanifest[i] >> 8) & 0xff);
638 }
639 ret = create_manifest_file(filename, (char *)&wmanifest[offset], (strlen(manifest)+1-offset) * sizeof(WCHAR), NULL, NULL);
640 HeapFree(GetProcessHeap(), 0, wmanifest);
641 return ret;
642}
643
644static HANDLE create_temp_manifest_file(const char *manifest, WCHAR *pathname)
645{
646 WCHAR tmp_path[MAX_PATH];
647 DWORD size, tmp_path_len;
648 HANDLE file, file_w;
649 UINT unique;
650
651 tmp_path_len = GetTempPathW(ARRAY_SIZE(tmp_path), tmp_path);
652 ok(tmp_path_len != 0, "GetTempPathW returned error %lu\n", GetLastError());
653 ok(tmp_path_len < ARRAY_SIZE(tmp_path), "GetTempPathW return value %lu should be less than %Iu\n",
654 tmp_path_len, ARRAY_SIZE(tmp_path));
655
656 memset(pathname, 0, MAX_PATH * sizeof(WCHAR));
657 unique = GetTempFileNameW(tmp_path, L"tst", 0, pathname);
658 ok(unique != 0, "GetTempFileNameW returned error %lu\n", GetLastError());
659
660 /* Open file handle that will be deleted on close or process termination */
661 file = CreateFileW(pathname,
662 GENERIC_READ | DELETE,
663 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
664 NULL,
665 CREATE_ALWAYS,
666 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE,
667 NULL);
668 ok(file != INVALID_HANDLE_VALUE, "CreateFile returned error %lu\n", GetLastError());
669
670 /* Re-open file with write access */
671 file_w = CreateFileW(pathname,
672 GENERIC_WRITE,
673 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
674 NULL,
675 TRUNCATE_EXISTING,
676 FILE_ATTRIBUTE_NORMAL,
677 NULL);
678 ok(file_w != INVALID_HANDLE_VALUE, "CreateFile returned error %lu\n", GetLastError());
679
680 WriteFile(file_w, manifest, strlen(manifest), &size, NULL);
681
682 /* Close file handle that was open for write to avoid sharing violation */
683 CloseHandle(file_w);
684
685 return file;
686}
687
688typedef struct {
689 ULONG format_version;
690 ULONG assembly_cnt_min;
691 ULONG assembly_cnt_max;
692 ULONG root_manifest_type;
693 LPWSTR root_manifest_path;
694 ULONG root_config_type;
695 ULONG app_dir_type;
696 LPCWSTR app_dir;
697} detailed_info_t;
698
699static const detailed_info_t detailed_info0 = {
700 0, 0, 0, 0, NULL, 0, 0, NULL
701};
702
703static const detailed_info_t detailed_info1 = {
704 1, 1, 1, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE, manifest_path,
705 ACTIVATION_CONTEXT_PATH_TYPE_NONE, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE,
706 app_dir,
707};
708
709static const detailed_info_t detailed_info1_child = {
710 1, 1, 1, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE, app_manifest_path,
711 ACTIVATION_CONTEXT_PATH_TYPE_NONE, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE,
712 app_dir,
713};
714
715/* On Vista+, there's an extra assembly for Microsoft.Windows.Common-Controls.Resources */
716static const detailed_info_t detailed_info2 = {
717 1, 2, 3, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE, manifest_path,
718 ACTIVATION_CONTEXT_PATH_TYPE_NONE, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE,
719 app_dir,
720};
721
722static void test_detailed_info(HANDLE handle, const detailed_info_t *exinfo, int line)
723{
724 ACTIVATION_CONTEXT_DETAILED_INFORMATION detailed_info_tmp, *detailed_info;
725 SIZE_T size, exsize, retsize;
726 BOOL b;
727
728 exsize = sizeof(ACTIVATION_CONTEXT_DETAILED_INFORMATION)
729 + (exinfo->root_manifest_path ? (lstrlenW(exinfo->root_manifest_path)+1)*sizeof(WCHAR):0)
730 + (exinfo->app_dir ? (lstrlenW(exinfo->app_dir)+1)*sizeof(WCHAR) : 0);
731
732 if(exsize != sizeof(ACTIVATION_CONTEXT_DETAILED_INFORMATION)) {
733 size = 0xdeadbeef;
734 b = QueryActCtxW(0, handle, NULL, ActivationContextDetailedInformation, &detailed_info_tmp,
735 sizeof(detailed_info_tmp), &size);
736 ok_(__FILE__, line)(!b, "QueryActCtx succeeded\n");
737 ok_(__FILE__, line)(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetLastError() = %lu\n", GetLastError());
738 ok_(__FILE__, line)(size == exsize, "size=%Id, expected %Id\n", size, exsize);
739 }else {
740 size = sizeof(ACTIVATION_CONTEXT_DETAILED_INFORMATION);
741 }
742
743 detailed_info = HeapAlloc(GetProcessHeap(), 0, size);
744 memset(detailed_info, 0xfe, size);
745 b = QueryActCtxW(0, handle, NULL, ActivationContextDetailedInformation, detailed_info, size, &retsize);
746 ok_(__FILE__, line)(b, "QueryActCtx failed: %lu\n", GetLastError());
747 ok_(__FILE__, line)(retsize == exsize, "size=%Id, expected %Id\n", retsize, exsize);
748
749 ok_(__FILE__, line)(detailed_info->dwFlags == 0, "detailed_info->dwFlags=%lx\n", detailed_info->dwFlags);
750 ok_(__FILE__, line)(detailed_info->ulFormatVersion == exinfo->format_version,
751 "detailed_info->ulFormatVersion=%lu, expected %lu\n", detailed_info->ulFormatVersion,
752 exinfo->format_version);
753 ok_(__FILE__, line)(exinfo->assembly_cnt_min <= detailed_info->ulAssemblyCount &&
754 detailed_info->ulAssemblyCount <= exinfo->assembly_cnt_max,
755 "detailed_info->ulAssemblyCount=%lu, expected between %lu and %lu\n", detailed_info->ulAssemblyCount,
756 exinfo->assembly_cnt_min, exinfo->assembly_cnt_max);
757 ok_(__FILE__, line)(detailed_info->ulRootManifestPathType == exinfo->root_manifest_type,
758 "detailed_info->ulRootManifestPathType=%lu, expected %lu\n",
759 detailed_info->ulRootManifestPathType, exinfo->root_manifest_type);
760 ok_(__FILE__, line)(detailed_info->ulRootManifestPathChars ==
761 (exinfo->root_manifest_path ? lstrlenW(exinfo->root_manifest_path) : 0),
762 "detailed_info->ulRootManifestPathChars=%lu, expected %u\n",
763 detailed_info->ulRootManifestPathChars,
764 exinfo->root_manifest_path ?lstrlenW(exinfo->root_manifest_path) : 0);
765 ok_(__FILE__, line)(detailed_info->ulRootConfigurationPathType == exinfo->root_config_type,
766 "detailed_info->ulRootConfigurationPathType=%lu, expected %lu\n",
767 detailed_info->ulRootConfigurationPathType, exinfo->root_config_type);
768 ok_(__FILE__, line)(detailed_info->ulRootConfigurationPathChars == 0,
769 "detailed_info->ulRootConfigurationPathChars=%ld\n", detailed_info->ulRootConfigurationPathChars);
770 ok_(__FILE__, line)(detailed_info->ulAppDirPathType == exinfo->app_dir_type,
771 "detailed_info->ulAppDirPathType=%lu, expected %lu\n", detailed_info->ulAppDirPathType,
772 exinfo->app_dir_type);
773 ok_(__FILE__, line)(detailed_info->ulAppDirPathChars == (exinfo->app_dir ? lstrlenW(exinfo->app_dir) : 0),
774 "detailed_info->ulAppDirPathChars=%lu, expected %u\n",
775 detailed_info->ulAppDirPathChars, exinfo->app_dir ? lstrlenW(exinfo->app_dir) : 0);
776 if(exinfo->root_manifest_path) {
777 ok_(__FILE__, line)(detailed_info->lpRootManifestPath != NULL, "detailed_info->lpRootManifestPath == NULL\n");
778 if(detailed_info->lpRootManifestPath)
779 ok_(__FILE__, line)(!lstrcmpiW(detailed_info->lpRootManifestPath, exinfo->root_manifest_path),
780 "unexpected detailed_info->lpRootManifestPath %s\n", wine_dbgstr_w(detailed_info->lpRootManifestPath));
781 }else {
782 ok_(__FILE__, line)(detailed_info->lpRootManifestPath == NULL, "detailed_info->lpRootManifestPath != NULL\n");
783 }
784 ok_(__FILE__, line)(detailed_info->lpRootConfigurationPath == NULL,
785 "detailed_info->lpRootConfigurationPath=%p\n", detailed_info->lpRootConfigurationPath);
786 if(exinfo->app_dir) {
787 ok_(__FILE__, line)(detailed_info->lpAppDirPath != NULL, "detailed_info->lpAppDirPath == NULL\n");
788 if(detailed_info->lpAppDirPath)
789 ok_(__FILE__, line)(!lstrcmpiW(exinfo->app_dir, detailed_info->lpAppDirPath),
790 "unexpected detailed_info->lpAppDirPath %s / %s\n",
791 wine_dbgstr_w(detailed_info->lpAppDirPath), wine_dbgstr_w( exinfo->app_dir ));
792 }else {
793 ok_(__FILE__, line)(detailed_info->lpAppDirPath == NULL, "detailed_info->lpAppDirPath != NULL\n");
794 }
795
796 HeapFree(GetProcessHeap(), 0, detailed_info);
797}
798
799typedef struct {
800 ULONG flags;
801/* ULONG manifest_path_type; FIXME */
802 LPCWSTR manifest_path;
803 LPCWSTR encoded_assembly_id;
804 BOOL has_assembly_dir;
805} info_in_assembly;
806
807static const info_in_assembly manifest1_info = {
808 1, manifest_path,
809 L"Wine.Test,type=\"win32\",version=\"1.0.0.0\"",
810 FALSE
811};
812
813static const info_in_assembly manifest1_child_info = {
814 1, app_manifest_path,
815 L"Wine.Test,type=\"win32\",version=\"1.0.0.0\"",
816 FALSE
817};
818
819static const info_in_assembly manifest2_info = {
820 1, manifest_path,
821 L"Wine.Test,type=\"win32\",version=\"1.2.3.4\"",
822 FALSE
823};
824
825static const info_in_assembly manifest3_info = {
826 1, manifest_path,
827 L"Wine.Test,publicKeyToken=\"6595b6414666f1df\",type=\"win32\",version=\"1.2.3.4\"",
828 FALSE
829};
830
831static const info_in_assembly manifest4_info = {
832 1, manifest_path,
833 L"Wine.Test,type=\"win32\",version=\"1.2.3.4\"",
834 FALSE
835};
836
837static const info_in_assembly depmanifest1_info = {
838 0x10, depmanifest_path,
839 L"testdep,processorArchitecture=\"" ARCH "\","
840 "type=\"win32\",version=\"6.5.4.3\"",
841 TRUE
842};
843
844static const info_in_assembly depmanifest2_info = {
845 0x10, depmanifest_path,
846 L"testdep,processorArchitecture=\"" ARCH "\","
847 "type=\"win32\",version=\"6.5.4.3\"",
848 TRUE
849};
850
851static const info_in_assembly depmanifest3_info = {
852 0x10, depmanifest_path,
853 L"testdep,processorArchitecture=\"" ARCH "\",type=\"win32\",version=\"6.5.4.3\"",
854 TRUE
855};
856
857static const info_in_assembly manifest_comctrl_info = {
858 0, NULL, NULL, TRUE /* These values may differ between Windows installations */
859};
860
861static void test_info_in_assembly(HANDLE handle, DWORD id, const info_in_assembly *exinfo, int line)
862{
863 ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION *info, info_tmp;
864 SIZE_T size, exsize;
865 ULONG len;
866 BOOL b;
867
868 exsize = sizeof(ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION);
869 if (exinfo->manifest_path) exsize += (lstrlenW(exinfo->manifest_path)+1) * sizeof(WCHAR);
870 if (exinfo->encoded_assembly_id) exsize += (lstrlenW(exinfo->encoded_assembly_id) + 1) * sizeof(WCHAR);
871
872 size = 0xdeadbeef;
873 b = QueryActCtxW(0, handle, &id, AssemblyDetailedInformationInActivationContext, &info_tmp, sizeof(info_tmp), &size);
874 ok_(__FILE__, line)(!b, "QueryActCtx succeeded\n");
875 ok_(__FILE__, line)(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetLastError() = %lu\n", GetLastError());
876
877 ok_(__FILE__, line)(size >= exsize, "size=%Iu, expected %Iu\n", size, exsize);
878
879 if (size == 0xdeadbeef)
880 {
881 skip("bad size\n");
882 return;
883 }
884
885 info = HeapAlloc(GetProcessHeap(), 0, size);
886 memset(info, 0xfe, size);
887
888 size = 0xdeadbeef;
889 b = QueryActCtxW(0, handle, &id, AssemblyDetailedInformationInActivationContext, info, size, &size);
890 ok_(__FILE__, line)(b, "QueryActCtx failed: %lu\n", GetLastError());
891 if (!exinfo->manifest_path)
892 exsize += info->ulManifestPathLength + sizeof(WCHAR);
893 if (!exinfo->encoded_assembly_id)
894 exsize += info->ulEncodedAssemblyIdentityLength + sizeof(WCHAR);
895 if (exinfo->has_assembly_dir)
896 exsize += info->ulAssemblyDirectoryNameLength + sizeof(WCHAR);
897 ok_(__FILE__, line)(size == exsize, "size=%Iu, expected %Iu\n", size, exsize);
898
899 if (0) /* FIXME: flags meaning unknown */
900 {
901 ok_(__FILE__, line)((info->ulFlags) == exinfo->flags, "info->ulFlags = %lx, expected %lx\n",
902 info->ulFlags, exinfo->flags);
903 }
904 if(exinfo->encoded_assembly_id) {
905 len = lstrlenW(exinfo->encoded_assembly_id)*sizeof(WCHAR);
906 ok_(__FILE__, line)(info->ulEncodedAssemblyIdentityLength == len,
907 "info->ulEncodedAssemblyIdentityLength = %lu, expected %lu\n",
908 info->ulEncodedAssemblyIdentityLength, len);
909 } else {
910 ok_(__FILE__, line)(info->ulEncodedAssemblyIdentityLength != 0,
911 "info->ulEncodedAssemblyIdentityLength == 0\n");
912 }
913 ok_(__FILE__, line)(info->ulManifestPathType == ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE,
914 "info->ulManifestPathType = %lx\n", info->ulManifestPathType);
915 if(exinfo->manifest_path) {
916 len = lstrlenW(exinfo->manifest_path)*sizeof(WCHAR);
917 ok_(__FILE__, line)(info->ulManifestPathLength == len, "info->ulManifestPathLength = %lu, expected %lu\n",
918 info->ulManifestPathLength, len);
919 } else {
920 ok_(__FILE__, line)(info->ulManifestPathLength != 0, "info->ulManifestPathLength == 0\n");
921 }
922
923 ok_(__FILE__, line)(info->ulPolicyPathType == ACTIVATION_CONTEXT_PATH_TYPE_NONE,
924 "info->ulPolicyPathType = %lx\n", info->ulPolicyPathType);
925 ok_(__FILE__, line)(info->ulPolicyPathLength == 0,
926 "info->ulPolicyPathLength = %lu, expected 0\n", info->ulPolicyPathLength);
927 ok_(__FILE__, line)(info->ulMetadataSatelliteRosterIndex == 0, "info->ulMetadataSatelliteRosterIndex = %lx\n",
928 info->ulMetadataSatelliteRosterIndex);
929 ok_(__FILE__, line)(info->ulManifestVersionMajor == 1,"info->ulManifestVersionMajor = %lx\n",
930 info->ulManifestVersionMajor);
931 ok_(__FILE__, line)(info->ulManifestVersionMinor == 0, "info->ulManifestVersionMinor = %lx\n",
932 info->ulManifestVersionMinor);
933 ok_(__FILE__, line)(info->ulPolicyVersionMajor == 0, "info->ulPolicyVersionMajor = %lx\n",
934 info->ulPolicyVersionMajor);
935 ok_(__FILE__, line)(info->ulPolicyVersionMinor == 0, "info->ulPolicyVersionMinor = %lx\n",
936 info->ulPolicyVersionMinor);
937 if(exinfo->has_assembly_dir)
938 ok_(__FILE__, line)(info->ulAssemblyDirectoryNameLength != 0,
939 "info->ulAssemblyDirectoryNameLength == 0\n");
940 else
941 ok_(__FILE__, line)(info->ulAssemblyDirectoryNameLength == 0,
942 "info->ulAssemblyDirectoryNameLength != 0\n");
943
944 ok_(__FILE__, line)(info->lpAssemblyEncodedAssemblyIdentity != NULL,
945 "info->lpAssemblyEncodedAssemblyIdentity == NULL\n");
946 if(info->lpAssemblyEncodedAssemblyIdentity && exinfo->encoded_assembly_id) {
947 ok_(__FILE__, line)(!lstrcmpW(info->lpAssemblyEncodedAssemblyIdentity, exinfo->encoded_assembly_id),
948 "unexpected info->lpAssemblyEncodedAssemblyIdentity %s / %s\n",
949 wine_dbgstr_w(info->lpAssemblyEncodedAssemblyIdentity), wine_dbgstr_w(exinfo->encoded_assembly_id));
950 }
951 if(exinfo->manifest_path) {
952 ok_(__FILE__, line)(info->lpAssemblyManifestPath != NULL, "info->lpAssemblyManifestPath == NULL\n");
953 if(info->lpAssemblyManifestPath)
954 ok_(__FILE__, line)(!lstrcmpiW(info->lpAssemblyManifestPath, exinfo->manifest_path),
955 "unexpected info->lpAssemblyManifestPath\n");
956 }else {
957 ok_(__FILE__, line)(info->lpAssemblyManifestPath != NULL, "info->lpAssemblyManifestPath == NULL\n");
958 }
959
960 ok_(__FILE__, line)(info->lpAssemblyPolicyPath == NULL, "info->lpAssemblyPolicyPath != NULL\n");
961 if(info->lpAssemblyPolicyPath)
962 ok_(__FILE__, line)(*(WORD*)info->lpAssemblyPolicyPath == 0, "info->lpAssemblyPolicyPath is not empty\n");
963 if(exinfo->has_assembly_dir)
964 ok_(__FILE__, line)(info->lpAssemblyDirectoryName != NULL, "info->lpAssemblyDirectoryName == NULL\n");
965 else
966 ok_(__FILE__, line)(info->lpAssemblyDirectoryName == NULL, "info->lpAssemblyDirectoryName = %s\n",
967 wine_dbgstr_w(info->lpAssemblyDirectoryName));
968 HeapFree(GetProcessHeap(), 0, info);
969}
970
971static void test_file_info(HANDLE handle, ULONG assid, ULONG fileid, LPCWSTR filename, int line)
972{
973 ASSEMBLY_FILE_DETAILED_INFORMATION *info, info_tmp;
974 ACTIVATION_CONTEXT_QUERY_INDEX index = {assid, fileid};
975 SIZE_T size, exsize;
976 BOOL b;
977
978 exsize = sizeof(ASSEMBLY_FILE_DETAILED_INFORMATION)
979 +(lstrlenW(filename)+1)*sizeof(WCHAR);
980
981 size = 0xdeadbeef;
982 b = QueryActCtxW(0, handle, &index, FileInformationInAssemblyOfAssemblyInActivationContext, &info_tmp,
983 sizeof(info_tmp), &size);
984 ok_(__FILE__, line)(!b, "QueryActCtx succeeded\n");
985 ok_(__FILE__, line)(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetLastError() = %lu\n", GetLastError());
986 ok_(__FILE__, line)(size == exsize, "size=%Iu, expected %Iu\n", size, exsize);
987
988 if(size == 0xdeadbeef)
989 {
990 skip("bad size\n");
991 return;
992 }
993
994 info = HeapAlloc(GetProcessHeap(), 0, size);
995 memset(info, 0xfe, size);
996
997 b = QueryActCtxW(0, handle, &index, FileInformationInAssemblyOfAssemblyInActivationContext, info, size, &size);
998 ok_(__FILE__, line)(b, "QueryActCtx failed: %lu\n", GetLastError());
999 ok_(__FILE__, line)(!size, "size=%Iu, expected 0\n", size);
1000
1001 ok_(__FILE__, line)(info->ulFlags == 2, "info->ulFlags=%lx, expected 2\n", info->ulFlags);
1002 ok_(__FILE__, line)(info->ulFilenameLength == lstrlenW(filename)*sizeof(WCHAR),
1003 "info->ulFilenameLength=%lu, expected %u*sizeof(WCHAR)\n",
1004 info->ulFilenameLength, lstrlenW(filename));
1005 ok_(__FILE__, line)(info->ulPathLength == 0, "info->ulPathLength=%lu\n", info->ulPathLength);
1006 ok_(__FILE__, line)(info->lpFileName != NULL, "info->lpFileName == NULL\n");
1007 if(info->lpFileName)
1008 ok_(__FILE__, line)(!lstrcmpiW(info->lpFileName, filename), "unexpected info->lpFileName\n");
1009 ok_(__FILE__, line)(info->lpFilePath == NULL, "info->lpFilePath != NULL\n");
1010 HeapFree(GetProcessHeap(), 0, info);
1011}
1012
1013typedef struct {
1014 ACTCTX_REQUESTED_RUN_LEVEL run_level;
1015 DWORD ui_access;
1016} runlevel_info_t;
1017
1018static const runlevel_info_t runlevel_info0 = {
1019 ACTCTX_RUN_LEVEL_UNSPECIFIED, FALSE,
1020};
1021
1022static const runlevel_info_t runlevel_info6 = {
1023 ACTCTX_RUN_LEVEL_AS_INVOKER, FALSE,
1024};
1025
1026static const runlevel_info_t runlevel_info7 = {
1027 ACTCTX_RUN_LEVEL_REQUIRE_ADMIN, TRUE,
1028};
1029
1030static const runlevel_info_t runlevel_info8 = {
1031 ACTCTX_RUN_LEVEL_REQUIRE_ADMIN, TRUE,
1032};
1033
1034static const runlevel_info_t runlevel_info9 = {
1035 ACTCTX_RUN_LEVEL_REQUIRE_ADMIN, FALSE,
1036};
1037
1038static void test_runlevel_info(HANDLE handle, const runlevel_info_t *exinfo, int line)
1039{
1040 ACTIVATION_CONTEXT_RUN_LEVEL_INFORMATION runlevel_info;
1041 SIZE_T size, retsize;
1042 BOOL b;
1043
1044 size = sizeof(runlevel_info);
1045 b = QueryActCtxW(0, handle, NULL, RunlevelInformationInActivationContext, &runlevel_info,
1046 sizeof(runlevel_info), &retsize);
1047 if (!b && GetLastError() == ERROR_INVALID_PARAMETER)
1048 {
1049 win_skip("RunlevelInformationInActivationContext not supported.\n");
1050 return;
1051 }
1052
1053 ok_(__FILE__, line)(b, "QueryActCtx failed: %lu\n", GetLastError());
1054 ok_(__FILE__, line)(retsize == size, "size=%Id, expected %Id\n", retsize, size);
1055
1056 ok_(__FILE__, line)(runlevel_info.ulFlags == 0, "runlevel_info.ulFlags=%lx\n", runlevel_info.ulFlags);
1057 ok_(__FILE__, line)(runlevel_info.RunLevel == exinfo->run_level,
1058 "runlevel_info.RunLevel=%u, expected %u\n", runlevel_info.RunLevel, exinfo->run_level);
1059 ok_(__FILE__, line)(runlevel_info.UiAccess == exinfo->ui_access,
1060 "runlevel_info.UiAccess=%lu, expected %lu\n", runlevel_info.UiAccess, exinfo->ui_access);
1061}
1062
1063static HANDLE test_create(const char *file)
1064{
1065 ACTCTXW actctx;
1066 HANDLE handle;
1067 WCHAR path[MAX_PATH];
1068
1069 MultiByteToWideChar( CP_ACP, 0, file, -1, path, MAX_PATH );
1070 memset(&actctx, 0, sizeof(ACTCTXW));
1071 actctx.cbSize = sizeof(ACTCTXW);
1072 actctx.lpSource = path;
1073
1074 handle = CreateActCtxW(&actctx);
1075 /* to be tested outside of this helper, including last error */
1076 if (handle == INVALID_HANDLE_VALUE) return handle;
1077
1078 ok(actctx.cbSize == sizeof(actctx), "actctx.cbSize=%ld\n", actctx.cbSize);
1079 ok(actctx.dwFlags == 0, "actctx.dwFlags=%ld\n", actctx.dwFlags);
1080 ok(actctx.lpSource == path, "actctx.lpSource=%p\n", actctx.lpSource);
1081 ok(actctx.wProcessorArchitecture == 0,
1082 "actctx.wProcessorArchitecture=%d\n", actctx.wProcessorArchitecture);
1083 ok(actctx.wLangId == 0, "actctx.wLangId=%d\n", actctx.wLangId);
1084 ok(actctx.lpAssemblyDirectory == NULL,
1085 "actctx.lpAssemblyDirectory=%p\n", actctx.lpAssemblyDirectory);
1086 ok(actctx.lpResourceName == NULL, "actctx.lpResourceName=%p\n", actctx.lpResourceName);
1087 ok(actctx.lpApplicationName == NULL, "actctx.lpApplicationName=%p\n",
1088 actctx.lpApplicationName);
1089 ok(actctx.hModule == NULL, "actctx.hModule=%p\n", actctx.hModule);
1090
1091 return handle;
1092}
1093
1094static void test_create_and_fail(const char *manifest, const char *depmanifest, int todo, BOOL is_broken)
1095{
1096 ACTCTXW actctx;
1097 HANDLE handle;
1098 WCHAR path[MAX_PATH];
1099
1100 MultiByteToWideChar( CP_ACP, 0, "bad.manifest", -1, path, MAX_PATH );
1101 memset(&actctx, 0, sizeof(ACTCTXW));
1102 actctx.cbSize = sizeof(ACTCTXW);
1103 actctx.lpSource = path;
1104
1105 create_manifest_file("bad.manifest", manifest, -1, "testdep.manifest", depmanifest);
1106 handle = CreateActCtxW(&actctx);
1107 todo_wine_if(todo)
1108 {
1109 if (is_broken)
1110 ok(broken(handle != INVALID_HANDLE_VALUE) || handle == INVALID_HANDLE_VALUE,
1111 "Unexpected context handle %p.\n", handle);
1112 else
1113 ok(handle == INVALID_HANDLE_VALUE, "Unexpected context handle %p.\n", handle);
1114
1115 if (handle == INVALID_HANDLE_VALUE)
1116 ok(GetLastError() == ERROR_SXS_CANT_GEN_ACTCTX, "Unexpected error %ld.\n", GetLastError());
1117 }
1118 if (handle != INVALID_HANDLE_VALUE) ReleaseActCtx( handle );
1119 DeleteFileA("bad.manifest");
1120 DeleteFileA("testdep.manifest");
1121}
1122
1123static void test_create_wide_and_fail(const char *manifest, BOOL fBOM)
1124{
1125 ACTCTXW actctx;
1126 HANDLE handle;
1127 WCHAR path[MAX_PATH];
1128
1129 MultiByteToWideChar( CP_ACP, 0, "bad.manifest", -1, path, MAX_PATH );
1130 memset(&actctx, 0, sizeof(ACTCTXW));
1131 actctx.cbSize = sizeof(ACTCTXW);
1132 actctx.lpSource = path;
1133
1134 create_wide_manifest("bad.manifest", manifest, fBOM, FALSE);
1135 handle = CreateActCtxW(&actctx);
1136 ok(handle == INVALID_HANDLE_VALUE, "handle != INVALID_HANDLE_VALUE\n");
1137 ok(GetLastError() == ERROR_SXS_CANT_GEN_ACTCTX, "GetLastError == %lu\n", GetLastError());
1138
1139 if (handle != INVALID_HANDLE_VALUE) ReleaseActCtx( handle );
1140 DeleteFileA("bad.manifest");
1141}
1142
1143static void test_create_fail(void)
1144{
1145 ACTCTXW actctx;
1146 HANDLE handle;
1147 WCHAR path[MAX_PATH];
1148
1149 MultiByteToWideChar( CP_ACP, 0, "nonexistent.manifest", -1, path, MAX_PATH );
1150 memset(&actctx, 0, sizeof(ACTCTXW));
1151 actctx.cbSize = sizeof(ACTCTXW);
1152 actctx.lpSource = path;
1153
1154 handle = CreateActCtxW(&actctx);
1155 ok(handle == INVALID_HANDLE_VALUE, "handle != INVALID_HANDLE_VALUE\n");
1156 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "GetLastError == %lu\n", GetLastError());
1157
1158 trace("wrong_manifest1\n");
1159 test_create_and_fail(wrong_manifest1, NULL, 0, FALSE);
1160 trace("wrong_manifest2\n");
1161 test_create_and_fail(wrong_manifest2, NULL, 0, FALSE);
1162 trace("wrong_manifest3\n");
1163 test_create_and_fail(wrong_manifest3, NULL, 1, FALSE);
1164 trace("wrong_manifest4\n");
1165 test_create_and_fail(wrong_manifest4, NULL, 1, FALSE);
1166 trace("wrong_manifest5\n");
1167 test_create_and_fail(wrong_manifest5, NULL, 0, FALSE);
1168 trace("wrong_manifest6\n");
1169 test_create_and_fail(wrong_manifest6, NULL, 0, FALSE);
1170 trace("wrong_manifest7\n");
1171 test_create_and_fail(wrong_manifest7, NULL, 1, FALSE);
1172 trace("wrong_manifest8\n");
1173 test_create_and_fail(wrong_manifest8, NULL, 0, FALSE);
1174 trace("wrong_manifest9\n");
1175 test_create_and_fail(wrong_manifest9, NULL, 0, TRUE /* WinXP */);
1176 trace("wrong_manifest10\n");
1177 test_create_and_fail(wrong_manifest10, NULL, 0, TRUE /* WinXP */);
1178 trace("wrong_manifest11\n");
1179 test_create_and_fail(wrong_manifest11, NULL, 1, TRUE /* w1064v1909 */);
1180 trace("UTF-16 manifest1 without BOM\n");
1181 test_create_wide_and_fail(manifest1, FALSE );
1182 trace("manifest2\n");
1183 test_create_and_fail(manifest2, NULL, 0, FALSE);
1184 trace("manifest2+depmanifest1\n");
1185 test_create_and_fail(manifest2, wrong_depmanifest1, 0, FALSE);
1186}
1187
1188struct strsection_header
1189{
1190 DWORD magic;
1191 ULONG size;
1192 DWORD unk1[3];
1193 ULONG count;
1194 ULONG index_offset;
1195 DWORD unk2[2];
1196 ULONG global_offset;
1197 ULONG global_len;
1198};
1199
1200struct string_index
1201{
1202 ULONG hash;
1203 ULONG name_offset;
1204 ULONG name_len;
1205 ULONG data_offset;
1206 ULONG data_len;
1207 ULONG rosterindex;
1208};
1209
1210struct guidsection_header
1211{
1212 DWORD magic;
1213 ULONG size;
1214 DWORD unk[3];
1215 ULONG count;
1216 ULONG index_offset;
1217 DWORD unk2;
1218 ULONG names_offset;
1219 ULONG names_len;
1220};
1221
1222struct guid_index
1223{
1224 GUID guid;
1225 ULONG data_offset;
1226 ULONG data_len;
1227 ULONG rosterindex;
1228};
1229
1230struct wndclass_redirect_data
1231{
1232 ULONG size;
1233 DWORD res;
1234 ULONG name_len;
1235 ULONG name_offset; /* versioned name offset */
1236 ULONG module_len;
1237 ULONG module_offset;/* container name offset */
1238};
1239
1240struct dllredirect_data_path
1241{
1242 ULONG len;
1243 ULONG offset;
1244};
1245
1246struct dllredirect_data
1247{
1248 ULONG size;
1249 ULONG flags;
1250 ULONG total_len;
1251 ULONG paths_count;
1252 ULONG paths_offset;
1253 struct dllredirect_data_path paths[1];
1254};
1255
1256#define DLL_REDIRECT_PATH_INCLUDES_BASE_NAME 1
1257#define DLL_REDIRECT_PATH_OMITS_ASSEMBLY_ROOT 2
1258#define DLL_REDIRECT_PATH_EXPAND 4
1259#define DLL_REDIRECT_PATH_SYSTEM_DEFAULT_REDIRECTED_SYSTEM32_DLL 8
1260
1261struct tlibredirect_data
1262{
1263 ULONG size;
1264 DWORD res;
1265 ULONG name_len;
1266 ULONG name_offset;
1267 LANGID langid;
1268 WORD flags;
1269 ULONG help_len;
1270 ULONG help_offset;
1271 WORD major_version;
1272 WORD minor_version;
1273};
1274
1275struct progidredirect_data
1276{
1277 ULONG size;
1278 DWORD reserved;
1279 ULONG clsid_offset;
1280};
1281
1282static void test_find_dll_redirection(HANDLE handle, LPCWSTR libname, ULONG exid, int line)
1283{
1284 ACTCTX_SECTION_KEYED_DATA data;
1285 BOOL ret;
1286
1287 memset(&data, 0xfe, sizeof(data));
1288 data.cbSize = sizeof(data);
1289
1290 ret = FindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION, libname, &data);
1291 ok_(__FILE__, line)(ret, "FindActCtxSectionStringW failed: %lu\n", GetLastError());
1292 if (!ret) return;
1293
1294 ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%lu\n", data.cbSize);
1295 ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%lu\n", data.ulDataFormatVersion);
1296 ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
1297 ok_(__FILE__, line)(data.ulLength == offsetof( struct dllredirect_data, paths[0]), "data.ulLength=%lu\n", data.ulLength);
1298
1299 if (data.lpData)
1300 {
1301 struct dllredirect_data *dlldata = (struct dllredirect_data*)data.lpData;
1302 ok_(__FILE__, line)(dlldata->size == offsetof( struct dllredirect_data, paths[dlldata->paths_count]),
1303 "got wrong size %ld\n", dlldata->size);
1304 ok_(__FILE__, line)(dlldata->flags == DLL_REDIRECT_PATH_OMITS_ASSEMBLY_ROOT,
1305 "got wrong flags value %lx\n", dlldata->flags);
1306 ok_(__FILE__, line)(dlldata->total_len == 0, "got wrong total len value %ld\n", dlldata->total_len);
1307 ok_(__FILE__, line)(dlldata->paths_count == 0, "got wrong paths count value %ld\n", dlldata->paths_count);
1308 ok_(__FILE__, line)(dlldata->paths_offset == 0, "got wrong paths offset value %ld\n", dlldata->paths_offset);
1309 }
1310
1311 ok_(__FILE__, line)(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
1312 ok_(__FILE__, line)(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%lu\n",
1313 data.ulSectionGlobalDataLength);
1314 ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
1315 ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%lu\n",
1316 data.ulSectionTotalLength);
1317 ok_(__FILE__, line)(data.hActCtx == NULL, "data.hActCtx=%p\n", data.hActCtx);
1318 ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%lu, expected %lu\n",
1319 data.ulAssemblyRosterIndex, exid);
1320
1321 memset(&data, 0xfe, sizeof(data));
1322 data.cbSize = sizeof(data);
1323
1324 ret = FindActCtxSectionStringW(FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX, NULL,
1325 ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION, libname, &data);
1326 ok_(__FILE__, line)(ret, "FindActCtxSectionStringW failed: %lu\n", GetLastError());
1327 if (!ret) return;
1328
1329 ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%lu\n", data.cbSize);
1330 ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%lu\n", data.ulDataFormatVersion);
1331 ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
1332 ok_(__FILE__, line)(data.ulLength == 20, "data.ulLength=%lu\n", data.ulLength);
1333 ok_(__FILE__, line)(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
1334 ok_(__FILE__, line)(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%lu\n",
1335 data.ulSectionGlobalDataLength);
1336 ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
1337 ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%lu\n",
1338 data.ulSectionTotalLength);
1339 ok_(__FILE__, line)(data.hActCtx == handle, "data.hActCtx=%p\n", data.hActCtx);
1340 ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%lu, expected %lu\n",
1341 data.ulAssemblyRosterIndex, exid);
1342
1343 ReleaseActCtx(handle);
1344}
1345
1346static void test_find_window_class(HANDLE handle, LPCWSTR clsname, ULONG exid, int line)
1347{
1348 struct wndclass_redirect_data *wnddata;
1349 struct strsection_header *header;
1350 ACTCTX_SECTION_KEYED_DATA data;
1351 BOOL ret;
1352
1353 memset(&data, 0xfe, sizeof(data));
1354 data.cbSize = sizeof(data);
1355
1356 ret = FindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION, clsname, &data);
1357 ok_(__FILE__, line)(ret, "FindActCtxSectionStringW failed: %lu, class %s\n", GetLastError(),
1358 wine_dbgstr_w(clsname));
1359 if (!ret) return;
1360
1361 header = (struct strsection_header*)data.lpSectionBase;
1362 wnddata = (struct wndclass_redirect_data*)data.lpData;
1363
1364 ok_(__FILE__, line)(header->magic == 0x64487353, "got wrong magic 0x%08lx\n", header->magic);
1365 ok_(__FILE__, line)(header->count > 0, "got count %ld\n", header->count);
1366 ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%lu\n", data.cbSize);
1367 ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%lu\n", data.ulDataFormatVersion);
1368 ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
1369 ok_(__FILE__, line)(wnddata->size == sizeof(*wnddata), "got %ld for header size\n", wnddata->size);
1370 if (data.lpData && wnddata->size == sizeof(*wnddata))
1371 {
1372 static const WCHAR verW[] = {'6','.','5','.','4','.','3','!',0};
1373 WCHAR buff[50];
1374 WCHAR *ptr;
1375 ULONG len;
1376
1377 ok_(__FILE__, line)(wnddata->res == 0, "got reserved as %ld\n", wnddata->res);
1378 /* redirect class name (versioned or not) is stored just after header data */
1379 ok_(__FILE__, line)(wnddata->name_offset == wnddata->size, "got name offset as %ld\n", wnddata->name_offset);
1380 ok_(__FILE__, line)(wnddata->module_len > 0, "got module name length as %ld\n", wnddata->module_len);
1381
1382 /* expected versioned name */
1383 lstrcpyW(buff, verW);
1384 lstrcatW(buff, clsname);
1385 ptr = (WCHAR*)((BYTE*)wnddata + wnddata->name_offset);
1386 ok_(__FILE__, line)(!lstrcmpW(ptr, buff), "got wrong class name %s, expected %s\n", wine_dbgstr_w(ptr), wine_dbgstr_w(buff));
1387 ok_(__FILE__, line)(lstrlenW(ptr)*sizeof(WCHAR) == wnddata->name_len,
1388 "got wrong class name length %ld, expected %d\n", wnddata->name_len, lstrlenW(ptr));
1389
1390 /* data length is simply header length + string data length including nulls */
1391 len = wnddata->size + wnddata->name_len + wnddata->module_len + 2*sizeof(WCHAR);
1392 ok_(__FILE__, line)(data.ulLength == len, "got wrong data length %ld, expected %ld\n", data.ulLength, len);
1393
1394 if (data.ulSectionTotalLength > wnddata->module_offset)
1395 {
1396 WCHAR *modulename, *sectionptr;
1397
1398 /* just compare pointers */
1399 modulename = (WCHAR*)((BYTE*)wnddata + wnddata->size + wnddata->name_len + sizeof(WCHAR));
1400 sectionptr = (WCHAR*)((BYTE*)data.lpSectionBase + wnddata->module_offset);
1401 ok_(__FILE__, line)(modulename == sectionptr, "got wrong name offset %p, expected %p\n", sectionptr, modulename);
1402 }
1403 }
1404
1405 ok_(__FILE__, line)(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
1406 ok_(__FILE__, line)(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%lu\n",
1407 data.ulSectionGlobalDataLength);
1408 ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
1409 ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%lu\n",
1410 data.ulSectionTotalLength);
1411 ok_(__FILE__, line)(data.hActCtx == NULL, "data.hActCtx=%p\n", data.hActCtx);
1412 ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%lu, expected %lu\n",
1413 data.ulAssemblyRosterIndex, exid);
1414
1415 memset(&data, 0xfe, sizeof(data));
1416 data.cbSize = sizeof(data);
1417
1418 ret = FindActCtxSectionStringW(FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX, NULL,
1419 ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION, clsname, &data);
1420 ok_(__FILE__, line)(ret, "FindActCtxSectionStringW failed: %lu, class %s\n", GetLastError(),
1421 wine_dbgstr_w(clsname));
1422 if (!ret) return;
1423
1424 ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%lu\n", data.cbSize);
1425 ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%lu\n", data.ulDataFormatVersion);
1426 ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
1427 ok_(__FILE__, line)(data.ulLength > 0, "data.ulLength=%lu\n", data.ulLength);
1428 ok_(__FILE__, line)(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
1429 ok_(__FILE__, line)(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%lu\n",
1430 data.ulSectionGlobalDataLength);
1431 ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
1432 ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%lu\n", data.ulSectionTotalLength);
1433 ok_(__FILE__, line)(data.hActCtx == handle, "data.hActCtx=%p\n", data.hActCtx);
1434 ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%lu, expected %lu\n",
1435 data.ulAssemblyRosterIndex, exid);
1436
1437 ReleaseActCtx(handle);
1438}
1439
1440enum winrt_threading_model
1441{
1442 WINRT_THREADING_MODEL_BOTH = 0,
1443 WINRT_THREADING_MODEL_STA = 1,
1444 WINRT_THREADING_MODEL_MTA = 2,
1445};
1446
1447struct activatable_class_data
1448{
1449 ULONG size;
1450 DWORD unk;
1451 DWORD module_len;
1452 DWORD module_offset;
1453 DWORD threading_model;
1454};
1455
1456static void test_find_activatable_class(HANDLE handle, const WCHAR *classid, enum winrt_threading_model threading_model,
1457 const WCHAR *file, ULONG exid, int line)
1458{
1459 struct activatable_class_data *activatable_class;
1460 struct strsection_header *header;
1461 ACTCTX_SECTION_KEYED_DATA data;
1462 void *ptr;
1463 BOOL ret;
1464
1465 memset(&data, 0xfe, sizeof(data));
1466 data.cbSize = sizeof(data);
1467
1468 ret = FindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_WINRT_ACTIVATABLE_CLASSES, classid, &data);
1469 ok_(__FILE__, line)(ret || broken(!ret) /* <= Win10 v1809 */, "FindActCtxSectionStringW failed, error %lu\n", GetLastError());
1470 if (!ret)
1471 {
1472 ok_(__FILE__, line)(GetLastError() == ERROR_SXS_SECTION_NOT_FOUND, "got error %lu\n", GetLastError());
1473 return;
1474 }
1475
1476 ok_(__FILE__, line)(data.cbSize == sizeof(data), "got cbSize %lu\n", data.cbSize);
1477 ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "got ulDataFormatVersion %lu\n", data.ulDataFormatVersion);
1478 ok_(__FILE__, line)(data.lpData != NULL, "got lpData %p\n", data.lpData);
1479
1480 header = (struct strsection_header *)data.lpSectionBase;
1481 ok_(__FILE__, line)(data.lpSectionBase != NULL, "got lpSectionBase %p\n", data.lpSectionBase);
1482 ok_(__FILE__, line)(header->magic == 0x64487353, "got wrong magic 0x%08lx\n", header->magic);
1483 ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "got ulSectionTotalLength %lu\n", data.ulSectionTotalLength);
1484 ok_(__FILE__, line)(data.lpSectionGlobalData == (BYTE *)header + header->global_offset,
1485 "got lpSectionGlobalData %p\n", data.lpSectionGlobalData);
1486 ok_(__FILE__, line)(data.ulSectionGlobalDataLength == header->global_len,
1487 "got ulSectionGlobalDataLength %lu\n", data.ulSectionGlobalDataLength);
1488 ok_(__FILE__, line)(data.hActCtx == NULL, "got hActCtx %p\n", data.hActCtx);
1489 ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "got ulAssemblyRosterIndex %lu\n", data.ulAssemblyRosterIndex);
1490
1491 activatable_class = (struct activatable_class_data *)data.lpData;
1492 ok_(__FILE__, line)(activatable_class->size == sizeof(*activatable_class), "got size %lu\n",
1493 activatable_class->size);
1494 ok_(__FILE__, line)(activatable_class->threading_model == threading_model, "got threading_model %lu\n",
1495 activatable_class->threading_model);
1496
1497 ptr = (BYTE *)header + activatable_class->module_offset;
1498 ok_(__FILE__, line)(wcslen(ptr) * sizeof(WCHAR) == activatable_class->module_len,
1499 "got module_len %lu\n", activatable_class->module_len);
1500 ok_(__FILE__, line)(!wcscmp(ptr, file), "got data.lpSectionGlobalData %s\n", debugstr_w(ptr));
1501}
1502
1503static void test_find_string_fail(void)
1504{
1505 ACTCTX_SECTION_KEYED_DATA data = {sizeof(data)};
1506 BOOL ret;
1507
1508 ret = FindActCtxSectionStringW(0, NULL, 100, testlib_dll, &data);
1509 ok(!ret, "FindActCtxSectionStringW succeeded\n");
1510 ok(GetLastError() == ERROR_SXS_SECTION_NOT_FOUND, "GetLastError()=%lu\n", GetLastError());
1511
1512 ret = FindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION, testlib2_dll, &data);
1513 ok(!ret, "FindActCtxSectionStringW succeeded\n");
1514 ok(GetLastError() == ERROR_SXS_KEY_NOT_FOUND, "GetLastError()=%lu\n", GetLastError());
1515
1516 ret = FindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION, testlib_dll, NULL);
1517 ok(!ret, "FindActCtxSectionStringW succeeded\n");
1518 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError()=%lu\n", GetLastError());
1519
1520 ret = FindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION, NULL, &data);
1521 ok(!ret, "FindActCtxSectionStringW succeeded\n");
1522 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError()=%lu\n", GetLastError());
1523
1524 data.cbSize = 0;
1525 ret = FindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION, testlib_dll, &data);
1526 ok(!ret, "FindActCtxSectionStringW succeeded\n");
1527 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError()=%lu\n", GetLastError());
1528
1529 data.cbSize = 35;
1530 ret = FindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION, testlib_dll, &data);
1531 ok(!ret, "FindActCtxSectionStringW succeeded\n");
1532 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError()=%lu\n", GetLastError());
1533}
1534
1535
1536static void test_basic_info(HANDLE handle, int line)
1537{
1538 ACTIVATION_CONTEXT_BASIC_INFORMATION basic;
1539 SIZE_T size;
1540 BOOL b;
1541
1542 b = QueryActCtxW(QUERY_ACTCTX_FLAG_NO_ADDREF, handle, NULL, ActivationContextBasicInformation, &basic,
1543 sizeof(basic), &size);
1544
1545 ok_(__FILE__, line) (b,"ActivationContextBasicInformation failed\n");
1546 ok_(__FILE__, line) (size == sizeof(ACTIVATION_CONTEXT_BASIC_INFORMATION),"size mismatch\n");
1547 ok_(__FILE__, line) (basic.dwFlags == 0, "unexpected flags %lx\n",basic.dwFlags);
1548 ok_(__FILE__, line) (basic.hActCtx == handle, "unexpected handle\n");
1549
1550 b = QueryActCtxW(QUERY_ACTCTX_FLAG_USE_ACTIVE_ACTCTX | QUERY_ACTCTX_FLAG_NO_ADDREF, handle, NULL,
1551 ActivationContextBasicInformation, &basic,
1552 sizeof(basic), &size);
1553 if (handle)
1554 {
1555 ok_(__FILE__, line) (!b,"ActivationContextBasicInformation succeeded\n");
1556 ok_(__FILE__, line) (size == 0,"size mismatch\n");
1557 ok_(__FILE__, line) (GetLastError() == ERROR_INVALID_PARAMETER, "Wrong last error\n");
1558 ok_(__FILE__, line) (basic.dwFlags == 0, "unexpected flags %lx\n",basic.dwFlags);
1559 ok_(__FILE__, line) (basic.hActCtx == handle, "unexpected handle\n");
1560 }
1561 else
1562 {
1563 ok_(__FILE__, line) (b,"ActivationContextBasicInformation failed\n");
1564 ok_(__FILE__, line) (size == sizeof(ACTIVATION_CONTEXT_BASIC_INFORMATION),"size mismatch\n");
1565 ok_(__FILE__, line) (basic.dwFlags == 0, "unexpected flags %lx\n",basic.dwFlags);
1566 ok_(__FILE__, line) (basic.hActCtx == handle, "unexpected handle\n");
1567 }
1568}
1569
1570enum comclass_threadingmodel {
1571 ThreadingModel_Apartment = 1,
1572 ThreadingModel_Free = 2,
1573 ThreadingModel_No = 3,
1574 ThreadingModel_Both = 4,
1575 ThreadingModel_Neutral = 5
1576};
1577
1578enum comclass_miscfields {
1579 MiscStatus = 1,
1580 MiscStatusIcon = 2,
1581 MiscStatusContent = 4,
1582 MiscStatusThumbnail = 8,
1583 MiscStatusDocPrint = 16
1584};
1585
1586struct comclassredirect_data {
1587 ULONG size;
1588 ULONG flags;
1589 DWORD model;
1590 GUID clsid;
1591 GUID alias;
1592 GUID clsid2;
1593 GUID tlid;
1594 ULONG name_len;
1595 ULONG name_offset;
1596 ULONG progid_len;
1597 ULONG progid_offset;
1598 ULONG clrdata_len;
1599 ULONG clrdata_offset;
1600 DWORD miscstatus;
1601 DWORD miscstatuscontent;
1602 DWORD miscstatusthumbnail;
1603 DWORD miscstatusicon;
1604 DWORD miscstatusdocprint;
1605};
1606
1607struct clrclass_data {
1608 ULONG size;
1609 DWORD res[2];
1610 ULONG module_len;
1611 ULONG module_offset;
1612 ULONG name_len;
1613 ULONG name_offset;
1614 ULONG version_len;
1615 ULONG version_offset;
1616 DWORD res2[2];
1617};
1618
1619static void validate_guid_index(const ACTCTX_SECTION_KEYED_DATA *data, int line)
1620{
1621#define GUIDSECTION_MAGIC 0x64487347 /* dHsG */
1622 struct guidsection_header *header;
1623 struct guid_index *index;
1624 unsigned int i;
1625
1626 header = (struct guidsection_header *)data->lpSectionBase;
1627
1628 ok_(__FILE__, line)(header->magic == GUIDSECTION_MAGIC, "Unexpected magic %#lx.\n", header->magic);
1629 ok_(__FILE__, line)(header->size == sizeof(*header), "Unexpected size %ld.\n", header->size);
1630 ok_(__FILE__, line)(header->index_offset >= sizeof(*header), "Unexpected index offset %lu.\n", header->index_offset);
1631
1632 index = (struct guid_index *)((BYTE *)data->lpSectionBase + header->index_offset);
1633 for (i = 0; i < header->count; ++i)
1634 {
1635 ok_(__FILE__, line)(index[i].data_len <= data->ulSectionTotalLength, "Unexpected data length.\n");
1636 ok_(__FILE__, line)(index[i].data_offset <= data->ulSectionTotalLength - index[i].data_len,
1637 "Unexpected data offset %ld, section total length %lu, data length %lu.\n",
1638 index[i].data_offset, data->ulSectionTotalLength, index[i].data_len);
1639 }
1640}
1641
1642static void test_find_com_redirection(HANDLE handle, const GUID *clsid, const GUID *tlid, const WCHAR *progid, ULONG exid, int line)
1643{
1644 struct comclassredirect_data *comclass, *comclass2;
1645 ACTCTX_SECTION_KEYED_DATA data, data2;
1646 struct guidsection_header *header;
1647 BOOL ret;
1648
1649 memset(&data, 0xfe, sizeof(data));
1650 data.cbSize = sizeof(data);
1651
1652 ret = FindActCtxSectionGuid(0, NULL, ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION, clsid, &data);
1653 if (!ret)
1654 {
1655 skip("failed for guid %s\n", wine_dbgstr_guid(clsid));
1656 return;
1657 }
1658 ok_(__FILE__, line)(ret, "FindActCtxSectionGuid failed: %lu\n", GetLastError());
1659
1660 comclass = (struct comclassredirect_data*)data.lpData;
1661
1662 ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%lu\n", data.cbSize);
1663 ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%lu\n", data.ulDataFormatVersion);
1664 ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
1665 ok_(__FILE__, line)(comclass->size == sizeof(*comclass), "got %ld for header size\n", comclass->size);
1666 if (data.lpData && comclass->size == sizeof(*comclass))
1667 {
1668 ULONG len, miscmask;
1669 WCHAR *ptr;
1670
1671 ok_(__FILE__, line)(comclass->model == ThreadingModel_Neutral, "got model %ld\n", comclass->model);
1672 ok_(__FILE__, line)(IsEqualGUID(&comclass->clsid, clsid), "got wrong clsid %s\n", wine_dbgstr_guid(&comclass->clsid));
1673 ok_(__FILE__, line)(IsEqualGUID(&comclass->clsid2, clsid), "got wrong clsid2 %s\n", wine_dbgstr_guid(&comclass->clsid2));
1674 if (tlid)
1675 ok_(__FILE__, line)(IsEqualGUID(&comclass->tlid, tlid), "got wrong tlid %s\n", wine_dbgstr_guid(&comclass->tlid));
1676 ok_(__FILE__, line)(comclass->name_len > 0, "got modulename len %ld\n", comclass->name_len);
1677
1678 if (progid)
1679 {
1680 len = comclass->size + comclass->clrdata_len;
1681 ok_(__FILE__, line)(comclass->progid_offset == len, "got progid offset %ld, expected %ld\n", comclass->progid_offset, len);
1682 }
1683 else
1684 ok_(__FILE__, line)(comclass->progid_offset == 0, "got progid offset %ld, expected 0\n", comclass->progid_offset);
1685
1686 if (comclass->progid_offset)
1687 {
1688 ptr = (WCHAR*)((BYTE*)comclass + comclass->progid_offset);
1689 ok_(__FILE__, line)(!lstrcmpW(ptr, progid), "got wrong progid %s, expected %s\n", wine_dbgstr_w(ptr), wine_dbgstr_w(progid));
1690 ok_(__FILE__, line)(lstrlenW(progid)*sizeof(WCHAR) == comclass->progid_len,
1691 "got progid name length %ld\n", comclass->progid_len);
1692 }
1693
1694 /* data length is simply header length + string data length including nulls */
1695 len = comclass->size + comclass->clrdata_len;
1696 if (comclass->progid_len) len += comclass->progid_len + sizeof(WCHAR);
1697 ok_(__FILE__, line)(data.ulLength == len, "got wrong data length %ld, expected %ld\n", data.ulLength, len);
1698
1699 /* keyed data structure doesn't include module name, it's available from section data */
1700 ok_(__FILE__, line)(data.ulSectionTotalLength > comclass->name_offset, "got wrong offset %ld\n", comclass->name_offset);
1701
1702 /* check misc fields are set */
1703 miscmask = (comclass->flags >> 8) & 0xff;
1704 if (miscmask)
1705 {
1706 if (miscmask & MiscStatus)
1707 ok_(__FILE__, line)(comclass->miscstatus != 0, "got miscstatus 0x%08lx\n", comclass->miscstatus);
1708 if (miscmask & MiscStatusIcon)
1709 ok_(__FILE__, line)(comclass->miscstatusicon != 0, "got miscstatusicon 0x%08lx\n", comclass->miscstatusicon);
1710 if (miscmask & MiscStatusContent)
1711 ok_(__FILE__, line)(comclass->miscstatuscontent != 0, "got miscstatuscontent 0x%08lx\n", comclass->miscstatuscontent);
1712 if (miscmask & MiscStatusThumbnail)
1713 ok_(__FILE__, line)(comclass->miscstatusthumbnail != 0, "got miscstatusthumbnail 0x%08lx\n", comclass->miscstatusthumbnail);
1714 if (miscmask & MiscStatusDocPrint)
1715 ok_(__FILE__, line)(comclass->miscstatusdocprint != 0, "got miscstatusdocprint 0x%08lx\n", comclass->miscstatusdocprint);
1716 }
1717 ok_(__FILE__, line)(!(comclass->flags & 0xffff00ff), "Unexpected flags %#lx.\n", comclass->flags);
1718
1719 /* part used for clrClass only */
1720 if (comclass->clrdata_len)
1721 {
1722 static const WCHAR mscoreeW[] = {'M','S','C','O','R','E','E','.','D','L','L',0};
1723 static const WCHAR mscoree2W[] = {'m','s','c','o','r','e','e','.','d','l','l',0};
1724 struct clrclass_data *clrclass;
1725 WCHAR *ptrW;
1726
1727 clrclass = (struct clrclass_data*)((BYTE*)data.lpData + comclass->clrdata_offset);
1728 ok_(__FILE__, line)(clrclass->size == sizeof(*clrclass), "clrclass: got size %ld\n", clrclass->size);
1729 ok_(__FILE__, line)(clrclass->res[0] == 0, "clrclass: got res[0]=0x%08lx\n", clrclass->res[0]);
1730 ok_(__FILE__, line)(clrclass->res[1] == 2, "clrclass: got res[1]=0x%08lx\n", clrclass->res[1]);
1731 ok_(__FILE__, line)(clrclass->module_len == lstrlenW(mscoreeW)*sizeof(WCHAR), "clrclass: got module len %ld\n", clrclass->module_len);
1732 ok_(__FILE__, line)(clrclass->module_offset > 0, "clrclass: got module offset %ld\n", clrclass->module_offset);
1733
1734 ok_(__FILE__, line)(clrclass->name_len > 0, "clrclass: got name len %ld\n", clrclass->name_len);
1735 ok_(__FILE__, line)(clrclass->name_offset == clrclass->size, "clrclass: got name offset %ld\n", clrclass->name_offset);
1736 ok_(__FILE__, line)(clrclass->version_len > 0, "clrclass: got version len %ld\n", clrclass->version_len);
1737 ok_(__FILE__, line)(clrclass->version_offset > 0, "clrclass: got version offset %ld\n", clrclass->version_offset);
1738
1739 ok_(__FILE__, line)(clrclass->res2[0] == 0, "clrclass: got res2[0]=0x%08lx\n", clrclass->res2[0]);
1740 ok_(__FILE__, line)(clrclass->res2[1] == 0, "clrclass: got res2[1]=0x%08lx\n", clrclass->res2[1]);
1741
1742 /* clrClass uses mscoree.dll as module name, but in two variants - comclass data points to module name
1743 in lower case, clsclass subsection - in upper case */
1744 ok_(__FILE__, line)(comclass->name_len == lstrlenW(mscoree2W)*sizeof(WCHAR), "clrclass: got com name len %ld\n", comclass->name_len);
1745 ok_(__FILE__, line)(comclass->name_offset > 0, "clrclass: got name offset %ld\n", clrclass->name_offset);
1746
1747 ptrW = (WCHAR*)((BYTE*)data.lpSectionBase + comclass->name_offset);
1748 ok_(__FILE__, line)(!lstrcmpW(ptrW, mscoreeW), "clrclass: module name %s\n", wine_dbgstr_w(ptrW));
1749
1750 ptrW = (WCHAR*)((BYTE*)data.lpSectionBase + clrclass->module_offset);
1751 ok_(__FILE__, line)(!lstrcmpW(ptrW, mscoree2W), "clrclass: module name2 %s\n", wine_dbgstr_w(ptrW));
1752 }
1753 }
1754
1755 header = (struct guidsection_header*)data.lpSectionBase;
1756 ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
1757 ok_(__FILE__, line)(data.lpSectionGlobalData == ((BYTE*)header + header->names_offset), "data.lpSectionGlobalData == NULL\n");
1758 ok_(__FILE__, line)(data.ulSectionGlobalDataLength == header->names_len, "data.ulSectionGlobalDataLength=%lu\n",
1759 data.ulSectionGlobalDataLength);
1760 ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%lu\n",
1761 data.ulSectionTotalLength);
1762 ok_(__FILE__, line)(data.hActCtx == NULL, "data.hActCtx=%p\n", data.hActCtx);
1763 ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%lu, expected %lu\n",
1764 data.ulAssemblyRosterIndex, exid);
1765 validate_guid_index(&data, line);
1766
1767 /* generated guid for this class works as key guid in search */
1768 memset(&data2, 0xfe, sizeof(data2));
1769 data2.cbSize = sizeof(data2);
1770 ret = FindActCtxSectionGuid(0, NULL, ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION, &comclass->alias, &data2);
1771 ok_(__FILE__, line)(ret, "FindActCtxSectionGuid failed: %lu\n", GetLastError());
1772
1773 comclass2 = (struct comclassredirect_data*)data2.lpData;
1774 ok_(__FILE__, line)(comclass->size == comclass2->size, "got wrong data length %ld, expected %ld\n", comclass2->size, comclass->size);
1775 ok_(__FILE__, line)(!memcmp(comclass, comclass2, comclass->size), "got wrong data\n");
1776}
1777
1778enum ifaceps_mask
1779{
1780 NumMethods = 1,
1781 BaseIface = 2
1782};
1783
1784struct ifacepsredirect_data
1785{
1786 ULONG size;
1787 DWORD mask;
1788 GUID iid;
1789 ULONG nummethods;
1790 GUID tlbid;
1791 GUID base;
1792 ULONG name_len;
1793 ULONG name_offset;
1794};
1795
1796static void test_find_ifaceps_redirection(HANDLE handle, const GUID *iid, const GUID *tlbid, const GUID *base,
1797 const GUID *ps32, ULONG exid, int line)
1798{
1799 struct ifacepsredirect_data *ifaceps;
1800 ACTCTX_SECTION_KEYED_DATA data;
1801 BOOL ret;
1802
1803 memset(&data, 0xfe, sizeof(data));
1804 data.cbSize = sizeof(data);
1805
1806 ret = FindActCtxSectionGuid(0, NULL, ACTIVATION_CONTEXT_SECTION_COM_INTERFACE_REDIRECTION, iid, &data);
1807 ok_(__FILE__, line)(ret, "FindActCtxSectionGuid failed: %lu\n", GetLastError());
1808
1809 ifaceps = (struct ifacepsredirect_data*)data.lpData;
1810
1811 ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%lu\n", data.cbSize);
1812 ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%lu\n", data.ulDataFormatVersion);
1813 ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
1814 ok_(__FILE__, line)(ifaceps->size == sizeof(*ifaceps), "got %ld for header size\n", ifaceps->size);
1815 if (data.lpData && ifaceps->size == sizeof(*ifaceps))
1816 {
1817 ULONG len;
1818
1819 /* for external proxy stubs it contains a value from 'proxyStubClsid32' */
1820 if (ps32)
1821 {
1822 ok_(__FILE__, line)(IsEqualGUID(&ifaceps->iid, ps32), "got wrong iid %s\n", wine_dbgstr_guid(&ifaceps->iid));
1823 }
1824 else
1825 ok_(__FILE__, line)(IsEqualGUID(&ifaceps->iid, iid), "got wrong iid %s\n", wine_dbgstr_guid(&ifaceps->iid));
1826
1827 ok_(__FILE__, line)(IsEqualGUID(&ifaceps->tlbid, tlbid), "got wrong tlid %s\n", wine_dbgstr_guid(&ifaceps->tlbid));
1828 ok_(__FILE__, line)(ifaceps->name_len > 0, "got modulename len %ld\n", ifaceps->name_len);
1829 ok_(__FILE__, line)(ifaceps->name_offset == ifaceps->size, "got progid offset %ld\n", ifaceps->name_offset);
1830
1831 /* data length is simply header length + string data length including nulls */
1832 len = ifaceps->size + ifaceps->name_len + sizeof(WCHAR);
1833 ok_(__FILE__, line)(data.ulLength == len, "got wrong data length %ld, expected %ld\n", data.ulLength, len);
1834
1835 /* mask purpose is to indicate if attribute was specified, for testing purposes assume that manifest
1836 always has non-zero value for it */
1837 if (ifaceps->mask & NumMethods)
1838 ok_(__FILE__, line)(ifaceps->nummethods != 0, "got nummethods %ld\n", ifaceps->nummethods);
1839 if (ifaceps->mask & BaseIface)
1840 ok_(__FILE__, line)(IsEqualGUID(&ifaceps->base, base), "got base %s\n", wine_dbgstr_guid(&ifaceps->base));
1841 }
1842
1843 ok_(__FILE__, line)(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
1844 ok_(__FILE__, line)(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%lu\n",
1845 data.ulSectionGlobalDataLength);
1846 ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
1847 ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%lu\n",
1848 data.ulSectionTotalLength);
1849 ok_(__FILE__, line)(data.hActCtx == NULL, "data.hActCtx=%p\n", data.hActCtx);
1850 ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%lu, expected %lu\n",
1851 data.ulAssemblyRosterIndex, exid);
1852
1853 validate_guid_index(&data, line);
1854}
1855
1856struct clrsurrogate_data
1857{
1858 ULONG size;
1859 DWORD res;
1860 GUID clsid;
1861 ULONG version_offset;
1862 ULONG version_len;
1863 ULONG name_offset;
1864 ULONG name_len;
1865};
1866
1867static void test_find_surrogate(HANDLE handle, const GUID *clsid, const WCHAR *name, const WCHAR *version,
1868 ULONG exid, int line)
1869{
1870 struct clrsurrogate_data *surrogate;
1871 ACTCTX_SECTION_KEYED_DATA data;
1872 BOOL ret;
1873
1874#ifdef __REACTOS__
1875 if (is_reactos()) {
1876 ok(FALSE, "FIXME: This test crashes on ReactOS\n");
1877 return;
1878 }
1879#endif
1880 memset(&data, 0xfe, sizeof(data));
1881 data.cbSize = sizeof(data);
1882
1883 ret = FindActCtxSectionGuid(0, NULL, ACTIVATION_CONTEXT_SECTION_CLR_SURROGATES, clsid, &data);
1884 if (!ret)
1885 {
1886 skip("surrogate sections are not supported\n");
1887 return;
1888 }
1889 ok_(__FILE__, line)(ret, "FindActCtxSectionGuid failed: %lu\n", GetLastError());
1890
1891 surrogate = (struct clrsurrogate_data*)data.lpData;
1892
1893 ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%lu\n", data.cbSize);
1894 ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%lu\n", data.ulDataFormatVersion);
1895 ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
1896 ok_(__FILE__, line)(surrogate->size == sizeof(*surrogate), "got %ld for header size\n", surrogate->size);
1897 if (data.lpData && surrogate->size == sizeof(*surrogate))
1898 {
1899 WCHAR *ptrW;
1900 ULONG len;
1901
1902 ok_(__FILE__, line)(surrogate->res == 0, "invalid res value %ld\n", surrogate->res);
1903 ok_(__FILE__, line)(IsEqualGUID(&surrogate->clsid, clsid), "got wrong clsid %s\n", wine_dbgstr_guid(&surrogate->clsid));
1904
1905 ok_(__FILE__, line)(surrogate->version_len == lstrlenW(version)*sizeof(WCHAR), "got version len %ld\n", surrogate->version_len);
1906 ok_(__FILE__, line)(surrogate->version_offset == surrogate->size, "got version offset %ld\n", surrogate->version_offset);
1907
1908 ok_(__FILE__, line)(surrogate->name_len == lstrlenW(name)*sizeof(WCHAR), "got name len %ld\n", surrogate->name_len);
1909 ok_(__FILE__, line)(surrogate->name_offset > surrogate->version_offset, "got name offset %ld\n", surrogate->name_offset);
1910
1911 len = surrogate->size + surrogate->name_len + surrogate->version_len + 2*sizeof(WCHAR);
1912 ok_(__FILE__, line)(data.ulLength == len, "got wrong data length %ld, expected %ld\n", data.ulLength, len);
1913
1914 ptrW = (WCHAR*)((BYTE*)surrogate + surrogate->name_offset);
1915 ok(!lstrcmpW(ptrW, name), "got wrong name %s\n", wine_dbgstr_w(ptrW));
1916
1917 ptrW = (WCHAR*)((BYTE*)surrogate + surrogate->version_offset);
1918 ok(!lstrcmpW(ptrW, version), "got wrong name %s\n", wine_dbgstr_w(ptrW));
1919 }
1920
1921 ok_(__FILE__, line)(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
1922 ok_(__FILE__, line)(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%lu\n",
1923 data.ulSectionGlobalDataLength);
1924 ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
1925 ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%lu\n",
1926 data.ulSectionTotalLength);
1927 ok_(__FILE__, line)(data.hActCtx == NULL, "data.hActCtx=%p\n", data.hActCtx);
1928 ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%lu, expected %lu\n",
1929 data.ulAssemblyRosterIndex, exid);
1930
1931 validate_guid_index(&data, line);
1932}
1933
1934static void test_find_progid_redirection(HANDLE handle, const GUID *clsid, const char *progid, ULONG exid, int line)
1935{
1936 struct progidredirect_data *progiddata;
1937 struct comclassredirect_data *comclass;
1938 ACTCTX_SECTION_KEYED_DATA data, data2;
1939 struct strsection_header *header;
1940 BOOL ret;
1941
1942#if defined(__REACTOS__) && defined(_MSC_VER)
1943 if (is_reactos()) {
1944 ok(FALSE, "FIXME: This crashes on MSVC ReactOS\n");
1945 return;
1946 }
1947#endif
1948 memset(&data, 0xfe, sizeof(data));
1949 data.cbSize = sizeof(data);
1950
1951 ret = FindActCtxSectionStringA(0, NULL, ACTIVATION_CONTEXT_SECTION_COM_PROGID_REDIRECTION, progid, &data);
1952 ok_(__FILE__, line)(ret, "FindActCtxSectionStringA failed: %lu\n", GetLastError());
1953
1954 progiddata = (struct progidredirect_data*)data.lpData;
1955
1956 ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%lu\n", data.cbSize);
1957 ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%lu\n", data.ulDataFormatVersion);
1958 ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
1959 ok_(__FILE__, line)(progiddata->size == sizeof(*progiddata), "got %ld for header size\n", progiddata->size);
1960 if (data.lpData && progiddata->size == sizeof(*progiddata))
1961 {
1962 GUID *guid;
1963
1964 ok_(__FILE__, line)(progiddata->reserved == 0, "got reserved as %ld\n", progiddata->reserved);
1965 ok_(__FILE__, line)(progiddata->clsid_offset > 0, "got clsid_offset as %ld\n", progiddata->clsid_offset);
1966
1967 /* progid data points to generated alias guid */
1968 guid = (GUID*)((BYTE*)data.lpSectionBase + progiddata->clsid_offset);
1969
1970 memset(&data2, 0, sizeof(data2));
1971 data2.cbSize = sizeof(data2);
1972 ret = FindActCtxSectionGuid(0, NULL, ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION, guid, &data2);
1973 ok_(__FILE__, line)(ret, "FindActCtxSectionGuid failed: %lu\n", GetLastError());
1974
1975 comclass = (struct comclassredirect_data*)data2.lpData;
1976 ok_(__FILE__, line)(IsEqualGUID(guid, &comclass->alias), "got wrong alias referenced from progid %s, %s\n", progid, wine_dbgstr_guid(guid));
1977 ok_(__FILE__, line)(IsEqualGUID(clsid, &comclass->clsid), "got wrong class referenced from progid %s, %s\n", progid, wine_dbgstr_guid(clsid));
1978
1979 validate_guid_index(&data2, line);
1980 }
1981
1982 header = (struct strsection_header*)data.lpSectionBase;
1983 ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
1984 ok_(__FILE__, line)(data.lpSectionGlobalData == (BYTE*)header + header->global_offset, "data.lpSectionGlobalData == NULL\n");
1985 ok_(__FILE__, line)(data.ulSectionGlobalDataLength == header->global_len, "data.ulSectionGlobalDataLength=%lu\n", data.ulSectionGlobalDataLength);
1986 ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%lu\n", data.ulSectionTotalLength);
1987 ok_(__FILE__, line)(data.hActCtx == NULL, "data.hActCtx=%p\n", data.hActCtx);
1988 ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%lu, expected %lu\n",
1989 data.ulAssemblyRosterIndex, exid);
1990}
1991
1992static void test_wndclass_section(void)
1993{
1994 static const WCHAR cls1W[] = {'1','.','2','.','3','.','4','!','w','n','d','C','l','a','s','s','1',0};
1995 ACTCTX_SECTION_KEYED_DATA data, data2;
1996 struct wndclass_redirect_data *classdata;
1997 struct strsection_header *section;
1998 ULONG_PTR cookie;
1999 HANDLE handle;
2000 WCHAR *ptrW;
2001 BOOL ret;
2002
2003 /* use two dependent manifests, each defines 2 window class redirects */
2004 create_manifest_file("testdep1.manifest", manifest_wndcls1, -1, NULL, NULL);
2005 create_manifest_file("testdep2.manifest", manifest_wndcls2, -1, NULL, NULL);
2006 create_manifest_file("main_wndcls.manifest", manifest_wndcls_main, -1, NULL, NULL);
2007
2008 handle = test_create("main_wndcls.manifest");
2009 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %lu\n", GetLastError());
2010
2011 DeleteFileA("testdep1.manifest");
2012 DeleteFileA("testdep2.manifest");
2013 DeleteFileA("main_wndcls.manifest");
2014
2015 ret = ActivateActCtx(handle, &cookie);
2016 ok(ret, "ActivateActCtx failed: %lu\n", GetLastError());
2017
2018 memset(&data, 0, sizeof(data));
2019 memset(&data2, 0, sizeof(data2));
2020 data.cbSize = sizeof(data);
2021 data2.cbSize = sizeof(data2);
2022
2023 /* get data for two classes from different assemblies */
2024 ret = FindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION, wndClass1W, &data);
2025 ok(ret, "got %d\n", ret);
2026 ret = FindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION, wndClass3W, &data2);
2027 ok(ret, "got %d\n", ret);
2028
2029 section = (struct strsection_header*)data.lpSectionBase;
2030 ok(section->count == 4, "got %ld\n", section->count);
2031 ok(section->size == sizeof(*section), "got %ld\n", section->size);
2032
2033 /* For both string same section is returned, meaning it's one wndclass section per context */
2034 ok(data.lpSectionBase == data2.lpSectionBase, "got %p, %p\n", data.lpSectionBase, data2.lpSectionBase);
2035 ok(data.ulSectionTotalLength == data2.ulSectionTotalLength, "got %lu, %lu\n", data.ulSectionTotalLength,
2036 data2.ulSectionTotalLength);
2037
2038 /* wndClass1 is versioned, wndClass3 is not */
2039 classdata = (struct wndclass_redirect_data*)data.lpData;
2040 ptrW = (WCHAR*)((BYTE*)data.lpData + classdata->name_offset);
2041 ok(!lstrcmpW(ptrW, cls1W), "got %s\n", wine_dbgstr_w(ptrW));
2042
2043 classdata = (struct wndclass_redirect_data*)data2.lpData;
2044 ptrW = (WCHAR*)((BYTE*)data2.lpData + classdata->name_offset);
2045 ok(!lstrcmpW(ptrW, wndClass3W), "got %s\n", wine_dbgstr_w(ptrW));
2046
2047 ret = DeactivateActCtx(0, cookie);
2048 ok(ret, "DeactivateActCtx failed: %lu\n", GetLastError());
2049
2050 ReleaseActCtx(handle);
2051}
2052
2053static void test_dllredirect_section(void)
2054{
2055 static const WCHAR testlib1W[] = {'t','e','s','t','l','i','b','1','.','d','l','l',0};
2056 static const WCHAR testlib2W[] = {'t','e','s','t','l','i','b','2','.','d','l','l',0};
2057 ACTCTX_SECTION_KEYED_DATA data, data2;
2058 struct strsection_header *section;
2059 ULONG_PTR cookie;
2060 HANDLE handle;
2061 BOOL ret;
2062
2063 /* use two dependent manifests, 4 'files' total */
2064 create_manifest_file("testdep1.manifest", manifest_wndcls1, -1, NULL, NULL);
2065 create_manifest_file("testdep2.manifest", manifest_wndcls2, -1, NULL, NULL);
2066 create_manifest_file("main_wndcls.manifest", manifest_wndcls_main, -1, NULL, NULL);
2067
2068 handle = test_create("main_wndcls.manifest");
2069 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %lu\n", GetLastError());
2070
2071 DeleteFileA("testdep1.manifest");
2072 DeleteFileA("testdep2.manifest");
2073 DeleteFileA("main_wndcls.manifest");
2074
2075 ret = ActivateActCtx(handle, &cookie);
2076 ok(ret, "ActivateActCtx failed: %lu\n", GetLastError());
2077
2078 memset(&data, 0, sizeof(data));
2079 memset(&data2, 0, sizeof(data2));
2080 data.cbSize = sizeof(data);
2081 data2.cbSize = sizeof(data2);
2082
2083 /* get data for two files from different assemblies */
2084 ret = FindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION, testlib1W, &data);
2085 ok(ret, "got %d\n", ret);
2086 ret = FindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION, testlib2W, &data2);
2087 ok(ret, "got %d\n", ret);
2088
2089 section = (struct strsection_header*)data.lpSectionBase;
2090 ok(section->count == 4, "got %ld\n", section->count);
2091 ok(section->size == sizeof(*section), "got %ld\n", section->size);
2092
2093 /* For both string same section is returned, meaning it's one dll redirect section per context */
2094 ok(data.lpSectionBase == data2.lpSectionBase, "got %p, %p\n", data.lpSectionBase, data2.lpSectionBase);
2095 ok(data.ulSectionTotalLength == data2.ulSectionTotalLength, "got %lu, %lu\n", data.ulSectionTotalLength,
2096 data2.ulSectionTotalLength);
2097
2098 ret = DeactivateActCtx(0, cookie);
2099 ok(ret, "DeactivateActCtx failed: %lu\n", GetLastError());
2100
2101 ReleaseActCtx(handle);
2102}
2103
2104static void test_typelib_section(void)
2105{
2106 static const WCHAR helpW[] = {'h','e','l','p'};
2107 ACTCTX_SECTION_KEYED_DATA data, data2;
2108 struct guidsection_header *section;
2109 struct tlibredirect_data *tlib;
2110 ULONG_PTR cookie;
2111 HANDLE handle;
2112 BOOL ret;
2113
2114 /* use two dependent manifests, 4 'files' total */
2115 create_manifest_file("testdep1.manifest", manifest_wndcls1, -1, NULL, NULL);
2116 create_manifest_file("testdep2.manifest", manifest_wndcls2, -1, NULL, NULL);
2117 create_manifest_file("main_wndcls.manifest", manifest_wndcls_main, -1, NULL, NULL);
2118
2119 handle = test_create("main_wndcls.manifest");
2120 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %lu\n", GetLastError());
2121
2122 DeleteFileA("testdep1.manifest");
2123 DeleteFileA("testdep2.manifest");
2124 DeleteFileA("main_wndcls.manifest");
2125
2126 ret = ActivateActCtx(handle, &cookie);
2127 ok(ret, "ActivateActCtx failed: %lu\n", GetLastError());
2128
2129 memset(&data, 0, sizeof(data));
2130 memset(&data2, 0, sizeof(data2));
2131 data.cbSize = sizeof(data);
2132 data2.cbSize = sizeof(data2);
2133
2134 /* get data for two typelibs from different assemblies */
2135 ret = FindActCtxSectionGuid(0, NULL, ACTIVATION_CONTEXT_SECTION_COM_TYPE_LIBRARY_REDIRECTION, &IID_TlibTest, &data);
2136 ok(ret, "got %d\n", ret);
2137
2138 ret = FindActCtxSectionGuid(0, NULL, ACTIVATION_CONTEXT_SECTION_COM_TYPE_LIBRARY_REDIRECTION,
2139 &IID_TlibTest4, &data2);
2140 ok(ret, "got %d\n", ret);
2141
2142 section = (struct guidsection_header*)data.lpSectionBase;
2143 ok(section->count == 4, "got %ld\n", section->count);
2144 ok(section->size == sizeof(*section), "got %ld\n", section->size);
2145 validate_guid_index(&data, __LINE__);
2146
2147 /* For both GUIDs same section is returned */
2148 ok(data.lpSectionBase == data2.lpSectionBase, "got %p, %p\n", data.lpSectionBase, data2.lpSectionBase);
2149 ok(data.ulSectionTotalLength == data2.ulSectionTotalLength, "got %lu, %lu\n", data.ulSectionTotalLength,
2150 data2.ulSectionTotalLength);
2151
2152 ok(data.lpSectionGlobalData == ((BYTE*)section + section->names_offset), "data.lpSectionGlobalData == NULL\n");
2153 ok(data.ulSectionGlobalDataLength == section->names_len, "data.ulSectionGlobalDataLength=%lu\n",
2154 data.ulSectionGlobalDataLength);
2155
2156 /* test some actual data */
2157 tlib = (struct tlibredirect_data*)data.lpData;
2158 ok(tlib->size == sizeof(*tlib), "got %ld\n", tlib->size);
2159 ok(tlib->major_version == 1, "got %d\n", tlib->major_version);
2160 ok(tlib->minor_version == 0, "got %d\n", tlib->minor_version);
2161 ok(tlib->help_offset > 0, "got %ld\n", tlib->help_offset);
2162 ok(tlib->help_len == sizeof(helpW), "got %ld\n", tlib->help_len);
2163 ok(tlib->flags == (LIBFLAG_FHIDDEN|LIBFLAG_FCONTROL|LIBFLAG_FRESTRICTED), "got %x\n", tlib->flags);
2164
2165 ret = DeactivateActCtx(0, cookie);
2166 ok(ret, "DeactivateActCtx failed: %lu\n", GetLastError());
2167
2168 ReleaseActCtx(handle);
2169}
2170
2171static void test_allowDelayedBinding(void)
2172{
2173 HANDLE handle;
2174
2175 if (!create_manifest_file("test5.manifest", manifest5, -1, NULL, NULL)) {
2176 skip("Could not create manifest file\n");
2177 return;
2178 }
2179
2180 handle = test_create("test5.manifest");
2181 if (handle == INVALID_HANDLE_VALUE) {
2182 win_skip("allowDelayedBinding attribute is not supported.\n");
2183 return;
2184 }
2185
2186 DeleteFileA("test5.manifest");
2187 DeleteFileA("testdep.manifest");
2188 if (handle != INVALID_HANDLE_VALUE) {
2189 test_basic_info(handle, __LINE__);
2190 ReleaseActCtx(handle);
2191 }
2192}
2193
2194static void test_actctx(void)
2195{
2196 ULONG_PTR cookie;
2197 HANDLE handle;
2198 BOOL b;
2199
2200 trace("default actctx\n");
2201
2202 b = GetCurrentActCtx(&handle);
2203 ok(handle == NULL, "handle = %p, expected NULL\n", handle);
2204 ok(b, "GetCurrentActCtx failed: %lu\n", GetLastError());
2205 if(b) {
2206 test_basic_info(handle, __LINE__);
2207 test_detailed_info(handle, &detailed_info0, __LINE__);
2208 test_runlevel_info(handle, &runlevel_info0, __LINE__);
2209 ReleaseActCtx(handle);
2210 }
2211
2212 /* test for whitespace handling in Eq ::= S? '=' S? */
2213 create_manifest_file("test1_1.manifest", manifest1_1, -1, NULL, NULL);
2214 handle = test_create("test1_1.manifest");
2215 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %lu\n", GetLastError());
2216 DeleteFileA("test1_1.manifest");
2217 ReleaseActCtx(handle);
2218
2219 if(!create_manifest_file("test1.manifest", manifest1, -1, NULL, NULL)) {
2220 skip("Could not create manifest file\n");
2221 return;
2222 }
2223
2224 trace("manifest1\n");
2225
2226 handle = test_create("test1.manifest");
2227 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %lu\n", GetLastError());
2228 DeleteFileA("test1.manifest");
2229 if(handle != INVALID_HANDLE_VALUE) {
2230 test_basic_info(handle, __LINE__);
2231 test_detailed_info(handle, &detailed_info1, __LINE__);
2232 test_info_in_assembly(handle, 1, &manifest1_info, __LINE__);
2233
2234 if (!IsDebuggerPresent())
2235 {
2236 /* CloseHandle will generate an exception if a debugger is present */
2237 b = CloseHandle(handle);
2238 ok(!b, "CloseHandle succeeded\n");
2239 ok(GetLastError() == ERROR_INVALID_HANDLE, "GetLastError() == %lu\n", GetLastError());
2240 }
2241
2242 ReleaseActCtx(handle);
2243 }
2244
2245 if(!create_manifest_file("test2.manifest", manifest2, -1, "testdep.manifest", testdep_manifest1)) {
2246 skip("Could not create manifest file\n");
2247 return;
2248 }
2249
2250 trace("manifest2 depmanifest1\n");
2251
2252 handle = test_create("test2.manifest");
2253 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %lu\n", GetLastError());
2254 DeleteFileA("test2.manifest");
2255 DeleteFileA("testdep.manifest");
2256 if(handle != INVALID_HANDLE_VALUE) {
2257 test_basic_info(handle, __LINE__);
2258 test_detailed_info(handle, &detailed_info2, __LINE__);
2259 test_info_in_assembly(handle, 1, &manifest2_info, __LINE__);
2260 test_info_in_assembly(handle, 2, &depmanifest1_info, __LINE__);
2261 ReleaseActCtx(handle);
2262 }
2263
2264 if(!create_manifest_file("test2-2.manifest", manifest2, -1, "testdep.manifest", testdep_manifest2)) {
2265 skip("Could not create manifest file\n");
2266 return;
2267 }
2268
2269 trace("manifest2 depmanifest2\n");
2270
2271 handle = test_create("test2-2.manifest");
2272 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %lu\n", GetLastError());
2273 DeleteFileA("test2-2.manifest");
2274 DeleteFileA("testdep.manifest");
2275 if(handle != INVALID_HANDLE_VALUE) {
2276 test_basic_info(handle, __LINE__);
2277 test_detailed_info(handle, &detailed_info2, __LINE__);
2278 test_info_in_assembly(handle, 1, &manifest2_info, __LINE__);
2279 test_info_in_assembly(handle, 2, &depmanifest2_info, __LINE__);
2280 test_file_info(handle, 1, 0, testlib_dll, __LINE__);
2281 test_file_info(handle, 1, 1, testlib2_dll, __LINE__);
2282
2283 b = ActivateActCtx(handle, &cookie);
2284 ok(b, "ActivateActCtx failed: %lu\n", GetLastError());
2285 test_find_dll_redirection(handle, testlib_dll, 2, __LINE__);
2286 test_find_dll_redirection(handle, testlib2_dll, 2, __LINE__);
2287 b = DeactivateActCtx(0, cookie);
2288 ok(b, "DeactivateActCtx failed: %lu\n", GetLastError());
2289
2290 ReleaseActCtx(handle);
2291 }
2292
2293 trace("manifest2 depmanifest3\n");
2294
2295 if(!create_manifest_file("test2-3.manifest", manifest2, -1, "testdep.manifest", testdep_manifest3)) {
2296 skip("Could not create manifest file\n");
2297 return;
2298 }
2299
2300 handle = test_create("test2-3.manifest");
2301 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %lu\n", GetLastError());
2302 DeleteFileA("test2-3.manifest");
2303 DeleteFileA("testdep.manifest");
2304 if(handle != INVALID_HANDLE_VALUE) {
2305 test_basic_info(handle, __LINE__);
2306 test_detailed_info(handle, &detailed_info2, __LINE__);
2307 test_info_in_assembly(handle, 1, &manifest2_info, __LINE__);
2308 test_info_in_assembly(handle, 2, &depmanifest3_info, __LINE__);
2309 test_file_info(handle, 1, 0, testlib_dll, __LINE__);
2310 test_file_info(handle, 1, 1, testlib2_dll, __LINE__);
2311
2312 b = ActivateActCtx(handle, &cookie);
2313 ok(b, "ActivateActCtx failed: %lu\n", GetLastError());
2314 test_find_dll_redirection(handle, testlib_dll, 2, __LINE__);
2315 test_find_dll_redirection(handle, testlib2_dll, 2, __LINE__);
2316 test_find_window_class(handle, wndClassW, 2, __LINE__);
2317 test_find_window_class(handle, wndClass2W, 2, __LINE__);
2318 b = DeactivateActCtx(0, cookie);
2319 ok(b, "DeactivateActCtx failed: %lu\n", GetLastError());
2320
2321 ReleaseActCtx(handle);
2322 }
2323
2324 trace("manifest3\n");
2325
2326 if(!create_manifest_file("test3.manifest", manifest3, -1, NULL, NULL)) {
2327 skip("Could not create manifest file\n");
2328 return;
2329 }
2330
2331 handle = test_create("test3.manifest");
2332 ok(handle != INVALID_HANDLE_VALUE || broken(handle == INVALID_HANDLE_VALUE) /* XP pre-SP2, win2k3 w/o SP */,
2333 "handle == INVALID_HANDLE_VALUE, error %lu\n", GetLastError());
2334 if (handle == INVALID_HANDLE_VALUE)
2335 win_skip("Some activation context features not supported, skipping a test (possibly old XP/Win2k3 system\n");
2336 DeleteFileA("test3.manifest");
2337 if(handle != INVALID_HANDLE_VALUE) {
2338 static const WCHAR nameW[] = {'t','e','s','t','s','u','r','r','o','g','a','t','e',0};
2339 static const WCHAR versionW[] = {'v','2','.','0','.','5','0','7','2','7',0};
2340 static const WCHAR progidW[] = {'P','r','o','g','I','d','.','P','r','o','g','I','d',0};
2341 static const WCHAR clrprogidW[] = {'c','l','r','p','r','o','g','i','d',0};
2342
2343 test_basic_info(handle, __LINE__);
2344 test_detailed_info(handle, &detailed_info1, __LINE__);
2345 test_info_in_assembly(handle, 1, &manifest3_info, __LINE__);
2346 test_file_info(handle, 0, 0, testlib_dll, __LINE__);
2347
2348 b = ActivateActCtx(handle, &cookie);
2349 ok(b, "ActivateActCtx failed: %lu\n", GetLastError());
2350 test_find_dll_redirection(handle, testlib_dll, 1, __LINE__);
2351 test_find_dll_redirection(handle, testlib_dll, 1, __LINE__);
2352 test_find_com_redirection(handle, &IID_CoTest, &IID_TlibTest, progidW, 1, __LINE__);
2353 test_find_com_redirection(handle, &IID_CoTest2, NULL, NULL, 1, __LINE__);
2354 test_find_com_redirection(handle, &CLSID_clrclass, &IID_TlibTest, clrprogidW, 1, __LINE__);
2355 test_find_progid_redirection(handle, &IID_CoTest, "ProgId.ProgId", 1, __LINE__);
2356 test_find_progid_redirection(handle, &IID_CoTest, "ProgId.ProgId.1", 1, __LINE__);
2357 test_find_progid_redirection(handle, &IID_CoTest, "ProgId.ProgId.2", 1, __LINE__);
2358 test_find_progid_redirection(handle, &IID_CoTest, "ProgId.ProgId.3", 1, __LINE__);
2359 test_find_progid_redirection(handle, &IID_CoTest, "ProgId.ProgId.4", 1, __LINE__);
2360 test_find_progid_redirection(handle, &IID_CoTest, "ProgId.ProgId.5", 1, __LINE__);
2361 test_find_progid_redirection(handle, &IID_CoTest, "ProgId.ProgId.6", 1, __LINE__);
2362 test_find_progid_redirection(handle, &CLSID_clrclass, "clrprogid", 1, __LINE__);
2363 test_find_progid_redirection(handle, &CLSID_clrclass, "clrprogid.1", 1, __LINE__);
2364 test_find_progid_redirection(handle, &CLSID_clrclass, "clrprogid.2", 1, __LINE__);
2365 test_find_progid_redirection(handle, &CLSID_clrclass, "clrprogid.3", 1, __LINE__);
2366 test_find_progid_redirection(handle, &CLSID_clrclass, "clrprogid.4", 1, __LINE__);
2367 test_find_progid_redirection(handle, &CLSID_clrclass, "clrprogid.5", 1, __LINE__);
2368 test_find_progid_redirection(handle, &CLSID_clrclass, "clrprogid.6", 1, __LINE__);
2369 test_find_surrogate(handle, &IID_Iiface, nameW, versionW, 1, __LINE__);
2370 test_find_ifaceps_redirection(handle, &IID_Iifaceps, &IID_TlibTest4, &IID_Ibifaceps, NULL, 1, __LINE__);
2371 test_find_ifaceps_redirection(handle, &IID_Iifaceps2, &IID_TlibTest4, &IID_Ibifaceps, &IID_PS32, 1, __LINE__);
2372 test_find_ifaceps_redirection(handle, &IID_Iifaceps3, &IID_TlibTest4, &IID_Ibifaceps, NULL, 1, __LINE__);
2373 test_find_string_fail();
2374 test_find_activatable_class(handle, L"Wine.Test.Class1", WINRT_THREADING_MODEL_MTA, L"testlib.dll", 1, __LINE__);
2375 test_find_activatable_class(handle, L"Wine.Test.Class2", WINRT_THREADING_MODEL_BOTH, L"testlib.dll", 1, __LINE__);
2376 test_find_activatable_class(handle, L"Wine.Test.Class3", WINRT_THREADING_MODEL_STA, L"testlib.dll", 1, __LINE__);
2377 test_find_activatable_class(handle, L"Wine.Test.Class4", WINRT_THREADING_MODEL_STA, L"Wine.Test.dll", 1, __LINE__);
2378
2379 b = DeactivateActCtx(0, cookie);
2380 ok(b, "DeactivateActCtx failed: %lu\n", GetLastError());
2381 ReleaseActCtx(handle);
2382 }
2383
2384 trace("manifest6\n");
2385
2386 if(create_manifest_file("test6.manifest", manifest6, -1, NULL, NULL)) {
2387 handle = test_create("test6.manifest");
2388 ok(handle != INVALID_HANDLE_VALUE || broken(handle == INVALID_HANDLE_VALUE) /* WinXP */,
2389 "Unexpected context handle %p.\n", handle);
2390 DeleteFileA("test6.manifest");
2391 DeleteFileA("testdep.manifest");
2392 if(handle != INVALID_HANDLE_VALUE)
2393 {
2394 test_runlevel_info(handle, &runlevel_info6, __LINE__);
2395 ReleaseActCtx(handle);
2396 }
2397 }
2398 else
2399 skip("Could not create manifest file 6\n");
2400
2401 trace("manifest7\n");
2402
2403 if(create_manifest_file("test7.manifest", manifest7, -1, NULL, NULL)) {
2404 handle = test_create("test7.manifest");
2405 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %lu\n", GetLastError());
2406 DeleteFileA("test7.manifest");
2407 DeleteFileA("testdep.manifest");
2408 if(handle != INVALID_HANDLE_VALUE)
2409 {
2410 test_runlevel_info(handle, &runlevel_info7, __LINE__);
2411 ReleaseActCtx(handle);
2412 }
2413 }
2414 else
2415 skip("Could not create manifest file 7\n");
2416
2417 trace("manifest8\n");
2418
2419 if(create_manifest_file("test8.manifest", manifest8, -1, NULL, NULL)) {
2420 handle = test_create("test8.manifest");
2421 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %lu\n", GetLastError());
2422 DeleteFileA("test8.manifest");
2423 DeleteFileA("testdep.manifest");
2424 if(handle != INVALID_HANDLE_VALUE)
2425 {
2426 test_runlevel_info(handle, &runlevel_info8, __LINE__);
2427 ReleaseActCtx(handle);
2428 }
2429 }
2430 else
2431 skip("Could not create manifest file 8\n");
2432
2433 trace("manifest9\n");
2434
2435 if(create_manifest_file("test9.manifest", manifest9, -1, NULL, NULL)) {
2436 handle = test_create("test9.manifest");
2437 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %lu\n", GetLastError());
2438 DeleteFileA("test9.manifest");
2439 DeleteFileA("testdep.manifest");
2440 if(handle != INVALID_HANDLE_VALUE)
2441 {
2442 test_runlevel_info(handle, &runlevel_info9, __LINE__);
2443 ReleaseActCtx(handle);
2444 }
2445 }
2446 else
2447 skip("Could not create manifest file 9\n");
2448
2449 if(create_manifest_file("test10.manifest", manifest10, -1, NULL, NULL)) {
2450 handle = test_create("test10.manifest");
2451 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %lu\n", GetLastError());
2452 DeleteFileA("test10.manifest");
2453 DeleteFileA("testdep.manifest");
2454 if(handle != INVALID_HANDLE_VALUE)
2455 {
2456 test_runlevel_info(handle, &runlevel_info8, __LINE__);
2457 ReleaseActCtx(handle);
2458 }
2459 }
2460 else
2461 skip("Could not create manifest file 10\n");
2462
2463 if (create_manifest_file("test11.manifest", manifest11, -1, NULL, NULL))
2464 {
2465 handle = test_create("test11.manifest");
2466 ok(handle != INVALID_HANDLE_VALUE, "Failed to create activation context for %s, error %lu\n",
2467 "manifest11", GetLastError());
2468 DeleteFileA("test11.manifest");
2469 if (handle != INVALID_HANDLE_VALUE)
2470 ReleaseActCtx(handle);
2471 }
2472 else
2473 skip("Could not create manifest file 11\n");
2474
2475 trace("manifest4\n");
2476
2477 if(!create_manifest_file("test4.manifest", manifest4, -1, NULL, NULL)) {
2478 skip("Could not create manifest file\n");
2479 return;
2480 }
2481
2482 handle = test_create("test4.manifest");
2483 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %lu\n", GetLastError());
2484 DeleteFileA("test4.manifest");
2485 DeleteFileA("testdep.manifest");
2486 if(handle != INVALID_HANDLE_VALUE) {
2487 test_basic_info(handle, __LINE__);
2488 test_detailed_info(handle, &detailed_info2, __LINE__);
2489 test_info_in_assembly(handle, 1, &manifest4_info, __LINE__);
2490 test_info_in_assembly(handle, 2, &manifest_comctrl_info, __LINE__);
2491 ReleaseActCtx(handle);
2492 }
2493
2494 trace("manifest1 in subdir\n");
2495
2496 CreateDirectoryW(work_dir_subdir, NULL);
2497 if (SetCurrentDirectoryW(work_dir_subdir))
2498 {
2499 if(!create_manifest_file("..\\test1.manifest", manifest1, -1, NULL, NULL)) {
2500 skip("Could not create manifest file\n");
2501 return;
2502 }
2503 handle = test_create("..\\test1.manifest");
2504 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %lu\n", GetLastError());
2505 DeleteFileA("..\\test1.manifest");
2506 if(handle != INVALID_HANDLE_VALUE) {
2507 test_basic_info(handle, __LINE__);
2508 test_detailed_info(handle, &detailed_info1, __LINE__);
2509 test_info_in_assembly(handle, 1, &manifest1_info, __LINE__);
2510 ReleaseActCtx(handle);
2511 }
2512 SetCurrentDirectoryW(work_dir);
2513 }
2514 else
2515 skip("Couldn't change directory\n");
2516 RemoveDirectoryW(work_dir_subdir);
2517
2518 trace("UTF-16 manifest1, with BOM\n");
2519 if(!create_wide_manifest("test1.manifest", manifest1, TRUE, FALSE)) {
2520 skip("Could not create manifest file\n");
2521 return;
2522 }
2523
2524 handle = test_create("test1.manifest");
2525 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %lu\n", GetLastError());
2526 DeleteFileA("test1.manifest");
2527 if (handle != INVALID_HANDLE_VALUE) {
2528 test_basic_info(handle, __LINE__);
2529 test_detailed_info(handle, &detailed_info1, __LINE__);
2530 test_info_in_assembly(handle, 1, &manifest1_info, __LINE__);
2531 ReleaseActCtx(handle);
2532 }
2533
2534 trace("UTF-16 manifest1, reverse endian, with BOM\n");
2535 if(!create_wide_manifest("test1.manifest", manifest1, TRUE, TRUE)) {
2536 skip("Could not create manifest file\n");
2537 return;
2538 }
2539
2540 handle = test_create("test1.manifest");
2541 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %lu\n", GetLastError());
2542 DeleteFileA("test1.manifest");
2543 if (handle != INVALID_HANDLE_VALUE) {
2544 test_basic_info(handle, __LINE__);
2545 test_detailed_info(handle, &detailed_info1, __LINE__);
2546 test_info_in_assembly(handle, 1, &manifest1_info, __LINE__);
2547 ReleaseActCtx(handle);
2548 }
2549
2550 /* Empty <assembly/> element. */
2551 create_manifest_file("empty_assembly.manifest", empty_assembly_manifest, -1, NULL, NULL);
2552 handle = test_create("empty_assembly.manifest");
2553 ok(handle != INVALID_HANDLE_VALUE, "Failed to create activation context.\n");
2554 DeleteFileA("empty_assembly.manifest");
2555 if (handle != INVALID_HANDLE_VALUE)
2556 {
2557 test_basic_info(handle, __LINE__);
2558 ReleaseActCtx(handle);
2559 }
2560
2561 test_wndclass_section();
2562 test_dllredirect_section();
2563 test_typelib_section();
2564 test_allowDelayedBinding();
2565}
2566
2567static void test_app_manifest(void)
2568{
2569 HANDLE handle;
2570 BOOL b;
2571
2572 trace("child process manifest1\n");
2573
2574 b = GetCurrentActCtx(&handle);
2575 ok(handle == NULL, "handle != NULL\n");
2576 ok(b, "GetCurrentActCtx failed: %lu\n", GetLastError());
2577 if(b) {
2578 test_basic_info(handle, __LINE__);
2579 test_detailed_info(handle, &detailed_info1_child, __LINE__);
2580 test_info_in_assembly(handle, 1, &manifest1_child_info, __LINE__);
2581 ReleaseActCtx(handle);
2582 }
2583}
2584
2585static HANDLE create_manifest(const char *filename, const char *data, int line)
2586{
2587 HANDLE handle;
2588 create_manifest_file(filename, data, -1, NULL, NULL);
2589
2590 handle = test_create(filename);
2591 ok_(__FILE__, line)(handle != INVALID_HANDLE_VALUE,
2592 "handle == INVALID_HANDLE_VALUE, error %lu\n", GetLastError());
2593
2594 DeleteFileA(filename);
2595 return handle;
2596}
2597
2598static void kernel32_find(ULONG section, const char *string_to_find, BOOL should_find, BOOL todo, int line)
2599{
2600 UNICODE_STRING string_to_findW;
2601 ACTCTX_SECTION_KEYED_DATA data;
2602 BOOL ret;
2603 DWORD err;
2604
2605 pRtlCreateUnicodeStringFromAsciiz(&string_to_findW, string_to_find);
2606
2607 memset(&data, 0xfe, sizeof(data));
2608 data.cbSize = sizeof(data);
2609
2610 SetLastError(0);
2611 ret = FindActCtxSectionStringA(0, NULL, section, string_to_find, &data);
2612 err = GetLastError();
2613 ok_(__FILE__, line)(ret == should_find,
2614 "FindActCtxSectionStringA: expected ret = %u, got %u\n", should_find, ret);
2615 todo_wine_if(todo)
2616 ok_(__FILE__, line)(err == (should_find ? ERROR_SUCCESS : ERROR_SXS_KEY_NOT_FOUND),
2617 "FindActCtxSectionStringA: unexpected error %lu\n", err);
2618
2619 memset(&data, 0xfe, sizeof(data));
2620 data.cbSize = sizeof(data);
2621
2622 SetLastError(0);
2623 ret = FindActCtxSectionStringW(0, NULL, section, string_to_findW.Buffer, &data);
2624 err = GetLastError();
2625 ok_(__FILE__, line)(ret == should_find,
2626 "FindActCtxSectionStringW: expected ret = %u, got %u\n", should_find, ret);
2627 todo_wine_if(todo)
2628 ok_(__FILE__, line)(err == (should_find ? ERROR_SUCCESS : ERROR_SXS_KEY_NOT_FOUND),
2629 "FindActCtxSectionStringW: unexpected error %lu\n", err);
2630
2631 SetLastError(0);
2632 ret = FindActCtxSectionStringA(0, NULL, section, string_to_find, NULL);
2633 err = GetLastError();
2634 ok_(__FILE__, line)(!ret,
2635 "FindActCtxSectionStringA: expected failure, got %u\n", ret);
2636 ok_(__FILE__, line)(err == ERROR_INVALID_PARAMETER,
2637 "FindActCtxSectionStringA: unexpected error %lu\n", err);
2638
2639 SetLastError(0);
2640 ret = FindActCtxSectionStringW(0, NULL, section, string_to_findW.Buffer, NULL);
2641 err = GetLastError();
2642 ok_(__FILE__, line)(!ret,
2643 "FindActCtxSectionStringW: expected failure, got %u\n", ret);
2644 ok_(__FILE__, line)(err == ERROR_INVALID_PARAMETER,
2645 "FindActCtxSectionStringW: unexpected error %lu\n", err);
2646
2647 pRtlFreeUnicodeString(&string_to_findW);
2648}
2649
2650static void ntdll_find(ULONG section, const char *string_to_find, BOOL should_find, BOOL todo, int line)
2651{
2652 UNICODE_STRING string_to_findW;
2653 ACTCTX_SECTION_KEYED_DATA data;
2654 NTSTATUS ret;
2655
2656 pRtlCreateUnicodeStringFromAsciiz(&string_to_findW, string_to_find);
2657
2658 memset(&data, 0xfe, sizeof(data));
2659 data.cbSize = sizeof(data);
2660
2661 ret = pRtlFindActivationContextSectionString(0, NULL, section, &string_to_findW, &data);
2662 todo_wine_if(todo)
2663 ok_(__FILE__, line)(ret == (should_find ? STATUS_SUCCESS : STATUS_SXS_KEY_NOT_FOUND),
2664 "RtlFindActivationContextSectionString: unexpected status 0x%lx\n", ret);
2665
2666 ret = pRtlFindActivationContextSectionString(0, NULL, section, &string_to_findW, NULL);
2667 todo_wine_if(todo)
2668 ok_(__FILE__, line)(ret == (should_find ? STATUS_SUCCESS : STATUS_SXS_KEY_NOT_FOUND),
2669 "RtlFindActivationContextSectionString: unexpected status 0x%lx\n", ret);
2670
2671 pRtlFreeUnicodeString(&string_to_findW);
2672}
2673
2674static void test_findsectionstring(void)
2675{
2676 HANDLE handle;
2677 BOOL ret;
2678 ULONG_PTR cookie;
2679
2680 handle = create_manifest("test.manifest", testdep_manifest3, __LINE__);
2681 ret = ActivateActCtx(handle, &cookie);
2682 ok(ret, "ActivateActCtx failed: %lu\n", GetLastError());
2683
2684 /* first we show the parameter validation from kernel32 */
2685 kernel32_find(ACTIVATION_CONTEXT_SECTION_ASSEMBLY_INFORMATION, "testdep", FALSE, TRUE, __LINE__);
2686 kernel32_find(ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION, "testlib.dll", TRUE, FALSE, __LINE__);
2687 kernel32_find(ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION, "testlib2.dll", TRUE, FALSE, __LINE__);
2688 kernel32_find(ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION, "testlib3.dll", FALSE, FALSE, __LINE__);
2689 kernel32_find(ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION, "wndClass", TRUE, FALSE, __LINE__);
2690 kernel32_find(ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION, "wndClass2", TRUE, FALSE, __LINE__);
2691 kernel32_find(ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION, "wndClass3", FALSE, FALSE, __LINE__);
2692
2693 /* then we show that ntdll plays by different rules */
2694 ntdll_find(ACTIVATION_CONTEXT_SECTION_ASSEMBLY_INFORMATION, "testdep", FALSE, TRUE, __LINE__);
2695 ntdll_find(ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION, "testlib.dll", TRUE, FALSE, __LINE__);
2696 ntdll_find(ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION, "testlib2.dll", TRUE, FALSE, __LINE__);
2697 ntdll_find(ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION, "testlib3.dll", FALSE, FALSE, __LINE__);
2698 ntdll_find(ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION, "wndClass", TRUE, FALSE, __LINE__);
2699 ntdll_find(ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION, "wndClass2", TRUE, FALSE, __LINE__);
2700 ntdll_find(ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION, "wndClass3", FALSE, FALSE, __LINE__);
2701
2702#ifdef __REACTOS__
2703 if (is_reactos()) {
2704 trace("HACK: ReactOS crashes on DeactivateActCtx() below.\n");
2705 ret = FALSE;
2706 } else
2707#endif
2708 ret = DeactivateActCtx(0, cookie);
2709 ok(ret, "DeactivateActCtx failed: %lu\n", GetLastError());
2710 ReleaseActCtx(handle);
2711}
2712
2713static void run_child_process(void)
2714{
2715 char cmdline[MAX_PATH];
2716 char path[MAX_PATH];
2717 char **argv;
2718 PROCESS_INFORMATION pi;
2719 STARTUPINFOA si = { 0 };
2720 HANDLE file;
2721 FILETIME now;
2722 BOOL ret;
2723
2724 GetModuleFileNameA(NULL, path, MAX_PATH);
2725 strcat(path, ".manifest");
2726 if(!create_manifest_file(path, manifest1, -1, NULL, NULL)) {
2727 skip("Could not create manifest file\n");
2728 return;
2729 }
2730
2731 si.cb = sizeof(si);
2732 winetest_get_mainargs( &argv );
2733 /* Vista+ seems to cache presence of .manifest files. Change last modified
2734 date to defeat the cache */
2735 file = CreateFileA(argv[0], FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE,
2736 NULL, OPEN_EXISTING, 0, NULL);
2737 if (file != INVALID_HANDLE_VALUE) {
2738 GetSystemTimeAsFileTime(&now);
2739 SetFileTime(file, NULL, NULL, &now);
2740 CloseHandle(file);
2741 }
2742 sprintf(cmdline, "\"%s\" %s manifest1", argv[0], argv[1]);
2743 ret = CreateProcessA(argv[0], cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
2744 ok(ret, "Could not create process: %lu\n", GetLastError());
2745 wait_child_process( pi.hProcess );
2746 CloseHandle(pi.hThread);
2747 CloseHandle(pi.hProcess);
2748 DeleteFileA(path);
2749}
2750
2751static void init_paths(void)
2752{
2753 LPWSTR ptr;
2754
2755 static const WCHAR dot_manifest[] = {'.','M','a','n','i','f','e','s','t',0};
2756 static const WCHAR backslash[] = {'\\',0};
2757 static const WCHAR subdir[] = {'T','e','s','t','S','u','b','d','i','r','\\',0};
2758
2759 GetModuleFileNameW(NULL, exe_path, ARRAY_SIZE(exe_path));
2760 lstrcpyW(app_dir, exe_path);
2761 for(ptr=app_dir+lstrlenW(app_dir); *ptr != '\\' && *ptr != '/'; ptr--);
2762 ptr[1] = 0;
2763
2764 GetCurrentDirectoryW(MAX_PATH, work_dir);
2765 ptr = work_dir + lstrlenW( work_dir ) - 1;
2766 if (*ptr != '\\' && *ptr != '/')
2767 lstrcatW(work_dir, backslash);
2768 lstrcpyW(work_dir_subdir, work_dir);
2769 lstrcatW(work_dir_subdir, subdir);
2770
2771 GetModuleFileNameW(NULL, app_manifest_path, ARRAY_SIZE(app_manifest_path));
2772 lstrcpyW(app_manifest_path+lstrlenW(app_manifest_path), dot_manifest);
2773}
2774
2775static void write_manifest(const char *filename, const char *manifest)
2776{
2777 HANDLE file;
2778 DWORD size;
2779 CHAR path[MAX_PATH];
2780
2781 GetTempPathA(ARRAY_SIZE(path), path);
2782 strcat(path, filename);
2783
2784 file = CreateFileA(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
2785 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %lu\n", GetLastError());
2786 WriteFile(file, manifest, strlen(manifest), &size, NULL);
2787 CloseHandle(file);
2788}
2789
2790static void delete_manifest_file(const char *filename)
2791{
2792 CHAR path[MAX_PATH];
2793
2794 GetTempPathA(ARRAY_SIZE(path), path);
2795 strcat(path, filename);
2796 DeleteFileA(path);
2797}
2798
2799static void extract_resource(const char *name, const char *type, const char *path)
2800{
2801 DWORD written;
2802 HANDLE file;
2803 HRSRC res;
2804 void *ptr;
2805
2806 file = CreateFileA(path, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
2807 ok(file != INVALID_HANDLE_VALUE, "file creation failed, at %s, error %ld\n", path, GetLastError());
2808
2809 res = FindResourceA(NULL, name, type);
2810 ok( res != 0, "couldn't find resource\n" );
2811 ptr = LockResource( LoadResource( GetModuleHandleA(NULL), res ));
2812 WriteFile( file, ptr, SizeofResource( GetModuleHandleA(NULL), res ), &written, NULL );
2813 ok( written == SizeofResource( GetModuleHandleA(NULL), res ), "couldn't write resource\n" );
2814 CloseHandle( file );
2815}
2816
2817static void test_CreateActCtx(void)
2818{
2819 static const DWORD flags[] = {LOAD_LIBRARY_AS_DATAFILE, LOAD_LIBRARY_AS_IMAGE_RESOURCE,
2820 LOAD_LIBRARY_AS_IMAGE_RESOURCE | LOAD_LIBRARY_AS_DATAFILE};
2821 static const struct
2822 {
2823 DWORD size, flags, error;
2824 } test[] =
2825 {
2826 { FIELD_OFFSET(ACTCTXW, lpSource), 0, ERROR_INVALID_PARAMETER },
2827 { FIELD_OFFSET(ACTCTXW, wProcessorArchitecture), 0, 0 },
2828 { FIELD_OFFSET(ACTCTXW, lpAssemblyDirectory), ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID, ERROR_INVALID_PARAMETER },
2829 { FIELD_OFFSET(ACTCTXW, lpResourceName), ACTCTX_FLAG_RESOURCE_NAME_VALID, ERROR_INVALID_PARAMETER },
2830 { FIELD_OFFSET(ACTCTXW, hModule), ACTCTX_FLAG_RESOURCE_NAME_VALID | ACTCTX_FLAG_HMODULE_VALID, ERROR_INVALID_PARAMETER },
2831 };
2832 char path[MAX_PATH], dir[MAX_PATH], dll[MAX_PATH], source[MAX_PATH];
2833 WCHAR pathW[MAX_PATH], dirW[MAX_PATH], sourceW[MAX_PATH];
2834 ACTCTXA actctx;
2835 ACTCTXW ctxW;
2836 HANDLE handle;
2837 int i;
2838
2839 GetTempPathA(ARRAY_SIZE(path), path);
2840 strcpy(dir, path);
2841 strcat(path, "main_wndcls.manifest");
2842
2843 write_manifest("testdep1.manifest", manifest_wndcls1);
2844 write_manifest("testdep2.manifest", manifest_wndcls2);
2845 write_manifest("main_wndcls.manifest", manifest_wndcls_main);
2846
2847 GetModuleFileNameA(NULL, source, ARRAY_SIZE(source));
2848 GetModuleFileNameW(NULL, sourceW, ARRAY_SIZE(sourceW));
2849
2850 GetTempPathW(ARRAY_SIZE(pathW), pathW);
2851 wcscpy(dirW, pathW);
2852 wcscat(pathW, L"main_wndcls.manifest");
2853
2854 memset(&ctxW, 0, sizeof(ctxW));
2855 ctxW.cbSize = sizeof(ctxW);
2856 ctxW.dwFlags = ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID | ACTCTX_FLAG_RESOURCE_NAME_VALID | ACTCTX_FLAG_HMODULE_VALID;
2857 ctxW.lpSource = pathW;
2858 ctxW.lpAssemblyDirectory = dirW;
2859 ctxW.lpResourceName = (LPWSTR)124;
2860 ctxW.hModule = GetModuleHandleW(NULL);
2861 handle = CreateActCtxW(&ctxW);
2862 ok(handle != INVALID_HANDLE_VALUE, "CreateActCtx error %lu\n", GetLastError());
2863 ReleaseActCtx(handle);
2864
2865 for (i = 0; i < ARRAY_SIZE(test); i++)
2866 {
2867 winetest_push_context("%i", i);
2868 ctxW.cbSize = test[i].size;
2869 ctxW.dwFlags = test[i].flags;
2870 SetLastError(0xdeadbeef);
2871 handle = CreateActCtxW(&ctxW);
2872 if (!test[i].error)
2873 {
2874 ok(handle != INVALID_HANDLE_VALUE, "CreateActCtx error %lu\n", GetLastError());
2875 ReleaseActCtx(handle);
2876 }
2877 else
2878 {
2879 ok(handle == INVALID_HANDLE_VALUE, "CreateActCtx should fail\n");
2880 ok(test[i].error == GetLastError(), "expected %lu, got %lu\n", test[i].error, GetLastError());
2881 }
2882
2883 ctxW.cbSize += sizeof(void *);
2884 if ((ctxW.dwFlags & (ACTCTX_FLAG_RESOURCE_NAME_VALID | ACTCTX_FLAG_HMODULE_VALID)) == ACTCTX_FLAG_RESOURCE_NAME_VALID)
2885 ctxW.lpSource = sourceW; /* source without hModule must point to valid PE */
2886 SetLastError(0xdeadbeef);
2887 handle = CreateActCtxW(&ctxW);
2888 ok(handle != INVALID_HANDLE_VALUE, "CreateActCtx error %lu\n", GetLastError());
2889 ReleaseActCtx(handle);
2890
2891 winetest_pop_context();
2892 }
2893
2894 memset(&actctx, 0, sizeof(actctx));
2895 actctx.cbSize = sizeof(actctx);
2896 actctx.dwFlags = ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID | ACTCTX_FLAG_RESOURCE_NAME_VALID | ACTCTX_FLAG_HMODULE_VALID;
2897 actctx.lpSource = path;
2898 actctx.lpAssemblyDirectory = dir;
2899 actctx.lpResourceName = (LPSTR)124;
2900 actctx.hModule = GetModuleHandleW(NULL);
2901 handle = CreateActCtxA(&actctx);
2902 ok(handle != INVALID_HANDLE_VALUE, "CreateActCtx error %lu\n", GetLastError());
2903 ReleaseActCtx(handle);
2904
2905 for (i = 0; i < ARRAY_SIZE(test); i++)
2906 {
2907 winetest_push_context("%i", i);
2908 actctx.cbSize = test[i].size;
2909 actctx.dwFlags = test[i].flags;
2910 SetLastError(0xdeadbeef);
2911 handle = CreateActCtxA(&actctx);
2912 if (!test[i].error)
2913 {
2914 ok(handle != INVALID_HANDLE_VALUE, "CreateActCtx error %lu\n", GetLastError());
2915 ReleaseActCtx(handle);
2916 }
2917 else
2918 {
2919 ok(handle == INVALID_HANDLE_VALUE, "CreateActCtx should fail\n");
2920 ok(test[i].error == GetLastError(), "expected %lu, got %lu\n", test[i].error, GetLastError());
2921 }
2922
2923 actctx.cbSize += sizeof(void *);
2924 if ((actctx.dwFlags & (ACTCTX_FLAG_RESOURCE_NAME_VALID | ACTCTX_FLAG_HMODULE_VALID)) == ACTCTX_FLAG_RESOURCE_NAME_VALID)
2925 actctx.lpSource = source; /* source without hModule must point to valid PE */
2926 SetLastError(0xdeadbeef);
2927 handle = CreateActCtxA(&actctx);
2928 ok(handle != INVALID_HANDLE_VALUE, "CreateActCtx error %lu\n", GetLastError());
2929 ReleaseActCtx(handle);
2930
2931 winetest_pop_context();
2932 }
2933
2934 memset(&actctx, 0, sizeof(ACTCTXA));
2935 actctx.cbSize = sizeof(ACTCTXA);
2936 actctx.lpSource = path;
2937
2938 /* create using lpSource without specified directory */
2939 handle = CreateActCtxA(&actctx);
2940 ok(handle != INVALID_HANDLE_VALUE, "failed to generate context, error %lu\n", GetLastError());
2941 ReleaseActCtx(handle);
2942
2943 /* with specified directory, that doesn't contain dependent assembly */
2944 GetWindowsDirectoryA(dir, ARRAY_SIZE(dir));
2945
2946 memset(&actctx, 0, sizeof(ACTCTXA));
2947 actctx.cbSize = sizeof(ACTCTXA);
2948 actctx.dwFlags = ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID;
2949 actctx.lpAssemblyDirectory = dir;
2950 actctx.lpSource = path;
2951
2952 SetLastError(0xdeadbeef);
2953 handle = CreateActCtxA(&actctx);
2954todo_wine {
2955 ok(handle == INVALID_HANDLE_VALUE, "got handle %p\n", handle);
2956 ok(GetLastError() == ERROR_SXS_CANT_GEN_ACTCTX, "got error %ld\n", GetLastError());
2957}
2958 if (handle != INVALID_HANDLE_VALUE) ReleaseActCtx(handle);
2959
2960 /* with specified directory, that does contain dependent assembly */
2961 GetTempPathA(ARRAY_SIZE(dir), dir);
2962 actctx.lpAssemblyDirectory = dir;
2963 handle = CreateActCtxA(&actctx);
2964 ok(handle != INVALID_HANDLE_VALUE, "got handle %p\n", handle);
2965 ReleaseActCtx(handle);
2966
2967 /* Should still work if we add a dll with the same name, but without manifest */
2968 strcpy(dll, dir);
2969 strcat(dll, "testdep1.dll");
2970 extract_resource("dummy.dll", "TESTDLL", dll);
2971 handle = CreateActCtxA(&actctx);
2972 ok(handle != INVALID_HANDLE_VALUE || broken(GetLastError() == ERROR_SXS_CANT_GEN_ACTCTX) , "got error %ld\n", GetLastError());
2973 ReleaseActCtx(handle);
2974 DeleteFileA(dll);
2975
2976 delete_manifest_file("main_wndcls.manifest");
2977 delete_manifest_file("testdep1.manifest");
2978 delete_manifest_file("testdep2.manifest");
2979
2980 /* create from HMODULE - resource doesn't exist, lpSource is set */
2981 memset(&actctx, 0, sizeof(ACTCTXA));
2982 actctx.cbSize = sizeof(ACTCTXA);
2983 actctx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID | ACTCTX_FLAG_HMODULE_VALID;
2984 actctx.lpSource = "dummyfile.dll";
2985 actctx.lpResourceName = MAKEINTRESOURCEA(20);
2986 actctx.hModule = GetModuleHandleA(NULL);
2987
2988 SetLastError(0xdeadbeef);
2989 handle = CreateActCtxA(&actctx);
2990 ok(handle == INVALID_HANDLE_VALUE, "got handle %p\n", handle);
2991 ok(GetLastError() == ERROR_RESOURCE_NAME_NOT_FOUND, "got error %ld\n", GetLastError());
2992
2993 /* load manifest from lpAssemblyDirectory directory */
2994 write_manifest("testdir.manifest", manifest1);
2995 GetTempPathA(ARRAY_SIZE(path), path);
2996 SetCurrentDirectoryA(path);
2997 strcat(path, "assembly_dir");
2998 strcpy(dir, path);
2999 strcat(path, "\\testdir.manifest");
3000
3001 memset(&actctx, 0, sizeof(actctx));
3002 actctx.cbSize = sizeof(actctx);
3003 actctx.dwFlags = ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID;
3004 actctx.lpSource = "testdir.manifest";
3005 actctx.lpAssemblyDirectory = dir;
3006
3007 SetLastError(0xdeadbeef);
3008 handle = CreateActCtxA(&actctx);
3009 ok(handle == INVALID_HANDLE_VALUE, "got handle %p\n", handle);
3010 ok(GetLastError()==ERROR_PATH_NOT_FOUND ||
3011 broken(GetLastError()==ERROR_FILE_NOT_FOUND) /* WinXP */,
3012 "got error %ld\n", GetLastError());
3013
3014 CreateDirectoryA(dir, NULL);
3015 memset(&actctx, 0, sizeof(actctx));
3016 actctx.cbSize = sizeof(actctx);
3017 actctx.dwFlags = ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID;
3018 actctx.lpSource = "testdir.manifest";
3019 actctx.lpAssemblyDirectory = dir;
3020
3021 SetLastError(0xdeadbeef);
3022 handle = CreateActCtxA(&actctx);
3023 ok(handle == INVALID_HANDLE_VALUE, "got handle %p\n", handle);
3024 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "got error %ld\n", GetLastError());
3025 SetCurrentDirectoryW(work_dir);
3026
3027 write_manifest("assembly_dir\\testdir.manifest", manifest1);
3028 memset(&actctx, 0, sizeof(actctx));
3029 actctx.cbSize = sizeof(actctx);
3030 actctx.dwFlags = ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID;
3031 actctx.lpSource = "testdir.manifest";
3032 actctx.lpAssemblyDirectory = dir;
3033
3034 handle = CreateActCtxA(&actctx);
3035 ok(handle != INVALID_HANDLE_VALUE, "got handle %p\n", handle);
3036 ReleaseActCtx(handle);
3037
3038 memset(&actctx, 0, sizeof(actctx));
3039 actctx.cbSize = sizeof(actctx);
3040 actctx.dwFlags = ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID;
3041 actctx.lpSource = path;
3042 actctx.lpAssemblyDirectory = dir;
3043
3044 handle = CreateActCtxA(&actctx);
3045 ok(handle != INVALID_HANDLE_VALUE, "got handle %p\n", handle);
3046 ReleaseActCtx(handle);
3047
3048 delete_manifest_file("testdir.manifest");
3049 delete_manifest_file("assembly_dir\\testdir.manifest");
3050 RemoveDirectoryA(dir);
3051
3052 /* create using lpSource with a DLL relative name */
3053 memset(&actctx, 0, sizeof(actctx));
3054 actctx.cbSize = sizeof(actctx);
3055 actctx.lpSource = "shell32.dll";
3056 actctx.lpResourceName = MAKEINTRESOURCEA(124);
3057 actctx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID;
3058 handle = CreateActCtxA(&actctx);
3059 ok(handle == INVALID_HANDLE_VALUE, "CreateActCtxA succeeded\n");
3060
3061 /* create from module loaded as data file */
3062 memset(&actctx, 0, sizeof(actctx));
3063 actctx.cbSize = sizeof(actctx);
3064 actctx.lpResourceName = MAKEINTRESOURCEA(1);
3065 actctx.dwFlags = ACTCTX_FLAG_HMODULE_VALID | ACTCTX_FLAG_RESOURCE_NAME_VALID;
3066#ifdef __REACTOS__
3067 char path_explorer[MAX_PATH];
3068 GetWindowsDirectoryA(path_explorer, sizeof(path_explorer));
3069 strcat(path_explorer, "\\explorer.exe");
3070#endif
3071 for (i = 0; i < ARRAY_SIZE(flags); ++i)
3072 {
3073 winetest_push_context("%lu", flags[i]);
3074
3075 /* use explorer.exe because using modules already loaded has a different behavior */
3076#ifdef __REACTOS__
3077 if (GetNTVersion() < _WIN32_WINNT_VISTA && i > 0)
3078 break; // Only the first test is valid for WS03.
3079 actctx.hModule = LoadLibraryExA(path_explorer, NULL, flags[i]);
3080#else
3081 actctx.hModule = LoadLibraryExA("C:\\windows\\explorer.exe", NULL, flags[i]);
3082#endif
3083 ok(actctx.hModule != NULL, "LoadLibraryExA failed, error %lu\n", GetLastError());
3084 handle = CreateActCtxA(&actctx);
3085 ok(handle == INVALID_HANDLE_VALUE, "CreateActCtxA succeeded\n");
3086 FreeLibrary(actctx.hModule);
3087
3088 winetest_pop_context();
3089 }
3090}
3091
3092static void test_CreateActCtx_share_mode(void)
3093{
3094 WCHAR tmp_manifest_pathname[MAX_PATH];
3095 HANDLE handle, manifest_file;
3096 ACTCTXW actctx;
3097
3098 manifest_file = create_temp_manifest_file(manifest1, tmp_manifest_pathname);
3099
3100 memset(&actctx, 0, sizeof(ACTCTXW));
3101 actctx.cbSize = sizeof(ACTCTXW);
3102 actctx.lpSource = tmp_manifest_pathname;
3103
3104 handle = CreateActCtxW(&actctx);
3105#ifdef __REACTOS__
3106 ok(handle != INVALID_HANDLE_VALUE || GetLastError() == ERROR_SHARING_VIOLATION /* WS03 */, "CreateActCtxW returned error %lu\n", GetLastError());
3107#else
3108 ok(handle != INVALID_HANDLE_VALUE, "CreateActCtxW returned error %lu\n", GetLastError());
3109#endif
3110 ok(handle != NULL, "CreateActCtxW returned %p\n", handle);
3111
3112 ReleaseActCtx(handle);
3113
3114 CloseHandle(manifest_file);
3115}
3116
3117static BOOL init_funcs(void)
3118{
3119 HMODULE hLibrary = GetModuleHandleA("kernel32.dll");
3120
3121#define X(f) if (!(p##f = (void*)GetProcAddress(hLibrary, #f))) return FALSE;
3122 pQueryActCtxSettingsW = (void *)GetProcAddress( hLibrary, "QueryActCtxSettingsW" );
3123
3124 hLibrary = GetModuleHandleA("ntdll.dll");
3125 X(RtlFindActivationContextSectionString);
3126 X(RtlCreateUnicodeStringFromAsciiz);
3127 X(RtlFreeUnicodeString);
3128#undef X
3129
3130 return TRUE;
3131}
3132
3133static void test_ZombifyActCtx(void)
3134{
3135 ACTIVATION_CONTEXT_BASIC_INFORMATION basicinfo;
3136 ULONG_PTR cookie;
3137 HANDLE handle, current;
3138 BOOL ret;
3139
3140 SetLastError(0xdeadbeef);
3141 ret = ZombifyActCtx(NULL);
3142 todo_wine
3143 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "got %d, error %ld\n", ret, GetLastError());
3144
3145 handle = create_manifest("test.manifest", testdep_manifest3, __LINE__);
3146
3147 ret = GetCurrentActCtx(¤t);
3148 ok(ret, "got %d, error %ld\n", ret, GetLastError());
3149 ok(current == NULL, "got %p\n", current);
3150
3151 ret = ActivateActCtx(handle, &cookie);
3152 ok(ret, "ActivateActCtx failed: %lu\n", GetLastError());
3153
3154 ret = GetCurrentActCtx(¤t);
3155 ok(ret, "got %d, error %ld\n", ret, GetLastError());
3156 ok(handle == current, "got %p, %p\n", current, handle);
3157
3158 memset(&basicinfo, 0xff, sizeof(basicinfo));
3159 ret = QueryActCtxW(0, handle, 0, ActivationContextBasicInformation, &basicinfo, sizeof(basicinfo), NULL);
3160 ok(ret, "got %d, error %ld\n", ret, GetLastError());
3161 ok(basicinfo.hActCtx == handle, "got %p\n", basicinfo.hActCtx);
3162 ok(basicinfo.dwFlags == 0, "got %lx\n", basicinfo.dwFlags);
3163
3164 memset(&basicinfo, 0xff, sizeof(basicinfo));
3165 ret = QueryActCtxW(QUERY_ACTCTX_FLAG_USE_ACTIVE_ACTCTX, NULL, 0, ActivationContextBasicInformation,
3166 &basicinfo, sizeof(basicinfo), NULL);
3167 ok(ret, "got %d, error %ld\n", ret, GetLastError());
3168 ok(basicinfo.hActCtx == handle, "got %p\n", basicinfo.hActCtx);
3169 ok(basicinfo.dwFlags == 0, "got %lx\n", basicinfo.dwFlags);
3170
3171 ret = ZombifyActCtx(handle);
3172 todo_wine
3173 ok(ret, "got %d\n", ret);
3174
3175 memset(&basicinfo, 0xff, sizeof(basicinfo));
3176 ret = QueryActCtxW(0, handle, 0, ActivationContextBasicInformation, &basicinfo, sizeof(basicinfo), NULL);
3177 ok(ret, "got %d, error %ld\n", ret, GetLastError());
3178 ok(basicinfo.hActCtx == handle, "got %p\n", basicinfo.hActCtx);
3179 ok(basicinfo.dwFlags == 0, "got %lx\n", basicinfo.dwFlags);
3180
3181 memset(&basicinfo, 0xff, sizeof(basicinfo));
3182 ret = QueryActCtxW(QUERY_ACTCTX_FLAG_USE_ACTIVE_ACTCTX, NULL, 0, ActivationContextBasicInformation,
3183 &basicinfo, sizeof(basicinfo), NULL);
3184 ok(ret, "got %d, error %ld\n", ret, GetLastError());
3185 ok(basicinfo.hActCtx == handle, "got %p\n", basicinfo.hActCtx);
3186 ok(basicinfo.dwFlags == 0, "got %lx\n", basicinfo.dwFlags);
3187
3188 ret = GetCurrentActCtx(¤t);
3189 ok(ret, "got %d, error %ld\n", ret, GetLastError());
3190 ok(current == handle, "got %p\n", current);
3191
3192 /* one more time */
3193 ret = ZombifyActCtx(handle);
3194 todo_wine
3195 ok(ret, "got %d\n", ret);
3196
3197#ifdef __REACTOS__
3198 if (is_reactos()) {
3199 trace("HACK: ReactOS crashes on DeactivateActCtx() below.\n");
3200 ret = FALSE;
3201 } else
3202#endif
3203 ret = DeactivateActCtx(0, cookie);
3204 ok(ret, "DeactivateActCtx failed: %lu\n", GetLastError());
3205 ReleaseActCtx(handle);
3206}
3207
3208/* Test structure to verify alignment */
3209typedef struct _test_act_ctx_compat_info {
3210 DWORD ElementCount;
3211 COMPATIBILITY_CONTEXT_ELEMENT Elements[10];
3212} test_act_ctx_compat_info;
3213
3214/* Win10 versions before 1909 don't have the MaxVersionTested field */
3215typedef struct
3216{
3217 GUID Id;
3218 ACTCTX_COMPATIBILITY_ELEMENT_TYPE Type;
3219} old_win10_COMPATIBILITY_CONTEXT_ELEMENT;
3220
3221typedef struct
3222{
3223 DWORD ElementCount;
3224 old_win10_COMPATIBILITY_CONTEXT_ELEMENT Elements[10];
3225} old_win10_test_act_ctx_compat_info;
3226
3227
3228static void test_no_compat(HANDLE handle, int line)
3229{
3230 test_act_ctx_compat_info compat_info;
3231 SIZE_T size;
3232 BOOL b;
3233
3234 memset(&compat_info, 0, sizeof(compat_info));
3235 b = QueryActCtxW(QUERY_ACTCTX_FLAG_NO_ADDREF, handle, NULL, CompatibilityInformationInActivationContext,
3236 &compat_info, sizeof(compat_info), &size);
3237
3238 ok_(__FILE__, line)(b, "CompatibilityInformationInActivationContext failed\n");
3239 ok_(__FILE__, line)(size == offsetof(test_act_ctx_compat_info,Elements[0]) ||
3240 broken(size == offsetof(old_win10_test_act_ctx_compat_info,Elements[0])),
3241 "size mismatch got %Iu\n", size);
3242 ok_(__FILE__, line)(compat_info.ElementCount == 0, "unexpected ElementCount %lu\n", compat_info.ElementCount);
3243}
3244
3245static void test_with_compat(HANDLE handle, DWORD num_compat, DWORD num_version,
3246 const GUID *expected_compat[], const ULONGLONG expected_version[], int line)
3247{
3248 test_act_ctx_compat_info compat_info;
3249 SIZE_T size;
3250 DWORD n;
3251 BOOL b;
3252
3253 memset(&compat_info, 0, sizeof(compat_info));
3254 b = QueryActCtxW(QUERY_ACTCTX_FLAG_NO_ADDREF, handle, NULL, CompatibilityInformationInActivationContext,
3255 &compat_info, sizeof(compat_info), &size);
3256
3257 ok_(__FILE__, line)(b, "CompatibilityInformationInActivationContext failed\n");
3258 ok_(__FILE__, line)(size == offsetof(test_act_ctx_compat_info,Elements[num_compat + num_version]) ||
3259 broken(size == offsetof(old_win10_test_act_ctx_compat_info,Elements[num_compat])),
3260 "size mismatch got %Iu\n", size);
3261 ok_(__FILE__, line)(compat_info.ElementCount == num_compat + num_version ||
3262 broken(compat_info.ElementCount == num_compat),
3263 "unexpected ElementCount %lu\n", compat_info.ElementCount);
3264
3265 if (size == offsetof(old_win10_test_act_ctx_compat_info,Elements[num_compat]))
3266 {
3267 for (n = 0; n < num_compat; ++n)
3268 {
3269 old_win10_test_act_ctx_compat_info *info = (old_win10_test_act_ctx_compat_info *)&compat_info;
3270 ok_(__FILE__, line)(IsEqualGUID(&info->Elements[n].Id, expected_compat[n]),
3271 "got wrong clsid %s, expected %s for %lu\n",
3272 wine_dbgstr_guid(&info->Elements[n].Id),
3273 wine_dbgstr_guid(expected_compat[n]),
3274 n);
3275 ok_(__FILE__, line)(info->Elements[n].Type == ACTCTX_COMPATIBILITY_ELEMENT_TYPE_OS,
3276 "Wrong type, got %lu for %lu\n", (DWORD)info->Elements[n].Type, n);
3277 }
3278 }
3279 else
3280 {
3281 for (n = 0; n < num_compat; ++n)
3282 {
3283 ok_(__FILE__, line)(IsEqualGUID(&compat_info.Elements[n].Id, expected_compat[n]),
3284 "got wrong clsid %s, expected %s for %lu\n",
3285 wine_dbgstr_guid(&compat_info.Elements[n].Id),
3286 wine_dbgstr_guid(expected_compat[n]),
3287 n);
3288 ok_(__FILE__, line)(compat_info.Elements[n].Type == ACTCTX_COMPATIBILITY_ELEMENT_TYPE_OS,
3289 "Wrong type, got %lu for %lu\n", (DWORD)compat_info.Elements[n].Type, n);
3290 }
3291 for (; n < num_compat + num_version; ++n)
3292 {
3293 ok_(__FILE__, line)(compat_info.Elements[n].Type == ACTCTX_COMPATIBILITY_ELEMENT_TYPE_MAXVERSIONTESTED,
3294 "Wrong type, got %lu for %lu\n", (DWORD)compat_info.Elements[n].Type, n);
3295 ok_(__FILE__, line)(compat_info.Elements[n].MaxVersionTested == expected_version[n - num_compat],
3296 "Wrong version, got %s for %lu\n", wine_dbgstr_longlong(compat_info.Elements[n].MaxVersionTested), n);
3297 }
3298 }
3299}
3300
3301static void test_compatibility(void)
3302{
3303 HANDLE handle;
3304
3305 /* No compat results returned */
3306 trace("manifest1\n");
3307 if(!create_manifest_file("test1.manifest", manifest1, -1, NULL, NULL))
3308 {
3309 skip("Could not create manifest file\n");
3310 return;
3311 }
3312 handle = test_create("test1.manifest");
3313 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %lu\n", GetLastError());
3314 DeleteFileA("test1.manifest");
3315 if(handle != INVALID_HANDLE_VALUE)
3316 {
3317 char buffer[sizeof(COMPATIBILITY_CONTEXT_ELEMENT) * 2 + sizeof(DWORD)];
3318 SIZE_T size;
3319 BOOL b;
3320
3321 memset(buffer, 0, sizeof(buffer));
3322 b = QueryActCtxW(QUERY_ACTCTX_FLAG_NO_ADDREF, handle, NULL, CompatibilityInformationInActivationContext,
3323 buffer, sizeof(buffer), &size);
3324
3325 if (!b && GetLastError() == ERROR_INVALID_PARAMETER)
3326 {
3327 win_skip("CompatibilityInformationInActivationContext not supported.\n");
3328 ReleaseActCtx(handle);
3329 return;
3330 }
3331
3332 test_basic_info(handle, __LINE__);
3333 test_no_compat(handle, __LINE__);
3334 ReleaseActCtx(handle);
3335 }
3336
3337 /* Still no compat results returned */
3338 trace("no_supportedOs\n");
3339 if(!create_manifest_file("no_supportedOs.manifest", compat_manifest_no_supportedOs, -1, NULL, NULL))
3340 {
3341 skip("Could not create manifest file\n");
3342 return;
3343 }
3344 handle = test_create("no_supportedOs.manifest");
3345 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %lu\n", GetLastError());
3346 DeleteFileA("no_supportedOs.manifest");
3347 if(handle != INVALID_HANDLE_VALUE)
3348 {
3349 test_basic_info(handle, __LINE__);
3350 test_no_compat(handle, __LINE__);
3351 ReleaseActCtx(handle);
3352 }
3353
3354 /* Just one result returned */
3355 trace("manifest_vista\n");
3356 if(!create_manifest_file("manifest_vista.manifest", compat_manifest_vista, -1, NULL, NULL))
3357 {
3358 skip("Could not create manifest file\n");
3359 return;
3360 }
3361 handle = test_create("manifest_vista.manifest");
3362 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %lu\n", GetLastError());
3363 DeleteFileA("manifest_vista.manifest");
3364 if(handle != INVALID_HANDLE_VALUE)
3365 {
3366 static const GUID* expect_manifest[] =
3367 {
3368 &VISTA_COMPAT_GUID
3369 };
3370 test_basic_info(handle, __LINE__);
3371 test_with_compat(handle, 1, 0, expect_manifest, NULL, __LINE__);
3372 ReleaseActCtx(handle);
3373 }
3374
3375 /* Show that the order is retained */
3376 trace("manifest_vista_7_8_10_81\n");
3377 if(!create_manifest_file("manifest_vista_7_8_10_81.manifest", compat_manifest_vista_7_8_10_81, -1, NULL, NULL))
3378 {
3379 skip("Could not create manifest file\n");
3380 return;
3381 }
3382 handle = test_create("manifest_vista_7_8_10_81.manifest");
3383 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %lu\n", GetLastError());
3384 DeleteFileA("manifest_vista_7_8_10_81.manifest");
3385 if(handle != INVALID_HANDLE_VALUE)
3386 {
3387 static const GUID* expect_manifest[] =
3388 {
3389 &VISTA_COMPAT_GUID,
3390 &WIN7_COMPAT_GUID,
3391 &WIN8_COMPAT_GUID,
3392 &WIN10_COMPAT_GUID,
3393 &WIN81_COMPAT_GUID,
3394 };
3395 static const ULONGLONG expect_version[] =
3396 {
3397 0x000a000047b60000ull, /* 10.0.18358.0 */
3398 0x0002000300040005ull, /* 2.3.4.5 */
3399 };
3400 test_basic_info(handle, __LINE__);
3401 test_with_compat(handle, 5, 2, expect_manifest, expect_version, __LINE__);
3402 ReleaseActCtx(handle);
3403 }
3404
3405 /* Show that even unknown GUID's are stored */
3406 trace("manifest_other_guid\n");
3407 if(!create_manifest_file("manifest_other_guid.manifest", compat_manifest_other_guid, -1, NULL, NULL))
3408 {
3409 skip("Could not create manifest file\n");
3410 return;
3411 }
3412 handle = test_create("manifest_other_guid.manifest");
3413 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %lu\n", GetLastError());
3414 DeleteFileA("manifest_other_guid.manifest");
3415 if(handle != INVALID_HANDLE_VALUE)
3416 {
3417 static const GUID* expect_manifest[] =
3418 {
3419 &OTHER_COMPAT_GUID,
3420 };
3421 test_basic_info(handle, __LINE__);
3422 test_with_compat(handle, 1, 0, expect_manifest, NULL, __LINE__);
3423 ReleaseActCtx(handle);
3424 }
3425}
3426
3427static void test_settings(void)
3428{
3429 static const WCHAR dpiAwareW[] = {'d','p','i','A','w','a','r','e',0};
3430 static const WCHAR dpiAwarenessW[] = {'d','p','i','A','w','a','r','e','n','e','s','s',0};
3431 static const WCHAR dummyW[] = {'d','u','m','m','y',0};
3432 static const WCHAR trueW[] = {'t','r','u','e',0};
3433 static const WCHAR namespace2005W[] = {'h','t','t','p',':','/','/','s','c','h','e','m','a','s','.','m','i','c','r','o','s','o','f','t','.','c','o','m','/','S','M','I','/','2','0','0','5','/','W','i','n','d','o','w','s','S','e','t','t','i','n','g','s',0};
3434 static const WCHAR namespace2016W[] = {'h','t','t','p',':','/','/','s','c','h','e','m','a','s','.','m','i','c','r','o','s','o','f','t','.','c','o','m','/','S','M','I','/','2','0','1','6','/','W','i','n','d','o','w','s','S','e','t','t','i','n','g','s',0};
3435 WCHAR buffer[80];
3436 SIZE_T size;
3437 HANDLE handle;
3438 BOOL ret;
3439
3440#if defined(__REACTOS__) && DLL_EXPORT_VERSION >= 0x600
3441 /* FIXME: QueryActCtxSettingsW() is a STUB on ReactOS. */
3442 if (is_reactos() || !pQueryActCtxSettingsW)
3443#else
3444 if (!pQueryActCtxSettingsW)
3445#endif
3446 {
3447 win_skip( "QueryActCtxSettingsW is missing\n" );
3448 return;
3449 }
3450 create_manifest_file( "manifest_settings.manifest", settings_manifest, -1, NULL, NULL );
3451 handle = test_create("manifest_settings.manifest");
3452 ok( handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %lu\n", GetLastError() );
3453 DeleteFileA( "manifest_settings.manifest" );
3454
3455 SetLastError( 0xdeadbeef );
3456 ret = pQueryActCtxSettingsW( 1, handle, NULL, dpiAwareW, buffer, 80, &size );
3457 ok( !ret, "QueryActCtxSettingsW failed err %lu\n", GetLastError() );
3458 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
3459 SetLastError( 0xdeadbeef );
3460 ret = pQueryActCtxSettingsW( 0, handle, dummyW, dpiAwareW, buffer, 80, &size );
3461 ok( !ret, "QueryActCtxSettingsW failed err %lu\n", GetLastError() );
3462 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
3463 SetLastError( 0xdeadbeef );
3464 size = 0xdead;
3465 memset( buffer, 0xcc, sizeof(buffer) );
3466 ret = pQueryActCtxSettingsW( 0, handle, NULL, dpiAwareW, buffer, 80, &size );
3467 ok( ret, "QueryActCtxSettingsW failed err %lu\n", GetLastError() );
3468 ok( !lstrcmpW( buffer, trueW ), "got %s\n", wine_dbgstr_w(buffer) );
3469 ok( size == lstrlenW( buffer ) + 1, "wrong len %Iu\n", size );
3470 SetLastError( 0xdeadbeef );
3471 size = 0xdead;
3472 memset( buffer, 0xcc, sizeof(buffer) );
3473 ret = pQueryActCtxSettingsW( 0, handle, NULL, dummyW, buffer, 80, &size );
3474 ok( !ret, "QueryActCtxSettingsW succeeded\n" );
3475 ok( GetLastError() == ERROR_SXS_KEY_NOT_FOUND, "wrong error %lu\n", GetLastError() );
3476 ok( buffer[0] == 0xcccc, "got %s\n", wine_dbgstr_w(buffer) );
3477 SetLastError( 0xdeadbeef );
3478 size = 0xdead;
3479 memset( buffer, 0xcc, sizeof(buffer) );
3480 ret = pQueryActCtxSettingsW( 0, handle, namespace2005W, dpiAwareW, buffer, 80, &size );
3481 ok( ret, "QueryActCtxSettingsW failed err %lu\n", GetLastError() );
3482 ok( !lstrcmpW( buffer, trueW ), "got %s\n", wine_dbgstr_w(buffer) );
3483 ok( size == ARRAY_SIZE(trueW), "wrong len %Iu\n", size );
3484 SetLastError( 0xdeadbeef );
3485 size = 0xdead;
3486 memset( buffer, 0xcc, sizeof(buffer) );
3487 ret = pQueryActCtxSettingsW( 0, handle, namespace2005W, dpiAwareW, buffer, lstrlenW(trueW) + 1, &size );
3488 ok( ret, "QueryActCtxSettingsW failed err %lu\n", GetLastError() );
3489 ok( !lstrcmpW( buffer, trueW ), "got %s\n", wine_dbgstr_w(buffer) );
3490 ok( size == ARRAY_SIZE(trueW), "wrong len %Iu\n", size );
3491 SetLastError( 0xdeadbeef );
3492 size = 0xdead;
3493 memset( buffer, 0xcc, sizeof(buffer) );
3494 ret = pQueryActCtxSettingsW( 0, handle, namespace2016W, dpiAwareW, buffer, lstrlenW(trueW) + 1, &size );
3495 ok( !ret, "QueryActCtxSettingsW succeeded\n" );
3496 ok( GetLastError() == ERROR_SXS_KEY_NOT_FOUND || broken( GetLastError() == ERROR_INVALID_PARAMETER ),
3497 "wrong error %lu\n", GetLastError() );
3498 ok( buffer[0] == 0xcccc, "got %s\n", wine_dbgstr_w(buffer) );
3499 SetLastError( 0xdeadbeef );
3500 size = 0xdead;
3501 memset( buffer, 0xcc, sizeof(buffer) );
3502 ret = pQueryActCtxSettingsW( 0, handle, NULL, dpiAwarenessW, buffer, lstrlenW(trueW) + 1, &size );
3503 ok( !ret, "QueryActCtxSettingsW succeeded\n" );
3504 ok( GetLastError() == ERROR_SXS_KEY_NOT_FOUND, "wrong error %lu\n", GetLastError() );
3505 ok( buffer[0] == 0xcccc, "got %s\n", wine_dbgstr_w(buffer) );
3506 SetLastError( 0xdeadbeef );
3507 size = 0xdead;
3508 memset( buffer, 0xcc, sizeof(buffer) );
3509 ret = pQueryActCtxSettingsW( 0, handle, namespace2005W, dpiAwarenessW, buffer, lstrlenW(trueW) + 1, &size );
3510 ok( !ret, "QueryActCtxSettingsW succeeded\n" );
3511 ok( GetLastError() == ERROR_SXS_KEY_NOT_FOUND, "wrong error %lu\n", GetLastError() );
3512 ok( buffer[0] == 0xcccc, "got %s\n", wine_dbgstr_w(buffer) );
3513 SetLastError( 0xdeadbeef );
3514 size = 0xdead;
3515 memset( buffer, 0xcc, sizeof(buffer) );
3516 ret = pQueryActCtxSettingsW( 0, handle, namespace2016W, dpiAwarenessW, buffer, lstrlenW(trueW) + 1, &size );
3517 ok( ret || broken( GetLastError() == ERROR_INVALID_PARAMETER ),
3518 "QueryActCtxSettingsW failed err %lu\n", GetLastError() );
3519 if (ret)
3520 {
3521 ok( !lstrcmpW( buffer, trueW ), "got %s\n", wine_dbgstr_w(buffer) );
3522 ok( size == ARRAY_SIZE(trueW), "wrong len %Iu\n", size );
3523 }
3524 else ok( buffer[0] == 0xcccc, "got %s\n", wine_dbgstr_w(buffer) );
3525 SetLastError( 0xdeadbeef );
3526 size = 0xdead;
3527 memset( buffer, 0xcc, sizeof(buffer) );
3528 ret = pQueryActCtxSettingsW( 0, handle, NULL, dpiAwareW, buffer, lstrlenW(trueW), &size );
3529 ok( ret, "QueryActCtxSettingsW failed err %lu\n", GetLastError() );
3530 ok( !lstrcmpW( buffer, trueW ), "got %s\n", wine_dbgstr_w(buffer) );
3531 ok( size == ARRAY_SIZE(trueW), "wrong len %Iu\n", size );
3532 SetLastError( 0xdeadbeef );
3533 size = 0xdead;
3534 memset( buffer, 0xcc, sizeof(buffer) );
3535 ret = pQueryActCtxSettingsW( 0, handle, NULL, dpiAwareW, buffer, lstrlenW(trueW) - 1, &size );
3536 ok( !ret, "QueryActCtxSettingsW failed err %lu\n", GetLastError() );
3537 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER, "wrong error %lu\n", GetLastError() );
3538 ok( buffer[0] == 0xcccc, "got %s\n", wine_dbgstr_w(buffer) );
3539 ok( size == ARRAY_SIZE(trueW), "wrong len %Iu\n", size );
3540 ReleaseActCtx(handle);
3541
3542 create_manifest_file( "manifest_settings2.manifest", settings_manifest2, -1, NULL, NULL );
3543 handle = test_create("manifest_settings2.manifest");
3544 ok( handle != INVALID_HANDLE_VALUE || broken( handle == INVALID_HANDLE_VALUE ), /* <= vista */
3545 "handle == INVALID_HANDLE_VALUE, error %lu\n", GetLastError() );
3546 DeleteFileA( "manifest_settings2.manifest" );
3547 if (handle != INVALID_HANDLE_VALUE)
3548 {
3549 SetLastError( 0xdeadbeef );
3550 size = 0xdead;
3551 memset( buffer, 0xcc, sizeof(buffer) );
3552 ret = pQueryActCtxSettingsW( 0, handle, NULL, dpiAwareW, buffer, 80, &size );
3553 ok( ret, "QueryActCtxSettingsW failed err %lu\n", GetLastError() );
3554 ok( !lstrcmpW( buffer, trueW ), "got %s\n", wine_dbgstr_w(buffer) );
3555 ok( size == lstrlenW( buffer ) + 1, "wrong len %Iu\n", size );
3556 ReleaseActCtx(handle);
3557 }
3558
3559 create_manifest_file( "manifest_settings3.manifest", settings_manifest3, -1, NULL, NULL );
3560 handle = test_create("manifest_settings3.manifest");
3561 ok( handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %lu\n", GetLastError() );
3562 DeleteFileA( "manifest_settings3.manifest" );
3563 SetLastError( 0xdeadbeef );
3564 size = 0xdead;
3565 memset( buffer, 0xcc, sizeof(buffer) );
3566 ret = pQueryActCtxSettingsW( 0, handle, NULL, dpiAwareW, buffer, 80, &size );
3567 ok( !ret, "QueryActCtxSettingsW succeeded\n" );
3568 ok( GetLastError() == ERROR_SXS_KEY_NOT_FOUND, "wrong error %lu\n", GetLastError() );
3569 ReleaseActCtx(handle);
3570
3571 /* lookup occurs in first non empty node */
3572 create_manifest_file( "manifest_settings4.manifest", settings_manifest4, -1, NULL, NULL );
3573 handle = test_create("manifest_settings4.manifest");
3574 ok( handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %lu\n", GetLastError() );
3575 DeleteFileA( "manifest_settings4.manifest" );
3576 SetLastError( 0xdeadbeef );
3577 size = 0xdead;
3578 memset( buffer, 0xcc, sizeof(buffer) );
3579 ret = pQueryActCtxSettingsW( 0, handle, NULL, dpiAwareW, buffer, 80, &size );
3580 ok( ret, "QueryActCtxSettingsW failed\n" );
3581 SetLastError( 0xdeadbeef );
3582 size = 0xdead;
3583 memset( buffer, 0xcc, sizeof(buffer) );
3584 ret = pQueryActCtxSettingsW( 0, handle, NULL, dpiAwarenessW, buffer, 80, &size );
3585 ok( !ret, "QueryActCtxSettingsW succeeded\n" );
3586 ReleaseActCtx(handle);
3587}
3588
3589typedef struct
3590{
3591 char path_tmp[MAX_PATH];
3592 char path_dll[MAX_PATH + 11];
3593 char path_manifest_exe[MAX_PATH + 12];
3594 char path_manifest_dll[MAX_PATH + 16];
3595 ACTCTXA context;
3596 ULONG_PTR cookie;
3597 HANDLE handle_context;
3598 HMODULE module;
3599 void (WINAPI *get_path)(char *buffer, int buffer_size);
3600} sxs_info;
3601
3602static BOOL fill_sxs_info(sxs_info *info, const char *temp, const char *path_dll, const char *exe_manifest, const char *dll_manifest, BOOL do_load)
3603{
3604 BOOL success;
3605
3606 GetTempPathA(MAX_PATH, info->path_tmp);
3607 strcat(info->path_tmp, temp);
3608 strcat(info->path_tmp, "\\");
3609 CreateDirectoryA(info->path_tmp, NULL);
3610
3611 sprintf(info->path_dll, "%s%s", info->path_tmp, "sxs_dll.dll");
3612 extract_resource(path_dll, "TESTDLL", info->path_dll);
3613
3614 sprintf(info->path_manifest_exe, "%s%s", info->path_tmp, "exe.manifest");
3615 create_manifest_file(info->path_manifest_exe, exe_manifest, -1, NULL, NULL);
3616
3617 sprintf(info->path_manifest_dll, "%s%s", info->path_tmp, "sxs_dll.manifest");
3618 create_manifest_file(info->path_manifest_dll, dll_manifest, -1, NULL, NULL);
3619
3620 info->context.cbSize = sizeof(ACTCTXA);
3621 info->context.lpSource = info->path_manifest_exe;
3622 info->context.lpAssemblyDirectory = info->path_tmp;
3623 info->context.dwFlags = ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID;
3624
3625 info->handle_context = CreateActCtxA(&info->context);
3626 ok((info->handle_context != NULL && info->handle_context != INVALID_HANDLE_VALUE )
3627 || broken(GetLastError() == ERROR_SXS_CANT_GEN_ACTCTX), /* XP doesn't support manifests outside of PE files */
3628 "CreateActCtxA failed: %ld\n", GetLastError());
3629 if (GetLastError() == ERROR_SXS_CANT_GEN_ACTCTX)
3630 {
3631 skip("Failed to create activation context.\n");
3632 return FALSE;
3633 }
3634
3635 if (do_load)
3636 {
3637 success = ActivateActCtx(info->handle_context, &info->cookie);
3638 ok(success, "ActivateActCtx failed: %ld\n", GetLastError());
3639
3640 info->module = LoadLibraryA("sxs_dll.dll");
3641 ok(info->module != NULL, "LoadLibrary failed\n");
3642
3643 info->get_path = (void *)GetProcAddress(info->module, "get_path");
3644 ok(info->get_path != NULL, "GetProcAddress failed\n");
3645
3646 DeactivateActCtx(0, info->cookie);
3647 }
3648 return TRUE;
3649}
3650
3651static void clean_sxs_info(sxs_info *info)
3652{
3653 if (info->handle_context)
3654 ReleaseActCtx(info->handle_context);
3655 if (*info->path_dll)
3656 {
3657 BOOL ret = DeleteFileA(info->path_dll);
3658 ok(ret, "DeleteFileA failed for %s: %ld\n", info->path_dll, GetLastError());
3659 }
3660 if (*info->path_manifest_exe)
3661 {
3662 BOOL ret = DeleteFileA(info->path_manifest_exe);
3663 ok(ret, "DeleteFileA failed for %s: %ld\n", info->path_manifest_exe, GetLastError());
3664 }
3665 if (*info->path_manifest_dll)
3666 {
3667 BOOL ret = DeleteFileA(info->path_manifest_dll);
3668 ok(ret, "DeleteFileA failed for %s: %ld\n", info->path_manifest_dll, GetLastError());
3669 }
3670 if (*info->path_tmp)
3671 {
3672 BOOL ret = RemoveDirectoryA(info->path_tmp);
3673 ok(ret, "RemoveDirectoryA failed for %s: %ld\n", info->path_tmp, GetLastError());
3674 }
3675}
3676
3677static void get_application_directory(char *buffer, int buffer_size)
3678{
3679 char *end;
3680 GetModuleFileNameA(NULL, buffer, buffer_size);
3681 end = strrchr(buffer, '\\');
3682 end[1] = 0;
3683}
3684
3685/* Test loading two sxs dlls at the same time */
3686static void test_two_dlls_at_same_time(void)
3687{
3688 sxs_info dll_1;
3689 sxs_info dll_2;
3690 char path1[MAX_PATH], path2[MAX_PATH];
3691
3692 if (!fill_sxs_info(&dll_1, "1", "dummy.dll", two_dll_manifest_exe, two_dll_manifest_dll, TRUE))
3693 goto cleanup1;
3694 if (!fill_sxs_info(&dll_2, "2", "dummy.dll", two_dll_manifest_exe, two_dll_manifest_dll, TRUE))
3695 goto cleanup2;
3696
3697 ok(dll_1.module != dll_2.module, "Libraries are the same\n");
3698 dll_1.get_path(path1, sizeof(path1));
3699 ok(strcmp(path1, dll_1.path_dll) == 0, "Got '%s', expected '%s'\n", path1, dll_1.path_dll);
3700 dll_2.get_path(path2, sizeof(path2));
3701 ok(strcmp(path2, dll_2.path_dll) == 0, "Got '%s', expected '%s'\n", path2, dll_2.path_dll);
3702
3703cleanup2:
3704 if (dll_2.module)
3705 FreeLibrary(dll_2.module);
3706 clean_sxs_info(&dll_2);
3707cleanup1:
3708 if (dll_1.module)
3709 FreeLibrary(dll_1.module);
3710 clean_sxs_info(&dll_1);
3711}
3712
3713/* Test loading a normal dll and then a sxs dll with the same name */
3714static void test_one_sxs_and_one_local_1(void)
3715{
3716 sxs_info dll;
3717 char path_dll_local[MAX_PATH + 11];
3718 char path_application[MAX_PATH];
3719 HMODULE module = NULL;
3720 char path1[MAX_PATH], path2[MAX_PATH];
3721 void (WINAPI *get_path)(char *buffer, int buffer_size);
3722
3723 get_application_directory(path_application, sizeof(path_application));
3724
3725 sprintf(path_dll_local, "%s%s", path_application, "sxs_dll.dll");
3726 extract_resource("dummy.dll", "TESTDLL", path_dll_local);
3727
3728 module = LoadLibraryA(path_dll_local);
3729 get_path = (void *)GetProcAddress(module, "get_path");
3730
3731 if (!fill_sxs_info(&dll, "1", "dummy.dll", two_dll_manifest_exe, two_dll_manifest_dll, TRUE))
3732 goto cleanup;
3733
3734 ok(dll.module != module, "Libraries are the same\n");
3735 dll.get_path(path1, sizeof(path1));
3736 ok(strcmp(path1, dll.path_dll) == 0, "Got '%s', expected '%s'\n", path1, dll.path_dll);
3737 get_path(path2, sizeof(path2));
3738 ok(strcmp(path2, path_dll_local) == 0, "Got '%s', expected '%s'\n", path2, path_dll_local);
3739
3740cleanup:
3741 if (module)
3742 FreeLibrary(module);
3743 if (dll.module)
3744 FreeLibrary(dll.module);
3745 if (*path_dll_local)
3746 {
3747 BOOL success = DeleteFileA(path_dll_local);
3748 ok(success, "DeleteFileA failed for %s: %ld\n", path_dll_local, GetLastError());
3749 }
3750 clean_sxs_info(&dll);
3751}
3752
3753/* Test if sxs dll has priority over normal dll */
3754static void test_one_sxs_and_one_local_2(void)
3755{
3756 sxs_info dll;
3757 char path_dll_local[MAX_PATH + 11];
3758 char path_application[MAX_PATH];
3759 HMODULE module = NULL;
3760 char path1[MAX_PATH], path2[MAX_PATH];
3761 void (WINAPI *get_path)(char *buffer, int buffer_size);
3762
3763 get_application_directory(path_application, sizeof(path_application));
3764
3765 sprintf(path_dll_local, "%s%s", path_application, "sxs_dll.dll");
3766 extract_resource("dummy.dll", "TESTDLL", path_dll_local);
3767
3768 if (!fill_sxs_info(&dll, "1", "dummy.dll", two_dll_manifest_exe, two_dll_manifest_dll, TRUE))
3769 goto cleanup;
3770
3771 module = LoadLibraryA(path_dll_local);
3772 get_path = (void *)GetProcAddress(module, "get_path");
3773
3774 ok(dll.module != module, "Libraries are the same\n");
3775 dll.get_path(path1, sizeof(path1));
3776 ok(strcmp(path1, dll.path_dll) == 0, "Got '%s', expected '%s'\n", path1, dll.path_dll);
3777 get_path(path2, sizeof(path2));
3778 ok(strcmp(path2, path_dll_local) == 0, "Got '%s', expected '%s'\n", path2, path_dll_local);
3779
3780cleanup:
3781 if (module)
3782 FreeLibrary(module);
3783 if (dll.module)
3784 FreeLibrary(dll.module);
3785 if (*path_dll_local)
3786 {
3787 BOOL success = DeleteFileA(path_dll_local);
3788 ok(success, "DeleteFileA failed for %s: %ld\n", path_dll_local, GetLastError());
3789 }
3790 clean_sxs_info(&dll);
3791}
3792
3793
3794/* Test if we can get a module handle from loaded normal dll while context is active */
3795static void test_one_with_sxs_and_GetModuleHandleA(void)
3796{
3797 sxs_info dll;
3798 char path_dll_local[MAX_PATH + 11];
3799 char path_tmp[MAX_PATH];
3800 HMODULE module = NULL, module_temp;
3801 BOOL success;
3802
3803 GetTempPathA(sizeof(path_tmp), path_tmp);
3804
3805 sprintf(path_dll_local, "%s%s", path_tmp, "sxs_dll.dll");
3806 extract_resource("dummy.dll", "TESTDLL", path_dll_local);
3807
3808 module = LoadLibraryA(path_dll_local);
3809
3810 if (!fill_sxs_info(&dll, "1", "dummy.dll", two_dll_manifest_exe, two_dll_manifest_dll, FALSE))
3811 goto cleanup;
3812
3813 success = ActivateActCtx(dll.handle_context, &dll.cookie);
3814 ok(success, "ActivateActCtx failed: %ld\n", GetLastError());
3815
3816 module_temp = GetModuleHandleA("sxs_dll.dll");
3817 ok (module_temp == 0, "Expected 0, got %p\n", module_temp);
3818
3819 DeactivateActCtx(0, dll.cookie);
3820
3821cleanup:
3822 if (module)
3823 FreeLibrary(module);
3824 if (dll.module)
3825 FreeLibrary(dll.module);
3826 if (*path_dll_local)
3827 {
3828 success = DeleteFileA(path_dll_local);
3829 ok(success, "DeleteFileA failed for %s: %ld\n", path_dll_local, GetLastError());
3830 }
3831 clean_sxs_info(&dll);
3832}
3833
3834static void test_builtin_sxs(void)
3835{
3836 char path_manifest[MAX_PATH + 12];
3837 char path_tmp[MAX_PATH];
3838 HMODULE module_msvcp = 0, module_msvcr = 0;
3839 char path_msvcp[MAX_PATH], path_msvcr[MAX_PATH];
3840 ACTCTXA context;
3841 ULONG_PTR cookie;
3842 HANDLE handle_context;
3843 BOOL success;
3844#ifdef __REACTOS__
3845 static char expected_path[MAX_PATH];
3846 GetWindowsDirectoryA(expected_path, sizeof(expected_path));
3847 strcat(expected_path, "\\WinSxS");
3848#else
3849 static const char *expected_path = "C:\\Windows\\WinSxS";
3850#endif
3851
3852 GetTempPathA(sizeof(path_tmp), path_tmp);
3853
3854 sprintf(path_manifest, "%s%s", path_tmp, "exe.manifest");
3855 create_manifest_file(path_manifest, builtin_dll_manifest, -1, NULL, NULL);
3856
3857 context.cbSize = sizeof(ACTCTXA);
3858 context.lpSource = path_manifest;
3859 context.lpAssemblyDirectory = path_tmp;
3860 context.dwFlags = ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID;
3861
3862 handle_context = CreateActCtxA(&context);
3863 ok((handle_context != NULL && handle_context != INVALID_HANDLE_VALUE )
3864 || broken(GetLastError() == ERROR_SXS_CANT_GEN_ACTCTX), /* XP doesn't support manifests outside of PE files */
3865 "CreateActCtxA failed: %ld\n", GetLastError());
3866 if (GetLastError() == ERROR_SXS_CANT_GEN_ACTCTX)
3867 {
3868 skip("Failed to create activation context.\n");
3869 goto cleanup;
3870 }
3871
3872
3873 success = ActivateActCtx(handle_context, &cookie);
3874 ok(success, "ActivateActCtx failed: %ld\n", GetLastError());
3875
3876 module_msvcp = LoadLibraryA("msvcp90.dll");
3877 ok (module_msvcp != 0 || broken(module_msvcp == 0), "LoadLibraryA failed, %ld\n", GetLastError());
3878 module_msvcr = LoadLibraryA("msvcr90.dll");
3879 ok (module_msvcr != 0 || broken(module_msvcr == 0), "LoadLibraryA failed, %ld\n", GetLastError());
3880 if (!module_msvcp || !module_msvcr)
3881 {
3882 skip("Failed to find msvcp90 or msvcr90.\n");
3883 goto cleanup;
3884 }
3885
3886 GetModuleFileNameA(module_msvcp, path_msvcp, sizeof(path_msvcp));
3887 GetModuleFileNameA(module_msvcr, path_msvcr, sizeof(path_msvcr));
3888 ok(strnicmp(expected_path, path_msvcp, strlen(expected_path)) == 0, "Expected path to start with %s, got %s\n", expected_path, path_msvcp);
3889 ok(strnicmp(expected_path, path_msvcr, strlen(expected_path)) == 0, "Expected path to start with %s, got %s\n", expected_path, path_msvcr);
3890
3891 DeactivateActCtx(0, cookie);
3892
3893cleanup:
3894 if (module_msvcp)
3895 FreeLibrary(module_msvcp);
3896 if (module_msvcr)
3897 FreeLibrary(module_msvcr);
3898 if (*path_manifest)
3899 {
3900 success = DeleteFileA(path_manifest);
3901 ok(success, "DeleteFileA failed for %s: %ld\n", path_manifest, GetLastError());
3902 }
3903}
3904
3905struct manifest_res_spec
3906{
3907 const char *name;
3908 LANGID lang;
3909 const char *override_manifest;
3910};
3911
3912struct manifest_res_spec_list
3913{
3914 size_t count;
3915 const struct manifest_res_spec *items;
3916};
3917
3918static void add_sxs_dll_manifest(const char *pathname,
3919 const struct manifest_res_spec_list *res_lists,
3920 size_t num_lists,
3921 const char *manifest)
3922{
3923 HANDLE update_h;
3924 BOOL ret;
3925 size_t i, j;
3926
3927 update_h = BeginUpdateResourceA(pathname, FALSE);
3928 ok(update_h != NULL, "BeginUpdateResourceA returned error %lu.\n", GetLastError());
3929
3930 for (i = 0; i < num_lists; i++)
3931 {
3932 for (j = 0; j < res_lists[i].count; j++)
3933 {
3934 const struct manifest_res_spec *res_spec = &res_lists[i].items[j];
3935 const char *cur_manifest = res_spec->override_manifest ? res_spec->override_manifest : manifest;
3936 ret = UpdateResourceA(update_h,
3937 MAKEINTRESOURCEA(RT_MANIFEST),
3938 res_spec->name,
3939 res_spec->lang,
3940 (void *)cur_manifest,
3941 strlen(cur_manifest));
3942 ok(ret, "UpdateResourceA returned error %lu.\n", GetLastError());
3943 }
3944 }
3945
3946 ret = EndUpdateResourceA(update_h, FALSE);
3947 ok(ret, "EndUpdateResourceA returned error %lu.\n", GetLastError());
3948}
3949
3950struct multiple_manifest_test
3951{
3952 struct manifest_res_spec manifest_inline; /* optional */
3953 const struct manifest_res_spec *manifests; /* optional */
3954 DWORD expected_error;
3955};
3956
3957#define subtest_manifest_res(d,e,t,l) subtest_manifest_res_(__LINE__,d,e,t,l)
3958static DWORD subtest_manifest_res_(int line, const char *manifest_exe, const char *manifest_dll,
3959 const struct multiple_manifest_test *test_data, LANGID lang)
3960{
3961 char path_tmp[MAX_PATH] = "", path_dll[MAX_PATH] = "", path_manifest_exe[MAX_PATH] = "";
3962 static const char path_tmp_suffix[] = "winek32t\\";
3963 WCHAR locale_name[LOCALE_NAME_MAX_LENGTH] = {0};
3964 struct manifest_res_spec_list res_lists[2];
3965 char path_tmp_lang[MAX_PATH] = "";
3966 static volatile LONG last_uniqid;
3967 DWORD err, prefix_len;
3968 ACTCTXA actctx;
3969 HANDLE handle;
3970 BOOL ret;
3971 int r;
3972
3973 prefix_len = GetTempPathA(MAX_PATH - ARRAY_SIZE(path_tmp_suffix), path_tmp);
3974 ok_(__FILE__, line)(prefix_len > 0, "GetTempPathA returned error %lu.\n", GetLastError());
3975
3976 memcpy(&path_tmp[prefix_len], path_tmp_suffix, sizeof(path_tmp_suffix) - sizeof(*path_tmp_suffix));
3977 ret = CreateDirectoryA(path_tmp, NULL);
3978 ok_(__FILE__, line)(ret || GetLastError() == ERROR_ALREADY_EXISTS,
3979 "CreateDirectoryA returned error %lu.\n", GetLastError());
3980
3981 if (lang)
3982 {
3983#if !defined(__REACTOS__) || DLL_EXPORT_VERSION >= 0x600
3984 r = LCIDToLocaleName(MAKELCID(lang, SORT_DEFAULT),
3985 locale_name, ARRAY_SIZE(locale_name), LOCALE_ALLOW_NEUTRAL_NAMES);
3986 ok(r > 0, "lang 0x%04x, error %lu.\n", lang, GetLastError());
3987#endif
3988 }
3989
3990 if (locale_name[0])
3991 {
3992 r = snprintf(path_tmp_lang, ARRAY_SIZE(path_tmp_lang), "%s%ls\\", path_tmp, locale_name);
3993 ok_(__FILE__, line)(r > 0 && r < ARRAY_SIZE(path_tmp_lang), "got %d\n", r);
3994
3995 ret = CreateDirectoryA(path_tmp_lang, NULL);
3996 ok_(__FILE__, line)(ret || GetLastError() == ERROR_ALREADY_EXISTS,
3997 "CreateDirectoryA returned error %lu.\n", GetLastError());
3998 }
3999 else
4000 {
4001 r = snprintf(path_tmp_lang, ARRAY_SIZE(path_tmp_lang), "%s", path_tmp);
4002 ok_(__FILE__, line)(r > 0 && r < ARRAY_SIZE(path_tmp_lang), "got %d\n", r);
4003 }
4004
4005 r = snprintf(path_dll, ARRAY_SIZE(path_dll), "%s%s", path_tmp_lang, "sxs_dll.dll");
4006 ok_(__FILE__, line)(r > 0 && r < ARRAY_SIZE(path_dll), "got %d\n", r);
4007
4008 r = snprintf(path_manifest_exe, ARRAY_SIZE(path_manifest_exe), "%sexe%08lx.manifest",
4009 path_tmp, InterlockedIncrement(&last_uniqid));
4010 ok_(__FILE__, line)(r > 0 && r < ARRAY_SIZE(path_manifest_exe), "got %d\n", r);
4011 create_manifest_file(path_manifest_exe, manifest_exe, -1, NULL, NULL);
4012
4013 extract_resource("dummy.dll", "TESTDLL", path_dll);
4014
4015 res_lists[0].count = test_data->manifest_inline.name ? 1 : 0;
4016 res_lists[0].items = &test_data->manifest_inline;
4017
4018 if (test_data->manifests)
4019 {
4020 size_t n = 0;
4021
4022 while (test_data->manifests[n].name)
4023 n++;
4024
4025 res_lists[1].count = n;
4026 res_lists[1].items = test_data->manifests;
4027 }
4028 else
4029 {
4030 res_lists[1].count = 0;
4031 res_lists[1].items = NULL;
4032 }
4033
4034 add_sxs_dll_manifest(path_dll, res_lists, ARRAY_SIZE(res_lists), manifest_dll);
4035
4036 memset(&actctx, 0, sizeof(actctx));
4037 actctx.cbSize = sizeof(actctx);
4038 actctx.lpSource = path_manifest_exe;
4039 actctx.lpAssemblyDirectory = path_tmp;
4040 actctx.dwFlags = ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID;
4041
4042 SetLastError(0xccccccccUL);
4043 handle = CreateActCtxA(&actctx);
4044 if (handle == INVALID_HANDLE_VALUE)
4045 {
4046 err = GetLastError();
4047 ok_(__FILE__, line)(err != ERROR_SUCCESS, "got %#lx.\n", err);
4048 }
4049 else
4050 {
4051 err = ERROR_SUCCESS;
4052 ok_(__FILE__, line)(handle != NULL, "CreateActCtxA returned %p (error %lu)\n", handle, err);
4053 ReleaseActCtx(handle);
4054 }
4055 ok_(__FILE__, line)(err == test_data->expected_error,
4056 "expected error %lu, got %lu\n", test_data->expected_error, err);
4057
4058 ret = DeleteFileA(path_manifest_exe);
4059 ok_(__FILE__, line)(ret, "DeleteFileA(%s) returned error %lu\n.",
4060 debugstr_a(path_manifest_exe), GetLastError());
4061
4062 ret = DeleteFileA(path_dll);
4063 ok_(__FILE__, line)(ret, "DeleteFileA(%s) returned error %lu\n.", debugstr_a(path_dll), GetLastError());
4064
4065 if (locale_name[0])
4066 {
4067 ret = RemoveDirectoryA(path_tmp_lang);
4068 ok_(__FILE__, line)(ret, "RemoveDirectoryA(%s) returned error %lu\n.",
4069 debugstr_a(path_tmp_lang), GetLastError());
4070 }
4071
4072 ret = RemoveDirectoryA(path_tmp);
4073 ok_(__FILE__, line)(ret, "RemoveDirectoryA(%s) returned error %lu %s\n.",
4074 debugstr_a(path_tmp), GetLastError(), debugstr_a(path_tmp_lang));
4075
4076 return err;
4077}
4078
4079/* Test loading DLL with dependency assembly in manifest resource */
4080static void test_manifest_resources(void)
4081{
4082#ifdef __REACTOS__
4083 skip("test_manifest_resources() is invalid for WS03 - Win10 1607.\n");
4084#else
4085 static const struct manifest_res_spec wrong_manifest_resources_numbered[] = {
4086 { (char *)2, MAKELANGID(LANG_ENGLISH,SUBLANG_DEFAULT), wrong_manifest1 },
4087 { (char *)2, MAKELANGID(LANG_FRENCH,SUBLANG_DEFAULT), wrong_manifest1 },
4088 { (char *)3, 0, wrong_manifest1 },
4089 { (char *)0x1234, 0, wrong_manifest1 },
4090 { NULL },
4091 };
4092 static const struct manifest_res_spec correct_manifest_resources_numbered[] = {
4093 { (char *)2, MAKELANGID(LANG_ENGLISH,SUBLANG_DEFAULT) },
4094 { (char *)2, MAKELANGID(LANG_FRENCH,SUBLANG_DEFAULT) },
4095 { (char *)3, 0 },
4096 { (char *)0x1234, 0 },
4097 { NULL },
4098 };
4099 static const struct manifest_res_spec wrong_manifest_resources_gte_3[] = {
4100 { (char *)3, 0, wrong_manifest1 },
4101 { (char *)3, MAKELANGID(LANG_ENGLISH,SUBLANG_DEFAULT), wrong_manifest1 },
4102 { NULL },
4103 };
4104 static const struct manifest_res_spec correct_manifest_resources_gte_3[] = {
4105 { (char *)3, 0 },
4106 { (char *)3, MAKELANGID(LANG_ENGLISH,SUBLANG_DEFAULT) },
4107 { NULL },
4108 };
4109 static const struct manifest_res_spec wrong_manifest_resources_named[] = {
4110 { "foo", 0, wrong_manifest1 },
4111 { "bar", MAKELANGID(LANG_ENGLISH,SUBLANG_DEFAULT), wrong_manifest1 },
4112 { NULL },
4113 };
4114 static const struct manifest_res_spec correct_manifest_resources_named[] = {
4115 { "foo", 0 },
4116 { "bar", MAKELANGID(LANG_ENGLISH,SUBLANG_DEFAULT) },
4117 { NULL },
4118 };
4119 struct multiple_manifest_test tests[] = {
4120 /* Test well-known manifest resource IDs */
4121 { { (char *)CREATEPROCESS_MANIFEST_RESOURCE_ID }, NULL, ERROR_SUCCESS },
4122 { { (char *)ISOLATIONAWARE_MANIFEST_RESOURCE_ID }, NULL, ERROR_SUCCESS },
4123 { { (char *)ISOLATIONAWARE_NOSTATICIMPORT_MANIFEST_RESOURCE_ID }, NULL, ERROR_SUCCESS },
4124
4125 /* Test remaining reserved manifest resource IDs */
4126 { { (char *)4 }, NULL, ERROR_SUCCESS },
4127 { { (char *)5 }, NULL, ERROR_SUCCESS },
4128 { { (char *)6 }, NULL, ERROR_SUCCESS },
4129 { { (char *)7 }, NULL, ERROR_SUCCESS },
4130 { { (char *)8 }, NULL, ERROR_SUCCESS },
4131 { { (char *)9 }, NULL, ERROR_SUCCESS },
4132 { { (char *)10 }, NULL, ERROR_SUCCESS },
4133 { { (char *)11 }, NULL, ERROR_SUCCESS },
4134 { { (char *)12 }, NULL, ERROR_SUCCESS },
4135 { { (char *)13 }, NULL, ERROR_SUCCESS },
4136 { { (char *)14 }, NULL, ERROR_SUCCESS },
4137 { { (char *)15 }, NULL, ERROR_SUCCESS },
4138 { { (char *)MAXIMUM_RESERVED_MANIFEST_RESOURCE_ID }, NULL, ERROR_SUCCESS },
4139
4140 /* Test arbitrary resource IDs */
4141 { { (char *)0x1234 }, NULL, ERROR_SUCCESS },
4142 { { (char *)0x89ab }, NULL, ERROR_SUCCESS },
4143 { { (char *)0xffff }, NULL, ERROR_SUCCESS },
4144
4145 /* Test arbitrary LANGID */
4146 { { (char *)2, MAKELANGID(LANG_ENGLISH,SUBLANG_DEFAULT) }, NULL, ERROR_SUCCESS },
4147 { { (char *)2, MAKELANGID(LANG_FRENCH,SUBLANG_DEFAULT) }, NULL, ERROR_SUCCESS },
4148 { { (char *)2, 0x1234 }, NULL, ERROR_SUCCESS },
4149 { { (char *)2, 0xffff }, NULL, ERROR_SUCCESS },
4150
4151 /* Test multiple manifest resources coexisting inside a module */
4152 { { (char *)2, 0 }, wrong_manifest_resources_numbered, ERROR_SUCCESS },
4153 { { (char *)2, 0, wrong_manifest1 }, correct_manifest_resources_numbered,
4154 ERROR_SXS_CANT_GEN_ACTCTX },
4155
4156 /* Test that smaller resource ID takes precedence regardless of language ID */
4157 { { (char *)2, MAKELANGID(LANG_INVARIANT,SUBLANG_NEUTRAL) },
4158 wrong_manifest_resources_gte_3, ERROR_SUCCESS },
4159 { { (char *)2, MAKELANGID(LANG_INVARIANT,SUBLANG_NEUTRAL), wrong_manifest1 },
4160 correct_manifest_resources_gte_3, ERROR_SXS_CANT_GEN_ACTCTX },
4161
4162 /* Test multiple manifest resources (ID / name) coexisting inside a module */
4163 { { (char *)2, 0 }, wrong_manifest_resources_named, ERROR_SUCCESS },
4164 { { (char *)2, 0, wrong_manifest1 },
4165 correct_manifest_resources_named, ERROR_SXS_CANT_GEN_ACTCTX },
4166
4167 /* Test name-only RT_MANIFEST resources */
4168 { { NULL }, correct_manifest_resources_named, ERROR_SXS_CANT_GEN_ACTCTX },
4169 };
4170 size_t i;
4171
4172 for (i = 0; i < ARRAY_SIZE(tests); i++)
4173 {
4174 winetest_push_context("tests[%Iu] (%p 0x%04x)", i,
4175 tests[i].manifest_inline.name, tests[i].manifest_inline.lang);
4176 subtest_manifest_res(two_dll_manifest_exe, two_dll_manifest_dll, &tests[i], 0);
4177 winetest_pop_context();
4178 }
4179#endif
4180}
4181
4182#define LANGID_PREC_MAX_COUNT 5
4183
4184static void get_langid_precedence(LANGID *langs_arr, size_t *lang_count)
4185{
4186 LANGID src_langs[LANGID_PREC_MAX_COUNT];
4187 LANGID user_ui_lang;
4188 size_t i, j, n = 0;
4189
4190 user_ui_lang = GetUserDefaultUILanguage();
4191
4192 src_langs[0] = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL);
4193 src_langs[1] = user_ui_lang;
4194 src_langs[2] = MAKELANGID(PRIMARYLANGID(user_ui_lang), SUBLANG_NEUTRAL);
4195 src_langs[3] = MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT);
4196 src_langs[4] = 0x1; /* least number that is a valid LANGID */
4197
4198 for (i = 0; i < ARRAY_SIZE(src_langs); i++)
4199 {
4200 LANGID item = src_langs[i];
4201 BOOL is_item_duplicate = FALSE;
4202
4203 for (j = 0; j < n; j++)
4204 {
4205 if (langs_arr[j] == item)
4206 {
4207 is_item_duplicate = TRUE;
4208 break;
4209 }
4210 }
4211
4212 if (!is_item_duplicate)
4213 {
4214 langs_arr[n++] = item;
4215 }
4216 }
4217
4218 *lang_count = n;
4219}
4220
4221static void subtest_valid_manifest_resources_locale(LANGID actctx_lang)
4222{
4223 static const char manifest_exe_fmt[] =
4224 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
4225 "<dependency>"
4226 "<dependentAssembly>"
4227 "<assemblyIdentity type=\"win32\" name=\"sxs_dll\" version=\"1.0.0.0\""
4228 " processorArchitecture=\"" ARCH "\" publicKeyToken=\"0000000000000000\" language=\"%ls\"/>"
4229 "</dependentAssembly>"
4230 "</dependency>"
4231 "</assembly>";
4232 static const char manifest_dll_fmt[] =
4233 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersion=\"1.0\">"
4234 "<assemblyIdentity type=\"win32\" name=\"sxs_dll\" version=\"1.0.0.0\""
4235 " processorArchitecture=\"" ARCH "\" publicKeyToken=\"0000000000000000\" language=\"%ls\"/>"
4236 "</assembly>";
4237 static const char manifest_dll_nofmt[] =
4238 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v3\" manifestVersion=\"1.0\">"
4239 "<assemblyIdentity type=\"win32\" name=\"sxs_dll\" version=\"1.0.0.0\""
4240 " processorArchitecture=\"" ARCH "\" publicKeyToken=\"0000000000000000\"/>"
4241 "</assembly>";
4242 char manifest_exe[1024], manifest_dll[1024];
4243 WCHAR locale_name[LOCALE_NAME_MAX_LENGTH];
4244 UINT16 langs_arr[LANGID_PREC_MAX_COUNT];
4245 size_t lang_count = 0, i, j;
4246 int ret;
4247
4248 if (actctx_lang == MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL))
4249 {
4250 wcscpy(locale_name, L"*");
4251 strcpy(manifest_dll, manifest_dll_nofmt);
4252 }
4253 else
4254 {
4255 actctx_lang = ConvertDefaultLocale(actctx_lang);
4256 ok(actctx_lang != MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
4257 "unexpected neutral locale\n");
4258#if !defined(__REACTOS__) || DLL_EXPORT_VERSION >= 0x600
4259 ret = LCIDToLocaleName(MAKELCID(actctx_lang, SORT_DEFAULT),
4260 locale_name, ARRAY_SIZE(locale_name), LOCALE_ALLOW_NEUTRAL_NAMES);
4261 ok(ret > 0, "error %lu.\n", GetLastError());
4262#endif
4263
4264 ret = snprintf(manifest_dll, ARRAY_SIZE(manifest_dll), manifest_dll_fmt, locale_name);
4265 ok(ret > 0 && ret < ARRAY_SIZE(manifest_dll), "ret %d.\n", ret);
4266 }
4267
4268 ret = snprintf(manifest_exe, ARRAY_SIZE(manifest_exe), manifest_exe_fmt, locale_name);
4269 ok(ret > 0 && ret < ARRAY_SIZE(manifest_exe), "ret %d.\n", ret);
4270
4271 get_langid_precedence(langs_arr, &lang_count);
4272
4273 for (i = 0; i < lang_count; i++)
4274 {
4275 struct manifest_res_spec specs[ARRAY_SIZE(langs_arr) + 1];
4276 struct multiple_manifest_test test = { { NULL } };
4277 size_t num_specs;
4278 DWORD err;
4279
4280 winetest_push_context("langs[%Id:]", i);
4281
4282 /* Generate manifest spec list from language IDs.
4283 *
4284 * All manifest spec items point to the wrong manifest, expect for the
4285 * current language ID.
4286 */
4287 num_specs = 0;
4288 for (j = i; j < lang_count; j++)
4289 {
4290 struct manifest_res_spec spec = {(char *)2};
4291 spec.lang = langs_arr[j];
4292 if (j != i) spec.override_manifest = wrong_manifest1;
4293 ok(num_specs < ARRAY_SIZE(specs), "overrun\n");
4294 specs[num_specs++] = spec;
4295 }
4296 memset(&specs[num_specs++], 0, sizeof(*specs));
4297
4298 test.manifests = specs;
4299 test.expected_error = ERROR_SUCCESS;
4300 err = subtest_manifest_res(manifest_exe, manifest_dll, &test, actctx_lang);
4301
4302 if (winetest_debug > 1 && err != ERROR_SUCCESS)
4303 {
4304 for (j = 0; j < lang_count; j++)
4305 {
4306 trace("langs[%Id] = 0x%04x %c\n", j, langs_arr[j], j == i ? '<' : ' ');
4307 }
4308 }
4309
4310 winetest_pop_context();
4311 }
4312}
4313
4314static void test_valid_manifest_resources_locale(void)
4315{
4316#ifdef __REACTOS__
4317 skip("test_valid_manifest_resources_locale() is invalid for WS03 - Win10 1607.\n");
4318#else
4319 static const LANGID langs[] = {
4320 MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
4321 MAKELANGID(LANG_INVARIANT, SUBLANG_NEUTRAL),
4322 };
4323 size_t i;
4324
4325 for (i = 0; i < ARRAY_SIZE(langs); i++)
4326 {
4327 winetest_push_context("[%Iu]lang=0x%04x", i, langs[i]);
4328 subtest_valid_manifest_resources_locale(langs[i]);
4329 winetest_pop_context();
4330 }
4331#endif
4332}
4333
4334static void run_sxs_test(int run)
4335{
4336 switch(run)
4337 {
4338 case 1:
4339 test_two_dlls_at_same_time();
4340 break;
4341 case 2:
4342 test_one_sxs_and_one_local_1();
4343 break;
4344 case 3:
4345 test_one_sxs_and_one_local_2();
4346 break;
4347 case 4:
4348 test_one_with_sxs_and_GetModuleHandleA();
4349 break;
4350 case 5:
4351 test_builtin_sxs();
4352 break;
4353 }
4354}
4355
4356static void run_child_process_two_dll(int run)
4357{
4358 char cmdline[MAX_PATH];
4359 char exe[MAX_PATH];
4360 char **argv;
4361 PROCESS_INFORMATION pi;
4362 STARTUPINFOA si = { 0 };
4363 BOOL ret;
4364
4365 winetest_get_mainargs( &argv );
4366
4367 if (strstr(argv[0], ".exe"))
4368 sprintf(exe, "%s", argv[0]);
4369 else
4370 sprintf(exe, "%s.exe", argv[0]);
4371 sprintf(cmdline, "\"%s\" %s two_dll %d", argv[0], argv[1], run);
4372
4373 si.cb = sizeof(si);
4374 ret = CreateProcessA(exe, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
4375 ok(ret, "Could not create process: %lu\n", GetLastError());
4376
4377 wait_child_process( pi.hProcess );
4378
4379 CloseHandle(pi.hThread);
4380 CloseHandle(pi.hProcess);
4381}
4382
4383static const detailed_info_t detailed_info3 =
4384{
4385 1, 1, 1, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE, exe_path,
4386 ACTIVATION_CONTEXT_PATH_TYPE_NONE, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE,
4387 app_dir,
4388};
4389
4390static void test_manifest_in_module(void)
4391{
4392 ACTCTXW ctx;
4393 HANDLE handle;
4394
4395#ifdef __REACTOS__
4396 if (GetNTVersion() < _WIN32_WINNT_VISTA) {
4397 skip("test_manifest_in_module() crashes on WS03.\n");
4398 return;
4399 }
4400#endif
4401 memset(&ctx, 0, sizeof(ctx));
4402 ctx.cbSize = sizeof(ctx);
4403 ctx.dwFlags = ACTCTX_FLAG_HMODULE_VALID | ACTCTX_FLAG_RESOURCE_NAME_VALID;
4404 ctx.lpResourceName = (LPWSTR)124;
4405 ctx.hModule = GetModuleHandleW(NULL);
4406 handle = CreateActCtxW(&ctx);
4407 ok(handle != INVALID_HANDLE_VALUE, "CreateActCtx error %lu\n", GetLastError());
4408
4409 test_basic_info(handle, __LINE__);
4410 test_detailed_info(handle, &detailed_info3, __LINE__);
4411
4412 ReleaseActCtx(handle);
4413}
4414
4415static void test_manifest_resource_name_omitted(void)
4416{
4417 WCHAR pathbuf[MAX_PATH];
4418 HANDLE handle;
4419 ACTCTXW ctx;
4420 DWORD err, len;
4421
4422 memset(&ctx, 0, sizeof(ctx));
4423 ctx.cbSize = sizeof(ctx);
4424 ctx.dwFlags = ACTCTX_FLAG_HMODULE_VALID;
4425 ctx.hModule = GetModuleHandleW(NULL);
4426 handle = CreateActCtxW(&ctx);
4427 err = GetLastError();
4428 ok(handle == INVALID_HANDLE_VALUE, "CreateActCtxW shall fail\n");
4429 todo_wine
4430#ifdef __REACTOS__
4431 ok(err == ERROR_RESOURCE_TYPE_NOT_FOUND || broken(err == ERROR_NOT_ENOUGH_MEMORY) /* WS03 */, "got %lu\n", err);
4432#else
4433 ok(err == ERROR_RESOURCE_TYPE_NOT_FOUND, "got %lu\n", err);
4434#endif
4435
4436 memset(&ctx, 0, sizeof(ctx));
4437 ctx.cbSize = sizeof(ctx);
4438 ctx.dwFlags = ACTCTX_FLAG_HMODULE_VALID | ACTCTX_FLAG_RESOURCE_NAME_VALID;
4439 ctx.hModule = GetModuleHandleW(NULL);
4440 ctx.lpResourceName = NULL;
4441 handle = CreateActCtxW(&ctx);
4442 err = GetLastError();
4443 ok(handle == INVALID_HANDLE_VALUE, "CreateActCtxW shall fail\n");
4444#ifdef __REACTOS__
4445 ok(err == ERROR_INVALID_PARAMETER || broken(err == ERROR_NOT_ENOUGH_MEMORY) /* WS03 */, "got %lu\n", err);
4446#else
4447 ok(err == ERROR_INVALID_PARAMETER, "got %lu\n", err);
4448#endif
4449
4450 len = GetModuleFileNameW(NULL, pathbuf, ARRAY_SIZE(pathbuf));
4451 ok(len > 0 && len < ARRAY_SIZE(pathbuf), "GetModuleFileNameW returned error %lu\n", GetLastError());
4452
4453 memset(&ctx, 0, sizeof(ctx));
4454 ctx.cbSize = sizeof(ctx);
4455 ctx.lpSource = pathbuf;
4456 ctx.dwFlags = 0;
4457 handle = CreateActCtxW(&ctx);
4458 err = GetLastError();
4459 ok(handle == INVALID_HANDLE_VALUE, "CreateActCtxW shall fail\n");
4460 todo_wine
4461 ok(err == ERROR_RESOURCE_TYPE_NOT_FOUND, "got %lu\n", err);
4462
4463 memset(&ctx, 0, sizeof(ctx));
4464 ctx.cbSize = sizeof(ctx);
4465 ctx.lpSource = pathbuf;
4466 ctx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID;
4467 ctx.lpResourceName = NULL;
4468 handle = CreateActCtxW(&ctx);
4469 err = GetLastError();
4470 ok(handle == INVALID_HANDLE_VALUE, "CreateActCtxW shall fail\n");
4471 ok(err == ERROR_INVALID_PARAMETER, "got %lu\n", err);
4472}
4473
4474START_TEST(actctx)
4475{
4476 int argc;
4477 char **argv;
4478
4479 argc = winetest_get_mainargs(&argv);
4480
4481 if (!init_funcs())
4482 {
4483 win_skip("Needed functions are not available\n");
4484 return;
4485 }
4486 init_paths();
4487
4488 if(argc > 2 && !strcmp(argv[2], "manifest1")) {
4489 test_app_manifest();
4490 return;
4491 }
4492
4493 if (argc > 2 && !strcmp(argv[2], "two_dll"))
4494 {
4495 int run = atoi(argv[3]);
4496 run_sxs_test(run);
4497 return;
4498 }
4499
4500 test_manifest_in_module();
4501 test_manifest_resource_name_omitted();
4502 test_manifest_resources();
4503 test_valid_manifest_resources_locale();
4504 test_actctx();
4505 test_create_fail();
4506 test_CreateActCtx();
4507 test_CreateActCtx_share_mode();
4508 test_findsectionstring();
4509 test_ZombifyActCtx();
4510 run_child_process();
4511 test_compatibility();
4512 test_settings();
4513#ifdef __REACTOS__
4514 if (GetNTVersion() > _WIN32_WINNT_VISTA) {
4515#endif
4516 run_child_process_two_dll(1);
4517 run_child_process_two_dll(2);
4518 run_child_process_two_dll(3);
4519 run_child_process_two_dll(4);
4520 run_child_process_two_dll(5);
4521#ifdef __REACTOS__
4522 }
4523#endif
4524}