https://git.reactos.org/?p=reactos.git;a=commitdiff;h=23b6397ae97bae1cfa8b3f5d12582e96fc0ac124

commit 23b6397ae97bae1cfa8b3f5d12582e96fc0ac124
Author:     Mark Jansen <[email protected]>
AuthorDate: Wed Apr 7 20:21:32 2021 +0200
Commit:     Mark Jansen <[email protected]>
CommitDate: Sat May 8 15:53:43 2021 +0200

    [FONTEXT_APITEST] Test more cases for GetDisplayNameOf
---
 .../rostests/apitests/fontext/GetDisplayNameOf.cpp | 131 +++++++++++++++++++--
 modules/rostests/apitests/fontext/shellext.cpp     |   2 +-
 2 files changed, 119 insertions(+), 14 deletions(-)

diff --git a/modules/rostests/apitests/fontext/GetDisplayNameOf.cpp 
b/modules/rostests/apitests/fontext/GetDisplayNameOf.cpp
index a0c164d6683..f843b2b26b0 100644
--- a/modules/rostests/apitests/fontext/GetDisplayNameOf.cpp
+++ b/modules/rostests/apitests/fontext/GetDisplayNameOf.cpp
@@ -15,9 +15,27 @@
 #include <shlobj.h>
 #include <shlwapi.h>
 #include <shellutils.h>
+#include <versionhelpers.h>
 #include "wine/test.h"
 
-static HRESULT Initialize(CComPtr<IShellFolder>& spFolder)
+static const CLSID CLSID_FontExt = { 0xBD84B380, 0x8CA2, 0x1069, { 0xAB, 0x1D, 
0x08, 0x00, 0x09, 0x48, 0xF5, 0x34 } };
+static BOOL g_bFontFolderWithShellView = FALSE;
+static BOOL g_bVistaWorkaround = FALSE;
+
+static HRESULT GetDisplayName(CComPtr<IShellFolder>& spFolder, LPCITEMIDLIST 
pidlRelative, SHGDNF uFlags, WCHAR Buf[MAX_PATH])
+{
+    STRRET strret;
+    HRESULT hr = spFolder->GetDisplayNameOf(pidlRelative, uFlags, &strret);
+    ok_hex(hr, S_OK);
+    if (FAILED(hr))
+        return hr;
+
+    hr = StrRetToBufW(&strret, pidlRelative, Buf, MAX_PATH);
+    ok_hex(hr, S_OK);
+    return hr;
+}
+
+static HRESULT Initialize(CComPtr<IShellFolder>& spFolder, WCHAR 
FolderName[MAX_PATH])
 {
     WCHAR Path[MAX_PATH] = {0};
     HRESULT hr = SHGetFolderPathW(NULL, CSIDL_FONTS, NULL, 0, Path);
@@ -39,10 +57,21 @@ static HRESULT Initialize(CComPtr<IShellFolder>& spFolder)
 
     hr = desktopFolder->BindToObject(pidl, NULL, IID_PPV_ARG(IShellFolder, 
&spFolder));
     ok_hex(hr, S_OK);
-    return hr;
+    if (FAILED(hr))
+        return hr;
+
+
+    CComPtr<IShellFolder> psfParent;
+    LPCITEMIDLIST pidlRelative = NULL;
+    hr = SHBindToParent(pidl, IID_PPV_ARG(IShellFolder, &psfParent), 
&pidlRelative);
+    ok_hex(hr, S_OK);
+    if (FAILED(hr))
+        return hr;
+
+    return GetDisplayName(psfParent, pidlRelative, SHGDN_NORMAL, FolderName);
 }
 
-static void Test_GetDisplayNameOf(CComPtr<IShellFolder>& spFolder)
+static void Test_GetDisplayNameOf(CComPtr<IShellFolder>& spFolder, const 
WCHAR* FolderName)
 {
     CComPtr<IEnumIDList> fontsEnum;
     HRESULT hr = spFolder->EnumObjects(NULL, SHCONTF_NONFOLDERS, &fontsEnum);
@@ -52,27 +81,91 @@ static void Test_GetDisplayNameOf(CComPtr<IShellFolder>& 
spFolder)
         return;
 
     CComHeapPtr<ITEMIDLIST> fontPidl;
+
+    // Get the first item from the folder
     ULONG fetched = 0;
     hr = fontsEnum->Next(1, &fontPidl, &fetched);
-    STRRET strret;
-    hr = spFolder->GetDisplayNameOf(fontPidl, SHGDN_FORPARSING, &strret);
     ok_hex(hr, S_OK);
     if (FAILED(hr))
         return;
 
-    WCHAR Buf[MAX_PATH];
-    hr = StrRetToBufW(&strret, fontPidl, Buf, _countof(Buf));
-    ok_hex(hr, S_OK);
-    if (FAILED(hr))
+
+    WCHAR Buf[MAX_PATH], *Ptr;
+    if (FAILED(GetDisplayName(spFolder, fontPidl, SHGDN_FORPARSING, Buf)))
         return;
 
     // On 2k3 where this is not a custom IShellFolder, it will return 
something like:
+    // Same for Vista??
     // 'C:\\WINDOWS\\Fonts\\arial.ttf'
-    // On Vista+ this results in something like:
+    // On 7+ this results is:
     // 'C:\\Windows\\Fonts\\System Bold'
     BOOL bRelative = PathIsRelativeW(Buf);
+    Ptr = PathFindNextComponentW(Buf);
+    trace("Path: %s\n", wine_dbgstr_w(Buf));
+    ok(bRelative == FALSE, "Path not absolute? (%s)\n", wine_dbgstr_w(Buf));
+    ok(Ptr != (Buf + wcslen(Buf)), "Did not find a separator in '%s'!\n", 
wine_dbgstr_w(Buf));
+
+    // Expected 'arial.ttf' (2k3), 'Arial' (Vista) or 'System Bold' (7+), 
'System \0388\03bd\03c4\03bf\03bd\03b7 \03b3\03c1\03b1\03c6\03ae' in greek
+    if (FAILED(GetDisplayName(spFolder, fontPidl, SHGDN_INFOLDER, Buf)))
+        return;
+
+    bRelative = PathIsRelativeW(Buf);
+    Ptr = PathFindNextComponentW(Buf);
+    trace("Path: %s\n", wine_dbgstr_w(Buf));
+    ok(bRelative != FALSE, "Path not relative? (%s)\n", wine_dbgstr_w(Buf));
+    ok(Ptr == (Buf + wcslen(Buf)), "Found a separator in '%s'!\n", 
wine_dbgstr_w(Buf));
+
+    // Expected 'arial.ttf' (2k3) or 'Arial' (Vista), 'System Bold' (7+), 
'System \0388\03bd\03c4\03bf\03bd\03b7 \03b3\03c1\03b1\03c6\03ae' in greek
+    if (FAILED(GetDisplayName(spFolder, fontPidl, SHGDN_NORMAL, Buf)))
+        return;
+
+    bRelative = PathIsRelativeW(Buf);
+    Ptr = PathFindNextComponentW(Buf);
+    trace("Path: %s\n", wine_dbgstr_w(Buf));
+    ok(bRelative != FALSE, "Path not relative? (%s)\n", wine_dbgstr_w(Buf));
+    ok(Ptr == (Buf + wcslen(Buf)), "Found a separator in '%s'!\n", 
wine_dbgstr_w(Buf));
+
+    // Expected 'arial.ttf' (2k3), 'C:\\WINDOWS\\Fonts\\arial.ttf' (Vista), 
'System Bold' (7+)
+    if (FAILED(GetDisplayName(spFolder, fontPidl, SHGDN_INFOLDER | 
SHGDN_FORPARSING, Buf)))
+        return;
+
+    bRelative = PathIsRelativeW(Buf);
+    Ptr = PathFindNextComponentW(Buf);
     trace("Path: %s\n", wine_dbgstr_w(Buf));
-    ok(bRelative == FALSE, "Path not relative? (%s)\n", wine_dbgstr_w(Buf));
+    if (g_bVistaWorkaround)
+    {
+        // Vista is the odd one here
+        ok(bRelative == FALSE, "Path not absolute? (%s)\n", 
wine_dbgstr_w(Buf));
+        ok(Ptr != (Buf + wcslen(Buf)), "Did not find a separator in '%s'!\n", 
wine_dbgstr_w(Buf));
+    }
+    else
+    {
+        ok(bRelative != FALSE, "Path not relative? (%s)\n", 
wine_dbgstr_w(Buf));
+        ok(Ptr == (Buf + wcslen(Buf)), "Found a separator in '%s'!\n", 
wine_dbgstr_w(Buf));
+    }
+
+    // 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
+    if (FAILED(GetDisplayName(spFolder, fontPidl, SHGDN_FORADDRESSBAR, Buf)))
+        return;
+
+    bRelative = PathIsRelativeW(Buf);
+    Ptr = PathFindNextComponentW(Buf);
+    trace("Path: %s\n", wine_dbgstr_w(Buf));
+    ok(bRelative != FALSE, "Path not relative? (%s)\n", wine_dbgstr_w(Buf));
+
+    // 2k3 does not have a custom IShellFolder, so there this weird behavior 
does not exist:
+    // (And vista's version is ???)
+    if (g_bFontFolderWithShellView || g_bVistaWorkaround)
+    {
+        ok(Ptr == (Buf + wcslen(Buf)), "Found a separator in '%s'!\n", 
wine_dbgstr_w(Buf));
+    }
+    else
+    {
+        // For some reason, there is 'Fonts\\' in front of the fontname...
+        ok(Ptr != (Buf + wcslen(Buf)), "Did not find a separator in '%s'!\n", 
wine_dbgstr_w(Buf));
+        ok(!_wcsnicmp(FolderName, Buf, wcslen(FolderName)), "Result (%s) does 
not start with fonts folder (%s)\n",
+            wine_dbgstr_w(Buf), wine_dbgstr_w(FolderName));
+    }
 }
 
 
@@ -80,12 +173,24 @@ START_TEST(GetDisplayNameOf)
 {
     CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
 
+    // Detect if this is an old (2k3) style fontext, or a new one.
+    // The old one has an IShellView, the new one an IShellFolder
+    {
+        CComPtr<IShellView> spView;
+        HRESULT hr = CoCreateInstance(CLSID_FontExt, NULL, 
CLSCTX_INPROC_SERVER, IID_PPV_ARG(IShellView, &spView));
+        g_bFontFolderWithShellView = SUCCEEDED(hr);
+    }
+
+    g_bVistaWorkaround = IsWindowsVistaOrGreater() && !IsWindows7OrGreater();
+
+    trace("Has shellview: %d, Vista: %d\n", g_bFontFolderWithShellView, 
g_bVistaWorkaround);
     {
         CComPtr<IShellFolder> spFolder;
-        HRESULT hr = Initialize(spFolder);
+        WCHAR FolderName[MAX_PATH];
+        HRESULT hr = Initialize(spFolder, FolderName);
         if (SUCCEEDED(hr))
         {
-            Test_GetDisplayNameOf(spFolder);
+            Test_GetDisplayNameOf(spFolder, FolderName);
         }
     }
 
diff --git a/modules/rostests/apitests/fontext/shellext.cpp 
b/modules/rostests/apitests/fontext/shellext.cpp
index 00480a7497c..7a23002137a 100644
--- a/modules/rostests/apitests/fontext/shellext.cpp
+++ b/modules/rostests/apitests/fontext/shellext.cpp
@@ -17,7 +17,7 @@
 #include <shellutils.h>
 #include "wine/test.h"
 
-const CLSID CLSID_FontExt = { 0xBD84B380, 0x8CA2, 0x1069, { 0xAB, 0x1D, 0x08, 
0x00, 0x09, 0x48, 0xF5, 0x34 } };
+static const CLSID CLSID_FontExt = { 0xBD84B380, 0x8CA2, 0x1069, { 0xAB, 0x1D, 
0x08, 0x00, 0x09, 0x48, 0xF5, 0x34 } };
 static DWORD g_WinVersion;
 
 

Reply via email to