ntdll: Implement compatible typelib section.
[wine/multimedia.git] / dlls / kernel32 / tests / actctx.c
blob1a53749c63e8e071ddbbb21ae10b92625aa4c611
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 #include "oaidl.h"
28 #include "initguid.h"
30 static BOOL (WINAPI *pActivateActCtx)(HANDLE,ULONG_PTR*);
31 static HANDLE (WINAPI *pCreateActCtxW)(PCACTCTXW);
32 static BOOL (WINAPI *pDeactivateActCtx)(DWORD,ULONG_PTR);
33 static BOOL (WINAPI *pFindActCtxSectionStringW)(DWORD,const GUID *,ULONG,LPCWSTR,PACTCTX_SECTION_KEYED_DATA);
34 static BOOL (WINAPI *pGetCurrentActCtx)(HANDLE *);
35 static BOOL (WINAPI *pIsDebuggerPresent)(void);
36 static BOOL (WINAPI *pQueryActCtxW)(DWORD,HANDLE,PVOID,ULONG,PVOID,SIZE_T,SIZE_T*);
37 static VOID (WINAPI *pReleaseActCtx)(HANDLE);
38 static BOOL (WINAPI *pFindActCtxSectionGuid)(DWORD,const GUID*,ULONG,const GUID*,PACTCTX_SECTION_KEYED_DATA);
40 static const char* strw(LPCWSTR x)
42 static char buffer[1024];
43 char* p = buffer;
45 if (!x) return "(nil)";
46 else while ((*p++ = *x++));
47 return buffer;
50 static const char *debugstr_guid(REFIID riid)
52 static char buf[50];
54 sprintf(buf, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
55 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
56 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
57 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
59 return buf;
62 #ifdef __i386__
63 #define ARCH "x86"
64 #elif defined __x86_64__
65 #define ARCH "amd64"
66 #else
67 #define ARCH "none"
68 #endif
70 static const char manifest1[] =
71 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
72 "<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
73 "</assembly>";
75 static const char manifest2[] =
76 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
77 "<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\">"
78 "</assemblyIdentity>"
79 "<dependency>"
80 "<dependentAssembly>"
81 "<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"" ARCH "\">"
82 "</assemblyIdentity>"
83 "</dependentAssembly>"
84 "</dependency>"
85 "</assembly>";
87 DEFINE_GUID(IID_CoTest, 0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x11, 0x11, 0x22, 0x22, 0x33, 0x33);
88 DEFINE_GUID(IID_TlibTest, 0x99999999, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55);
89 DEFINE_GUID(IID_TlibTest2, 0x99999999, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x56);
90 DEFINE_GUID(IID_TlibTest3, 0x99999999, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x57);
91 DEFINE_GUID(IID_TlibTest4, 0x99999999, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x58);
93 static const char manifest3[] =
94 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
95 "<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\""
96 " publicKeyToken=\"6595b6414666f1df\" />"
97 "<file name=\"testlib.dll\">"
98 "<windowClass>wndClass</windowClass>"
99 " <comClass description=\"Test com class\""
100 " clsid=\"{12345678-1234-5678-1234-111122223333}\""
101 " tlbid=\"{99999999-8888-7777-6666-555555555555}\""
102 " threadingModel=\"Neutral\""
103 " progid=\"ProgId.ProgId\""
104 " />"
105 "</file>"
106 "</assembly>";
108 static const char manifest_wndcls1[] =
109 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
110 "<assemblyIdentity version=\"1.2.3.4\" name=\"testdep1\" type=\"win32\" processorArchitecture=\"" ARCH "\"/>"
111 "<file name=\"testlib1.dll\">"
112 "<windowClass versioned=\"yes\">wndClass1</windowClass>"
113 "<windowClass>wndClass2</windowClass>"
114 " <typelib tlbid=\"{99999999-8888-7777-6666-555555555558}\" version=\"1.0\" helpdir=\"\" />"
115 "</file>"
116 "<file name=\"testlib1_2.dll\" />"
117 "</assembly>";
119 static const char manifest_wndcls2[] =
120 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
121 "<assemblyIdentity version=\"4.3.2.1\" name=\"testdep2\" type=\"win32\" processorArchitecture=\"" ARCH "\" />"
122 "<file name=\"testlib2.dll\">"
123 " <windowClass versioned=\"no\">wndClass3</windowClass>"
124 " <windowClass>wndClass4</windowClass>"
125 " <typelib tlbid=\"{99999999-8888-7777-6666-555555555555}\" version=\"1.0\" helpdir=\"help\" resourceid=\"409\""
126 " flags=\"HIDDEN,CONTROL,RESTRICTED\" />"
127 " <typelib tlbid=\"{99999999-8888-7777-6666-555555555556}\" version=\"1.0\" helpdir=\"help1\" resourceid=\"409\" />"
128 " <typelib tlbid=\"{99999999-8888-7777-6666-555555555557}\" version=\"1.0\" helpdir=\"\" />"
129 "</file>"
130 "<file name=\"testlib2_2.dll\" />"
131 "</assembly>";
133 static const char manifest_wndcls_main[] =
134 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
135 "<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\" />"
136 "<dependency>"
137 " <dependentAssembly>"
138 " <assemblyIdentity type=\"win32\" name=\"testdep1\" version=\"1.2.3.4\" processorArchitecture=\"" ARCH "\" />"
139 " </dependentAssembly>"
140 "</dependency>"
141 "<dependency>"
142 " <dependentAssembly>"
143 " <assemblyIdentity type=\"win32\" name=\"testdep2\" version=\"4.3.2.1\" processorArchitecture=\"" ARCH "\" />"
144 " </dependentAssembly>"
145 "</dependency>"
146 "</assembly>";
148 static const char manifest4[] =
149 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
150 "<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\">"
151 "</assemblyIdentity>"
152 "<dependency>"
153 "<dependentAssembly>"
154 "<assemblyIdentity type=\"win32\" name=\"Microsoft.Windows.Common-Controls\" "
155 "version=\"6.0.1.0\" processorArchitecture=\"" ARCH "\" publicKeyToken=\"6595b64144ccf1df\">"
156 "</assemblyIdentity>"
157 "</dependentAssembly>"
158 "</dependency>"
159 "</assembly>";
161 static const char testdep_manifest1[] =
162 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
163 "<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"" ARCH "\"/>"
164 "</assembly>";
166 static const char testdep_manifest2[] =
167 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
168 "<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"" ARCH "\" />"
169 "<file name=\"testlib.dll\"></file>"
170 "<file name=\"testlib2.dll\" hash=\"63c978c2b53d6cf72b42fb7308f9af12ab19ec53\" hashalg=\"SHA1\" />"
171 "</assembly>";
173 static const char testdep_manifest3[] =
174 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\"> "
175 "<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"" ARCH "\"/>"
176 "<file name=\"testlib.dll\"/>"
177 "<file name=\"testlib2.dll\" hash=\"63c978c2b53d6cf72b42fb7308f9af12ab19ec53\" hashalg=\"SHA1\">"
178 "<windowClass>wndClass</windowClass>"
179 "<windowClass>wndClass2</windowClass>"
180 "</file>"
181 "</assembly>";
183 static const char wrong_manifest1[] =
184 "<assembly manifestVersion=\"1.0\">"
185 "<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
186 "</assembly>";
188 static const char wrong_manifest2[] =
189 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\">"
190 "<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
191 "</assembly>";
193 static const char wrong_manifest3[] =
194 "<assembly test=\"test\" xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
195 "<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
196 "</assembly>";
198 static const char wrong_manifest4[] =
199 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
200 "<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
201 "<test></test>"
202 "</assembly>";
204 static const char wrong_manifest5[] =
205 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
206 "<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
207 "</assembly>"
208 "<test></test>";
210 static const char wrong_manifest6[] =
211 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v5\" manifestVersion=\"1.0\">"
212 "<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
213 "</assembly>";
215 static const char wrong_manifest7[] =
216 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
217 "<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"" ARCH "\" />"
218 "<file name=\"testlib.dll\" hash=\"63c978c2b53d6cf72b42fb7308f9af12ab19ec5\" hashalg=\"SHA1\" />"
219 "</assembly>";
221 static const char wrong_manifest8[] =
222 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
223 "<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
224 "<file></file>"
225 "</assembly>";
227 static const char wrong_depmanifest1[] =
228 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
229 "<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.4\" processorArchitecture=\"" ARCH "\" />"
230 "</assembly>";
232 static const WCHAR testlib_dll[] =
233 {'t','e','s','t','l','i','b','.','d','l','l',0};
234 static const WCHAR testlib2_dll[] =
235 {'t','e','s','t','l','i','b','2','.','d','l','l',0};
236 static const WCHAR wndClassW[] =
237 {'w','n','d','C','l','a','s','s',0};
238 static const WCHAR wndClass1W[] =
239 {'w','n','d','C','l','a','s','s','1',0};
240 static const WCHAR wndClass2W[] =
241 {'w','n','d','C','l','a','s','s','2',0};
242 static const WCHAR wndClass3W[] =
243 {'w','n','d','C','l','a','s','s','3',0};
244 static const WCHAR acr_manifest[] =
245 {'a','c','r','.','m','a','n','i','f','e','s','t',0};
247 static WCHAR app_dir[MAX_PATH], exe_path[MAX_PATH], work_dir[MAX_PATH], work_dir_subdir[MAX_PATH];
248 static WCHAR app_manifest_path[MAX_PATH], manifest_path[MAX_PATH], depmanifest_path[MAX_PATH];
250 static int strcmp_aw(LPCWSTR strw, const char *stra)
252 WCHAR buf[1024];
254 if (!stra) return 1;
255 MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(WCHAR));
256 return lstrcmpW(strw, buf);
259 static DWORD strlen_aw(const char *str)
261 return MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0) - 1;
264 static BOOL create_manifest_file(const char *filename, const char *manifest, int manifest_len,
265 const char *depfile, const char *depmanifest)
267 DWORD size;
268 HANDLE file;
269 WCHAR path[MAX_PATH];
271 MultiByteToWideChar( CP_ACP, 0, filename, -1, path, MAX_PATH );
272 GetFullPathNameW(path, sizeof(manifest_path)/sizeof(WCHAR), manifest_path, NULL);
274 if (manifest_len == -1)
275 manifest_len = strlen(manifest);
277 file = CreateFileW(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
278 FILE_ATTRIBUTE_NORMAL, NULL);
279 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %u\n", GetLastError());
280 if(file == INVALID_HANDLE_VALUE)
281 return FALSE;
282 WriteFile(file, manifest, manifest_len, &size, NULL);
283 CloseHandle(file);
285 if (depmanifest)
287 MultiByteToWideChar( CP_ACP, 0, depfile, -1, path, MAX_PATH );
288 GetFullPathNameW(path, sizeof(depmanifest_path)/sizeof(WCHAR), depmanifest_path, NULL);
289 file = CreateFileW(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
290 FILE_ATTRIBUTE_NORMAL, NULL);
291 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %u\n", GetLastError());
292 if(file == INVALID_HANDLE_VALUE)
293 return FALSE;
294 WriteFile(file, depmanifest, strlen(depmanifest), &size, NULL);
295 CloseHandle(file);
297 return TRUE;
300 static BOOL create_wide_manifest(const char *filename, const char *manifest, BOOL fBOM, BOOL fReverse)
302 WCHAR *wmanifest = HeapAlloc(GetProcessHeap(), 0, (strlen(manifest)+2) * sizeof(WCHAR));
303 BOOL ret;
304 int offset = (fBOM ? 0 : 1);
306 MultiByteToWideChar(CP_ACP, 0, manifest, -1, &wmanifest[1], (strlen(manifest)+1));
307 wmanifest[0] = 0xfeff;
308 if (fReverse)
310 size_t i;
311 for (i = 0; i < strlen(manifest)+1; i++)
312 wmanifest[i] = (wmanifest[i] << 8) | ((wmanifest[i] >> 8) & 0xff);
314 ret = create_manifest_file(filename, (char *)&wmanifest[offset], (strlen(manifest)+1-offset) * sizeof(WCHAR), NULL, NULL);
315 HeapFree(GetProcessHeap(), 0, wmanifest);
316 return ret;
319 typedef struct {
320 ULONG format_version;
321 ULONG assembly_cnt_min;
322 ULONG assembly_cnt_max;
323 ULONG root_manifest_type;
324 LPWSTR root_manifest_path;
325 ULONG root_config_type;
326 ULONG app_dir_type;
327 LPCWSTR app_dir;
328 } detailed_info_t;
330 static const detailed_info_t detailed_info0 = {
331 0, 0, 0, 0, NULL, 0, 0, NULL
334 static const detailed_info_t detailed_info1 = {
335 1, 1, 1, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE, manifest_path,
336 ACTIVATION_CONTEXT_PATH_TYPE_NONE, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE,
337 work_dir,
340 static const detailed_info_t detailed_info1_child = {
341 1, 1, 1, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE, app_manifest_path,
342 ACTIVATION_CONTEXT_PATH_TYPE_NONE, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE,
343 app_dir,
346 /* On Vista+, there's an extra assembly for Microsoft.Windows.Common-Controls.Resources */
347 static const detailed_info_t detailed_info2 = {
348 1, 2, 3, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE, manifest_path,
349 ACTIVATION_CONTEXT_PATH_TYPE_NONE, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE,
350 work_dir,
353 static void test_detailed_info(HANDLE handle, const detailed_info_t *exinfo, int line)
355 ACTIVATION_CONTEXT_DETAILED_INFORMATION detailed_info_tmp, *detailed_info;
356 SIZE_T size, exsize, retsize;
357 BOOL b;
359 exsize = sizeof(ACTIVATION_CONTEXT_DETAILED_INFORMATION)
360 + (exinfo->root_manifest_path ? (lstrlenW(exinfo->root_manifest_path)+1)*sizeof(WCHAR):0)
361 + (exinfo->app_dir ? (lstrlenW(exinfo->app_dir)+1)*sizeof(WCHAR) : 0);
363 if(exsize != sizeof(ACTIVATION_CONTEXT_DETAILED_INFORMATION)) {
364 size = 0xdeadbeef;
365 b = pQueryActCtxW(0, handle, NULL,
366 ActivationContextDetailedInformation, &detailed_info_tmp,
367 sizeof(detailed_info_tmp), &size);
368 ok_(__FILE__, line)(!b, "QueryActCtx succeeded\n");
369 ok_(__FILE__, line)(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetLastError() = %u\n", GetLastError());
370 ok_(__FILE__, line)(size == exsize, "size=%ld, expected %ld\n", size, exsize);
371 }else {
372 size = sizeof(ACTIVATION_CONTEXT_DETAILED_INFORMATION);
375 detailed_info = HeapAlloc(GetProcessHeap(), 0, size);
376 memset(detailed_info, 0xfe, size);
377 b = pQueryActCtxW(0, handle, NULL,
378 ActivationContextDetailedInformation, detailed_info,
379 size, &retsize);
380 ok_(__FILE__, line)(b, "QueryActCtx failed: %u\n", GetLastError());
381 ok_(__FILE__, line)(retsize == exsize, "size=%ld, expected %ld\n", retsize, exsize);
383 ok_(__FILE__, line)(detailed_info->dwFlags == 0, "detailed_info->dwFlags=%x\n", detailed_info->dwFlags);
384 ok_(__FILE__, line)(detailed_info->ulFormatVersion == exinfo->format_version,
385 "detailed_info->ulFormatVersion=%u, expected %u\n", detailed_info->ulFormatVersion,
386 exinfo->format_version);
387 ok_(__FILE__, line)(exinfo->assembly_cnt_min <= detailed_info->ulAssemblyCount &&
388 detailed_info->ulAssemblyCount <= exinfo->assembly_cnt_max,
389 "detailed_info->ulAssemblyCount=%u, expected between %u and %u\n", detailed_info->ulAssemblyCount,
390 exinfo->assembly_cnt_min, exinfo->assembly_cnt_max);
391 ok_(__FILE__, line)(detailed_info->ulRootManifestPathType == exinfo->root_manifest_type,
392 "detailed_info->ulRootManifestPathType=%u, expected %u\n",
393 detailed_info->ulRootManifestPathType, exinfo->root_manifest_type);
394 ok_(__FILE__, line)(detailed_info->ulRootManifestPathChars ==
395 (exinfo->root_manifest_path ? lstrlenW(exinfo->root_manifest_path) : 0),
396 "detailed_info->ulRootManifestPathChars=%u, expected %u\n",
397 detailed_info->ulRootManifestPathChars,
398 exinfo->root_manifest_path ?lstrlenW(exinfo->root_manifest_path) : 0);
399 ok_(__FILE__, line)(detailed_info->ulRootConfigurationPathType == exinfo->root_config_type,
400 "detailed_info->ulRootConfigurationPathType=%u, expected %u\n",
401 detailed_info->ulRootConfigurationPathType, exinfo->root_config_type);
402 ok_(__FILE__, line)(detailed_info->ulRootConfigurationPathChars == 0,
403 "detailed_info->ulRootConfigurationPathChars=%d\n", detailed_info->ulRootConfigurationPathChars);
404 ok_(__FILE__, line)(detailed_info->ulAppDirPathType == exinfo->app_dir_type,
405 "detailed_info->ulAppDirPathType=%u, expected %u\n", detailed_info->ulAppDirPathType,
406 exinfo->app_dir_type);
407 ok_(__FILE__, line)(detailed_info->ulAppDirPathChars == (exinfo->app_dir ? lstrlenW(exinfo->app_dir) : 0),
408 "detailed_info->ulAppDirPathChars=%u, expected %u\n",
409 detailed_info->ulAppDirPathChars, exinfo->app_dir ? lstrlenW(exinfo->app_dir) : 0);
410 if(exinfo->root_manifest_path) {
411 ok_(__FILE__, line)(detailed_info->lpRootManifestPath != NULL, "detailed_info->lpRootManifestPath == NULL\n");
412 if(detailed_info->lpRootManifestPath)
413 ok_(__FILE__, line)(!lstrcmpiW(detailed_info->lpRootManifestPath, exinfo->root_manifest_path),
414 "unexpected detailed_info->lpRootManifestPath\n");
415 }else {
416 ok_(__FILE__, line)(detailed_info->lpRootManifestPath == NULL, "detailed_info->lpRootManifestPath != NULL\n");
418 ok_(__FILE__, line)(detailed_info->lpRootConfigurationPath == NULL,
419 "detailed_info->lpRootConfigurationPath=%p\n", detailed_info->lpRootConfigurationPath);
420 if(exinfo->app_dir) {
421 ok_(__FILE__, line)(detailed_info->lpAppDirPath != NULL, "detailed_info->lpAppDirPath == NULL\n");
422 if(detailed_info->lpAppDirPath)
423 ok_(__FILE__, line)(!lstrcmpiW(exinfo->app_dir, detailed_info->lpAppDirPath),
424 "unexpected detailed_info->lpAppDirPath\n%s\n",strw(detailed_info->lpAppDirPath));
425 }else {
426 ok_(__FILE__, line)(detailed_info->lpAppDirPath == NULL, "detailed_info->lpAppDirPath != NULL\n");
429 HeapFree(GetProcessHeap(), 0, detailed_info);
432 typedef struct {
433 ULONG flags;
434 /* ULONG manifest_path_type; FIXME */
435 LPCWSTR manifest_path;
436 LPCSTR encoded_assembly_id;
437 BOOL has_assembly_dir;
438 } info_in_assembly;
440 static const info_in_assembly manifest1_info = {
441 1, manifest_path,
442 "Wine.Test,type=\"win32\",version=\"1.0.0.0\"",
443 FALSE
446 static const info_in_assembly manifest1_child_info = {
447 1, app_manifest_path,
448 "Wine.Test,type=\"win32\",version=\"1.0.0.0\"",
449 FALSE
452 static const info_in_assembly manifest2_info = {
453 1, manifest_path,
454 "Wine.Test,type=\"win32\",version=\"1.2.3.4\"",
455 FALSE
458 static const info_in_assembly manifest3_info = {
459 1, manifest_path,
460 "Wine.Test,publicKeyToken=\"6595b6414666f1df\",type=\"win32\",version=\"1.2.3.4\"",
461 FALSE
464 static const info_in_assembly manifest4_info = {
465 1, manifest_path,
466 "Wine.Test,type=\"win32\",version=\"1.2.3.4\"",
467 FALSE
470 static const info_in_assembly depmanifest1_info = {
471 0x10, depmanifest_path,
472 "testdep,processorArchitecture=\"" ARCH "\","
473 "type=\"win32\",version=\"6.5.4.3\"",
474 TRUE
477 static const info_in_assembly depmanifest2_info = {
478 0x10, depmanifest_path,
479 "testdep,processorArchitecture=\"" ARCH "\","
480 "type=\"win32\",version=\"6.5.4.3\"",
481 TRUE
484 static const info_in_assembly depmanifest3_info = {
485 0x10, depmanifest_path,
486 "testdep,processorArchitecture=\"" ARCH "\",type=\"win32\",version=\"6.5.4.3\"",
487 TRUE
490 static const info_in_assembly manifest_comctrl_info = {
491 0, NULL, NULL, TRUE /* These values may differ between Windows installations */
494 static void test_info_in_assembly(HANDLE handle, DWORD id, const info_in_assembly *exinfo, int line)
496 ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION *info, info_tmp;
497 SIZE_T size, exsize;
498 ULONG len;
499 BOOL b;
501 exsize = sizeof(ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION);
502 if (exinfo->manifest_path) exsize += (lstrlenW(exinfo->manifest_path)+1) * sizeof(WCHAR);
503 if (exinfo->encoded_assembly_id) exsize += (strlen_aw(exinfo->encoded_assembly_id) + 1) * sizeof(WCHAR);
505 size = 0xdeadbeef;
506 b = pQueryActCtxW(0, handle, &id,
507 AssemblyDetailedInformationInActivationContext, &info_tmp,
508 sizeof(info_tmp), &size);
509 ok_(__FILE__, line)(!b, "QueryActCtx succeeded\n");
510 ok_(__FILE__, line)(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetLastError() = %u\n", GetLastError());
512 ok_(__FILE__, line)(size >= exsize, "size=%lu, expected %lu\n", size, exsize);
514 if (size == 0xdeadbeef)
516 skip("bad size\n");
517 return;
520 info = HeapAlloc(GetProcessHeap(), 0, size);
521 memset(info, 0xfe, size);
523 size = 0xdeadbeef;
524 b = pQueryActCtxW(0, handle, &id,
525 AssemblyDetailedInformationInActivationContext, info, size, &size);
526 ok_(__FILE__, line)(b, "QueryActCtx failed: %u\n", GetLastError());
527 if (!exinfo->manifest_path)
528 exsize += info->ulManifestPathLength + sizeof(WCHAR);
529 if (!exinfo->encoded_assembly_id)
530 exsize += info->ulEncodedAssemblyIdentityLength + sizeof(WCHAR);
531 if (exinfo->has_assembly_dir)
532 exsize += info->ulAssemblyDirectoryNameLength + sizeof(WCHAR);
533 ok_(__FILE__, line)(size == exsize, "size=%lu, expected %lu\n", size, exsize);
535 if (0) /* FIXME: flags meaning unknown */
537 ok_(__FILE__, line)((info->ulFlags) == exinfo->flags, "info->ulFlags = %x, expected %x\n",
538 info->ulFlags, exinfo->flags);
540 if(exinfo->encoded_assembly_id) {
541 len = strlen_aw(exinfo->encoded_assembly_id)*sizeof(WCHAR);
542 ok_(__FILE__, line)(info->ulEncodedAssemblyIdentityLength == len,
543 "info->ulEncodedAssemblyIdentityLength = %u, expected %u\n",
544 info->ulEncodedAssemblyIdentityLength, len);
545 } else {
546 ok_(__FILE__, line)(info->ulEncodedAssemblyIdentityLength != 0,
547 "info->ulEncodedAssemblyIdentityLength == 0\n");
549 ok_(__FILE__, line)(info->ulManifestPathType == ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE,
550 "info->ulManifestPathType = %x\n", info->ulManifestPathType);
551 if(exinfo->manifest_path) {
552 len = lstrlenW(exinfo->manifest_path)*sizeof(WCHAR);
553 ok_(__FILE__, line)(info->ulManifestPathLength == len, "info->ulManifestPathLength = %u, expected %u\n",
554 info->ulManifestPathLength, len);
555 } else {
556 ok_(__FILE__, line)(info->ulManifestPathLength != 0, "info->ulManifestPathLength == 0\n");
559 ok_(__FILE__, line)(info->ulPolicyPathType == ACTIVATION_CONTEXT_PATH_TYPE_NONE,
560 "info->ulPolicyPathType = %x\n", info->ulPolicyPathType);
561 ok_(__FILE__, line)(info->ulPolicyPathLength == 0,
562 "info->ulPolicyPathLength = %u, expected 0\n", info->ulPolicyPathLength);
563 ok_(__FILE__, line)(info->ulMetadataSatelliteRosterIndex == 0, "info->ulMetadataSatelliteRosterIndex = %x\n",
564 info->ulMetadataSatelliteRosterIndex);
565 ok_(__FILE__, line)(info->ulManifestVersionMajor == 1,"info->ulManifestVersionMajor = %x\n",
566 info->ulManifestVersionMajor);
567 ok_(__FILE__, line)(info->ulManifestVersionMinor == 0, "info->ulManifestVersionMinor = %x\n",
568 info->ulManifestVersionMinor);
569 ok_(__FILE__, line)(info->ulPolicyVersionMajor == 0, "info->ulPolicyVersionMajor = %x\n",
570 info->ulPolicyVersionMajor);
571 ok_(__FILE__, line)(info->ulPolicyVersionMinor == 0, "info->ulPolicyVersionMinor = %x\n",
572 info->ulPolicyVersionMinor);
573 if(exinfo->has_assembly_dir)
574 ok_(__FILE__, line)(info->ulAssemblyDirectoryNameLength != 0,
575 "info->ulAssemblyDirectoryNameLength == 0\n");
576 else
577 ok_(__FILE__, line)(info->ulAssemblyDirectoryNameLength == 0,
578 "info->ulAssemblyDirectoryNameLength != 0\n");
580 ok_(__FILE__, line)(info->lpAssemblyEncodedAssemblyIdentity != NULL,
581 "info->lpAssemblyEncodedAssemblyIdentity == NULL\n");
582 if(info->lpAssemblyEncodedAssemblyIdentity && exinfo->encoded_assembly_id) {
583 ok_(__FILE__, line)(!strcmp_aw(info->lpAssemblyEncodedAssemblyIdentity, exinfo->encoded_assembly_id),
584 "unexpected info->lpAssemblyEncodedAssemblyIdentity %s / %s\n",
585 strw(info->lpAssemblyEncodedAssemblyIdentity), exinfo->encoded_assembly_id);
587 if(exinfo->manifest_path) {
588 ok_(__FILE__, line)(info->lpAssemblyManifestPath != NULL, "info->lpAssemblyManifestPath == NULL\n");
589 if(info->lpAssemblyManifestPath)
590 ok_(__FILE__, line)(!lstrcmpiW(info->lpAssemblyManifestPath, exinfo->manifest_path),
591 "unexpected info->lpAssemblyManifestPath\n");
592 }else {
593 ok_(__FILE__, line)(info->lpAssemblyManifestPath != NULL, "info->lpAssemblyManifestPath == NULL\n");
596 ok_(__FILE__, line)(info->lpAssemblyPolicyPath == NULL, "info->lpAssemblyPolicyPath != NULL\n");
597 if(info->lpAssemblyPolicyPath)
598 ok_(__FILE__, line)(*(WORD*)info->lpAssemblyPolicyPath == 0, "info->lpAssemblyPolicyPath is not empty\n");
599 if(exinfo->has_assembly_dir)
600 ok_(__FILE__, line)(info->lpAssemblyDirectoryName != NULL, "info->lpAssemblyDirectoryName == NULL\n");
601 else
602 ok_(__FILE__, line)(info->lpAssemblyDirectoryName == NULL, "info->lpAssemblyDirectoryName = %s\n",
603 strw(info->lpAssemblyDirectoryName));
604 HeapFree(GetProcessHeap(), 0, info);
607 static void test_file_info(HANDLE handle, ULONG assid, ULONG fileid, LPCWSTR filename, int line)
609 ASSEMBLY_FILE_DETAILED_INFORMATION *info, info_tmp;
610 ACTIVATION_CONTEXT_QUERY_INDEX index = {assid, fileid};
611 SIZE_T size, exsize;
612 BOOL b;
614 exsize = sizeof(ASSEMBLY_FILE_DETAILED_INFORMATION)
615 +(lstrlenW(filename)+1)*sizeof(WCHAR);
617 size = 0xdeadbeef;
618 b = pQueryActCtxW(0, handle, &index,
619 FileInformationInAssemblyOfAssemblyInActivationContext, &info_tmp,
620 sizeof(info_tmp), &size);
621 ok_(__FILE__, line)(!b, "QueryActCtx succeeded\n");
622 ok_(__FILE__, line)(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetLastError() = %u\n", GetLastError());
623 ok_(__FILE__, line)(size == exsize, "size=%lu, expected %lu\n", size, exsize);
625 if(size == 0xdeadbeef)
627 skip("bad size\n");
628 return;
631 info = HeapAlloc(GetProcessHeap(), 0, size);
632 memset(info, 0xfe, size);
634 b = pQueryActCtxW(0, handle, &index,
635 FileInformationInAssemblyOfAssemblyInActivationContext, info, size, &size);
636 ok_(__FILE__, line)(b, "QueryActCtx failed: %u\n", GetLastError());
637 ok_(__FILE__, line)(!size, "size=%lu, expected 0\n", size);
639 ok_(__FILE__, line)(info->ulFlags == 2, "info->ulFlags=%x, expected 2\n", info->ulFlags);
640 ok_(__FILE__, line)(info->ulFilenameLength == lstrlenW(filename)*sizeof(WCHAR),
641 "info->ulFilenameLength=%u, expected %u*sizeof(WCHAR)\n",
642 info->ulFilenameLength, lstrlenW(filename));
643 ok_(__FILE__, line)(info->ulPathLength == 0, "info->ulPathLength=%u\n", info->ulPathLength);
644 ok_(__FILE__, line)(info->lpFileName != NULL, "info->lpFileName == NULL\n");
645 if(info->lpFileName)
646 ok_(__FILE__, line)(!lstrcmpiW(info->lpFileName, filename), "unexpected info->lpFileName\n");
647 ok_(__FILE__, line)(info->lpFilePath == NULL, "info->lpFilePath != NULL\n");
648 HeapFree(GetProcessHeap(), 0, info);
651 static HANDLE test_create(const char *file)
653 ACTCTXW actctx;
654 HANDLE handle;
655 WCHAR path[MAX_PATH];
657 MultiByteToWideChar( CP_ACP, 0, file, -1, path, MAX_PATH );
658 memset(&actctx, 0, sizeof(ACTCTXW));
659 actctx.cbSize = sizeof(ACTCTXW);
660 actctx.lpSource = path;
662 handle = pCreateActCtxW(&actctx);
663 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
665 ok(actctx.cbSize == sizeof(actctx), "actctx.cbSize=%d\n", actctx.cbSize);
666 ok(actctx.dwFlags == 0, "actctx.dwFlags=%d\n", actctx.dwFlags);
667 ok(actctx.lpSource == path, "actctx.lpSource=%p\n", actctx.lpSource);
668 ok(actctx.wProcessorArchitecture == 0,
669 "actctx.wProcessorArchitecture=%d\n", actctx.wProcessorArchitecture);
670 ok(actctx.wLangId == 0, "actctx.wLangId=%d\n", actctx.wLangId);
671 ok(actctx.lpAssemblyDirectory == NULL,
672 "actctx.lpAssemblyDirectory=%p\n", actctx.lpAssemblyDirectory);
673 ok(actctx.lpResourceName == NULL, "actctx.lpResourceName=%p\n", actctx.lpResourceName);
674 ok(actctx.lpApplicationName == NULL, "actctx.lpApplicationName=%p\n",
675 actctx.lpApplicationName);
676 ok(actctx.hModule == NULL, "actctx.hModule=%p\n", actctx.hModule);
678 return handle;
681 static void test_create_and_fail(const char *manifest, const char *depmanifest, int todo)
683 ACTCTXW actctx;
684 HANDLE handle;
685 WCHAR path[MAX_PATH];
687 MultiByteToWideChar( CP_ACP, 0, "bad.manifest", -1, path, MAX_PATH );
688 memset(&actctx, 0, sizeof(ACTCTXW));
689 actctx.cbSize = sizeof(ACTCTXW);
690 actctx.lpSource = path;
692 create_manifest_file("bad.manifest", manifest, -1, "testdep.manifest", depmanifest);
693 handle = pCreateActCtxW(&actctx);
694 if (todo) todo_wine
696 ok(handle == INVALID_HANDLE_VALUE, "handle != INVALID_HANDLE_VALUE\n");
697 ok(GetLastError() == ERROR_SXS_CANT_GEN_ACTCTX, "GetLastError == %u\n", GetLastError());
699 else
701 ok(handle == INVALID_HANDLE_VALUE, "handle != INVALID_HANDLE_VALUE\n");
702 ok(GetLastError() == ERROR_SXS_CANT_GEN_ACTCTX, "GetLastError == %u\n", GetLastError());
704 if (handle != INVALID_HANDLE_VALUE) pReleaseActCtx( handle );
705 DeleteFileA("bad.manifest");
706 DeleteFileA("testdep.manifest");
709 static void test_create_wide_and_fail(const char *manifest, BOOL fBOM)
711 ACTCTXW actctx;
712 HANDLE handle;
713 WCHAR path[MAX_PATH];
715 MultiByteToWideChar( CP_ACP, 0, "bad.manifest", -1, path, MAX_PATH );
716 memset(&actctx, 0, sizeof(ACTCTXW));
717 actctx.cbSize = sizeof(ACTCTXW);
718 actctx.lpSource = path;
720 create_wide_manifest("bad.manifest", manifest, fBOM, FALSE);
721 handle = pCreateActCtxW(&actctx);
722 ok(handle == INVALID_HANDLE_VALUE, "handle != INVALID_HANDLE_VALUE\n");
723 ok(GetLastError() == ERROR_SXS_CANT_GEN_ACTCTX, "GetLastError == %u\n", GetLastError());
725 if (handle != INVALID_HANDLE_VALUE) pReleaseActCtx( handle );
726 DeleteFileA("bad.manifest");
729 static void test_create_fail(void)
731 ACTCTXW actctx;
732 HANDLE handle;
733 WCHAR path[MAX_PATH];
735 MultiByteToWideChar( CP_ACP, 0, "nonexistent.manifest", -1, path, MAX_PATH );
736 memset(&actctx, 0, sizeof(ACTCTXW));
737 actctx.cbSize = sizeof(ACTCTXW);
738 actctx.lpSource = path;
740 handle = pCreateActCtxW(&actctx);
741 ok(handle == INVALID_HANDLE_VALUE, "handle != INVALID_HANDLE_VALUE\n");
742 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "GetLastError == %u\n", GetLastError());
744 trace("wrong_manifest1\n");
745 test_create_and_fail(wrong_manifest1, NULL, 0 );
746 trace("wrong_manifest2\n");
747 test_create_and_fail(wrong_manifest2, NULL, 0 );
748 trace("wrong_manifest3\n");
749 test_create_and_fail(wrong_manifest3, NULL, 1 );
750 trace("wrong_manifest4\n");
751 test_create_and_fail(wrong_manifest4, NULL, 1 );
752 trace("wrong_manifest5\n");
753 test_create_and_fail(wrong_manifest5, NULL, 0 );
754 trace("wrong_manifest6\n");
755 test_create_and_fail(wrong_manifest6, NULL, 0 );
756 trace("wrong_manifest7\n");
757 test_create_and_fail(wrong_manifest7, NULL, 1 );
758 trace("wrong_manifest8\n");
759 test_create_and_fail(wrong_manifest8, NULL, 0 );
760 trace("UTF-16 manifest1 without BOM\n");
761 test_create_wide_and_fail(manifest1, FALSE );
762 trace("manifest2\n");
763 test_create_and_fail(manifest2, NULL, 0 );
764 trace("manifest2+depmanifest1\n");
765 test_create_and_fail(manifest2, wrong_depmanifest1, 0 );
768 struct strsection_header
770 DWORD magic;
771 ULONG size;
772 DWORD unk1[3];
773 ULONG count;
774 ULONG index_offset;
775 DWORD unk2[4];
778 struct string_index
780 ULONG hash;
781 ULONG name_offset;
782 ULONG name_len;
783 ULONG data_offset;
784 ULONG data_len;
785 ULONG rosterindex;
788 struct guidsection_header
790 DWORD magic;
791 ULONG size;
792 DWORD unk[3];
793 ULONG count;
794 ULONG index_offset;
795 DWORD unk2;
796 ULONG names_offset;
797 ULONG names_len;
800 struct guid_index
802 GUID guid;
803 ULONG data_offset;
804 ULONG data_len;
805 ULONG rosterindex;
808 struct wndclass_redirect_data
810 ULONG size;
811 DWORD res;
812 ULONG name_len;
813 ULONG name_offset; /* versioned name offset */
814 ULONG module_len;
815 ULONG module_offset;/* container name offset */
818 struct dllredirect_data
820 ULONG size;
821 ULONG unk;
822 DWORD res[3];
825 struct tlibredirect_data
827 ULONG size;
828 DWORD res;
829 ULONG name_len;
830 ULONG name_offset;
831 LANGID langid;
832 WORD flags;
833 ULONG help_len;
834 ULONG help_offset;
835 WORD major_version;
836 WORD minor_version;
839 static void test_find_dll_redirection(HANDLE handle, LPCWSTR libname, ULONG exid, int line)
841 ACTCTX_SECTION_KEYED_DATA data;
842 BOOL ret;
844 memset(&data, 0xfe, sizeof(data));
845 data.cbSize = sizeof(data);
847 ret = pFindActCtxSectionStringW(0, NULL,
848 ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
849 libname, &data);
850 ok_(__FILE__, line)(ret, "FindActCtxSectionStringW failed: %u\n", GetLastError());
851 if (!ret) return;
853 ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
854 ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
855 ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
856 ok_(__FILE__, line)(data.ulLength == 20, "data.ulLength=%u\n", data.ulLength);
858 if (data.lpData)
860 struct dllredirect_data *dlldata = (struct dllredirect_data*)data.lpData;
861 ok_(__FILE__, line)(dlldata->size == data.ulLength, "got wrong size %d\n", dlldata->size);
862 ok_(__FILE__, line)(dlldata->unk == 2, "got wrong field value %d\n", dlldata->unk);
863 ok_(__FILE__, line)(dlldata->res[0] == 0, "got wrong res[0] value %d\n", dlldata->res[0]);
864 ok_(__FILE__, line)(dlldata->res[1] == 0, "got wrong res[1] value %d\n", dlldata->res[1]);
865 ok_(__FILE__, line)(dlldata->res[2] == 0, "got wrong res[2] value %d\n", dlldata->res[2]);
868 ok_(__FILE__, line)(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
869 ok_(__FILE__, line)(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%u\n",
870 data.ulSectionGlobalDataLength);
871 ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
872 ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%u\n",
873 data.ulSectionTotalLength);
874 ok_(__FILE__, line)(data.hActCtx == NULL, "data.hActCtx=%p\n", data.hActCtx);
875 ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
876 data.ulAssemblyRosterIndex, exid);
878 memset(&data, 0xfe, sizeof(data));
879 data.cbSize = sizeof(data);
881 ret = pFindActCtxSectionStringW(FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX, NULL,
882 ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
883 libname, &data);
884 ok_(__FILE__, line)(ret, "FindActCtxSectionStringW failed: %u\n", GetLastError());
885 if (!ret) return;
887 ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
888 ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
889 ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
890 ok_(__FILE__, line)(data.ulLength == 20, "data.ulLength=%u\n", data.ulLength);
891 ok_(__FILE__, line)(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
892 ok_(__FILE__, line)(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%u\n",
893 data.ulSectionGlobalDataLength);
894 ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
895 ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%u\n",
896 data.ulSectionTotalLength);
897 ok_(__FILE__, line)(data.hActCtx == handle, "data.hActCtx=%p\n", data.hActCtx);
898 ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
899 data.ulAssemblyRosterIndex, exid);
901 pReleaseActCtx(handle);
904 static void test_find_window_class(HANDLE handle, LPCWSTR clsname, ULONG exid, int line)
906 struct wndclass_redirect_data *wnddata;
907 struct strsection_header *header;
908 ACTCTX_SECTION_KEYED_DATA data;
909 BOOL ret;
911 memset(&data, 0xfe, sizeof(data));
912 data.cbSize = sizeof(data);
914 ret = pFindActCtxSectionStringW(0, NULL,
915 ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION,
916 clsname, &data);
917 ok_(__FILE__, line)(ret, "FindActCtxSectionStringW failed: %u, class %s\n", GetLastError(),
918 wine_dbgstr_w(clsname));
919 if (!ret) return;
921 header = (struct strsection_header*)data.lpSectionBase;
922 wnddata = (struct wndclass_redirect_data*)data.lpData;
924 ok_(__FILE__, line)(header->magic == 0x64487353, "got wrong magic 0x%08x\n", header->magic);
925 ok_(__FILE__, line)(header->count > 0, "got count %d\n", header->count);
926 ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
927 ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
928 ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
929 ok_(__FILE__, line)(wnddata->size == sizeof(*wnddata), "got %d for header size\n", wnddata->size);
930 if (data.lpData && wnddata->size == sizeof(*wnddata))
932 static const WCHAR verW[] = {'6','.','5','.','4','.','3','!',0};
933 WCHAR buff[50];
934 WCHAR *ptr;
935 ULONG len;
937 ok_(__FILE__, line)(wnddata->res == 0, "got reserved as %d\n", wnddata->res);
938 /* redirect class name (versioned or not) is stored just after header data */
939 ok_(__FILE__, line)(wnddata->name_offset == wnddata->size, "got name offset as %d\n", wnddata->name_offset);
940 ok_(__FILE__, line)(wnddata->module_len > 0, "got module name length as %d\n", wnddata->module_len);
942 /* expected versioned name */
943 lstrcpyW(buff, verW);
944 lstrcatW(buff, clsname);
945 ptr = (WCHAR*)((BYTE*)wnddata + wnddata->name_offset);
946 ok_(__FILE__, line)(!lstrcmpW(ptr, buff), "got wrong class name %s, expected %s\n", wine_dbgstr_w(ptr), wine_dbgstr_w(buff));
947 ok_(__FILE__, line)(lstrlenW(ptr)*sizeof(WCHAR) == wnddata->name_len,
948 "got wrong class name length %d, expected %d\n", wnddata->name_len, lstrlenW(ptr));
950 /* data length is simply header length + string data length including nulls */
951 len = wnddata->size + wnddata->name_len + wnddata->module_len + 2*sizeof(WCHAR);
952 ok_(__FILE__, line)(data.ulLength == len, "got wrong data length %d, expected %d\n", data.ulLength, len);
954 if (data.ulSectionTotalLength > wnddata->module_offset)
956 WCHAR *modulename, *sectionptr;
958 /* just compare pointers */
959 modulename = (WCHAR*)((BYTE*)wnddata + wnddata->size + wnddata->name_len + sizeof(WCHAR));
960 sectionptr = (WCHAR*)((BYTE*)data.lpSectionBase + wnddata->module_offset);
961 ok_(__FILE__, line)(modulename == sectionptr, "got wrong name offset %p, expected %p\n", sectionptr, modulename);
965 ok_(__FILE__, line)(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
966 ok_(__FILE__, line)(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%u\n",
967 data.ulSectionGlobalDataLength);
968 ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
969 ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%u\n",
970 data.ulSectionTotalLength);
971 ok_(__FILE__, line)(data.hActCtx == NULL, "data.hActCtx=%p\n", data.hActCtx);
972 ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
973 data.ulAssemblyRosterIndex, exid);
975 memset(&data, 0xfe, sizeof(data));
976 data.cbSize = sizeof(data);
978 ret = pFindActCtxSectionStringW(FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX, NULL,
979 ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION,
980 clsname, &data);
981 ok_(__FILE__, line)(ret, "FindActCtxSectionStringW failed: %u, class %s\n", GetLastError(),
982 wine_dbgstr_w(clsname));
983 if (!ret) return;
985 ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
986 ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
987 ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
988 ok_(__FILE__, line)(data.ulLength > 0, "data.ulLength=%u\n", data.ulLength);
989 ok_(__FILE__, line)(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
990 ok_(__FILE__, line)(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%u\n",
991 data.ulSectionGlobalDataLength);
992 ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
993 ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%u\n", data.ulSectionTotalLength);
994 ok_(__FILE__, line)(data.hActCtx == handle, "data.hActCtx=%p\n", data.hActCtx);
995 ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
996 data.ulAssemblyRosterIndex, exid);
998 pReleaseActCtx(handle);
1001 static void test_find_string_fail(void)
1003 ACTCTX_SECTION_KEYED_DATA data = {sizeof(data)};
1004 BOOL ret;
1006 ret = pFindActCtxSectionStringW(0, NULL, 100, testlib_dll, &data);
1007 ok(!ret, "FindActCtxSectionStringW succeeded\n");
1008 ok(GetLastError() == ERROR_SXS_SECTION_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
1010 ret = pFindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
1011 testlib2_dll, &data);
1012 ok(!ret, "FindActCtxSectionStringW succeeded\n");
1013 ok(GetLastError() == ERROR_SXS_KEY_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
1015 ret = pFindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
1016 testlib_dll, NULL);
1017 ok(!ret, "FindActCtxSectionStringW succeeded\n");
1018 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError()=%u\n", GetLastError());
1020 ret = pFindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
1021 NULL, &data);
1022 ok(!ret, "FindActCtxSectionStringW succeeded\n");
1023 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError()=%u\n", GetLastError());
1025 data.cbSize = 0;
1026 ret = pFindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
1027 testlib_dll, &data);
1028 ok(!ret, "FindActCtxSectionStringW succeeded\n");
1029 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError()=%u\n", GetLastError());
1031 data.cbSize = 35;
1032 ret = pFindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
1033 testlib_dll, &data);
1034 ok(!ret, "FindActCtxSectionStringW succeeded\n");
1035 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError()=%u\n", GetLastError());
1039 static void test_basic_info(HANDLE handle, int line)
1041 ACTIVATION_CONTEXT_BASIC_INFORMATION basic;
1042 SIZE_T size;
1043 BOOL b;
1045 b = pQueryActCtxW(QUERY_ACTCTX_FLAG_NO_ADDREF, handle, NULL,
1046 ActivationContextBasicInformation, &basic,
1047 sizeof(basic), &size);
1049 ok_(__FILE__, line) (b,"ActivationContextBasicInformation failed\n");
1050 ok_(__FILE__, line) (size == sizeof(ACTIVATION_CONTEXT_BASIC_INFORMATION),"size mismatch\n");
1051 ok_(__FILE__, line) (basic.dwFlags == 0, "unexpected flags %x\n",basic.dwFlags);
1052 ok_(__FILE__, line) (basic.hActCtx == handle, "unexpected handle\n");
1054 b = pQueryActCtxW(QUERY_ACTCTX_FLAG_USE_ACTIVE_ACTCTX |
1055 QUERY_ACTCTX_FLAG_NO_ADDREF, handle, NULL,
1056 ActivationContextBasicInformation, &basic,
1057 sizeof(basic), &size);
1058 if (handle)
1060 ok_(__FILE__, line) (!b,"ActivationContextBasicInformation succeeded\n");
1061 ok_(__FILE__, line) (size == 0,"size mismatch\n");
1062 ok_(__FILE__, line) (GetLastError() == ERROR_INVALID_PARAMETER, "Wrong last error\n");
1063 ok_(__FILE__, line) (basic.dwFlags == 0, "unexpected flags %x\n",basic.dwFlags);
1064 ok_(__FILE__, line) (basic.hActCtx == handle, "unexpected handle\n");
1066 else
1068 ok_(__FILE__, line) (b,"ActivationContextBasicInformation failed\n");
1069 ok_(__FILE__, line) (size == sizeof(ACTIVATION_CONTEXT_BASIC_INFORMATION),"size mismatch\n");
1070 ok_(__FILE__, line) (basic.dwFlags == 0, "unexpected flags %x\n",basic.dwFlags);
1071 ok_(__FILE__, line) (basic.hActCtx == handle, "unexpected handle\n");
1075 enum comclass_threadingmodel {
1076 ThreadingModel_Apartment = 1,
1077 ThreadingModel_Free = 2,
1078 ThreadingModel_Both = 4,
1079 ThreadingModel_Neutral = 5
1082 enum comclass_miscfields {
1083 MiscStatus = 0x1,
1084 MiscStatusIcon = 0x2,
1085 MiscStatusContent = 0x4,
1086 MiscStatusThumbnail = 0x8
1089 struct comclass_keyed_data {
1090 DWORD size;
1091 BYTE reserved;
1092 BYTE miscmask;
1093 BYTE unk[2];
1094 DWORD model;
1095 GUID clsid;
1096 GUID unkguid;
1097 GUID clsid2;
1098 GUID tlid;
1099 DWORD modulename_len;
1100 DWORD modulename_offset;
1101 DWORD progid_len;
1102 DWORD progid_offset;
1103 DWORD res2[7];
1104 WCHAR strdata[1];
1107 static void test_find_com_redirection(HANDLE handle, const GUID *clsid, const GUID *tlid, ULONG exid, int line)
1109 struct comclass_keyed_data *comclass;
1110 ACTCTX_SECTION_KEYED_DATA data;
1111 BOOL ret;
1113 memset(&data, 0xfe, sizeof(data));
1114 data.cbSize = sizeof(data);
1116 ret = pFindActCtxSectionGuid(0, NULL,
1117 ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION,
1118 clsid, &data);
1119 todo_wine
1120 ok_(__FILE__, line)(ret, "FindActCtxSectionGuid failed: %u\n", GetLastError());
1121 if(!ret)
1123 skip("couldn't find guid %s\n", debugstr_guid(clsid));
1124 return;
1127 comclass = (struct comclass_keyed_data*)data.lpData;
1129 ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
1130 ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
1131 ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
1132 ok_(__FILE__, line)(comclass->size == FIELD_OFFSET(struct comclass_keyed_data, strdata), "got %d for header size\n", comclass->size);
1133 if (data.lpData && comclass->size == FIELD_OFFSET(struct comclass_keyed_data, strdata))
1135 static const WCHAR progid[] = {'P','r','o','g','I','d','.','P','r','o','g','I','d',0};
1136 WCHAR *ptr;
1137 ULONG len;
1139 ok_(__FILE__, line)(comclass->reserved == 0, "got reserved as %d\n", comclass->reserved);
1140 ok_(__FILE__, line)(comclass->miscmask == 0, "got miscmask as %02x\n", comclass->miscmask);
1141 ok_(__FILE__, line)(comclass->unk[0] == 0, "got unk[0] as %02x\n", comclass->unk[0]);
1142 ok_(__FILE__, line)(comclass->unk[1] == 0, "got unk[1] as %02x\n", comclass->unk[1]);
1143 ok_(__FILE__, line)(comclass->model == ThreadingModel_Neutral, "got model %d\n", comclass->model);
1144 ok_(__FILE__, line)(IsEqualGUID(&comclass->clsid, clsid), "got wrong clsid %s\n", debugstr_guid(&comclass->clsid));
1145 ok_(__FILE__, line)(IsEqualGUID(&comclass->clsid2, clsid), "got wrong clsid2 %s\n", debugstr_guid(&comclass->clsid2));
1146 ok_(__FILE__, line)(IsEqualGUID(&comclass->tlid, tlid), "got wrong tlid %s\n", debugstr_guid(&comclass->tlid));
1147 ok_(__FILE__, line)(comclass->modulename_len > 0, "got modulename len %d\n", comclass->modulename_len);
1148 ok_(__FILE__, line)(comclass->progid_offset == comclass->size, "got progid offset %d\n", comclass->progid_offset);
1150 ptr = (WCHAR*)((BYTE*)comclass + comclass->size);
1151 ok_(__FILE__, line)(!lstrcmpW(ptr, progid), "got wrong progid %s, expected %s\n", wine_dbgstr_w(ptr), wine_dbgstr_w(progid));
1152 ok_(__FILE__, line)(lstrlenW(ptr)*sizeof(WCHAR) == comclass->progid_len,
1153 "got progid name length %d, expected %d\n", comclass->progid_len, lstrlenW(ptr));
1155 /* data length is simply header length + string data length including nulls */
1156 len = comclass->size + comclass->progid_len + sizeof(WCHAR);
1157 ok_(__FILE__, line)(data.ulLength == len, "got wrong data length %d, expected %d\n", data.ulLength, len);
1159 /* keyed data structure doesn't include module name, it's available from section data */
1160 ok_(__FILE__, line)(data.ulSectionTotalLength > comclass->modulename_offset, "got wrong offset %d\n", comclass->modulename_offset);
1163 ok_(__FILE__, line)(data.lpSectionGlobalData != NULL, "data.lpSectionGlobalData == NULL\n");
1164 ok_(__FILE__, line)(data.ulSectionGlobalDataLength > 0, "data.ulSectionGlobalDataLength=%u\n",
1165 data.ulSectionGlobalDataLength);
1166 ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
1167 ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%u\n",
1168 data.ulSectionTotalLength);
1169 ok_(__FILE__, line)(data.hActCtx == NULL, "data.hActCtx=%p\n", data.hActCtx);
1170 ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
1171 data.ulAssemblyRosterIndex, exid);
1174 static void test_wndclass_section(void)
1176 static const WCHAR cls1W[] = {'1','.','2','.','3','.','4','!','w','n','d','C','l','a','s','s','1',0};
1177 ACTCTX_SECTION_KEYED_DATA data, data2;
1178 struct wndclass_redirect_data *classdata;
1179 struct strsection_header *section;
1180 ULONG_PTR cookie;
1181 HANDLE handle;
1182 WCHAR *ptrW;
1183 BOOL ret;
1185 /* use two dependent manifests, each defines 2 window class redirects */
1186 create_manifest_file("testdep1.manifest", manifest_wndcls1, -1, NULL, NULL);
1187 create_manifest_file("testdep2.manifest", manifest_wndcls2, -1, NULL, NULL);
1188 create_manifest_file("main_wndcls.manifest", manifest_wndcls_main, -1, NULL, NULL);
1190 handle = test_create("main_wndcls.manifest");
1191 DeleteFileA("testdep1.manifest");
1192 DeleteFileA("testdep2.manifest");
1193 DeleteFileA("main_wndcls.manifest");
1195 ret = pActivateActCtx(handle, &cookie);
1196 ok(ret, "ActivateActCtx failed: %u\n", GetLastError());
1198 memset(&data, 0, sizeof(data));
1199 memset(&data2, 0, sizeof(data2));
1200 data.cbSize = sizeof(data);
1201 data2.cbSize = sizeof(data2);
1203 /* get data for two classes from different assemblies */
1204 ret = pFindActCtxSectionStringW(0, NULL,
1205 ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION,
1206 wndClass1W, &data);
1207 ok(ret, "got %d\n", ret);
1208 ret = pFindActCtxSectionStringW(0, NULL,
1209 ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION,
1210 wndClass3W, &data2);
1211 ok(ret, "got %d\n", ret);
1213 section = (struct strsection_header*)data.lpSectionBase;
1214 ok(section->count == 4, "got %d\n", section->count);
1215 ok(section->size == sizeof(*section), "got %d\n", section->size);
1217 /* For both string same section is returned, meaning it's one wndclass section per context */
1218 ok(data.lpSectionBase == data2.lpSectionBase, "got %p, %p\n", data.lpSectionBase, data2.lpSectionBase);
1219 ok(data.ulSectionTotalLength == data2.ulSectionTotalLength, "got %u, %u\n", data.ulSectionTotalLength,
1220 data2.ulSectionTotalLength);
1222 /* wndClass1 is versioned, wndClass3 is not */
1223 classdata = (struct wndclass_redirect_data*)data.lpData;
1224 ptrW = (WCHAR*)((BYTE*)data.lpData + classdata->name_offset);
1225 ok(!lstrcmpW(ptrW, cls1W), "got %s\n", wine_dbgstr_w(ptrW));
1227 classdata = (struct wndclass_redirect_data*)data2.lpData;
1228 ptrW = (WCHAR*)((BYTE*)data2.lpData + classdata->name_offset);
1229 ok(!lstrcmpW(ptrW, wndClass3W), "got %s\n", wine_dbgstr_w(ptrW));
1231 ret = pDeactivateActCtx(0, cookie);
1232 ok(ret, "DeactivateActCtx failed: %u\n", GetLastError());
1234 pReleaseActCtx(handle);
1237 static void test_dllredirect_section(void)
1239 static const WCHAR testlib1W[] = {'t','e','s','t','l','i','b','1','.','d','l','l',0};
1240 static const WCHAR testlib2W[] = {'t','e','s','t','l','i','b','2','.','d','l','l',0};
1241 ACTCTX_SECTION_KEYED_DATA data, data2;
1242 struct strsection_header *section;
1243 ULONG_PTR cookie;
1244 HANDLE handle;
1245 BOOL ret;
1247 /* use two dependent manifests, 4 'files' total */
1248 create_manifest_file("testdep1.manifest", manifest_wndcls1, -1, NULL, NULL);
1249 create_manifest_file("testdep2.manifest", manifest_wndcls2, -1, NULL, NULL);
1250 create_manifest_file("main_wndcls.manifest", manifest_wndcls_main, -1, NULL, NULL);
1252 handle = test_create("main_wndcls.manifest");
1253 DeleteFileA("testdep1.manifest");
1254 DeleteFileA("testdep2.manifest");
1255 DeleteFileA("main_wndcls.manifest");
1257 ret = pActivateActCtx(handle, &cookie);
1258 ok(ret, "ActivateActCtx failed: %u\n", GetLastError());
1260 memset(&data, 0, sizeof(data));
1261 memset(&data2, 0, sizeof(data2));
1262 data.cbSize = sizeof(data);
1263 data2.cbSize = sizeof(data2);
1265 /* get data for two files from different assemblies */
1266 ret = pFindActCtxSectionStringW(0, NULL,
1267 ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
1268 testlib1W, &data);
1269 ok(ret, "got %d\n", ret);
1270 ret = pFindActCtxSectionStringW(0, NULL,
1271 ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
1272 testlib2W, &data2);
1273 ok(ret, "got %d\n", ret);
1275 section = (struct strsection_header*)data.lpSectionBase;
1276 ok(section->count == 4, "got %d\n", section->count);
1277 ok(section->size == sizeof(*section), "got %d\n", section->size);
1279 /* For both string same section is returned, meaning it's one dll redirect section per context */
1280 ok(data.lpSectionBase == data2.lpSectionBase, "got %p, %p\n", data.lpSectionBase, data2.lpSectionBase);
1281 ok(data.ulSectionTotalLength == data2.ulSectionTotalLength, "got %u, %u\n", data.ulSectionTotalLength,
1282 data2.ulSectionTotalLength);
1284 ret = pDeactivateActCtx(0, cookie);
1285 ok(ret, "DeactivateActCtx failed: %u\n", GetLastError());
1287 pReleaseActCtx(handle);
1290 static void test_typelib_section(void)
1292 static const WCHAR helpW[] = {'h','e','l','p'};
1293 ACTCTX_SECTION_KEYED_DATA data, data2;
1294 struct guidsection_header *section;
1295 struct tlibredirect_data *tlib;
1296 ULONG_PTR cookie;
1297 HANDLE handle;
1298 BOOL ret;
1300 /* use two dependent manifests, 4 'files' total */
1301 create_manifest_file("testdep1.manifest", manifest_wndcls1, -1, NULL, NULL);
1302 create_manifest_file("testdep2.manifest", manifest_wndcls2, -1, NULL, NULL);
1303 create_manifest_file("main_wndcls.manifest", manifest_wndcls_main, -1, NULL, NULL);
1305 handle = test_create("main_wndcls.manifest");
1306 DeleteFileA("testdep1.manifest");
1307 DeleteFileA("testdep2.manifest");
1308 DeleteFileA("main_wndcls.manifest");
1310 ret = pActivateActCtx(handle, &cookie);
1311 ok(ret, "ActivateActCtx failed: %u\n", GetLastError());
1313 memset(&data, 0, sizeof(data));
1314 memset(&data2, 0, sizeof(data2));
1315 data.cbSize = sizeof(data);
1316 data2.cbSize = sizeof(data2);
1318 /* get data for two typelibs from different assemblies */
1319 ret = pFindActCtxSectionGuid(0, NULL,
1320 ACTIVATION_CONTEXT_SECTION_COM_TYPE_LIBRARY_REDIRECTION,
1321 &IID_TlibTest, &data);
1322 ok(ret, "got %d\n", ret);
1324 ret = pFindActCtxSectionGuid(0, NULL,
1325 ACTIVATION_CONTEXT_SECTION_COM_TYPE_LIBRARY_REDIRECTION,
1326 &IID_TlibTest4, &data2);
1327 ok(ret, "got %d\n", ret);
1329 section = (struct guidsection_header*)data.lpSectionBase;
1330 ok(section->count == 4, "got %d\n", section->count);
1331 ok(section->size == sizeof(*section), "got %d\n", section->size);
1333 /* For both GUIDs same section is returned */
1334 ok(data.lpSectionBase == data2.lpSectionBase, "got %p, %p\n", data.lpSectionBase, data2.lpSectionBase);
1335 ok(data.ulSectionTotalLength == data2.ulSectionTotalLength, "got %u, %u\n", data.ulSectionTotalLength,
1336 data2.ulSectionTotalLength);
1338 /* test some actual data */
1339 tlib = (struct tlibredirect_data*)data.lpData;
1340 ok(tlib->size == sizeof(*tlib), "got %d\n", tlib->size);
1341 ok(tlib->major_version == 1, "got %d\n", tlib->major_version);
1342 ok(tlib->minor_version == 0, "got %d\n", tlib->minor_version);
1343 ok(tlib->help_offset > 0, "got %d\n", tlib->help_offset);
1344 ok(tlib->help_len == sizeof(helpW), "got %d\n", tlib->help_len);
1345 ok(tlib->flags == (LIBFLAG_FHIDDEN|LIBFLAG_FCONTROL|LIBFLAG_FRESTRICTED), "got %x\n", tlib->flags);
1347 ret = pDeactivateActCtx(0, cookie);
1348 ok(ret, "DeactivateActCtx failed: %u\n", GetLastError());
1350 pReleaseActCtx(handle);
1353 static void test_actctx(void)
1355 ULONG_PTR cookie;
1356 HANDLE handle;
1357 BOOL b;
1359 test_create_fail();
1361 trace("default actctx\n");
1363 b = pGetCurrentActCtx(&handle);
1364 ok(handle == NULL, "handle = %p, expected NULL\n", handle);
1365 ok(b, "GetCurrentActCtx failed: %u\n", GetLastError());
1366 if(b) {
1367 test_basic_info(handle, __LINE__);
1368 test_detailed_info(handle, &detailed_info0, __LINE__);
1369 pReleaseActCtx(handle);
1372 if(!create_manifest_file("test1.manifest", manifest1, -1, NULL, NULL)) {
1373 skip("Could not create manifest file\n");
1374 return;
1377 trace("manifest1\n");
1379 handle = test_create("test1.manifest");
1380 DeleteFileA("test1.manifest");
1381 if(handle != INVALID_HANDLE_VALUE) {
1382 test_basic_info(handle, __LINE__);
1383 test_detailed_info(handle, &detailed_info1, __LINE__);
1384 test_info_in_assembly(handle, 1, &manifest1_info, __LINE__);
1386 if (pIsDebuggerPresent && !pIsDebuggerPresent())
1388 /* CloseHandle will generate an exception if a debugger is present */
1389 b = CloseHandle(handle);
1390 ok(!b, "CloseHandle succeeded\n");
1391 ok(GetLastError() == ERROR_INVALID_HANDLE, "GetLastError() == %u\n", GetLastError());
1394 pReleaseActCtx(handle);
1397 if(!create_manifest_file("test2.manifest", manifest2, -1, "testdep.manifest", testdep_manifest1)) {
1398 skip("Could not create manifest file\n");
1399 return;
1402 trace("manifest2 depmanifest1\n");
1404 handle = test_create("test2.manifest");
1405 DeleteFileA("test2.manifest");
1406 DeleteFileA("testdep.manifest");
1407 if(handle != INVALID_HANDLE_VALUE) {
1408 test_basic_info(handle, __LINE__);
1409 test_detailed_info(handle, &detailed_info2, __LINE__);
1410 test_info_in_assembly(handle, 1, &manifest2_info, __LINE__);
1411 test_info_in_assembly(handle, 2, &depmanifest1_info, __LINE__);
1412 pReleaseActCtx(handle);
1415 if(!create_manifest_file("test2-2.manifest", manifest2, -1, "testdep.manifest", testdep_manifest2)) {
1416 skip("Could not create manifest file\n");
1417 return;
1420 trace("manifest2 depmanifest2\n");
1422 handle = test_create("test2-2.manifest");
1423 DeleteFileA("test2-2.manifest");
1424 DeleteFileA("testdep.manifest");
1425 if(handle != INVALID_HANDLE_VALUE) {
1426 test_basic_info(handle, __LINE__);
1427 test_detailed_info(handle, &detailed_info2, __LINE__);
1428 test_info_in_assembly(handle, 1, &manifest2_info, __LINE__);
1429 test_info_in_assembly(handle, 2, &depmanifest2_info, __LINE__);
1430 test_file_info(handle, 1, 0, testlib_dll, __LINE__);
1431 test_file_info(handle, 1, 1, testlib2_dll, __LINE__);
1433 b = pActivateActCtx(handle, &cookie);
1434 ok(b, "ActivateActCtx failed: %u\n", GetLastError());
1435 test_find_dll_redirection(handle, testlib_dll, 2, __LINE__);
1436 test_find_dll_redirection(handle, testlib2_dll, 2, __LINE__);
1437 b = pDeactivateActCtx(0, cookie);
1438 ok(b, "DeactivateActCtx failed: %u\n", GetLastError());
1440 pReleaseActCtx(handle);
1443 trace("manifest2 depmanifest3\n");
1445 if(!create_manifest_file("test2-3.manifest", manifest2, -1, "testdep.manifest", testdep_manifest3)) {
1446 skip("Could not create manifest file\n");
1447 return;
1450 handle = test_create("test2-3.manifest");
1451 DeleteFileA("test2-3.manifest");
1452 DeleteFileA("testdep.manifest");
1453 if(handle != INVALID_HANDLE_VALUE) {
1454 test_basic_info(handle, __LINE__);
1455 test_detailed_info(handle, &detailed_info2, __LINE__);
1456 test_info_in_assembly(handle, 1, &manifest2_info, __LINE__);
1457 test_info_in_assembly(handle, 2, &depmanifest3_info, __LINE__);
1458 test_file_info(handle, 1, 0, testlib_dll, __LINE__);
1459 test_file_info(handle, 1, 1, testlib2_dll, __LINE__);
1461 b = pActivateActCtx(handle, &cookie);
1462 ok(b, "ActivateActCtx failed: %u\n", GetLastError());
1463 test_find_dll_redirection(handle, testlib_dll, 2, __LINE__);
1464 test_find_dll_redirection(handle, testlib2_dll, 2, __LINE__);
1465 test_find_window_class(handle, wndClassW, 2, __LINE__);
1466 test_find_window_class(handle, wndClass2W, 2, __LINE__);
1467 b = pDeactivateActCtx(0, cookie);
1468 ok(b, "DeactivateActCtx failed: %u\n", GetLastError());
1470 pReleaseActCtx(handle);
1473 trace("manifest3\n");
1475 if(!create_manifest_file("test3.manifest", manifest3, -1, NULL, NULL)) {
1476 skip("Could not create manifest file\n");
1477 return;
1480 handle = test_create("test3.manifest");
1481 DeleteFileA("test3.manifest");
1482 if(handle != INVALID_HANDLE_VALUE) {
1483 test_basic_info(handle, __LINE__);
1484 test_detailed_info(handle, &detailed_info1, __LINE__);
1485 test_info_in_assembly(handle, 1, &manifest3_info, __LINE__);
1486 test_file_info(handle, 0, 0, testlib_dll, __LINE__);
1488 b = pActivateActCtx(handle, &cookie);
1489 ok(b, "ActivateActCtx failed: %u\n", GetLastError());
1490 test_find_dll_redirection(handle, testlib_dll, 1, __LINE__);
1491 test_find_dll_redirection(handle, testlib_dll, 1, __LINE__);
1492 test_find_com_redirection(handle, &IID_CoTest, &IID_TlibTest, 1, __LINE__);
1493 test_find_string_fail();
1494 b = pDeactivateActCtx(0, cookie);
1495 ok(b, "DeactivateActCtx failed: %u\n", GetLastError());
1497 pReleaseActCtx(handle);
1500 trace("manifest4\n");
1502 if(!create_manifest_file("test4.manifest", manifest4, -1, NULL, NULL)) {
1503 skip("Could not create manifest file\n");
1504 return;
1507 handle = test_create("test4.manifest");
1508 DeleteFileA("test4.manifest");
1509 DeleteFileA("testdep.manifest");
1510 if(handle != INVALID_HANDLE_VALUE) {
1511 test_basic_info(handle, __LINE__);
1512 test_detailed_info(handle, &detailed_info2, __LINE__);
1513 test_info_in_assembly(handle, 1, &manifest4_info, __LINE__);
1514 test_info_in_assembly(handle, 2, &manifest_comctrl_info, __LINE__);
1515 pReleaseActCtx(handle);
1518 trace("manifest1 in subdir\n");
1520 CreateDirectoryW(work_dir_subdir, NULL);
1521 if (SetCurrentDirectoryW(work_dir_subdir))
1523 if(!create_manifest_file("..\\test1.manifest", manifest1, -1, NULL, NULL)) {
1524 skip("Could not create manifest file\n");
1525 return;
1527 handle = test_create("..\\test1.manifest");
1528 DeleteFileA("..\\test1.manifest");
1529 if(handle != INVALID_HANDLE_VALUE) {
1530 test_basic_info(handle, __LINE__);
1531 test_detailed_info(handle, &detailed_info1, __LINE__);
1532 test_info_in_assembly(handle, 1, &manifest1_info, __LINE__);
1533 pReleaseActCtx(handle);
1535 SetCurrentDirectoryW(work_dir);
1537 else
1538 skip("Couldn't change directory\n");
1539 RemoveDirectoryW(work_dir_subdir);
1541 trace("UTF-16 manifest1, with BOM\n");
1542 if(!create_wide_manifest("test1.manifest", manifest1, TRUE, FALSE)) {
1543 skip("Could not create manifest file\n");
1544 return;
1547 handle = test_create("test1.manifest");
1548 DeleteFileA("test1.manifest");
1549 if (handle != INVALID_HANDLE_VALUE) {
1550 test_basic_info(handle, __LINE__);
1551 test_detailed_info(handle, &detailed_info1, __LINE__);
1552 test_info_in_assembly(handle, 1, &manifest1_info, __LINE__);
1553 pReleaseActCtx(handle);
1556 trace("UTF-16 manifest1, reverse endian, with BOM\n");
1557 if(!create_wide_manifest("test1.manifest", manifest1, TRUE, TRUE)) {
1558 skip("Could not create manifest file\n");
1559 return;
1562 handle = test_create("test1.manifest");
1563 DeleteFileA("test1.manifest");
1564 if (handle != INVALID_HANDLE_VALUE) {
1565 test_basic_info(handle, __LINE__);
1566 test_detailed_info(handle, &detailed_info1, __LINE__);
1567 test_info_in_assembly(handle, 1, &manifest1_info, __LINE__);
1568 pReleaseActCtx(handle);
1571 test_wndclass_section();
1572 test_dllredirect_section();
1573 test_typelib_section();
1576 static void test_app_manifest(void)
1578 HANDLE handle;
1579 BOOL b;
1581 trace("child process manifest1\n");
1583 b = pGetCurrentActCtx(&handle);
1584 ok(handle == NULL, "handle != NULL\n");
1585 ok(b, "GetCurrentActCtx failed: %u\n", GetLastError());
1586 if(b) {
1587 test_basic_info(handle, __LINE__);
1588 test_detailed_info(handle, &detailed_info1_child, __LINE__);
1589 test_info_in_assembly(handle, 1, &manifest1_child_info, __LINE__);
1590 pReleaseActCtx(handle);
1594 static void run_child_process(void)
1596 char cmdline[MAX_PATH];
1597 char path[MAX_PATH];
1598 char **argv;
1599 PROCESS_INFORMATION pi;
1600 STARTUPINFO si = { 0 };
1601 HANDLE file;
1602 FILETIME now;
1603 BOOL ret;
1605 GetModuleFileNameA(NULL, path, MAX_PATH);
1606 strcat(path, ".manifest");
1607 if(!create_manifest_file(path, manifest1, -1, NULL, NULL)) {
1608 skip("Could not create manifest file\n");
1609 return;
1612 si.cb = sizeof(si);
1613 winetest_get_mainargs( &argv );
1614 /* Vista+ seems to cache presence of .manifest files. Change last modified
1615 date to defeat the cache */
1616 file = CreateFileA(argv[0], FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE,
1617 NULL, OPEN_EXISTING, 0, NULL);
1618 if (file != INVALID_HANDLE_VALUE) {
1619 GetSystemTimeAsFileTime(&now);
1620 SetFileTime(file, NULL, NULL, &now);
1621 CloseHandle(file);
1623 sprintf(cmdline, "\"%s\" %s manifest1", argv[0], argv[1]);
1624 ret = CreateProcess(argv[0], cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
1625 ok(ret, "Could not create process: %u\n", GetLastError());
1626 winetest_wait_child_process( pi.hProcess );
1627 CloseHandle(pi.hThread);
1628 CloseHandle(pi.hProcess);
1629 DeleteFileA(path);
1632 static void init_paths(void)
1634 LPWSTR ptr;
1635 WCHAR last;
1637 static const WCHAR dot_manifest[] = {'.','M','a','n','i','f','e','s','t',0};
1638 static const WCHAR backslash[] = {'\\',0};
1639 static const WCHAR subdir[] = {'T','e','s','t','S','u','b','d','i','r','\\',0};
1641 GetModuleFileNameW(NULL, exe_path, sizeof(exe_path)/sizeof(WCHAR));
1642 lstrcpyW(app_dir, exe_path);
1643 for(ptr=app_dir+lstrlenW(app_dir); *ptr != '\\' && *ptr != '/'; ptr--);
1644 ptr[1] = 0;
1646 GetCurrentDirectoryW(MAX_PATH, work_dir);
1647 last = work_dir[lstrlenW(work_dir) - 1];
1648 if (last != '\\' && last != '/')
1649 lstrcatW(work_dir, backslash);
1650 lstrcpyW(work_dir_subdir, work_dir);
1651 lstrcatW(work_dir_subdir, subdir);
1653 GetModuleFileNameW(NULL, app_manifest_path, sizeof(app_manifest_path)/sizeof(WCHAR));
1654 lstrcpyW(app_manifest_path+lstrlenW(app_manifest_path), dot_manifest);
1657 static BOOL init_funcs(void)
1659 HMODULE hKernel32 = GetModuleHandle("kernel32");
1661 #define X(f) if (!(p##f = (void*)GetProcAddress(hKernel32, #f))) return FALSE;
1662 X(ActivateActCtx);
1663 X(CreateActCtxW);
1664 X(DeactivateActCtx);
1665 X(FindActCtxSectionStringW);
1666 X(GetCurrentActCtx);
1667 X(IsDebuggerPresent);
1668 X(QueryActCtxW);
1669 X(ReleaseActCtx);
1670 X(FindActCtxSectionGuid);
1671 #undef X
1673 return TRUE;
1676 START_TEST(actctx)
1678 int argc;
1679 char **argv;
1681 argc = winetest_get_mainargs(&argv);
1683 if (!init_funcs())
1685 win_skip("Needed functions are not available\n");
1686 return;
1688 init_paths();
1690 if(argc > 2 && !strcmp(argv[2], "manifest1")) {
1691 test_app_manifest();
1692 return;
1695 test_actctx();
1696 run_child_process();