From 6bd0ffc49479c1e9d94bc0a4324eadd4b81a828c Mon Sep 17 00:00:00 2001 From: Whindmar Saksit Date: Sat, 24 May 2025 22:08:54 +0200 Subject: [PATCH] [SHELL32_APITEST] Fix control panel printers PIDL test (#8022) --- .../rostests/apitests/shell32/ItemIDList.cpp | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/modules/rostests/apitests/shell32/ItemIDList.cpp b/modules/rostests/apitests/shell32/ItemIDList.cpp index 14d9f551d47..f64ad892823 100644 --- a/modules/rostests/apitests/shell32/ItemIDList.cpp +++ b/modules/rostests/apitests/shell32/ItemIDList.cpp @@ -13,6 +13,8 @@ enum { DIRBIT = 1, FILEBIT = 2, PT_COMPUTER_REGITEM = 0x2E, PT_INTERNET_URL = 0x61, + PT_CONTROLS_OLDREGITEM = 0x70, + PT_CONTROLS_NEWREGITEM = 0x71, }; static BYTE GetPIDLType(LPCITEMIDLIST pidl) @@ -49,6 +51,13 @@ static int FileStruct_Att(LPCITEMIDLIST pidl) return p ? p->att : (UINT(1) << 31); } +static HRESULT ParseDisplayName(PWSTR pszPath, LPITEMIDLIST *ppidl, IBindCtx *pBC = NULL) +{ + CComPtr pSF; + HRESULT hr = SHGetDesktopFolder(&pSF); + return FAILED(hr) ? hr : pSF->ParseDisplayName(NULL, pBC, pszPath, NULL, ppidl, NULL); +} + static HRESULT GetDisplayNameOf(IShellFolder *pSF, LPCITEMIDLIST pidl, UINT Flags, PWSTR Buf, UINT Cap) { STRRET sr; @@ -58,6 +67,14 @@ static HRESULT GetDisplayNameOf(IShellFolder *pSF, LPCITEMIDLIST pidl, UINT Flag return hr; } +static HRESULT GetDisplayNameOf(PCIDLIST_ABSOLUTE pidl, UINT Flags, PWSTR Buf, UINT Cap) +{ + CComPtr pSF; + PCUITEMID_CHILD pidlChild; + HRESULT hr = SHBindToParent(pidl, IID_PPV_ARG(IShellFolder, &pSF), &pidlChild); + return FAILED(hr) ? hr : GetDisplayNameOf(pSF, pidlChild, Flags, Buf, Cap); +} + #define TEST_CLSID(pidl, type, offset, clsid) \ do { \ ok_long(GetPIDLType(pidl), (type)); \ @@ -217,9 +234,32 @@ START_TEST(PIDL) pidl = SHCloneSpecialIDList(NULL, CSIDL_PRINTERS, FALSE); if (pidl) - TEST_CLSID(ILFindLastID(pidl), 0x71, 14, CLSID_Printers); + { + // Accept both the old and new format from the special folder API (NT5 vs NT6) + LPITEMIDLIST pidlLeaf = ILFindLastID(pidl); + if (LOBYTE(GetVersion()) < 6) + TEST_CLSID(pidlLeaf, PT_CONTROLS_OLDREGITEM, 4, CLSID_Printers); + else + TEST_CLSID(pidlLeaf, PT_CONTROLS_NEWREGITEM, 14, CLSID_Printers); + + // The Control Panel should always return the new format when parsing + LPITEMIDLIST pidl2; + WCHAR szParse[MAX_PATH]; + if (SUCCEEDED(GetDisplayNameOf(pidl, SHGDN_FORPARSING, szParse, _countof(szParse))) && + SUCCEEDED(ParseDisplayName(szParse, &pidl2))) + { + TEST_CLSID(ILFindLastID(pidl2), PT_CONTROLS_NEWREGITEM, 14, CLSID_Printers); + ILFree(pidl2); + } + else + { + skip("Failed to parse in Control Panel\n"); + } + } else + { skip("?\n"); + } ILFree(pidl);