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