From: Sebastian Lackner Subject: [3/3] comctl32/tests: Add tests for LoadIconMetric function. Message-Id: <560E8305.1040307@fds-team.de> Date: Fri, 2 Oct 2015 15:13:41 +0200 From: Michael Müller Signed-off-by: Michael Müller Signed-off-by: Sebastian Lackner --- dlls/comctl32/tests/misc.c | 153 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) diff --git a/dlls/comctl32/tests/misc.c b/dlls/comctl32/tests/misc.c index 280b46c..ffd0dca 100644 --- a/dlls/comctl32/tests/misc.c +++ b/dlls/comctl32/tests/misc.c @@ -20,6 +20,7 @@ #include #include +#include #include "wine/test.h" #include "v6util.h" @@ -36,6 +37,18 @@ static BOOL (WINAPI * pStr_SetPtrW)(LPWSTR, LPCWSTR); static HMODULE hComctl32 = 0; +static char testicon_data[] = +{ + 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x02, 0x02, 0x00, 0x00, 0x01, 0x00, + 0x20, 0x00, 0x40, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x28, 0x00, + 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x12, 0x0b, + 0x00, 0x00, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xde, 0xde, 0xde, 0xff, 0xde, 0xde, 0xde, 0xff, 0xde, 0xde, + 0xde, 0xff, 0xde, 0xde, 0xde, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00 +}; + #define COMCTL32_GET_PROC(ordinal, func) \ p ## func = (void*)GetProcAddress(hComctl32, (LPSTR)ordinal); \ if(!p ## func) { \ @@ -205,6 +218,145 @@ static void test_TaskDialogIndirect(void) ok(ptr == ptr2, "got wrong pointer for ordinal 345, %p expected %p\n", ptr2, ptr); } +static void test_LoadIconWithScaleDown(void) +{ + static const WCHAR nonexisting_fileW[] = {'n','o','n','e','x','i','s','t','i','n','g','.','i','c','o',0}; + static const WCHAR nonexisting_resourceW[] = {'N','o','n','e','x','i','s','t','i','n','g',0}; + static const WCHAR prefixW[] = {'I','C','O',0}; + HRESULT (WINAPI *pLoadIconMetric)(HINSTANCE, const WCHAR *, int, HICON *); + HRESULT (WINAPI *pLoadIconWithScaleDown)(HINSTANCE, const WCHAR *, int, int, HICON *); + WCHAR tmp_path[MAX_PATH], icon_path[MAX_PATH]; + ICONINFO info; + HMODULE hinst; + HANDLE handle; + DWORD written; + HRESULT hr; + BITMAP bmp; + HICON icon; + void *ptr; + int bytes; + BOOL res; + + hinst = LoadLibraryA("comctl32.dll"); + pLoadIconMetric = (void *)GetProcAddress(hinst, "LoadIconMetric"); + pLoadIconWithScaleDown = (void *)GetProcAddress(hinst, "LoadIconWithScaleDown"); + if (!pLoadIconMetric || !pLoadIconWithScaleDown) + { + win_skip("LoadIconMetric or pLoadIconWithScaleDown not exported by name\n"); + FreeLibrary(hinst); + return; + } + + GetTempPathW(MAX_PATH, tmp_path); + GetTempFileNameW(tmp_path, prefixW, 0, icon_path); + handle = CreateFileW(icon_path, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, NULL); + ok(handle != INVALID_HANDLE_VALUE, "CreateFileW failed with error %u\n", GetLastError()); + res = WriteFile(handle, testicon_data, sizeof(testicon_data), &written, NULL); + ok(res && written == sizeof(testicon_data), "Failed to write icon file\n"); + CloseHandle(handle); + + /* test ordinals */ + ptr = GetProcAddress(hinst, (const char *)380); + ok(ptr == pLoadIconMetric, + "got wrong pointer for ordinal 380, %p expected %p\n", ptr, pLoadIconMetric); + + ptr = GetProcAddress(hinst, (const char *)381); + ok(ptr == pLoadIconWithScaleDown, + "got wrong pointer for ordinal 381, %p expected %p\n", ptr, pLoadIconWithScaleDown); + + /* invalid arguments */ + icon = (HICON)0x1234; + hr = pLoadIconMetric(NULL, MAKEINTRESOURCEW(IDI_APPLICATION), 0x100, &icon); + ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %x\n", hr); + ok(icon == NULL, "Expected NULL, got %p\n", icon); + + icon = (HICON)0x1234; + hr = pLoadIconMetric(NULL, NULL, LIM_LARGE, &icon); + ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %x\n", hr); + ok(icon == NULL, "Expected NULL, got %p\n", icon); + + icon = (HICON)0x1234; + hr = pLoadIconWithScaleDown(NULL, NULL, 32, 32, &icon); + ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %x\n", hr); + ok(icon == NULL, "Expected NULL, got %p\n", icon); + + /* non-existing filename */ + hr = pLoadIconMetric(NULL, nonexisting_fileW, LIM_LARGE, &icon); + todo_wine + ok(hr == HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND), + "Expected HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND), got %x\n", hr); + + hr = pLoadIconWithScaleDown(NULL, nonexisting_fileW, 32, 32, &icon); + todo_wine + ok(hr == HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND), + "Expected HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND), got %x\n", hr); + + /* non-existing resource name */ + hr = pLoadIconMetric(hinst, nonexisting_resourceW, LIM_LARGE, &icon); + ok(hr == HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND), + "Expected HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND), got %x\n", hr); + + hr = pLoadIconWithScaleDown(hinst, nonexisting_resourceW, 32, 32, &icon); + ok(hr == HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND), + "Expected HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND), got %x\n", hr); + + /* load icon using predefined identifier */ + hr = pLoadIconMetric(NULL, MAKEINTRESOURCEW(IDI_APPLICATION), LIM_SMALL, &icon); + ok(hr == S_OK, "Expected S_OK, got %x\n", hr); + res = GetIconInfo(icon, &info); + ok(res, "Failed to get icon info, error %u\n", GetLastError()); + bytes = GetObjectA(info.hbmColor, sizeof(bmp), &bmp); + ok(bytes > 0, "Failed to get bitmap info for icon\n"); + ok(bmp.bmWidth == GetSystemMetrics(SM_CXSMICON), "Wrong icon width %d\n", bmp.bmWidth); + ok(bmp.bmHeight == GetSystemMetrics(SM_CYSMICON), "Wrong icon height %d\n", bmp.bmHeight); + DestroyIcon(icon); + + hr = pLoadIconMetric(NULL, MAKEINTRESOURCEW(IDI_APPLICATION), LIM_LARGE, &icon); + ok(hr == S_OK, "Expected S_OK, got %x\n", hr); + res = GetIconInfo(icon, &info); + ok(res, "Failed to get icon info, error %u\n", GetLastError()); + bytes = GetObjectA(info.hbmColor, sizeof(bmp), &bmp); + ok(bytes > 0, "Failed to get bitmap info for icon\n"); + ok(bmp.bmWidth == GetSystemMetrics(SM_CXICON), "Wrong icon width %d\n", bmp.bmWidth); + ok(bmp.bmHeight == GetSystemMetrics(SM_CYICON), "Wrong icon height %d\n", bmp.bmHeight); + DestroyIcon(icon); + + hr = pLoadIconWithScaleDown(NULL, MAKEINTRESOURCEW(IDI_APPLICATION), 42, 42, &icon); + ok(hr == S_OK, "Expected S_OK, got %x\n", hr); + res = GetIconInfo(icon, &info); + ok(res, "Failed to get icon info, error %u\n", GetLastError()); + bytes = GetObjectA(info.hbmColor, sizeof(bmp), &bmp); + ok(bytes > 0, "Failed to get bitmap info for icon\n"); + ok(bmp.bmWidth == 42, "Wrong icon width %d\n", bmp.bmWidth); + ok(bmp.bmHeight == 42, "Wrong icon height %d\n", bmp.bmHeight); + DestroyIcon(icon); + + /* load icon from file */ + hr = pLoadIconMetric(NULL, icon_path, LIM_SMALL, &icon); + ok(hr == S_OK, "Expected S_OK, got %x\n", hr); + res = GetIconInfo(icon, &info); + ok(res, "Failed to get icon info, error %u\n", GetLastError()); + bytes = GetObjectA(info.hbmColor, sizeof(bmp), &bmp); + ok(bytes > 0, "Failed to get bitmap info for icon\n"); + ok(bmp.bmWidth == GetSystemMetrics(SM_CXSMICON), "Wrong icon width %d\n", bmp.bmWidth); + ok(bmp.bmHeight == GetSystemMetrics(SM_CYSMICON), "Wrong icon height %d\n", bmp.bmHeight); + DestroyIcon(icon); + + hr = pLoadIconWithScaleDown(NULL, icon_path, 42, 42, &icon); + ok(hr == S_OK, "Expected S_OK, got %x\n", hr); + res = GetIconInfo(icon, &info); + ok(res, "Failed to get icon info, error %u\n", GetLastError()); + bytes = GetObjectA(info.hbmColor, sizeof(bmp), &bmp); + ok(bytes > 0, "Failed to get bitmap info for icon\n"); + ok(bmp.bmWidth == 42, "Wrong icon width %d\n", bmp.bmWidth); + ok(bmp.bmHeight == 42, "Wrong icon height %d\n", bmp.bmHeight); + DestroyIcon(icon); + + DeleteFileW(icon_path); + FreeLibrary(hinst); +} + START_TEST(misc) { ULONG_PTR ctx_cookie; @@ -220,6 +372,7 @@ START_TEST(misc) return; test_TaskDialogIndirect(); + test_LoadIconWithScaleDown(); unload_v6_module(ctx_cookie, hCtx); } -- 2.5.1