mirror of
https://github.com/reactos/reactos.git
synced 2025-05-07 02:41:22 +00:00
[USER32_APITEST] Improve user32:PrivateExtractIcons test (#5209)
- Improve the test by examining total number of icon groups in files and by adding more testcases including two new icon files. - Add new ROS.ico file which has both a normal icon and a PNG one. - Add tests for explorer.exe and new ROS.ico and sysicon.ico files. CORE-18897
This commit is contained in:
parent
d8e82ee45f
commit
454a27cdff
5 changed files with 120 additions and 11 deletions
|
@ -3,38 +3,132 @@
|
|||
* LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
|
||||
* PURPOSE: Test for PrivateExtractIcons
|
||||
* PROGRAMMER: Hermes Belusca-Maito
|
||||
* Doug Lyons <douglyons@douglyons.com>
|
||||
*/
|
||||
|
||||
#include "precomp.h"
|
||||
#include <stdio.h>
|
||||
|
||||
BOOL FileExists(PCWSTR FileName)
|
||||
{
|
||||
DWORD Attribute = GetFileAttributesW(FileName);
|
||||
|
||||
return (Attribute != INVALID_FILE_ATTRIBUTES &&
|
||||
!(Attribute & FILE_ATTRIBUTE_DIRECTORY));
|
||||
}
|
||||
|
||||
BOOL ResourceToFile(INT i, PCWSTR FileName)
|
||||
{
|
||||
FILE *fout;
|
||||
HGLOBAL hData;
|
||||
HRSRC hRes;
|
||||
PVOID pResLock;
|
||||
UINT iSize;
|
||||
|
||||
if (FileExists(FileName))
|
||||
{
|
||||
skip("'%S' already exists. Exiting now\n", FileName);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
hRes = FindResourceW(NULL, MAKEINTRESOURCEW(i), MAKEINTRESOURCEW(RT_RCDATA));
|
||||
if (hRes == NULL)
|
||||
{
|
||||
skip("Could not locate resource (%d). Exiting now\n", i);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
iSize = SizeofResource(NULL, hRes);
|
||||
|
||||
hData = LoadResource(NULL, hRes);
|
||||
if (hData == NULL)
|
||||
{
|
||||
skip("Could not load resource (%d). Exiting now\n", i);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Lock the resource into global memory.
|
||||
pResLock = LockResource(hData);
|
||||
if (pResLock == NULL)
|
||||
{
|
||||
skip("Could not lock resource (%d). Exiting now\n", i);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
fout = _wfopen(FileName, L"wb");
|
||||
fwrite(pResLock, iSize, 1, fout);
|
||||
fclose(fout);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static struct
|
||||
{
|
||||
PCWSTR FilePath;
|
||||
UINT cIcons; // Return value from PrivateExtractIconsW
|
||||
UINT cIcons; // Return value of the first icon group extracted (should be 1 if no error)
|
||||
UINT cTotalIcons; // Return value of total icon groups in file
|
||||
BOOL bhIconValid; // Whether or not the returned icon handle is not NULL.
|
||||
} IconTests[] =
|
||||
{
|
||||
/* Executables with icons */
|
||||
{L"notepad.exe", 1, TRUE},
|
||||
{L"%SystemRoot%\\System32\\cmd.exe", 1, TRUE},
|
||||
/* Executables with just one icon group */
|
||||
{L"notepad.exe", 1, 1, TRUE},
|
||||
{L"%SystemRoot%\\System32\\cmd.exe", 1, 1, TRUE},
|
||||
|
||||
/* Executable without icon */
|
||||
{L"%SystemRoot%\\System32\\autochk.exe", 0, FALSE},
|
||||
/* Executable without icon groups */
|
||||
{L"%SystemRoot%\\System32\\autochk.exe", 0, 0, FALSE},
|
||||
|
||||
/* Existing file */
|
||||
{L"%SystemRoot%\\System32\\shell32.dll", 1, TRUE},
|
||||
/* Existing file (shell32 has 233 icon groups in ReactOS only) */
|
||||
{L"%SystemRoot%\\System32\\shell32.dll", 1, 233, TRUE},
|
||||
|
||||
/* Non-existing files */
|
||||
{L"%SystemRoot%\\non-existent-file.sdf", 0xFFFFFFFF, FALSE},
|
||||
{L"%SystemRoot%\\non-existent-file.sdf", 0xFFFFFFFF, 0, FALSE},
|
||||
|
||||
/* Executable with 18 icon groups */
|
||||
{L"%SystemRoot%\\explorer.exe", 1, 18, TRUE},
|
||||
|
||||
/* Icon group file containing 6 icons */
|
||||
{L"%temp%\\sysicon.ico", 1, 1, TRUE},
|
||||
|
||||
/* Icon group file containing one PNG icon and one normal icon */
|
||||
{L"%temp%\\ROS.ico", 1, 1, TRUE},
|
||||
};
|
||||
|
||||
static struct
|
||||
{
|
||||
PCWSTR FileName;
|
||||
INT ResourceId;
|
||||
} IconFiles[] =
|
||||
{
|
||||
{L"%temp%\\ROS.ico", IDR_ICONS_PNG},
|
||||
{L"%temp%\\sysicon.ico", IDR_ICONS_NORMAL},
|
||||
};
|
||||
|
||||
START_TEST(PrivateExtractIcons)
|
||||
{
|
||||
HICON ahIcon;
|
||||
UINT i, aIconId, cIcons;
|
||||
UINT i, aIconId, cIcons, cIcoTotal;
|
||||
WCHAR PathBuffer[MAX_PATH];
|
||||
|
||||
/* Extract icons */
|
||||
for (i = 0; i < _countof(IconFiles); ++i)
|
||||
{
|
||||
ExpandEnvironmentStringsW(IconFiles[i].FileName, PathBuffer, _countof(PathBuffer));
|
||||
|
||||
if (!ResourceToFile(IconFiles[i].ResourceId, PathBuffer))
|
||||
goto Cleanup;
|
||||
}
|
||||
|
||||
for (i = 0; i < _countof(IconTests); ++i)
|
||||
{
|
||||
/* Get total number of icon groups in file.
|
||||
* None of the hard numbers in the function matter since we have
|
||||
* two NULLs for the Icon Handle and Count to be set. */
|
||||
cIcoTotal = PrivateExtractIconsW(IconTests[i].FilePath, 0, 16, 16, NULL, NULL, 0, 0);
|
||||
ok((i == 3 ?
|
||||
cIcoTotal > 232 && cIcoTotal < 240 : /* shell32 case: ROS has 233, W2K2SP2 has 239 icon groups. */
|
||||
cIcoTotal == IconTests[i].cTotalIcons),
|
||||
"PrivateExtractIconsW(%u): "
|
||||
"got %u, expected %u\n", i, cIcoTotal, IconTests[i].cTotalIcons);
|
||||
|
||||
/* Always test extraction of the FIRST icon (index 0) */
|
||||
ahIcon = (HICON)UlongToHandle(0xdeadbeef);
|
||||
aIconId = 0xdeadbeef;
|
||||
|
@ -46,7 +140,9 @@ START_TEST(PrivateExtractIcons)
|
|||
i, IconTests[i].bhIconValid ? "valid" : "not valid", ahIcon);
|
||||
if (cIcons == 0xFFFFFFFF)
|
||||
{
|
||||
ok(aIconId == 0xdeadbeef, "PrivateExtractIconsW(%u): id should not be set\n", i);
|
||||
ok(aIconId == 0xdeadbeef,
|
||||
"PrivateExtractIconsW(%u): id should not be set to 0x%x\n",
|
||||
i, aIconId);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -55,4 +151,11 @@ START_TEST(PrivateExtractIcons)
|
|||
if (ahIcon && ahIcon != (HICON)UlongToHandle(0xdeadbeef))
|
||||
DestroyIcon(ahIcon);
|
||||
}
|
||||
|
||||
Cleanup:
|
||||
for (i = 0; i < _countof(IconFiles); ++i)
|
||||
{
|
||||
ExpandEnvironmentStringsW(IconFiles[i].FileName, PathBuffer, _countof(PathBuffer));
|
||||
DeleteFileW(PathBuffer);
|
||||
}
|
||||
}
|
||||
|
|
BIN
modules/rostests/apitests/user32/ROS.ico
Normal file
BIN
modules/rostests/apitests/user32/ROS.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
|
@ -1,2 +1,5 @@
|
|||
|
||||
#define IDI_TEST 1000
|
||||
|
||||
#define IDR_ICONS_PNG 2000
|
||||
#define IDR_ICONS_NORMAL 2001
|
||||
|
|
BIN
modules/rostests/apitests/user32/sysicon.ico
Normal file
BIN
modules/rostests/apitests/user32/sysicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
|
@ -8,6 +8,9 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
|
|||
IDI_TEST ICON "test.ico"
|
||||
TESTCURSOR CURSOR "test.cur"
|
||||
|
||||
IDR_ICONS_PNG RCDATA "ROS.ico"
|
||||
IDR_ICONS_NORMAL RCDATA "sysicon.ico"
|
||||
|
||||
TESTDIALOG DIALOG 0,0, 200,200
|
||||
CLASS "TestDialogClass"
|
||||
CAPTION "Testdialog"
|
||||
|
|
Loading…
Reference in a new issue