1d315fd93SMark Jansen /*
2d315fd93SMark Jansen * PROJECT: fontext_apitest
3d315fd93SMark Jansen * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4d315fd93SMark Jansen * PURPOSE: Tests for fontext shell extension behavior
5d315fd93SMark Jansen * COPYRIGHT: Copyright 2019 Mark Jansen (mark.jansen@reactos.org)
6d315fd93SMark Jansen */
7d315fd93SMark Jansen
8d315fd93SMark Jansen #include <ntstatus.h>
9d315fd93SMark Jansen #define WIN32_NO_STATUS
10d315fd93SMark Jansen #include <windef.h>
11d315fd93SMark Jansen #include <ntndk.h>
12d315fd93SMark Jansen #include <atlbase.h>
13d315fd93SMark Jansen #include <atlcom.h>
14d315fd93SMark Jansen #include <shellapi.h>
15d315fd93SMark Jansen #include <shlobj.h>
16d315fd93SMark Jansen #include <shobjidl.h>
17d315fd93SMark Jansen #include <shellutils.h>
18d315fd93SMark Jansen #include "wine/test.h"
19d315fd93SMark Jansen
20*23b6397aSMark Jansen static const CLSID CLSID_FontExt = { 0xBD84B380, 0x8CA2, 0x1069, { 0xAB, 0x1D, 0x08, 0x00, 0x09, 0x48, 0xF5, 0x34 } };
21d315fd93SMark Jansen static DWORD g_WinVersion;
22d315fd93SMark Jansen
23d315fd93SMark Jansen
Initialize(CComPtr<IPersistFolder> & spFolder,LPCWSTR Path)24d315fd93SMark Jansen static HRESULT Initialize(CComPtr<IPersistFolder>& spFolder, LPCWSTR Path)
25d315fd93SMark Jansen {
26d315fd93SMark Jansen CComHeapPtr<ITEMIDLIST> pidl;
27d315fd93SMark Jansen CComPtr<IShellFolder> spDesktop;
28d315fd93SMark Jansen
29d315fd93SMark Jansen HRESULT hr = SHGetDesktopFolder(&spDesktop);
30d315fd93SMark Jansen ok_hex(hr, S_OK);
31d315fd93SMark Jansen if (FAILED(hr))
32d315fd93SMark Jansen return hr;
33d315fd93SMark Jansen
34d315fd93SMark Jansen DWORD Attributes = 0, chEaten = 0;
35d315fd93SMark Jansen hr = spDesktop->ParseDisplayName(NULL, NULL, (LPOLESTR)Path, &chEaten, &pidl, &Attributes);
36d315fd93SMark Jansen ok_hex(hr, S_OK);
37d315fd93SMark Jansen if (FAILED(hr))
38d315fd93SMark Jansen return hr;
39d315fd93SMark Jansen
40d315fd93SMark Jansen return spFolder->Initialize(pidl);
41d315fd93SMark Jansen }
42d315fd93SMark Jansen
43d315fd93SMark Jansen
CreateObjectsFromPersistFolder()44d315fd93SMark Jansen static void CreateObjectsFromPersistFolder()
45d315fd93SMark Jansen {
46d315fd93SMark Jansen WCHAR Path[MAX_PATH] = { 0 };
47d315fd93SMark Jansen
48d315fd93SMark Jansen CComPtr<IPersistFolder> spFolder;
49d315fd93SMark Jansen HRESULT hr = CoCreateInstance(CLSID_FontExt, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IPersistFolder, &spFolder));
50d315fd93SMark Jansen ok_hex(hr, S_OK);
51d315fd93SMark Jansen if (!SUCCEEDED(hr))
52d315fd93SMark Jansen return;
53d315fd93SMark Jansen
54d315fd93SMark Jansen hr = SHGetFolderPathW(NULL, CSIDL_WINDOWS, NULL, 0, Path);
55d315fd93SMark Jansen ok_hex(hr, S_OK);
56d315fd93SMark Jansen if (FAILED(hr))
57d315fd93SMark Jansen return;
58d315fd93SMark Jansen
59d315fd93SMark Jansen // Initializing this in another folder fails
60d315fd93SMark Jansen hr = Initialize(spFolder, Path);
61d315fd93SMark Jansen ok_hex(hr, E_FAIL);
62d315fd93SMark Jansen
63d315fd93SMark Jansen hr = SHGetFolderPathW(NULL, CSIDL_FONTS, NULL, 0, Path);
64d315fd93SMark Jansen ok_hex(hr, S_OK);
65d315fd93SMark Jansen if (FAILED(hr))
66d315fd93SMark Jansen return;
67d315fd93SMark Jansen
68d315fd93SMark Jansen // Initializing it in the font folder works
69d315fd93SMark Jansen hr = Initialize(spFolder, Path);
70d315fd93SMark Jansen ok_hex(hr, S_OK);
71d315fd93SMark Jansen
72d315fd93SMark Jansen // For ros we do not implement the ShellView, but go directly to the ShellFolder.
73d315fd93SMark Jansen // So we detect this special case
74d315fd93SMark Jansen if (g_WinVersion < _WIN32_WINNT_VISTA)
75d315fd93SMark Jansen {
76d315fd93SMark Jansen CComPtr<IShellFolder> spShellFolder;
77d315fd93SMark Jansen hr = spFolder->QueryInterface(IID_PPV_ARG(IShellFolder, &spShellFolder));
78d315fd93SMark Jansen
79d315fd93SMark Jansen if (SUCCEEDED(hr))
80d315fd93SMark Jansen {
81d315fd93SMark Jansen trace("Got IShellFolder on < Vista, faking 0x601\n");
82d315fd93SMark Jansen g_WinVersion = _WIN32_WINNT_WIN7;
83d315fd93SMark Jansen }
84d315fd93SMark Jansen }
85d315fd93SMark Jansen
86d315fd93SMark Jansen if (g_WinVersion < _WIN32_WINNT_VISTA)
87d315fd93SMark Jansen {
88d315fd93SMark Jansen // A view is present
89d315fd93SMark Jansen CComPtr<IShellView> spView;
90d315fd93SMark Jansen hr = spFolder->QueryInterface(IID_PPV_ARG(IShellView, &spView));
91d315fd93SMark Jansen ok_hex(hr, S_OK);
92d315fd93SMark Jansen
93d315fd93SMark Jansen // No shell folder
94d315fd93SMark Jansen CComPtr<IShellFolder> spShellFolder;
95d315fd93SMark Jansen hr = spFolder->QueryInterface(IID_PPV_ARG(IShellFolder, &spShellFolder));
96d315fd93SMark Jansen ok_hex(hr, E_NOINTERFACE);
97d315fd93SMark Jansen
98d315fd93SMark Jansen // Ask the view:
99d315fd93SMark Jansen if (spView)
100d315fd93SMark Jansen {
101d315fd93SMark Jansen CComPtr<IObjectWithSite> spObjectWithSite;
102d315fd93SMark Jansen hr = spView->QueryInterface(IID_PPV_ARG(IObjectWithSite, &spObjectWithSite));
103d315fd93SMark Jansen ok_hex(hr, E_NOINTERFACE);
104d315fd93SMark Jansen
105d315fd93SMark Jansen CComPtr<IInternetSecurityManager> spISM;
106d315fd93SMark Jansen hr = spView->QueryInterface(IID_PPV_ARG(IInternetSecurityManager, &spISM));
107d315fd93SMark Jansen ok_hex(hr, E_NOINTERFACE);
108d315fd93SMark Jansen }
109d315fd93SMark Jansen
110d315fd93SMark Jansen
111d315fd93SMark Jansen CComPtr<IDropTarget> spDropTarget;
112d315fd93SMark Jansen hr = spFolder->QueryInterface(IID_PPV_ARG(IDropTarget, &spDropTarget));
113d315fd93SMark Jansen ok_hex(hr, S_OK);
114d315fd93SMark Jansen
115d315fd93SMark Jansen CComPtr<IExtractIconW> spExtractIcon;
116d315fd93SMark Jansen hr = spFolder->QueryInterface(IID_PPV_ARG(IExtractIconW, &spExtractIcon));
117d315fd93SMark Jansen ok_hex(hr, E_NOINTERFACE);
118d315fd93SMark Jansen }
119d315fd93SMark Jansen else
120d315fd93SMark Jansen {
121d315fd93SMark Jansen // Here we have a shell folder
122d315fd93SMark Jansen CComPtr<IShellFolder> spShellFolder;
123d315fd93SMark Jansen hr = spFolder->QueryInterface(IID_PPV_ARG(IShellFolder, &spShellFolder));
124d315fd93SMark Jansen ok_hex(hr, S_OK);
125d315fd93SMark Jansen
126d315fd93SMark Jansen // But no view anymore
127d315fd93SMark Jansen CComPtr<IShellView> spView;
128d315fd93SMark Jansen hr = spFolder->QueryInterface(IID_PPV_ARG(IShellView, &spView));
129d315fd93SMark Jansen ok_hex(hr, E_NOINTERFACE);
130d315fd93SMark Jansen spView.Release();
131d315fd93SMark Jansen
132d315fd93SMark Jansen
133d315fd93SMark Jansen CComPtr<IDropTarget> spDropTarget;
134d315fd93SMark Jansen hr = spFolder->QueryInterface(IID_PPV_ARG(IDropTarget, &spDropTarget));
135d315fd93SMark Jansen ok_hex(hr, E_NOINTERFACE);
136d315fd93SMark Jansen
137d315fd93SMark Jansen CComPtr<IExtractIconW> spExtractIcon;
138d315fd93SMark Jansen hr = spFolder->QueryInterface(IID_PPV_ARG(IExtractIconW, &spExtractIcon));
139d315fd93SMark Jansen ok_hex(hr, E_NOINTERFACE);
140d315fd93SMark Jansen }
141d315fd93SMark Jansen }
142d315fd93SMark Jansen
143d315fd93SMark Jansen
CreateDropTarget()144d315fd93SMark Jansen static void CreateDropTarget()
145d315fd93SMark Jansen {
146d315fd93SMark Jansen CComPtr<IDropTarget> spDropTarget;
147d315fd93SMark Jansen HRESULT hr = CoCreateInstance(CLSID_FontExt, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IDropTarget, &spDropTarget));
148d315fd93SMark Jansen ok_hex(hr, E_NOINTERFACE);
149d315fd93SMark Jansen }
150d315fd93SMark Jansen
CreateExtractIcon()151d315fd93SMark Jansen static void CreateExtractIcon()
152d315fd93SMark Jansen {
153d315fd93SMark Jansen if (g_WinVersion < _WIN32_WINNT_VISTA)
154d315fd93SMark Jansen {
155d315fd93SMark Jansen CComPtr<IExtractIconA> spExtractIconA;
156d315fd93SMark Jansen HRESULT hr = CoCreateInstance(CLSID_FontExt, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IExtractIconA, &spExtractIconA));
157d315fd93SMark Jansen ok_hex(hr, S_OK);
158d315fd93SMark Jansen
159d315fd93SMark Jansen CComPtr<IExtractIconW> spExtractIconW;
160d315fd93SMark Jansen hr = CoCreateInstance(CLSID_FontExt, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IExtractIconW, &spExtractIconW));
161d315fd93SMark Jansen ok_hex(hr, S_OK);
162d315fd93SMark Jansen }
163d315fd93SMark Jansen else
164d315fd93SMark Jansen {
165d315fd93SMark Jansen CComPtr<IExtractIconA> spExtractIconA;
166d315fd93SMark Jansen HRESULT hr = CoCreateInstance(CLSID_FontExt, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IExtractIconA, &spExtractIconA));
167d315fd93SMark Jansen ok_hex(hr, E_NOINTERFACE);
168d315fd93SMark Jansen
169d315fd93SMark Jansen CComPtr<IExtractIconW> spExtractIconW;
170d315fd93SMark Jansen hr = CoCreateInstance(CLSID_FontExt, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IExtractIconW, &spExtractIconW));
171d315fd93SMark Jansen ok_hex(hr, E_NOINTERFACE);
172d315fd93SMark Jansen }
173d315fd93SMark Jansen }
174d315fd93SMark Jansen
175d315fd93SMark Jansen
176d315fd93SMark Jansen
START_TEST(shellext)177d315fd93SMark Jansen START_TEST(shellext)
178d315fd93SMark Jansen {
179d315fd93SMark Jansen RTL_OSVERSIONINFOEXW rtlinfo = {0};
180d315fd93SMark Jansen
181d315fd93SMark Jansen rtlinfo.dwOSVersionInfoSize = sizeof(rtlinfo);
182d315fd93SMark Jansen RtlGetVersion((PRTL_OSVERSIONINFOW)&rtlinfo);
183d315fd93SMark Jansen g_WinVersion = (rtlinfo.dwMajorVersion << 8) | rtlinfo.dwMinorVersion;
184d315fd93SMark Jansen
185d315fd93SMark Jansen trace("g_WinVersion=0x%x\n", g_WinVersion);
186d315fd93SMark Jansen
187d315fd93SMark Jansen CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
188d315fd93SMark Jansen
189d315fd93SMark Jansen CreateObjectsFromPersistFolder();
190d315fd93SMark Jansen CreateDropTarget();
191d315fd93SMark Jansen CreateExtractIcon();
192d315fd93SMark Jansen
193d315fd93SMark Jansen CoUninitialize();
194d315fd93SMark Jansen }
195