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