ReactOS  0.4.15-dev-2993-g14fbe80
GetDisplayNameOf.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: fontext_apitest
3  * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE: Tests for fontext GetDisplayNameOf behavior
5  * COPYRIGHT: Copyright 2021 Mark Jansen <mark.jansen@reactos.org>
6  */
7 
8 #include <ntstatus.h>
9 #define WIN32_NO_STATUS
10 #include <windef.h>
11 #include <ntndk.h>
12 #include <atlbase.h>
13 #include <atlcom.h>
14 #include <shellapi.h>
15 #include <shlobj.h>
16 #include <shlwapi.h>
17 #include <shellutils.h>
18 #include <versionhelpers.h>
19 #include "wine/test.h"
20 
21 static const CLSID CLSID_FontExt = { 0xBD84B380, 0x8CA2, 0x1069, { 0xAB, 0x1D, 0x08, 0x00, 0x09, 0x48, 0xF5, 0x34 } };
24 
25 static HRESULT GetDisplayName(CComPtr<IShellFolder>& spFolder, LPCITEMIDLIST pidlRelative, SHGDNF uFlags, WCHAR Buf[MAX_PATH])
26 {
27  STRRET strret;
28  HRESULT hr = spFolder->GetDisplayNameOf(pidlRelative, uFlags, &strret);
29  ok_hex(hr, S_OK);
30  if (FAILED(hr))
31  return hr;
32 
33  hr = StrRetToBufW(&strret, pidlRelative, Buf, MAX_PATH);
34  ok_hex(hr, S_OK);
35  return hr;
36 }
37 
38 static HRESULT Initialize(CComPtr<IShellFolder>& spFolder, WCHAR FolderName[MAX_PATH])
39 {
40  WCHAR Path[MAX_PATH] = {0};
42  ok_hex(hr, S_OK);
43  if (FAILED(hr))
44  return hr;
45 
46  CComPtr<IShellFolder> desktopFolder;
47  hr = SHGetDesktopFolder(&desktopFolder);
48  ok_hex(hr, S_OK);
49  if (FAILED(hr))
50  return hr;
51 
52  CComHeapPtr<ITEMIDLIST> pidl;
53  hr = desktopFolder->ParseDisplayName(NULL, NULL, Path, NULL, &pidl, NULL);
54  ok_hex(hr, S_OK);
55  if (FAILED(hr))
56  return hr;
57 
58  hr = desktopFolder->BindToObject(pidl, NULL, IID_PPV_ARG(IShellFolder, &spFolder));
59  ok_hex(hr, S_OK);
60  if (FAILED(hr))
61  return hr;
62 
63 
64  CComPtr<IShellFolder> psfParent;
65  LPCITEMIDLIST pidlRelative = NULL;
66  hr = SHBindToParent(pidl, IID_PPV_ARG(IShellFolder, &psfParent), &pidlRelative);
67  ok_hex(hr, S_OK);
68  if (FAILED(hr))
69  return hr;
70 
71  return GetDisplayName(psfParent, pidlRelative, SHGDN_NORMAL, FolderName);
72 }
73 
74 static void Test_GetDisplayNameOf(CComPtr<IShellFolder>& spFolder, const WCHAR* FolderName)
75 {
76  CComPtr<IEnumIDList> fontsEnum;
77  HRESULT hr = spFolder->EnumObjects(NULL, SHCONTF_NONFOLDERS, &fontsEnum);
78 
79  ok_hex(hr, S_OK);
80  if (FAILED(hr))
81  return;
82 
83  CComHeapPtr<ITEMIDLIST> fontPidl;
84 
85  // Get the first item from the folder
86  ULONG fetched = 0;
87  hr = fontsEnum->Next(1, &fontPidl, &fetched);
88  ok_hex(hr, S_OK);
89  if (FAILED(hr))
90  return;
91 
92 
93  WCHAR Buf[MAX_PATH], *Ptr;
94  if (FAILED(GetDisplayName(spFolder, fontPidl, SHGDN_FORPARSING, Buf)))
95  return;
96 
97  // On 2k3 where this is not a custom IShellFolder, it will return something like:
98  // Same for Vista??
99  // 'C:\\WINDOWS\\Fonts\\arial.ttf'
100  // On 7+ this results is:
101  // 'C:\\Windows\\Fonts\\System Bold'
102  BOOL bRelative = PathIsRelativeW(Buf);
104  trace("Path: %s\n", wine_dbgstr_w(Buf));
105  ok(bRelative == FALSE, "Path not absolute? (%s)\n", wine_dbgstr_w(Buf));
106  ok(Ptr != (Buf + wcslen(Buf)), "Did not find a separator in '%s'!\n", wine_dbgstr_w(Buf));
107 
108  // Expected 'arial.ttf' (2k3), 'Arial' (Vista) or 'System Bold' (7+), 'System \0388\03bd\03c4\03bf\03bd\03b7 \03b3\03c1\03b1\03c6\03ae' in greek
109  if (FAILED(GetDisplayName(spFolder, fontPidl, SHGDN_INFOLDER, Buf)))
110  return;
111 
112  bRelative = PathIsRelativeW(Buf);
114  trace("Path: %s\n", wine_dbgstr_w(Buf));
115  ok(bRelative != FALSE, "Path not relative? (%s)\n", wine_dbgstr_w(Buf));
116  ok(Ptr == (Buf + wcslen(Buf)), "Found a separator in '%s'!\n", wine_dbgstr_w(Buf));
117 
118  // Expected 'arial.ttf' (2k3) or 'Arial' (Vista), 'System Bold' (7+), 'System \0388\03bd\03c4\03bf\03bd\03b7 \03b3\03c1\03b1\03c6\03ae' in greek
119  if (FAILED(GetDisplayName(spFolder, fontPidl, SHGDN_NORMAL, Buf)))
120  return;
121 
122  bRelative = PathIsRelativeW(Buf);
124  trace("Path: %s\n", wine_dbgstr_w(Buf));
125  ok(bRelative != FALSE, "Path not relative? (%s)\n", wine_dbgstr_w(Buf));
126  ok(Ptr == (Buf + wcslen(Buf)), "Found a separator in '%s'!\n", wine_dbgstr_w(Buf));
127 
128  // Expected 'arial.ttf' (2k3), 'C:\\WINDOWS\\Fonts\\arial.ttf' (Vista), 'System Bold' (7+)
129  if (FAILED(GetDisplayName(spFolder, fontPidl, SHGDN_INFOLDER | SHGDN_FORPARSING, Buf)))
130  return;
131 
132  bRelative = PathIsRelativeW(Buf);
134  trace("Path: %s\n", wine_dbgstr_w(Buf));
135  if (g_bVistaWorkaround)
136  {
137  // Vista is the odd one here
138  ok(bRelative == FALSE, "Path not absolute? (%s)\n", wine_dbgstr_w(Buf));
139  ok(Ptr != (Buf + wcslen(Buf)), "Did not find a separator in '%s'!\n", wine_dbgstr_w(Buf));
140  }
141  else
142  {
143  ok(bRelative != FALSE, "Path not relative? (%s)\n", wine_dbgstr_w(Buf));
144  ok(Ptr == (Buf + wcslen(Buf)), "Found a separator in '%s'!\n", wine_dbgstr_w(Buf));
145  }
146 
147  // Expected 'arial.ttf' (2k3), 'Arial' (Vista) or 'Fonts\\System Bold' (7+), 'Fonts\\System \0388\03bd\03c4\03bf\03bd\03b7 \03b3\03c1\03b1\03c6\03ae' in greek
148  if (FAILED(GetDisplayName(spFolder, fontPidl, SHGDN_FORADDRESSBAR, Buf)))
149  return;
150 
151  bRelative = PathIsRelativeW(Buf);
153  trace("Path: %s\n", wine_dbgstr_w(Buf));
154  ok(bRelative != FALSE, "Path not relative? (%s)\n", wine_dbgstr_w(Buf));
155 
156  // 2k3 does not have a custom IShellFolder, so there this weird behavior does not exist:
157  // (And vista's version is ???)
159  {
160  ok(Ptr == (Buf + wcslen(Buf)), "Found a separator in '%s'!\n", wine_dbgstr_w(Buf));
161  }
162  else
163  {
164  // For some reason, there is 'Fonts\\' in front of the fontname...
165  ok(Ptr != (Buf + wcslen(Buf)), "Did not find a separator in '%s'!\n", wine_dbgstr_w(Buf));
166  ok(!_wcsnicmp(FolderName, Buf, wcslen(FolderName)), "Result (%s) does not start with fonts folder (%s)\n",
167  wine_dbgstr_w(Buf), wine_dbgstr_w(FolderName));
168  }
169 }
170 
171 
172 START_TEST(GetDisplayNameOf)
173 {
175 
176  // Detect if this is an old (2k3) style fontext, or a new one.
177  // The old one has an IShellView, the new one an IShellFolder
178  {
179  CComPtr<IShellView> spView;
180  HRESULT hr = CoCreateInstance(CLSID_FontExt, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IShellView, &spView));
182  }
183 
185 
186  trace("Has shellview: %d, Vista: %d\n", g_bFontFolderWithShellView, g_bVistaWorkaround);
187  {
188  CComPtr<IShellFolder> spFolder;
189  WCHAR FolderName[MAX_PATH];
190  HRESULT hr = Initialize(spFolder, FolderName);
191  if (SUCCEEDED(hr))
192  {
193  Test_GetDisplayNameOf(spFolder, FolderName);
194  }
195  }
196 
197  CoUninitialize();
198 }
BOOL WINAPI PathIsRelativeW(LPCWSTR lpszPath)
Definition: path.c:1578
LPWSTR WINAPI PathFindNextComponentW(LPCWSTR lpszPath)
Definition: path.c:2578
HRESULT hr
Definition: shlfolder.c:183
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
HRESULT WINAPI StrRetToBufW(LPSTRRET src, const ITEMIDLIST *pidl, LPWSTR dest, UINT len)
Definition: string.c:1522
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
START_TEST(GetDisplayNameOf)
UINT uFlags
Definition: api.c:59
#define CSIDL_FONTS
Definition: shlobj.h:2031
#define IID_PPV_ARG(Itype, ppType)
#define ok_hex(expression, result)
Definition: atltest.h:94
static HRESULT GetDisplayName(CComPtr< IShellFolder > &spFolder, LPCITEMIDLIST pidlRelative, SHGDNF uFlags, WCHAR Buf[MAX_PATH])
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
if SUCCEEDED(hr)
VERSIONHELPERAPI IsWindowsVistaOrGreater()
HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
#define trace
Definition: atltest.h:70
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:79
#define MAX_PATH
Definition: compat.h:34
static void Test_GetDisplayNameOf(CComPtr< IShellFolder > &spFolder, const WCHAR *FolderName)
static HRESULT Initialize(CComPtr< IShellFolder > &spFolder, WCHAR FolderName[MAX_PATH])
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
#define S_OK
Definition: intsafe.h:52
static const CLSID CLSID_FontExt
PRTL_UNICODE_STRING_BUFFER Path
HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
Definition: pidl.c:1337
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
#define ok(value,...)
Definition: atltest.h:57
HRESULT WINAPI DECLSPEC_HOTPATCH CoInitializeEx(LPVOID lpReserved, DWORD dwCoInit)
Definition: compobj.c:2002
#define NULL
Definition: types.h:112
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
VERSIONHELPERAPI IsWindows7OrGreater()
HRESULT WINAPI SHGetFolderPathW(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath)
Definition: shellpath.c:2447
static BOOL g_bFontFolderWithShellView
unsigned int ULONG
Definition: retypes.h:1
static BOOL g_bVistaWorkaround