ReactOS 0.4.16-dev-927-g467dec4
imagelist.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API Tests
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Test for imagelist
5 * COPYRIGHT: Copyright 2024 Whindmar Saksit <whindsaks@proton.me>
6 */
7
8#include "wine/test.h"
9#include <stdio.h>
10#include <windows.h>
11#include <commctrl.h>
12#include <comctl32_undoc.h>
13
14#define WinVerMajor() LOBYTE(GetVersion())
15
16#define ILC_COLORMASK 0xfe
17#define IL_IMGSIZE 16
18
20{
21 int w = -42, h;
22 if (!himl || IsBadReadPtr(himl, sizeof(void*)))
23 return FALSE;
24 return ImageList_GetIconSize(himl, &w, &h) && w != -42;
25}
26
28{
29 if (himl && !IL_IsValid(himl))
30 return E_INVALIDARG;
32}
33
35{
37}
38
40{
42 return (ilc & ~ILC_COLORMASK) | bpp;
43}
44
46{
47 int idx = -1;
48 HINSTANCE hInst = LoadLibraryW(L"USER32");
49 if (!hInst)
50 return FALSE;
51 HICON hIco = (HICON)LoadImage(hInst, MAKEINTRESOURCE(100), /* Windows */
53 if (!hIco)
54 hIco = (HICON)LoadImage(hInst, MAKEINTRESOURCE(32512), /* ReactOS */
56
57 if (hIco)
58 {
59 idx = ImageList_AddIcon(himl, hIco);
60 DestroyIcon(hIco);
61 }
63 return idx != -1;
64}
65
66static void Test_SystemIL(void)
67{
70
72 ok(IL_Destroy(himl) == S_OK && !IL_IsValid(himl), "Can destroy normal\n");
73
74 /* You can (sometimes) destroy a system imagelist!
75 * On Win9x it destroys it for all processes according to
76 * https://sporks.space/2021/09/18/notes-on-the-system-image-list/ and
77 * https://www.catch22.net/tuts/win32/system-image-list/
78 */
80 if (WinVerMajor() >= 6)
81 ok(IL_Destroy(himl) == S_FALSE && IL_IsValid(himl), "Can't destroy system\n");
82 else
83 ok(IL_Destroy(himl) == S_OK && !IL_IsValid(himl), "Can destroy system\n");
84}
85
86static void Test_Flags(void)
87{
89 UINT flagsIn, flagsOut;
91
92 himl = IL_Create(flagsIn = flags);
93 flagsOut = ImageList_GetFlags(himl);
94 if (himl ? TRUE : (skip("Could not initialize\n"), FALSE))
95 {
96 ok((flagsOut & ILC_COLORMASK) == (flagsIn & ILC_COLORMASK), "ILC_COLOR\n");
97 ok(!(flagsOut & ILC_SYSTEM), "!ILC_SYSTEM\n");
98
99 ok(IL_AddImagesForTest(himl), "Initialize\n");
100 flagsIn = IL_CalculateOtherBpp(flagsIn);
101 ok(ImageList_SetFlags(himl, flagsIn), "Can change BPP\n");
102 ok(ImageList_GetImageCount(himl) == 0, "SetFlags deletes all images\n");
103
104 ok(IL_AddImagesForTest(himl), "Initialize\n");
105 ok(ImageList_SetFlags(himl, ImageList_GetFlags(himl)), "Can set same flags\n");
106 if (WinVerMajor() >= 6)
107 {
108 ok(ImageList_GetImageCount(himl) != 0, "SetFlags does not delete with same flags\n");
109 ok(ImageList_SetFlags(himl, flagsIn ^ ILC_SYSTEM), "Can change ILC_SYSTEM\n");
110 }
111 else
112 {
113 ok(ImageList_GetImageCount(himl) == 0, "SetFlags deletes all images even with same flags\n");
114 ok(!ImageList_SetFlags(himl, flagsIn ^ ILC_SYSTEM), "Can't change ILC_SYSTEM\n");
115 }
116
118 }
119
120 himl = IL_Create(flagsIn = flags | ILC_SYSTEM);
121 flagsOut = ImageList_GetFlags(himl);
122 if (himl ? TRUE : (skip("Could not initialize\n"), FALSE))
123 {
124 ok((flagsOut & ILC_SYSTEM), "ILC_SYSTEM\n"); /* Flag is not hidden */
125
126 ok(IL_AddImagesForTest(himl), "Initialize\n");
127
128 flagsIn = IL_CalculateOtherBpp(flagsIn);
129 ok(ImageList_SetFlags(himl, flagsIn), "Can change BPP\n");
130 ok(ImageList_GetImageCount(himl) == 0, "SetFlags deletes all images\n");
131
132 ok(IL_AddImagesForTest(himl), "Initialize\n");
133 ok(ImageList_SetFlags(himl, ImageList_GetFlags(himl)), "Can set same flags\n");
134 if (WinVerMajor() >= 6)
135 {
136 ok(ImageList_SetFlags(himl, flagsIn ^ ILC_SYSTEM), "Can change ILC_SYSTEM\n");
137 }
138 else
139 {
140 ok(!ImageList_SetFlags(himl, flagsIn ^ ILC_SYSTEM), "Can't change ILC_SYSTEM\n");
141 }
142
144 }
145}
146
147START_TEST(ImageListApi)
148{
151 Test_Flags();
152}
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
HIMAGELIST himl
#define ILC_SYSTEM
VOID WINAPI InitCommonControls(void)
Definition: commctrl.c:870
#define E_INVALIDARG
Definition: ddrawi.h:101
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
DWORD bpp
Definition: surface.c:185
unsigned int idx
Definition: utils.c:41
DWORD WINAPI ImageList_SetFlags(HIMAGELIST himl, DWORD flags)
Definition: imagelist.c:3095
BOOL WINAPI ImageList_Destroy(HIMAGELIST himl)
Definition: imagelist.c:941
INT WINAPI ImageList_GetImageCount(HIMAGELIST himl)
Definition: imagelist.c:2081
HIMAGELIST WINAPI ImageList_Create(INT cx, INT cy, UINT flags, INT cInitial, INT cGrow)
Definition: imagelist.c:814
BOOL WINAPI ImageList_GetIconSize(HIMAGELIST himl, INT *cx, INT *cy)
Definition: imagelist.c:2055
DWORD WINAPI ImageList_GetFlags(HIMAGELIST himl)
Definition: imagelist.c:1952
#define FreeLibrary(x)
Definition: compat.h:748
#define LoadLibraryW(x)
Definition: compat.h:747
BOOL WINAPI IsBadReadPtr(IN LPCVOID lp, IN UINT_PTR ucb)
Definition: except.c:805
HINSTANCE hInst
Definition: dxdiag.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
GLbitfield flags
Definition: glext.h:7161
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
#define S_OK
Definition: intsafe.h:52
static BOOL IL_AddImagesForTest(HIMAGELIST himl)
Definition: imagelist.c:45
static HIMAGELIST IL_Create(UINT flags)
Definition: imagelist.c:34
static void Test_SystemIL(void)
Definition: imagelist.c:66
static void Test_Flags(void)
Definition: imagelist.c:86
#define IL_IMGSIZE
Definition: imagelist.c:17
#define WinVerMajor()
Definition: imagelist.c:14
static HRESULT IL_Destroy(HIMAGELIST himl)
Definition: imagelist.c:27
#define ILC_COLORMASK
Definition: imagelist.c:16
static UINT IL_CalculateOtherBpp(UINT ilc)
Definition: imagelist.c:39
static BOOL IL_IsValid(HIMAGELIST himl)
Definition: imagelist.c:19
static HICON
Definition: imagelist.c:80
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
#define ILC_COLOR16
Definition: commctrl.h:356
#define ILC_COLOR32
Definition: commctrl.h:358
#define ImageList_AddIcon(himl, hicon)
Definition: commctrl.h:415
#define ILC_MASK
Definition: commctrl.h:351
#define S_FALSE
Definition: winerror.h:2357
#define IMAGE_ICON
Definition: winuser.h:212
#define LoadImage
Definition: winuser.h:5827
#define MAKEINTRESOURCE
Definition: winuser.h:591
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2139