From: Detlef Riekenberg Subject: [PATCH 2/2] shell32/tests: Add basic tests for SHGetStockIconInfo Message-Id: <1359606958-16533-2-git-send-email-wine.dev@web.de> Date: Thu, 31 Jan 2013 05:35:58 +0100 I added the new tests in shelllink.c since there are already other icon related tests in this file. -- By by ... Detlef --- dlls/shell32/tests/shelllink.c | 101 +++++++++++++++++++++++++++++++++++++++- 1 files changed, 99 insertions(+), 2 deletions(-) diff --git a/dlls/shell32/tests/shelllink.c b/dlls/shell32/tests/shelllink.c index b22079c..5a1aa74 100644 --- a/dlls/shell32/tests/shelllink.c +++ b/dlls/shell32/tests/shelllink.c @@ -38,7 +38,7 @@ static void (WINAPI *pILFree)(LPITEMIDLIST); static BOOL (WINAPI *pILIsEqual)(LPCITEMIDLIST, LPCITEMIDLIST); static HRESULT (WINAPI *pSHILCreateFromPath)(LPCWSTR, LPITEMIDLIST *,DWORD*); static HRESULT (WINAPI *pSHDefExtractIconA)(LPCSTR, int, UINT, HICON*, HICON*, UINT); - +static HRESULT (WINAPI *pSHGetStockIconInfo)(SHSTOCKICONID, UINT, SHSTOCKICONINFO *); static DWORD (WINAPI *pGetLongPathNameA)(LPCSTR, LPSTR, DWORD); static DWORD (WINAPI *pGetShortPathNameA)(LPCSTR, LPSTR, DWORD); @@ -93,7 +93,7 @@ static LPITEMIDLIST path_to_pidl(const char* path) /* * Test manipulation of an IShellLink's properties. - */ +*/ static void test_get_set(void) { @@ -991,6 +991,101 @@ static void test_GetIconLocation(void) IShellLinkA_Release(sl); } +static void test_SHGetStockIconInfo(void) +{ + BYTE buffer[sizeof(SHSTOCKICONINFO) + 16]; + SHSTOCKICONINFO *sii = (SHSTOCKICONINFO *) buffer; + BOOL atleast_win7; + HRESULT hr; + INT i; + + /* not present before vista */ + if (!pSHGetStockIconInfo) + { + win_skip("SHGetStockIconInfo not available\n"); + return; + } + + /* negative values are handled */ + for (i = -3; i < 0; i++) + { + memset(buffer, '#', sizeof(buffer)); + sii->cbSize = sizeof(SHSTOCKICONINFO); + hr = pSHGetStockIconInfo(i, SHGSI_ICONLOCATION, sii); + ok(hr == E_INVALIDARG, "%3d: got 0x%x (expected E_INVALIDARG)\n", i, hr); + } + + /* max. id for vista is 140 (no definition exists) */ + for (; i <= 140; i++) + { + memset(buffer, '#', sizeof(buffer)); + sii->cbSize = sizeof(SHSTOCKICONINFO); + hr = pSHGetStockIconInfo(i, SHGSI_ICONLOCATION, sii); + + ok(hr == S_OK, "%3d: got 0x%x, iSysImageIndex: 0x%x, iIcon: 0x%x (expected S_OK)\n", + i, hr, sii->iSysImageIndex, sii->iIcon); + if ((hr == S_OK) && (winetest_debug > 1)) + trace("%3d: got iSysImageIndex %3d, iIcon %3d and %s\n", i, sii->iSysImageIndex, + sii->iIcon, wine_dbgstr_w(sii->szPath)); + } + + memset(buffer, '#', sizeof(buffer)); + sii->cbSize = sizeof(SHSTOCKICONINFO); + hr = pSHGetStockIconInfo(i, SHGSI_ICONLOCATION, sii); + atleast_win7 = (!hr); + + for (; i < (SIID_MAX_ICONS + 25) ; i++) + { + memset(buffer, '#', sizeof(buffer)); + sii->cbSize = sizeof(SHSTOCKICONINFO); + hr = pSHGetStockIconInfo(i, SHGSI_ICONLOCATION, sii); + + if (atleast_win7 && (i < (SIID_MAX_ICONS - 1))) + { + ok(hr == S_OK, "%3d: got 0x%x, iSysImageIndex: 0x%x, iIcon: 0x%x (expected S_OK)\n", + i, hr, sii->iSysImageIndex, sii->iIcon); + if ((hr == S_OK) && (winetest_debug > 1)) + trace("%3d: got iSysImageIndex %3d, iIcon %3d and %s\n", i, sii->iSysImageIndex, + sii->iIcon, wine_dbgstr_w(sii->szPath)); + } + else + ok(hr == E_INVALIDARG, "%3d: got 0x%x (expected E_INVALIDARG)\n", i, hr); + } + + /* test without extra flags */ + memset(buffer, '#', sizeof(buffer)); + sii->cbSize = sizeof(SHSTOCKICONINFO); + hr = pSHGetStockIconInfo(SIID_FOLDER, SHGSI_ICONLOCATION, sii); + ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr); + ok(!sii->hIcon, "got %p (expected NULL)\n", sii->hIcon); + ok(sii->iSysImageIndex == -1, "got %d (expected -1)\n", sii->iSysImageIndex); + + /* the exact size is required of the struct */ + memset(buffer, '#', sizeof(buffer)); + sii->cbSize = sizeof(SHSTOCKICONINFO) + 2; + hr = pSHGetStockIconInfo(SIID_FOLDER, SHGSI_ICONLOCATION, sii); + ok(hr == E_INVALIDARG, "+2: got 0x%x, iSysImageIndex: 0x%x, iIcon: 0x%x\n", hr, sii->iSysImageIndex, sii->iIcon); + + memset(buffer, '#', sizeof(buffer)); + sii->cbSize = sizeof(SHSTOCKICONINFO) + 1; + hr = pSHGetStockIconInfo(SIID_FOLDER, SHGSI_ICONLOCATION, sii); + ok(hr == E_INVALIDARG, "+1: got 0x%x, iSysImageIndex: 0x%x, iIcon: 0x%x\n", hr, sii->iSysImageIndex, sii->iIcon); + + memset(buffer, '#', sizeof(buffer)); + sii->cbSize = sizeof(SHSTOCKICONINFO) - 1; + hr = pSHGetStockIconInfo(SIID_FOLDER, SHGSI_ICONLOCATION, sii); + ok(hr == E_INVALIDARG, "-1: got 0x%x, iSysImageIndex: 0x%x, iIcon: 0x%x\n", hr, sii->iSysImageIndex, sii->iIcon); + + memset(buffer, '#', sizeof(buffer)); + sii->cbSize = sizeof(SHSTOCKICONINFO) - 2; + hr = pSHGetStockIconInfo(SIID_FOLDER, SHGSI_ICONLOCATION, sii); + ok(hr == E_INVALIDARG, "-2: got 0x%x, iSysImageIndex: 0x%x, iIcon: 0x%x\n", hr, sii->iSysImageIndex, sii->iIcon); + + /* there is a NULL check for the struct */ + hr = pSHGetStockIconInfo(SIID_FOLDER, SHGSI_ICONLOCATION, NULL); + ok(hr == E_INVALIDARG, "NULL: got 0x%x\n", hr); +} + START_TEST(shelllink) { HRESULT r; @@ -1001,6 +1096,7 @@ START_TEST(shelllink) pILIsEqual = (void *)GetProcAddress(hmod, (LPSTR)21); pSHILCreateFromPath = (void *)GetProcAddress(hmod, (LPSTR)28); pSHDefExtractIconA = (void *)GetProcAddress(hmod, "SHDefExtractIconA"); + pSHGetStockIconInfo = (void *)GetProcAddress(hmod, "SHGetStockIconInfo"); pGetLongPathNameA = (void *)GetProcAddress(hkernel32, "GetLongPathNameA"); pGetShortPathNameA = (void *)GetProcAddress(hkernel32, "GetShortPathNameA"); @@ -1015,6 +1111,7 @@ START_TEST(shelllink) test_datalink(); test_shdefextracticon(); test_GetIconLocation(); + test_SHGetStockIconInfo(); CoUninitialize(); } -- 1.7.5.4