Reactos
at master 198 lines 7.1 kB view raw
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 21static const CLSID CLSID_FontExt = { 0xBD84B380, 0x8CA2, 0x1069, { 0xAB, 0x1D, 0x08, 0x00, 0x09, 0x48, 0xF5, 0x34 } }; 22static BOOL g_bFontFolderWithShellView = FALSE; 23static BOOL g_bVistaWorkaround = FALSE; 24 25static 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 38static HRESULT Initialize(CComPtr<IShellFolder>& spFolder, WCHAR FolderName[MAX_PATH]) 39{ 40 WCHAR Path[MAX_PATH] = {0}; 41 HRESULT hr = SHGetFolderPathW(NULL, CSIDL_FONTS, NULL, 0, Path); 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 74static 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); 103 Ptr = PathFindNextComponentW(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); 113 Ptr = PathFindNextComponentW(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); 123 Ptr = PathFindNextComponentW(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); 133 Ptr = PathFindNextComponentW(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); 152 Ptr = PathFindNextComponentW(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 ???) 158 if (g_bFontFolderWithShellView || g_bVistaWorkaround) 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 172START_TEST(GetDisplayNameOf) 173{ 174 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); 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)); 181 g_bFontFolderWithShellView = SUCCEEDED(hr); 182 } 183 184 g_bVistaWorkaround = IsWindowsVistaOrGreater() && !IsWindows7OrGreater(); 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}