[PATCH] mscoree: Add test for registration-less COM components
Fabian Maurer
dark.shadow4 at web.de
Sat Jul 28 13:23:01 CDT 2018
I don't see a way to build the .NET dll as part of the test,
so I added a binary.
If you don't trust the .NET binary, just rebuilt it, source is included
(works with mono's csc)
Signed-off-by: Fabian Maurer <dark.shadow4 at web.de>
---
dlls/mscoree/tests/Makefile.in | 4 +
dlls/mscoree/tests/comtest.c | 254 ++++++++++++++++++++++++
dlls/mscoree/tests/comtest.cs | 23 +++
dlls/mscoree/tests/comtest.dll | Bin 0 -> 3584 bytes
dlls/mscoree/tests/comtest_dll.manifest | 16 ++
dlls/mscoree/tests/comtest_exe.manifest | 11 +
dlls/mscoree/tests/interfaces.idl | 33 +++
dlls/mscoree/tests/resource.rc | 30 +++
8 files changed, 371 insertions(+)
create mode 100644 dlls/mscoree/tests/comtest.c
create mode 100644 dlls/mscoree/tests/comtest.cs
create mode 100644 dlls/mscoree/tests/comtest.dll
create mode 100644 dlls/mscoree/tests/comtest_dll.manifest
create mode 100644 dlls/mscoree/tests/comtest_exe.manifest
create mode 100644 dlls/mscoree/tests/interfaces.idl
create mode 100644 dlls/mscoree/tests/resource.rc
diff --git a/dlls/mscoree/tests/Makefile.in b/dlls/mscoree/tests/Makefile.in
index 7c1ba5cb11..9e53b7c577 100644
--- a/dlls/mscoree/tests/Makefile.in
+++ b/dlls/mscoree/tests/Makefile.in
@@ -2,6 +2,10 @@ TESTDLL = mscoree.dll
IMPORTS = ole32 shlwapi uuid
C_SRCS = \
+ comtest.c \
debugging.c \
metahost.c \
mscoree.c
+
+RC_SRCS = resource.rc
+IDL_SRCS = interfaces.idl
diff --git a/dlls/mscoree/tests/comtest.c b/dlls/mscoree/tests/comtest.c
new file mode 100644
index 0000000000..f3db35f7ef
--- /dev/null
+++ b/dlls/mscoree/tests/comtest.c
@@ -0,0 +1,254 @@
+/*
+ * Copyright 2018 Fabian Maurer
+ *
+ * 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
+ */
+
+#define COBJMACROS
+#include <stdio.h>
+
+#include "windows.h"
+#include "ole2.h"
+#include "mscoree.h"
+#include "corerror.h"
+
+#include "wine/test.h"
+
+#include "initguid.h"
+#include "interfaces.h"
+
+HMODULE hmscoree;
+
+static BOOL write_resource_file(const char *path_tmp, const char *name_res, const char *name_file, char *path_file)
+{
+ HRSRC rsrc;
+ void *rsrc_data;
+ DWORD rsrc_size;
+ BOOL ret;
+ HANDLE hfile;
+
+ rsrc = FindResourceA(GetModuleHandleA(NULL), name_res, (LPCSTR)RT_RCDATA);
+ if (!rsrc) return FALSE;
+
+ rsrc_data = LockResource(LoadResource(GetModuleHandleA(NULL), rsrc));
+ if (!rsrc_data) return FALSE;
+
+ rsrc_size = SizeofResource(GetModuleHandleA(NULL), rsrc);
+ if (!rsrc_size) return FALSE;
+
+ sprintf(path_file, "%s%s", path_tmp, name_file);
+ hfile = CreateFileA(path_file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
+ if (hfile == INVALID_HANDLE_VALUE) return FALSE;
+
+ ret = WriteFile(hfile, rsrc_data, rsrc_size, &rsrc_size, NULL);
+
+ CloseHandle(hfile);
+ return ret;
+}
+
+typedef HRESULT (WINAPI *_DllGetClassObject)(REFCLSID rclsid, REFIID riid, LPVOID *ppv);
+
+static void run_test(int run)
+{
+ ITest *test = NULL;
+ HRESULT hr;
+ _DllGetClassObject getClassObject;
+ IClassFactory *classFactory = NULL;
+
+ hr = CoCreateInstance(&CLSID_Test, NULL, CLSCTX_INPROC_SERVER, &IID_ITest, (void**)&test);
+ if (hr == COR_E_NEWER_RUNTIME)
+ {
+ win_skip(".NET Framework 4 is not installed\n");
+ return;
+ }
+ todo_wine
+ ok(hr == S_OK, "Got %x\n", hr);
+
+ if (test)
+ {
+ int i = 0;
+ hr = ITest_Func(test, &i);
+ ok(hr == S_OK, "Got %x\n", hr);
+ ok(i == 42, "Expected 42, got %d\n", i);
+ }
+
+ getClassObject = (_DllGetClassObject)GetProcAddress(LoadLibraryA("mscoree"), "DllGetClassObject");
+ hr = getClassObject(&CLSID_Test, &IID_IClassFactory, (void **)&classFactory);
+ ok(hr == S_OK, "Got %x\n", hr);
+
+ if (classFactory)
+ {
+ ITest *test2 = NULL;
+ hr = IClassFactory_CreateInstance(classFactory, NULL, &IID_ITest, (void **)&test2);
+ todo_wine
+ ok(hr == S_OK, "Got %x\n", hr);
+
+ if (test2)
+ {
+ int i = 0;
+ hr = ITest_Func(test2, &i);
+ ok(hr == S_OK, "Got %x\n", hr);
+ ok(i == 42, "Expected 42, got %d\n", i);
+ }
+ }
+}
+
+static void prepare_and_run_test(int run, const char *dll)
+{
+ char path_tmp[MAX_PATH] = {0};
+ char path_dll[MAX_PATH] = {0};
+ char path_current[MAX_PATH] = {0};
+ char path_manifest_dll[MAX_PATH] = {0};
+ char path_manifest_exe[MAX_PATH] = {0};
+ BOOL success;
+ ACTCTXA context = {0};
+ ULONG_PTR cookie;
+ HANDLE handle_context = 0;
+
+ GetCurrentDirectoryA(MAX_PATH, path_current);
+ GetTempPathA(MAX_PATH, path_tmp);
+
+ if (!write_resource_file(path_current, dll, "comtest.dll", path_dll))
+ {
+ skip("run %d: Failed to create file for testing\n", run);
+ goto cleanup;
+ }
+
+ if (!write_resource_file(path_tmp, "comtest_exe.manifest", "exe.manifest", path_manifest_exe))
+ {
+ skip("run %d: Failed to create file for testing\n", run);
+ goto cleanup;
+ }
+
+ if (!write_resource_file(path_tmp, "comtest_dll.manifest", "comtest.manifest", path_manifest_dll))
+ {
+ skip("run %d: Failed to create file for testing\n", run);
+ goto cleanup;
+ }
+
+ context.cbSize = sizeof(ACTCTXA);
+ context.lpSource = path_manifest_exe;
+ context.lpAssemblyDirectory = path_tmp;
+ context.dwFlags = ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID;
+
+ handle_context = CreateActCtxA(&context);
+ ok(handle_context != NULL && handle_context != INVALID_HANDLE_VALUE, "run %d: CreateActCtxA failed: %d\n", run, GetLastError());
+
+ if (handle_context == NULL || handle_context == INVALID_HANDLE_VALUE)
+ {
+ skip("Failed to create activation context\n");
+ goto cleanup;
+ }
+
+ success = ActivateActCtx(handle_context, &cookie);
+ ok(success, "run %d: ActivateActCtx failed: %d\n", run, GetLastError());
+
+ run_test(run);
+
+cleanup:
+ if (handle_context != NULL && handle_context != INVALID_HANDLE_VALUE)
+ {
+ success = DeactivateActCtx(0, cookie);
+ ok(success, "run %d: DeactivateActCtx failed: %d\n", run, GetLastError());
+ ReleaseActCtx(handle_context);
+ }
+ if (*path_manifest_exe)
+ {
+ success = DeleteFileA(path_manifest_exe);
+ ok(success, "run %d: DeleteFileA failed: %d\n", run, GetLastError());
+ }
+ if(*path_manifest_dll)
+ {
+ success = DeleteFileA(path_manifest_dll);
+ ok(success, "run %d: DeleteFileA failed: %d\n", run, GetLastError());
+ }
+return;
+ /* dll cleanup is handled by the parent, because it might still be used by the child */
+}
+
+
+static void cleanup_test(int run)
+{
+ char path_current[MAX_PATH] = {0};
+ char path_dll[MAX_PATH] = {0};
+ BOOL success;
+
+ GetCurrentDirectoryA(MAX_PATH, path_current);
+ sprintf(path_dll, "%s%s", path_current, "comtest.dll");
+
+ success = DeleteFileA(path_dll);
+ ok(success, "run %d: DeleteFileA failed: %d\n", run, GetLastError());
+}
+
+static void run_child_process(int run, const char *dll)
+{
+ char cmdline[MAX_PATH];
+ char exe[MAX_PATH];
+ char **argv;
+ PROCESS_INFORMATION pi;
+ STARTUPINFOA si = { 0 };
+ BOOL ret;
+
+ winetest_get_mainargs(&argv);
+
+ if (strstr(argv[0], ".exe"))
+ sprintf(exe, "%s", argv[0]);
+ else
+ sprintf(exe, "%s.exe", argv[0]);
+ sprintf(cmdline, "\"%s\" %s %d %s", argv[0], argv[1], run, dll);
+
+ si.cb = sizeof(si);
+ ret = CreateProcessA(exe, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
+ ok(ret, "Could not create process: %u\n", GetLastError());
+
+ winetest_wait_child_process(pi.hProcess);
+
+ CloseHandle(pi.hThread);
+ CloseHandle(pi.hProcess);
+
+ /* Cleanup dll, because it might still have been used by the child */
+ cleanup_test(run);
+}
+
+START_TEST(comtest)
+{
+ int argc;
+ char **argv;
+
+ CoInitialize(NULL);
+
+ argc = winetest_get_mainargs(&argv);
+ if (argc > 2)
+ {
+ int run = atoi(argv[2]);
+ const char *dll = argv[3];
+ prepare_and_run_test(run, dll);
+
+ CoUninitialize();
+ return;
+ }
+
+ hmscoree = LoadLibraryA("mscoree.dll");
+ if (!hmscoree)
+ {
+ skip(".NET or mono not available\n");
+ return;
+ }
+
+ run_child_process(1, "comtest.dll");
+
+ FreeLibrary(hmscoree);
+ CoUninitialize();
+}
diff --git a/dlls/mscoree/tests/comtest.cs b/dlls/mscoree/tests/comtest.cs
new file mode 100644
index 0000000000..64c67ccc9d
--- /dev/null
+++ b/dlls/mscoree/tests/comtest.cs
@@ -0,0 +1,23 @@
+/* Compile with
+ csc /target:library /out:dll.dll comtest.cs
+*/
+
+using System.Runtime.InteropServices;
+
+namespace DLL
+{
+ [Guid("1dbc4491-080d-45c5-a15d-1e3c4610bdd9"), ComVisible(true), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ public interface ITest
+ {
+ void Func(ref int i);
+ }
+
+ [Guid("2e106e50-e7a4-4489-8538-83643f100fdc"), ComVisible(true), ClassInterface(ClassInterfaceType.None)]
+ public class Test : ITest
+ {
+ public void Func(ref int i)
+ {
+ i = 42;
+ }
+ }
+}
diff --git a/dlls/mscoree/tests/comtest.dll b/dlls/mscoree/tests/comtest.dll
new file mode 100644
index 0000000000000000000000000000000000000000..71b95583fc419b073cbb349006bbb90f26905ef1
GIT binary patch
literal 3584
zcmeHJOK%%h6#m9};HES*Aey#3I&D(a2R36oE-9emCT>frv<b1B at +fM?<B2n9JY&s_
zOVULZp at PH)b;Xt<!3MElfkcJGlGmau`U5H<Sn}9aEE>LZZO3t`ia at G_L{D<RIj?&j
z_s-nw6R%!E4}e~d)m7jMpF(+scZL<32X}lqh|f1%-FZcuy1KKp=tg=y46313({0Q5
zgIF&+df4!F*VhZvMZFeOob;wm1Ea0bGe>|atp~?HIrCaO+jZ>HH);mZPmK)HO_`u`
z<T-%Nicd7_7KPNWXoX0<P!IBNi>v&1o-I*Sq)!=lT9`a=xiwG3HJS(RUlaZTqXWrx
z?n%lou9MTTvlLVA?IX~p`n)AS)${2v3T>KIZFw@%==#7Esm`ZE#|!AFYMrN2V%<_W
z{l=;7qU*A*B&jWdKFsUf59ZKB`7dZYdUot9?c0^u!y*T;Z at hSXTx&&>a?Y7)Bb_y}
znS&C%4<7L%lZ{*ee&aJ1z8HtDUya10!k1H89ywLSB6-=$kz=PO3w$n7z9#ax7nJ!F
zV%yrWVPJy at e`r~3Y4);_BHh)HrIG$*8O2X{8Ng4iXFooMq4ncyg$uZe2QWjIe&jJk
z{dt9tDtu32O5sU`XSLr|v}R1{{zJ+O+5k}`ja^hJrN~JwLf`Za<0;BBx=253A|-HI
zN$+gE!OT*<h96tl!|FHS1~o&(erzKSU at vhqGQ@{*n7AD;5p}#m>_-|Kkt05YL&Qh$
zIwmlJ1>$~OB4+VEY-&CripIus_#VA0OxZ;q8<Rb0(-RnMv%vEwf=a`44xunLg<50>
zq34!ywBg&B2x^ml?1T%J?Ua`54kkP+in>+D8gAuq%>6Gn;#(a$`hrt#RI66mb2>Uk
zpK~L(OV<^<%eC%$R_q4;tm9crii<k-*@hpxHHQ)FG?iV?jh8!C7j{sKohVLMJP*a?
zD0XT{+i?)Kgml5Rs(ui~t{t^it&nL|QBW^B;W^iK{$iGtuIGen_GYL28n~=<pDw at Q
z*fAzcOy4d;t^I{(zrFZFCUyL+{of5I%MT8tSJ$*;j}EPm%+QdCg8~U9Kc;YZ@{99l
z=C+yF-xYClGO4wWmdE8KEhV;`4z2phz(2BNJ9SyD(qb6A8EN#pPrclGHH>B|W!p3l
zW>UtOQAwFOJD0LDxk at VIWNq_6#wb at R{MP#<A~;dagG_wd$ruNmoRM;#vCNcdjvY*m
z<+5X`vFrgeyO1%Ag^I1Fv|p}kqiqiOMR>g<ujkrlT2ps+A_xnfcfxZ0=KJV4YU9MZ
zx|=c7?XZ6S|Cg7O3D^p(bgw~k+l<@j#ZT^zm-9fOeV9=$BuwHQia1L=f?0BtylGET
zo+KV^-n#gz_t%^4)0Y$0=!F(1=ghjWN?RamjA|id9G7>9!<ar#vOw8K)#+5C)uJ|{
z-9k*ifKrn_>-~uDp~jkGdb!kBZxd-n`50*bnJAM7o at 7PZnty@WBc7EKr{0xEr?0^;
zs^dFH-;my&S`41VodJyT($-WrvGVm<yT|piP@@dy3CM{pBBoKHRqoI|s-`LGt7^ss
z{pwg&RaLP_U#QO|ui{U)^wPP+Z?B?Acg|y~er7m7VD1L%iMbQqU3L1A-lQj4gTt&i
iqGye(=&>^WZ|8C9J-XW~ptpV|=I(Z)d-4B^EAS`sU3HTH
literal 0
HcmV?d00001
diff --git a/dlls/mscoree/tests/comtest_dll.manifest b/dlls/mscoree/tests/comtest_dll.manifest
new file mode 100644
index 0000000000..bab62ef1f0
--- /dev/null
+++ b/dlls/mscoree/tests/comtest_dll.manifest
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+ <assemblyIdentity
+ name="comtest"
+ version="1.0.0.0"
+ type="win32"
+ />
+ <clrClass
+ clsid="{2e106e50-e7a4-4489-8538-83643f100fdc}"
+ threadingModel="Both"
+ name="DLL.Test"
+ runtimeVersion="v4.0.0.0">
+ </clrClass>
+ <file name="DLL.dll">
+ </file>
+</assembly>
diff --git a/dlls/mscoree/tests/comtest_exe.manifest b/dlls/mscoree/tests/comtest_exe.manifest
new file mode 100644
index 0000000000..4fec5ebc22
--- /dev/null
+++ b/dlls/mscoree/tests/comtest_exe.manifest
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+ <dependency>
+ <dependentAssembly>
+ <assemblyIdentity
+ name="comtest"
+ version="1.0.0.0"
+ type="win32"/>
+ </dependentAssembly>
+ </dependency>
+</assembly>
diff --git a/dlls/mscoree/tests/interfaces.idl b/dlls/mscoree/tests/interfaces.idl
new file mode 100644
index 0000000000..9e64988197
--- /dev/null
+++ b/dlls/mscoree/tests/interfaces.idl
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2018 Fabian Maurer
+ *
+ * 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 "unknwn.idl"
+
+[
+ object,
+ uuid(1dbc4491-080d-45c5-a15d-1e3c4610bdd9),
+ local
+]
+interface ITest : IUnknown {
+ HRESULT Func([in, out] int *i);
+};
+
+[
+ uuid(2e106e50-e7a4-4489-8538-83643f100fdc),
+]
+coclass Test { interface ITest; };
diff --git a/dlls/mscoree/tests/resource.rc b/dlls/mscoree/tests/resource.rc
new file mode 100644
index 0000000000..117ec55d46
--- /dev/null
+++ b/dlls/mscoree/tests/resource.rc
@@ -0,0 +1,30 @@
+/*
+ * Resources for mscoree test suite.
+ *
+ * Copyright 2018 Fabian Maurer
+ *
+ * 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 "windef.h"
+
+/* @makedep: comtest.dll */
+comtest.dll RCDATA comtest.dll
+
+/* @makedep: comtest_exe.manifest */
+comtest_exe.manifest RCDATA comtest_exe.manifest
+
+/* @makedep: comtest_dll.manifest */
+comtest_dll.manifest RCDATA comtest_dll.manifest
--
2.18.0
More information about the wine-devel
mailing list