push 0f15bbd80d260bbd8adf052e820484a405c49375
[wine/hacks.git] / dlls / kernel32 / tests / actctx.c
blob40f8b6e353fa83f1e4c81b606d5874b1861d5859
1 /*
2 * Copyright 2007 Jacek Caban for CodeWeavers
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.
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.
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
19 #include "wine/test.h"
20 #include <winbase.h>
21 #include <windef.h>
22 #include <winnt.h>
23 #include <winternl.h>
24 #include <winnls.h>
25 #include <stdio.h>
27 static BOOL (WINAPI *pActivateActCtx)(HANDLE,ULONG_PTR*);
28 static HANDLE (WINAPI *pCreateActCtxW)(PCACTCTXW);
29 static BOOL (WINAPI *pDeactivateActCtx)(DWORD,ULONG_PTR);
30 static BOOL (WINAPI *pFindActCtxSectionStringW)(DWORD,const GUID *,ULONG,LPCWSTR,PACTCTX_SECTION_KEYED_DATA);
31 static BOOL (WINAPI *pGetCurrentActCtx)(HANDLE *);
32 static BOOL (WINAPI *pQueryActCtxW)(DWORD,HANDLE,PVOID,ULONG,PVOID,SIZE_T,SIZE_T*);
33 static VOID (WINAPI *pReleaseActCtx)(HANDLE);
35 static const char* strw(LPCWSTR x)
37 static char buffer[1024];
38 char* p = buffer;
40 if (!x) return "(nil)";
41 else while ((*p++ = *x++));
42 return buffer;
45 static const char manifest1[] =
46 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
47 "<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
48 "</assembly>";
50 static const char manifest2[] =
51 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
52 "<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\">"
53 "</assemblyIdentity>"
54 "<dependency>"
55 "<dependentAssembly>"
56 "<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"x86\">"
57 "</assemblyIdentity>"
58 "</dependentAssembly>"
59 "</dependency>"
60 "</assembly>";
62 static const char manifest3[] =
63 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
64 "<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\""
65 " publicKeyToken=\"6595b6414666f1df\" />"
66 "<file name=\"testlib.dll\">"
67 "<windowClass>wndClass</windowClass>"
68 "</file>"
69 "</assembly>";
71 static const char manifest4[] =
72 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
73 "<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\">"
74 "</assemblyIdentity>"
75 "<dependency>"
76 "<dependentAssembly>"
77 "<assemblyIdentity type=\"win32\" name=\"Microsoft.Windows.Common-Controls\" "
78 "version=\"6.0.1.0\" processorArchitecture=\"x86\" publicKeyToken=\"6595b64144ccf1df\">"
79 "</assemblyIdentity>"
80 "</dependentAssembly>"
81 "</dependency>"
82 "</assembly>";
84 static const char testdep_manifest1[] =
85 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
86 "<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"x86\"/>"
87 "</assembly>";
89 static const char testdep_manifest2[] =
90 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
91 "<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"x86\" />"
92 "<file name=\"testlib.dll\"></file>"
93 "<file name=\"testlib2.dll\" hash=\"63c978c2b53d6cf72b42fb7308f9af12ab19ec53\" hashalg=\"SHA1\" />"
94 "</assembly>";
96 static const char testdep_manifest3[] =
97 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\"> "
98 "<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"x86\"/>"
99 "<file name=\"testlib.dll\"/>"
100 "<file name=\"testlib2.dll\" hash=\"63c978c2b53d6cf72b42fb7308f9af12ab19ec53\" hashalg=\"SHA1\">"
101 "<windowClass>wndClass</windowClass>"
102 "<windowClass>wndClass2</windowClass>"
103 "</file>"
104 "</assembly>";
106 static const char wrong_manifest1[] =
107 "<assembly manifestVersion=\"1.0\">"
108 "<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
109 "</assembly>";
111 static const char wrong_manifest2[] =
112 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\">"
113 "<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
114 "</assembly>";
116 static const char wrong_manifest3[] =
117 "<assembly test=\"test\" xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
118 "<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
119 "</assembly>";
121 static const char wrong_manifest4[] =
122 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
123 "<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
124 "<test></test>"
125 "</assembly>";
127 static const char wrong_manifest5[] =
128 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
129 "<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
130 "</assembly>"
131 "<test></test>";
133 static const char wrong_manifest6[] =
134 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v5\" manifestVersion=\"1.0\">"
135 "<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
136 "</assembly>";
138 static const char wrong_manifest7[] =
139 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
140 "<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"x86\" />"
141 "<file name=\"testlib.dll\" hash=\"63c978c2b53d6cf72b42fb7308f9af12ab19ec5\" hashalg=\"SHA1\" />"
142 "</assembly>";
144 static const char wrong_manifest8[] =
145 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
146 "<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
147 "<file></file>"
148 "</assembly>";
150 static const char wrong_depmanifest1[] =
151 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
152 "<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.4\" processorArchitecture=\"x86\" />"
153 "</assembly>";
155 static const WCHAR testlib_dll[] =
156 {'t','e','s','t','l','i','b','.','d','l','l',0};
157 static const WCHAR testlib2_dll[] =
158 {'t','e','s','t','l','i','b','2','.','d','l','l',0};
159 static const WCHAR wndClassW[] =
160 {'w','n','d','C','l','a','s','s',0};
161 static const WCHAR wndClass2W[] =
162 {'w','n','d','C','l','a','s','s','2',0};
163 static const WCHAR acr_manifest[] =
164 {'a','c','r','.','m','a','n','i','f','e','s','t',0};
166 static WCHAR app_dir[MAX_PATH], exe_path[MAX_PATH], work_dir[MAX_PATH], work_dir_subdir[MAX_PATH];
167 static WCHAR app_manifest_path[MAX_PATH], manifest_path[MAX_PATH], depmanifest_path[MAX_PATH];
169 static int strcmp_aw(LPCWSTR strw, const char *stra)
171 WCHAR buf[1024];
173 if (!stra) return 1;
174 MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(WCHAR));
175 return lstrcmpW(strw, buf);
178 static DWORD strlen_aw(const char *str)
180 return MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0) - 1;
183 static BOOL create_manifest_file(const char *filename, const char *manifest, int manifest_len,
184 const char *depfile, const char *depmanifest)
186 DWORD size;
187 HANDLE file;
188 WCHAR path[MAX_PATH];
190 MultiByteToWideChar( CP_ACP, 0, filename, -1, path, MAX_PATH );
191 GetFullPathNameW(path, sizeof(manifest_path)/sizeof(WCHAR), manifest_path, NULL);
193 if (manifest_len == -1)
194 manifest_len = strlen(manifest);
196 file = CreateFileW(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
197 FILE_ATTRIBUTE_NORMAL, NULL);
198 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %u\n", GetLastError());
199 if(file == INVALID_HANDLE_VALUE)
200 return FALSE;
201 WriteFile(file, manifest, manifest_len, &size, NULL);
202 CloseHandle(file);
204 if (depmanifest)
206 MultiByteToWideChar( CP_ACP, 0, depfile, -1, path, MAX_PATH );
207 GetFullPathNameW(path, sizeof(depmanifest_path)/sizeof(WCHAR), depmanifest_path, NULL);
208 file = CreateFileW(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
209 FILE_ATTRIBUTE_NORMAL, NULL);
210 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %u\n", GetLastError());
211 if(file == INVALID_HANDLE_VALUE)
212 return FALSE;
213 WriteFile(file, depmanifest, strlen(depmanifest), &size, NULL);
214 CloseHandle(file);
216 return TRUE;
219 static BOOL create_wide_manifest(const char *filename, const char *manifest, BOOL fBOM, BOOL fReverse)
221 WCHAR *wmanifest = HeapAlloc(GetProcessHeap(), 0, (strlen(manifest)+2) * sizeof(WCHAR));
222 BOOL ret;
223 int offset = (fBOM ? 0 : 1);
225 MultiByteToWideChar(CP_ACP, 0, manifest, -1, &wmanifest[1], (strlen(manifest)+1) * sizeof(WCHAR));
226 wmanifest[0] = 0xfeff;
227 if (fReverse)
229 size_t i;
230 for (i = 0; i < strlen(manifest)+1; i++)
231 wmanifest[i] = (wmanifest[i] << 8) | ((wmanifest[i] >> 8) & 0xff);
233 ret = create_manifest_file(filename, (char *)&wmanifest[offset], (strlen(manifest)+1-offset) * sizeof(WCHAR), NULL, NULL);
234 HeapFree(GetProcessHeap(), 0, wmanifest);
235 return ret;
238 typedef struct {
239 ULONG format_version;
240 ULONG assembly_cnt;
241 ULONG root_manifest_type;
242 LPWSTR root_manifest_path;
243 ULONG root_config_type;
244 ULONG app_dir_type;
245 LPCWSTR app_dir;
246 } detailed_info_t;
248 static const detailed_info_t detailed_info0 = {
249 0, 0, 0, NULL, 0, 0, NULL
252 static const detailed_info_t detailed_info1 = {
253 1, 1, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE, manifest_path,
254 ACTIVATION_CONTEXT_PATH_TYPE_NONE, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE,
255 work_dir,
258 static const detailed_info_t detailed_info1_child = {
259 1, 1, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE, app_manifest_path,
260 ACTIVATION_CONTEXT_PATH_TYPE_NONE, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE,
261 app_dir,
264 static const detailed_info_t detailed_info2 = {
265 1, 2, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE, manifest_path,
266 ACTIVATION_CONTEXT_PATH_TYPE_NONE, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE,
267 work_dir,
270 static void test_detailed_info(HANDLE handle, const detailed_info_t *exinfo)
272 ACTIVATION_CONTEXT_DETAILED_INFORMATION detailed_info_tmp, *detailed_info;
273 SIZE_T size, exsize, retsize;
274 BOOL b;
276 exsize = sizeof(ACTIVATION_CONTEXT_DETAILED_INFORMATION)
277 + (exinfo->root_manifest_path ? (lstrlenW(exinfo->root_manifest_path)+1)*sizeof(WCHAR):0)
278 + (exinfo->app_dir ? (lstrlenW(exinfo->app_dir)+1)*sizeof(WCHAR) : 0);
280 if(exsize != sizeof(ACTIVATION_CONTEXT_DETAILED_INFORMATION)) {
281 size = 0xdeadbeef;
282 b = pQueryActCtxW(0, handle, NULL,
283 ActivationContextDetailedInformation, &detailed_info_tmp,
284 sizeof(detailed_info_tmp), &size);
285 ok(!b, "QueryActCtx succeeded\n");
286 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetLastError() = %u\n", GetLastError());
287 ok(size == exsize, "size=%ld, expected %ld\n", size, exsize);
288 }else {
289 size = sizeof(ACTIVATION_CONTEXT_DETAILED_INFORMATION);
292 detailed_info = HeapAlloc(GetProcessHeap(), 0, size);
293 memset(detailed_info, 0xfe, size);
294 b = pQueryActCtxW(0, handle, NULL,
295 ActivationContextDetailedInformation, detailed_info,
296 size, &retsize);
297 ok(b, "QueryActCtx failed: %u\n", GetLastError());
298 ok(retsize == exsize, "size=%ld, expected %ld\n", retsize, exsize);
300 ok(detailed_info->dwFlags == 0, "detailed_info->dwFlags=%x\n", detailed_info->dwFlags);
301 ok(detailed_info->ulFormatVersion == exinfo->format_version,
302 "detailed_info->ulFormatVersion=%u, expected %u\n", detailed_info->ulFormatVersion,
303 exinfo->format_version);
304 ok(detailed_info->ulAssemblyCount == exinfo->assembly_cnt,
305 "detailed_info->ulAssemblyCount=%u, expected %u\n", detailed_info->ulAssemblyCount,
306 exinfo->assembly_cnt);
307 ok(detailed_info->ulRootManifestPathType == exinfo->root_manifest_type,
308 "detailed_info->ulRootManifestPathType=%u, expected %u\n",
309 detailed_info->ulRootManifestPathType, exinfo->root_manifest_type);
310 ok(detailed_info->ulRootManifestPathChars ==
311 (exinfo->root_manifest_path ? lstrlenW(exinfo->root_manifest_path) : 0),
312 "detailed_info->ulRootManifestPathChars=%u, expected %u\n",
313 detailed_info->ulRootManifestPathChars,
314 exinfo->root_manifest_path ?lstrlenW(exinfo->root_manifest_path) : 0);
315 ok(detailed_info->ulRootConfigurationPathType == exinfo->root_config_type,
316 "detailed_info->ulRootConfigurationPathType=%u, expected %u\n",
317 detailed_info->ulRootConfigurationPathType, exinfo->root_config_type);
318 ok(detailed_info->ulRootConfigurationPathChars == 0,
319 "detailed_info->ulRootConfigurationPathChars=%d\n", detailed_info->ulRootConfigurationPathChars);
320 ok(detailed_info->ulAppDirPathType == exinfo->app_dir_type,
321 "detailed_info->ulAppDirPathType=%u, expected %u\n", detailed_info->ulAppDirPathType,
322 exinfo->app_dir_type);
323 ok(detailed_info->ulAppDirPathChars == (exinfo->app_dir ? lstrlenW(exinfo->app_dir) : 0),
324 "detailed_info->ulAppDirPathChars=%u, expected %u\n",
325 detailed_info->ulAppDirPathChars, exinfo->app_dir ? lstrlenW(exinfo->app_dir) : 0);
326 if(exinfo->root_manifest_path) {
327 ok(detailed_info->lpRootManifestPath != NULL, "detailed_info->lpRootManifestPath == NULL\n");
328 if(detailed_info->lpRootManifestPath)
329 ok(!lstrcmpiW(detailed_info->lpRootManifestPath, exinfo->root_manifest_path),
330 "unexpected detailed_info->lpRootManifestPath\n");
331 }else {
332 ok(detailed_info->lpRootManifestPath == NULL, "detailed_info->lpRootManifestPath != NULL\n");
334 ok(detailed_info->lpRootConfigurationPath == NULL,
335 "detailed_info->lpRootConfigurationPath=%p\n", detailed_info->lpRootConfigurationPath);
336 if(exinfo->app_dir) {
337 ok(detailed_info->lpAppDirPath != NULL, "detailed_info->lpAppDirPath == NULL\n");
338 if(detailed_info->lpAppDirPath)
339 ok(!lstrcmpiW(exinfo->app_dir, detailed_info->lpAppDirPath),
340 "unexpected detailed_info->lpAppDirPath\n%s\n",strw(detailed_info->lpAppDirPath));
341 }else {
342 ok(detailed_info->lpAppDirPath == NULL, "detailed_info->lpAppDirPath != NULL\n");
345 HeapFree(GetProcessHeap(), 0, detailed_info);
348 typedef struct {
349 ULONG flags;
350 /* ULONG manifest_path_type; FIXME */
351 LPCWSTR manifest_path;
352 LPCSTR encoded_assembly_id;
353 BOOL has_assembly_dir;
354 } info_in_assembly;
356 static const info_in_assembly manifest1_info = {
357 1, manifest_path,
358 "Wine.Test,type=\"win32\",version=\"1.0.0.0\"",
359 FALSE
362 static const info_in_assembly manifest1_child_info = {
363 1, app_manifest_path,
364 "Wine.Test,type=\"win32\",version=\"1.0.0.0\"",
365 FALSE
368 static const info_in_assembly manifest2_info = {
369 1, manifest_path,
370 "Wine.Test,type=\"win32\",version=\"1.2.3.4\"",
371 FALSE
374 static const info_in_assembly manifest3_info = {
375 1, manifest_path,
376 "Wine.Test,publicKeyToken=\"6595b6414666f1df\",type=\"win32\",version=\"1.2.3.4\"",
377 FALSE
380 static const info_in_assembly manifest4_info = {
381 1, manifest_path,
382 "Wine.Test,type=\"win32\",version=\"1.2.3.4\"",
383 FALSE
386 static const info_in_assembly depmanifest1_info = {
387 0x10, depmanifest_path,
388 "testdep,processorArchitecture=\"x86\","
389 "type=\"win32\",version=\"6.5.4.3\"",
390 TRUE
393 static const info_in_assembly depmanifest2_info = {
394 0x10, depmanifest_path,
395 "testdep,processorArchitecture=\"x86\","
396 "type=\"win32\",version=\"6.5.4.3\"",
397 TRUE
400 static const info_in_assembly depmanifest3_info = {
401 0x10, depmanifest_path,
402 "testdep,processorArchitecture=\"x86\",type=\"win32\",version=\"6.5.4.3\"",
403 TRUE
406 static const info_in_assembly manifest_comctrl_info = {
407 0, NULL, NULL, TRUE /* These values may differ between Windows installations */
410 static void test_info_in_assembly(HANDLE handle, DWORD id, const info_in_assembly *exinfo)
412 ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION *info, info_tmp;
413 SIZE_T size, exsize;
414 ULONG len;
415 BOOL b;
417 exsize = sizeof(ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION);
418 if (exinfo->manifest_path) exsize += (lstrlenW(exinfo->manifest_path)+1) * sizeof(WCHAR);
419 if (exinfo->encoded_assembly_id) exsize += (strlen_aw(exinfo->encoded_assembly_id) + 1) * sizeof(WCHAR);
421 size = 0xdeadbeef;
422 b = pQueryActCtxW(0, handle, &id,
423 AssemblyDetailedInformationInActivationContext, &info_tmp,
424 sizeof(info_tmp), &size);
425 ok(!b, "QueryActCtx succeeded\n");
426 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetLastError() = %u\n", GetLastError());
428 ok(size >= exsize, "size=%lu, expected %lu\n", size, exsize);
430 if (size == 0xdeadbeef)
432 skip("bad size\n");
433 return;
436 info = HeapAlloc(GetProcessHeap(), 0, size);
437 memset(info, 0xfe, size);
439 size = 0xdeadbeef;
440 b = pQueryActCtxW(0, handle, &id,
441 AssemblyDetailedInformationInActivationContext, info, size, &size);
442 ok(b, "QueryActCtx failed: %u\n", GetLastError());
443 if (!exinfo->manifest_path)
444 exsize += info->ulManifestPathLength + sizeof(WCHAR);
445 if (!exinfo->encoded_assembly_id)
446 exsize += info->ulEncodedAssemblyIdentityLength + sizeof(WCHAR);
447 if (exinfo->has_assembly_dir)
448 exsize += info->ulAssemblyDirectoryNameLength + sizeof(WCHAR);
449 ok(size == exsize, "size=%lu, expected %lu\n", size, exsize);
451 if (0) /* FIXME: flags meaning unknown */
453 ok((info->ulFlags) == exinfo->flags, "info->ulFlags = %x, expected %x\n",
454 info->ulFlags, exinfo->flags);
456 if(exinfo->encoded_assembly_id) {
457 len = strlen_aw(exinfo->encoded_assembly_id)*sizeof(WCHAR);
458 ok(info->ulEncodedAssemblyIdentityLength == len,
459 "info->ulEncodedAssemblyIdentityLength = %u, expected %u\n",
460 info->ulEncodedAssemblyIdentityLength, len);
461 } else {
462 ok(info->ulEncodedAssemblyIdentityLength != 0,
463 "info->ulEncodedAssemblyIdentityLength == 0\n");
465 ok(info->ulManifestPathType == ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE,
466 "info->ulManifestPathType = %x\n", info->ulManifestPathType);
467 if(exinfo->manifest_path) {
468 len = lstrlenW(exinfo->manifest_path)*sizeof(WCHAR);
469 ok(info->ulManifestPathLength == len, "info->ulManifestPathLength = %u, expected %u\n",
470 info->ulManifestPathLength, len);
471 } else {
472 ok(info->ulManifestPathLength != 0, "info->ulManifestPathLength == 0\n");
475 ok(info->ulPolicyPathType == ACTIVATION_CONTEXT_PATH_TYPE_NONE,
476 "info->ulPolicyPathType = %x\n", info->ulPolicyPathType);
477 ok(info->ulPolicyPathLength == 0,
478 "info->ulPolicyPathLength = %u, expected 0\n", info->ulPolicyPathLength);
479 ok(info->ulMetadataSatelliteRosterIndex == 0, "info->ulMetadataSatelliteRosterIndex = %x\n",
480 info->ulMetadataSatelliteRosterIndex);
481 ok(info->ulManifestVersionMajor == 1,"info->ulManifestVersionMajor = %x\n",
482 info->ulManifestVersionMajor);
483 ok(info->ulManifestVersionMinor == 0, "info->ulManifestVersionMinor = %x\n",
484 info->ulManifestVersionMinor);
485 ok(info->ulPolicyVersionMajor == 0, "info->ulPolicyVersionMajor = %x\n",
486 info->ulPolicyVersionMajor);
487 ok(info->ulPolicyVersionMinor == 0, "info->ulPolicyVersionMinor = %x\n",
488 info->ulPolicyVersionMinor);
489 if(exinfo->has_assembly_dir)
490 ok(info->ulAssemblyDirectoryNameLength != 0,
491 "info->ulAssemblyDirectoryNameLength == 0\n");
492 else
493 ok(info->ulAssemblyDirectoryNameLength == 0,
494 "info->ulAssemblyDirectoryNameLength != 0\n");
496 ok(info->lpAssemblyEncodedAssemblyIdentity != NULL,
497 "info->lpAssemblyEncodedAssemblyIdentity == NULL\n");
498 if(info->lpAssemblyEncodedAssemblyIdentity && exinfo->encoded_assembly_id) {
499 ok(!strcmp_aw(info->lpAssemblyEncodedAssemblyIdentity, exinfo->encoded_assembly_id),
500 "unexpected info->lpAssemblyEncodedAssemblyIdentity %s / %s\n",
501 strw(info->lpAssemblyEncodedAssemblyIdentity), exinfo->encoded_assembly_id);
503 if(exinfo->manifest_path) {
504 ok(info->lpAssemblyManifestPath != NULL, "info->lpAssemblyManifestPath == NULL\n");
505 if(info->lpAssemblyManifestPath)
506 ok(!lstrcmpiW(info->lpAssemblyManifestPath, exinfo->manifest_path),
507 "unexpected info->lpAssemblyManifestPath\n");
508 }else {
509 ok(info->lpAssemblyManifestPath != NULL, "info->lpAssemblyManifestPath == NULL\n");
512 ok(info->lpAssemblyPolicyPath == NULL, "info->lpAssemblyPolicyPath != NULL\n");
513 if(info->lpAssemblyPolicyPath)
514 ok(*(WORD*)info->lpAssemblyPolicyPath == 0, "info->lpAssemblyPolicyPath is not empty\n");
515 if(exinfo->has_assembly_dir)
516 ok(info->lpAssemblyDirectoryName != NULL, "info->lpAssemblyDirectoryName == NULL\n");
517 else
518 ok(info->lpAssemblyDirectoryName == NULL, "info->lpAssemblyDirectoryName = %s\n",
519 strw(info->lpAssemblyDirectoryName));
520 HeapFree(GetProcessHeap(), 0, info);
523 static void test_file_info(HANDLE handle, ULONG assid, ULONG fileid, LPCWSTR filename)
525 ASSEMBLY_FILE_DETAILED_INFORMATION *info, info_tmp;
526 ACTIVATION_CONTEXT_QUERY_INDEX index = {assid, fileid};
527 SIZE_T size, exsize;
528 BOOL b;
530 exsize = sizeof(ASSEMBLY_FILE_DETAILED_INFORMATION)
531 +(lstrlenW(filename)+1)*sizeof(WCHAR);
533 size = 0xdeadbeef;
534 b = pQueryActCtxW(0, handle, &index,
535 FileInformationInAssemblyOfAssemblyInActivationContext, &info_tmp,
536 sizeof(info_tmp), &size);
537 ok(!b, "QueryActCtx succeeded\n");
538 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetLastError() = %u\n", GetLastError());
539 ok(size == exsize, "size=%lu, expected %lu\n", size, exsize);
541 if(size == 0xdeadbeef)
543 skip("bad size\n");
544 return;
547 info = HeapAlloc(GetProcessHeap(), 0, size);
548 memset(info, 0xfe, size);
550 b = pQueryActCtxW(0, handle, &index,
551 FileInformationInAssemblyOfAssemblyInActivationContext, info, size, &size);
552 ok(b, "QueryActCtx failed: %u\n", GetLastError());
553 ok(!size, "size=%lu, expected 0\n", size);
555 ok(info->ulFlags == 2, "info->ulFlags=%x, expected 2\n", info->ulFlags);
556 ok(info->ulFilenameLength == lstrlenW(filename)*sizeof(WCHAR),
557 "info->ulFilenameLength=%u, expected %u\n",
558 info->ulFilenameLength, lstrlenW(filename)*sizeof(WCHAR));
559 ok(info->ulPathLength == 0, "info->ulPathLength=%u\n", info->ulPathLength);
560 ok(info->lpFileName != NULL, "info->lpFileName == NULL\n");
561 if(info->lpFileName)
562 ok(!lstrcmpiW(info->lpFileName, filename), "unexpected info->lpFileName\n");
563 ok(info->lpFilePath == NULL, "info->lpFilePath != NULL\n");
564 HeapFree(GetProcessHeap(), 0, info);
567 static HANDLE test_create(const char *file, const char *manifest)
569 ACTCTXW actctx;
570 HANDLE handle;
571 WCHAR path[MAX_PATH];
573 MultiByteToWideChar( CP_ACP, 0, file, -1, path, MAX_PATH );
574 memset(&actctx, 0, sizeof(ACTCTXW));
575 actctx.cbSize = sizeof(ACTCTXW);
576 actctx.lpSource = path;
578 handle = pCreateActCtxW(&actctx);
579 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
581 ok(actctx.cbSize == sizeof(actctx), "actctx.cbSize=%d\n", actctx.cbSize);
582 ok(actctx.dwFlags == 0, "actctx.=%d\n", actctx.dwFlags);
583 ok(actctx.lpSource == path, "actctx.lpSource=%p\n", actctx.lpSource);
584 ok(actctx.wProcessorArchitecture == 0,
585 "actctx.wProcessorArchitecture=%d\n", actctx.wProcessorArchitecture);
586 ok(actctx.wLangId == 0, "actctx.wLangId=%d\n", actctx.wLangId);
587 ok(actctx.lpAssemblyDirectory == NULL,
588 "actctx.lpAssemblyDirectory=%p\n", actctx.lpAssemblyDirectory);
589 ok(actctx.lpResourceName == NULL, "actctx.lpResourceName=%p\n", actctx.lpResourceName);
590 ok(actctx.lpApplicationName == NULL, "actctx.lpApplocationName=%p\n",
591 actctx.lpApplicationName);
592 ok(actctx.hModule == NULL, "actctx.hModule=%p\n", actctx.hModule);
594 return handle;
597 static void test_create_and_fail(const char *manifest, const char *depmanifest, int todo)
599 ACTCTXW actctx;
600 HANDLE handle;
601 WCHAR path[MAX_PATH];
603 MultiByteToWideChar( CP_ACP, 0, "bad.manifest", -1, path, MAX_PATH );
604 memset(&actctx, 0, sizeof(ACTCTXW));
605 actctx.cbSize = sizeof(ACTCTXW);
606 actctx.lpSource = path;
608 create_manifest_file("bad.manifest", manifest, -1, "testdep.manifest", depmanifest);
609 handle = pCreateActCtxW(&actctx);
610 if (todo) todo_wine
612 ok(handle == INVALID_HANDLE_VALUE, "handle != INVALID_HANDLE_VALUE\n");
613 ok(GetLastError() == ERROR_SXS_CANT_GEN_ACTCTX, "GetLastError == %u\n", GetLastError());
615 else
617 ok(handle == INVALID_HANDLE_VALUE, "handle != INVALID_HANDLE_VALUE\n");
618 ok(GetLastError() == ERROR_SXS_CANT_GEN_ACTCTX, "GetLastError == %u\n", GetLastError());
620 if (handle != INVALID_HANDLE_VALUE) pReleaseActCtx( handle );
621 DeleteFileA("bad.manifest");
622 DeleteFileA("testdep.manifest");
625 static void test_create_wide_and_fail(const char *manifest, BOOL fBOM)
627 ACTCTXW actctx;
628 HANDLE handle;
629 WCHAR path[MAX_PATH];
631 MultiByteToWideChar( CP_ACP, 0, "bad.manifest", -1, path, MAX_PATH );
632 memset(&actctx, 0, sizeof(ACTCTXW));
633 actctx.cbSize = sizeof(ACTCTXW);
634 actctx.lpSource = path;
636 create_wide_manifest("bad.manifest", manifest, fBOM, FALSE);
637 handle = pCreateActCtxW(&actctx);
638 ok(handle == INVALID_HANDLE_VALUE, "handle != INVALID_HANDLE_VALUE\n");
639 ok(GetLastError() == ERROR_SXS_CANT_GEN_ACTCTX, "GetLastError == %u\n", GetLastError());
641 if (handle != INVALID_HANDLE_VALUE) pReleaseActCtx( handle );
642 DeleteFileA("bad.manifest");
645 static void test_create_fail(void)
647 ACTCTXW actctx;
648 HANDLE handle;
649 WCHAR path[MAX_PATH];
651 MultiByteToWideChar( CP_ACP, 0, "nonexistent.manifest", -1, path, MAX_PATH );
652 memset(&actctx, 0, sizeof(ACTCTXW));
653 actctx.cbSize = sizeof(ACTCTXW);
654 actctx.lpSource = path;
656 handle = pCreateActCtxW(&actctx);
657 ok(handle == INVALID_HANDLE_VALUE, "handle != INVALID_HANDLE_VALUE\n");
658 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "GetLastError == %u\n", GetLastError());
660 trace("wrong_manifest1\n");
661 test_create_and_fail(wrong_manifest1, NULL, 0 );
662 trace("wrong_manifest2\n");
663 test_create_and_fail(wrong_manifest2, NULL, 0 );
664 trace("wrong_manifest3\n");
665 test_create_and_fail(wrong_manifest3, NULL, 1 );
666 trace("wrong_manifest4\n");
667 test_create_and_fail(wrong_manifest4, NULL, 1 );
668 trace("wrong_manifest5\n");
669 test_create_and_fail(wrong_manifest5, NULL, 0 );
670 trace("wrong_manifest6\n");
671 test_create_and_fail(wrong_manifest6, NULL, 0 );
672 trace("wrong_manifest7\n");
673 test_create_and_fail(wrong_manifest7, NULL, 1 );
674 trace("wrong_manifest8\n");
675 test_create_and_fail(wrong_manifest8, NULL, 0 );
676 trace("UTF-16 manifest1 without BOM\n");
677 test_create_wide_and_fail(manifest1, FALSE );
678 trace("manifest2\n");
679 test_create_and_fail(manifest2, NULL, 0 );
680 trace("manifest2+depmanifest1\n");
681 test_create_and_fail(manifest2, wrong_depmanifest1, 0 );
684 static void test_find_dll_redirection(HANDLE handle, LPCWSTR libname, ULONG exid)
686 ACTCTX_SECTION_KEYED_DATA data;
687 DWORD *p;
688 BOOL ret;
690 memset(&data, 0xfe, sizeof(data));
691 data.cbSize = sizeof(data);
693 ret = pFindActCtxSectionStringW(0, NULL,
694 ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
695 libname, &data);
696 ok(ret, "FindActCtxSectionStringW failed: %u\n", GetLastError());
697 if(!ret)
699 skip("couldn't find %s\n",strw(libname));
700 return;
703 ok(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
704 ok(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
705 ok(data.lpData != NULL, "data.lpData == NULL\n");
706 ok(data.ulLength == 20, "data.ulLength=%u\n", data.ulLength);
708 p = data.lpData;
709 if(ret && p) todo_wine {
710 ok(p[0] == 20 && p[1] == 2 && p[2] == 0 && p[3] == 0 && p[4] == 0,
711 "wrong data %u,%u,%u,%u,%u\n",p[0], p[1], p[2], p[3], p[4]);
714 ok(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
715 ok(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%u\n",
716 data.ulSectionGlobalDataLength);
717 ok(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
718 /* ok(data.ulSectionTotalLength == ??, "data.ulSectionTotalLength=%u\n",
719 data.ulSectionTotalLength); */
720 ok(data.hActCtx == NULL, "data.hActCtx=%p\n", data.hActCtx);
721 ok(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
722 data.ulAssemblyRosterIndex, exid);
724 memset(&data, 0xfe, sizeof(data));
725 data.cbSize = sizeof(data);
727 ret = pFindActCtxSectionStringW(FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX, NULL,
728 ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
729 libname, &data);
730 ok(ret, "FindActCtxSectionStringW failed: %u\n", GetLastError());
731 if(!ret)
733 skip("couldn't find\n");
734 return;
737 ok(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
738 ok(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
739 ok(data.lpData != NULL, "data.lpData == NULL\n");
740 ok(data.ulLength == 20, "data.ulLength=%u\n", data.ulLength);
741 ok(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
742 ok(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%u\n",
743 data.ulSectionGlobalDataLength);
744 ok(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
745 /* ok(data.ulSectionTotalLength == ?? , "data.ulSectionTotalLength=%u\n",
746 data.ulSectionTotalLength); */
747 ok(data.hActCtx == handle, "data.hActCtx=%p\n", data.hActCtx);
748 ok(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
749 data.ulAssemblyRosterIndex, exid);
751 pReleaseActCtx(handle);
754 static void test_find_window_class(HANDLE handle, LPCWSTR clsname, ULONG exid)
756 ACTCTX_SECTION_KEYED_DATA data;
757 BOOL ret;
759 memset(&data, 0xfe, sizeof(data));
760 data.cbSize = sizeof(data);
762 ret = pFindActCtxSectionStringW(0, NULL,
763 ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION,
764 clsname, &data);
765 ok(ret, "FindActCtxSectionStringW failed: %u\n", GetLastError());
766 if(!ret)
768 skip("couldn't find\n");
769 return;
772 ok(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
773 ok(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
774 ok(data.lpData != NULL, "data.lpData == NULL\n");
775 /* ok(data.ulLength == ??, "data.ulLength=%u\n", data.ulLength); */
776 ok(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
777 ok(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%u\n",
778 data.ulSectionGlobalDataLength);
779 ok(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
780 /* ok(data.ulSectionTotalLength == 0, "data.ulSectionTotalLength=%u\n",
781 data.ulSectionTotalLength); FIXME */
782 ok(data.hActCtx == NULL, "data.hActCtx=%p\n", data.hActCtx);
783 ok(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
784 data.ulAssemblyRosterIndex, exid);
786 memset(&data, 0xfe, sizeof(data));
787 data.cbSize = sizeof(data);
789 ret = pFindActCtxSectionStringW(FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX, NULL,
790 ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION,
791 clsname, &data);
792 ok(ret, "FindActCtxSectionStringW failed: %u\n", GetLastError());
793 if(!ret)
795 skip("couldn't find\n");
796 return;
799 ok(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
800 ok(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
801 ok(data.lpData != NULL, "data.lpData == NULL\n");
802 /* ok(data.ulLength == ??, "data.ulLength=%u\n", data.ulLength); FIXME */
803 ok(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
804 ok(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%u\n",
805 data.ulSectionGlobalDataLength);
806 ok(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
807 /* ok(data.ulSectionTotalLength == 0, "data.ulSectionTotalLength=%u\n",
808 data.ulSectionTotalLength); FIXME */
809 ok(data.hActCtx == handle, "data.hActCtx=%p\n", data.hActCtx);
810 ok(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
811 data.ulAssemblyRosterIndex, exid);
813 pReleaseActCtx(handle);
816 static void test_find_string_fail(void)
818 ACTCTX_SECTION_KEYED_DATA data = {sizeof(data)};
819 BOOL ret;
821 ret = pFindActCtxSectionStringW(0, NULL, 100, testlib_dll, &data);
822 ok(!ret, "FindActCtxSectionStringW succeeded\n");
823 ok(GetLastError() == ERROR_SXS_SECTION_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
825 ret = pFindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
826 testlib2_dll, &data);
827 ok(!ret, "FindActCtxSectionStringW succeeded\n");
828 ok(GetLastError() == ERROR_SXS_KEY_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
830 ret = pFindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
831 testlib_dll, NULL);
832 ok(!ret, "FindActCtxSectionStringW succeeded\n");
833 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError()=%u\n", GetLastError());
835 ret = pFindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
836 NULL, &data);
837 ok(!ret, "FindActCtxSectionStringW succeeded\n");
838 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError()=%u\n", GetLastError());
840 data.cbSize = 0;
841 ret = pFindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
842 testlib_dll, &data);
843 ok(!ret, "FindActCtxSectionStringW succeeded\n");
844 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError()=%u\n", GetLastError());
846 data.cbSize = 35;
847 ret = pFindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
848 testlib_dll, &data);
849 ok(!ret, "FindActCtxSectionStringW succeeded\n");
850 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError()=%u\n", GetLastError());
853 static void test_actctx(void)
855 ULONG_PTR cookie;
856 HANDLE handle;
857 BOOL b;
859 test_create_fail();
861 trace("default actctx\n");
863 b = pGetCurrentActCtx(&handle);
864 ok(handle == NULL, "handle = %p, expected NULL\n", handle);
865 ok(b, "GetCurrentActCtx failed: %u\n", GetLastError());
866 if(b) {
867 test_detailed_info(handle, &detailed_info0);
868 pReleaseActCtx(handle);
871 if(!create_manifest_file("test1.manifest", manifest1, -1, NULL, NULL)) {
872 skip("Could not create manifest file\n");
873 return;
876 trace("manifest1\n");
878 handle = test_create("test1.manifest", manifest1);
879 DeleteFileA("test1.manifest");
880 if(handle != INVALID_HANDLE_VALUE) {
881 test_detailed_info(handle, &detailed_info1);
882 test_info_in_assembly(handle, 1, &manifest1_info);
884 if (!IsDebuggerPresent()) /* CloseHandle will generate an exception if a debugger is present */
886 b = CloseHandle(handle);
887 ok(!b, "CloseHandle succeeded\n");
888 ok(GetLastError() == ERROR_INVALID_HANDLE, "GetLastError() == %u\n", GetLastError());
891 pReleaseActCtx(handle);
894 if(!create_manifest_file("test2.manifest", manifest2, -1, "testdep.manifest", testdep_manifest1)) {
895 skip("Could not create manifest file\n");
896 return;
899 trace("manifest2 depmanifest1\n");
901 handle = test_create("test2.manifest", manifest2);
902 DeleteFileA("test2.manifest");
903 DeleteFileA("testdep.manifest");
904 if(handle != INVALID_HANDLE_VALUE) {
905 test_detailed_info(handle, &detailed_info2);
906 test_info_in_assembly(handle, 1, &manifest2_info);
907 test_info_in_assembly(handle, 2, &depmanifest1_info);
908 pReleaseActCtx(handle);
911 if(!create_manifest_file("test3.manifest", manifest2, -1, "testdep.manifest", testdep_manifest2)) {
912 skip("Could not create manifest file\n");
913 return;
916 trace("manifest2 depmanifest2\n");
918 handle = test_create("test3.manifest", manifest2);
919 DeleteFileA("test3.manifest");
920 DeleteFileA("testdep.manifest");
921 if(handle != INVALID_HANDLE_VALUE) {
922 test_detailed_info(handle, &detailed_info2);
923 test_info_in_assembly(handle, 1, &manifest2_info);
924 test_info_in_assembly(handle, 2, &depmanifest2_info);
925 test_file_info(handle, 1, 0, testlib_dll);
926 test_file_info(handle, 1, 1, testlib2_dll);
928 b = pActivateActCtx(handle, &cookie);
929 ok(b, "ActivateActCtx failed: %u\n", GetLastError());
930 test_find_dll_redirection(handle, testlib_dll, 2);
931 test_find_dll_redirection(handle, testlib2_dll, 2);
932 b = pDeactivateActCtx(0, cookie);
933 ok(b, "DeactivateActCtx failed: %u\n", GetLastError());
935 pReleaseActCtx(handle);
938 trace("manifest2 depmanifest3\n");
940 if(!create_manifest_file("test2-3.manifest", manifest2, -1, "testdep.manifest", testdep_manifest3)) {
941 skip("Could not create manifest file\n");
942 return;
945 handle = test_create("test2-3.manifest", manifest2);
946 DeleteFileA("test2-3.manifest");
947 DeleteFileA("testdep.manifest");
948 if(handle != INVALID_HANDLE_VALUE) {
949 test_detailed_info(handle, &detailed_info2);
950 test_info_in_assembly(handle, 1, &manifest2_info);
951 test_info_in_assembly(handle, 2, &depmanifest3_info);
952 test_file_info(handle, 1, 0, testlib_dll);
953 test_file_info(handle, 1, 1, testlib2_dll);
955 b = pActivateActCtx(handle, &cookie);
956 ok(b, "ActivateActCtx failed: %u\n", GetLastError());
957 test_find_dll_redirection(handle, testlib_dll, 2);
958 test_find_dll_redirection(handle, testlib2_dll, 2);
959 test_find_window_class(handle, wndClassW, 2);
960 test_find_window_class(handle, wndClass2W, 2);
961 b = pDeactivateActCtx(0, cookie);
962 ok(b, "DeactivateActCtx failed: %u\n", GetLastError());
964 pReleaseActCtx(handle);
967 trace("manifest3\n");
969 if(!create_manifest_file("test3.manifest", manifest3, -1, NULL, NULL)) {
970 skip("Could not create manifest file\n");
971 return;
974 handle = test_create("test3.manifest", manifest3);
975 DeleteFileA("test3.manifest");
976 if(handle != INVALID_HANDLE_VALUE) {
977 test_detailed_info(handle, &detailed_info1);
978 test_info_in_assembly(handle, 1, &manifest3_info);
979 test_file_info(handle, 0, 0, testlib_dll);
981 b = pActivateActCtx(handle, &cookie);
982 ok(b, "ActivateActCtx failed: %u\n", GetLastError());
983 test_find_dll_redirection(handle, testlib_dll, 1);
984 test_find_dll_redirection(handle, testlib_dll, 1);
985 test_find_string_fail();
986 b = pDeactivateActCtx(0, cookie);
987 ok(b, "DeactivateActCtx failed: %u\n", GetLastError());
989 pReleaseActCtx(handle);
992 trace("manifest4\n");
994 if(!create_manifest_file("test4.manifest", manifest4, -1, NULL, NULL)) {
995 skip("Could not create manifest file\n");
996 return;
999 handle = test_create("test4.manifest", manifest4);
1000 DeleteFileA("test4.manifest");
1001 DeleteFileA("testdep.manifest");
1002 if(handle != INVALID_HANDLE_VALUE) {
1003 test_detailed_info(handle, &detailed_info2);
1004 test_info_in_assembly(handle, 1, &manifest4_info);
1005 test_info_in_assembly(handle, 2, &manifest_comctrl_info);
1006 pReleaseActCtx(handle);
1009 trace("manifest1 in subdir\n");
1011 CreateDirectoryW(work_dir_subdir, NULL);
1012 if (SetCurrentDirectoryW(work_dir_subdir))
1014 if(!create_manifest_file("..\\test1.manifest", manifest1, -1, NULL, NULL)) {
1015 skip("Could not create manifest file\n");
1016 return;
1018 handle = test_create("..\\test1.manifest", manifest1);
1019 DeleteFileA("..\\test1.manifest");
1020 if(handle != INVALID_HANDLE_VALUE) {
1021 test_detailed_info(handle, &detailed_info1);
1022 test_info_in_assembly(handle, 1, &manifest1_info);
1023 pReleaseActCtx(handle);
1025 SetCurrentDirectoryW(work_dir);
1027 else
1028 skip("Couldn't change directory\n");
1029 RemoveDirectoryW(work_dir_subdir);
1031 trace("UTF-16 manifest1, with BOM\n");
1032 if(!create_wide_manifest("test1.manifest", manifest1, TRUE, FALSE)) {
1033 skip("Could not create manifest file\n");
1034 return;
1037 handle = test_create("test1.manifest", manifest1);
1038 DeleteFileA("test1.manifest");
1039 if (handle != INVALID_HANDLE_VALUE) {
1040 test_detailed_info(handle, &detailed_info1);
1041 test_info_in_assembly(handle, 1, &manifest1_info);
1042 pReleaseActCtx(handle);
1045 trace("UTF-16 manifest1, reverse endian, with BOM\n");
1046 if(!create_wide_manifest("test1.manifest", manifest1, TRUE, TRUE)) {
1047 skip("Could not create manifest file\n");
1048 return;
1051 handle = test_create("test1.manifest", manifest1);
1052 DeleteFileA("test1.manifest");
1053 if (handle != INVALID_HANDLE_VALUE) {
1054 test_detailed_info(handle, &detailed_info1);
1055 test_info_in_assembly(handle, 1, &manifest1_info);
1056 pReleaseActCtx(handle);
1061 static void test_app_manifest(void)
1063 HANDLE handle;
1064 BOOL b;
1066 trace("child process manifest1\n");
1068 b = pGetCurrentActCtx(&handle);
1069 ok(handle == NULL, "handle != NULL\n");
1070 ok(b, "GetCurrentActCtx failed: %u\n", GetLastError());
1071 if(b) {
1072 test_detailed_info(handle, &detailed_info1_child);
1073 test_info_in_assembly(handle, 1, &manifest1_child_info);
1074 pReleaseActCtx(handle);
1078 static void run_child_process(void)
1080 char cmdline[MAX_PATH];
1081 char path[MAX_PATH];
1082 char **argv;
1083 PROCESS_INFORMATION pi;
1084 STARTUPINFO si = { 0 };
1086 GetModuleFileNameA(NULL, path, MAX_PATH);
1087 strcat(path, ".manifest");
1088 if(!create_manifest_file(path, manifest1, -1, NULL, NULL)) {
1089 skip("Could not create manifest file\n");
1090 return;
1093 si.cb = sizeof(si);
1094 winetest_get_mainargs( &argv );
1095 sprintf(cmdline, "\"%s\" %s manifest1", argv[0], argv[1]);
1096 ok(CreateProcess(argv[0], cmdline, NULL, NULL, FALSE, 0, NULL, NULL,
1097 &si, &pi) != 0, "Could not create process: %u\n", GetLastError());
1098 CloseHandle(pi.hThread);
1100 WaitForSingleObject(pi.hProcess, INFINITE);
1101 CloseHandle(pi.hProcess);
1102 DeleteFileA(path);
1105 static void init_paths(void)
1107 LPWSTR ptr;
1108 WCHAR last;
1110 static const WCHAR dot_manifest[] = {'.','M','a','n','i','f','e','s','t',0};
1111 static const WCHAR backslash[] = {'\\',0};
1112 static const WCHAR subdir[] = {'T','e','s','t','S','u','b','d','i','r','\\',0};
1114 GetModuleFileNameW(NULL, exe_path, sizeof(exe_path)/sizeof(WCHAR));
1115 lstrcpyW(app_dir, exe_path);
1116 for(ptr=app_dir+lstrlenW(app_dir); *ptr != '\\' && *ptr != '/'; ptr--);
1117 ptr[1] = 0;
1119 GetCurrentDirectoryW(MAX_PATH, work_dir);
1120 last = work_dir[lstrlenW(work_dir) - 1];
1121 if (last != '\\' && last != '/')
1122 lstrcatW(work_dir, backslash);
1123 lstrcpyW(work_dir_subdir, work_dir);
1124 lstrcatW(work_dir_subdir, subdir);
1126 GetModuleFileNameW(NULL, app_manifest_path, sizeof(app_manifest_path)/sizeof(WCHAR));
1127 lstrcpyW(app_manifest_path+lstrlenW(app_manifest_path), dot_manifest);
1130 static BOOL init_funcs(void)
1132 HMODULE hKernel32 = GetModuleHandle("kernel32");
1134 #define X(f) if (!(p##f = (void*)GetProcAddress(hKernel32, #f))) return FALSE;
1135 X(ActivateActCtx);
1136 X(CreateActCtxW);
1137 X(DeactivateActCtx);
1138 X(FindActCtxSectionStringW);
1139 X(GetCurrentActCtx);
1140 X(QueryActCtxW);
1141 X(ReleaseActCtx);
1142 #undef X
1144 return TRUE;
1147 START_TEST(actctx)
1149 int argc;
1150 char **argv;
1152 argc = winetest_get_mainargs(&argv);
1154 if (!init_funcs())
1156 skip("Needed functions are not available\n");
1157 return;
1159 init_paths();
1161 if(argc > 2 && !strcmp(argv[2], "manifest1")) {
1162 test_app_manifest();
1163 return;
1166 test_actctx();
1167 run_child_process();