mirror of
https://github.com/reactos/reactos.git
synced 2025-02-23 00:45:24 +00:00
[APITESTS/USER32]
Improve GetIconInfo tests: -Stop leaking each handle we create -Show Icons sensitivity to screen bit depth svn path=/trunk/; revision=57477
This commit is contained in:
parent
7b8f6ee98f
commit
8dafc1da92
1 changed files with 102 additions and 34 deletions
|
@ -7,7 +7,7 @@
|
|||
// FIXME user32
|
||||
|
||||
void
|
||||
Test_GetIconInfo(BOOL fIcon)
|
||||
Test_GetIconInfo(BOOL fIcon, DWORD screen_bpp)
|
||||
{
|
||||
HICON hicon;
|
||||
ICONINFO iconinfo, iconinfo2;
|
||||
|
@ -41,6 +41,7 @@ Test_GetIconInfo(BOOL fIcon)
|
|||
ok(iconinfo2.hbmMask != NULL, "\n");
|
||||
ok(iconinfo2.hbmMask != iconinfo.hbmMask, "\n");
|
||||
ok(iconinfo2.hbmColor == NULL, "\n");
|
||||
DeleteObject(iconinfo2.hbmMask);
|
||||
|
||||
ok(GetIconInfo(hicon, &iconinfo2), "\n");
|
||||
ok(iconinfo2.fIcon == iconinfo.fIcon, "\n");
|
||||
|
@ -57,6 +58,8 @@ Test_GetIconInfo(BOOL fIcon)
|
|||
ok(iconinfo2.hbmMask != NULL, "\n");
|
||||
ok(iconinfo2.hbmMask != iconinfo.hbmMask, "\n");
|
||||
ok(iconinfo2.hbmColor == NULL, "\n");
|
||||
DeleteObject(iconinfo2.hbmMask);
|
||||
ok(DestroyIcon(hicon), "\n");
|
||||
|
||||
iconinfo.hbmColor = CreateBitmap(2, 2, 1, 1, NULL);
|
||||
hicon = CreateIconIndirect(&iconinfo);
|
||||
|
@ -77,7 +80,7 @@ Test_GetIconInfo(BOOL fIcon)
|
|||
ok(iconinfo2.hbmMask != NULL, "\n");
|
||||
ok(iconinfo2.hbmMask != iconinfo.hbmMask, "\n");
|
||||
ok(iconinfo2.hbmColor != NULL, "\n");
|
||||
ok(iconinfo2.hbmMask != iconinfo.hbmColor, "\n");
|
||||
ok(iconinfo2.hbmColor != iconinfo.hbmColor, "\n");
|
||||
|
||||
ok(GetObject(iconinfo2.hbmMask, sizeof(bitmap), &bitmap), "GetObject failed\n");
|
||||
ok(bitmap.bmType == 0, "\n");
|
||||
|
@ -94,8 +97,11 @@ Test_GetIconInfo(BOOL fIcon)
|
|||
ok(bitmap.bmHeight == 16, "\n");
|
||||
ok(bitmap.bmWidthBytes == 8 * bitmap.bmBitsPixel / 8, "\n");
|
||||
ok(bitmap.bmPlanes == 1, "\n");
|
||||
ok(bitmap.bmBitsPixel == 32, "\n");
|
||||
ok(bitmap.bmBitsPixel == screen_bpp, "\n");
|
||||
ok(bitmap.bmBits == NULL, "\n");
|
||||
DeleteObject(iconinfo2.hbmMask);
|
||||
DeleteObject(iconinfo2.hbmColor);
|
||||
ok(DestroyIcon(hicon), "\n");
|
||||
|
||||
DeleteObject(iconinfo.hbmMask);
|
||||
iconinfo.hbmMask = NULL;
|
||||
|
@ -126,11 +132,13 @@ Test_GetIconInfo(BOOL fIcon)
|
|||
ok(bitmap.bmType == 0, "\n");
|
||||
ok(bitmap.bmWidth == 8, "%ld\n", bitmap.bmWidth);
|
||||
ok(bitmap.bmHeight == 16, "%ld\n", bitmap.bmHeight);
|
||||
ok(bitmap.bmWidthBytes == 32, "%ld\n", bitmap.bmWidthBytes);
|
||||
ok(bitmap.bmWidthBytes == screen_bpp, "%ld\n", bitmap.bmWidthBytes);
|
||||
ok(bitmap.bmPlanes == 1, "%d\n", bitmap.bmPlanes);
|
||||
ok(bitmap.bmBitsPixel == 32, "%d\n", bitmap.bmBitsPixel);
|
||||
ok(bitmap.bmBitsPixel == screen_bpp, "%d\n", bitmap.bmBitsPixel);
|
||||
ok(bitmap.bmBits == NULL, "\n");
|
||||
|
||||
DeleteObject(iconinfo2.hbmMask);
|
||||
DeleteObject(iconinfo2.hbmColor);
|
||||
ok(DestroyIcon(hicon), "\n");
|
||||
}
|
||||
|
||||
|
||||
|
@ -140,9 +148,15 @@ START_TEST(GetIconInfo)
|
|||
ICONINFO iconinfo2;
|
||||
BITMAP bitmap;
|
||||
DWORD data[] = {0, 0, 0, 0, 0, 0};
|
||||
DWORD bpp, screenbpp, creationbpp;
|
||||
DEVMODEW dm;
|
||||
|
||||
/* Test icons behaviour regarding display settings */
|
||||
EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &dm);
|
||||
screenbpp = dm.dmBitsPerPel;
|
||||
|
||||
Test_GetIconInfo(0);
|
||||
Test_GetIconInfo(1);
|
||||
Test_GetIconInfo(0, screenbpp);
|
||||
Test_GetIconInfo(1, screenbpp);
|
||||
|
||||
hcursor = LoadCursor(GetModuleHandle(NULL), "TESTCURSOR");
|
||||
ok(hcursor != 0, "should not fail, error %ld\n", GetLastError());
|
||||
|
@ -152,33 +166,82 @@ START_TEST(GetIconInfo)
|
|||
ok(iconinfo2.yHotspot == 29, "%ld\n", iconinfo2.yHotspot);
|
||||
ok(iconinfo2.hbmMask != NULL, "\n");
|
||||
ok(iconinfo2.hbmColor != NULL, "\n");
|
||||
/* Delete objects */
|
||||
DeleteObject(iconinfo2.hbmColor);
|
||||
DeleteObject(iconinfo2.hbmMask);
|
||||
/* Delete cursor */
|
||||
DestroyCursor(hcursor);
|
||||
|
||||
/* To sum it up:
|
||||
* There are two criteria when using icons: performance and aesthetics (=alpha channel).
|
||||
* Performance asks for bit parity with the screen display.
|
||||
* Aesthetics needs a 32bpp bitmap.
|
||||
* The behaviour is basically : aesthetics first if already loaded.
|
||||
* ie: if the 32bpp bitmap were already loaded because of previous display settings, always use it.
|
||||
* Otherwise, use the bitmap matching the screen bit depth.
|
||||
*/
|
||||
|
||||
/* if we use LR_SHARED here, and reverse the loop (32->16), then hbmColor.bmBitsPixel is always 32. */
|
||||
for(creationbpp = 16; creationbpp <=32; creationbpp += 8)
|
||||
{
|
||||
dm.dmBitsPerPel = creationbpp;
|
||||
if(ChangeDisplaySettingsExW(NULL, &dm, NULL, 0, NULL) != DISP_CHANGE_SUCCESSFUL)
|
||||
{
|
||||
skip("Unable to change bpp to %lu.\n", creationbpp);
|
||||
continue;
|
||||
}
|
||||
hcursor = LoadImage(GetModuleHandle(NULL),
|
||||
MAKEINTRESOURCE(IDI_TEST),
|
||||
IMAGE_ICON,
|
||||
0,
|
||||
0,
|
||||
LR_DEFAULTCOLOR);
|
||||
ok(hcursor != 0, "should not fail\n");
|
||||
|
||||
/* If we reverse the loop here (32->16 bpp), then hbmColor.bmBitsPixel is always 32 */
|
||||
for(bpp = 16; bpp <=32; bpp += 8)
|
||||
{
|
||||
dm.dmBitsPerPel = bpp;
|
||||
if(ChangeDisplaySettingsExW(NULL, &dm, NULL, 0, NULL) != DISP_CHANGE_SUCCESSFUL)
|
||||
{
|
||||
skip("Unable to change bpp to %lu.\n", bpp);
|
||||
continue;
|
||||
}
|
||||
ok(GetIconInfo(hcursor, &iconinfo2), "\n");
|
||||
ok(iconinfo2.fIcon == 1, "\n");
|
||||
ok(iconinfo2.xHotspot == 24, "%ld\n", iconinfo2.xHotspot);
|
||||
ok(iconinfo2.yHotspot == 24, "%ld\n", iconinfo2.yHotspot);
|
||||
ok(iconinfo2.hbmMask != NULL, "\n");
|
||||
ok(iconinfo2.hbmColor != NULL, "\n");
|
||||
|
||||
hcursor = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_TEST));
|
||||
ok(hcursor != 0, "should not fail\n");
|
||||
ok(GetIconInfo(hcursor, &iconinfo2), "\n");
|
||||
ok(iconinfo2.fIcon == 1, "\n");
|
||||
ok(iconinfo2.xHotspot == 16, "%ld\n", iconinfo2.xHotspot);
|
||||
ok(iconinfo2.yHotspot == 16, "%ld\n", iconinfo2.yHotspot);
|
||||
ok(iconinfo2.hbmMask != NULL, "\n");
|
||||
ok(iconinfo2.hbmColor != NULL, "\n");
|
||||
ok(GetObject(iconinfo2.hbmMask, sizeof(bitmap), &bitmap), "GetObject failed\n");
|
||||
ok(bitmap.bmType == 0, "\n");
|
||||
ok(bitmap.bmWidth == 48, "%ld\n", bitmap.bmWidth);
|
||||
ok(bitmap.bmHeight == 48, "\n");
|
||||
ok(bitmap.bmWidthBytes == 6, "\n");
|
||||
ok(bitmap.bmPlanes == 1, "\n");
|
||||
ok(bitmap.bmBitsPixel == 1, "\n");
|
||||
ok(bitmap.bmBits == NULL, "\n");
|
||||
|
||||
ok(GetObject(iconinfo2.hbmMask, sizeof(bitmap), &bitmap), "GetObject failed\n");
|
||||
ok(bitmap.bmType == 0, "\n");
|
||||
ok(bitmap.bmWidth == 32, "%ld\n", bitmap.bmWidth);
|
||||
ok(bitmap.bmHeight == 32, "\n");
|
||||
ok(bitmap.bmWidthBytes == 4, "\n");
|
||||
ok(bitmap.bmPlanes == 1, "\n");
|
||||
ok(bitmap.bmBitsPixel == 1, "\n");
|
||||
ok(bitmap.bmBits == NULL, "\n");
|
||||
|
||||
ok(GetObject(iconinfo2.hbmColor, sizeof(bitmap), &bitmap), "GetObject failed\n");
|
||||
ok(bitmap.bmType == 0, "\n");
|
||||
ok(bitmap.bmWidth == 32, "\n");
|
||||
ok(bitmap.bmHeight == 32, "\n");
|
||||
ok(bitmap.bmWidthBytes == 32 * bitmap.bmBitsPixel / 8, "\n");
|
||||
ok(bitmap.bmPlanes == 1, "\n");
|
||||
ok(bitmap.bmBitsPixel == 32, "\n");
|
||||
ok(bitmap.bmBits == NULL, "\n");
|
||||
ok(GetObject(iconinfo2.hbmColor, sizeof(bitmap), &bitmap), "GetObject failed\n");
|
||||
ok(bitmap.bmType == 0, "\n");
|
||||
ok(bitmap.bmWidth == 48, "\n");
|
||||
ok(bitmap.bmHeight == 48, "\n");
|
||||
ok(bitmap.bmWidthBytes == 48 * bitmap.bmBitsPixel / 8, "\n");
|
||||
ok(bitmap.bmPlanes == 1, "\n");
|
||||
ok(bitmap.bmBitsPixel == (creationbpp == 32 ? 32 : bpp), "creationbpp: %lu, bpp: %lu:\n", creationbpp, bpp);
|
||||
ok(bitmap.bmBits == NULL, "\n");
|
||||
|
||||
/* Delete objects */
|
||||
DeleteObject(iconinfo2.hbmColor);
|
||||
DeleteObject(iconinfo2.hbmMask);
|
||||
}
|
||||
ok(DestroyIcon(hcursor), "\n");
|
||||
}
|
||||
/* Restore display settings */
|
||||
dm.dmBitsPerPel = screenbpp;
|
||||
if(ChangeDisplaySettingsExW(NULL, &dm, NULL, 0, NULL) != DISP_CHANGE_SUCCESSFUL)
|
||||
trace("Unable to go back to previous display settings. Sorry.\n");
|
||||
|
||||
hcursor = CreateCursor(NULL, 1, 2, 4, 4, data, data);
|
||||
ok(hcursor != 0, "should not fail\n");
|
||||
|
@ -197,7 +260,12 @@ START_TEST(GetIconInfo)
|
|||
ok(bitmap.bmPlanes == 1, "\n");
|
||||
ok(bitmap.bmBitsPixel == 1, "\n");
|
||||
ok(bitmap.bmBits == NULL, "\n");
|
||||
|
||||
|
||||
/* Delete objects */
|
||||
DeleteObject(iconinfo2.hbmColor);
|
||||
DeleteObject(iconinfo2.hbmMask);
|
||||
/* Delete cursor */
|
||||
DestroyCursor(hcursor);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue