ddraw/tests: Rewrite LimitTest().
[wine.git] / dlls / kernel32 / tests / actctx.c
blobaf3dadf79a5c2f2d656cbfee90786e6ad04326ba
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 "ntstatus.h"
20 #define WIN32_NO_STATUS
21 #include "wine/test.h"
22 #include <winbase.h>
23 #include <windef.h>
24 #include <winnt.h>
25 #include <winternl.h>
26 #include <winnls.h>
27 #include <stdio.h>
29 #include "oaidl.h"
30 #include "initguid.h"
32 static BOOL (WINAPI *pActivateActCtx)(HANDLE,ULONG_PTR*);
33 static HANDLE (WINAPI *pCreateActCtxA)(PCACTCTXA);
34 static HANDLE (WINAPI *pCreateActCtxW)(PCACTCTXW);
35 static BOOL (WINAPI *pDeactivateActCtx)(DWORD,ULONG_PTR);
36 static BOOL (WINAPI *pFindActCtxSectionStringA)(DWORD,const GUID *,ULONG,LPCSTR,PACTCTX_SECTION_KEYED_DATA);
37 static BOOL (WINAPI *pFindActCtxSectionStringW)(DWORD,const GUID *,ULONG,LPCWSTR,PACTCTX_SECTION_KEYED_DATA);
38 static BOOL (WINAPI *pGetCurrentActCtx)(HANDLE *);
39 static BOOL (WINAPI *pIsDebuggerPresent)(void);
40 static BOOL (WINAPI *pQueryActCtxW)(DWORD,HANDLE,PVOID,ULONG,PVOID,SIZE_T,SIZE_T*);
41 static VOID (WINAPI *pReleaseActCtx)(HANDLE);
42 static BOOL (WINAPI *pFindActCtxSectionGuid)(DWORD,const GUID*,ULONG,const GUID*,PACTCTX_SECTION_KEYED_DATA);
43 static BOOL (WINAPI *pZombifyActCtx)(HANDLE);
45 static NTSTATUS(NTAPI *pRtlFindActivationContextSectionString)(DWORD,const GUID *,ULONG,PUNICODE_STRING,PACTCTX_SECTION_KEYED_DATA);
46 static BOOLEAN (NTAPI *pRtlCreateUnicodeStringFromAsciiz)(PUNICODE_STRING, PCSZ);
47 static VOID (NTAPI *pRtlFreeUnicodeString)(PUNICODE_STRING);
49 static const char* strw(LPCWSTR x)
51 static char buffer[1024];
52 char* p = buffer;
54 if (!x) return "(nil)";
55 else while ((*p++ = *x++));
56 return buffer;
59 #ifdef __i386__
60 #define ARCH "x86"
61 #elif defined __x86_64__
62 #define ARCH "amd64"
63 #elif defined __arm__
64 #define ARCH "arm"
65 #elif defined __aarch64__
66 #define ARCH "arm64"
67 #else
68 #define ARCH "none"
69 #endif
71 static const char manifest1[] =
72 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
73 "<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
74 "</assembly>";
76 static const char manifest1_1[] =
77 "<assembly xmlns = \"urn:schemas-microsoft-com:asm.v1\" manifestVersion = \"1.0\">"
78 "<assemblyIdentity version = \"1.0.0.0\" name = \"Wine.Test\" type = \"win32\"></assemblyIdentity>"
79 "</assembly>";
81 static const char manifest2[] =
82 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
83 "<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\">"
84 "</assemblyIdentity>"
85 "<dependency>"
86 "<dependentAssembly>"
87 "<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"" ARCH "\">"
88 "</assemblyIdentity>"
89 "</dependentAssembly>"
90 "</dependency>"
91 "</assembly>";
93 DEFINE_GUID(IID_CoTest, 0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x11, 0x11, 0x22, 0x22, 0x33, 0x33);
94 DEFINE_GUID(IID_CoTest2, 0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x11, 0x11, 0x22, 0x22, 0x33, 0x34);
95 DEFINE_GUID(CLSID_clrclass,0x22345678, 0x1234, 0x5678, 0x12, 0x34, 0x11, 0x11, 0x22, 0x22, 0x33, 0x33);
96 DEFINE_GUID(IID_TlibTest, 0x99999999, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55);
97 DEFINE_GUID(IID_TlibTest2, 0x99999999, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x56);
98 DEFINE_GUID(IID_TlibTest3, 0x99999999, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x57);
99 DEFINE_GUID(IID_TlibTest4, 0x99999999, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x58);
100 DEFINE_GUID(IID_Iifaceps, 0x66666666, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55);
101 DEFINE_GUID(IID_Ibifaceps, 0x66666666, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x57);
102 DEFINE_GUID(IID_Iifaceps2, 0x76666666, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55);
103 DEFINE_GUID(IID_Iifaceps3, 0x86666666, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55);
104 DEFINE_GUID(IID_Iiface, 0x96666666, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55);
105 DEFINE_GUID(IID_PS32, 0x66666666, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x56);
107 static const char manifest3[] =
108 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
109 "<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\""
110 " publicKeyToken=\"6595b6414666f1df\" />"
111 "<description />"
112 "<file name=\"testlib.dll\">"
113 "<windowClass>wndClass</windowClass>"
114 " <comClass description=\"Test com class\""
115 " clsid=\"{12345678-1234-5678-1234-111122223333}\""
116 " tlbid=\"{99999999-8888-7777-6666-555555555555}\""
117 " threadingModel=\"Neutral\""
118 " progid=\"ProgId.ProgId\""
119 " miscStatus=\"cantlinkinside\""
120 " miscStatusIcon=\"recomposeonresize\""
121 " miscStatusContent=\"insideout\""
122 " miscStatusThumbnail=\"alignable\""
123 " miscStatusDocPrint=\"simpleframe,setclientsitefirst\""
124 " >"
125 " <progid>ProgId.ProgId.1</progid>"
126 " <progid>ProgId.ProgId.2</progid>"
127 " <progid>ProgId.ProgId.3</progid>"
128 " <progid>ProgId.ProgId.4</progid>"
129 " <progid>ProgId.ProgId.5</progid>"
130 " <progid>ProgId.ProgId.6</progid>"
131 " </comClass>"
132 " <comClass clsid=\"{12345678-1234-5678-1234-111122223334}\" threadingModel=\"Neutral\" >"
133 " <progid>ProgId.ProgId.7</progid>"
134 " </comClass>"
135 " <comInterfaceProxyStub "
136 " name=\"Iifaceps\""
137 " tlbid=\"{99999999-8888-7777-6666-555555555558}\""
138 " iid=\"{66666666-8888-7777-6666-555555555555}\""
139 " proxyStubClsid32=\"{66666666-8888-7777-6666-555555555556}\""
140 " threadingModel=\"Free\""
141 " numMethods=\"10\""
142 " baseInterface=\"{66666666-8888-7777-6666-555555555557}\""
143 " />"
144 "</file>"
145 " <comInterfaceExternalProxyStub "
146 " name=\"Iifaceps2\""
147 " tlbid=\"{99999999-8888-7777-6666-555555555558}\""
148 " iid=\"{76666666-8888-7777-6666-555555555555}\""
149 " proxyStubClsid32=\"{66666666-8888-7777-6666-555555555556}\""
150 " numMethods=\"10\""
151 " baseInterface=\"{66666666-8888-7777-6666-555555555557}\""
152 " />"
153 " <comInterfaceExternalProxyStub "
154 " name=\"Iifaceps3\""
155 " tlbid=\"{99999999-8888-7777-6666-555555555558}\""
156 " iid=\"{86666666-8888-7777-6666-555555555555}\""
157 " numMethods=\"10\""
158 " baseInterface=\"{66666666-8888-7777-6666-555555555557}\""
159 " />"
160 " <clrSurrogate "
161 " clsid=\"{96666666-8888-7777-6666-555555555555}\""
162 " name=\"testsurrogate\""
163 " runtimeVersion=\"v2.0.50727\""
164 " />"
165 " <clrClass "
166 " clsid=\"{22345678-1234-5678-1234-111122223333}\""
167 " name=\"clrclass\""
168 " progid=\"clrprogid\""
169 " description=\"test description\""
170 " tlbid=\"{99999999-8888-7777-6666-555555555555}\""
171 " runtimeVersion=\"1.2.3.4\""
172 " threadingModel=\"Neutral\""
173 " >"
174 " <progid>clrprogid.1</progid>"
175 " <progid>clrprogid.2</progid>"
176 " <progid>clrprogid.3</progid>"
177 " <progid>clrprogid.4</progid>"
178 " <progid>clrprogid.5</progid>"
179 " <progid>clrprogid.6</progid>"
180 " </clrClass>"
181 "</assembly>";
183 static const char manifest_wndcls1[] =
184 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
185 "<assemblyIdentity version=\"1.2.3.4\" name=\"testdep1\" type=\"win32\" processorArchitecture=\"" ARCH "\"/>"
186 "<file name=\"testlib1.dll\">"
187 "<windowClass versioned=\"yes\">wndClass1</windowClass>"
188 "<windowClass>wndClass2</windowClass>"
189 " <typelib tlbid=\"{99999999-8888-7777-6666-555555555558}\" version=\"1.0\" helpdir=\"\" />"
190 "</file>"
191 "<file name=\"testlib1_2.dll\" />"
192 "</assembly>";
194 static const char manifest_wndcls2[] =
195 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
196 "<assemblyIdentity version=\"4.3.2.1\" name=\"testdep2\" type=\"win32\" processorArchitecture=\"" ARCH "\" />"
197 "<file name=\"testlib2.dll\">"
198 " <windowClass versioned=\"no\">wndClass3</windowClass>"
199 " <windowClass>wndClass4</windowClass>"
200 " <typelib tlbid=\"{99999999-8888-7777-6666-555555555555}\" version=\"1.0\" helpdir=\"help\" resourceid=\"409\""
201 " flags=\"HiddeN,CoNTROL,rESTRICTED\" />"
202 " <typelib tlbid=\"{99999999-8888-7777-6666-555555555556}\" version=\"1.0\" helpdir=\"help1\" resourceid=\"409\" />"
203 " <typelib tlbid=\"{99999999-8888-7777-6666-555555555557}\" version=\"1.0\" helpdir=\"\" />"
204 "</file>"
205 "<file name=\"testlib2_2.dll\" />"
206 "</assembly>";
208 static const char manifest_wndcls_main[] =
209 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
210 "<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\" />"
211 "<dependency>"
212 " <dependentAssembly>"
213 " <assemblyIdentity type=\"win32\" name=\"testdep1\" version=\"1.2.3.4\" processorArchitecture=\"" ARCH "\" />"
214 " </dependentAssembly>"
215 "</dependency>"
216 "<dependency>"
217 " <dependentAssembly>"
218 " <assemblyIdentity type=\"win32\" name=\"testdep2\" version=\"4.3.2.1\" processorArchitecture=\"" ARCH "\" />"
219 " </dependentAssembly>"
220 "</dependency>"
221 "</assembly>";
223 static const char manifest4[] =
224 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
225 "<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\">"
226 "</assemblyIdentity>"
227 "<dependency>"
228 "<dependentAssembly>"
229 "<assemblyIdentity type=\"win32\" name=\"Microsoft.Windows.Common-Controls\" "
230 "version=\"6.0.1.0\" processorArchitecture=\"" ARCH "\" publicKeyToken=\"6595b64144ccf1df\">"
231 "</assemblyIdentity>"
232 "</dependentAssembly>"
233 "</dependency>"
234 "</assembly>";
236 static const char manifest5[] =
237 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
238 "<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\">"
239 "</assemblyIdentity>"
240 "<dependency>"
241 " <dependentAssembly dependencyType=\"preRequisite\" allowDelayedBinding=\"true\">"
242 " <assemblyIdentity name=\"Missing.Assembly\" version=\"1.0.0.0\" />"
243 " </dependentAssembly>"
244 "</dependency>"
245 "</assembly>";
247 static const char testdep_manifest1[] =
248 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
249 "<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"" ARCH "\"/>"
250 "</assembly>";
252 static const char testdep_manifest2[] =
253 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
254 "<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"" ARCH "\" />"
255 "<file name=\"testlib.dll\"></file>"
256 "<file name=\"testlib2.dll\" hash=\"63c978c2b53d6cf72b42fb7308f9af12ab19ec53\" hashalg=\"SHA1\" />"
257 "</assembly>";
259 static const char testdep_manifest3[] =
260 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\"> "
261 "<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"" ARCH "\"/>"
262 "<file name=\"testlib.dll\"/>"
263 "<file name=\"testlib2.dll\" hash=\"63c978c2b53d6cf72b42fb7308f9af12ab19ec53\" hashalg=\"SHA1\">"
264 "<windowClass>wndClass</windowClass>"
265 "<windowClass>wndClass2</windowClass>"
266 "</file>"
267 "</assembly>";
269 static const char wrong_manifest1[] =
270 "<assembly manifestVersion=\"1.0\">"
271 "<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
272 "</assembly>";
274 static const char wrong_manifest2[] =
275 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\">"
276 "<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
277 "</assembly>";
279 static const char wrong_manifest3[] =
280 "<assembly test=\"test\" xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
281 "<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
282 "</assembly>";
284 static const char wrong_manifest4[] =
285 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
286 "<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
287 "<test></test>"
288 "</assembly>";
290 static const char wrong_manifest5[] =
291 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
292 "<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
293 "</assembly>"
294 "<test></test>";
296 static const char wrong_manifest6[] =
297 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v5\" manifestVersion=\"1.0\">"
298 "<assemblyIdentity version=\"1.0.0.0\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
299 "</assembly>";
301 static const char wrong_manifest7[] =
302 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
303 "<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"" ARCH "\" />"
304 "<file name=\"testlib.dll\" hash=\"63c978c2b53d6cf72b42fb7308f9af12ab19ec5\" hashalg=\"SHA1\" />"
305 "</assembly>";
307 static const char wrong_manifest8[] =
308 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
309 "<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
310 "<file></file>"
311 "</assembly>";
313 static const char wrong_depmanifest1[] =
314 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
315 "<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.4\" processorArchitecture=\"" ARCH "\" />"
316 "</assembly>";
318 static const WCHAR testlib_dll[] =
319 {'t','e','s','t','l','i','b','.','d','l','l',0};
320 static const WCHAR testlib2_dll[] =
321 {'t','e','s','t','l','i','b','2','.','d','l','l',0};
322 static const WCHAR wndClassW[] =
323 {'w','n','d','C','l','a','s','s',0};
324 static const WCHAR wndClass1W[] =
325 {'w','n','d','C','l','a','s','s','1',0};
326 static const WCHAR wndClass2W[] =
327 {'w','n','d','C','l','a','s','s','2',0};
328 static const WCHAR wndClass3W[] =
329 {'w','n','d','C','l','a','s','s','3',0};
331 static WCHAR app_dir[MAX_PATH], exe_path[MAX_PATH], work_dir[MAX_PATH], work_dir_subdir[MAX_PATH];
332 static WCHAR app_manifest_path[MAX_PATH], manifest_path[MAX_PATH], depmanifest_path[MAX_PATH];
334 static int strcmp_aw(LPCWSTR strw, const char *stra)
336 WCHAR buf[1024];
338 if (!stra) return 1;
339 MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(WCHAR));
340 return lstrcmpW(strw, buf);
343 static DWORD strlen_aw(const char *str)
345 return MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0) - 1;
348 static BOOL create_manifest_file(const char *filename, const char *manifest, int manifest_len,
349 const char *depfile, const char *depmanifest)
351 DWORD size;
352 HANDLE file;
353 WCHAR path[MAX_PATH];
355 MultiByteToWideChar( CP_ACP, 0, filename, -1, path, MAX_PATH );
356 GetFullPathNameW(path, sizeof(manifest_path)/sizeof(WCHAR), manifest_path, NULL);
358 if (manifest_len == -1)
359 manifest_len = strlen(manifest);
361 file = CreateFileW(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
362 FILE_ATTRIBUTE_NORMAL, NULL);
363 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %u\n", GetLastError());
364 if(file == INVALID_HANDLE_VALUE)
365 return FALSE;
366 WriteFile(file, manifest, manifest_len, &size, NULL);
367 CloseHandle(file);
369 if (depmanifest)
371 MultiByteToWideChar( CP_ACP, 0, depfile, -1, path, MAX_PATH );
372 GetFullPathNameW(path, sizeof(depmanifest_path)/sizeof(WCHAR), depmanifest_path, NULL);
373 file = CreateFileW(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
374 FILE_ATTRIBUTE_NORMAL, NULL);
375 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %u\n", GetLastError());
376 if(file == INVALID_HANDLE_VALUE)
377 return FALSE;
378 WriteFile(file, depmanifest, strlen(depmanifest), &size, NULL);
379 CloseHandle(file);
381 return TRUE;
384 static BOOL create_wide_manifest(const char *filename, const char *manifest, BOOL fBOM, BOOL fReverse)
386 WCHAR *wmanifest = HeapAlloc(GetProcessHeap(), 0, (strlen(manifest)+2) * sizeof(WCHAR));
387 BOOL ret;
388 int offset = (fBOM ? 0 : 1);
390 MultiByteToWideChar(CP_ACP, 0, manifest, -1, &wmanifest[1], (strlen(manifest)+1));
391 wmanifest[0] = 0xfeff;
392 if (fReverse)
394 size_t i;
395 for (i = 0; i < strlen(manifest)+1; i++)
396 wmanifest[i] = (wmanifest[i] << 8) | ((wmanifest[i] >> 8) & 0xff);
398 ret = create_manifest_file(filename, (char *)&wmanifest[offset], (strlen(manifest)+1-offset) * sizeof(WCHAR), NULL, NULL);
399 HeapFree(GetProcessHeap(), 0, wmanifest);
400 return ret;
403 typedef struct {
404 ULONG format_version;
405 ULONG assembly_cnt_min;
406 ULONG assembly_cnt_max;
407 ULONG root_manifest_type;
408 LPWSTR root_manifest_path;
409 ULONG root_config_type;
410 ULONG app_dir_type;
411 LPCWSTR app_dir;
412 } detailed_info_t;
414 static const detailed_info_t detailed_info0 = {
415 0, 0, 0, 0, NULL, 0, 0, NULL
418 static const detailed_info_t detailed_info1 = {
419 1, 1, 1, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE, manifest_path,
420 ACTIVATION_CONTEXT_PATH_TYPE_NONE, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE,
421 work_dir,
424 static const detailed_info_t detailed_info1_child = {
425 1, 1, 1, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE, app_manifest_path,
426 ACTIVATION_CONTEXT_PATH_TYPE_NONE, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE,
427 app_dir,
430 /* On Vista+, there's an extra assembly for Microsoft.Windows.Common-Controls.Resources */
431 static const detailed_info_t detailed_info2 = {
432 1, 2, 3, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE, manifest_path,
433 ACTIVATION_CONTEXT_PATH_TYPE_NONE, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE,
434 work_dir,
437 static void test_detailed_info(HANDLE handle, const detailed_info_t *exinfo, int line)
439 ACTIVATION_CONTEXT_DETAILED_INFORMATION detailed_info_tmp, *detailed_info;
440 SIZE_T size, exsize, retsize;
441 BOOL b;
443 exsize = sizeof(ACTIVATION_CONTEXT_DETAILED_INFORMATION)
444 + (exinfo->root_manifest_path ? (lstrlenW(exinfo->root_manifest_path)+1)*sizeof(WCHAR):0)
445 + (exinfo->app_dir ? (lstrlenW(exinfo->app_dir)+1)*sizeof(WCHAR) : 0);
447 if(exsize != sizeof(ACTIVATION_CONTEXT_DETAILED_INFORMATION)) {
448 size = 0xdeadbeef;
449 b = pQueryActCtxW(0, handle, NULL,
450 ActivationContextDetailedInformation, &detailed_info_tmp,
451 sizeof(detailed_info_tmp), &size);
452 ok_(__FILE__, line)(!b, "QueryActCtx succeeded\n");
453 ok_(__FILE__, line)(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetLastError() = %u\n", GetLastError());
454 ok_(__FILE__, line)(size == exsize, "size=%ld, expected %ld\n", size, exsize);
455 }else {
456 size = sizeof(ACTIVATION_CONTEXT_DETAILED_INFORMATION);
459 detailed_info = HeapAlloc(GetProcessHeap(), 0, size);
460 memset(detailed_info, 0xfe, size);
461 b = pQueryActCtxW(0, handle, NULL,
462 ActivationContextDetailedInformation, detailed_info,
463 size, &retsize);
464 ok_(__FILE__, line)(b, "QueryActCtx failed: %u\n", GetLastError());
465 ok_(__FILE__, line)(retsize == exsize, "size=%ld, expected %ld\n", retsize, exsize);
467 ok_(__FILE__, line)(detailed_info->dwFlags == 0, "detailed_info->dwFlags=%x\n", detailed_info->dwFlags);
468 ok_(__FILE__, line)(detailed_info->ulFormatVersion == exinfo->format_version,
469 "detailed_info->ulFormatVersion=%u, expected %u\n", detailed_info->ulFormatVersion,
470 exinfo->format_version);
471 ok_(__FILE__, line)(exinfo->assembly_cnt_min <= detailed_info->ulAssemblyCount &&
472 detailed_info->ulAssemblyCount <= exinfo->assembly_cnt_max,
473 "detailed_info->ulAssemblyCount=%u, expected between %u and %u\n", detailed_info->ulAssemblyCount,
474 exinfo->assembly_cnt_min, exinfo->assembly_cnt_max);
475 ok_(__FILE__, line)(detailed_info->ulRootManifestPathType == exinfo->root_manifest_type,
476 "detailed_info->ulRootManifestPathType=%u, expected %u\n",
477 detailed_info->ulRootManifestPathType, exinfo->root_manifest_type);
478 ok_(__FILE__, line)(detailed_info->ulRootManifestPathChars ==
479 (exinfo->root_manifest_path ? lstrlenW(exinfo->root_manifest_path) : 0),
480 "detailed_info->ulRootManifestPathChars=%u, expected %u\n",
481 detailed_info->ulRootManifestPathChars,
482 exinfo->root_manifest_path ?lstrlenW(exinfo->root_manifest_path) : 0);
483 ok_(__FILE__, line)(detailed_info->ulRootConfigurationPathType == exinfo->root_config_type,
484 "detailed_info->ulRootConfigurationPathType=%u, expected %u\n",
485 detailed_info->ulRootConfigurationPathType, exinfo->root_config_type);
486 ok_(__FILE__, line)(detailed_info->ulRootConfigurationPathChars == 0,
487 "detailed_info->ulRootConfigurationPathChars=%d\n", detailed_info->ulRootConfigurationPathChars);
488 ok_(__FILE__, line)(detailed_info->ulAppDirPathType == exinfo->app_dir_type,
489 "detailed_info->ulAppDirPathType=%u, expected %u\n", detailed_info->ulAppDirPathType,
490 exinfo->app_dir_type);
491 ok_(__FILE__, line)(detailed_info->ulAppDirPathChars == (exinfo->app_dir ? lstrlenW(exinfo->app_dir) : 0),
492 "detailed_info->ulAppDirPathChars=%u, expected %u\n",
493 detailed_info->ulAppDirPathChars, exinfo->app_dir ? lstrlenW(exinfo->app_dir) : 0);
494 if(exinfo->root_manifest_path) {
495 ok_(__FILE__, line)(detailed_info->lpRootManifestPath != NULL, "detailed_info->lpRootManifestPath == NULL\n");
496 if(detailed_info->lpRootManifestPath)
497 ok_(__FILE__, line)(!lstrcmpiW(detailed_info->lpRootManifestPath, exinfo->root_manifest_path),
498 "unexpected detailed_info->lpRootManifestPath\n");
499 }else {
500 ok_(__FILE__, line)(detailed_info->lpRootManifestPath == NULL, "detailed_info->lpRootManifestPath != NULL\n");
502 ok_(__FILE__, line)(detailed_info->lpRootConfigurationPath == NULL,
503 "detailed_info->lpRootConfigurationPath=%p\n", detailed_info->lpRootConfigurationPath);
504 if(exinfo->app_dir) {
505 ok_(__FILE__, line)(detailed_info->lpAppDirPath != NULL, "detailed_info->lpAppDirPath == NULL\n");
506 if(detailed_info->lpAppDirPath)
507 ok_(__FILE__, line)(!lstrcmpiW(exinfo->app_dir, detailed_info->lpAppDirPath),
508 "unexpected detailed_info->lpAppDirPath\n%s\n",strw(detailed_info->lpAppDirPath));
509 }else {
510 ok_(__FILE__, line)(detailed_info->lpAppDirPath == NULL, "detailed_info->lpAppDirPath != NULL\n");
513 HeapFree(GetProcessHeap(), 0, detailed_info);
516 typedef struct {
517 ULONG flags;
518 /* ULONG manifest_path_type; FIXME */
519 LPCWSTR manifest_path;
520 LPCSTR encoded_assembly_id;
521 BOOL has_assembly_dir;
522 } info_in_assembly;
524 static const info_in_assembly manifest1_info = {
525 1, manifest_path,
526 "Wine.Test,type=\"win32\",version=\"1.0.0.0\"",
527 FALSE
530 static const info_in_assembly manifest1_child_info = {
531 1, app_manifest_path,
532 "Wine.Test,type=\"win32\",version=\"1.0.0.0\"",
533 FALSE
536 static const info_in_assembly manifest2_info = {
537 1, manifest_path,
538 "Wine.Test,type=\"win32\",version=\"1.2.3.4\"",
539 FALSE
542 static const info_in_assembly manifest3_info = {
543 1, manifest_path,
544 "Wine.Test,publicKeyToken=\"6595b6414666f1df\",type=\"win32\",version=\"1.2.3.4\"",
545 FALSE
548 static const info_in_assembly manifest4_info = {
549 1, manifest_path,
550 "Wine.Test,type=\"win32\",version=\"1.2.3.4\"",
551 FALSE
554 static const info_in_assembly depmanifest1_info = {
555 0x10, depmanifest_path,
556 "testdep,processorArchitecture=\"" ARCH "\","
557 "type=\"win32\",version=\"6.5.4.3\"",
558 TRUE
561 static const info_in_assembly depmanifest2_info = {
562 0x10, depmanifest_path,
563 "testdep,processorArchitecture=\"" ARCH "\","
564 "type=\"win32\",version=\"6.5.4.3\"",
565 TRUE
568 static const info_in_assembly depmanifest3_info = {
569 0x10, depmanifest_path,
570 "testdep,processorArchitecture=\"" ARCH "\",type=\"win32\",version=\"6.5.4.3\"",
571 TRUE
574 static const info_in_assembly manifest_comctrl_info = {
575 0, NULL, NULL, TRUE /* These values may differ between Windows installations */
578 static void test_info_in_assembly(HANDLE handle, DWORD id, const info_in_assembly *exinfo, int line)
580 ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION *info, info_tmp;
581 SIZE_T size, exsize;
582 ULONG len;
583 BOOL b;
585 exsize = sizeof(ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION);
586 if (exinfo->manifest_path) exsize += (lstrlenW(exinfo->manifest_path)+1) * sizeof(WCHAR);
587 if (exinfo->encoded_assembly_id) exsize += (strlen_aw(exinfo->encoded_assembly_id) + 1) * sizeof(WCHAR);
589 size = 0xdeadbeef;
590 b = pQueryActCtxW(0, handle, &id,
591 AssemblyDetailedInformationInActivationContext, &info_tmp,
592 sizeof(info_tmp), &size);
593 ok_(__FILE__, line)(!b, "QueryActCtx succeeded\n");
594 ok_(__FILE__, line)(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetLastError() = %u\n", GetLastError());
596 ok_(__FILE__, line)(size >= exsize, "size=%lu, expected %lu\n", size, exsize);
598 if (size == 0xdeadbeef)
600 skip("bad size\n");
601 return;
604 info = HeapAlloc(GetProcessHeap(), 0, size);
605 memset(info, 0xfe, size);
607 size = 0xdeadbeef;
608 b = pQueryActCtxW(0, handle, &id,
609 AssemblyDetailedInformationInActivationContext, info, size, &size);
610 ok_(__FILE__, line)(b, "QueryActCtx failed: %u\n", GetLastError());
611 if (!exinfo->manifest_path)
612 exsize += info->ulManifestPathLength + sizeof(WCHAR);
613 if (!exinfo->encoded_assembly_id)
614 exsize += info->ulEncodedAssemblyIdentityLength + sizeof(WCHAR);
615 if (exinfo->has_assembly_dir)
616 exsize += info->ulAssemblyDirectoryNameLength + sizeof(WCHAR);
617 ok_(__FILE__, line)(size == exsize, "size=%lu, expected %lu\n", size, exsize);
619 if (0) /* FIXME: flags meaning unknown */
621 ok_(__FILE__, line)((info->ulFlags) == exinfo->flags, "info->ulFlags = %x, expected %x\n",
622 info->ulFlags, exinfo->flags);
624 if(exinfo->encoded_assembly_id) {
625 len = strlen_aw(exinfo->encoded_assembly_id)*sizeof(WCHAR);
626 ok_(__FILE__, line)(info->ulEncodedAssemblyIdentityLength == len,
627 "info->ulEncodedAssemblyIdentityLength = %u, expected %u\n",
628 info->ulEncodedAssemblyIdentityLength, len);
629 } else {
630 ok_(__FILE__, line)(info->ulEncodedAssemblyIdentityLength != 0,
631 "info->ulEncodedAssemblyIdentityLength == 0\n");
633 ok_(__FILE__, line)(info->ulManifestPathType == ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE,
634 "info->ulManifestPathType = %x\n", info->ulManifestPathType);
635 if(exinfo->manifest_path) {
636 len = lstrlenW(exinfo->manifest_path)*sizeof(WCHAR);
637 ok_(__FILE__, line)(info->ulManifestPathLength == len, "info->ulManifestPathLength = %u, expected %u\n",
638 info->ulManifestPathLength, len);
639 } else {
640 ok_(__FILE__, line)(info->ulManifestPathLength != 0, "info->ulManifestPathLength == 0\n");
643 ok_(__FILE__, line)(info->ulPolicyPathType == ACTIVATION_CONTEXT_PATH_TYPE_NONE,
644 "info->ulPolicyPathType = %x\n", info->ulPolicyPathType);
645 ok_(__FILE__, line)(info->ulPolicyPathLength == 0,
646 "info->ulPolicyPathLength = %u, expected 0\n", info->ulPolicyPathLength);
647 ok_(__FILE__, line)(info->ulMetadataSatelliteRosterIndex == 0, "info->ulMetadataSatelliteRosterIndex = %x\n",
648 info->ulMetadataSatelliteRosterIndex);
649 ok_(__FILE__, line)(info->ulManifestVersionMajor == 1,"info->ulManifestVersionMajor = %x\n",
650 info->ulManifestVersionMajor);
651 ok_(__FILE__, line)(info->ulManifestVersionMinor == 0, "info->ulManifestVersionMinor = %x\n",
652 info->ulManifestVersionMinor);
653 ok_(__FILE__, line)(info->ulPolicyVersionMajor == 0, "info->ulPolicyVersionMajor = %x\n",
654 info->ulPolicyVersionMajor);
655 ok_(__FILE__, line)(info->ulPolicyVersionMinor == 0, "info->ulPolicyVersionMinor = %x\n",
656 info->ulPolicyVersionMinor);
657 if(exinfo->has_assembly_dir)
658 ok_(__FILE__, line)(info->ulAssemblyDirectoryNameLength != 0,
659 "info->ulAssemblyDirectoryNameLength == 0\n");
660 else
661 ok_(__FILE__, line)(info->ulAssemblyDirectoryNameLength == 0,
662 "info->ulAssemblyDirectoryNameLength != 0\n");
664 ok_(__FILE__, line)(info->lpAssemblyEncodedAssemblyIdentity != NULL,
665 "info->lpAssemblyEncodedAssemblyIdentity == NULL\n");
666 if(info->lpAssemblyEncodedAssemblyIdentity && exinfo->encoded_assembly_id) {
667 ok_(__FILE__, line)(!strcmp_aw(info->lpAssemblyEncodedAssemblyIdentity, exinfo->encoded_assembly_id),
668 "unexpected info->lpAssemblyEncodedAssemblyIdentity %s / %s\n",
669 strw(info->lpAssemblyEncodedAssemblyIdentity), exinfo->encoded_assembly_id);
671 if(exinfo->manifest_path) {
672 ok_(__FILE__, line)(info->lpAssemblyManifestPath != NULL, "info->lpAssemblyManifestPath == NULL\n");
673 if(info->lpAssemblyManifestPath)
674 ok_(__FILE__, line)(!lstrcmpiW(info->lpAssemblyManifestPath, exinfo->manifest_path),
675 "unexpected info->lpAssemblyManifestPath\n");
676 }else {
677 ok_(__FILE__, line)(info->lpAssemblyManifestPath != NULL, "info->lpAssemblyManifestPath == NULL\n");
680 ok_(__FILE__, line)(info->lpAssemblyPolicyPath == NULL, "info->lpAssemblyPolicyPath != NULL\n");
681 if(info->lpAssemblyPolicyPath)
682 ok_(__FILE__, line)(*(WORD*)info->lpAssemblyPolicyPath == 0, "info->lpAssemblyPolicyPath is not empty\n");
683 if(exinfo->has_assembly_dir)
684 ok_(__FILE__, line)(info->lpAssemblyDirectoryName != NULL, "info->lpAssemblyDirectoryName == NULL\n");
685 else
686 ok_(__FILE__, line)(info->lpAssemblyDirectoryName == NULL, "info->lpAssemblyDirectoryName = %s\n",
687 strw(info->lpAssemblyDirectoryName));
688 HeapFree(GetProcessHeap(), 0, info);
691 static void test_file_info(HANDLE handle, ULONG assid, ULONG fileid, LPCWSTR filename, int line)
693 ASSEMBLY_FILE_DETAILED_INFORMATION *info, info_tmp;
694 ACTIVATION_CONTEXT_QUERY_INDEX index = {assid, fileid};
695 SIZE_T size, exsize;
696 BOOL b;
698 exsize = sizeof(ASSEMBLY_FILE_DETAILED_INFORMATION)
699 +(lstrlenW(filename)+1)*sizeof(WCHAR);
701 size = 0xdeadbeef;
702 b = pQueryActCtxW(0, handle, &index,
703 FileInformationInAssemblyOfAssemblyInActivationContext, &info_tmp,
704 sizeof(info_tmp), &size);
705 ok_(__FILE__, line)(!b, "QueryActCtx succeeded\n");
706 ok_(__FILE__, line)(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetLastError() = %u\n", GetLastError());
707 ok_(__FILE__, line)(size == exsize, "size=%lu, expected %lu\n", size, exsize);
709 if(size == 0xdeadbeef)
711 skip("bad size\n");
712 return;
715 info = HeapAlloc(GetProcessHeap(), 0, size);
716 memset(info, 0xfe, size);
718 b = pQueryActCtxW(0, handle, &index,
719 FileInformationInAssemblyOfAssemblyInActivationContext, info, size, &size);
720 ok_(__FILE__, line)(b, "QueryActCtx failed: %u\n", GetLastError());
721 ok_(__FILE__, line)(!size, "size=%lu, expected 0\n", size);
723 ok_(__FILE__, line)(info->ulFlags == 2, "info->ulFlags=%x, expected 2\n", info->ulFlags);
724 ok_(__FILE__, line)(info->ulFilenameLength == lstrlenW(filename)*sizeof(WCHAR),
725 "info->ulFilenameLength=%u, expected %u*sizeof(WCHAR)\n",
726 info->ulFilenameLength, lstrlenW(filename));
727 ok_(__FILE__, line)(info->ulPathLength == 0, "info->ulPathLength=%u\n", info->ulPathLength);
728 ok_(__FILE__, line)(info->lpFileName != NULL, "info->lpFileName == NULL\n");
729 if(info->lpFileName)
730 ok_(__FILE__, line)(!lstrcmpiW(info->lpFileName, filename), "unexpected info->lpFileName\n");
731 ok_(__FILE__, line)(info->lpFilePath == NULL, "info->lpFilePath != NULL\n");
732 HeapFree(GetProcessHeap(), 0, info);
735 static HANDLE test_create(const char *file)
737 ACTCTXW actctx;
738 HANDLE handle;
739 WCHAR path[MAX_PATH];
741 MultiByteToWideChar( CP_ACP, 0, file, -1, path, MAX_PATH );
742 memset(&actctx, 0, sizeof(ACTCTXW));
743 actctx.cbSize = sizeof(ACTCTXW);
744 actctx.lpSource = path;
746 handle = pCreateActCtxW(&actctx);
747 /* to be tested outside of this helper, including last error */
748 if (handle == INVALID_HANDLE_VALUE) return handle;
750 ok(actctx.cbSize == sizeof(actctx), "actctx.cbSize=%d\n", actctx.cbSize);
751 ok(actctx.dwFlags == 0, "actctx.dwFlags=%d\n", actctx.dwFlags);
752 ok(actctx.lpSource == path, "actctx.lpSource=%p\n", actctx.lpSource);
753 ok(actctx.wProcessorArchitecture == 0,
754 "actctx.wProcessorArchitecture=%d\n", actctx.wProcessorArchitecture);
755 ok(actctx.wLangId == 0, "actctx.wLangId=%d\n", actctx.wLangId);
756 ok(actctx.lpAssemblyDirectory == NULL,
757 "actctx.lpAssemblyDirectory=%p\n", actctx.lpAssemblyDirectory);
758 ok(actctx.lpResourceName == NULL, "actctx.lpResourceName=%p\n", actctx.lpResourceName);
759 ok(actctx.lpApplicationName == NULL, "actctx.lpApplicationName=%p\n",
760 actctx.lpApplicationName);
761 ok(actctx.hModule == NULL, "actctx.hModule=%p\n", actctx.hModule);
763 return handle;
766 static void test_create_and_fail(const char *manifest, const char *depmanifest, int todo)
768 ACTCTXW actctx;
769 HANDLE handle;
770 WCHAR path[MAX_PATH];
772 MultiByteToWideChar( CP_ACP, 0, "bad.manifest", -1, path, MAX_PATH );
773 memset(&actctx, 0, sizeof(ACTCTXW));
774 actctx.cbSize = sizeof(ACTCTXW);
775 actctx.lpSource = path;
777 create_manifest_file("bad.manifest", manifest, -1, "testdep.manifest", depmanifest);
778 handle = pCreateActCtxW(&actctx);
779 todo_wine_if(todo)
781 ok(handle == INVALID_HANDLE_VALUE, "handle != INVALID_HANDLE_VALUE\n");
782 ok(GetLastError() == ERROR_SXS_CANT_GEN_ACTCTX, "GetLastError == %u\n", GetLastError());
784 if (handle != INVALID_HANDLE_VALUE) pReleaseActCtx( handle );
785 DeleteFileA("bad.manifest");
786 DeleteFileA("testdep.manifest");
789 static void test_create_wide_and_fail(const char *manifest, BOOL fBOM)
791 ACTCTXW actctx;
792 HANDLE handle;
793 WCHAR path[MAX_PATH];
795 MultiByteToWideChar( CP_ACP, 0, "bad.manifest", -1, path, MAX_PATH );
796 memset(&actctx, 0, sizeof(ACTCTXW));
797 actctx.cbSize = sizeof(ACTCTXW);
798 actctx.lpSource = path;
800 create_wide_manifest("bad.manifest", manifest, fBOM, FALSE);
801 handle = pCreateActCtxW(&actctx);
802 ok(handle == INVALID_HANDLE_VALUE, "handle != INVALID_HANDLE_VALUE\n");
803 ok(GetLastError() == ERROR_SXS_CANT_GEN_ACTCTX, "GetLastError == %u\n", GetLastError());
805 if (handle != INVALID_HANDLE_VALUE) pReleaseActCtx( handle );
806 DeleteFileA("bad.manifest");
809 static void test_create_fail(void)
811 ACTCTXW actctx;
812 HANDLE handle;
813 WCHAR path[MAX_PATH];
815 MultiByteToWideChar( CP_ACP, 0, "nonexistent.manifest", -1, path, MAX_PATH );
816 memset(&actctx, 0, sizeof(ACTCTXW));
817 actctx.cbSize = sizeof(ACTCTXW);
818 actctx.lpSource = path;
820 handle = pCreateActCtxW(&actctx);
821 ok(handle == INVALID_HANDLE_VALUE, "handle != INVALID_HANDLE_VALUE\n");
822 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "GetLastError == %u\n", GetLastError());
824 trace("wrong_manifest1\n");
825 test_create_and_fail(wrong_manifest1, NULL, 0 );
826 trace("wrong_manifest2\n");
827 test_create_and_fail(wrong_manifest2, NULL, 0 );
828 trace("wrong_manifest3\n");
829 test_create_and_fail(wrong_manifest3, NULL, 1 );
830 trace("wrong_manifest4\n");
831 test_create_and_fail(wrong_manifest4, NULL, 1 );
832 trace("wrong_manifest5\n");
833 test_create_and_fail(wrong_manifest5, NULL, 0 );
834 trace("wrong_manifest6\n");
835 test_create_and_fail(wrong_manifest6, NULL, 0 );
836 trace("wrong_manifest7\n");
837 test_create_and_fail(wrong_manifest7, NULL, 1 );
838 trace("wrong_manifest8\n");
839 test_create_and_fail(wrong_manifest8, NULL, 0 );
840 trace("UTF-16 manifest1 without BOM\n");
841 test_create_wide_and_fail(manifest1, FALSE );
842 trace("manifest2\n");
843 test_create_and_fail(manifest2, NULL, 0 );
844 trace("manifest2+depmanifest1\n");
845 test_create_and_fail(manifest2, wrong_depmanifest1, 0 );
848 struct strsection_header
850 DWORD magic;
851 ULONG size;
852 DWORD unk1[3];
853 ULONG count;
854 ULONG index_offset;
855 DWORD unk2[2];
856 ULONG global_offset;
857 ULONG global_len;
860 struct string_index
862 ULONG hash;
863 ULONG name_offset;
864 ULONG name_len;
865 ULONG data_offset;
866 ULONG data_len;
867 ULONG rosterindex;
870 struct guidsection_header
872 DWORD magic;
873 ULONG size;
874 DWORD unk[3];
875 ULONG count;
876 ULONG index_offset;
877 DWORD unk2;
878 ULONG names_offset;
879 ULONG names_len;
882 struct guid_index
884 GUID guid;
885 ULONG data_offset;
886 ULONG data_len;
887 ULONG rosterindex;
890 struct wndclass_redirect_data
892 ULONG size;
893 DWORD res;
894 ULONG name_len;
895 ULONG name_offset; /* versioned name offset */
896 ULONG module_len;
897 ULONG module_offset;/* container name offset */
900 struct dllredirect_data
902 ULONG size;
903 ULONG unk;
904 DWORD res[3];
907 struct tlibredirect_data
909 ULONG size;
910 DWORD res;
911 ULONG name_len;
912 ULONG name_offset;
913 LANGID langid;
914 WORD flags;
915 ULONG help_len;
916 ULONG help_offset;
917 WORD major_version;
918 WORD minor_version;
921 struct progidredirect_data
923 ULONG size;
924 DWORD reserved;
925 ULONG clsid_offset;
928 static void test_find_dll_redirection(HANDLE handle, LPCWSTR libname, ULONG exid, int line)
930 ACTCTX_SECTION_KEYED_DATA data;
931 BOOL ret;
933 memset(&data, 0xfe, sizeof(data));
934 data.cbSize = sizeof(data);
936 ret = pFindActCtxSectionStringW(0, NULL,
937 ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
938 libname, &data);
939 ok_(__FILE__, line)(ret, "FindActCtxSectionStringW failed: %u\n", GetLastError());
940 if (!ret) return;
942 ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
943 ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
944 ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
945 ok_(__FILE__, line)(data.ulLength == 20, "data.ulLength=%u\n", data.ulLength);
947 if (data.lpData)
949 struct dllredirect_data *dlldata = (struct dllredirect_data*)data.lpData;
950 ok_(__FILE__, line)(dlldata->size == data.ulLength, "got wrong size %d\n", dlldata->size);
951 ok_(__FILE__, line)(dlldata->unk == 2, "got wrong field value %d\n", dlldata->unk);
952 ok_(__FILE__, line)(dlldata->res[0] == 0, "got wrong res[0] value %d\n", dlldata->res[0]);
953 ok_(__FILE__, line)(dlldata->res[1] == 0, "got wrong res[1] value %d\n", dlldata->res[1]);
954 ok_(__FILE__, line)(dlldata->res[2] == 0, "got wrong res[2] value %d\n", dlldata->res[2]);
957 ok_(__FILE__, line)(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
958 ok_(__FILE__, line)(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%u\n",
959 data.ulSectionGlobalDataLength);
960 ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
961 ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%u\n",
962 data.ulSectionTotalLength);
963 ok_(__FILE__, line)(data.hActCtx == NULL, "data.hActCtx=%p\n", data.hActCtx);
964 ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
965 data.ulAssemblyRosterIndex, exid);
967 memset(&data, 0xfe, sizeof(data));
968 data.cbSize = sizeof(data);
970 ret = pFindActCtxSectionStringW(FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX, NULL,
971 ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
972 libname, &data);
973 ok_(__FILE__, line)(ret, "FindActCtxSectionStringW failed: %u\n", GetLastError());
974 if (!ret) return;
976 ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
977 ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
978 ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
979 ok_(__FILE__, line)(data.ulLength == 20, "data.ulLength=%u\n", data.ulLength);
980 ok_(__FILE__, line)(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
981 ok_(__FILE__, line)(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%u\n",
982 data.ulSectionGlobalDataLength);
983 ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
984 ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%u\n",
985 data.ulSectionTotalLength);
986 ok_(__FILE__, line)(data.hActCtx == handle, "data.hActCtx=%p\n", data.hActCtx);
987 ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
988 data.ulAssemblyRosterIndex, exid);
990 pReleaseActCtx(handle);
993 static void test_find_window_class(HANDLE handle, LPCWSTR clsname, ULONG exid, int line)
995 struct wndclass_redirect_data *wnddata;
996 struct strsection_header *header;
997 ACTCTX_SECTION_KEYED_DATA data;
998 BOOL ret;
1000 memset(&data, 0xfe, sizeof(data));
1001 data.cbSize = sizeof(data);
1003 ret = pFindActCtxSectionStringW(0, NULL,
1004 ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION,
1005 clsname, &data);
1006 ok_(__FILE__, line)(ret, "FindActCtxSectionStringW failed: %u, class %s\n", GetLastError(),
1007 wine_dbgstr_w(clsname));
1008 if (!ret) return;
1010 header = (struct strsection_header*)data.lpSectionBase;
1011 wnddata = (struct wndclass_redirect_data*)data.lpData;
1013 ok_(__FILE__, line)(header->magic == 0x64487353, "got wrong magic 0x%08x\n", header->magic);
1014 ok_(__FILE__, line)(header->count > 0, "got count %d\n", header->count);
1015 ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
1016 ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
1017 ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
1018 ok_(__FILE__, line)(wnddata->size == sizeof(*wnddata), "got %d for header size\n", wnddata->size);
1019 if (data.lpData && wnddata->size == sizeof(*wnddata))
1021 static const WCHAR verW[] = {'6','.','5','.','4','.','3','!',0};
1022 WCHAR buff[50];
1023 WCHAR *ptr;
1024 ULONG len;
1026 ok_(__FILE__, line)(wnddata->res == 0, "got reserved as %d\n", wnddata->res);
1027 /* redirect class name (versioned or not) is stored just after header data */
1028 ok_(__FILE__, line)(wnddata->name_offset == wnddata->size, "got name offset as %d\n", wnddata->name_offset);
1029 ok_(__FILE__, line)(wnddata->module_len > 0, "got module name length as %d\n", wnddata->module_len);
1031 /* expected versioned name */
1032 lstrcpyW(buff, verW);
1033 lstrcatW(buff, clsname);
1034 ptr = (WCHAR*)((BYTE*)wnddata + wnddata->name_offset);
1035 ok_(__FILE__, line)(!lstrcmpW(ptr, buff), "got wrong class name %s, expected %s\n", wine_dbgstr_w(ptr), wine_dbgstr_w(buff));
1036 ok_(__FILE__, line)(lstrlenW(ptr)*sizeof(WCHAR) == wnddata->name_len,
1037 "got wrong class name length %d, expected %d\n", wnddata->name_len, lstrlenW(ptr));
1039 /* data length is simply header length + string data length including nulls */
1040 len = wnddata->size + wnddata->name_len + wnddata->module_len + 2*sizeof(WCHAR);
1041 ok_(__FILE__, line)(data.ulLength == len, "got wrong data length %d, expected %d\n", data.ulLength, len);
1043 if (data.ulSectionTotalLength > wnddata->module_offset)
1045 WCHAR *modulename, *sectionptr;
1047 /* just compare pointers */
1048 modulename = (WCHAR*)((BYTE*)wnddata + wnddata->size + wnddata->name_len + sizeof(WCHAR));
1049 sectionptr = (WCHAR*)((BYTE*)data.lpSectionBase + wnddata->module_offset);
1050 ok_(__FILE__, line)(modulename == sectionptr, "got wrong name offset %p, expected %p\n", sectionptr, modulename);
1054 ok_(__FILE__, line)(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
1055 ok_(__FILE__, line)(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%u\n",
1056 data.ulSectionGlobalDataLength);
1057 ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
1058 ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%u\n",
1059 data.ulSectionTotalLength);
1060 ok_(__FILE__, line)(data.hActCtx == NULL, "data.hActCtx=%p\n", data.hActCtx);
1061 ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
1062 data.ulAssemblyRosterIndex, exid);
1064 memset(&data, 0xfe, sizeof(data));
1065 data.cbSize = sizeof(data);
1067 ret = pFindActCtxSectionStringW(FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX, NULL,
1068 ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION,
1069 clsname, &data);
1070 ok_(__FILE__, line)(ret, "FindActCtxSectionStringW failed: %u, class %s\n", GetLastError(),
1071 wine_dbgstr_w(clsname));
1072 if (!ret) return;
1074 ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
1075 ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
1076 ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
1077 ok_(__FILE__, line)(data.ulLength > 0, "data.ulLength=%u\n", data.ulLength);
1078 ok_(__FILE__, line)(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
1079 ok_(__FILE__, line)(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%u\n",
1080 data.ulSectionGlobalDataLength);
1081 ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
1082 ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%u\n", data.ulSectionTotalLength);
1083 ok_(__FILE__, line)(data.hActCtx == handle, "data.hActCtx=%p\n", data.hActCtx);
1084 ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
1085 data.ulAssemblyRosterIndex, exid);
1087 pReleaseActCtx(handle);
1090 static void test_find_string_fail(void)
1092 ACTCTX_SECTION_KEYED_DATA data = {sizeof(data)};
1093 BOOL ret;
1095 ret = pFindActCtxSectionStringW(0, NULL, 100, testlib_dll, &data);
1096 ok(!ret, "FindActCtxSectionStringW succeeded\n");
1097 ok(GetLastError() == ERROR_SXS_SECTION_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
1099 ret = pFindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
1100 testlib2_dll, &data);
1101 ok(!ret, "FindActCtxSectionStringW succeeded\n");
1102 ok(GetLastError() == ERROR_SXS_KEY_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
1104 ret = pFindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
1105 testlib_dll, NULL);
1106 ok(!ret, "FindActCtxSectionStringW succeeded\n");
1107 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError()=%u\n", GetLastError());
1109 ret = pFindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
1110 NULL, &data);
1111 ok(!ret, "FindActCtxSectionStringW succeeded\n");
1112 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError()=%u\n", GetLastError());
1114 data.cbSize = 0;
1115 ret = pFindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
1116 testlib_dll, &data);
1117 ok(!ret, "FindActCtxSectionStringW succeeded\n");
1118 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError()=%u\n", GetLastError());
1120 data.cbSize = 35;
1121 ret = pFindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
1122 testlib_dll, &data);
1123 ok(!ret, "FindActCtxSectionStringW succeeded\n");
1124 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError()=%u\n", GetLastError());
1128 static void test_basic_info(HANDLE handle, int line)
1130 ACTIVATION_CONTEXT_BASIC_INFORMATION basic;
1131 SIZE_T size;
1132 BOOL b;
1134 b = pQueryActCtxW(QUERY_ACTCTX_FLAG_NO_ADDREF, handle, NULL,
1135 ActivationContextBasicInformation, &basic,
1136 sizeof(basic), &size);
1138 ok_(__FILE__, line) (b,"ActivationContextBasicInformation failed\n");
1139 ok_(__FILE__, line) (size == sizeof(ACTIVATION_CONTEXT_BASIC_INFORMATION),"size mismatch\n");
1140 ok_(__FILE__, line) (basic.dwFlags == 0, "unexpected flags %x\n",basic.dwFlags);
1141 ok_(__FILE__, line) (basic.hActCtx == handle, "unexpected handle\n");
1143 b = pQueryActCtxW(QUERY_ACTCTX_FLAG_USE_ACTIVE_ACTCTX |
1144 QUERY_ACTCTX_FLAG_NO_ADDREF, handle, NULL,
1145 ActivationContextBasicInformation, &basic,
1146 sizeof(basic), &size);
1147 if (handle)
1149 ok_(__FILE__, line) (!b,"ActivationContextBasicInformation succeeded\n");
1150 ok_(__FILE__, line) (size == 0,"size mismatch\n");
1151 ok_(__FILE__, line) (GetLastError() == ERROR_INVALID_PARAMETER, "Wrong last error\n");
1152 ok_(__FILE__, line) (basic.dwFlags == 0, "unexpected flags %x\n",basic.dwFlags);
1153 ok_(__FILE__, line) (basic.hActCtx == handle, "unexpected handle\n");
1155 else
1157 ok_(__FILE__, line) (b,"ActivationContextBasicInformation failed\n");
1158 ok_(__FILE__, line) (size == sizeof(ACTIVATION_CONTEXT_BASIC_INFORMATION),"size mismatch\n");
1159 ok_(__FILE__, line) (basic.dwFlags == 0, "unexpected flags %x\n",basic.dwFlags);
1160 ok_(__FILE__, line) (basic.hActCtx == handle, "unexpected handle\n");
1164 enum comclass_threadingmodel {
1165 ThreadingModel_Apartment = 1,
1166 ThreadingModel_Free = 2,
1167 ThreadingModel_No = 3,
1168 ThreadingModel_Both = 4,
1169 ThreadingModel_Neutral = 5
1172 enum comclass_miscfields {
1173 MiscStatus = 1,
1174 MiscStatusIcon = 2,
1175 MiscStatusContent = 4,
1176 MiscStatusThumbnail = 8,
1177 MiscStatusDocPrint = 16
1180 struct comclassredirect_data {
1181 ULONG size;
1182 BYTE res;
1183 BYTE miscmask;
1184 BYTE res1[2];
1185 DWORD model;
1186 GUID clsid;
1187 GUID alias;
1188 GUID clsid2;
1189 GUID tlid;
1190 ULONG name_len;
1191 ULONG name_offset;
1192 ULONG progid_len;
1193 ULONG progid_offset;
1194 ULONG clrdata_len;
1195 ULONG clrdata_offset;
1196 DWORD miscstatus;
1197 DWORD miscstatuscontent;
1198 DWORD miscstatusthumbnail;
1199 DWORD miscstatusicon;
1200 DWORD miscstatusdocprint;
1203 struct clrclass_data {
1204 ULONG size;
1205 DWORD res[2];
1206 ULONG module_len;
1207 ULONG module_offset;
1208 ULONG name_len;
1209 ULONG name_offset;
1210 ULONG version_len;
1211 ULONG version_offset;
1212 DWORD res2[2];
1215 static void test_find_com_redirection(HANDLE handle, const GUID *clsid, const GUID *tlid, const WCHAR *progid, ULONG exid, int line)
1217 struct comclassredirect_data *comclass, *comclass2;
1218 ACTCTX_SECTION_KEYED_DATA data, data2;
1219 struct guidsection_header *header;
1220 BOOL ret;
1222 memset(&data, 0xfe, sizeof(data));
1223 data.cbSize = sizeof(data);
1225 ret = pFindActCtxSectionGuid(0, NULL,
1226 ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION,
1227 clsid, &data);
1228 if (!ret)
1230 skip("failed for guid %s\n", wine_dbgstr_guid(clsid));
1231 return;
1233 ok_(__FILE__, line)(ret, "FindActCtxSectionGuid failed: %u\n", GetLastError());
1235 comclass = (struct comclassredirect_data*)data.lpData;
1237 ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
1238 ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
1239 ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
1240 ok_(__FILE__, line)(comclass->size == sizeof(*comclass), "got %d for header size\n", comclass->size);
1241 if (data.lpData && comclass->size == sizeof(*comclass))
1243 WCHAR *ptr;
1244 ULONG len;
1246 ok_(__FILE__, line)(comclass->res == 0, "got res as %d\n", comclass->res);
1247 ok_(__FILE__, line)(comclass->res1[0] == 0, "got res1[0] as %02x\n", comclass->res1[0]);
1248 ok_(__FILE__, line)(comclass->res1[1] == 0, "got res1[1] as %02x\n", comclass->res1[1]);
1249 ok_(__FILE__, line)(comclass->model == ThreadingModel_Neutral, "got model %d\n", comclass->model);
1250 ok_(__FILE__, line)(IsEqualGUID(&comclass->clsid, clsid), "got wrong clsid %s\n", wine_dbgstr_guid(&comclass->clsid));
1251 ok_(__FILE__, line)(IsEqualGUID(&comclass->clsid2, clsid), "got wrong clsid2 %s\n", wine_dbgstr_guid(&comclass->clsid2));
1252 if (tlid)
1253 ok_(__FILE__, line)(IsEqualGUID(&comclass->tlid, tlid), "got wrong tlid %s\n", wine_dbgstr_guid(&comclass->tlid));
1254 ok_(__FILE__, line)(comclass->name_len > 0, "got modulename len %d\n", comclass->name_len);
1256 if (progid)
1258 len = comclass->size + comclass->clrdata_len;
1259 ok_(__FILE__, line)(comclass->progid_offset == len, "got progid offset %d, expected %d\n", comclass->progid_offset, len);
1261 else
1262 ok_(__FILE__, line)(comclass->progid_offset == 0, "got progid offset %d, expected 0\n", comclass->progid_offset);
1264 if (comclass->progid_offset)
1266 ptr = (WCHAR*)((BYTE*)comclass + comclass->progid_offset);
1267 ok_(__FILE__, line)(!lstrcmpW(ptr, progid), "got wrong progid %s, expected %s\n", wine_dbgstr_w(ptr), wine_dbgstr_w(progid));
1268 ok_(__FILE__, line)(lstrlenW(progid)*sizeof(WCHAR) == comclass->progid_len,
1269 "got progid name length %d\n", comclass->progid_len);
1272 /* data length is simply header length + string data length including nulls */
1273 len = comclass->size + comclass->clrdata_len;
1274 if (comclass->progid_len) len += comclass->progid_len + sizeof(WCHAR);
1275 ok_(__FILE__, line)(data.ulLength == len, "got wrong data length %d, expected %d\n", data.ulLength, len);
1277 /* keyed data structure doesn't include module name, it's available from section data */
1278 ok_(__FILE__, line)(data.ulSectionTotalLength > comclass->name_offset, "got wrong offset %d\n", comclass->name_offset);
1280 /* check misc fields are set */
1281 if (comclass->miscmask)
1283 if (comclass->miscmask & MiscStatus)
1284 ok_(__FILE__, line)(comclass->miscstatus != 0, "got miscstatus 0x%08x\n", comclass->miscstatus);
1285 if (comclass->miscmask & MiscStatusIcon)
1286 ok_(__FILE__, line)(comclass->miscstatusicon != 0, "got miscstatusicon 0x%08x\n", comclass->miscstatusicon);
1287 if (comclass->miscmask & MiscStatusContent)
1288 ok_(__FILE__, line)(comclass->miscstatuscontent != 0, "got miscstatuscontent 0x%08x\n", comclass->miscstatuscontent);
1289 if (comclass->miscmask & MiscStatusThumbnail)
1290 ok_(__FILE__, line)(comclass->miscstatusthumbnail != 0, "got miscstatusthumbnail 0x%08x\n", comclass->miscstatusthumbnail);
1291 if (comclass->miscmask & MiscStatusDocPrint)
1292 ok_(__FILE__, line)(comclass->miscstatusdocprint != 0, "got miscstatusdocprint 0x%08x\n", comclass->miscstatusdocprint);
1295 /* part used for clrClass only */
1296 if (comclass->clrdata_len)
1298 static const WCHAR mscoreeW[] = {'M','S','C','O','R','E','E','.','D','L','L',0};
1299 static const WCHAR mscoree2W[] = {'m','s','c','o','r','e','e','.','d','l','l',0};
1300 struct clrclass_data *clrclass;
1301 WCHAR *ptrW;
1303 clrclass = (struct clrclass_data*)((BYTE*)data.lpData + comclass->clrdata_offset);
1304 ok_(__FILE__, line)(clrclass->size == sizeof(*clrclass), "clrclass: got size %d\n", clrclass->size);
1305 ok_(__FILE__, line)(clrclass->res[0] == 0, "clrclass: got res[0]=0x%08x\n", clrclass->res[0]);
1306 ok_(__FILE__, line)(clrclass->res[1] == 2, "clrclass: got res[1]=0x%08x\n", clrclass->res[1]);
1307 ok_(__FILE__, line)(clrclass->module_len == lstrlenW(mscoreeW)*sizeof(WCHAR), "clrclass: got module len %d\n", clrclass->module_len);
1308 ok_(__FILE__, line)(clrclass->module_offset > 0, "clrclass: got module offset %d\n", clrclass->module_offset);
1310 ok_(__FILE__, line)(clrclass->name_len > 0, "clrclass: got name len %d\n", clrclass->name_len);
1311 ok_(__FILE__, line)(clrclass->name_offset == clrclass->size, "clrclass: got name offset %d\n", clrclass->name_offset);
1312 ok_(__FILE__, line)(clrclass->version_len > 0, "clrclass: got version len %d\n", clrclass->version_len);
1313 ok_(__FILE__, line)(clrclass->version_offset > 0, "clrclass: got version offset %d\n", clrclass->version_offset);
1315 ok_(__FILE__, line)(clrclass->res2[0] == 0, "clrclass: got res2[0]=0x%08x\n", clrclass->res2[0]);
1316 ok_(__FILE__, line)(clrclass->res2[1] == 0, "clrclass: got res2[1]=0x%08x\n", clrclass->res2[1]);
1318 /* clrClass uses mscoree.dll as module name, but in two variants - comclass data points to module name
1319 in lower case, clsclass subsection - in upper case */
1320 ok_(__FILE__, line)(comclass->name_len == lstrlenW(mscoree2W)*sizeof(WCHAR), "clrclass: got com name len %d\n", comclass->name_len);
1321 ok_(__FILE__, line)(comclass->name_offset > 0, "clrclass: got name offset %d\n", clrclass->name_offset);
1323 ptrW = (WCHAR*)((BYTE*)data.lpSectionBase + comclass->name_offset);
1324 ok_(__FILE__, line)(!lstrcmpW(ptrW, mscoreeW), "clrclass: module name %s\n", wine_dbgstr_w(ptrW));
1326 ptrW = (WCHAR*)((BYTE*)data.lpSectionBase + clrclass->module_offset);
1327 ok_(__FILE__, line)(!lstrcmpW(ptrW, mscoree2W), "clrclass: module name2 %s\n", wine_dbgstr_w(ptrW));
1331 header = (struct guidsection_header*)data.lpSectionBase;
1332 ok_(__FILE__, line)(data.lpSectionGlobalData == ((BYTE*)header + header->names_offset), "data.lpSectionGlobalData == NULL\n");
1333 ok_(__FILE__, line)(data.ulSectionGlobalDataLength == header->names_len, "data.ulSectionGlobalDataLength=%u\n",
1334 data.ulSectionGlobalDataLength);
1335 ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
1336 ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%u\n",
1337 data.ulSectionTotalLength);
1338 ok_(__FILE__, line)(data.hActCtx == NULL, "data.hActCtx=%p\n", data.hActCtx);
1339 ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
1340 data.ulAssemblyRosterIndex, exid);
1342 /* generated guid for this class works as key guid in search */
1343 memset(&data2, 0xfe, sizeof(data2));
1344 data2.cbSize = sizeof(data2);
1345 ret = pFindActCtxSectionGuid(0, NULL,
1346 ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION,
1347 &comclass->alias, &data2);
1348 ok_(__FILE__, line)(ret, "FindActCtxSectionGuid failed: %u\n", GetLastError());
1350 comclass2 = (struct comclassredirect_data*)data2.lpData;
1351 ok_(__FILE__, line)(comclass->size == comclass2->size, "got wrong data length %d, expected %d\n", comclass2->size, comclass->size);
1352 ok_(__FILE__, line)(!memcmp(comclass, comclass2, comclass->size), "got wrong data\n");
1355 enum ifaceps_mask
1357 NumMethods = 1,
1358 BaseIface = 2
1361 struct ifacepsredirect_data
1363 ULONG size;
1364 DWORD mask;
1365 GUID iid;
1366 ULONG nummethods;
1367 GUID tlbid;
1368 GUID base;
1369 ULONG name_len;
1370 ULONG name_offset;
1373 static void test_find_ifaceps_redirection(HANDLE handle, const GUID *iid, const GUID *tlbid, const GUID *base,
1374 const GUID *ps32, ULONG exid, int line)
1376 struct ifacepsredirect_data *ifaceps;
1377 ACTCTX_SECTION_KEYED_DATA data;
1378 BOOL ret;
1380 memset(&data, 0xfe, sizeof(data));
1381 data.cbSize = sizeof(data);
1383 ret = pFindActCtxSectionGuid(0, NULL,
1384 ACTIVATION_CONTEXT_SECTION_COM_INTERFACE_REDIRECTION,
1385 iid, &data);
1386 ok_(__FILE__, line)(ret, "FindActCtxSectionGuid failed: %u\n", GetLastError());
1388 ifaceps = (struct ifacepsredirect_data*)data.lpData;
1390 ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
1391 ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
1392 ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
1393 ok_(__FILE__, line)(ifaceps->size == sizeof(*ifaceps), "got %d for header size\n", ifaceps->size);
1394 if (data.lpData && ifaceps->size == sizeof(*ifaceps))
1396 ULONG len;
1398 /* for external proxy stubs it contains a value from 'proxyStubClsid32' */
1399 if (ps32)
1401 ok_(__FILE__, line)(IsEqualGUID(&ifaceps->iid, ps32), "got wrong iid %s\n", wine_dbgstr_guid(&ifaceps->iid));
1403 else
1404 ok_(__FILE__, line)(IsEqualGUID(&ifaceps->iid, iid), "got wrong iid %s\n", wine_dbgstr_guid(&ifaceps->iid));
1406 ok_(__FILE__, line)(IsEqualGUID(&ifaceps->tlbid, tlbid), "got wrong tlid %s\n", wine_dbgstr_guid(&ifaceps->tlbid));
1407 ok_(__FILE__, line)(ifaceps->name_len > 0, "got modulename len %d\n", ifaceps->name_len);
1408 ok_(__FILE__, line)(ifaceps->name_offset == ifaceps->size, "got progid offset %d\n", ifaceps->name_offset);
1410 /* data length is simply header length + string data length including nulls */
1411 len = ifaceps->size + ifaceps->name_len + sizeof(WCHAR);
1412 ok_(__FILE__, line)(data.ulLength == len, "got wrong data length %d, expected %d\n", data.ulLength, len);
1414 /* mask purpose is to indicate if attribute was specified, for testing purposes assume that manifest
1415 always has non-zero value for it */
1416 if (ifaceps->mask & NumMethods)
1417 ok_(__FILE__, line)(ifaceps->nummethods != 0, "got nummethods %d\n", ifaceps->nummethods);
1418 if (ifaceps->mask & BaseIface)
1419 ok_(__FILE__, line)(IsEqualGUID(&ifaceps->base, base), "got base %s\n", wine_dbgstr_guid(&ifaceps->base));
1422 ok_(__FILE__, line)(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
1423 ok_(__FILE__, line)(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%u\n",
1424 data.ulSectionGlobalDataLength);
1425 ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
1426 ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%u\n",
1427 data.ulSectionTotalLength);
1428 ok_(__FILE__, line)(data.hActCtx == NULL, "data.hActCtx=%p\n", data.hActCtx);
1429 ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
1430 data.ulAssemblyRosterIndex, exid);
1433 struct clrsurrogate_data
1435 ULONG size;
1436 DWORD res;
1437 GUID clsid;
1438 ULONG version_offset;
1439 ULONG version_len;
1440 ULONG name_offset;
1441 ULONG name_len;
1444 static void test_find_surrogate(HANDLE handle, const GUID *clsid, const WCHAR *name, const WCHAR *version,
1445 ULONG exid, int line)
1447 struct clrsurrogate_data *surrogate;
1448 ACTCTX_SECTION_KEYED_DATA data;
1449 BOOL ret;
1451 memset(&data, 0xfe, sizeof(data));
1452 data.cbSize = sizeof(data);
1454 ret = pFindActCtxSectionGuid(0, NULL,
1455 ACTIVATION_CONTEXT_SECTION_CLR_SURROGATES,
1456 clsid, &data);
1457 if (!ret)
1459 skip("surrogate sections are not supported\n");
1460 return;
1462 ok_(__FILE__, line)(ret, "FindActCtxSectionGuid failed: %u\n", GetLastError());
1464 surrogate = (struct clrsurrogate_data*)data.lpData;
1466 ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
1467 ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
1468 ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
1469 ok_(__FILE__, line)(surrogate->size == sizeof(*surrogate), "got %d for header size\n", surrogate->size);
1470 if (data.lpData && surrogate->size == sizeof(*surrogate))
1472 WCHAR *ptrW;
1473 ULONG len;
1475 ok_(__FILE__, line)(surrogate->res == 0, "invalid res value %d\n", surrogate->res);
1476 ok_(__FILE__, line)(IsEqualGUID(&surrogate->clsid, clsid), "got wrong clsid %s\n", wine_dbgstr_guid(&surrogate->clsid));
1478 ok_(__FILE__, line)(surrogate->version_len == lstrlenW(version)*sizeof(WCHAR), "got version len %d\n", surrogate->version_len);
1479 ok_(__FILE__, line)(surrogate->version_offset == surrogate->size, "got version offset %d\n", surrogate->version_offset);
1481 ok_(__FILE__, line)(surrogate->name_len == lstrlenW(name)*sizeof(WCHAR), "got name len %d\n", surrogate->name_len);
1482 ok_(__FILE__, line)(surrogate->name_offset > surrogate->version_offset, "got name offset %d\n", surrogate->name_offset);
1484 len = surrogate->size + surrogate->name_len + surrogate->version_len + 2*sizeof(WCHAR);
1485 ok_(__FILE__, line)(data.ulLength == len, "got wrong data length %d, expected %d\n", data.ulLength, len);
1487 ptrW = (WCHAR*)((BYTE*)surrogate + surrogate->name_offset);
1488 ok(!lstrcmpW(ptrW, name), "got wrong name %s\n", wine_dbgstr_w(ptrW));
1490 ptrW = (WCHAR*)((BYTE*)surrogate + surrogate->version_offset);
1491 ok(!lstrcmpW(ptrW, version), "got wrong name %s\n", wine_dbgstr_w(ptrW));
1494 ok_(__FILE__, line)(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
1495 ok_(__FILE__, line)(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%u\n",
1496 data.ulSectionGlobalDataLength);
1497 ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
1498 ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%u\n",
1499 data.ulSectionTotalLength);
1500 ok_(__FILE__, line)(data.hActCtx == NULL, "data.hActCtx=%p\n", data.hActCtx);
1501 ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
1502 data.ulAssemblyRosterIndex, exid);
1505 static void test_find_progid_redirection(HANDLE handle, const GUID *clsid, const char *progid, ULONG exid, int line)
1507 struct progidredirect_data *progiddata;
1508 struct comclassredirect_data *comclass;
1509 ACTCTX_SECTION_KEYED_DATA data, data2;
1510 struct strsection_header *header;
1511 BOOL ret;
1513 memset(&data, 0xfe, sizeof(data));
1514 data.cbSize = sizeof(data);
1516 ret = pFindActCtxSectionStringA(0, NULL,
1517 ACTIVATION_CONTEXT_SECTION_COM_PROGID_REDIRECTION,
1518 progid, &data);
1519 ok_(__FILE__, line)(ret, "FindActCtxSectionStringA failed: %u\n", GetLastError());
1521 progiddata = (struct progidredirect_data*)data.lpData;
1523 ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
1524 ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
1525 ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
1526 ok_(__FILE__, line)(progiddata->size == sizeof(*progiddata), "got %d for header size\n", progiddata->size);
1527 if (data.lpData && progiddata->size == sizeof(*progiddata))
1529 GUID *guid;
1531 ok_(__FILE__, line)(progiddata->reserved == 0, "got reserved as %d\n", progiddata->reserved);
1532 ok_(__FILE__, line)(progiddata->clsid_offset > 0, "got clsid_offset as %d\n", progiddata->clsid_offset);
1534 /* progid data points to generated alias guid */
1535 guid = (GUID*)((BYTE*)data.lpSectionBase + progiddata->clsid_offset);
1537 memset(&data2, 0, sizeof(data2));
1538 data2.cbSize = sizeof(data2);
1539 ret = pFindActCtxSectionGuid(0, NULL,
1540 ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION,
1541 guid, &data2);
1542 ok_(__FILE__, line)(ret, "FindActCtxSectionGuid failed: %u\n", GetLastError());
1544 comclass = (struct comclassredirect_data*)data2.lpData;
1545 ok_(__FILE__, line)(IsEqualGUID(guid, &comclass->alias), "got wrong alias referenced from progid %s, %s\n", progid, wine_dbgstr_guid(guid));
1546 ok_(__FILE__, line)(IsEqualGUID(clsid, &comclass->clsid), "got wrong class referenced from progid %s, %s\n", progid, wine_dbgstr_guid(clsid));
1549 header = (struct strsection_header*)data.lpSectionBase;
1550 ok_(__FILE__, line)(data.lpSectionGlobalData == (BYTE*)header + header->global_offset, "data.lpSectionGlobalData == NULL\n");
1551 ok_(__FILE__, line)(data.ulSectionGlobalDataLength == header->global_len, "data.ulSectionGlobalDataLength=%u\n", data.ulSectionGlobalDataLength);
1552 ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
1553 ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%u\n", data.ulSectionTotalLength);
1554 ok_(__FILE__, line)(data.hActCtx == NULL, "data.hActCtx=%p\n", data.hActCtx);
1555 ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
1556 data.ulAssemblyRosterIndex, exid);
1559 static void test_wndclass_section(void)
1561 static const WCHAR cls1W[] = {'1','.','2','.','3','.','4','!','w','n','d','C','l','a','s','s','1',0};
1562 ACTCTX_SECTION_KEYED_DATA data, data2;
1563 struct wndclass_redirect_data *classdata;
1564 struct strsection_header *section;
1565 ULONG_PTR cookie;
1566 HANDLE handle;
1567 WCHAR *ptrW;
1568 BOOL ret;
1570 /* use two dependent manifests, each defines 2 window class redirects */
1571 create_manifest_file("testdep1.manifest", manifest_wndcls1, -1, NULL, NULL);
1572 create_manifest_file("testdep2.manifest", manifest_wndcls2, -1, NULL, NULL);
1573 create_manifest_file("main_wndcls.manifest", manifest_wndcls_main, -1, NULL, NULL);
1575 handle = test_create("main_wndcls.manifest");
1576 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
1578 DeleteFileA("testdep1.manifest");
1579 DeleteFileA("testdep2.manifest");
1580 DeleteFileA("main_wndcls.manifest");
1582 ret = pActivateActCtx(handle, &cookie);
1583 ok(ret, "ActivateActCtx failed: %u\n", GetLastError());
1585 memset(&data, 0, sizeof(data));
1586 memset(&data2, 0, sizeof(data2));
1587 data.cbSize = sizeof(data);
1588 data2.cbSize = sizeof(data2);
1590 /* get data for two classes from different assemblies */
1591 ret = pFindActCtxSectionStringW(0, NULL,
1592 ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION,
1593 wndClass1W, &data);
1594 ok(ret, "got %d\n", ret);
1595 ret = pFindActCtxSectionStringW(0, NULL,
1596 ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION,
1597 wndClass3W, &data2);
1598 ok(ret, "got %d\n", ret);
1600 section = (struct strsection_header*)data.lpSectionBase;
1601 ok(section->count == 4, "got %d\n", section->count);
1602 ok(section->size == sizeof(*section), "got %d\n", section->size);
1604 /* For both string same section is returned, meaning it's one wndclass section per context */
1605 ok(data.lpSectionBase == data2.lpSectionBase, "got %p, %p\n", data.lpSectionBase, data2.lpSectionBase);
1606 ok(data.ulSectionTotalLength == data2.ulSectionTotalLength, "got %u, %u\n", data.ulSectionTotalLength,
1607 data2.ulSectionTotalLength);
1609 /* wndClass1 is versioned, wndClass3 is not */
1610 classdata = (struct wndclass_redirect_data*)data.lpData;
1611 ptrW = (WCHAR*)((BYTE*)data.lpData + classdata->name_offset);
1612 ok(!lstrcmpW(ptrW, cls1W), "got %s\n", wine_dbgstr_w(ptrW));
1614 classdata = (struct wndclass_redirect_data*)data2.lpData;
1615 ptrW = (WCHAR*)((BYTE*)data2.lpData + classdata->name_offset);
1616 ok(!lstrcmpW(ptrW, wndClass3W), "got %s\n", wine_dbgstr_w(ptrW));
1618 ret = pDeactivateActCtx(0, cookie);
1619 ok(ret, "DeactivateActCtx failed: %u\n", GetLastError());
1621 pReleaseActCtx(handle);
1624 static void test_dllredirect_section(void)
1626 static const WCHAR testlib1W[] = {'t','e','s','t','l','i','b','1','.','d','l','l',0};
1627 static const WCHAR testlib2W[] = {'t','e','s','t','l','i','b','2','.','d','l','l',0};
1628 ACTCTX_SECTION_KEYED_DATA data, data2;
1629 struct strsection_header *section;
1630 ULONG_PTR cookie;
1631 HANDLE handle;
1632 BOOL ret;
1634 /* use two dependent manifests, 4 'files' total */
1635 create_manifest_file("testdep1.manifest", manifest_wndcls1, -1, NULL, NULL);
1636 create_manifest_file("testdep2.manifest", manifest_wndcls2, -1, NULL, NULL);
1637 create_manifest_file("main_wndcls.manifest", manifest_wndcls_main, -1, NULL, NULL);
1639 handle = test_create("main_wndcls.manifest");
1640 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
1642 DeleteFileA("testdep1.manifest");
1643 DeleteFileA("testdep2.manifest");
1644 DeleteFileA("main_wndcls.manifest");
1646 ret = pActivateActCtx(handle, &cookie);
1647 ok(ret, "ActivateActCtx failed: %u\n", GetLastError());
1649 memset(&data, 0, sizeof(data));
1650 memset(&data2, 0, sizeof(data2));
1651 data.cbSize = sizeof(data);
1652 data2.cbSize = sizeof(data2);
1654 /* get data for two files from different assemblies */
1655 ret = pFindActCtxSectionStringW(0, NULL,
1656 ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
1657 testlib1W, &data);
1658 ok(ret, "got %d\n", ret);
1659 ret = pFindActCtxSectionStringW(0, NULL,
1660 ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
1661 testlib2W, &data2);
1662 ok(ret, "got %d\n", ret);
1664 section = (struct strsection_header*)data.lpSectionBase;
1665 ok(section->count == 4, "got %d\n", section->count);
1666 ok(section->size == sizeof(*section), "got %d\n", section->size);
1668 /* For both string same section is returned, meaning it's one dll redirect section per context */
1669 ok(data.lpSectionBase == data2.lpSectionBase, "got %p, %p\n", data.lpSectionBase, data2.lpSectionBase);
1670 ok(data.ulSectionTotalLength == data2.ulSectionTotalLength, "got %u, %u\n", data.ulSectionTotalLength,
1671 data2.ulSectionTotalLength);
1673 ret = pDeactivateActCtx(0, cookie);
1674 ok(ret, "DeactivateActCtx failed: %u\n", GetLastError());
1676 pReleaseActCtx(handle);
1679 static void test_typelib_section(void)
1681 static const WCHAR helpW[] = {'h','e','l','p'};
1682 ACTCTX_SECTION_KEYED_DATA data, data2;
1683 struct guidsection_header *section;
1684 struct tlibredirect_data *tlib;
1685 ULONG_PTR cookie;
1686 HANDLE handle;
1687 BOOL ret;
1689 /* use two dependent manifests, 4 'files' total */
1690 create_manifest_file("testdep1.manifest", manifest_wndcls1, -1, NULL, NULL);
1691 create_manifest_file("testdep2.manifest", manifest_wndcls2, -1, NULL, NULL);
1692 create_manifest_file("main_wndcls.manifest", manifest_wndcls_main, -1, NULL, NULL);
1694 handle = test_create("main_wndcls.manifest");
1695 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
1697 DeleteFileA("testdep1.manifest");
1698 DeleteFileA("testdep2.manifest");
1699 DeleteFileA("main_wndcls.manifest");
1701 ret = pActivateActCtx(handle, &cookie);
1702 ok(ret, "ActivateActCtx failed: %u\n", GetLastError());
1704 memset(&data, 0, sizeof(data));
1705 memset(&data2, 0, sizeof(data2));
1706 data.cbSize = sizeof(data);
1707 data2.cbSize = sizeof(data2);
1709 /* get data for two typelibs from different assemblies */
1710 ret = pFindActCtxSectionGuid(0, NULL,
1711 ACTIVATION_CONTEXT_SECTION_COM_TYPE_LIBRARY_REDIRECTION,
1712 &IID_TlibTest, &data);
1713 ok(ret, "got %d\n", ret);
1715 ret = pFindActCtxSectionGuid(0, NULL,
1716 ACTIVATION_CONTEXT_SECTION_COM_TYPE_LIBRARY_REDIRECTION,
1717 &IID_TlibTest4, &data2);
1718 ok(ret, "got %d\n", ret);
1720 section = (struct guidsection_header*)data.lpSectionBase;
1721 ok(section->count == 4, "got %d\n", section->count);
1722 ok(section->size == sizeof(*section), "got %d\n", section->size);
1724 /* For both GUIDs same section is returned */
1725 ok(data.lpSectionBase == data2.lpSectionBase, "got %p, %p\n", data.lpSectionBase, data2.lpSectionBase);
1726 ok(data.ulSectionTotalLength == data2.ulSectionTotalLength, "got %u, %u\n", data.ulSectionTotalLength,
1727 data2.ulSectionTotalLength);
1729 ok(data.lpSectionGlobalData == ((BYTE*)section + section->names_offset), "data.lpSectionGlobalData == NULL\n");
1730 ok(data.ulSectionGlobalDataLength == section->names_len, "data.ulSectionGlobalDataLength=%u\n",
1731 data.ulSectionGlobalDataLength);
1733 /* test some actual data */
1734 tlib = (struct tlibredirect_data*)data.lpData;
1735 ok(tlib->size == sizeof(*tlib), "got %d\n", tlib->size);
1736 ok(tlib->major_version == 1, "got %d\n", tlib->major_version);
1737 ok(tlib->minor_version == 0, "got %d\n", tlib->minor_version);
1738 ok(tlib->help_offset > 0, "got %d\n", tlib->help_offset);
1739 ok(tlib->help_len == sizeof(helpW), "got %d\n", tlib->help_len);
1740 ok(tlib->flags == (LIBFLAG_FHIDDEN|LIBFLAG_FCONTROL|LIBFLAG_FRESTRICTED), "got %x\n", tlib->flags);
1742 ret = pDeactivateActCtx(0, cookie);
1743 ok(ret, "DeactivateActCtx failed: %u\n", GetLastError());
1745 pReleaseActCtx(handle);
1748 static void test_allowDelayedBinding(void)
1750 HANDLE handle;
1752 if (!create_manifest_file("test5.manifest", manifest5, -1, NULL, NULL)) {
1753 skip("Could not create manifest file\n");
1754 return;
1757 handle = test_create("test5.manifest");
1758 if (handle == INVALID_HANDLE_VALUE) {
1759 win_skip("allowDelayedBinding attribute is not supported.\n");
1760 return;
1763 DeleteFileA("test5.manifest");
1764 DeleteFileA("testdep.manifest");
1765 if (handle != INVALID_HANDLE_VALUE) {
1766 test_basic_info(handle, __LINE__);
1767 pReleaseActCtx(handle);
1771 static void test_actctx(void)
1773 ULONG_PTR cookie;
1774 HANDLE handle;
1775 BOOL b;
1777 test_create_fail();
1779 trace("default actctx\n");
1781 b = pGetCurrentActCtx(&handle);
1782 ok(handle == NULL, "handle = %p, expected NULL\n", handle);
1783 ok(b, "GetCurrentActCtx failed: %u\n", GetLastError());
1784 if(b) {
1785 test_basic_info(handle, __LINE__);
1786 test_detailed_info(handle, &detailed_info0, __LINE__);
1787 pReleaseActCtx(handle);
1790 /* test for whitespace handling in Eq ::= S? '=' S? */
1791 create_manifest_file("test1_1.manifest", manifest1_1, -1, NULL, NULL);
1792 handle = test_create("test1_1.manifest");
1793 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
1794 DeleteFileA("test1_1.manifest");
1795 pReleaseActCtx(handle);
1797 if(!create_manifest_file("test1.manifest", manifest1, -1, NULL, NULL)) {
1798 skip("Could not create manifest file\n");
1799 return;
1802 trace("manifest1\n");
1804 handle = test_create("test1.manifest");
1805 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
1806 DeleteFileA("test1.manifest");
1807 if(handle != INVALID_HANDLE_VALUE) {
1808 test_basic_info(handle, __LINE__);
1809 test_detailed_info(handle, &detailed_info1, __LINE__);
1810 test_info_in_assembly(handle, 1, &manifest1_info, __LINE__);
1812 if (pIsDebuggerPresent && !pIsDebuggerPresent())
1814 /* CloseHandle will generate an exception if a debugger is present */
1815 b = CloseHandle(handle);
1816 ok(!b, "CloseHandle succeeded\n");
1817 ok(GetLastError() == ERROR_INVALID_HANDLE, "GetLastError() == %u\n", GetLastError());
1820 pReleaseActCtx(handle);
1823 if(!create_manifest_file("test2.manifest", manifest2, -1, "testdep.manifest", testdep_manifest1)) {
1824 skip("Could not create manifest file\n");
1825 return;
1828 trace("manifest2 depmanifest1\n");
1830 handle = test_create("test2.manifest");
1831 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
1832 DeleteFileA("test2.manifest");
1833 DeleteFileA("testdep.manifest");
1834 if(handle != INVALID_HANDLE_VALUE) {
1835 test_basic_info(handle, __LINE__);
1836 test_detailed_info(handle, &detailed_info2, __LINE__);
1837 test_info_in_assembly(handle, 1, &manifest2_info, __LINE__);
1838 test_info_in_assembly(handle, 2, &depmanifest1_info, __LINE__);
1839 pReleaseActCtx(handle);
1842 if(!create_manifest_file("test2-2.manifest", manifest2, -1, "testdep.manifest", testdep_manifest2)) {
1843 skip("Could not create manifest file\n");
1844 return;
1847 trace("manifest2 depmanifest2\n");
1849 handle = test_create("test2-2.manifest");
1850 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
1851 DeleteFileA("test2-2.manifest");
1852 DeleteFileA("testdep.manifest");
1853 if(handle != INVALID_HANDLE_VALUE) {
1854 test_basic_info(handle, __LINE__);
1855 test_detailed_info(handle, &detailed_info2, __LINE__);
1856 test_info_in_assembly(handle, 1, &manifest2_info, __LINE__);
1857 test_info_in_assembly(handle, 2, &depmanifest2_info, __LINE__);
1858 test_file_info(handle, 1, 0, testlib_dll, __LINE__);
1859 test_file_info(handle, 1, 1, testlib2_dll, __LINE__);
1861 b = pActivateActCtx(handle, &cookie);
1862 ok(b, "ActivateActCtx failed: %u\n", GetLastError());
1863 test_find_dll_redirection(handle, testlib_dll, 2, __LINE__);
1864 test_find_dll_redirection(handle, testlib2_dll, 2, __LINE__);
1865 b = pDeactivateActCtx(0, cookie);
1866 ok(b, "DeactivateActCtx failed: %u\n", GetLastError());
1868 pReleaseActCtx(handle);
1871 trace("manifest2 depmanifest3\n");
1873 if(!create_manifest_file("test2-3.manifest", manifest2, -1, "testdep.manifest", testdep_manifest3)) {
1874 skip("Could not create manifest file\n");
1875 return;
1878 handle = test_create("test2-3.manifest");
1879 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
1880 DeleteFileA("test2-3.manifest");
1881 DeleteFileA("testdep.manifest");
1882 if(handle != INVALID_HANDLE_VALUE) {
1883 test_basic_info(handle, __LINE__);
1884 test_detailed_info(handle, &detailed_info2, __LINE__);
1885 test_info_in_assembly(handle, 1, &manifest2_info, __LINE__);
1886 test_info_in_assembly(handle, 2, &depmanifest3_info, __LINE__);
1887 test_file_info(handle, 1, 0, testlib_dll, __LINE__);
1888 test_file_info(handle, 1, 1, testlib2_dll, __LINE__);
1890 b = pActivateActCtx(handle, &cookie);
1891 ok(b, "ActivateActCtx failed: %u\n", GetLastError());
1892 test_find_dll_redirection(handle, testlib_dll, 2, __LINE__);
1893 test_find_dll_redirection(handle, testlib2_dll, 2, __LINE__);
1894 test_find_window_class(handle, wndClassW, 2, __LINE__);
1895 test_find_window_class(handle, wndClass2W, 2, __LINE__);
1896 b = pDeactivateActCtx(0, cookie);
1897 ok(b, "DeactivateActCtx failed: %u\n", GetLastError());
1899 pReleaseActCtx(handle);
1902 trace("manifest3\n");
1904 if(!create_manifest_file("test3.manifest", manifest3, -1, NULL, NULL)) {
1905 skip("Could not create manifest file\n");
1906 return;
1909 handle = test_create("test3.manifest");
1910 ok(handle != INVALID_HANDLE_VALUE || broken(handle == INVALID_HANDLE_VALUE) /* XP pre-SP2, win2k3 w/o SP */,
1911 "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
1912 if (handle == INVALID_HANDLE_VALUE)
1913 win_skip("Some activation context features not supported, skipping a test (possibly old XP/Win2k3 system\n");
1914 DeleteFileA("test3.manifest");
1915 if(handle != INVALID_HANDLE_VALUE) {
1916 static const WCHAR nameW[] = {'t','e','s','t','s','u','r','r','o','g','a','t','e',0};
1917 static const WCHAR versionW[] = {'v','2','.','0','.','5','0','7','2','7',0};
1918 static const WCHAR progidW[] = {'P','r','o','g','I','d','.','P','r','o','g','I','d',0};
1919 static const WCHAR clrprogidW[] = {'c','l','r','p','r','o','g','i','d',0};
1921 test_basic_info(handle, __LINE__);
1922 test_detailed_info(handle, &detailed_info1, __LINE__);
1923 test_info_in_assembly(handle, 1, &manifest3_info, __LINE__);
1924 test_file_info(handle, 0, 0, testlib_dll, __LINE__);
1926 b = pActivateActCtx(handle, &cookie);
1927 ok(b, "ActivateActCtx failed: %u\n", GetLastError());
1928 test_find_dll_redirection(handle, testlib_dll, 1, __LINE__);
1929 test_find_dll_redirection(handle, testlib_dll, 1, __LINE__);
1930 test_find_com_redirection(handle, &IID_CoTest, &IID_TlibTest, progidW, 1, __LINE__);
1931 test_find_com_redirection(handle, &IID_CoTest2, NULL, NULL, 1, __LINE__);
1932 test_find_com_redirection(handle, &CLSID_clrclass, &IID_TlibTest, clrprogidW, 1, __LINE__);
1933 test_find_progid_redirection(handle, &IID_CoTest, "ProgId.ProgId", 1, __LINE__);
1934 test_find_progid_redirection(handle, &IID_CoTest, "ProgId.ProgId.1", 1, __LINE__);
1935 test_find_progid_redirection(handle, &IID_CoTest, "ProgId.ProgId.2", 1, __LINE__);
1936 test_find_progid_redirection(handle, &IID_CoTest, "ProgId.ProgId.3", 1, __LINE__);
1937 test_find_progid_redirection(handle, &IID_CoTest, "ProgId.ProgId.4", 1, __LINE__);
1938 test_find_progid_redirection(handle, &IID_CoTest, "ProgId.ProgId.5", 1, __LINE__);
1939 test_find_progid_redirection(handle, &IID_CoTest, "ProgId.ProgId.6", 1, __LINE__);
1940 test_find_progid_redirection(handle, &CLSID_clrclass, "clrprogid", 1, __LINE__);
1941 test_find_progid_redirection(handle, &CLSID_clrclass, "clrprogid.1", 1, __LINE__);
1942 test_find_progid_redirection(handle, &CLSID_clrclass, "clrprogid.2", 1, __LINE__);
1943 test_find_progid_redirection(handle, &CLSID_clrclass, "clrprogid.3", 1, __LINE__);
1944 test_find_progid_redirection(handle, &CLSID_clrclass, "clrprogid.4", 1, __LINE__);
1945 test_find_progid_redirection(handle, &CLSID_clrclass, "clrprogid.5", 1, __LINE__);
1946 test_find_progid_redirection(handle, &CLSID_clrclass, "clrprogid.6", 1, __LINE__);
1947 test_find_surrogate(handle, &IID_Iiface, nameW, versionW, 1, __LINE__);
1948 test_find_ifaceps_redirection(handle, &IID_Iifaceps, &IID_TlibTest4, &IID_Ibifaceps, NULL, 1, __LINE__);
1949 test_find_ifaceps_redirection(handle, &IID_Iifaceps2, &IID_TlibTest4, &IID_Ibifaceps, &IID_PS32, 1, __LINE__);
1950 test_find_ifaceps_redirection(handle, &IID_Iifaceps3, &IID_TlibTest4, &IID_Ibifaceps, NULL, 1, __LINE__);
1951 test_find_string_fail();
1953 b = pDeactivateActCtx(0, cookie);
1954 ok(b, "DeactivateActCtx failed: %u\n", GetLastError());
1955 pReleaseActCtx(handle);
1958 trace("manifest4\n");
1960 if(!create_manifest_file("test4.manifest", manifest4, -1, NULL, NULL)) {
1961 skip("Could not create manifest file\n");
1962 return;
1965 handle = test_create("test4.manifest");
1966 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
1967 DeleteFileA("test4.manifest");
1968 DeleteFileA("testdep.manifest");
1969 if(handle != INVALID_HANDLE_VALUE) {
1970 test_basic_info(handle, __LINE__);
1971 test_detailed_info(handle, &detailed_info2, __LINE__);
1972 test_info_in_assembly(handle, 1, &manifest4_info, __LINE__);
1973 test_info_in_assembly(handle, 2, &manifest_comctrl_info, __LINE__);
1974 pReleaseActCtx(handle);
1977 trace("manifest1 in subdir\n");
1979 CreateDirectoryW(work_dir_subdir, NULL);
1980 if (SetCurrentDirectoryW(work_dir_subdir))
1982 if(!create_manifest_file("..\\test1.manifest", manifest1, -1, NULL, NULL)) {
1983 skip("Could not create manifest file\n");
1984 return;
1986 handle = test_create("..\\test1.manifest");
1987 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
1988 DeleteFileA("..\\test1.manifest");
1989 if(handle != INVALID_HANDLE_VALUE) {
1990 test_basic_info(handle, __LINE__);
1991 test_detailed_info(handle, &detailed_info1, __LINE__);
1992 test_info_in_assembly(handle, 1, &manifest1_info, __LINE__);
1993 pReleaseActCtx(handle);
1995 SetCurrentDirectoryW(work_dir);
1997 else
1998 skip("Couldn't change directory\n");
1999 RemoveDirectoryW(work_dir_subdir);
2001 trace("UTF-16 manifest1, with BOM\n");
2002 if(!create_wide_manifest("test1.manifest", manifest1, TRUE, FALSE)) {
2003 skip("Could not create manifest file\n");
2004 return;
2007 handle = test_create("test1.manifest");
2008 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
2009 DeleteFileA("test1.manifest");
2010 if (handle != INVALID_HANDLE_VALUE) {
2011 test_basic_info(handle, __LINE__);
2012 test_detailed_info(handle, &detailed_info1, __LINE__);
2013 test_info_in_assembly(handle, 1, &manifest1_info, __LINE__);
2014 pReleaseActCtx(handle);
2017 trace("UTF-16 manifest1, reverse endian, with BOM\n");
2018 if(!create_wide_manifest("test1.manifest", manifest1, TRUE, TRUE)) {
2019 skip("Could not create manifest file\n");
2020 return;
2023 handle = test_create("test1.manifest");
2024 ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
2025 DeleteFileA("test1.manifest");
2026 if (handle != INVALID_HANDLE_VALUE) {
2027 test_basic_info(handle, __LINE__);
2028 test_detailed_info(handle, &detailed_info1, __LINE__);
2029 test_info_in_assembly(handle, 1, &manifest1_info, __LINE__);
2030 pReleaseActCtx(handle);
2033 test_wndclass_section();
2034 test_dllredirect_section();
2035 test_typelib_section();
2036 test_allowDelayedBinding();
2039 static void test_app_manifest(void)
2041 HANDLE handle;
2042 BOOL b;
2044 trace("child process manifest1\n");
2046 b = pGetCurrentActCtx(&handle);
2047 ok(handle == NULL, "handle != NULL\n");
2048 ok(b, "GetCurrentActCtx failed: %u\n", GetLastError());
2049 if(b) {
2050 test_basic_info(handle, __LINE__);
2051 test_detailed_info(handle, &detailed_info1_child, __LINE__);
2052 test_info_in_assembly(handle, 1, &manifest1_child_info, __LINE__);
2053 pReleaseActCtx(handle);
2057 static HANDLE create_manifest(const char *filename, const char *data, int line)
2059 HANDLE handle;
2060 create_manifest_file(filename, data, -1, NULL, NULL);
2062 handle = test_create(filename);
2063 ok_(__FILE__, line)(handle != INVALID_HANDLE_VALUE,
2064 "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
2066 DeleteFileA(filename);
2067 return handle;
2070 static void kernel32_find(ULONG section, const char *string_to_find, BOOL should_find, BOOL todo, int line)
2072 UNICODE_STRING string_to_findW;
2073 ACTCTX_SECTION_KEYED_DATA data;
2074 BOOL ret;
2075 DWORD err;
2077 pRtlCreateUnicodeStringFromAsciiz(&string_to_findW, string_to_find);
2079 memset(&data, 0xfe, sizeof(data));
2080 data.cbSize = sizeof(data);
2082 SetLastError(0);
2083 ret = pFindActCtxSectionStringA(0, NULL, section, string_to_find, &data);
2084 err = GetLastError();
2085 ok_(__FILE__, line)(ret == should_find,
2086 "FindActCtxSectionStringA: expected ret = %u, got %u\n", should_find, ret);
2087 todo_wine_if(todo)
2088 ok_(__FILE__, line)(err == (should_find ? ERROR_SUCCESS : ERROR_SXS_KEY_NOT_FOUND),
2089 "FindActCtxSectionStringA: unexpected error %u\n", err);
2091 memset(&data, 0xfe, sizeof(data));
2092 data.cbSize = sizeof(data);
2094 SetLastError(0);
2095 ret = pFindActCtxSectionStringW(0, NULL, section, string_to_findW.Buffer, &data);
2096 err = GetLastError();
2097 ok_(__FILE__, line)(ret == should_find,
2098 "FindActCtxSectionStringW: expected ret = %u, got %u\n", should_find, ret);
2099 todo_wine_if(todo)
2100 ok_(__FILE__, line)(err == (should_find ? ERROR_SUCCESS : ERROR_SXS_KEY_NOT_FOUND),
2101 "FindActCtxSectionStringW: unexpected error %u\n", err);
2103 SetLastError(0);
2104 ret = pFindActCtxSectionStringA(0, NULL, section, string_to_find, NULL);
2105 err = GetLastError();
2106 ok_(__FILE__, line)(!ret,
2107 "FindActCtxSectionStringA: expected failure, got %u\n", ret);
2108 ok_(__FILE__, line)(err == ERROR_INVALID_PARAMETER,
2109 "FindActCtxSectionStringA: unexpected error %u\n", err);
2111 SetLastError(0);
2112 ret = pFindActCtxSectionStringW(0, NULL, section, string_to_findW.Buffer, NULL);
2113 err = GetLastError();
2114 ok_(__FILE__, line)(!ret,
2115 "FindActCtxSectionStringW: expected failure, got %u\n", ret);
2116 ok_(__FILE__, line)(err == ERROR_INVALID_PARAMETER,
2117 "FindActCtxSectionStringW: unexpected error %u\n", err);
2119 pRtlFreeUnicodeString(&string_to_findW);
2122 static void ntdll_find(ULONG section, const char *string_to_find, BOOL should_find, BOOL todo, int line)
2124 UNICODE_STRING string_to_findW;
2125 ACTCTX_SECTION_KEYED_DATA data;
2126 NTSTATUS ret;
2128 pRtlCreateUnicodeStringFromAsciiz(&string_to_findW, string_to_find);
2130 memset(&data, 0xfe, sizeof(data));
2131 data.cbSize = sizeof(data);
2133 ret = pRtlFindActivationContextSectionString(0, NULL, section, &string_to_findW, &data);
2134 todo_wine_if(todo)
2135 ok_(__FILE__, line)(ret == (should_find ? STATUS_SUCCESS : STATUS_SXS_KEY_NOT_FOUND),
2136 "RtlFindActivationContextSectionString: unexpected status 0x%x\n", ret);
2138 ret = pRtlFindActivationContextSectionString(0, NULL, section, &string_to_findW, NULL);
2139 todo_wine_if(todo)
2140 ok_(__FILE__, line)(ret == (should_find ? STATUS_SUCCESS : STATUS_SXS_KEY_NOT_FOUND),
2141 "RtlFindActivationContextSectionString: unexpected status 0x%x\n", ret);
2143 pRtlFreeUnicodeString(&string_to_findW);
2146 static void test_findsectionstring(void)
2148 HANDLE handle;
2149 BOOL ret;
2150 ULONG_PTR cookie;
2152 handle = create_manifest("test.manifest", testdep_manifest3, __LINE__);
2153 ret = pActivateActCtx(handle, &cookie);
2154 ok(ret, "ActivateActCtx failed: %u\n", GetLastError());
2156 /* first we show the parameter validation from kernel32 */
2157 kernel32_find(ACTIVATION_CONTEXT_SECTION_ASSEMBLY_INFORMATION, "testdep", FALSE, TRUE, __LINE__);
2158 kernel32_find(ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION, "testlib.dll", TRUE, FALSE, __LINE__);
2159 kernel32_find(ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION, "testlib2.dll", TRUE, FALSE, __LINE__);
2160 kernel32_find(ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION, "testlib3.dll", FALSE, FALSE, __LINE__);
2161 kernel32_find(ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION, "wndClass", TRUE, FALSE, __LINE__);
2162 kernel32_find(ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION, "wndClass2", TRUE, FALSE, __LINE__);
2163 kernel32_find(ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION, "wndClass3", FALSE, FALSE, __LINE__);
2165 /* then we show that ntdll plays by different rules */
2166 ntdll_find(ACTIVATION_CONTEXT_SECTION_ASSEMBLY_INFORMATION, "testdep", FALSE, TRUE, __LINE__);
2167 ntdll_find(ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION, "testlib.dll", TRUE, FALSE, __LINE__);
2168 ntdll_find(ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION, "testlib2.dll", TRUE, FALSE, __LINE__);
2169 ntdll_find(ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION, "testlib3.dll", FALSE, FALSE, __LINE__);
2170 ntdll_find(ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION, "wndClass", TRUE, FALSE, __LINE__);
2171 ntdll_find(ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION, "wndClass2", TRUE, FALSE, __LINE__);
2172 ntdll_find(ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION, "wndClass3", FALSE, FALSE, __LINE__);
2174 ret = pDeactivateActCtx(0, cookie);
2175 ok(ret, "DeactivateActCtx failed: %u\n", GetLastError());
2176 pReleaseActCtx(handle);
2179 static void run_child_process(void)
2181 char cmdline[MAX_PATH];
2182 char path[MAX_PATH];
2183 char **argv;
2184 PROCESS_INFORMATION pi;
2185 STARTUPINFOA si = { 0 };
2186 HANDLE file;
2187 FILETIME now;
2188 BOOL ret;
2190 GetModuleFileNameA(NULL, path, MAX_PATH);
2191 strcat(path, ".manifest");
2192 if(!create_manifest_file(path, manifest1, -1, NULL, NULL)) {
2193 skip("Could not create manifest file\n");
2194 return;
2197 si.cb = sizeof(si);
2198 winetest_get_mainargs( &argv );
2199 /* Vista+ seems to cache presence of .manifest files. Change last modified
2200 date to defeat the cache */
2201 file = CreateFileA(argv[0], FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE,
2202 NULL, OPEN_EXISTING, 0, NULL);
2203 if (file != INVALID_HANDLE_VALUE) {
2204 GetSystemTimeAsFileTime(&now);
2205 SetFileTime(file, NULL, NULL, &now);
2206 CloseHandle(file);
2208 sprintf(cmdline, "\"%s\" %s manifest1", argv[0], argv[1]);
2209 ret = CreateProcessA(argv[0], cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
2210 ok(ret, "Could not create process: %u\n", GetLastError());
2211 winetest_wait_child_process( pi.hProcess );
2212 CloseHandle(pi.hThread);
2213 CloseHandle(pi.hProcess);
2214 DeleteFileA(path);
2217 static void init_paths(void)
2219 LPWSTR ptr;
2221 static const WCHAR dot_manifest[] = {'.','M','a','n','i','f','e','s','t',0};
2222 static const WCHAR backslash[] = {'\\',0};
2223 static const WCHAR subdir[] = {'T','e','s','t','S','u','b','d','i','r','\\',0};
2225 GetModuleFileNameW(NULL, exe_path, sizeof(exe_path)/sizeof(WCHAR));
2226 lstrcpyW(app_dir, exe_path);
2227 for(ptr=app_dir+lstrlenW(app_dir); *ptr != '\\' && *ptr != '/'; ptr--);
2228 ptr[1] = 0;
2230 GetCurrentDirectoryW(MAX_PATH, work_dir);
2231 ptr = work_dir + lstrlenW( work_dir ) - 1;
2232 if (*ptr != '\\' && *ptr != '/')
2233 lstrcatW(work_dir, backslash);
2234 lstrcpyW(work_dir_subdir, work_dir);
2235 lstrcatW(work_dir_subdir, subdir);
2237 GetModuleFileNameW(NULL, app_manifest_path, sizeof(app_manifest_path)/sizeof(WCHAR));
2238 lstrcpyW(app_manifest_path+lstrlenW(app_manifest_path), dot_manifest);
2241 static void write_manifest(const char *filename, const char *manifest)
2243 HANDLE file;
2244 DWORD size;
2245 CHAR path[MAX_PATH];
2247 GetTempPathA(sizeof(path)/sizeof(CHAR), path);
2248 strcat(path, filename);
2250 file = CreateFileA(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
2251 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %u\n", GetLastError());
2252 WriteFile(file, manifest, strlen(manifest), &size, NULL);
2253 CloseHandle(file);
2256 static void delete_manifest_file(const char *filename)
2258 CHAR path[MAX_PATH];
2260 GetTempPathA(sizeof(path)/sizeof(CHAR), path);
2261 strcat(path, filename);
2262 DeleteFileA(path);
2265 static void test_CreateActCtx(void)
2267 CHAR path[MAX_PATH], dir[MAX_PATH];
2268 ACTCTXA actctx;
2269 HANDLE handle;
2271 GetTempPathA(sizeof(path)/sizeof(CHAR), path);
2272 strcat(path, "main_wndcls.manifest");
2274 write_manifest("testdep1.manifest", manifest_wndcls1);
2275 write_manifest("testdep2.manifest", manifest_wndcls2);
2276 write_manifest("main_wndcls.manifest", manifest_wndcls_main);
2278 memset(&actctx, 0, sizeof(ACTCTXA));
2279 actctx.cbSize = sizeof(ACTCTXA);
2280 actctx.lpSource = path;
2282 /* create using lpSource without specified directory */
2283 handle = pCreateActCtxA(&actctx);
2284 ok(handle != INVALID_HANDLE_VALUE, "failed to generate context, error %u\n", GetLastError());
2285 pReleaseActCtx(handle);
2287 /* with specified directory, that doesn't contain dependent assembly */
2288 GetWindowsDirectoryA(dir, sizeof(dir)/sizeof(CHAR));
2290 memset(&actctx, 0, sizeof(ACTCTXA));
2291 actctx.cbSize = sizeof(ACTCTXA);
2292 actctx.dwFlags = ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID;
2293 actctx.lpAssemblyDirectory = dir;
2294 actctx.lpSource = path;
2296 SetLastError(0xdeadbeef);
2297 handle = pCreateActCtxA(&actctx);
2298 todo_wine {
2299 ok(handle == INVALID_HANDLE_VALUE, "got handle %p\n", handle);
2300 ok(GetLastError() == ERROR_SXS_CANT_GEN_ACTCTX, "got error %d\n", GetLastError());
2302 if (handle != INVALID_HANDLE_VALUE) pReleaseActCtx(handle);
2304 delete_manifest_file("main_wndcls.manifest");
2305 delete_manifest_file("testdep1.manifest");
2306 delete_manifest_file("testdep2.manifest");
2308 /* ACTCTX_FLAG_HMODULE_VALID but hModule is not set */
2309 memset(&actctx, 0, sizeof(ACTCTXA));
2310 actctx.cbSize = sizeof(ACTCTXA);
2311 actctx.dwFlags = ACTCTX_FLAG_HMODULE_VALID;
2312 SetLastError(0xdeadbeef);
2313 handle = pCreateActCtxA(&actctx);
2314 ok(handle == INVALID_HANDLE_VALUE, "got handle %p\n", handle);
2315 todo_wine
2316 ok(GetLastError() == ERROR_SXS_CANT_GEN_ACTCTX || broken(GetLastError() == ERROR_NOT_ENOUGH_MEMORY) /* XP, win2k3 */,
2317 "got error %d\n", GetLastError());
2319 /* create from HMODULE - resource doesn't exist, lpSource is set */
2320 memset(&actctx, 0, sizeof(ACTCTXA));
2321 actctx.cbSize = sizeof(ACTCTXA);
2322 actctx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID | ACTCTX_FLAG_HMODULE_VALID;
2323 actctx.lpSource = "dummyfile.dll";
2324 actctx.lpResourceName = MAKEINTRESOURCEA(20);
2325 actctx.hModule = GetModuleHandleA(NULL);
2327 SetLastError(0xdeadbeef);
2328 handle = pCreateActCtxA(&actctx);
2329 ok(handle == INVALID_HANDLE_VALUE, "got handle %p\n", handle);
2330 ok(GetLastError() == ERROR_RESOURCE_TYPE_NOT_FOUND, "got error %d\n", GetLastError());
2332 /* load manifest from lpAssemblyDirectory directory */
2333 write_manifest("testdir.manifest", manifest1);
2334 GetTempPathA(sizeof(path)/sizeof(path[0]), path);
2335 SetCurrentDirectoryA(path);
2336 strcat(path, "assembly_dir");
2337 strcpy(dir, path);
2338 strcat(path, "\\testdir.manifest");
2340 memset(&actctx, 0, sizeof(actctx));
2341 actctx.cbSize = sizeof(actctx);
2342 actctx.dwFlags = ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID;
2343 actctx.lpSource = "testdir.manifest";
2344 actctx.lpAssemblyDirectory = dir;
2346 SetLastError(0xdeadbeef);
2347 handle = pCreateActCtxA(&actctx);
2348 ok(handle == INVALID_HANDLE_VALUE, "got handle %p\n", handle);
2349 ok(GetLastError()==ERROR_PATH_NOT_FOUND ||
2350 broken(GetLastError()==ERROR_FILE_NOT_FOUND) /* WinXP */,
2351 "got error %d\n", GetLastError());
2353 CreateDirectoryA(dir, NULL);
2354 memset(&actctx, 0, sizeof(actctx));
2355 actctx.cbSize = sizeof(actctx);
2356 actctx.dwFlags = ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID;
2357 actctx.lpSource = "testdir.manifest";
2358 actctx.lpAssemblyDirectory = dir;
2360 SetLastError(0xdeadbeef);
2361 handle = pCreateActCtxA(&actctx);
2362 ok(handle == INVALID_HANDLE_VALUE, "got handle %p\n", handle);
2363 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "got error %d\n", GetLastError());
2364 SetCurrentDirectoryW(work_dir);
2366 write_manifest("assembly_dir\\testdir.manifest", manifest1);
2367 memset(&actctx, 0, sizeof(actctx));
2368 actctx.cbSize = sizeof(actctx);
2369 actctx.dwFlags = ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID;
2370 actctx.lpSource = "testdir.manifest";
2371 actctx.lpAssemblyDirectory = dir;
2373 handle = pCreateActCtxA(&actctx);
2374 ok(handle != INVALID_HANDLE_VALUE, "got handle %p\n", handle);
2375 pReleaseActCtx(handle);
2377 memset(&actctx, 0, sizeof(actctx));
2378 actctx.cbSize = sizeof(actctx);
2379 actctx.dwFlags = ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID;
2380 actctx.lpSource = path;
2381 actctx.lpAssemblyDirectory = dir;
2383 handle = pCreateActCtxA(&actctx);
2384 ok(handle != INVALID_HANDLE_VALUE, "got handle %p\n", handle);
2385 pReleaseActCtx(handle);
2387 delete_manifest_file("testdir.manifest");
2388 delete_manifest_file("assembly_dir\\testdir.manifest");
2389 RemoveDirectoryA(dir);
2392 static BOOL init_funcs(void)
2394 HMODULE hLibrary = GetModuleHandleA("kernel32.dll");
2396 #define X(f) if (!(p##f = (void*)GetProcAddress(hLibrary, #f))) return FALSE;
2397 X(ActivateActCtx);
2398 X(CreateActCtxA);
2399 X(CreateActCtxW);
2400 X(DeactivateActCtx);
2401 X(FindActCtxSectionStringA);
2402 X(FindActCtxSectionStringW);
2403 X(GetCurrentActCtx);
2404 X(IsDebuggerPresent);
2405 X(QueryActCtxW);
2406 X(ReleaseActCtx);
2407 X(FindActCtxSectionGuid);
2408 X(ZombifyActCtx);
2410 hLibrary = GetModuleHandleA("ntdll.dll");
2411 X(RtlFindActivationContextSectionString);
2412 X(RtlCreateUnicodeStringFromAsciiz);
2413 X(RtlFreeUnicodeString);
2414 #undef X
2416 return TRUE;
2419 static void test_ZombifyActCtx(void)
2421 ACTIVATION_CONTEXT_BASIC_INFORMATION basicinfo;
2422 ULONG_PTR cookie;
2423 HANDLE handle, current;
2424 BOOL ret;
2426 SetLastError(0xdeadbeef);
2427 ret = pZombifyActCtx(NULL);
2428 todo_wine
2429 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "got %d, error %d\n", ret, GetLastError());
2431 handle = create_manifest("test.manifest", testdep_manifest3, __LINE__);
2433 ret = pGetCurrentActCtx(&current);
2434 ok(ret, "got %d, error %d\n", ret, GetLastError());
2435 ok(current == NULL, "got %p\n", current);
2437 ret = pActivateActCtx(handle, &cookie);
2438 ok(ret, "ActivateActCtx failed: %u\n", GetLastError());
2440 ret = pGetCurrentActCtx(&current);
2441 ok(ret, "got %d, error %d\n", ret, GetLastError());
2442 ok(handle == current, "got %p, %p\n", current, handle);
2444 memset(&basicinfo, 0xff, sizeof(basicinfo));
2445 ret = pQueryActCtxW(0, handle, 0, ActivationContextBasicInformation,
2446 &basicinfo, sizeof(basicinfo), NULL);
2447 ok(ret, "got %d, error %d\n", ret, GetLastError());
2448 ok(basicinfo.hActCtx == handle, "got %p\n", basicinfo.hActCtx);
2449 ok(basicinfo.dwFlags == 0, "got %x\n", basicinfo.dwFlags);
2451 memset(&basicinfo, 0xff, sizeof(basicinfo));
2452 ret = pQueryActCtxW(QUERY_ACTCTX_FLAG_USE_ACTIVE_ACTCTX, NULL, 0, ActivationContextBasicInformation,
2453 &basicinfo, sizeof(basicinfo), NULL);
2454 ok(ret, "got %d, error %d\n", ret, GetLastError());
2455 ok(basicinfo.hActCtx == handle, "got %p\n", basicinfo.hActCtx);
2456 ok(basicinfo.dwFlags == 0, "got %x\n", basicinfo.dwFlags);
2458 ret = pZombifyActCtx(handle);
2459 todo_wine
2460 ok(ret, "got %d\n", ret);
2462 memset(&basicinfo, 0xff, sizeof(basicinfo));
2463 ret = pQueryActCtxW(0, handle, 0, ActivationContextBasicInformation,
2464 &basicinfo, sizeof(basicinfo), NULL);
2465 ok(ret, "got %d, error %d\n", ret, GetLastError());
2466 ok(basicinfo.hActCtx == handle, "got %p\n", basicinfo.hActCtx);
2467 ok(basicinfo.dwFlags == 0, "got %x\n", basicinfo.dwFlags);
2469 memset(&basicinfo, 0xff, sizeof(basicinfo));
2470 ret = pQueryActCtxW(QUERY_ACTCTX_FLAG_USE_ACTIVE_ACTCTX, NULL, 0, ActivationContextBasicInformation,
2471 &basicinfo, sizeof(basicinfo), NULL);
2472 ok(ret, "got %d, error %d\n", ret, GetLastError());
2473 ok(basicinfo.hActCtx == handle, "got %p\n", basicinfo.hActCtx);
2474 ok(basicinfo.dwFlags == 0, "got %x\n", basicinfo.dwFlags);
2476 ret = pGetCurrentActCtx(&current);
2477 ok(ret, "got %d, error %d\n", ret, GetLastError());
2478 ok(current == handle, "got %p\n", current);
2480 /* one more time */
2481 ret = pZombifyActCtx(handle);
2482 todo_wine
2483 ok(ret, "got %d\n", ret);
2485 ret = pDeactivateActCtx(0, cookie);
2486 ok(ret, "DeactivateActCtx failed: %u\n", GetLastError());
2487 pReleaseActCtx(handle);
2490 START_TEST(actctx)
2492 int argc;
2493 char **argv;
2495 argc = winetest_get_mainargs(&argv);
2497 if (!init_funcs())
2499 win_skip("Needed functions are not available\n");
2500 return;
2502 init_paths();
2504 if(argc > 2 && !strcmp(argv[2], "manifest1")) {
2505 test_app_manifest();
2506 return;
2509 test_actctx();
2510 test_CreateActCtx();
2511 test_findsectionstring();
2512 test_ZombifyActCtx();
2513 run_child_process();