From d315fd93d34009bf6e4d5b5dccca6a5364eb4e5b Mon Sep 17 00:00:00 2001 From: Mark Jansen Date: Sat, 3 Aug 2019 15:13:21 +0200 Subject: [PATCH] [FONTEXT_APITEST] Add simple api test showing interfaces CORE-14690 --- modules/rostests/apitests/CMakeLists.txt | 1 + .../rostests/apitests/fontext/CMakeLists.txt | 22 ++ .../rostests/apitests/fontext/shellext.cpp | 194 ++++++++++++++++++ modules/rostests/apitests/fontext/testlist.c | 12 ++ 4 files changed, 229 insertions(+) create mode 100644 modules/rostests/apitests/fontext/CMakeLists.txt create mode 100644 modules/rostests/apitests/fontext/shellext.cpp create mode 100644 modules/rostests/apitests/fontext/testlist.c diff --git a/modules/rostests/apitests/CMakeLists.txt b/modules/rostests/apitests/CMakeLists.txt index 1d623104fc7..8910f89b56a 100644 --- a/modules/rostests/apitests/CMakeLists.txt +++ b/modules/rostests/apitests/CMakeLists.txt @@ -12,6 +12,7 @@ add_subdirectory(crt) add_subdirectory(dbghelp) add_subdirectory(dciman32) add_subdirectory(dnsapi) +add_subdirectory(fontext) add_subdirectory(gdi32) add_subdirectory(gditools) add_subdirectory(iphlpapi) diff --git a/modules/rostests/apitests/fontext/CMakeLists.txt b/modules/rostests/apitests/fontext/CMakeLists.txt new file mode 100644 index 00000000000..80654e4d7d5 --- /dev/null +++ b/modules/rostests/apitests/fontext/CMakeLists.txt @@ -0,0 +1,22 @@ + +add_definitions( + -D__ROS_LONG64__ + -DWINETEST_USE_DBGSTR_LONGLONG + -DUNICODE + -D_UNICODE + -D_ATL_NO_EXCEPTIONS) + +set_cpp(WITH_RUNTIME) + +include_directories(${REACTOS_SOURCE_DIR}/sdk/lib/atl + ${CMAKE_CURRENT_BINARY_DIR}) + +list(APPEND SOURCE + shellext.cpp + testlist.c) + +add_executable(fontext_apitest ${SOURCE}) +set_module_type(fontext_apitest win32cui) +target_link_libraries(fontext_apitest uuid ${PSEH_LIB}) +add_importlibs(fontext_apitest oleaut32 ole32 shell32 user32 msvcrt kernel32 ntdll) +add_rostests_file(TARGET fontext_apitest) diff --git a/modules/rostests/apitests/fontext/shellext.cpp b/modules/rostests/apitests/fontext/shellext.cpp new file mode 100644 index 00000000000..00480a7497c --- /dev/null +++ b/modules/rostests/apitests/fontext/shellext.cpp @@ -0,0 +1,194 @@ +/* + * PROJECT: fontext_apitest + * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later) + * PURPOSE: Tests for fontext shell extension behavior + * COPYRIGHT: Copyright 2019 Mark Jansen (mark.jansen@reactos.org) + */ + +#include +#define WIN32_NO_STATUS +#include +#include +#include +#include +#include +#include +#include +#include +#include "wine/test.h" + +const CLSID CLSID_FontExt = { 0xBD84B380, 0x8CA2, 0x1069, { 0xAB, 0x1D, 0x08, 0x00, 0x09, 0x48, 0xF5, 0x34 } }; +static DWORD g_WinVersion; + + +static HRESULT Initialize(CComPtr& spFolder, LPCWSTR Path) +{ + CComHeapPtr pidl; + CComPtr spDesktop; + + HRESULT hr = SHGetDesktopFolder(&spDesktop); + ok_hex(hr, S_OK); + if (FAILED(hr)) + return hr; + + DWORD Attributes = 0, chEaten = 0; + hr = spDesktop->ParseDisplayName(NULL, NULL, (LPOLESTR)Path, &chEaten, &pidl, &Attributes); + ok_hex(hr, S_OK); + if (FAILED(hr)) + return hr; + + return spFolder->Initialize(pidl); +} + + +static void CreateObjectsFromPersistFolder() +{ + WCHAR Path[MAX_PATH] = { 0 }; + + CComPtr spFolder; + HRESULT hr = CoCreateInstance(CLSID_FontExt, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IPersistFolder, &spFolder)); + ok_hex(hr, S_OK); + if (!SUCCEEDED(hr)) + return; + + hr = SHGetFolderPathW(NULL, CSIDL_WINDOWS, NULL, 0, Path); + ok_hex(hr, S_OK); + if (FAILED(hr)) + return; + + // Initializing this in another folder fails + hr = Initialize(spFolder, Path); + ok_hex(hr, E_FAIL); + + hr = SHGetFolderPathW(NULL, CSIDL_FONTS, NULL, 0, Path); + ok_hex(hr, S_OK); + if (FAILED(hr)) + return; + + // Initializing it in the font folder works + hr = Initialize(spFolder, Path); + ok_hex(hr, S_OK); + + // For ros we do not implement the ShellView, but go directly to the ShellFolder. + // So we detect this special case + if (g_WinVersion < _WIN32_WINNT_VISTA) + { + CComPtr spShellFolder; + hr = spFolder->QueryInterface(IID_PPV_ARG(IShellFolder, &spShellFolder)); + + if (SUCCEEDED(hr)) + { + trace("Got IShellFolder on < Vista, faking 0x601\n"); + g_WinVersion = _WIN32_WINNT_WIN7; + } + } + + if (g_WinVersion < _WIN32_WINNT_VISTA) + { + // A view is present + CComPtr spView; + hr = spFolder->QueryInterface(IID_PPV_ARG(IShellView, &spView)); + ok_hex(hr, S_OK); + + // No shell folder + CComPtr spShellFolder; + hr = spFolder->QueryInterface(IID_PPV_ARG(IShellFolder, &spShellFolder)); + ok_hex(hr, E_NOINTERFACE); + + // Ask the view: + if (spView) + { + CComPtr spObjectWithSite; + hr = spView->QueryInterface(IID_PPV_ARG(IObjectWithSite, &spObjectWithSite)); + ok_hex(hr, E_NOINTERFACE); + + CComPtr spISM; + hr = spView->QueryInterface(IID_PPV_ARG(IInternetSecurityManager, &spISM)); + ok_hex(hr, E_NOINTERFACE); + } + + + CComPtr spDropTarget; + hr = spFolder->QueryInterface(IID_PPV_ARG(IDropTarget, &spDropTarget)); + ok_hex(hr, S_OK); + + CComPtr spExtractIcon; + hr = spFolder->QueryInterface(IID_PPV_ARG(IExtractIconW, &spExtractIcon)); + ok_hex(hr, E_NOINTERFACE); + } + else + { + // Here we have a shell folder + CComPtr spShellFolder; + hr = spFolder->QueryInterface(IID_PPV_ARG(IShellFolder, &spShellFolder)); + ok_hex(hr, S_OK); + + // But no view anymore + CComPtr spView; + hr = spFolder->QueryInterface(IID_PPV_ARG(IShellView, &spView)); + ok_hex(hr, E_NOINTERFACE); + spView.Release(); + + + CComPtr spDropTarget; + hr = spFolder->QueryInterface(IID_PPV_ARG(IDropTarget, &spDropTarget)); + ok_hex(hr, E_NOINTERFACE); + + CComPtr spExtractIcon; + hr = spFolder->QueryInterface(IID_PPV_ARG(IExtractIconW, &spExtractIcon)); + ok_hex(hr, E_NOINTERFACE); + } +} + + +static void CreateDropTarget() +{ + CComPtr spDropTarget; + HRESULT hr = CoCreateInstance(CLSID_FontExt, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IDropTarget, &spDropTarget)); + ok_hex(hr, E_NOINTERFACE); +} + +static void CreateExtractIcon() +{ + if (g_WinVersion < _WIN32_WINNT_VISTA) + { + CComPtr spExtractIconA; + HRESULT hr = CoCreateInstance(CLSID_FontExt, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IExtractIconA, &spExtractIconA)); + ok_hex(hr, S_OK); + + CComPtr spExtractIconW; + hr = CoCreateInstance(CLSID_FontExt, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IExtractIconW, &spExtractIconW)); + ok_hex(hr, S_OK); + } + else + { + CComPtr spExtractIconA; + HRESULT hr = CoCreateInstance(CLSID_FontExt, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IExtractIconA, &spExtractIconA)); + ok_hex(hr, E_NOINTERFACE); + + CComPtr spExtractIconW; + hr = CoCreateInstance(CLSID_FontExt, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IExtractIconW, &spExtractIconW)); + ok_hex(hr, E_NOINTERFACE); + } +} + + + +START_TEST(shellext) +{ + RTL_OSVERSIONINFOEXW rtlinfo = {0}; + + rtlinfo.dwOSVersionInfoSize = sizeof(rtlinfo); + RtlGetVersion((PRTL_OSVERSIONINFOW)&rtlinfo); + g_WinVersion = (rtlinfo.dwMajorVersion << 8) | rtlinfo.dwMinorVersion; + + trace("g_WinVersion=0x%x\n", g_WinVersion); + + CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); + + CreateObjectsFromPersistFolder(); + CreateDropTarget(); + CreateExtractIcon(); + + CoUninitialize(); +} diff --git a/modules/rostests/apitests/fontext/testlist.c b/modules/rostests/apitests/fontext/testlist.c new file mode 100644 index 00000000000..08fc9631feb --- /dev/null +++ b/modules/rostests/apitests/fontext/testlist.c @@ -0,0 +1,12 @@ +/* Automatically generated file; DO NOT EDIT!! */ + +#define STANDALONE +#include + +extern void func_shellext(void); + +const struct test winetest_testlist[] = +{ + { "shellext", func_shellext }, + { 0, 0 } +}; -- 2.17.1