[PATCH 4/5] shcore: Add process reference API.
Nikolay Sivov
nsivov at codeweavers.com
Tue Nov 27 02:55:47 CST 2018
Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
---
configure | 1 +
configure.ac | 1 +
dlls/shcore/main.c | 29 +++++++
dlls/shcore/shcore.spec | 4 +-
dlls/shcore/tests/Makefile.in | 4 +
dlls/shcore/tests/shcore.c | 140 ++++++++++++++++++++++++++++++++++
6 files changed, 177 insertions(+), 2 deletions(-)
create mode 100644 dlls/shcore/tests/Makefile.in
create mode 100644 dlls/shcore/tests/shcore.c
diff --git a/configure b/configure
index bb2817c074..45d0bc8023 100755
--- a/configure
+++ b/configure
@@ -19799,6 +19799,7 @@ wine_fn_config_makefile dlls/setupx.dll16 enable_win16
wine_fn_config_makefile dlls/sfc enable_sfc
wine_fn_config_makefile dlls/sfc_os enable_sfc_os
wine_fn_config_makefile dlls/shcore enable_shcore
+wine_fn_config_makefile dlls/shcore/tests enable_tests
wine_fn_config_makefile dlls/shdoclc enable_shdoclc
wine_fn_config_makefile dlls/shdocvw enable_shdocvw
wine_fn_config_makefile dlls/shdocvw/tests enable_tests
diff --git a/configure.ac b/configure.ac
index 8bf5e109e6..7fce8ef35f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3654,6 +3654,7 @@ WINE_CONFIG_MAKEFILE(dlls/setupx.dll16,enable_win16)
WINE_CONFIG_MAKEFILE(dlls/sfc)
WINE_CONFIG_MAKEFILE(dlls/sfc_os)
WINE_CONFIG_MAKEFILE(dlls/shcore)
+WINE_CONFIG_MAKEFILE(dlls/shcore/tests)
WINE_CONFIG_MAKEFILE(dlls/shdoclc)
WINE_CONFIG_MAKEFILE(dlls/shdocvw)
WINE_CONFIG_MAKEFILE(dlls/shdocvw/tests)
diff --git a/dlls/shcore/main.c b/dlls/shcore/main.c
index 7f423c1edd..488e78eb86 100644
--- a/dlls/shcore/main.c
+++ b/dlls/shcore/main.c
@@ -36,6 +36,7 @@
WINE_DEFAULT_DEBUG_CHANNEL(shcore);
static DWORD shcore_tls;
+static IUnknown *process_ref;
BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, void *reserved)
{
@@ -1261,3 +1262,31 @@ HRESULT WINAPI SHReleaseThreadRef(void)
FIXME("() - stub!\n");
return S_OK;
}
+
+/*************************************************************************
+ * GetProcessReference [SHCORE.@]
+ */
+HRESULT WINAPI GetProcessReference(IUnknown **obj)
+{
+ TRACE("(%p)\n", obj);
+
+ *obj = process_ref;
+
+ if (!process_ref)
+ return E_FAIL;
+
+ if (*obj)
+ IUnknown_AddRef(*obj);
+
+ return S_OK;
+}
+
+/*************************************************************************
+ * SetProcessReference [SHCORE.@]
+ */
+void WINAPI SetProcessReference(IUnknown *obj)
+{
+ TRACE("(%p)\n", obj);
+
+ process_ref = obj;
+}
diff --git a/dlls/shcore/shcore.spec b/dlls/shcore/shcore.spec
index 568cb20597..c98f2db54a 100644
--- a/dlls/shcore/shcore.spec
+++ b/dlls/shcore/shcore.spec
@@ -10,7 +10,7 @@
@ stdcall GetDpiForMonitor(long long ptr ptr)
@ stub GetDpiForShellUIComponent
@ stdcall GetProcessDpiAwareness(long ptr)
-@ stub GetProcessReference
+@ stdcall GetProcessReference(ptr)
@ stub GetScaleFactorForDevice
@ stub GetScaleFactorForMonitor
@ stub IStream_Copy
@@ -79,7 +79,7 @@
@ stdcall SHUnicodeToUnicode(wstr ptr long) shlwapi.SHUnicodeToUnicode
@ stdcall SetCurrentProcessExplicitAppUserModelID(wstr)
@ stdcall SetProcessDpiAwareness(long)
-@ stub SetProcessReference
+@ stdcall SetProcessReference(ptr)
@ stub UnregisterScaleChangeEvent
100 stub @
diff --git a/dlls/shcore/tests/Makefile.in b/dlls/shcore/tests/Makefile.in
new file mode 100644
index 0000000000..0ea769a348
--- /dev/null
+++ b/dlls/shcore/tests/Makefile.in
@@ -0,0 +1,4 @@
+TESTDLL = shcore.dll
+
+C_SRCS = \
+ shcore.c
diff --git a/dlls/shcore/tests/shcore.c b/dlls/shcore/tests/shcore.c
new file mode 100644
index 0000000000..de6a921fc2
--- /dev/null
+++ b/dlls/shcore/tests/shcore.c
@@ -0,0 +1,140 @@
+/*
+ * Copyright 2018 Nikolay Sivov 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
+ */
+
+#define COBJMACROS
+
+#include <stdarg.h>
+
+#include <windows.h>
+#include "initguid.h"
+#include "objidl.h"
+
+#include "wine/test.h"
+
+static HRESULT (WINAPI *pGetProcessReference)(IUnknown **);
+static void (WINAPI *pSetProcessReference)(IUnknown *);
+static HRESULT (WINAPI *pSHGetInstanceExplorer)(IUnknown **);
+
+static void init(HMODULE hshcore)
+{
+#define X(f) p##f = (void*)GetProcAddress(hshcore, #f)
+ X(GetProcessReference);
+ X(SetProcessReference);
+#undef X
+}
+
+static HRESULT WINAPI unk_QI(IUnknown *iface, REFIID riid, void **obj)
+{
+ if (IsEqualIID(riid, &IID_IUnknown))
+ {
+ *obj = iface;
+ IUnknown_AddRef(iface);
+ return S_OK;
+ }
+
+ *obj = NULL;
+ return E_NOINTERFACE;
+}
+
+struct test_unk
+{
+ IUnknown IUnknown_iface;
+ LONG refcount;
+};
+
+static struct test_unk *impl_from_IUnknown(IUnknown *iface)
+{
+ return CONTAINING_RECORD(iface, struct test_unk, IUnknown_iface);
+}
+
+static ULONG WINAPI unk_AddRef(IUnknown *iface)
+{
+ struct test_unk *obj = impl_from_IUnknown(iface);
+ return InterlockedIncrement(&obj->refcount);
+}
+
+static ULONG WINAPI unk_Release(IUnknown *iface)
+{
+ struct test_unk *obj = impl_from_IUnknown(iface);
+ return InterlockedDecrement(&obj->refcount);
+}
+
+static const IUnknownVtbl testunkvtbl =
+{
+ unk_QI,
+ unk_AddRef,
+ unk_Release,
+};
+
+static void test_unk_init(struct test_unk *testunk)
+{
+ testunk->IUnknown_iface.lpVtbl = &testunkvtbl;
+ testunk->refcount = 1;
+}
+
+static void test_process_reference(void)
+{
+ struct test_unk test_unk, test_unk2;
+ IUnknown *obj;
+ HMODULE hmod;
+ HRESULT hr;
+
+ obj = (void *)0xdeadbeef;
+ hr = pGetProcessReference(&obj);
+ ok(hr == E_FAIL, "Unexpected hr %#x.\n", hr);
+ ok(obj == NULL, "Unexpected pointer.\n");
+
+ test_unk_init(&test_unk);
+ test_unk_init(&test_unk2);
+
+ pSetProcessReference(&test_unk.IUnknown_iface);
+ ok(test_unk.refcount == 1, "Unexpected refcount %u.\n", test_unk.refcount);
+ pSetProcessReference(&test_unk2.IUnknown_iface);
+ ok(test_unk.refcount == 1, "Unexpected refcount %u.\n", test_unk.refcount);
+ ok(test_unk2.refcount == 1, "Unexpected refcount %u.\n", test_unk2.refcount);
+
+ hr = pGetProcessReference(&obj);
+ ok(hr == S_OK, "Failed to get reference, hr %#x.\n", hr);
+ ok(obj == &test_unk2.IUnknown_iface, "Unexpected pointer.\n");
+ ok(test_unk2.refcount == 2, "Unexpected refcount %u.\n", test_unk2.refcount);
+
+ hmod = LoadLibraryA("shell32.dll");
+
+ pSHGetInstanceExplorer = (void *)GetProcAddress(hmod, "SHGetInstanceExplorer");
+ hr = pSHGetInstanceExplorer(&obj);
+todo_wine {
+ ok(hr == S_OK, "Failed to get reference, hr %#x.\n", hr);
+ ok(obj == &test_unk2.IUnknown_iface, "Unexpected pointer.\n");
+ ok(test_unk2.refcount == 3, "Unexpected refcount %u.\n", test_unk2.refcount);
+}
+}
+
+START_TEST(shcore)
+{
+ HMODULE hshcore = LoadLibraryA("shcore.dll");
+
+ if (!hshcore)
+ {
+ win_skip("Shcore.dll is not available.\n");
+ return;
+ }
+
+ init(hshcore);
+
+ test_process_reference();
+}
--
2.19.2
More information about the wine-devel
mailing list