mirror of
https://github.com/reactos/reactos.git
synced 2024-12-26 17:14:41 +00:00
[USER32_APTEST][USER32] CopyImage improve regression test and function. (#7524)
CORE-19806 and CORE-17902.
* Follow-up of PR #6886 and commit d3ec7cd
to remove hack.
This commit is contained in:
parent
1ea3af8959
commit
1c55924045
2 changed files with 93 additions and 6 deletions
|
@ -3,6 +3,7 @@
|
||||||
* LICENSE: LGPL-2.1+ (https://spdx.org/licenses/LGPL-2.1+)
|
* LICENSE: LGPL-2.1+ (https://spdx.org/licenses/LGPL-2.1+)
|
||||||
* PURPOSE: Test for SetFocus/GetFocus/GetGUIThreadInfo
|
* PURPOSE: Test for SetFocus/GetFocus/GetGUIThreadInfo
|
||||||
* COPYRIGHT: Copyright 2024 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
|
* COPYRIGHT: Copyright 2024 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
|
||||||
|
* Copyright 2024 Doug Lyons <douglyons@douglyons.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "precomp.h"
|
#include "precomp.h"
|
||||||
|
@ -76,9 +77,61 @@ Test_CopyImage_Flags(UINT uType)
|
||||||
DeleteObject(hImage);
|
DeleteObject(hImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VOID
|
||||||
|
Test_CopyImage_hImage_NULL(void)
|
||||||
|
{
|
||||||
|
HANDLE hImg;
|
||||||
|
DWORD LastError;
|
||||||
|
|
||||||
|
/* Test NULL HANDLE return and GetLastError return. */
|
||||||
|
SetLastError(0xdeadbeef);
|
||||||
|
hImg = CopyImage(NULL, IMAGE_ICON, 16, 16, LR_COPYFROMRESOURCE);
|
||||||
|
LastError = GetLastError();
|
||||||
|
ok(LastError == ERROR_INVALID_CURSOR_HANDLE, "Wrong error 0x%08lx returned\n", LastError);
|
||||||
|
ok(!hImg, "Image returned should have been NULL, hImg was %p\n", hImg);
|
||||||
|
|
||||||
|
SetLastError(0xdeadbeef);
|
||||||
|
hImg = CopyImage(NULL, IMAGE_BITMAP, 16, 16, LR_COPYFROMRESOURCE);
|
||||||
|
LastError = GetLastError();
|
||||||
|
ok(LastError == ERROR_INVALID_HANDLE, "Wrong error 0x%08lx returned\n", LastError);
|
||||||
|
ok(!hImg, "Image returned should have been NULL, hImg was %p\n", hImg);
|
||||||
|
|
||||||
|
|
||||||
|
SetLastError(0xdeadbeef);
|
||||||
|
hImg = CopyImage(NULL, IMAGE_CURSOR, 16, 16, LR_COPYFROMRESOURCE);
|
||||||
|
LastError = GetLastError();
|
||||||
|
ok(LastError == ERROR_INVALID_CURSOR_HANDLE, "Wrong error 0x%08lx returned\n", LastError);
|
||||||
|
ok(!hImg, "Image returned should have been NULL, hImg was %p\n", hImg);
|
||||||
|
|
||||||
|
/* Test bad Flags for Invalid Parameter return */
|
||||||
|
SetLastError(0xdeadbeef);
|
||||||
|
/* 0x80000000 is an invalid flag value */
|
||||||
|
hImg = CopyImage(NULL, IMAGE_BITMAP, 16, 16, 0x80000000);
|
||||||
|
LastError = GetLastError();
|
||||||
|
ok(LastError == ERROR_INVALID_PARAMETER, "Wrong error 0x%08lx returned\n", LastError);
|
||||||
|
ok(!hImg, "Image returned should have been NULL, hImg was %p\n", hImg);
|
||||||
|
|
||||||
|
/* Test bad Type (5) GetLastError return value. Not Icon, Cursor, or Bitmap. */
|
||||||
|
SetLastError(0xdeadbeef);
|
||||||
|
hImg = CopyImage(NULL, 5, 16, 16, LR_COPYFROMRESOURCE);
|
||||||
|
LastError = GetLastError();
|
||||||
|
ok(LastError == ERROR_INVALID_PARAMETER, "Wrong error 0x%08lx returned\n", LastError);
|
||||||
|
ok(!hImg, "Image returned should have been NULL, hImg was %p\n", hImg);
|
||||||
|
|
||||||
|
/* Test bad type (5) GetLastError return value with good HANDLE */
|
||||||
|
hImg = CreateTestImage(IMAGE_ICON);
|
||||||
|
SetLastError(0xdeadbeef);
|
||||||
|
hImg = CopyImage(hImg, 5, 16, 16, LR_COPYFROMRESOURCE);
|
||||||
|
LastError = GetLastError();
|
||||||
|
ok(LastError == ERROR_INVALID_PARAMETER, "Wrong error 0x%08lx returned\n", LastError);
|
||||||
|
ok(!hImg, "Image returned should have been NULL, hImg was %p\n", hImg);
|
||||||
|
DeleteObject(hImg);
|
||||||
|
}
|
||||||
|
|
||||||
START_TEST(CopyImage)
|
START_TEST(CopyImage)
|
||||||
{
|
{
|
||||||
Test_CopyImage_Flags(IMAGE_BITMAP);
|
Test_CopyImage_Flags(IMAGE_BITMAP);
|
||||||
Test_CopyImage_Flags(IMAGE_CURSOR);
|
Test_CopyImage_Flags(IMAGE_CURSOR);
|
||||||
Test_CopyImage_Flags(IMAGE_ICON);
|
Test_CopyImage_Flags(IMAGE_ICON);
|
||||||
|
Test_CopyImage_hImage_NULL();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2041,16 +2041,50 @@ HANDLE WINAPI CopyImage(
|
||||||
switch(uType)
|
switch(uType)
|
||||||
{
|
{
|
||||||
case IMAGE_BITMAP:
|
case IMAGE_BITMAP:
|
||||||
|
if (!hImage)
|
||||||
|
{
|
||||||
|
SetLastError(ERROR_INVALID_HANDLE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
return BITMAP_CopyImage(hImage, cxDesired, cyDesired, fuFlags);
|
return BITMAP_CopyImage(hImage, cxDesired, cyDesired, fuFlags);
|
||||||
case IMAGE_CURSOR:
|
case IMAGE_CURSOR:
|
||||||
case IMAGE_ICON:
|
case IMAGE_ICON:
|
||||||
/* HACK: Copying bitmaps with LR_COPYFROMRESOURCE flag fails. CORE-17902.
|
|
||||||
* This is a way to return the original bit map if we need
|
|
||||||
* the icons to show up. We need a simpler test. */
|
|
||||||
{
|
{
|
||||||
HANDLE handle = CURSORICON_CopyImage(hImage, uType == IMAGE_ICON, cxDesired, cyDesired, fuFlags);
|
HANDLE handle;
|
||||||
if (!handle && (fuFlags & (LR_COPYFROMRESOURCE|LR_COPYRETURNORG)))
|
if (!hImage)
|
||||||
handle = CURSORICON_CopyImage(hImage, uType == IMAGE_ICON, cxDesired, cyDesired, (fuFlags & ~LR_COPYFROMRESOURCE));
|
{
|
||||||
|
SetLastError(ERROR_INVALID_CURSOR_HANDLE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
handle = CURSORICON_CopyImage(hImage, uType == IMAGE_ICON, cxDesired, cyDesired, fuFlags);
|
||||||
|
if (!handle && (fuFlags & LR_COPYFROMRESOURCE))
|
||||||
|
{
|
||||||
|
/* Test if the hImage is the same size as what we want by getting
|
||||||
|
* its BITMAP and comparing its dimensions to the desired size. */
|
||||||
|
BITMAP bm;
|
||||||
|
|
||||||
|
ICONINFO iconinfo = { 0 };
|
||||||
|
if (!GetIconInfo(hImage, &iconinfo))
|
||||||
|
{
|
||||||
|
ERR("GetIconInfo Failed. hImage %p\n", hImage);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (!GetObject(iconinfo.hbmColor, sizeof(bm), &bm))
|
||||||
|
{
|
||||||
|
ERR("GetObject Failed. iconinfo %p\n", iconinfo);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
DeleteObject(iconinfo.hbmMask);
|
||||||
|
DeleteObject(iconinfo.hbmColor);
|
||||||
|
|
||||||
|
/* If the images are the same size remove LF_COPYFROMRESOURCE and try again */
|
||||||
|
if (cxDesired == bm.bmWidth && cyDesired == bm.bmHeight)
|
||||||
|
{
|
||||||
|
handle = CURSORICON_CopyImage(hImage, uType == IMAGE_ICON, cxDesired,
|
||||||
|
cyDesired, (fuFlags & ~LR_COPYFROMRESOURCE));
|
||||||
|
}
|
||||||
|
}
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in a new issue