comctl32/tests: Add tests for LoadIconMetric function.

Signed-off-by: Michael Müller <michael@fds-team.de>
Signed-off-by: Sebastian Lackner <sebastian@fds-team.de>
This commit is contained in:
Michael Müller 2015-10-02 15:13:41 +02:00 committed by Alexandre Julliard
parent 088eb87e3b
commit 1e2c0a3029
1 changed files with 153 additions and 0 deletions

View File

@ -20,6 +20,7 @@
#include <stdio.h>
#include <windows.h>
#include <commctrl.h>
#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);
}