[PATCH 27/27] [Kernel32]: ActCtx: starting a couple of tests

Eric Pouech eric.pouech at wanadoo.fr
Mon May 7 14:52:40 CDT 2007


From: Jacek Caban <jacek at codeweavers.com>

(written by Jacek Caban)
---

 dlls/kernel32/tests/Makefile.in |    1 
 dlls/kernel32/tests/actctx.c    |  759 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 760 insertions(+), 0 deletions(-)

diff --git a/dlls/kernel32/tests/Makefile.in b/dlls/kernel32/tests/Makefile.in
index 92d0367..ca3c608 100644
--- a/dlls/kernel32/tests/Makefile.in
+++ b/dlls/kernel32/tests/Makefile.in
@@ -6,6 +6,7 @@ TESTDLL   = kernel32.dll
 IMPORTS   = advapi32 kernel32
 
 CTESTS = \
+	actctx.c \
 	alloc.c \
 	atom.c \
 	change.c \
diff --git a/dlls/kernel32/tests/actctx.c b/dlls/kernel32/tests/actctx.c
new file mode 100644
index 0000000..8f366f8
--- /dev/null
+++ b/dlls/kernel32/tests/actctx.c
@@ -0,0 +1,759 @@
+/*
+ * Copyright 2007 Jacek Caban for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <wine/test.h>
+#include <winbase.h>
+#include <windef.h>
+#include <winnt.h>
+#include <winternl.h>
+#include <winnls.h>
+
+static BOOL   (WINAPI *pActivateActCtx)(HANDLE,ULONG_PTR*);
+static HANDLE (WINAPI *pCreateActCtxW)(PCACTCTXW);
+static BOOL   (WINAPI *pDeactivateActCtx)(DWORD,ULONG_PTR);
+static BOOL   (WINAPI *pGetCurrentActCtx)(HANDLE *);
+static BOOL   (WINAPI *pQueryActCtxW)(DWORD,HANDLE,PVOID,ULONG,PVOID,SIZE_T,SIZE_T*);
+static VOID   (WINAPI *pReleaseActCtx)(HANDLE);
+
+static char* strw(LPCWSTR x)
+{
+    static char buffer[1024];
+    char*       p = buffer;
+
+    if (!x) strcpy(buffer, "(nil)");
+    else while ((*p++ = *x++));
+    return buffer;
+}
+
+static const char manifest1[] =
+"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
+"<assemblyIdentity version=\"1.0.0.0\"  name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
+"</assembly>";
+
+static const char manifest2[] =
+"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
+"<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\">"
+"</assemblyIdentity>"
+"<dependency>"
+"<dependentAssembly>"
+"<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"x86\">"
+"</assemblyIdentity>"
+"</dependentAssembly>"
+"</dependency>"
+"</assembly>";
+
+static const char manifest3[] =
+"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
+"<assemblyIdentity version=\"1.2.3.4\"  name=\"Wine.Test\" type=\"win32\""
+" publicKeyToken=\"6595b6414666f1df\" />"
+"<file name=\"testlib.dll\">"
+"<windowClass>wndClass</windowClass>"
+"</file>"
+"</assembly>";
+
+static const char testdep_manifest1[] =
+"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
+"<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"x86\"/>"
+"</assembly>";
+
+static const char testdep_manifest2[] =
+"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
+"<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"x86\" />"
+"<file name=\"testlib.dll\"></file>"
+"<file name=\"testlib2.dll\" hash=\"63c978c2b53d6cf72b42fb7308f9af12ab19ec53\" hashalg=\"SHA1\" />"
+"</assembly>";
+
+static const char testdep_manifest3[] =
+"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\"> "
+"<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"x86\"/>"
+"<file name=\"testlib.dll\"/>"
+"<file name=\"testlib2.dll\" hash=\"63c978c2b53d6cf72b42fb7308f9af12ab19ec53\" hashalg=\"SHA1\">"
+"<windowClass>wndClass</windowClass>"
+"<windowClass>wndClass2</windowClass>"
+"</file>"
+"</assembly>";
+
+static const char wrong_manifest1[] =
+"<assembly manifestVersion=\"1.0\">"
+"<assemblyIdentity version=\"1.0.0.0\"  name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
+"</assembly>";
+
+static const char wrong_manifest2[] =
+"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\">"
+"<assemblyIdentity version=\"1.0.0.0\"  name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
+"</assembly>";
+
+static const char wrong_manifest3[] =
+"<assembly test=\"test\" xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
+"<assemblyIdentity version=\"1.0.0.0\"  name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
+"</assembly>";
+
+static const char wrong_manifest4[] =
+"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
+"<assemblyIdentity version=\"1.0.0.0\"  name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
+"<test></test>"
+"</assembly>";
+
+static const char wrong_manifest5[] =
+"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
+"<assemblyIdentity version=\"1.0.0.0\"  name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
+"</assembly>"
+"<test></test>";
+
+static const char wrong_manifest6[] =
+"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v2\" manifestVersion=\"1.0\">"
+"<assemblyIdentity version=\"1.0.0.0\"  name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
+"</assembly>";
+
+static const char wrong_manifest7[] =
+"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
+"<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.3\" processorArchitecture=\"x86\" />"
+"<file name=\"testlib.dll\" hash=\"63c978c2b53d6cf72b42fb7308f9af12ab19ec5\" hashalg=\"SHA1\" />"
+"</assembly>";
+
+static const char wrong_manifest8[] =
+"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
+"<assemblyIdentity version=\"1.2.3.4\"  name=\"Wine.Test\" type=\"win32\"></assemblyIdentity>"
+"<file></file>"
+"</assembly>";
+
+static const char wrong_depmanifest1[] =
+"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
+"<assemblyIdentity type=\"win32\" name=\"testdep\" version=\"6.5.4.4\" processorArchitecture=\"x86\" />"
+"</assembly>";
+
+static const WCHAR wsz_empty[] = {0};
+
+static const WCHAR manifest_file[] =
+    {'t','e','s','t','.','m','a','n','i','f','e','s','t',0};
+static const WCHAR depmanifest_file[] =
+    {'t','e','s','t','d','e','p','.','m','a','n','i','f','e','s','t',0};
+static const WCHAR testlib_dll[] =
+    {'t','e','s','t','l','i','b','.','d','l','l',0};
+static const WCHAR testlib2_dll[] =
+    {'t','e','s','t','l','i','b','2','.','d','l','l',0};
+static const WCHAR wndClassW[] =
+    {'w','n','d','C','l','a','s','s',0};
+static const WCHAR wndClass2W[] =
+    {'w','n','d','C','l','a','s','s','2',0};
+
+static WCHAR app_dir[MAX_PATH], exe_path[MAX_PATH];
+static WCHAR manifest_path[MAX_PATH], depmanifest_path[MAX_PATH];
+
+static int strcmp_aw(LPCWSTR strw, const char *stra)
+{
+    WCHAR buf[1024];
+
+    if (!stra) return 1;
+    MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf));
+    return lstrcmpW(strw, buf);
+}
+
+static DWORD strlen_aw(const char *str)
+{
+    return MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0) - 1;
+}
+
+static BOOL create_manifest_file(LPCWSTR filename, const char *manifest)
+{
+    DWORD size;
+    HANDLE file;
+
+    file = CreateFileW(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
+            FILE_ATTRIBUTE_NORMAL, NULL);
+    ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %u\n", GetLastError());
+    if(file == INVALID_HANDLE_VALUE)
+        return FALSE;
+    WriteFile(file, manifest, strlen(manifest), &size, NULL);
+    CloseHandle(file);
+
+    return TRUE;
+}
+
+typedef struct {
+    ULONG format_version;
+    ULONG assembly_cnt;
+    ULONG root_manifest_type;
+    LPWSTR root_manifest_path;
+    ULONG root_config_type;
+    ULONG app_dir_type;
+    LPCWSTR app_dir;
+} detailed_info_t;
+
+static const detailed_info_t detailed_info0 = {
+    0, 0, 0, NULL, 0, 0, NULL
+};
+
+static const detailed_info_t detailed_info1 = {
+    1, 1, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE, manifest_path,
+    ACTIVATION_CONTEXT_PATH_TYPE_NONE, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE,
+    app_dir,
+};
+
+static const detailed_info_t detailed_info2 = {
+    1, 2, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE, manifest_path,
+    ACTIVATION_CONTEXT_PATH_TYPE_NONE, ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE,
+    app_dir,
+};
+
+static void test_detailed_info(HANDLE handle, const detailed_info_t *exinfo)
+{
+    ACTIVATION_CONTEXT_DETAILED_INFORMATION detailed_info_tmp, *detailed_info;
+    SIZE_T size, exsize;
+    BOOL b;
+
+    exsize = sizeof(ACTIVATION_CONTEXT_DETAILED_INFORMATION)
+        + (exinfo->root_manifest_path ? (lstrlenW(exinfo->root_manifest_path)+1)*sizeof(WCHAR):0)
+        + (exinfo->app_dir ? (lstrlenW(app_dir)+1)*sizeof(WCHAR) : 0);
+
+
+    if(exsize != sizeof(ACTIVATION_CONTEXT_DETAILED_INFORMATION)) {
+        size = 0xdeadbeef;
+        b = pQueryActCtxW(0, handle, NULL,
+                          ActivationContextDetailedInformation, &detailed_info_tmp,
+                          sizeof(detailed_info_tmp), &size);
+        ok(!b, "QueryActCtx succeeded\n");
+        ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetLastError() = %u\n", GetLastError());
+        ok(size == exsize, "size=%ld, expected %ld\n", size, exsize);
+    }else {
+        size = sizeof(ACTIVATION_CONTEXT_DETAILED_INFORMATION);
+    }
+
+    detailed_info = HeapAlloc(GetProcessHeap(), 0, size);
+    memset(detailed_info, 0xfe, size);
+
+    size = 0xdeadbeef;
+    b = pQueryActCtxW(0, handle, NULL,
+                      ActivationContextDetailedInformation, detailed_info,
+                      size, &size);
+    ok(b, "QueryActCtx failed: %u\n", GetLastError());
+    ok(size == exsize, "size=%ld, expected %ld\n", size, exsize);
+
+    ok(detailed_info->dwFlags == 0, "detailed_info->dwFlags=%x\n", detailed_info->dwFlags);
+    ok(detailed_info->ulFormatVersion == exinfo->format_version,
+       "detailed_info->ulFormatVersion=%u, expected %u\n", detailed_info->ulFormatVersion,
+       exinfo->format_version);
+    ok(detailed_info->ulAssemblyCount == exinfo->assembly_cnt,
+       "detailed_info->ulAssemblyCount=%u, expected %u\n", detailed_info->ulAssemblyCount,
+       exinfo->assembly_cnt);
+    ok(detailed_info->ulRootManifestPathType == exinfo->root_manifest_type,
+       "detailed_info->ulRootManifestPathType=%u, expected %u\n",
+       detailed_info->ulRootManifestPathType, exinfo->root_manifest_type);
+    ok(detailed_info->ulRootManifestPathChars ==
+       (exinfo->root_manifest_path ? lstrlenW(exinfo->root_manifest_path) : 0),
+       "detailed_info->ulRootManifestPathChars=%u, expected %u\n",
+       detailed_info->ulRootManifestPathChars,
+       exinfo->root_manifest_path ?lstrlenW(exinfo->root_manifest_path) : 0);
+    ok(detailed_info->ulRootConfigurationPathType == exinfo->root_config_type,
+       "detailed_info->ulRootConfigurationPathType=%u, expected %u\n",
+       detailed_info->ulRootConfigurationPathType, exinfo->root_config_type);
+    ok(detailed_info->ulRootConfigurationPathChars == 0,
+       "detailed_info->ulRootConfigurationPathChars=%d\n", detailed_info->ulRootConfigurationPathChars);
+    ok(detailed_info->ulAppDirPathType == exinfo->app_dir_type,
+       "detailed_info->ulAppDirPathType=%u, expected %u\n", detailed_info->ulAppDirPathType,
+       exinfo->app_dir_type);
+    ok(detailed_info->ulAppDirPathChars == (exinfo->app_dir ? lstrlenW(app_dir) : 0),
+       "detailed_info->ulAppDirPathChars=%u, expected %u\n",
+       detailed_info->ulAppDirPathChars, exinfo->app_dir ? lstrlenW(app_dir) : 0);
+    if(exinfo->root_manifest_path) {
+        ok(detailed_info->lpRootManifestPath != NULL, "detailed_info->lpRootManifestPath == NULL\n");
+        if(detailed_info->lpRootManifestPath)
+            ok(!lstrcmpW(detailed_info->lpRootManifestPath, exinfo->root_manifest_path),
+               "unexpected detailed_info->lpRootManifestPath\n");
+    }else {
+        ok(detailed_info->lpRootManifestPath == NULL, "detailed_info->lpRootManifestPath != NULL\n");
+    }
+    ok(detailed_info->lpRootConfigurationPath == NULL,
+       "detailed_info->lpRootConfigurationPath=%p\n", detailed_info->lpRootConfigurationPath);
+    if(exinfo->app_dir) {
+        ok(detailed_info->lpAppDirPath != NULL, "detailed_info->lpAppDirPath == NULL\n");
+        if(detailed_info->lpAppDirPath)
+            ok(!lstrcmpW(app_dir, detailed_info->lpAppDirPath),
+               "unexpected detailed_info->lpAppDirPath\n");
+
+
+    }else {
+        ok(detailed_info->lpAppDirPath == NULL, "detailed_info->lpAppDirPath != NULL\n");
+    }
+
+    HeapFree(GetProcessHeap(), 0, detailed_info);
+}
+
+typedef struct {
+    ULONG flags;
+//    ULONG manifest_path_type; FIXME
+    LPCWSTR manifest_path;
+    LPCSTR encoded_assembly_id;
+    BOOL test_assembly_dir;
+    LPCSTR assembly_dir;
+} info_in_assembly;
+
+static const info_in_assembly manifest1_info = {
+    1, manifest_path,
+    "Wine.Test,type=\"win32\",version=\"1.0.0.0\"",
+    TRUE, NULL
+};
+
+static const info_in_assembly manifest2_info = {
+    1, manifest_path,
+    "Wine.Test,type=\"win32\",version=\"1.2.3.4\"",
+    TRUE, NULL
+};
+
+static const info_in_assembly manifest3_info = {
+    1, manifest_path,
+    "Wine.Test,publicKeyToken=\"6595b6414666f1df\",type=\"win32\",version=\"1.2.3.4\"",
+    TRUE, NULL
+};
+
+static const info_in_assembly manifest4_info = {
+    1, manifest_path,
+    "Wine.Test,type=\"win32\",version=\"1.2.3.4\"",
+    TRUE, NULL
+};
+
+static const info_in_assembly depmanifest1_info = {
+    0x10, depmanifest_path,
+    "testdep,processorArchitecture=\"x86\","
+    "type=\"win32\",version=\"6.5.4.3\"",
+    TRUE, "x86_testdep_no-public-key_6.5.4.3_x-ww_5647e90e"
+};
+
+static const info_in_assembly depmanifest2_info = {
+    0x10, depmanifest_path,
+    "testdep,processorArchitecture=\"x86\","
+    "type=\"win32\",version=\"6.5.4.3\"",
+    TRUE, "x86_testdep_no-public-key_6.5.4.3_x-ww_5647e90e"
+};
+
+static const info_in_assembly depmanifest3_info = {
+    0x10, depmanifest_path,
+    "testdep,processorArchitecture=\"x86\",type=\"win32\",version=\"6.5.4.3\"",
+    TRUE, "x86_testdep_no-public-key_6.5.4.3_x-ww_5647e90e"
+};
+
+static const info_in_assembly manifest_comctrl_info = {
+    0, NULL, NULL, FALSE, NULL /* These values may differ between Windows instalations */
+};
+
+static void test_info_in_assembly(HANDLE handle, DWORD id, const info_in_assembly *exinfo)
+{
+    ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION *info, info_tmp;
+    SIZE_T size, exsize;
+    ULONG len;
+    BOOL b;
+
+    exsize = sizeof(ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION)
+        + (lstrlenW(exinfo->manifest_path)+1) * sizeof(WCHAR)
+        + (strlen_aw(exinfo->encoded_assembly_id) + 1) * sizeof(WCHAR)
+        + (exinfo->assembly_dir ? strlen_aw(exinfo->assembly_dir) + 1 : 0) * sizeof(WCHAR);
+
+    size = 0xdeadbeef;
+    b = pQueryActCtxW(0, handle, &id,
+                      AssemblyDetailedInformationInActivationContext, &info_tmp,
+                      sizeof(info_tmp), &size);
+    ok(!b, "QueryActCtx succeeded\n");
+    ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetLastError() = %u\n", GetLastError());
+
+    if (exinfo->encoded_assembly_id)
+        ok(size == exsize, "size=%lu, expected %lu\n", size, exsize);
+    ok(size == exsize, "size=%lu, expected %lu\n", size, exsize);
+
+    if (size == 0xdeadbeef)
+    {
+        skip("bad size\n");
+        return;
+    }
+
+    info = HeapAlloc(GetProcessHeap(), 0, size);
+    memset(info, 0xfe, size);
+
+    size = 0xdeadbeef;
+    b = pQueryActCtxW(0, handle, &id,
+                      AssemblyDetailedInformationInActivationContext, info, size, &size);
+    ok(b, "QueryActCtx failed: %u\n", GetLastError());
+    ok(size == exsize, "size=%lu, expected %lu\n", size, exsize);
+
+    ok(info->ulFlags == exinfo->flags, "info->ulFlags = %x, expected %x\n",
+       info->ulFlags, exinfo->flags);
+    if(exinfo->encoded_assembly_id) {
+        len = strlen_aw(exinfo->encoded_assembly_id)*sizeof(WCHAR);
+        ok(info->ulEncodedAssemblyIdentityLength == len,
+           "info->ulEncodedAssemblyIdentityLength = %u, expected %u\n",
+           info->ulEncodedAssemblyIdentityLength, len);
+    } else {
+        ok(info->ulEncodedAssemblyIdentityLength != 0,
+           "info->ulEncodedAssemblyIdentityLength == 0\n");
+    }
+    ok(info->ulManifestPathType == ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE,
+       "info->ulManifestPathType = %x\n", info->ulManifestPathType);
+    if(exinfo->manifest_path) {
+        len = lstrlenW(exinfo->manifest_path)*sizeof(WCHAR);
+        ok(info->ulManifestPathLength == len, "info->ulManifestPathLength = %u, expected %u\n",
+           info->ulManifestPathLength, len);
+    } else {
+        ok(info->ulManifestPathLength != 0, "info->ulManifestPathLength == 0\n");
+    }
+
+    ok(info->ulPolicyPathType == ACTIVATION_CONTEXT_PATH_TYPE_NONE,
+       "info->ulPolicyPathType = %x\n", info->ulPolicyPathType);
+    ok(info->ulPolicyPathLength == 0,
+       "info->ulPolicyPathLength = %u, expected 0\n", info->ulPolicyPathLength);
+    ok(info->ulMetadataSatelliteRosterIndex == 0, "info->ulMetadataSatelliteRosterIndex = %x\n",
+       info->ulMetadataSatelliteRosterIndex);
+    ok(info->ulManifestVersionMajor == 1,"info->ulManifestVersionMajor = %x\n",
+       info->ulManifestVersionMajor);
+    ok(info->ulManifestVersionMinor == 0, "info->ulManifestVersionMinor = %x\n",
+       info->ulManifestVersionMinor);
+    ok(info->ulPolicyVersionMajor == 0, "info->ulPolicyVersionMajor = %x\n",
+       info->ulPolicyVersionMajor);
+    ok(info->ulPolicyVersionMinor == 0, "info->ulPolicyVersionMinor = %x\n",
+       info->ulPolicyVersionMinor);
+    if(exinfo->test_assembly_dir) {
+        if(exinfo->assembly_dir) {
+            len = strlen_aw(exinfo->assembly_dir)*sizeof(WCHAR);
+            ok(info->ulAssemblyDirectoryNameLength == len,
+               "info->ulAssemblyDirectoryNameLength = %u, expected %u\n",
+               info->ulAssemblyDirectoryNameLength, len);
+        }else {
+            ok(info->ulAssemblyDirectoryNameLength == 0,
+               "info->ulAssemblyDirectoryNameLength != 0\n");
+        }
+    }else {
+        ok(info->ulAssemblyDirectoryNameLength != 0,
+           "info->ulAssemblyDirectoryNameLength == 0\n");
+    }
+    ok(info->lpAssemblyEncodedAssemblyIdentity != NULL,
+       "info->lpAssemblyEncodedAssemblyIdentity == NULL\n");
+    if(info->lpAssemblyEncodedAssemblyIdentity && exinfo->encoded_assembly_id) {
+        ok(!strcmp_aw(info->lpAssemblyEncodedAssemblyIdentity, exinfo->encoded_assembly_id),
+           "unexpected info->lpAssemblyEncodedAssemblyIdentity (%s)\n", strw(info->lpAssemblyEncodedAssemblyIdentity));
+    }
+    if(exinfo->manifest_path) {
+        ok(info->lpAssemblyManifestPath != NULL, "info->lpAssemblyManifestPath == NULL\n");
+        if(info->lpAssemblyManifestPath)
+            ok(!lstrcmpiW(info->lpAssemblyManifestPath, exinfo->manifest_path),
+               "unexpected info->lpAssemblyManifestPath\n");
+    }else {
+        ok(info->lpAssemblyManifestPath != NULL, "info->lpAssemblyManifestPath == NULL\n");
+    }
+
+    ok(info->lpAssemblyPolicyPath == NULL, "info->lpAssemblyPolicyPath != NULL\n");
+    if(info->lpAssemblyPolicyPath)
+        ok(*(WORD*)info->lpAssemblyPolicyPath == 0, "info->lpAssemblyPolicyPath is not empty\n");
+    if(exinfo->test_assembly_dir) {
+        if(exinfo->assembly_dir) {
+            ok(!strcmp_aw(info->lpAssemblyDirectoryName, exinfo->assembly_dir),
+               "unexpected info->lpAssemblyDirectoryName (%s -> %s)\n", strw(info->lpAssemblyDirectoryName), exinfo->assembly_dir);
+        }else {
+            ok(info->lpAssemblyDirectoryName == NULL, "info->lpAssemblyDirectoryName = %p\n",
+               info->lpAssemblyDirectoryName);
+        }
+    }else {
+        ok(info->lpAssemblyDirectoryName != NULL, "info->lpAssemblyDirectoryName == NULL\n");
+    }
+}
+
+static void test_file_info(HANDLE handle, ULONG assid, ULONG fileid, LPCWSTR filename)
+{
+    ASSEMBLY_FILE_DETAILED_INFORMATION *info, info_tmp;
+    ACTIVATION_CONTEXT_QUERY_INDEX index = {assid, fileid};
+    SIZE_T size, exsize;
+    BOOL b;
+
+    exsize = sizeof(ASSEMBLY_FILE_DETAILED_INFORMATION)
+        +(lstrlenW(filename)+1)*sizeof(WCHAR);
+
+    size = 0xdeadbeef;
+    b = pQueryActCtxW(0, handle, &index,
+                      FileInformationInAssemblyOfAssemblyInActivationContext, &info_tmp,
+                      sizeof(info_tmp), &size);
+    ok(!b, "QueryActCtx succeeded\n");
+    ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetLastError() = %u\n", GetLastError());
+    ok(size == exsize, "size=%lu, expected %lu\n", size, exsize);
+
+    if(size == 0xdeadbeef)
+    {
+        skip("bad size\n");
+        return;
+    }
+
+    info = HeapAlloc(GetProcessHeap(), 0, size);
+    memset(info, 0xfe, size);
+
+    b = pQueryActCtxW(0, handle, &index,
+                      FileInformationInAssemblyOfAssemblyInActivationContext, info, size, &size);
+    ok(b, "QueryActCtx failed: %u\n", GetLastError());
+    ok(!size, "size=%lu, expected 0\n", size);
+
+    ok(info->ulFlags == 2, "info->ulFlags=%x, expected 2\n", info->ulFlags);
+    ok(info->ulFilenameLength == lstrlenW(filename)*sizeof(WCHAR),
+       "info->ulFilenameLength=%u, expected %u\n",
+       info->ulFilenameLength, lstrlenW(filename)*sizeof(WCHAR));
+    ok(info->ulPathLength == 0, "info->ulPathLength=%u\n", info->ulPathLength);
+    ok(info->lpFileName != NULL, "info->lpFileName == NULL\n");
+    if(info->lpFileName)
+        ok(!lstrcmpW(info->lpFileName, filename), "unexpected info->lpFileName\n");
+    ok(info->lpFilePath == NULL, "info->lpFilePath != NULL\n");
+}
+
+static HANDLE test_create(const char *manifest)
+{
+    ACTCTXW actctx;
+    HANDLE handle;
+
+    memset(&actctx, 0, sizeof(ACTCTXW));
+    actctx.cbSize = sizeof(ACTCTXW);
+    actctx.lpSource = manifest_file;
+
+    handle = pCreateActCtxW(&actctx);
+    ok(handle != INVALID_HANDLE_VALUE, "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
+
+    ok(actctx.cbSize == sizeof(actctx), "actctx.cbSize=%d\n", actctx.cbSize);
+    ok(actctx.dwFlags == 0, "actctx.=%d\n", actctx.dwFlags);
+    ok(actctx.lpSource == manifest_file, "actctx.lpSource=%p\n", actctx.lpSource);
+    ok(actctx.wProcessorArchitecture == 0,
+       "actctx.wProcessorArchitecture=%d\n", actctx.wProcessorArchitecture);
+    ok(actctx.wLangId == 0, "actctx.wLangId=%d\n", actctx.wLangId);
+    ok(actctx.lpAssemblyDirectory == NULL,
+       "actctx.lpAssemblyDirectory=%p\n", actctx.lpAssemblyDirectory);
+    ok(actctx.lpResourceName == NULL, "actctx.lpResourceName=%p\n", actctx.lpResourceName);
+    ok(actctx.lpApplicationName == NULL, "actctx.lpApplocationName=%p\n",
+       actctx.lpApplicationName);
+    ok(actctx.hModule == NULL, "actctx.hModule=%p\n", actctx.hModule);
+
+    return handle;
+}
+
+static void test_create_and_fail(const char *manifest, const char *depmanifest)
+{
+    ACTCTXW actctx;
+    HANDLE handle;
+
+    memset(&actctx, 0, sizeof(ACTCTXW));
+    actctx.cbSize = sizeof(ACTCTXW);
+    actctx.lpSource = manifest_file;
+
+    create_manifest_file(manifest_file, manifest);
+    if(depmanifest)
+        create_manifest_file(depmanifest_file, depmanifest);
+    handle = pCreateActCtxW(&actctx);
+    ok(handle == INVALID_HANDLE_VALUE, "handle != INVALID_HANDLE_VALUE\n");
+    ok(GetLastError() == ERROR_SXS_CANT_GEN_ACTCTX, "GetLastError == %u\n", GetLastError());
+}
+
+static void test_create_fail(void)
+{
+    ACTCTXW actctx;
+    HANDLE handle;
+
+    memset(&actctx, 0, sizeof(ACTCTXW));
+    actctx.cbSize = sizeof(ACTCTXW);
+    actctx.lpSource = manifest_file;
+
+    handle = pCreateActCtxW(&actctx);
+    ok(handle == INVALID_HANDLE_VALUE, "handle != INVALID_HANDLE_VALUE\n");
+    ok(GetLastError() == ERROR_FILE_NOT_FOUND, "GetLastError == %u\n", GetLastError());
+
+    test_create_and_fail(wrong_manifest1, NULL);
+    test_create_and_fail(wrong_manifest2, NULL);
+    test_create_and_fail(wrong_manifest3, NULL);
+    test_create_and_fail(wrong_manifest4, NULL);
+    test_create_and_fail(wrong_manifest5, NULL);
+    test_create_and_fail(wrong_manifest6, NULL);
+    test_create_and_fail(wrong_manifest7, NULL);
+    test_create_and_fail(wrong_manifest8, NULL);
+    test_create_and_fail(manifest2, NULL);
+    test_create_and_fail(manifest2, wrong_depmanifest1);
+
+    DeleteFileW(manifest_file);
+}
+
+static void test_actctx(void)
+{
+    ULONG_PTR cookie;
+    HANDLE handle;
+    BOOL b;
+
+    DeleteFileW(manifest_file);
+
+    test_create_fail();
+
+    b = pGetCurrentActCtx(&handle);
+    ok(b, "GetCurrentActCtx failed: %u\n", GetLastError());
+    if(0 && b) {
+        test_detailed_info(handle, &detailed_info0);
+        pReleaseActCtx(handle);
+    }
+
+    if(!create_manifest_file(manifest_file, manifest1)) {
+        skip("Could not create manifest file\n");
+        return;
+    }
+
+    trace("manifest1\n");
+
+    handle = test_create(manifest1);
+    DeleteFileW(manifest_file);
+    if(handle != INVALID_HANDLE_VALUE) {
+        test_detailed_info(handle, &detailed_info1);
+        test_info_in_assembly(handle, 1, &manifest1_info);
+
+        b = CloseHandle(handle);
+        ok(!b, "CloseHandle succeeded\n");
+        ok(GetLastError() == ERROR_INVALID_HANDLE, "GetLastError() == %u\n", GetLastError());
+
+        pReleaseActCtx(handle);
+    }
+
+    if(!create_manifest_file(manifest_file, manifest2)
+       || !create_manifest_file(depmanifest_file, testdep_manifest1)) {
+        skip("Could not create manifest file\n");
+        return;
+    }
+
+    trace("manifest2 depmanifest1\n");
+
+    handle = test_create(manifest2);
+    DeleteFileW(manifest_file);
+    DeleteFileW(depmanifest_file);
+    if(handle != INVALID_HANDLE_VALUE) {
+        test_detailed_info(handle, &detailed_info2);
+        test_info_in_assembly(handle, 1, &manifest2_info);
+        test_info_in_assembly(handle, 2, &depmanifest1_info);
+        pReleaseActCtx(handle);
+    }
+
+    if(!create_manifest_file(manifest_file, manifest2)
+       || !create_manifest_file(depmanifest_file, testdep_manifest2)) {
+        skip("Could not create manifest file\n");
+        return;
+    }
+
+    trace("manifest2 depmanifest2\n");
+
+    handle = test_create(manifest2);
+    DeleteFileW(manifest_file);
+    DeleteFileW(depmanifest_file);
+    if(handle != INVALID_HANDLE_VALUE) {
+        test_detailed_info(handle, &detailed_info2);
+        test_info_in_assembly(handle, 1, &manifest2_info);
+        test_info_in_assembly(handle, 2, &depmanifest2_info);
+        test_file_info(handle, 1, 0, testlib_dll);
+        test_file_info(handle, 1, 1, testlib2_dll);
+
+        b = pActivateActCtx(handle, &cookie);
+        ok(b, "ActivateActCtx failed: %u\n", GetLastError());
+        b = pDeactivateActCtx(0, cookie);
+        ok(b, "DeactivateActCtx failed: %u\n", GetLastError());
+
+        pReleaseActCtx(handle);
+    }
+
+    trace("manifest2 depmanifest3\n");
+
+    if(!create_manifest_file(manifest_file, manifest2)
+       || !create_manifest_file(depmanifest_file, testdep_manifest3)) {
+        skip("Could not create manifest file\n");
+        return;
+    }
+
+    handle = test_create(manifest2);
+    DeleteFileW(manifest_file);
+    DeleteFileW(depmanifest_file);
+    if(handle != INVALID_HANDLE_VALUE) {
+        test_detailed_info(handle, &detailed_info2);
+        test_info_in_assembly(handle, 1, &manifest2_info);
+        test_info_in_assembly(handle, 2, &depmanifest3_info);
+        test_file_info(handle, 1, 0, testlib_dll);
+        test_file_info(handle, 1, 1, testlib2_dll);
+
+        b = pActivateActCtx(handle, &cookie);
+        ok(b, "ActivateActCtx failed: %u\n", GetLastError());
+        b = pDeactivateActCtx(0, cookie);
+        ok(b, "DeactivateActCtx failed: %u\n", GetLastError());
+
+        pReleaseActCtx(handle);
+    }
+
+    trace("manifest3\n");
+
+    if(!create_manifest_file(manifest_file, manifest3)) {
+        skip("Could not create manifest file\n");
+        return;
+    }
+
+    handle = test_create(manifest3);
+    DeleteFileW(manifest_file);
+    if(handle != INVALID_HANDLE_VALUE) {
+        test_detailed_info(handle, &detailed_info1);
+        test_info_in_assembly(handle, 1, &manifest3_info);
+        test_file_info(handle, 0, 0, testlib_dll);
+
+        b = pActivateActCtx(handle, &cookie);
+        ok(b, "ActivateActCtx failed: %u\n", GetLastError());
+        b = pDeactivateActCtx(0, cookie);
+        ok(b, "DeactivateActCtx failed: %u\n", GetLastError());
+
+        pReleaseActCtx(handle);
+    }
+}
+
+static void init_paths(void)
+{
+    LPWSTR ptr;
+
+    GetModuleFileNameW(NULL, exe_path, sizeof(exe_path)/sizeof(WCHAR));
+    lstrcpyW(app_dir, exe_path);
+    for(ptr=app_dir+lstrlenW(app_dir); *ptr != '\\'; ptr--);
+    ptr[1] = 0;
+
+    GetFullPathNameW(manifest_file, sizeof(manifest_path)/sizeof(WCHAR), manifest_path, NULL);
+    GetFullPathNameW(depmanifest_file, sizeof(depmanifest_path)/sizeof(WCHAR), depmanifest_path, NULL);
+}
+
+static BOOL init_funcs(void)
+{
+    HMODULE hKernel32 = GetModuleHandle("kernel32");
+
+#define X(f) \
+    p##f = (void*)GetProcAddress(hKernel32, #f);              \
+    if (!p##f) return FALSE;
+
+    X(ActivateActCtx);
+    X(CreateActCtxW);
+    X(DeactivateActCtx);
+    X(GetCurrentActCtx);
+    X(QueryActCtxW);
+    X(ReleaseActCtx);
+#undef X
+
+    return TRUE;
+}
+
+START_TEST(actctx)
+{
+    init_paths();
+    if (!init_funcs())
+    {
+        skip("Couldn't load kernel32\n");
+        return;
+    }
+
+    test_actctx();
+}





More information about the wine-patches mailing list