~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/kernel32/tests/actctx.c

Version: ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  1 /*
  2  * Copyright 2007 Jacek Caban for CodeWeavers
  3  *
  4  * This library is free software; you can redistribute it and/or
  5  * modify it under the terms of the GNU Lesser General Public
  6  * License as published by the Free Software Foundation; either
  7  * version 2.1 of the License, or (at your option) any later version.
  8  *
  9  * This library is distributed in the hope that it will be useful,
 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 12  * Lesser General Public License for more details.
 13  *
 14  * You should have received a copy of the GNU Lesser General Public
 15  * License along with this library; if not, write to the Free Software
 16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 17  */
 18 
 19 #include "wine/test.h"
 20 #include <winbase.h>
 21 #include <windef.h>
 22 #include <winnt.h>
 23 #include <winternl.h>
 24 #include <winnls.h>
 25 #include <stdio.h>
 26 
 27 static BOOL   (WINAPI *pActivateActCtx)(HANDLE,ULONG_PTR*);
 28 static HANDLE (WINAPI *pCreateActCtxW)(PCACTCTXW);
 29 static BOOL   (WINAPI *pDeactivateActCtx)(DWORD,ULONG_PTR);
 30 static BOOL   (WINAPI *pFindActCtxSectionStringW)(DWORD,const GUID *,ULONG,LPCWSTR,PACTCTX_SECTION_KEYED_DATA);
 31 static BOOL   (WINAPI *pGetCurrentActCtx)(HANDLE *);
 32 static BOOL   (WINAPI *pIsDebuggerPresent)(void);
 33 static BOOL   (WINAPI *pQueryActCtxW)(DWORD,HANDLE,PVOID,ULONG,PVOID,SIZE_T,SIZE_T*);
 34 static VOID   (WINAPI *pReleaseActCtx)(HANDLE);
 35 
 36 static const char* strw(LPCWSTR x)
 37 {
 38     static char buffer[1024];
 39     char*       p = buffer;
 40 
 41     if (!x) return "(nil)";
 42     else while ((*p++ = *x++));
 43     return buffer;
 44 }
 45 
 46 #ifdef __i386__
 47 #define ARCH "x86"
 48 #elif defined __x86_64__
 49 #define ARCH "amd64"
 50 #else
 51 #define ARCH "none"
 52 #endif
 53 
 54 static const char manifest1[] =
 55 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
 56 "<assemblyIdentity version=\"1.0.0.0\"  name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
 57 "</assembly>";
 58 
 59 static const char manifest2[] =
 60 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
 61 "<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\">"
 62 "</assemblyIdentity>"
 63 "<dependency>"
 64 "<dependentAssembly>"
 65 "<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"" ARCH "\">"
 66 "</assemblyIdentity>"
 67 "</dependentAssembly>"
 68 "</dependency>"
 69 "</assembly>";
 70 
 71 static const char manifest3[] =
 72 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
 73 "<assemblyIdentity version=\"1.2.3.4\"  name=\"Wine.Test\" type=\"win32\""
 74 " publicKeyToken=\"6595b6414666f1df\" />"
 75 "<file name=\"testlib.dll\">"
 76 "<windowClass>wndClass</windowClass>"
 77 "</file>"
 78 "</assembly>";
 79 
 80 static const char manifest4[] =
 81 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
 82 "<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\">"
 83 "</assemblyIdentity>"
 84 "<dependency>"
 85 "<dependentAssembly>"
 86 "<assemblyIdentity type=\"win32\" name=\"Microsoft.Windows.Common-Controls\" "
 87     "version=\"6.0.1.0\" processorArchitecture=\"" ARCH "\" publicKeyToken=\"6595b64144ccf1df\">"
 88 "</assemblyIdentity>"
 89 "</dependentAssembly>"
 90 "</dependency>"
 91 "</assembly>";
 92 
 93 static const char testdep_manifest1[] =
 94 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
 95 "<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"" ARCH "\"/>"
 96 "</assembly>";
 97 
 98 static const char testdep_manifest2[] =
 99 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
100 "<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"" ARCH "\" />"
101 "<file name=\"testlib.dll\"></file>"
102 "<file name=\"testlib2.dll\" hash=\"63c978c2b53d6cf72b42fb7308f9af12ab19ec53\" hashalg=\"SHA1\" />"
103 "</assembly>";
104 
105 static const char testdep_manifest3[] =
106 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\"> "
107 "<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"" ARCH "\"/>"
108 "<file name=\"testlib.dll\"/>"
109 "<file name=\"testlib2.dll\" hash=\"63c978c2b53d6cf72b42fb7308f9af12ab19ec53\" hashalg=\"SHA1\">"
110 "<windowClass>wndClass</windowClass>"
111 "<windowClass>wndClass2</windowClass>"
112 "</file>"
113 "</assembly>";
114 
115 static const char wrong_manifest1[] =
116 "<assembly manifestVersion=\"1.0\">"
117 "<assemblyIdentity version=\"1.0.0.0\"  name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
118 "</assembly>";
119 
120 static const char wrong_manifest2[] =
121 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\">"
122 "<assemblyIdentity version=\"1.0.0.0\"  name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
123 "</assembly>";
124 
125 static const char wrong_manifest3[] =
126 "<assembly test=\"test\" xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
127 "<assemblyIdentity version=\"1.0.0.0\"  name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
128 "</assembly>";
129 
130 static const char wrong_manifest4[] =
131 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
132 "<assemblyIdentity version=\"1.0.0.0\"  name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
133 "<test></test>"
134 "</assembly>";
135 
136 static const char wrong_manifest5[] =
137 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
138 "<assemblyIdentity version=\"1.0.0.0\"  name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
139 "</assembly>"
140 "<test></test>";
141 
142 static const char wrong_manifest6[] =
143 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v5\" manifestVersion=\"1.0\">"
144 "<assemblyIdentity version=\"1.0.0.0\"  name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
145 "</assembly>";
146 
147 static const char wrong_manifest7[] =
148 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
149 "<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"" ARCH "\" />"
150 "<file name=\"testlib.dll\" hash=\"63c978c2b53d6cf72b42fb7308f9af12ab19ec5\" hashalg=\"SHA1\" />"
151 "</assembly>";
152 
153 static const char wrong_manifest8[] =
154 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
155 "<assemblyIdentity version=\"1.2.3.4\"  name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
156 "<file></file>"
157 "</assembly>";
158 
159 static const char wrong_depmanifest1[] =
160 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
161 "<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.4\" processorArchitecture=\"" ARCH "\" />"
162 "</assembly>";
163 
164 static const WCHAR testlib_dll[] =
165     {'t','e','s','t','l','i','b','.','d','l','l',0};
166 static const WCHAR testlib2_dll[] =
167     {'t','e','s','t','l','i','b','2','.','d','l','l',0};
168 static const WCHAR wndClassW[] =
169     {'w','n','d','C','l','a','s','s',0};
170 static const WCHAR wndClass2W[] =
171     {'w','n','d','C','l','a','s','s','2',0};
172 static const WCHAR acr_manifest[] =
173     {'a','c','r','.','m','a','n','i','f','e','s','t',0};
174 
175 static WCHAR app_dir[MAX_PATH], exe_path[MAX_PATH], work_dir[MAX_PATH], work_dir_subdir[MAX_PATH];
176 static WCHAR app_manifest_path[MAX_PATH], manifest_path[MAX_PATH], depmanifest_path[MAX_PATH];
177 
178 static int strcmp_aw(LPCWSTR strw, const char *stra)
179 {
180     WCHAR buf[1024];
181 
182     if (!stra) return 1;
183     MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(WCHAR));
184     return lstrcmpW(strw, buf);
185 }
186 
187 static DWORD strlen_aw(const char *str)
188 {
189     return MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0) - 1;
190 }
191 
192 static BOOL create_manifest_file(const char *filename, const char *manifest, int manifest_len,
193                                  const char *depfile, const char *depmanifest)
194 {
195     DWORD size;
196     HANDLE file;
197     WCHAR path[MAX_PATH];
198 
199     MultiByteToWideChar( CP_ACP, 0, filename, -1, path, MAX_PATH );
200     GetFullPathNameW(path, sizeof(manifest_path)/sizeof(WCHAR), manifest_path, NULL);
201 
202     if (manifest_len == -1)
203         manifest_len = strlen(manifest);
204 
205     file = CreateFileW(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
206                        FILE_ATTRIBUTE_NORMAL, NULL);
207     ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %u\n", GetLastError());
208     if(file == INVALID_HANDLE_VALUE)
209         return FALSE;
210     WriteFile(file, manifest, manifest_len, &size, NULL);
211     CloseHandle(file);
212 
213     if (depmanifest)
214     {
215         MultiByteToWideChar( CP_ACP, 0, depfile, -1, path, MAX_PATH );
216         GetFullPathNameW(path, sizeof(depmanifest_path)/sizeof(WCHAR), depmanifest_path, NULL);
217         file = CreateFileW(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
218                            FILE_ATTRIBUTE_NORMAL, NULL);
219         ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %u\n", GetLastError());
220         if(file == INVALID_HANDLE_VALUE)
221             return FALSE;
222         WriteFile(file, depmanifest, strlen(depmanifest), &size, NULL);
223         CloseHandle(file);
224     }
225     return TRUE;
226 }
227 
228 static BOOL create_wide_manifest(const char *filename, const char *manifest, BOOL fBOM, BOOL fReverse)
229 {
230     WCHAR *wmanifest = HeapAlloc(GetProcessHeap(), 0, (strlen(manifest)+2) * sizeof(WCHAR));
231     BOOL ret;
232     int offset = (fBOM ? 0 : 1);
233 
234     MultiByteToWideChar(CP_ACP, 0, manifest, -1, &wmanifest[1], (strlen(manifest)+1));
235     wmanifest[0] = 0xfeff;
236     if (fReverse)
237     {
238         size_t i;
239         for (i = 0; i < strlen(manifest)+1; i++)
240             wmanifest[i] = (wmanifest[i] << 8) | ((wmanifest[i] >> 8) & 0xff);
241     }
242     ret = create_manifest_file(filename, (char *)&wmanifest[offset], (strlen(manifest)+1-offset) * sizeof(WCHAR), NULL, NULL);
243     HeapFree(GetProcessHeap(), 0, wmanifest);
244     return ret;
245 }
246 
247 typedef struct {
248     ULONG format_version;
249     ULONG assembly_cnt_min;
250     ULONG assembly_cnt_max;
251     ULONG root_manifest_type;
252     LPWSTR root_manifest_path;
253     ULONG root_config_type;
254     ULONG app_dir_type;
255     LPCWSTR app_dir;
256 } detailed_info_t;
257 
258 static const detailed_info_t detailed_info0 = {
259     0, 0, 0, 0, NULL, 0, 0, NULL
260 };
261 
262 static const detailed_info_t detailed_info1 = {
263     1, 1, 1, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE, manifest_path,
264     ACTIVATION_CONTEXT_PATH_TYPE_NONE, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE,
265     work_dir,
266 };
267 
268 static const detailed_info_t detailed_info1_child = {
269     1, 1, 1, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE, app_manifest_path,
270     ACTIVATION_CONTEXT_PATH_TYPE_NONE, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE,
271     app_dir,
272 };
273 
274 /* On Vista+, there's an extra assembly for Microsoft.Windows.Common-Controls.Resources */
275 static const detailed_info_t detailed_info2 = {
276     1, 2, 3, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE, manifest_path,
277     ACTIVATION_CONTEXT_PATH_TYPE_NONE, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE,
278     work_dir,
279 };
280 
281 static void test_detailed_info(HANDLE handle, const detailed_info_t *exinfo)
282 {
283     ACTIVATION_CONTEXT_DETAILED_INFORMATION detailed_info_tmp, *detailed_info;
284     SIZE_T size, exsize, retsize;
285     BOOL b;
286 
287     exsize = sizeof(ACTIVATION_CONTEXT_DETAILED_INFORMATION)
288         + (exinfo->root_manifest_path ? (lstrlenW(exinfo->root_manifest_path)+1)*sizeof(WCHAR):0)
289         + (exinfo->app_dir ? (lstrlenW(exinfo->app_dir)+1)*sizeof(WCHAR) : 0);
290 
291     if(exsize != sizeof(ACTIVATION_CONTEXT_DETAILED_INFORMATION)) {
292         size = 0xdeadbeef;
293         b = pQueryActCtxW(0, handle, NULL,
294                           ActivationContextDetailedInformation, &detailed_info_tmp,
295                           sizeof(detailed_info_tmp), &size);
296         ok(!b, "QueryActCtx succeeded\n");
297         ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetLastError() = %u\n", GetLastError());
298         ok(size == exsize, "size=%ld, expected %ld\n", size, exsize);
299     }else {
300         size = sizeof(ACTIVATION_CONTEXT_DETAILED_INFORMATION);
301     }
302 
303     detailed_info = HeapAlloc(GetProcessHeap(), 0, size);
304     memset(detailed_info, 0xfe, size);
305     b = pQueryActCtxW(0, handle, NULL,
306                       ActivationContextDetailedInformation, detailed_info,
307                       size, &retsize);
308     ok(b, "QueryActCtx failed: %u\n", GetLastError());
309     ok(retsize == exsize, "size=%ld, expected %ld\n", retsize, exsize);
310 
311     ok(detailed_info->dwFlags == 0, "detailed_info->dwFlags=%x\n", detailed_info->dwFlags);
312     ok(detailed_info->ulFormatVersion == exinfo->format_version,
313        "detailed_info->ulFormatVersion=%u, expected %u\n", detailed_info->ulFormatVersion,
314        exinfo->format_version);
315     ok(exinfo->assembly_cnt_min <= detailed_info->ulAssemblyCount &&
316        detailed_info->ulAssemblyCount <= exinfo->assembly_cnt_max,
317        "detailed_info->ulAssemblyCount=%u, expected between %u and %u\n", detailed_info->ulAssemblyCount,
318        exinfo->assembly_cnt_min, exinfo->assembly_cnt_max);
319     ok(detailed_info->ulRootManifestPathType == exinfo->root_manifest_type,
320        "detailed_info->ulRootManifestPathType=%u, expected %u\n",
321        detailed_info->ulRootManifestPathType, exinfo->root_manifest_type);
322     ok(detailed_info->ulRootManifestPathChars ==
323        (exinfo->root_manifest_path ? lstrlenW(exinfo->root_manifest_path) : 0),
324        "detailed_info->ulRootManifestPathChars=%u, expected %u\n",
325        detailed_info->ulRootManifestPathChars,
326        exinfo->root_manifest_path ?lstrlenW(exinfo->root_manifest_path) : 0);
327     ok(detailed_info->ulRootConfigurationPathType == exinfo->root_config_type,
328        "detailed_info->ulRootConfigurationPathType=%u, expected %u\n",
329        detailed_info->ulRootConfigurationPathType, exinfo->root_config_type);
330     ok(detailed_info->ulRootConfigurationPathChars == 0,
331        "detailed_info->ulRootConfigurationPathChars=%d\n", detailed_info->ulRootConfigurationPathChars);
332     ok(detailed_info->ulAppDirPathType == exinfo->app_dir_type,
333        "detailed_info->ulAppDirPathType=%u, expected %u\n", detailed_info->ulAppDirPathType,
334        exinfo->app_dir_type);
335     ok(detailed_info->ulAppDirPathChars == (exinfo->app_dir ? lstrlenW(exinfo->app_dir) : 0),
336        "detailed_info->ulAppDirPathChars=%u, expected %u\n",
337        detailed_info->ulAppDirPathChars, exinfo->app_dir ? lstrlenW(exinfo->app_dir) : 0);
338     if(exinfo->root_manifest_path) {
339         ok(detailed_info->lpRootManifestPath != NULL, "detailed_info->lpRootManifestPath == NULL\n");
340         if(detailed_info->lpRootManifestPath)
341             ok(!lstrcmpiW(detailed_info->lpRootManifestPath, exinfo->root_manifest_path),
342                "unexpected detailed_info->lpRootManifestPath\n");
343     }else {
344         ok(detailed_info->lpRootManifestPath == NULL, "detailed_info->lpRootManifestPath != NULL\n");
345     }
346     ok(detailed_info->lpRootConfigurationPath == NULL,
347        "detailed_info->lpRootConfigurationPath=%p\n", detailed_info->lpRootConfigurationPath);
348     if(exinfo->app_dir) {
349         ok(detailed_info->lpAppDirPath != NULL, "detailed_info->lpAppDirPath == NULL\n");
350         if(detailed_info->lpAppDirPath)
351             ok(!lstrcmpiW(exinfo->app_dir, detailed_info->lpAppDirPath),
352                "unexpected detailed_info->lpAppDirPath\n%s\n",strw(detailed_info->lpAppDirPath));
353     }else {
354         ok(detailed_info->lpAppDirPath == NULL, "detailed_info->lpAppDirPath != NULL\n");
355     }
356 
357     HeapFree(GetProcessHeap(), 0, detailed_info);
358 }
359 
360 typedef struct {
361     ULONG flags;
362 /*    ULONG manifest_path_type; FIXME */
363     LPCWSTR manifest_path;
364     LPCSTR encoded_assembly_id;
365     BOOL has_assembly_dir;
366 } info_in_assembly;
367 
368 static const info_in_assembly manifest1_info = {
369     1, manifest_path,
370     "Wine.Test,type=\"win32\",version=\"1.0.0.0\"",
371     FALSE
372 };
373 
374 static const info_in_assembly manifest1_child_info = {
375     1, app_manifest_path,
376     "Wine.Test,type=\"win32\",version=\"1.0.0.0\"",
377     FALSE
378 };
379 
380 static const info_in_assembly manifest2_info = {
381     1, manifest_path,
382     "Wine.Test,type=\"win32\",version=\"1.2.3.4\"",
383     FALSE
384 };
385 
386 static const info_in_assembly manifest3_info = {
387     1, manifest_path,
388     "Wine.Test,publicKeyToken=\"6595b6414666f1df\",type=\"win32\",version=\"1.2.3.4\"",
389     FALSE
390 };
391 
392 static const info_in_assembly manifest4_info = {
393     1, manifest_path,
394     "Wine.Test,type=\"win32\",version=\"1.2.3.4\"",
395     FALSE
396 };
397 
398 static const info_in_assembly depmanifest1_info = {
399     0x10, depmanifest_path,
400     "testdep,processorArchitecture=\"" ARCH "\","
401     "type=\"win32\",version=\"6.5.4.3\"",
402     TRUE
403 };
404 
405 static const info_in_assembly depmanifest2_info = {
406     0x10, depmanifest_path,
407     "testdep,processorArchitecture=\"" ARCH "\","
408     "type=\"win32\",version=\"6.5.4.3\"",
409     TRUE
410 };
411 
412 static const info_in_assembly depmanifest3_info = {
413     0x10, depmanifest_path,
414     "testdep,processorArchitecture=\"" ARCH "\",type=\"win32\",version=\"6.5.4.3\"",
415     TRUE
416 };
417 
418 static const info_in_assembly manifest_comctrl_info = {
419     0, NULL, NULL, TRUE /* These values may differ between Windows installations */
420 };
421 
422 static void test_info_in_assembly(HANDLE handle, DWORD id, const info_in_assembly *exinfo)
423 {
424     ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION *info, info_tmp;
425     SIZE_T size, exsize;
426     ULONG len;
427     BOOL b;
428 
429     exsize = sizeof(ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION);
430     if (exinfo->manifest_path) exsize += (lstrlenW(exinfo->manifest_path)+1) * sizeof(WCHAR);
431     if (exinfo->encoded_assembly_id) exsize += (strlen_aw(exinfo->encoded_assembly_id) + 1) * sizeof(WCHAR);
432 
433     size = 0xdeadbeef;
434     b = pQueryActCtxW(0, handle, &id,
435                       AssemblyDetailedInformationInActivationContext, &info_tmp,
436                       sizeof(info_tmp), &size);
437     ok(!b, "QueryActCtx succeeded\n");
438     ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetLastError() = %u\n", GetLastError());
439 
440     ok(size >= exsize, "size=%lu, expected %lu\n", size, exsize);
441 
442     if (size == 0xdeadbeef)
443     {
444         skip("bad size\n");
445         return;
446     }
447 
448     info = HeapAlloc(GetProcessHeap(), 0, size);
449     memset(info, 0xfe, size);
450 
451     size = 0xdeadbeef;
452     b = pQueryActCtxW(0, handle, &id,
453                       AssemblyDetailedInformationInActivationContext, info, size, &size);
454     ok(b, "QueryActCtx failed: %u\n", GetLastError());
455     if (!exinfo->manifest_path)
456         exsize += info->ulManifestPathLength + sizeof(WCHAR);
457     if (!exinfo->encoded_assembly_id)
458         exsize += info->ulEncodedAssemblyIdentityLength + sizeof(WCHAR);
459     if (exinfo->has_assembly_dir)
460         exsize += info->ulAssemblyDirectoryNameLength + sizeof(WCHAR);
461     ok(size == exsize, "size=%lu, expected %lu\n", size, exsize);
462 
463     if (0)  /* FIXME: flags meaning unknown */
464     {
465         ok((info->ulFlags) == exinfo->flags, "info->ulFlags = %x, expected %x\n",
466            info->ulFlags, exinfo->flags);
467     }
468     if(exinfo->encoded_assembly_id) {
469         len = strlen_aw(exinfo->encoded_assembly_id)*sizeof(WCHAR);
470         ok(info->ulEncodedAssemblyIdentityLength == len,
471            "info->ulEncodedAssemblyIdentityLength = %u, expected %u\n",
472            info->ulEncodedAssemblyIdentityLength, len);
473     } else {
474         ok(info->ulEncodedAssemblyIdentityLength != 0,
475            "info->ulEncodedAssemblyIdentityLength == 0\n");
476     }
477     ok(info->ulManifestPathType == ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE,
478        "info->ulManifestPathType = %x\n", info->ulManifestPathType);
479     if(exinfo->manifest_path) {
480         len = lstrlenW(exinfo->manifest_path)*sizeof(WCHAR);
481         ok(info->ulManifestPathLength == len, "info->ulManifestPathLength = %u, expected %u\n",
482            info->ulManifestPathLength, len);
483     } else {
484         ok(info->ulManifestPathLength != 0, "info->ulManifestPathLength == 0\n");
485     }
486 
487     ok(info->ulPolicyPathType == ACTIVATION_CONTEXT_PATH_TYPE_NONE,
488        "info->ulPolicyPathType = %x\n", info->ulPolicyPathType);
489     ok(info->ulPolicyPathLength == 0,
490        "info->ulPolicyPathLength = %u, expected 0\n", info->ulPolicyPathLength);
491     ok(info->ulMetadataSatelliteRosterIndex == 0, "info->ulMetadataSatelliteRosterIndex = %x\n",
492        info->ulMetadataSatelliteRosterIndex);
493     ok(info->ulManifestVersionMajor == 1,"info->ulManifestVersionMajor = %x\n",
494        info->ulManifestVersionMajor);
495     ok(info->ulManifestVersionMinor == 0, "info->ulManifestVersionMinor = %x\n",
496        info->ulManifestVersionMinor);
497     ok(info->ulPolicyVersionMajor == 0, "info->ulPolicyVersionMajor = %x\n",
498        info->ulPolicyVersionMajor);
499     ok(info->ulPolicyVersionMinor == 0, "info->ulPolicyVersionMinor = %x\n",
500        info->ulPolicyVersionMinor);
501     if(exinfo->has_assembly_dir)
502         ok(info->ulAssemblyDirectoryNameLength != 0,
503            "info->ulAssemblyDirectoryNameLength == 0\n");
504     else
505         ok(info->ulAssemblyDirectoryNameLength == 0,
506            "info->ulAssemblyDirectoryNameLength != 0\n");
507 
508     ok(info->lpAssemblyEncodedAssemblyIdentity != NULL,
509        "info->lpAssemblyEncodedAssemblyIdentity == NULL\n");
510     if(info->lpAssemblyEncodedAssemblyIdentity && exinfo->encoded_assembly_id) {
511         ok(!strcmp_aw(info->lpAssemblyEncodedAssemblyIdentity, exinfo->encoded_assembly_id),
512            "unexpected info->lpAssemblyEncodedAssemblyIdentity %s / %s\n",
513            strw(info->lpAssemblyEncodedAssemblyIdentity), exinfo->encoded_assembly_id);
514     }
515     if(exinfo->manifest_path) {
516         ok(info->lpAssemblyManifestPath != NULL, "info->lpAssemblyManifestPath == NULL\n");
517         if(info->lpAssemblyManifestPath)
518             ok(!lstrcmpiW(info->lpAssemblyManifestPath, exinfo->manifest_path),
519                "unexpected info->lpAssemblyManifestPath\n");
520     }else {
521         ok(info->lpAssemblyManifestPath != NULL, "info->lpAssemblyManifestPath == NULL\n");
522     }
523 
524     ok(info->lpAssemblyPolicyPath == NULL, "info->lpAssemblyPolicyPath != NULL\n");
525     if(info->lpAssemblyPolicyPath)
526         ok(*(WORD*)info->lpAssemblyPolicyPath == 0, "info->lpAssemblyPolicyPath is not empty\n");
527     if(exinfo->has_assembly_dir)
528         ok(info->lpAssemblyDirectoryName != NULL, "info->lpAssemblyDirectoryName == NULL\n");
529     else
530         ok(info->lpAssemblyDirectoryName == NULL, "info->lpAssemblyDirectoryName = %s\n",
531            strw(info->lpAssemblyDirectoryName));
532     HeapFree(GetProcessHeap(), 0, info);
533 }
534 
535 static void test_file_info(HANDLE handle, ULONG assid, ULONG fileid, LPCWSTR filename)
536 {
537     ASSEMBLY_FILE_DETAILED_INFORMATION *info, info_tmp;
538     ACTIVATION_CONTEXT_QUERY_INDEX index = {assid, fileid};
539     SIZE_T size, exsize;
540     BOOL b;
541 
542     exsize = sizeof(ASSEMBLY_FILE_DETAILED_INFORMATION)
543         +(lstrlenW(filename)+1)*sizeof(WCHAR);
544 
545     size = 0xdeadbeef;
546     b = pQueryActCtxW(0, handle, &index,
547                       FileInformationInAssemblyOfAssemblyInActivationContext, &info_tmp,
548                       sizeof(info_tmp), &size);
549     ok(!b, "QueryActCtx succeeded\n");
550     ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetLastError() = %u\n", GetLastError());
551     ok(size == exsize, "size=%lu, expected %lu\n", size, exsize);
552 
553     if(size == 0xdeadbeef)
554     {
555         skip("bad size\n");
556         return;
557     }
558 
559     info = HeapAlloc(GetProcessHeap(), 0, size);
560     memset(info, 0xfe, size);
561 
562     b = pQueryActCtxW(0, handle, &index,
563                       FileInformationInAssemblyOfAssemblyInActivationContext, info, size, &size);
564     ok(b, "QueryActCtx failed: %u\n", GetLastError());
565     ok(!size, "size=%lu, expected 0\n", size);
566 
567     ok(info->ulFlags == 2, "info->ulFlags=%x, expected 2\n", info->ulFlags);
568     ok(info->ulFilenameLength == lstrlenW(filename)*sizeof(WCHAR),
569        "info->ulFilenameLength=%u, expected %u*sizeof(WCHAR)\n",
570        info->ulFilenameLength, lstrlenW(filename));
571     ok(info->ulPathLength == 0, "info->ulPathLength=%u\n", info->ulPathLength);
572     ok(info->lpFileName != NULL, "info->lpFileName == NULL\n");
573     if(info->lpFileName)
574         ok(!lstrcmpiW(info->lpFileName, filename), "unexpected info->lpFileName\n");
575     ok(info->lpFilePath == NULL, "info->lpFilePath != NULL\n");
576     HeapFree(GetProcessHeap(), 0, info);
577 }
578 
579 static HANDLE test_create(const char *file, const char *manifest)
580 {
581     ACTCTXW actctx;
582     HANDLE handle;
583     WCHAR path[MAX_PATH];
584 
585     MultiByteToWideChar( CP_ACP, 0, file, -1, path, MAX_PATH );
586     memset(&actctx, 0, sizeof(ACTCTXW));
587     actctx.cbSize = sizeof(ACTCTXW);
588     actctx.lpSource = path;
589 
590     handle = pCreateActCtxW(&actctx);
591     ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
592 
593     ok(actctx.cbSize == sizeof(actctx), "actctx.cbSize=%d\n", actctx.cbSize);
594     ok(actctx.dwFlags == 0, "actctx.=%d\n", actctx.dwFlags);
595     ok(actctx.lpSource == path, "actctx.lpSource=%p\n", actctx.lpSource);
596     ok(actctx.wProcessorArchitecture == 0,
597        "actctx.wProcessorArchitecture=%d\n", actctx.wProcessorArchitecture);
598     ok(actctx.wLangId == 0, "actctx.wLangId=%d\n", actctx.wLangId);
599     ok(actctx.lpAssemblyDirectory == NULL,
600        "actctx.lpAssemblyDirectory=%p\n", actctx.lpAssemblyDirectory);
601     ok(actctx.lpResourceName == NULL, "actctx.lpResourceName=%p\n", actctx.lpResourceName);
602     ok(actctx.lpApplicationName == NULL, "actctx.lpApplocationName=%p\n",
603        actctx.lpApplicationName);
604     ok(actctx.hModule == NULL, "actctx.hModule=%p\n", actctx.hModule);
605 
606     return handle;
607 }
608 
609 static void test_create_and_fail(const char *manifest, const char *depmanifest, int todo)
610 {
611     ACTCTXW actctx;
612     HANDLE handle;
613     WCHAR path[MAX_PATH];
614 
615     MultiByteToWideChar( CP_ACP, 0, "bad.manifest", -1, path, MAX_PATH );
616     memset(&actctx, 0, sizeof(ACTCTXW));
617     actctx.cbSize = sizeof(ACTCTXW);
618     actctx.lpSource = path;
619 
620     create_manifest_file("bad.manifest", manifest, -1, "testdep.manifest", depmanifest);
621     handle = pCreateActCtxW(&actctx);
622     if (todo) todo_wine
623     {
624         ok(handle == INVALID_HANDLE_VALUE, "handle != INVALID_HANDLE_VALUE\n");
625         ok(GetLastError() == ERROR_SXS_CANT_GEN_ACTCTX, "GetLastError == %u\n", GetLastError());
626     }
627     else
628     {
629         ok(handle == INVALID_HANDLE_VALUE, "handle != INVALID_HANDLE_VALUE\n");
630         ok(GetLastError() == ERROR_SXS_CANT_GEN_ACTCTX, "GetLastError == %u\n", GetLastError());
631     }
632     if (handle != INVALID_HANDLE_VALUE) pReleaseActCtx( handle );
633     DeleteFileA("bad.manifest");
634     DeleteFileA("testdep.manifest");
635 }
636 
637 static void test_create_wide_and_fail(const char *manifest, BOOL fBOM)
638 {
639     ACTCTXW actctx;
640     HANDLE handle;
641     WCHAR path[MAX_PATH];
642 
643     MultiByteToWideChar( CP_ACP, 0, "bad.manifest", -1, path, MAX_PATH );
644     memset(&actctx, 0, sizeof(ACTCTXW));
645     actctx.cbSize = sizeof(ACTCTXW);
646     actctx.lpSource = path;
647 
648     create_wide_manifest("bad.manifest", manifest, fBOM, FALSE);
649     handle = pCreateActCtxW(&actctx);
650     ok(handle == INVALID_HANDLE_VALUE, "handle != INVALID_HANDLE_VALUE\n");
651     ok(GetLastError() == ERROR_SXS_CANT_GEN_ACTCTX, "GetLastError == %u\n", GetLastError());
652 
653     if (handle != INVALID_HANDLE_VALUE) pReleaseActCtx( handle );
654     DeleteFileA("bad.manifest");
655 }
656 
657 static void test_create_fail(void)
658 {
659     ACTCTXW actctx;
660     HANDLE handle;
661     WCHAR path[MAX_PATH];
662 
663     MultiByteToWideChar( CP_ACP, 0, "nonexistent.manifest", -1, path, MAX_PATH );
664     memset(&actctx, 0, sizeof(ACTCTXW));
665     actctx.cbSize = sizeof(ACTCTXW);
666     actctx.lpSource = path;
667 
668     handle = pCreateActCtxW(&actctx);
669     ok(handle == INVALID_HANDLE_VALUE, "handle != INVALID_HANDLE_VALUE\n");
670     ok(GetLastError() == ERROR_FILE_NOT_FOUND, "GetLastError == %u\n", GetLastError());
671 
672     trace("wrong_manifest1\n");
673     test_create_and_fail(wrong_manifest1, NULL, 0 );
674     trace("wrong_manifest2\n");
675     test_create_and_fail(wrong_manifest2, NULL, 0 );
676     trace("wrong_manifest3\n");
677     test_create_and_fail(wrong_manifest3, NULL, 1 );
678     trace("wrong_manifest4\n");
679     test_create_and_fail(wrong_manifest4, NULL, 1 );
680     trace("wrong_manifest5\n");
681     test_create_and_fail(wrong_manifest5, NULL, 0 );
682     trace("wrong_manifest6\n");
683     test_create_and_fail(wrong_manifest6, NULL, 0 );
684     trace("wrong_manifest7\n");
685     test_create_and_fail(wrong_manifest7, NULL, 1 );
686     trace("wrong_manifest8\n");
687     test_create_and_fail(wrong_manifest8, NULL, 0 );
688     trace("UTF-16 manifest1 without BOM\n");
689     test_create_wide_and_fail(manifest1, FALSE );
690     trace("manifest2\n");
691     test_create_and_fail(manifest2, NULL, 0 );
692     trace("manifest2+depmanifest1\n");
693     test_create_and_fail(manifest2, wrong_depmanifest1, 0 );
694 }
695 
696 static void test_find_dll_redirection(HANDLE handle, LPCWSTR libname, ULONG exid)
697 {
698     ACTCTX_SECTION_KEYED_DATA data;
699     DWORD *p;
700     BOOL ret;
701 
702     memset(&data, 0xfe, sizeof(data));
703     data.cbSize = sizeof(data);
704 
705     ret = pFindActCtxSectionStringW(0, NULL,
706                                     ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
707                                     libname, &data);
708     ok(ret, "FindActCtxSectionStringW failed: %u\n", GetLastError());
709     if(!ret)
710     {
711         skip("couldn't find %s\n",strw(libname));
712         return;
713     }
714 
715     ok(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
716     ok(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
717     ok(data.lpData != NULL, "data.lpData == NULL\n");
718     ok(data.ulLength == 20, "data.ulLength=%u\n", data.ulLength);
719 
720     p = data.lpData;
721     if(ret && p) todo_wine {
722         ok(p[0] == 20 && p[1] == 2 && p[2] == 0 && p[3] == 0 && p[4] == 0,
723            "wrong data %u,%u,%u,%u,%u\n",p[0], p[1], p[2], p[3], p[4]);
724     }
725 
726     ok(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
727     ok(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%u\n",
728        data.ulSectionGlobalDataLength);
729     ok(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
730     /* ok(data.ulSectionTotalLength == ??, "data.ulSectionTotalLength=%u\n",
731        data.ulSectionTotalLength); */
732     ok(data.hActCtx == NULL, "data.hActCtx=%p\n", data.hActCtx);
733     ok(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
734        data.ulAssemblyRosterIndex, exid);
735 
736     memset(&data, 0xfe, sizeof(data));
737     data.cbSize = sizeof(data);
738 
739     ret = pFindActCtxSectionStringW(FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX, NULL,
740                                     ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
741                                     libname, &data);
742     ok(ret, "FindActCtxSectionStringW failed: %u\n", GetLastError());
743     if(!ret)
744     {
745         skip("couldn't find\n");
746         return;
747     }
748 
749     ok(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
750     ok(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
751     ok(data.lpData != NULL, "data.lpData == NULL\n");
752     ok(data.ulLength == 20, "data.ulLength=%u\n", data.ulLength);
753     ok(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
754     ok(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%u\n",
755        data.ulSectionGlobalDataLength);
756     ok(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
757     /* ok(data.ulSectionTotalLength == ?? , "data.ulSectionTotalLength=%u\n",
758        data.ulSectionTotalLength); */
759     ok(data.hActCtx == handle, "data.hActCtx=%p\n", data.hActCtx);
760     ok(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
761        data.ulAssemblyRosterIndex, exid);
762 
763     pReleaseActCtx(handle);
764 }
765 
766 static void test_find_window_class(HANDLE handle, LPCWSTR clsname, ULONG exid)
767 {
768     ACTCTX_SECTION_KEYED_DATA data;
769     BOOL ret;
770 
771     memset(&data, 0xfe, sizeof(data));
772     data.cbSize = sizeof(data);
773 
774     ret = pFindActCtxSectionStringW(0, NULL,
775                                     ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION,
776                                     clsname, &data);
777     ok(ret, "FindActCtxSectionStringW failed: %u\n", GetLastError());
778     if(!ret)
779     {
780         skip("couldn't find\n");
781         return;
782     }
783 
784     ok(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
785     ok(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
786     ok(data.lpData != NULL, "data.lpData == NULL\n");
787     /* ok(data.ulLength == ??, "data.ulLength=%u\n", data.ulLength); */
788     ok(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
789     ok(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%u\n",
790        data.ulSectionGlobalDataLength);
791     ok(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
792     /* ok(data.ulSectionTotalLength == 0, "data.ulSectionTotalLength=%u\n",
793        data.ulSectionTotalLength); FIXME */
794     ok(data.hActCtx == NULL, "data.hActCtx=%p\n", data.hActCtx);
795     ok(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
796        data.ulAssemblyRosterIndex, exid);
797 
798     memset(&data, 0xfe, sizeof(data));
799     data.cbSize = sizeof(data);
800 
801     ret = pFindActCtxSectionStringW(FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX, NULL,
802                                     ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION,
803                                     clsname, &data);
804     ok(ret, "FindActCtxSectionStringW failed: %u\n", GetLastError());
805     if(!ret)
806     {
807         skip("couldn't find\n");
808         return;
809     }
810 
811     ok(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
812     ok(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
813     ok(data.lpData != NULL, "data.lpData == NULL\n");
814     /* ok(data.ulLength == ??, "data.ulLength=%u\n", data.ulLength); FIXME */
815     ok(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
816     ok(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%u\n",
817        data.ulSectionGlobalDataLength);
818     ok(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
819     /* ok(data.ulSectionTotalLength == 0, "data.ulSectionTotalLength=%u\n",
820        data.ulSectionTotalLength); FIXME */
821     ok(data.hActCtx == handle, "data.hActCtx=%p\n", data.hActCtx);
822     ok(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
823        data.ulAssemblyRosterIndex, exid);
824 
825     pReleaseActCtx(handle);
826 }
827 
828 static void test_find_string_fail(void)
829 {
830     ACTCTX_SECTION_KEYED_DATA data = {sizeof(data)};
831     BOOL ret;
832 
833     ret = pFindActCtxSectionStringW(0, NULL, 100, testlib_dll, &data);
834     ok(!ret, "FindActCtxSectionStringW succeeded\n");
835     ok(GetLastError() == ERROR_SXS_SECTION_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
836 
837     ret = pFindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
838                                     testlib2_dll, &data);
839     ok(!ret, "FindActCtxSectionStringW succeeded\n");
840     ok(GetLastError() == ERROR_SXS_KEY_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
841 
842     ret = pFindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
843                                     testlib_dll, NULL);
844     ok(!ret, "FindActCtxSectionStringW succeeded\n");
845     ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError()=%u\n", GetLastError());
846 
847     ret = pFindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
848                                     NULL, &data);
849     ok(!ret, "FindActCtxSectionStringW succeeded\n");
850     ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError()=%u\n", GetLastError());
851 
852     data.cbSize = 0;
853     ret = pFindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
854                                     testlib_dll, &data);
855     ok(!ret, "FindActCtxSectionStringW succeeded\n");
856     ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError()=%u\n", GetLastError());
857 
858     data.cbSize = 35;
859     ret = pFindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
860                                     testlib_dll, &data);
861     ok(!ret, "FindActCtxSectionStringW succeeded\n");
862     ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError()=%u\n", GetLastError());
863 }
864 
865 
866 static void test_basic_info(HANDLE handle)
867 {
868     ACTIVATION_CONTEXT_BASIC_INFORMATION basic;
869     SIZE_T size;
870     BOOL b;
871 
872     b = pQueryActCtxW(0, handle, NULL,
873                           ActivationContextBasicInformation, &basic,
874                           sizeof(basic), &size);
875 
876     ok (b,"ActivationContextBasicInformation failed\n");
877     ok (size == sizeof(ACTIVATION_CONTEXT_BASIC_INFORMATION),"size mismatch\n");
878     ok (basic.dwFlags == 0, "unexpected flags %x\n",basic.dwFlags);
879     ok (basic.hActCtx == handle, "unexpected handle\n");
880 
881     b = pQueryActCtxW(QUERY_ACTCTX_FLAG_USE_ACTIVE_ACTCTX, handle, NULL,
882                           ActivationContextBasicInformation, &basic,
883                           sizeof(basic), &size);
884     if (handle)
885     {
886         ok (!b,"ActivationContextBasicInformation succeeded\n");
887         ok (size == 0,"size mismatch\n");
888         ok (GetLastError() == ERROR_INVALID_PARAMETER, "Wrong last error\n");
889         ok (basic.dwFlags == 0, "unexpected flags %x\n",basic.dwFlags);
890         ok (basic.hActCtx == handle, "unexpected handle\n");
891     }
892     else
893     {
894         ok (b,"ActivationContextBasicInformation failed\n");
895         ok (size == sizeof(ACTIVATION_CONTEXT_BASIC_INFORMATION),"size mismatch\n");
896         ok (basic.dwFlags == 0, "unexpected flags %x\n",basic.dwFlags);
897         ok (basic.hActCtx == handle, "unexpected handle\n");
898     }
899 }
900 
901 static void test_actctx(void)
902 {
903     ULONG_PTR cookie;
904     HANDLE handle;
905     BOOL b;
906 
907     test_create_fail();
908 
909     trace("default actctx\n");
910 
911     b = pGetCurrentActCtx(&handle);
912     ok(handle == NULL, "handle = %p, expected NULL\n", handle);
913     ok(b, "GetCurrentActCtx failed: %u\n", GetLastError());
914     if(b) {
915         test_basic_info(handle);
916         test_detailed_info(handle, &detailed_info0);
917         pReleaseActCtx(handle);
918     }
919 
920     if(!create_manifest_file("test1.manifest", manifest1, -1, NULL, NULL)) {
921         skip("Could not create manifest file\n");
922         return;
923     }
924 
925     trace("manifest1\n");
926 
927     handle = test_create("test1.manifest", manifest1);
928     DeleteFileA("test1.manifest");
929     if(handle != INVALID_HANDLE_VALUE) {
930         test_basic_info(handle);
931         test_detailed_info(handle, &detailed_info1);
932         test_info_in_assembly(handle, 1, &manifest1_info);
933 
934         if (pIsDebuggerPresent && !pIsDebuggerPresent())
935         {
936             /* CloseHandle will generate an exception if a debugger is present */
937             b = CloseHandle(handle);
938             ok(!b, "CloseHandle succeeded\n");
939             ok(GetLastError() == ERROR_INVALID_HANDLE, "GetLastError() == %u\n", GetLastError());
940         }
941 
942         pReleaseActCtx(handle);
943     }
944 
945     if(!create_manifest_file("test2.manifest", manifest2, -1, "testdep.manifest", testdep_manifest1)) {
946         skip("Could not create manifest file\n");
947         return;
948     }
949 
950     trace("manifest2 depmanifest1\n");
951 
952     handle = test_create("test2.manifest", manifest2);
953     DeleteFileA("test2.manifest");
954     DeleteFileA("testdep.manifest");
955     if(handle != INVALID_HANDLE_VALUE) {
956         test_basic_info(handle);
957         test_detailed_info(handle, &detailed_info2);
958         test_info_in_assembly(handle, 1, &manifest2_info);
959         test_info_in_assembly(handle, 2, &depmanifest1_info);
960         pReleaseActCtx(handle);
961     }
962 
963     if(!create_manifest_file("test3.manifest", manifest2, -1, "testdep.manifest", testdep_manifest2)) {
964         skip("Could not create manifest file\n");
965         return;
966     }
967 
968     trace("manifest2 depmanifest2\n");
969 
970     handle = test_create("test3.manifest", manifest2);
971     DeleteFileA("test3.manifest");
972     DeleteFileA("testdep.manifest");
973     if(handle != INVALID_HANDLE_VALUE) {
974         test_basic_info(handle);
975         test_detailed_info(handle, &detailed_info2);
976         test_info_in_assembly(handle, 1, &manifest2_info);
977         test_info_in_assembly(handle, 2, &depmanifest2_info);
978         test_file_info(handle, 1, 0, testlib_dll);
979         test_file_info(handle, 1, 1, testlib2_dll);
980 
981         b = pActivateActCtx(handle, &cookie);
982         ok(b, "ActivateActCtx failed: %u\n", GetLastError());
983         test_find_dll_redirection(handle, testlib_dll, 2);
984         test_find_dll_redirection(handle, testlib2_dll, 2);
985         b = pDeactivateActCtx(0, cookie);
986         ok(b, "DeactivateActCtx failed: %u\n", GetLastError());
987 
988         pReleaseActCtx(handle);
989     }
990 
991     trace("manifest2 depmanifest3\n");
992 
993     if(!create_manifest_file("test2-3.manifest", manifest2, -1, "testdep.manifest", testdep_manifest3)) {
994         skip("Could not create manifest file\n");
995         return;
996     }
997 
998     handle = test_create("test2-3.manifest", manifest2);
999     DeleteFileA("test2-3.manifest");
1000     DeleteFileA("testdep.manifest");
1001     if(handle != INVALID_HANDLE_VALUE) {
1002         test_basic_info(handle);
1003         test_detailed_info(handle, &detailed_info2);
1004         test_info_in_assembly(handle, 1, &manifest2_info);
1005         test_info_in_assembly(handle, 2, &depmanifest3_info);
1006         test_file_info(handle, 1, 0, testlib_dll);
1007         test_file_info(handle, 1, 1, testlib2_dll);
1008 
1009         b = pActivateActCtx(handle, &cookie);
1010         ok(b, "ActivateActCtx failed: %u\n", GetLastError());
1011         test_find_dll_redirection(handle, testlib_dll, 2);
1012         test_find_dll_redirection(handle, testlib2_dll, 2);
1013         test_find_window_class(handle, wndClassW, 2);
1014         test_find_window_class(handle, wndClass2W, 2);
1015         b = pDeactivateActCtx(0, cookie);
1016         ok(b, "DeactivateActCtx failed: %u\n", GetLastError());
1017 
1018         pReleaseActCtx(handle);
1019     }
1020 
1021     trace("manifest3\n");
1022 
1023     if(!create_manifest_file("test3.manifest", manifest3, -1, NULL, NULL)) {
1024         skip("Could not create manifest file\n");
1025         return;
1026     }
1027 
1028     handle = test_create("test3.manifest", manifest3);
1029     DeleteFileA("test3.manifest");
1030     if(handle != INVALID_HANDLE_VALUE) {
1031         test_basic_info(handle);
1032         test_detailed_info(handle, &detailed_info1);
1033         test_info_in_assembly(handle, 1, &manifest3_info);
1034         test_file_info(handle, 0, 0, testlib_dll);
1035 
1036         b = pActivateActCtx(handle, &cookie);
1037         ok(b, "ActivateActCtx failed: %u\n", GetLastError());
1038         test_find_dll_redirection(handle, testlib_dll, 1);
1039         test_find_dll_redirection(handle, testlib_dll, 1);
1040         test_find_string_fail();
1041         b = pDeactivateActCtx(0, cookie);
1042         ok(b, "DeactivateActCtx failed: %u\n", GetLastError());
1043 
1044         pReleaseActCtx(handle);
1045     }
1046 
1047     trace("manifest4\n");
1048 
1049     if(!create_manifest_file("test4.manifest", manifest4, -1, NULL, NULL)) {
1050         skip("Could not create manifest file\n");
1051         return;
1052     }
1053 
1054     handle = test_create("test4.manifest", manifest4);
1055     DeleteFileA("test4.manifest");
1056     DeleteFileA("testdep.manifest");
1057     if(handle != INVALID_HANDLE_VALUE) {
1058         test_basic_info(handle);
1059         test_detailed_info(handle, &detailed_info2);
1060         test_info_in_assembly(handle, 1, &manifest4_info);
1061         test_info_in_assembly(handle, 2, &manifest_comctrl_info);
1062         pReleaseActCtx(handle);
1063     }
1064 
1065     trace("manifest1 in subdir\n");
1066 
1067     CreateDirectoryW(work_dir_subdir, NULL);
1068     if (SetCurrentDirectoryW(work_dir_subdir))
1069     {
1070         if(!create_manifest_file("..\\test1.manifest", manifest1, -1, NULL, NULL)) {
1071             skip("Could not create manifest file\n");
1072             return;
1073         }
1074         handle = test_create("..\\test1.manifest", manifest1);
1075         DeleteFileA("..\\test1.manifest");
1076         if(handle != INVALID_HANDLE_VALUE) {
1077             test_basic_info(handle);
1078             test_detailed_info(handle, &detailed_info1);
1079             test_info_in_assembly(handle, 1, &manifest1_info);
1080             pReleaseActCtx(handle);
1081         }
1082         SetCurrentDirectoryW(work_dir);
1083     }
1084     else
1085         skip("Couldn't change directory\n");
1086     RemoveDirectoryW(work_dir_subdir);
1087 
1088     trace("UTF-16 manifest1, with BOM\n");
1089     if(!create_wide_manifest("test1.manifest", manifest1, TRUE, FALSE)) {
1090         skip("Could not create manifest file\n");
1091         return;
1092     }
1093 
1094     handle = test_create("test1.manifest", manifest1);
1095     DeleteFileA("test1.manifest");
1096     if (handle != INVALID_HANDLE_VALUE) {
1097         test_basic_info(handle);
1098         test_detailed_info(handle, &detailed_info1);
1099         test_info_in_assembly(handle, 1, &manifest1_info);
1100         pReleaseActCtx(handle);
1101     }
1102 
1103     trace("UTF-16 manifest1, reverse endian, with BOM\n");
1104     if(!create_wide_manifest("test1.manifest", manifest1, TRUE, TRUE)) {
1105         skip("Could not create manifest file\n");
1106         return;
1107     }
1108 
1109     handle = test_create("test1.manifest", manifest1);
1110     DeleteFileA("test1.manifest");
1111     if (handle != INVALID_HANDLE_VALUE) {
1112         test_basic_info(handle);
1113         test_detailed_info(handle, &detailed_info1);
1114         test_info_in_assembly(handle, 1, &manifest1_info);
1115         pReleaseActCtx(handle);
1116     }
1117 
1118 }
1119 
1120 static void test_app_manifest(void)
1121 {
1122     HANDLE handle;
1123     BOOL b;
1124 
1125     trace("child process manifest1\n");
1126 
1127     b = pGetCurrentActCtx(&handle);
1128     ok(handle == NULL, "handle != NULL\n");
1129     ok(b, "GetCurrentActCtx failed: %u\n", GetLastError());
1130     if(b) {
1131         test_basic_info(handle);
1132         test_detailed_info(handle, &detailed_info1_child);
1133         test_info_in_assembly(handle, 1, &manifest1_child_info);
1134         pReleaseActCtx(handle);
1135     }
1136 }
1137 
1138 static void run_child_process(void)
1139 {
1140     char cmdline[MAX_PATH];
1141     char path[MAX_PATH];
1142     char **argv;
1143     PROCESS_INFORMATION pi;
1144     STARTUPINFO si = { 0 };
1145     HANDLE file;
1146     FILETIME now;
1147 
1148     GetModuleFileNameA(NULL, path, MAX_PATH);
1149     strcat(path, ".manifest");
1150     if(!create_manifest_file(path, manifest1, -1, NULL, NULL)) {
1151         skip("Could not create manifest file\n");
1152         return;
1153     }
1154 
1155     si.cb = sizeof(si);
1156     winetest_get_mainargs( &argv );
1157     /* Vista+ seems to cache presence of .manifest files. Change last modified
1158        date to defeat the cache */
1159     file = CreateFileA(argv[0], FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE,
1160                        NULL, OPEN_EXISTING, 0, NULL);
1161     if (file != INVALID_HANDLE_VALUE) {
1162         GetSystemTimeAsFileTime(&now);
1163         SetFileTime(file, NULL, NULL, &now);
1164         CloseHandle(file);
1165     }
1166     sprintf(cmdline, "\"%s\" %s manifest1", argv[0], argv[1]);
1167     ok(CreateProcess(argv[0], cmdline, NULL, NULL, FALSE, 0, NULL, NULL,
1168                      &si, &pi) != 0, "Could not create process: %u\n", GetLastError());
1169     winetest_wait_child_process( pi.hProcess );
1170     CloseHandle(pi.hThread);
1171     CloseHandle(pi.hProcess);
1172     DeleteFileA(path);
1173 }
1174 
1175 static void init_paths(void)
1176 {
1177     LPWSTR ptr;
1178     WCHAR last;
1179 
1180     static const WCHAR dot_manifest[] = {'.','M','a','n','i','f','e','s','t',0};
1181     static const WCHAR backslash[] = {'\\',0};
1182     static const WCHAR subdir[] = {'T','e','s','t','S','u','b','d','i','r','\\',0};
1183 
1184     GetModuleFileNameW(NULL, exe_path, sizeof(exe_path)/sizeof(WCHAR));
1185     lstrcpyW(app_dir, exe_path);
1186     for(ptr=app_dir+lstrlenW(app_dir); *ptr != '\\' && *ptr != '/'; ptr--);
1187     ptr[1] = 0;
1188 
1189     GetCurrentDirectoryW(MAX_PATH, work_dir);
1190     last = work_dir[lstrlenW(work_dir) - 1];
1191     if (last != '\\' && last != '/')
1192         lstrcatW(work_dir, backslash);
1193     lstrcpyW(work_dir_subdir, work_dir);
1194     lstrcatW(work_dir_subdir, subdir);
1195 
1196     GetModuleFileNameW(NULL, app_manifest_path, sizeof(app_manifest_path)/sizeof(WCHAR));
1197     lstrcpyW(app_manifest_path+lstrlenW(app_manifest_path), dot_manifest);
1198 }
1199 
1200 static BOOL init_funcs(void)
1201 {
1202     HMODULE hKernel32 = GetModuleHandle("kernel32");
1203 
1204 #define X(f) if (!(p##f = (void*)GetProcAddress(hKernel32, #f))) return FALSE;
1205     X(ActivateActCtx);
1206     X(CreateActCtxW);
1207     X(DeactivateActCtx);
1208     X(FindActCtxSectionStringW);
1209     X(GetCurrentActCtx);
1210     X(IsDebuggerPresent);
1211     X(QueryActCtxW);
1212     X(ReleaseActCtx);
1213 #undef X
1214 
1215     return TRUE;
1216 }
1217 
1218 START_TEST(actctx)
1219 {
1220     int argc;
1221     char **argv;
1222 
1223     argc = winetest_get_mainargs(&argv);
1224 
1225     if (!init_funcs())
1226     {
1227         win_skip("Needed functions are not available\n");
1228         return;
1229     }
1230     init_paths();
1231 
1232     if(argc > 2 && !strcmp(argv[2], "manifest1")) {
1233         test_app_manifest();
1234         return;
1235     }
1236 
1237     test_actctx();
1238     run_child_process();
1239 }
1240 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.