2 * Unit test suite for imagelist control.
4 * Copyright 2004 Michael Stefaniuc
5 * Copyright 2002 Mike McCormack for CodeWeavers
6 * Copyright 2007 Dmitry Timoshkov
7 * Copyright 2009 Owen Rudge for CodeWeavers
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define WIN32_NO_STATUS
26 #define COM_NO_WINDOWS_H
39 #include <commctrl.h> /* must be included after objbase.h to get ImageList_Write */
41 #include <commoncontrols.h>
44 #include <wine/test.h>
47 #define IMAGELIST_MAGIC (('L' << 8) | 'I')
50 /* Header used by ImageList_Read() and ImageList_Write() */
51 typedef struct _ILHEAD
66 static HIMAGELIST (WINAPI
*pImageList_Create
)(int, int, UINT
, int, int);
67 static int (WINAPI
*pImageList_Add
)(HIMAGELIST
, HBITMAP
, HBITMAP
);
68 static BOOL (WINAPI
*pImageList_DrawIndirect
)(IMAGELISTDRAWPARAMS
*);
69 static BOOL (WINAPI
*pImageList_SetImageCount
)(HIMAGELIST
,UINT
);
70 static HRESULT (WINAPI
*pImageList_CoCreateInstance
)(REFCLSID
,const IUnknown
*,
72 static HRESULT (WINAPI
*pHIMAGELIST_QueryInterface
)(HIMAGELIST
,REFIID
,void **);
74 static HINSTANCE hinst
;
76 /* only used in interactive mode */
77 static void force_redraw(HWND hwnd
)
79 if (!winetest_interactive
)
82 RedrawWindow(hwnd
, NULL
, 0, RDW_UPDATENOW
);
86 /* These macros build cursor/bitmap data in 4x4 pixel blocks */
87 #define B(x,y) ((x?0xf0:0)|(y?0xf:0))
88 #define ROW1(a,b,c,d,e,f,g,h) B(a,b),B(c,d),B(e,f),B(g,h)
89 #define ROW32(a,b,c,d,e,f,g,h) ROW1(a,b,c,d,e,f,g,h), ROW1(a,b,c,d,e,f,g,h), \
90 ROW1(a,b,c,d,e,f,g,h), ROW1(a,b,c,d,e,f,g,h)
91 #define ROW2(a,b,c,d,e,f,g,h,i,j,k,l) ROW1(a,b,c,d,e,f,g,h),B(i,j),B(k,l)
92 #define ROW48(a,b,c,d,e,f,g,h,i,j,k,l) ROW2(a,b,c,d,e,f,g,h,i,j,k,l), \
93 ROW2(a,b,c,d,e,f,g,h,i,j,k,l), ROW2(a,b,c,d,e,f,g,h,i,j,k,l), \
94 ROW2(a,b,c,d,e,f,g,h,i,j,k,l)
96 static const BYTE empty_bits
[48*48/8];
98 static const BYTE icon_bits
[32*32/8] =
100 ROW32(0,0,0,0,0,0,0,0),
101 ROW32(0,0,1,1,1,1,0,0),
102 ROW32(0,1,1,1,1,1,1,0),
103 ROW32(0,1,1,0,0,1,1,0),
104 ROW32(0,1,1,0,0,1,1,0),
105 ROW32(0,1,1,1,1,1,1,0),
106 ROW32(0,0,1,1,1,1,0,0),
107 ROW32(0,0,0,0,0,0,0,0)
110 static const BYTE bitmap_bits
[48*48/8] =
112 ROW48(0,0,0,0,0,0,0,0,0,0,0,0),
113 ROW48(0,1,1,1,1,1,1,1,1,1,1,0),
114 ROW48(0,1,1,0,0,0,0,0,0,1,1,0),
115 ROW48(0,1,0,0,0,0,0,0,1,0,1,0),
116 ROW48(0,1,0,0,0,0,0,1,0,0,1,0),
117 ROW48(0,1,0,0,0,0,1,0,0,0,1,0),
118 ROW48(0,1,0,0,0,1,0,0,0,0,1,0),
119 ROW48(0,1,0,0,1,0,0,0,0,0,1,0),
120 ROW48(0,1,0,1,0,0,0,0,0,0,1,0),
121 ROW48(0,1,1,0,0,0,0,0,0,1,1,0),
122 ROW48(0,1,1,1,1,1,1,1,1,1,1,0),
123 ROW48(0,0,0,0,0,0,0,0,0,0,0,0)
126 static HIMAGELIST
createImageList(int cx
, int cy
)
128 /* Create an ImageList and put an image into it */
129 HIMAGELIST himl
= ImageList_Create(cx
, cy
, ILC_COLOR
, 1, 1);
130 HBITMAP hbm
= CreateBitmap(48, 48, 1, 1, bitmap_bits
);
131 ImageList_Add(himl
, hbm
, NULL
);
136 static HWND
create_a_window(void)
138 char className
[] = "bmwnd";
139 char winName
[] = "Test Bitmap";
141 static BOOL registered
= FALSE
;
147 cls
.style
= CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
;
148 cls
.lpfnWndProc
= DefWindowProcA
;
152 cls
.hIcon
= LoadIconA(0, (LPCSTR
)IDI_APPLICATION
);
153 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
154 cls
.hbrBackground
= GetStockObject (WHITE_BRUSH
);
155 cls
.lpszMenuName
= 0;
156 cls
.lpszClassName
= className
;
158 RegisterClassA (&cls
);
163 hWnd
= CreateWindowA (className
, winName
,
164 WS_OVERLAPPEDWINDOW
,
165 CW_USEDEFAULT
, CW_USEDEFAULT
, 300, 300, 0,
168 if (winetest_interactive
)
170 ShowWindow (hWnd
, SW_SHOW
);
177 static HDC
show_image(HWND hwnd
, HIMAGELIST himl
, int idx
, int size
,
178 LPCSTR loc
, BOOL clear
)
182 if (!winetest_interactive
|| !himl
) return NULL
;
184 SetWindowTextA(hwnd
, loc
);
186 ImageList_Draw(himl
, idx
, hdc
, 0, 0, ILD_TRANSPARENT
);
192 BitBlt(hdc
, 0, 0, size
, size
, hdc
, size
+1, size
+1, SRCCOPY
);
193 ReleaseDC(hwnd
, hdc
);
200 /* Useful for checking differences */
201 static void dump_bits(const BYTE
*p
, const BYTE
*q
, int size
)
207 for (i
= 0; i
< size
* 2; i
++)
210 for (j
= 0; j
< size
; j
++)
211 printf("%c%c", p
[j
] & 0xf0 ? 'X' : ' ', p
[j
] & 0xf ? 'X' : ' ');
213 for (j
= 0; j
< size
; j
++)
214 printf("%c%c", q
[j
] & 0xf0 ? 'X' : ' ', q
[j
] & 0xf ? 'X' : ' ');
222 static void check_bits(HWND hwnd
, HIMAGELIST himl
, int idx
, int size
,
223 const BYTE
*checkbits
, LPCSTR loc
)
225 BYTE bits
[100*100/8];
230 if (!winetest_interactive
|| !himl
) return;
232 memset(bits
, 0, sizeof(bits
));
233 hdc
= show_image(hwnd
, himl
, idx
, size
, loc
, FALSE
);
235 c
= GetPixel(hdc
, 0, 0);
237 for (y
= 0; y
< size
; y
++)
239 for (x
= 0; x
< size
; x
++)
242 if (GetPixel(hdc
, x
, y
) != c
) bits
[i
] |= (0x80 >> (x
& 0x7));
246 BitBlt(hdc
, 0, 0, size
, size
, hdc
, size
+1, size
+1, SRCCOPY
);
247 ReleaseDC(hwnd
, hdc
);
249 ok (memcmp(bits
, checkbits
, (size
* size
)/8) == 0,
250 "%s: bits different\n", loc
);
251 if (memcmp(bits
, checkbits
, (size
* size
)/8))
252 dump_bits(bits
, checkbits
, size
);
255 static void test_begindrag(void)
257 HIMAGELIST himl
= createImageList(7,13);
263 count
= ImageList_GetImageCount(himl
);
264 ok(count
> 2, "Tests need an ImageList with more than 2 images\n");
266 /* Two BeginDrag() without EndDrag() in between */
267 ret
= ImageList_BeginDrag(himl
, 1, 0, 0);
268 drag
= ImageList_GetDragImage(NULL
, NULL
);
269 ok(ret
&& drag
, "ImageList_BeginDrag() failed\n");
270 ret
= ImageList_BeginDrag(himl
, 0, 3, 5);
271 ok(!ret
, "ImageList_BeginDrag() returned TRUE\n");
272 drag
= ImageList_GetDragImage(NULL
, &hotspot
);
273 ok(!!drag
, "No active ImageList drag left\n");
274 ok(hotspot
.x
== 0 && hotspot
.y
== 0, "New ImageList drag was created\n");
276 drag
= ImageList_GetDragImage(NULL
, NULL
);
277 ok(!drag
, "ImageList drag was not destroyed\n");
279 /* Invalid image index */
280 ImageList_BeginDrag(himl
, 0, 0, 0);
281 ret
= ImageList_BeginDrag(himl
, count
, 3, 5);
282 ok(!ret
, "ImageList_BeginDrag() returned TRUE\n");
283 drag
= ImageList_GetDragImage(NULL
, &hotspot
);
284 ok(drag
&& hotspot
.x
== 0 && hotspot
.y
== 0, "Active drag should not have been canceled\n");
286 drag
= ImageList_GetDragImage(NULL
, NULL
);
287 ok(!drag
, "ImageList drag was not destroyed\n");
288 /* Invalid negative image indexes succeed */
289 ret
= ImageList_BeginDrag(himl
, -17, 0, 0);
290 drag
= ImageList_GetDragImage(NULL
, NULL
);
291 ok(ret
&& drag
, "ImageList drag was created\n");
293 ret
= ImageList_BeginDrag(himl
, -1, 0, 0);
294 drag
= ImageList_GetDragImage(NULL
, NULL
);
295 ok(ret
&& drag
, "ImageList drag was created\n");
297 ImageList_Destroy(himl
);
300 static void test_hotspot(void)
311 #define HOTSPOTS_MAX 4 /* Number of entries in hotspots */
312 static const struct hotspot hotspots
[HOTSPOTS_MAX
] = {
319 HIMAGELIST himl1
= createImageList(SIZEX1
, SIZEY1
);
320 HIMAGELIST himl2
= createImageList(SIZEX2
, SIZEY2
);
321 HWND hwnd
= create_a_window();
324 for (i
= 0; i
< HOTSPOTS_MAX
; i
++) {
325 for (j
= 0; j
< HOTSPOTS_MAX
; j
++) {
326 int dx1
= hotspots
[i
].dx
;
327 int dy1
= hotspots
[i
].dy
;
328 int dx2
= hotspots
[j
].dx
;
329 int dy2
= hotspots
[j
].dy
;
330 int correctx
, correcty
, newx
, newy
;
335 ret
= ImageList_BeginDrag(himl1
, 0, dx1
, dy1
);
336 ok(ret
!= 0, "BeginDrag failed for { %d, %d }\n", dx1
, dy1
);
337 sprintf(loc
, "BeginDrag (%d,%d)\n", i
, j
);
338 show_image(hwnd
, himl1
, 0, max(SIZEX1
, SIZEY1
), loc
, TRUE
);
340 /* check merging the dragged image with a second image */
341 ret
= ImageList_SetDragCursorImage(himl2
, 0, dx2
, dy2
);
342 ok(ret
!= 0, "SetDragCursorImage failed for {%d, %d}{%d, %d}\n",
344 sprintf(loc
, "SetDragCursorImage (%d,%d)\n", i
, j
);
345 show_image(hwnd
, himl2
, 0, max(SIZEX2
, SIZEY2
), loc
, TRUE
);
347 /* check new hotspot, it should be the same like the old one */
348 himlNew
= ImageList_GetDragImage(NULL
, &ppt
);
349 ok(ppt
.x
== dx1
&& ppt
.y
== dy1
,
350 "Expected drag hotspot [%d,%d] got [%d,%d]\n",
351 dx1
, dy1
, ppt
.x
, ppt
.y
);
352 /* check size of new dragged image */
353 ImageList_GetIconSize(himlNew
, &newx
, &newy
);
354 correctx
= max(SIZEX1
, max(SIZEX2
+ dx2
, SIZEX1
- dx2
));
355 correcty
= max(SIZEY1
, max(SIZEY2
+ dy2
, SIZEY1
- dy2
));
356 ok(newx
== correctx
&& newy
== correcty
,
357 "Expected drag image size [%d,%d] got [%d,%d]\n",
358 correctx
, correcty
, newx
, newy
);
359 sprintf(loc
, "GetDragImage (%d,%d)\n", i
, j
);
360 show_image(hwnd
, himlNew
, 0, max(correctx
, correcty
), loc
, TRUE
);
369 ImageList_Destroy(himl2
);
370 ImageList_Destroy(himl1
);
374 static void test_add_remove(void)
382 /* create an imagelist to play with */
383 himl
= ImageList_Create(84, 84, ILC_COLOR16
, 0, 3);
384 ok(himl
!=0,"failed to create imagelist\n");
386 /* load the icons to add to the image list */
387 hicon1
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
388 ok(hicon1
!= 0, "no hicon1\n");
389 hicon2
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
390 ok(hicon2
!= 0, "no hicon2\n");
391 hicon3
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
392 ok(hicon3
!= 0, "no hicon3\n");
394 /* remove when nothing exists */
395 ok(!ImageList_Remove(himl
,0),"removed nonexistent icon\n");
396 /* removing everything from an empty imagelist should succeed */
397 ok(ImageList_RemoveAll(himl
),"removed nonexistent icon\n");
400 ok(0==ImageList_AddIcon(himl
, hicon1
),"failed to add icon1\n");
401 ok(1==ImageList_AddIcon(himl
, hicon2
),"failed to add icon2\n");
402 ok(2==ImageList_AddIcon(himl
, hicon3
),"failed to add icon3\n");
404 /* remove an index out of range */
405 ok(!ImageList_Remove(himl
,4711),"removed nonexistent icon\n");
408 ok(ImageList_Remove(himl
,0),"can't remove 0\n");
409 ok(ImageList_Remove(himl
,0),"can't remove 0\n");
410 ok(ImageList_Remove(himl
,0),"can't remove 0\n");
412 /* remove one extra */
413 ok(!ImageList_Remove(himl
,0),"removed nonexistent icon\n");
416 ok(ImageList_Destroy(himl
),"destroy imagelist failed\n");
418 ok(-1==ImageList_AddIcon((HIMAGELIST
)0xdeadbeef, hicon1
),"don't crash on bad handle\n");
420 ok(DestroyIcon(hicon1
),"icon 1 wasn't deleted\n");
421 ok(DestroyIcon(hicon2
),"icon 2 wasn't deleted\n");
422 ok(DestroyIcon(hicon3
),"icon 3 wasn't deleted\n");
425 static void test_imagecount(void)
429 ok(0==ImageList_GetImageCount((HIMAGELIST
)0xdeadbeef),"don't crash on bad handle\n");
431 if (!pImageList_SetImageCount
)
433 win_skip("ImageList_SetImageCount not available\n");
437 himl
= ImageList_Create(84, 84, ILC_COLOR16
, 0, 3);
438 ok(himl
!=0,"failed to create imagelist\n");
440 ok(pImageList_SetImageCount(himl
, 3), "couldn't increase image count\n");
441 ok(ImageList_GetImageCount(himl
) == 3, "invalid image count after increase\n");
442 ok(pImageList_SetImageCount(himl
, 1), "couldn't decrease image count\n");
443 ok(ImageList_GetImageCount(himl
) == 1, "invalid image count after decrease to 1\n");
444 ok(pImageList_SetImageCount(himl
, 0), "couldn't decrease image count\n");
445 ok(ImageList_GetImageCount(himl
) == 0, "invalid image count after decrease to 0\n");
447 ok(ImageList_Destroy(himl
), "destroy imagelist failed\n");
450 static void test_DrawIndirect(void)
458 IMAGELISTDRAWPARAMS imldp
;
462 if (!pImageList_DrawIndirect
)
464 win_skip("ImageList_DrawIndirect not available, skipping test\n");
468 hwndfortest
= create_a_window();
469 hdc
= GetDC(hwndfortest
);
470 ok(hdc
!=NULL
, "couldn't get DC\n");
472 /* create an imagelist to play with */
473 himl
= ImageList_Create(48, 48, ILC_COLOR16
, 0, 3);
474 ok(himl
!=0,"failed to create imagelist\n");
476 /* load the icons to add to the image list */
477 hbm1
= CreateBitmap(48, 48, 1, 1, bitmap_bits
);
478 ok(hbm1
!= 0, "no bitmap 1\n");
479 hbm2
= CreateBitmap(48, 48, 1, 1, bitmap_bits
);
480 ok(hbm2
!= 0, "no bitmap 2\n");
481 hbm3
= CreateBitmap(48, 48, 1, 1, bitmap_bits
);
482 ok(hbm3
!= 0, "no bitmap 3\n");
485 ok(0==ImageList_Add(himl
, hbm1
, 0),"failed to add bitmap 1\n");
486 ok(1==ImageList_Add(himl
, hbm2
, 0),"failed to add bitmap 2\n");
488 if (pImageList_SetImageCount
)
490 ok(pImageList_SetImageCount(himl
,3),"Setimage count failed\n");
491 /*ok(2==ImageList_Add(himl, hbm3, NULL),"failed to add bitmap 3\n"); */
492 ok(ImageList_Replace(himl
, 2, hbm3
, 0),"failed to replace bitmap 3\n");
495 memset(&imldp
, 0, sizeof (imldp
));
496 ok(!pImageList_DrawIndirect(&imldp
), "zero data succeeded!\n");
497 imldp
.cbSize
= IMAGELISTDRAWPARAMS_V3_SIZE
;
498 ok(!pImageList_DrawIndirect(&imldp
), "zero hdc succeeded!\n");
500 ok(!pImageList_DrawIndirect(&imldp
),"zero himl succeeded!\n");
501 imldp
.himl
= (HIMAGELIST
)0xdeadbeef;
502 ok(!pImageList_DrawIndirect(&imldp
),"bad himl succeeded!\n");
505 force_redraw(hwndfortest
);
507 imldp
.fStyle
= SRCCOPY
;
508 imldp
.rgbBk
= CLR_DEFAULT
;
509 imldp
.rgbFg
= CLR_DEFAULT
;
512 ok(pImageList_DrawIndirect(&imldp
),"should succeed\n");
514 ok(pImageList_DrawIndirect(&imldp
),"should succeed\n");
516 ok(pImageList_DrawIndirect(&imldp
),"should succeed\n");
518 ok(!pImageList_DrawIndirect(&imldp
),"should fail\n");
521 ok(ImageList_Remove(himl
, 0), "removing 1st bitmap\n");
522 ok(ImageList_Remove(himl
, 0), "removing 2nd bitmap\n");
523 ok(ImageList_Remove(himl
, 0), "removing 3rd bitmap\n");
526 ok(ImageList_Destroy(himl
),"destroy imagelist failed\n");
528 /* bitmaps should not be deleted by the imagelist */
529 ok(DeleteObject(hbm1
),"bitmap 1 can't be deleted\n");
530 ok(DeleteObject(hbm2
),"bitmap 2 can't be deleted\n");
531 ok(DeleteObject(hbm3
),"bitmap 3 can't be deleted\n");
533 ReleaseDC(hwndfortest
, hdc
);
534 DestroyWindow(hwndfortest
);
537 static int get_color_format(HBITMAP bmp
)
540 HDC hdc
= CreateCompatibleDC(0);
541 HBITMAP hOldBmp
= SelectObject(hdc
, bmp
);
544 memset(&bmi
, 0, sizeof(bmi
));
545 bmi
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
546 ret
= GetDIBits(hdc
, bmp
, 0, 0, 0, &bmi
, DIB_RGB_COLORS
);
547 ok(ret
, "GetDIBits failed\n");
549 SelectObject(hdc
, hOldBmp
);
551 return bmi
.bmiHeader
.biBitCount
;
554 static void test_merge_colors(void)
556 HIMAGELIST himl
[8], hmerge
;
557 int sizes
[] = { ILC_COLOR
, ILC_COLOR
| ILC_MASK
, ILC_COLOR4
, ILC_COLOR8
, ILC_COLOR16
, ILC_COLOR24
, ILC_COLOR32
, ILC_COLORDDB
};
562 hicon1
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
563 ok(hicon1
!= NULL
, "failed to create hicon1\n");
565 for (i
= 0; i
< 8; i
++)
567 himl
[i
] = ImageList_Create(32, 32, sizes
[i
], 0, 3);
568 ok(himl
[i
] != NULL
, "failed to create himl[%d]\n", i
);
569 ok(0 == ImageList_AddIcon(himl
[i
], hicon1
), "add icon1 to himl[%d] failed\n", i
);
570 if (i
== 0 || i
== 1 || i
== 7)
572 ImageList_GetImageInfo(himl
[i
], 0, &info
);
573 sizes
[i
] = get_color_format(info
.hbmImage
);
577 for (i
= 0; i
< 8; i
++)
578 for (j
= 0; j
< 8; j
++)
580 hmerge
= ImageList_Merge(himl
[i
], 0, himl
[j
], 0, 0, 0);
581 ok(hmerge
!= NULL
, "merge himl[%d], himl[%d] failed\n", i
, j
);
583 ImageList_GetImageInfo(hmerge
, 0, &info
);
584 bpp
= get_color_format(info
.hbmImage
);
585 /* ILC_COLOR[X] is defined as [X] */
586 if (i
== 4 && j
== 7)
587 ok(bpp
== 16, /* merging ILC_COLOR16 with ILC_COLORDDB seems to be a special case */
588 "wrong biBitCount %d when merging lists %d (%d) and %d (%d)\n", bpp
, i
, sizes
[i
], j
, sizes
[j
]);
590 ok(bpp
== (i
> j
? sizes
[i
] : sizes
[j
]),
591 "wrong biBitCount %d when merging lists %d (%d) and %d (%d)\n", bpp
, i
, sizes
[i
], j
, sizes
[j
]);
592 ok(info
.hbmMask
!= 0, "Imagelist merged from %d and %d had no mask\n", i
, j
);
594 if (hmerge
) ImageList_Destroy(hmerge
);
597 for (i
= 0; i
< 8; i
++)
598 ImageList_Destroy(himl
[i
]);
601 static void test_merge(void)
603 HIMAGELIST himl1
, himl2
, hmerge
;
605 HWND hwnd
= create_a_window();
607 himl1
= ImageList_Create(32,32,0,0,3);
608 ok(himl1
!= NULL
,"failed to create himl1\n");
610 himl2
= ImageList_Create(32,32,0,0,3);
611 ok(himl2
!= NULL
,"failed to create himl2\n");
613 hicon1
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
614 ok(hicon1
!= NULL
, "failed to create hicon1\n");
616 if (!himl1
|| !himl2
|| !hicon1
)
619 ok(0==ImageList_AddIcon(himl2
, hicon1
),"add icon1 to himl2 failed\n");
620 check_bits(hwnd
, himl2
, 0, 32, icon_bits
, "add icon1 to himl2");
622 /* If himl1 has no images, merge still succeeds */
623 hmerge
= ImageList_Merge(himl1
, -1, himl2
, 0, 0, 0);
624 ok(hmerge
!= NULL
, "merge himl1,-1 failed\n");
625 check_bits(hwnd
, hmerge
, 0, 32, empty_bits
, "merge himl1,-1");
626 if (hmerge
) ImageList_Destroy(hmerge
);
628 hmerge
= ImageList_Merge(himl1
, 0, himl2
, 0, 0, 0);
629 ok(hmerge
!= NULL
,"merge himl1,0 failed\n");
630 check_bits(hwnd
, hmerge
, 0, 32, empty_bits
, "merge himl1,0");
631 if (hmerge
) ImageList_Destroy(hmerge
);
633 /* Same happens if himl2 is empty */
634 ImageList_Destroy(himl2
);
635 himl2
= ImageList_Create(32,32,0,0,3);
636 ok(himl2
!= NULL
,"failed to recreate himl2\n");
640 hmerge
= ImageList_Merge(himl1
, -1, himl2
, -1, 0, 0);
641 ok(hmerge
!= NULL
, "merge himl2,-1 failed\n");
642 check_bits(hwnd
, hmerge
, 0, 32, empty_bits
, "merge himl2,-1");
643 if (hmerge
) ImageList_Destroy(hmerge
);
645 hmerge
= ImageList_Merge(himl1
, -1, himl2
, 0, 0, 0);
646 ok(hmerge
!= NULL
, "merge himl2,0 failed\n");
647 check_bits(hwnd
, hmerge
, 0, 32, empty_bits
, "merge himl2,0");
648 if (hmerge
) ImageList_Destroy(hmerge
);
650 /* Now try merging an image with itself */
651 ok(0==ImageList_AddIcon(himl2
, hicon1
),"re-add icon1 to himl2 failed\n");
653 hmerge
= ImageList_Merge(himl2
, 0, himl2
, 0, 0, 0);
654 ok(hmerge
!= NULL
, "merge himl2 with itself failed\n");
655 check_bits(hwnd
, hmerge
, 0, 32, empty_bits
, "merge himl2 with itself");
656 if (hmerge
) ImageList_Destroy(hmerge
);
658 /* Try merging 2 different image lists */
659 ok(0==ImageList_AddIcon(himl1
, hicon1
),"add icon1 to himl1 failed\n");
661 hmerge
= ImageList_Merge(himl1
, 0, himl2
, 0, 0, 0);
662 ok(hmerge
!= NULL
, "merge himl1 with himl2 failed\n");
663 check_bits(hwnd
, hmerge
, 0, 32, empty_bits
, "merge himl1 with himl2");
664 if (hmerge
) ImageList_Destroy(hmerge
);
666 hmerge
= ImageList_Merge(himl1
, 0, himl2
, 0, 8, 16);
667 ok(hmerge
!= NULL
, "merge himl1 with himl2 8,16 failed\n");
668 check_bits(hwnd
, hmerge
, 0, 32, empty_bits
, "merge himl1 with himl2, 8,16");
669 if (hmerge
) ImageList_Destroy(hmerge
);
671 ImageList_Destroy(himl1
);
672 ImageList_Destroy(himl2
);
677 /*********************** imagelist storage test ***************************/
683 IStream IStream_iface
;
684 char *iml_data
; /* written imagelist data */
688 static struct my_IStream
*impl_from_IStream(IStream
*iface
)
690 return CONTAINING_RECORD(iface
, struct my_IStream
, IStream_iface
);
693 static HRESULT STDMETHODCALLTYPE
Test_Stream_QueryInterface(IStream
*iface
, REFIID riid
,
696 ok(0, "unexpected call\n");
700 static ULONG STDMETHODCALLTYPE
Test_Stream_AddRef(IStream
*iface
)
702 ok(0, "unexpected call\n");
706 static ULONG STDMETHODCALLTYPE
Test_Stream_Release(IStream
*iface
)
708 ok(0, "unexpected call\n");
712 static HRESULT STDMETHODCALLTYPE
Test_Stream_Read(IStream
*iface
, void *pv
, ULONG cb
,
715 ok(0, "unexpected call\n");
719 static BOOL
allocate_storage(struct my_IStream
*my_is
, ULONG add
)
721 my_is
->iml_data_size
+= add
;
723 if (!my_is
->iml_data
)
724 my_is
->iml_data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, my_is
->iml_data_size
);
726 my_is
->iml_data
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, my_is
->iml_data
, my_is
->iml_data_size
);
728 return my_is
->iml_data
!= NULL
;
731 static HRESULT STDMETHODCALLTYPE
Test_Stream_Write(IStream
*iface
, const void *pv
, ULONG cb
,
734 struct my_IStream
*my_is
= impl_from_IStream(iface
);
735 ULONG current_iml_data_size
= my_is
->iml_data_size
;
737 if (!allocate_storage(my_is
, cb
)) return E_FAIL
;
739 memcpy(my_is
->iml_data
+ current_iml_data_size
, pv
, cb
);
740 if (pcbWritten
) *pcbWritten
= cb
;
745 static HRESULT STDMETHODCALLTYPE
Test_Stream_Seek(IStream
*iface
, LARGE_INTEGER dlibMove
,
746 DWORD dwOrigin
, ULARGE_INTEGER
*plibNewPosition
)
748 ok(0, "unexpected call\n");
752 static HRESULT STDMETHODCALLTYPE
Test_Stream_SetSize(IStream
*iface
, ULARGE_INTEGER libNewSize
)
754 ok(0, "unexpected call\n");
758 static HRESULT STDMETHODCALLTYPE
Test_Stream_CopyTo(IStream
*iface
, IStream
*pstm
,
759 ULARGE_INTEGER cb
, ULARGE_INTEGER
*pcbRead
,
760 ULARGE_INTEGER
*pcbWritten
)
762 ok(0, "unexpected call\n");
766 static HRESULT STDMETHODCALLTYPE
Test_Stream_Commit(IStream
*iface
, DWORD grfCommitFlags
)
768 ok(0, "unexpected call\n");
772 static HRESULT STDMETHODCALLTYPE
Test_Stream_Revert(IStream
*iface
)
774 ok(0, "unexpected call\n");
778 static HRESULT STDMETHODCALLTYPE
Test_Stream_LockRegion(IStream
*iface
, ULARGE_INTEGER libOffset
,
779 ULARGE_INTEGER cb
, DWORD dwLockType
)
781 ok(0, "unexpected call\n");
785 static HRESULT STDMETHODCALLTYPE
Test_Stream_UnlockRegion(IStream
*iface
, ULARGE_INTEGER libOffset
,
786 ULARGE_INTEGER cb
, DWORD dwLockType
)
788 ok(0, "unexpected call\n");
792 static HRESULT STDMETHODCALLTYPE
Test_Stream_Stat(IStream
*iface
, STATSTG
*pstatstg
,
795 ok(0, "unexpected call\n");
799 static HRESULT STDMETHODCALLTYPE
Test_Stream_Clone(IStream
*iface
, IStream
**ppstm
)
801 ok(0, "unexpected call\n");
805 static const IStreamVtbl Test_Stream_Vtbl
=
807 Test_Stream_QueryInterface
,
817 Test_Stream_LockRegion
,
818 Test_Stream_UnlockRegion
,
823 static struct my_IStream Test_Stream
= { { &Test_Stream_Vtbl
}, 0, 0 };
825 static INT
DIB_GetWidthBytes( int width
, int bpp
)
827 return ((width
* bpp
+ 31) / 8) & ~3;
830 static ULONG
check_bitmap_data(const char *bm_data
, ULONG bm_data_size
,
831 INT width
, INT height
, INT bpp
,
834 const BITMAPFILEHEADER
*bmfh
= (const BITMAPFILEHEADER
*)bm_data
;
835 const BITMAPINFOHEADER
*bmih
= (const BITMAPINFOHEADER
*)(bm_data
+ sizeof(*bmfh
));
836 ULONG hdr_size
, image_size
;
838 hdr_size
= sizeof(*bmfh
) + sizeof(*bmih
);
839 if (bmih
->biBitCount
<= 8) hdr_size
+= (1 << bpp
) * sizeof(RGBQUAD
);
841 ok(bmfh
->bfType
== (('M' << 8) | 'B'), "wrong bfType 0x%02x\n", bmfh
->bfType
);
842 ok(bmfh
->bfSize
== hdr_size
, "wrong bfSize 0x%02x\n", bmfh
->bfSize
);
843 ok(bmfh
->bfReserved1
== 0, "wrong bfReserved1 0x%02x\n", bmfh
->bfReserved1
);
844 ok(bmfh
->bfReserved2
== 0, "wrong bfReserved2 0x%02x\n", bmfh
->bfReserved2
);
845 ok(bmfh
->bfOffBits
== hdr_size
, "wrong bfOffBits 0x%02x\n", bmfh
->bfOffBits
);
847 ok(bmih
->biSize
== sizeof(*bmih
), "wrong biSize %d\n", bmih
->biSize
);
848 ok(bmih
->biWidth
== width
, "wrong biWidth %d (expected %d)\n", bmih
->biWidth
, width
);
849 ok(bmih
->biHeight
== height
, "wrong biHeight %d (expected %d)\n", bmih
->biHeight
, height
);
850 ok(bmih
->biPlanes
== 1, "wrong biPlanes %d\n", bmih
->biPlanes
);
851 ok(bmih
->biBitCount
== bpp
, "wrong biBitCount %d\n", bmih
->biBitCount
);
853 image_size
= DIB_GetWidthBytes(bmih
->biWidth
, bmih
->biBitCount
) * bmih
->biHeight
;
854 ok(bmih
->biSizeImage
== image_size
, "wrong biSizeImage %u\n", bmih
->biSizeImage
);
860 sprintf(fname
, "bmp_%s.bmp", comment
);
861 f
= fopen(fname
, "wb");
862 fwrite(bm_data
, 1, bm_data_size
, f
);
866 return hdr_size
+ image_size
;
869 static void check_ilhead_data(const char *ilh_data
, INT cx
, INT cy
, INT cur
, INT max
, INT grow
, INT flags
)
871 const ILHEAD
*ilh
= (const ILHEAD
*)ilh_data
;
873 ok(ilh
->usMagic
== IMAGELIST_MAGIC
, "wrong usMagic %4x (expected %02x)\n", ilh
->usMagic
, IMAGELIST_MAGIC
);
874 ok(ilh
->usVersion
== 0x101, "wrong usVersion %x (expected 0x101)\n", ilh
->usVersion
);
875 ok(ilh
->cCurImage
== cur
, "wrong cCurImage %d (expected %d)\n", ilh
->cCurImage
, cur
);
876 ok(ilh
->cMaxImage
== max
, "wrong cMaxImage %d (expected %d)\n", ilh
->cMaxImage
, max
);
877 ok(ilh
->cGrow
== grow
, "wrong cGrow %d (expected %d)\n", ilh
->cGrow
, grow
);
878 ok(ilh
->cx
== cx
, "wrong cx %d (expected %d)\n", ilh
->cx
, cx
);
879 ok(ilh
->cy
== cy
, "wrong cy %d (expected %d)\n", ilh
->cy
, cy
);
880 ok(ilh
->bkcolor
== CLR_NONE
, "wrong bkcolor %x\n", ilh
->bkcolor
);
881 ok(ilh
->flags
== flags
|| broken(!(ilh
->flags
& 0xfe) && (flags
& 0xfe) == ILC_COLOR4
), /* <= w2k */
882 "wrong flags %04x\n", ilh
->flags
);
883 ok(ilh
->ovls
[0] == -1, "wrong ovls[0] %04x\n", ilh
->ovls
[0]);
884 ok(ilh
->ovls
[1] == -1, "wrong ovls[1] %04x\n", ilh
->ovls
[1]);
885 ok(ilh
->ovls
[2] == -1, "wrong ovls[2] %04x\n", ilh
->ovls
[2]);
886 ok(ilh
->ovls
[3] == -1, "wrong ovls[3] %04x\n", ilh
->ovls
[3]);
889 static HBITMAP
create_bitmap(INT cx
, INT cy
, COLORREF color
, const char *comment
)
893 HBITMAP hbmp
, hbmp_old
;
895 RECT rc
= { 0, 0, cx
, cy
};
897 hdc
= CreateCompatibleDC(0);
899 memset(&bmi
, 0, sizeof(bmi
));
900 bmi
.bmiHeader
.biSize
= sizeof(bmi
.bmiHeader
);
901 bmi
.bmiHeader
.biHeight
= cx
;
902 bmi
.bmiHeader
.biWidth
= cy
;
903 bmi
.bmiHeader
.biBitCount
= 24;
904 bmi
.bmiHeader
.biPlanes
= 1;
905 bmi
.bmiHeader
.biCompression
= BI_RGB
;
906 hbmp
= CreateDIBSection(hdc
, &bmi
, DIB_RGB_COLORS
, NULL
, NULL
, 0);
908 hbmp_old
= SelectObject(hdc
, hbmp
);
910 hbrush
= CreateSolidBrush(color
);
911 FillRect(hdc
, &rc
, hbrush
);
912 DeleteObject(hbrush
);
914 DrawTextA(hdc
, comment
, -1, &rc
, DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
);
916 SelectObject(hdc
, hbmp_old
);
922 #define iml_clear_stream_data() \
923 HeapFree(GetProcessHeap(), 0, Test_Stream.iml_data); \
924 Test_Stream.iml_data = NULL; \
925 Test_Stream.iml_data_size = 0;
927 static void check_iml_data(HIMAGELIST himl
, INT cx
, INT cy
, INT cur
, INT max
, INT grow
,
928 INT width
, INT height
, INT flags
, const char *comment
)
930 INT ret
, cxx
, cyy
, size
;
932 trace("%s\n", comment
);
934 ret
= ImageList_GetImageCount(himl
);
935 ok(ret
== cur
, "expected image count %d got %d\n", cur
, ret
);
937 ret
= ImageList_GetIconSize(himl
, &cxx
, &cyy
);
938 ok(ret
, "ImageList_GetIconSize failed\n");
939 ok(cxx
== cx
, "wrong cx %d (expected %d)\n", cxx
, cx
);
940 ok(cyy
== cy
, "wrong cy %d (expected %d)\n", cyy
, cy
);
942 iml_clear_stream_data();
943 ret
= ImageList_Write(himl
, &Test_Stream
.IStream_iface
);
944 ok(ret
, "ImageList_Write failed\n");
946 ok(Test_Stream
.iml_data
!= 0, "ImageList_Write didn't write any data\n");
947 ok(Test_Stream
.iml_data_size
> sizeof(ILHEAD
), "ImageList_Write wrote not enough data\n");
949 check_ilhead_data(Test_Stream
.iml_data
, cx
, cy
, cur
, max
, grow
, flags
);
950 size
= check_bitmap_data(Test_Stream
.iml_data
+ sizeof(ILHEAD
),
951 Test_Stream
.iml_data_size
- sizeof(ILHEAD
),
952 width
, height
, flags
& 0xfe, comment
);
953 if (size
< Test_Stream
.iml_data_size
- sizeof(ILHEAD
)) /* mask is present */
955 ok( flags
& ILC_MASK
, "extra data %u/%u but mask not expected\n",
956 Test_Stream
.iml_data_size
, size
);
957 check_bitmap_data(Test_Stream
.iml_data
+ sizeof(ILHEAD
) + size
,
958 Test_Stream
.iml_data_size
- sizeof(ILHEAD
) - size
,
959 width
, height
, 1, comment
);
963 static void image_list_init(HIMAGELIST himl
)
969 static const struct test_data
972 INT cx
, cy
, cur
, max
, grow
, width
, height
, bpp
;
976 { 255, BMP_CX
, BMP_CX
, 1, 2, 4, BMP_CX
* 4, BMP_CX
* 1, 24, "total 1" },
977 { 170, BMP_CX
, BMP_CX
, 2, 7, 4, BMP_CX
* 4, BMP_CX
* 2, 24, "total 2" },
978 { 85, BMP_CX
, BMP_CX
, 3, 7, 4, BMP_CX
* 4, BMP_CX
* 2, 24, "total 3" },
979 { 0, BMP_CX
, BMP_CX
, 4, 7, 4, BMP_CX
* 4, BMP_CX
* 2, 24, "total 4" },
980 { 0, BMP_CX
, BMP_CX
, 5, 7, 4, BMP_CX
* 4, BMP_CX
* 2, 24, "total 5" },
981 { 85, BMP_CX
, BMP_CX
, 6, 7, 4, BMP_CX
* 4, BMP_CX
* 2, 24, "total 6" },
982 { 170, BMP_CX
, BMP_CX
, 7, 12, 4, BMP_CX
* 4, BMP_CX
* 3, 24, "total 7" },
983 { 255, BMP_CX
, BMP_CX
, 8, 12, 4, BMP_CX
* 4, BMP_CX
* 3, 24, "total 8" },
984 { 255, BMP_CX
, BMP_CX
, 9, 12, 4, BMP_CX
* 4, BMP_CX
* 3, 24, "total 9" },
985 { 170, BMP_CX
, BMP_CX
, 10, 12, 4, BMP_CX
* 4, BMP_CX
* 3, 24, "total 10" },
986 { 85, BMP_CX
, BMP_CX
, 11, 12, 4, BMP_CX
* 4, BMP_CX
* 3, 24, "total 11" },
987 { 0, BMP_CX
, BMP_CX
, 12, 17, 4, BMP_CX
* 4, BMP_CX
* 5, 24, "total 12" },
988 { 0, BMP_CX
, BMP_CX
, 13, 17, 4, BMP_CX
* 4, BMP_CX
* 5, 24, "total 13" },
989 { 85, BMP_CX
, BMP_CX
, 14, 17, 4, BMP_CX
* 4, BMP_CX
* 5, 24, "total 14" },
990 { 170, BMP_CX
, BMP_CX
, 15, 17, 4, BMP_CX
* 4, BMP_CX
* 5, 24, "total 15" },
991 { 255, BMP_CX
, BMP_CX
, 16, 17, 4, BMP_CX
* 4, BMP_CX
* 5, 24, "total 16" },
992 { 255, BMP_CX
, BMP_CX
, 17, 22, 4, BMP_CX
* 4, BMP_CX
* 6, 24, "total 17" },
993 { 170, BMP_CX
, BMP_CX
, 18, 22, 4, BMP_CX
* 4, BMP_CX
* 6, 24, "total 18" },
994 { 85, BMP_CX
, BMP_CX
, 19, 22, 4, BMP_CX
* 4, BMP_CX
* 6, 24, "total 19" },
995 { 0, BMP_CX
, BMP_CX
, 20, 22, 4, BMP_CX
* 4, BMP_CX
* 6, 24, "total 20" },
996 { 0, BMP_CX
, BMP_CX
, 21, 22, 4, BMP_CX
* 4, BMP_CX
* 6, 24, "total 21" },
997 { 85, BMP_CX
, BMP_CX
, 22, 27, 4, BMP_CX
* 4, BMP_CX
* 7, 24, "total 22" },
998 { 170, BMP_CX
, BMP_CX
, 23, 27, 4, BMP_CX
* 4, BMP_CX
* 7, 24, "total 23" },
999 { 255, BMP_CX
, BMP_CX
, 24, 27, 4, BMP_CX
* 4, BMP_CX
* 7, 24, "total 24" }
1002 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 2, 4, BMP_CX
* 4, BMP_CX
* 1, ILC_COLOR24
, "total 0");
1004 #define add_bitmap(grey) \
1005 sprintf(comment, "%d", n++); \
1006 hbm = create_bitmap(BMP_CX, BMP_CX, RGB((grey),(grey),(grey)), comment); \
1007 ImageList_Add(himl, hbm, NULL); \
1010 for (i
= 0; i
< sizeof(td
)/sizeof(td
[0]); i
++)
1012 add_bitmap(td
[i
].grey
);
1013 check_iml_data(himl
, td
[i
].cx
, td
[i
].cy
, td
[i
].cur
, td
[i
].max
, td
[i
].grow
,
1014 td
[i
].width
, td
[i
].height
, td
[i
].bpp
, td
[i
].comment
);
1019 static void test_imagelist_storage(void)
1026 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR24
, 1, 1);
1027 ok(himl
!= 0, "ImageList_Create failed\n");
1029 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 2, 4, BMP_CX
* 4, BMP_CX
* 1, ILC_COLOR24
, "empty");
1031 image_list_init(himl
);
1032 check_iml_data(himl
, BMP_CX
, BMP_CX
, 24, 27, 4, BMP_CX
* 4, BMP_CX
* 7, ILC_COLOR24
, "orig");
1034 ret
= ImageList_Remove(himl
, 4);
1035 ok(ret
, "ImageList_Remove failed\n");
1036 check_iml_data(himl
, BMP_CX
, BMP_CX
, 23, 27, 4, BMP_CX
* 4, BMP_CX
* 7, ILC_COLOR24
, "1");
1038 ret
= ImageList_Remove(himl
, 5);
1039 ok(ret
, "ImageList_Remove failed\n");
1040 check_iml_data(himl
, BMP_CX
, BMP_CX
, 22, 27, 4, BMP_CX
* 4, BMP_CX
* 7, ILC_COLOR24
, "2");
1042 ret
= ImageList_Remove(himl
, 6);
1043 ok(ret
, "ImageList_Remove failed\n");
1044 check_iml_data(himl
, BMP_CX
, BMP_CX
, 21, 27, 4, BMP_CX
* 4, BMP_CX
* 7, ILC_COLOR24
, "3");
1046 ret
= ImageList_Remove(himl
, 7);
1047 ok(ret
, "ImageList_Remove failed\n");
1048 check_iml_data(himl
, BMP_CX
, BMP_CX
, 20, 27, 4, BMP_CX
* 4, BMP_CX
* 7, ILC_COLOR24
, "4");
1050 ret
= ImageList_Remove(himl
, -2);
1051 ok(!ret
, "ImageList_Remove(-2) should fail\n");
1052 check_iml_data(himl
, BMP_CX
, BMP_CX
, 20, 27, 4, BMP_CX
* 4, BMP_CX
* 7, ILC_COLOR24
, "5");
1054 ret
= ImageList_Remove(himl
, 20);
1055 ok(!ret
, "ImageList_Remove(20) should fail\n");
1056 check_iml_data(himl
, BMP_CX
, BMP_CX
, 20, 27, 4, BMP_CX
* 4, BMP_CX
* 7, ILC_COLOR24
, "6");
1058 ret
= ImageList_Remove(himl
, -1);
1059 ok(ret
, "ImageList_Remove(-1) failed\n");
1060 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 4, 4, BMP_CX
* 4, BMP_CX
* 1, ILC_COLOR24
, "7");
1062 ret
= ImageList_Destroy(himl
);
1063 ok(ret
, "ImageList_Destroy failed\n");
1065 iml_clear_stream_data();
1067 /* test ImageList_Create storage allocation */
1069 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR24
, 0, 32);
1070 ok(himl
!= 0, "ImageList_Create failed\n");
1071 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 1, 32, BMP_CX
* 4, BMP_CX
* 1, ILC_COLOR24
, "init 0 grow 32");
1072 hbm
= create_bitmap(BMP_CX
* 9, BMP_CX
, 0, "9");
1073 ret
= ImageList_Add(himl
, hbm
, NULL
);
1074 ok(ret
== 0, "ImageList_Add returned %d, expected 0\n", ret
);
1075 check_iml_data(himl
, BMP_CX
, BMP_CX
, 1, 34, 32, BMP_CX
* 4, BMP_CX
* 9, ILC_COLOR24
, "add 1 x 9");
1077 ret
= ImageList_Destroy(himl
);
1078 ok(ret
, "ImageList_Destroy failed\n");
1079 iml_clear_stream_data();
1081 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR24
, 4, 4);
1082 ok(himl
!= 0, "ImageList_Create failed\n");
1083 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 5, 4, BMP_CX
* 4, BMP_CX
* 2, ILC_COLOR24
, "init 4 grow 4");
1084 hbm
= create_bitmap(BMP_CX
, BMP_CX
* 9, 0, "9");
1085 ret
= ImageList_Add(himl
, hbm
, NULL
);
1086 ok(ret
== 0, "ImageList_Add returned %d, expected 0\n", ret
);
1087 check_iml_data(himl
, BMP_CX
, BMP_CX
, 9, 15, 4, BMP_CX
* 4, BMP_CX
* 4, ILC_COLOR24
, "add 9 x 1");
1088 ret
= ImageList_Add(himl
, hbm
, NULL
);
1089 ok(ret
== 9, "ImageList_Add returned %d, expected 9\n", ret
);
1090 check_iml_data(himl
, BMP_CX
, BMP_CX
, 18, 25, 4, BMP_CX
* 4, BMP_CX
* 7, ILC_COLOR24
, "add 9 x 1");
1092 ret
= ImageList_Destroy(himl
);
1093 ok(ret
, "ImageList_Destroy failed\n");
1094 iml_clear_stream_data();
1096 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR24
, 207, 209);
1097 ok(himl
!= 0, "ImageList_Create failed\n");
1098 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 208, 212, BMP_CX
* 4, BMP_CX
* 52, ILC_COLOR24
, "init 207 grow 209");
1099 ret
= ImageList_Destroy(himl
);
1100 ok(ret
, "ImageList_Destroy failed\n");
1101 iml_clear_stream_data();
1103 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR24
, 209, 207);
1104 ok(himl
!= 0, "ImageList_Create failed\n");
1105 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 210, 208, BMP_CX
* 4, BMP_CX
* 53, ILC_COLOR24
, "init 209 grow 207");
1106 ret
= ImageList_Destroy(himl
);
1107 ok(ret
, "ImageList_Destroy failed\n");
1108 iml_clear_stream_data();
1110 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR24
, 14, 4);
1111 ok(himl
!= 0, "ImageList_Create failed\n");
1112 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 15, 4, BMP_CX
* 4, BMP_CX
* 4, ILC_COLOR24
, "init 14 grow 4");
1113 ret
= ImageList_Destroy(himl
);
1114 ok(ret
, "ImageList_Destroy failed\n");
1115 iml_clear_stream_data();
1117 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR24
, 5, 9);
1118 ok(himl
!= 0, "ImageList_Create failed\n");
1119 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 6, 12, BMP_CX
* 4, BMP_CX
* 2, ILC_COLOR24
, "init 5 grow 9");
1120 ret
= ImageList_Destroy(himl
);
1121 ok(ret
, "ImageList_Destroy failed\n");
1122 iml_clear_stream_data();
1124 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR24
, 9, 5);
1125 ok(himl
!= 0, "ImageList_Create failed\n");
1126 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 10, 8, BMP_CX
* 4, BMP_CX
* 3, ILC_COLOR24
, "init 9 grow 5");
1127 ret
= ImageList_Destroy(himl
);
1128 ok(ret
, "ImageList_Destroy failed\n");
1129 iml_clear_stream_data();
1131 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR24
, 2, 4);
1132 ok(himl
!= 0, "ImageList_Create failed\n");
1133 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 3, 4, BMP_CX
* 4, BMP_CX
* 1, ILC_COLOR24
, "init 2 grow 4");
1134 ret
= ImageList_Destroy(himl
);
1135 ok(ret
, "ImageList_Destroy failed\n");
1136 iml_clear_stream_data();
1138 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR24
, 4, 2);
1139 ok(himl
!= 0, "ImageList_Create failed\n");
1140 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 5, 4, BMP_CX
* 4, BMP_CX
* 2, ILC_COLOR24
, "init 4 grow 2");
1141 ret
= ImageList_Destroy(himl
);
1142 ok(ret
, "ImageList_Destroy failed\n");
1143 iml_clear_stream_data();
1145 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR8
, 4, 2);
1146 ok(himl
!= 0, "ImageList_Create failed\n");
1147 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 5, 4, BMP_CX
* 4, BMP_CX
* 2, ILC_COLOR8
, "bpp 8");
1148 ret
= ImageList_Destroy(himl
);
1149 ok(ret
, "ImageList_Destroy failed\n");
1150 iml_clear_stream_data();
1152 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR4
, 4, 2);
1153 ok(himl
!= 0, "ImageList_Create failed\n");
1154 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 5, 4, BMP_CX
* 4, BMP_CX
* 2, ILC_COLOR4
, "bpp 4");
1155 ret
= ImageList_Destroy(himl
);
1156 ok(ret
, "ImageList_Destroy failed\n");
1157 iml_clear_stream_data();
1159 himl
= ImageList_Create(BMP_CX
, BMP_CX
, 0, 4, 2);
1160 ok(himl
!= 0, "ImageList_Create failed\n");
1161 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 5, 4, BMP_CX
* 4, BMP_CX
* 2, ILC_COLOR4
, "bpp default");
1162 icon
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
1163 ok( ImageList_AddIcon(himl
, icon
) == 0,"failed to add icon\n");
1164 ok( ImageList_AddIcon(himl
, icon
) == 1,"failed to add icon\n");
1165 DestroyIcon( icon
);
1166 check_iml_data(himl
, BMP_CX
, BMP_CX
, 2, 5, 4, BMP_CX
* 4, BMP_CX
* 2, ILC_COLOR4
, "bpp default");
1167 ret
= ImageList_Destroy(himl
);
1168 ok(ret
, "ImageList_Destroy failed\n");
1169 iml_clear_stream_data();
1171 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR24
|ILC_MASK
, 4, 2);
1172 ok(himl
!= 0, "ImageList_Create failed\n");
1173 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 5, 4, BMP_CX
* 4, BMP_CX
* 2, ILC_COLOR24
|ILC_MASK
,
1175 icon
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
1176 ok( ImageList_AddIcon(himl
, icon
) == 0,"failed to add icon\n");
1177 ok( ImageList_AddIcon(himl
, icon
) == 1,"failed to add icon\n");
1178 DestroyIcon( icon
);
1179 check_iml_data(himl
, BMP_CX
, BMP_CX
, 2, 5, 4, BMP_CX
* 4, BMP_CX
* 2, ILC_COLOR24
|ILC_MASK
,
1181 ret
= ImageList_Destroy(himl
);
1182 ok(ret
, "ImageList_Destroy failed\n");
1183 iml_clear_stream_data();
1185 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR4
|ILC_MASK
, 4, 2);
1186 ok(himl
!= 0, "ImageList_Create failed\n");
1187 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 5, 4, BMP_CX
* 4, BMP_CX
* 2, ILC_COLOR4
|ILC_MASK
,
1189 icon
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
1190 ok( ImageList_AddIcon(himl
, icon
) == 0,"failed to add icon\n");
1191 ok( ImageList_AddIcon(himl
, icon
) == 1,"failed to add icon\n");
1192 DestroyIcon( icon
);
1193 check_iml_data(himl
, BMP_CX
, BMP_CX
, 2, 5, 4, BMP_CX
* 4, BMP_CX
* 2, ILC_COLOR4
|ILC_MASK
,
1195 ret
= ImageList_Destroy(himl
);
1196 ok(ret
, "ImageList_Destroy failed\n");
1197 iml_clear_stream_data();
1199 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR4
|ILC_MASK
, 2, 99);
1200 ok(himl
!= 0, "ImageList_Create failed\n");
1201 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 3, 100, BMP_CX
* 4, BMP_CX
, ILC_COLOR4
|ILC_MASK
,
1203 icon
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
1204 ok( ImageList_AddIcon(himl
, icon
) == 0,"failed to add icon\n");
1205 ok( ImageList_AddIcon(himl
, icon
) == 1,"failed to add icon\n");
1206 check_iml_data(himl
, BMP_CX
, BMP_CX
, 2, 3, 100, BMP_CX
* 4, BMP_CX
, ILC_COLOR4
|ILC_MASK
,
1207 "init 2 grow 99 2 icons");
1208 ok( ImageList_AddIcon(himl
, icon
) == 2,"failed to add icon\n");
1209 DestroyIcon( icon
);
1210 check_iml_data(himl
, BMP_CX
, BMP_CX
, 3, 104, 100, BMP_CX
* 4, BMP_CX
* 104/4, ILC_COLOR4
|ILC_MASK
,
1211 "init 2 grow 99 3 icons");
1212 ok( ImageList_Remove(himl
, -1) == TRUE
,"failed to remove icon\n");
1213 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 100, 100, BMP_CX
* 4, BMP_CX
* 100/4, ILC_COLOR4
|ILC_MASK
,
1214 "init 2 grow 99 empty");
1215 ok( ImageList_SetImageCount(himl
, 22) == TRUE
,"failed to set image count\n");
1216 check_iml_data(himl
, BMP_CX
, BMP_CX
, 22, 23, 100, BMP_CX
* 4, BMP_CX
* 24/4, ILC_COLOR4
|ILC_MASK
,
1217 "init 2 grow 99 set count 22");
1218 ok( ImageList_SetImageCount(himl
, 0) == TRUE
,"failed to set image count\n");
1219 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 1, 100, BMP_CX
* 4, BMP_CX
, ILC_COLOR4
|ILC_MASK
,
1220 "init 2 grow 99 set count 0");
1221 ok( ImageList_SetImageCount(himl
, 42) == TRUE
,"failed to set image count\n");
1222 check_iml_data(himl
, BMP_CX
, BMP_CX
, 42, 43, 100, BMP_CX
* 4, BMP_CX
* 44/4, ILC_COLOR4
|ILC_MASK
,
1223 "init 2 grow 99 set count 42");
1224 ret
= ImageList_Destroy(himl
);
1225 ok(ret
, "ImageList_Destroy failed\n");
1226 iml_clear_stream_data();
1228 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR4
|ILC_MASK
, 2, 65536+12);
1229 ok(himl
!= 0, "ImageList_Create failed\n");
1230 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 3, 12, BMP_CX
* 4, BMP_CX
, ILC_COLOR4
|ILC_MASK
,
1231 "init 2 grow 65536+12");
1232 ret
= ImageList_Destroy(himl
);
1233 ok(ret
, "ImageList_Destroy failed\n");
1234 iml_clear_stream_data();
1236 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR4
|ILC_MASK
, 2, 65535);
1237 ok(himl
!= 0, "ImageList_Create failed\n");
1238 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 3, 0, BMP_CX
* 4, BMP_CX
, ILC_COLOR4
|ILC_MASK
,
1239 "init 2 grow 65535");
1240 ret
= ImageList_Destroy(himl
);
1241 ok(ret
, "ImageList_Destroy failed\n");
1242 iml_clear_stream_data();
1244 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR4
|ILC_MASK
, 2, -20);
1245 ok(himl
!= 0, "ImageList_Create failed\n");
1246 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 3, 4, BMP_CX
* 4, BMP_CX
, ILC_COLOR4
|ILC_MASK
,
1248 ret
= ImageList_Destroy(himl
);
1249 ok(ret
, "ImageList_Destroy failed\n");
1250 iml_clear_stream_data();
1253 static void test_shell_imagelist(void)
1255 HRESULT (WINAPI
*pSHGetImageList
)(INT
, REFIID
, void**);
1256 IImageList
*iml
= NULL
;
1263 /* Try to load function from shell32 */
1264 hShell32
= LoadLibraryA("shell32.dll");
1265 pSHGetImageList
= (void*)GetProcAddress(hShell32
, (LPCSTR
) 727);
1267 if (!pSHGetImageList
)
1269 win_skip("SHGetImageList not available, skipping test\n");
1270 FreeLibrary(hShell32
);
1274 /* Get system image list */
1275 hr
= pSHGetImageList(SHIL_SYSSMALL
, &IID_IImageList
, (void**)&iml
);
1276 ok(SUCCEEDED(hr
), "SHGetImageList failed, hr=%x\n", hr
);
1279 FreeLibrary(hShell32
);
1283 IImageList_GetImageCount(iml
, &out
);
1284 ok(out
> 0, "IImageList_GetImageCount returned out <= 0\n");
1286 /* Fetch the small icon size */
1287 cx
= GetSystemMetrics(SM_CXSMICON
);
1288 cy
= GetSystemMetrics(SM_CYSMICON
);
1290 /* Check icon size matches */
1291 IImageList_GetImageRect(iml
, 0, &rect
);
1292 ok(((rect
.right
== cx
) && (rect
.bottom
== cy
)),
1293 "IImageList_GetImageRect returned r:%d,b:%d\n",
1294 rect
.right
, rect
.bottom
);
1296 IImageList_Release(iml
);
1297 FreeLibrary(hShell32
);
1300 static HBITMAP
create_test_bitmap(HDC hdc
, int bpp
, UINT32 pixel1
, UINT32 pixel2
)
1303 UINT32
*buffer
= NULL
;
1304 BITMAPINFO bitmapInfo
= {{sizeof(BITMAPINFOHEADER
), 2, 1, 1, bpp
, BI_RGB
,
1307 hBitmap
= CreateDIBSection(hdc
, &bitmapInfo
, DIB_RGB_COLORS
, (void**)&buffer
, NULL
, 0);
1308 ok(hBitmap
!= NULL
&& buffer
!= NULL
, "CreateDIBSection failed.\n");
1310 if(!hBitmap
|| !buffer
)
1312 DeleteObject(hBitmap
);
1322 static BOOL
colour_match(UINT32 x
, UINT32 y
)
1324 const INT32 tolerance
= 8;
1326 const INT32 dr
= abs((INT32
)(x
& 0x000000FF) - (INT32
)(y
& 0x000000FF));
1327 const INT32 dg
= abs((INT32
)((x
& 0x0000FF00) >> 8) - (INT32
)((y
& 0x0000FF00) >> 8));
1328 const INT32 db
= abs((INT32
)((x
& 0x00FF0000) >> 16) - (INT32
)((y
& 0x00FF0000) >> 16));
1330 return (dr
<= tolerance
&& dg
<= tolerance
&& db
<= tolerance
);
1333 static void check_ImageList_DrawIndirect(IMAGELISTDRAWPARAMS
*ildp
, UINT32
*bits
,
1334 UINT32 expected
, int line
)
1336 bits
[0] = 0x00FFFFFF;
1337 pImageList_DrawIndirect(ildp
);
1338 ok(colour_match(bits
[0], expected
),
1339 "ImageList_DrawIndirect: Pixel %08X, Expected a close match to %08X from line %d\n",
1340 bits
[0] & 0x00FFFFFF, expected
, line
);
1344 static void check_ImageList_DrawIndirect_fStyle(HDC hdc
, HIMAGELIST himl
, UINT32
*bits
, int i
,
1345 UINT fStyle
, UINT32 expected
, int line
)
1347 IMAGELISTDRAWPARAMS ildp
= {sizeof(IMAGELISTDRAWPARAMS
), himl
, i
, hdc
,
1348 0, 0, 0, 0, 0, 0, CLR_NONE
, CLR_NONE
, fStyle
, 0, ILS_NORMAL
, 0, 0x00000000};
1349 check_ImageList_DrawIndirect(&ildp
, bits
, expected
, line
);
1352 static void check_ImageList_DrawIndirect_ILD_ROP(HDC hdc
, HIMAGELIST himl
, UINT32
*bits
, int i
,
1353 DWORD dwRop
, UINT32 expected
, int line
)
1355 IMAGELISTDRAWPARAMS ildp
= {sizeof(IMAGELISTDRAWPARAMS
), himl
, i
, hdc
,
1356 0, 0, 0, 0, 0, 0, CLR_NONE
, CLR_NONE
, ILD_IMAGE
| ILD_ROP
, dwRop
, ILS_NORMAL
, 0, 0x00000000};
1357 check_ImageList_DrawIndirect(&ildp
, bits
, expected
, line
);
1360 static void check_ImageList_DrawIndirect_fState(HDC hdc
, HIMAGELIST himl
, UINT32
*bits
, int i
, UINT fStyle
,
1361 UINT fState
, DWORD Frame
, UINT32 expected
, int line
)
1363 IMAGELISTDRAWPARAMS ildp
= {sizeof(IMAGELISTDRAWPARAMS
), himl
, i
, hdc
,
1364 0, 0, 0, 0, 0, 0, CLR_NONE
, CLR_NONE
, fStyle
, 0, fState
, Frame
, 0x00000000};
1365 check_ImageList_DrawIndirect(&ildp
, bits
, expected
, line
);
1368 static void check_ImageList_DrawIndirect_broken(HDC hdc
, HIMAGELIST himl
, UINT32
*bits
, int i
,
1369 UINT fStyle
, UINT fState
, DWORD Frame
, UINT32 expected
,
1370 UINT32 broken_expected
, int line
)
1372 IMAGELISTDRAWPARAMS ildp
= {sizeof(IMAGELISTDRAWPARAMS
), himl
, i
, hdc
,
1373 0, 0, 0, 0, 0, 0, CLR_NONE
, CLR_NONE
, fStyle
, 0, fState
, Frame
, 0x00000000};
1374 bits
[0] = 0x00FFFFFF;
1375 pImageList_DrawIndirect(&ildp
);
1376 ok(colour_match(bits
[0], expected
) ||
1377 broken(colour_match(bits
[0], broken_expected
)),
1378 "ImageList_DrawIndirect: Pixel %08X, Expected a close match to %08X from line %d\n",
1379 bits
[0] & 0x00FFFFFF, expected
, line
);
1382 static void test_ImageList_DrawIndirect(void)
1384 HIMAGELIST himl
= NULL
;
1387 HBITMAP hbmOld
= NULL
, hbmDst
= NULL
;
1388 HBITMAP hbmMask
= NULL
, hbmInverseMask
= NULL
;
1389 HBITMAP hbmImage
= NULL
, hbmAlphaImage
= NULL
, hbmTransparentImage
= NULL
;
1390 int iImage
= -1, iAlphaImage
= -1, iTransparentImage
= -1;
1392 UINT32 maskBits
= 0x00000000, inverseMaskBits
= 0xFFFFFFFF;
1393 int bpp
, broken_value
;
1395 BITMAPINFO bitmapInfo
= {{sizeof(BITMAPINFOHEADER
), 2, 1, 1, 32, BI_RGB
,
1398 hdcDst
= CreateCompatibleDC(0);
1399 ok(hdcDst
!= 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1402 bpp
= GetDeviceCaps(hdcDst
, BITSPIXEL
);
1404 hbmMask
= CreateBitmap(2, 1, 1, 1, &maskBits
);
1405 ok(hbmMask
!= 0, "CreateBitmap failed\n");
1406 if(!hbmMask
) goto cleanup
;
1408 hbmInverseMask
= CreateBitmap(2, 1, 1, 1, &inverseMaskBits
);
1409 ok(hbmInverseMask
!= 0, "CreateBitmap failed\n");
1410 if(!hbmInverseMask
) goto cleanup
;
1412 himl
= pImageList_Create(2, 1, ILC_COLOR32
, 0, 1);
1413 ok(himl
!= 0, "ImageList_Create failed\n");
1414 if(!himl
) goto cleanup
;
1416 /* Add a no-alpha image */
1417 hbmImage
= create_test_bitmap(hdcDst
, 32, 0x00ABCDEF, 0x00ABCDEF);
1418 if(!hbmImage
) goto cleanup
;
1420 iImage
= pImageList_Add(himl
, hbmImage
, hbmMask
);
1421 ok(iImage
!= -1, "ImageList_Add failed\n");
1422 if(iImage
== -1) goto cleanup
;
1424 /* Add an alpha image */
1425 hbmAlphaImage
= create_test_bitmap(hdcDst
, 32, 0x89ABCDEF, 0x89ABCDEF);
1426 if(!hbmAlphaImage
) goto cleanup
;
1428 iAlphaImage
= pImageList_Add(himl
, hbmAlphaImage
, hbmMask
);
1429 ok(iAlphaImage
!= -1, "ImageList_Add failed\n");
1430 if(iAlphaImage
== -1) goto cleanup
;
1432 /* Add a transparent alpha image */
1433 hbmTransparentImage
= create_test_bitmap(hdcDst
, 32, 0x00ABCDEF, 0x89ABCDEF);
1434 if(!hbmTransparentImage
) goto cleanup
;
1436 iTransparentImage
= pImageList_Add(himl
, hbmTransparentImage
, hbmMask
);
1437 ok(iTransparentImage
!= -1, "ImageList_Add failed\n");
1438 if(iTransparentImage
== -1) goto cleanup
;
1441 bitmapInfo
.bmiHeader
.biBitCount
= 32;
1442 hbmDst
= CreateDIBSection(hdcDst
, &bitmapInfo
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
1443 ok (hbmDst
&& bits
, "CreateDIBSection failed to return a valid bitmap and buffer\n");
1444 if (!hbmDst
|| !bits
)
1446 hbmOld
= SelectObject(hdcDst
, hbmDst
);
1448 check_ImageList_DrawIndirect_fStyle(hdcDst
, himl
, bits
, iImage
, ILD_NORMAL
, 0x00ABCDEF, __LINE__
);
1449 check_ImageList_DrawIndirect_fStyle(hdcDst
, himl
, bits
, iImage
, ILD_TRANSPARENT
, 0x00ABCDEF, __LINE__
);
1450 todo_wine
check_ImageList_DrawIndirect_broken(hdcDst
, himl
, bits
, iAlphaImage
, ILD_BLEND25
, ILS_NORMAL
, 0, 0x00E8F1FA, 0x00D4D9DD, __LINE__
);
1451 if (bpp
== 16 || bpp
== 24) broken_value
= 0x00D4D9DD;
1452 else broken_value
= 0x00B4BDC4;
1453 todo_wine
check_ImageList_DrawIndirect_broken(hdcDst
, himl
, bits
, iAlphaImage
, ILD_BLEND50
, ILS_NORMAL
, 0, 0x00E8F1FA, broken_value
, __LINE__
);
1454 check_ImageList_DrawIndirect_fStyle(hdcDst
, himl
, bits
, iImage
, ILD_MASK
, 0x00ABCDEF, __LINE__
);
1455 check_ImageList_DrawIndirect_fStyle(hdcDst
, himl
, bits
, iImage
, ILD_IMAGE
, 0x00ABCDEF, __LINE__
);
1456 check_ImageList_DrawIndirect_fStyle(hdcDst
, himl
, bits
, iImage
, ILD_PRESERVEALPHA
, 0x00ABCDEF, __LINE__
);
1458 check_ImageList_DrawIndirect_fStyle(hdcDst
, himl
, bits
, iAlphaImage
, ILD_NORMAL
, 0x00D3E5F7, __LINE__
);
1459 check_ImageList_DrawIndirect_fStyle(hdcDst
, himl
, bits
, iAlphaImage
, ILD_TRANSPARENT
, 0x00D3E5F7, __LINE__
);
1461 if (bpp
== 16 || bpp
== 24) broken_value
= 0x00D4D9DD;
1462 else broken_value
= 0x009DA8B1;
1463 todo_wine
check_ImageList_DrawIndirect_broken(hdcDst
, himl
, bits
, iAlphaImage
, ILD_BLEND25
, ILS_NORMAL
, 0, 0x00E8F1FA, broken_value
, __LINE__
);
1464 if (bpp
== 16 || bpp
== 24) broken_value
= 0x00D4D9DD;
1465 else broken_value
= 0x008C99A3;
1466 todo_wine
check_ImageList_DrawIndirect_broken(hdcDst
, himl
, bits
, iAlphaImage
, ILD_BLEND50
, ILS_NORMAL
, 0, 0x00E8F1FA, broken_value
, __LINE__
);
1467 check_ImageList_DrawIndirect_fStyle(hdcDst
, himl
, bits
, iAlphaImage
, ILD_MASK
, 0x00D3E5F7, __LINE__
);
1468 check_ImageList_DrawIndirect_fStyle(hdcDst
, himl
, bits
, iAlphaImage
, ILD_IMAGE
, 0x00D3E5F7, __LINE__
);
1469 todo_wine
check_ImageList_DrawIndirect_fStyle(hdcDst
, himl
, bits
, iAlphaImage
, ILD_PRESERVEALPHA
, 0x005D6F81, __LINE__
);
1471 check_ImageList_DrawIndirect_fStyle(hdcDst
, himl
, bits
, iTransparentImage
, ILD_NORMAL
, 0x00FFFFFF, __LINE__
);
1473 check_ImageList_DrawIndirect_ILD_ROP(hdcDst
, himl
, bits
, iImage
, SRCCOPY
, 0x00ABCDEF, __LINE__
);
1474 check_ImageList_DrawIndirect_ILD_ROP(hdcDst
, himl
, bits
, iImage
, SRCINVERT
, 0x00543210, __LINE__
);
1476 /* ILD_ROP is ignored when the image has an alpha channel */
1477 check_ImageList_DrawIndirect_ILD_ROP(hdcDst
, himl
, bits
, iAlphaImage
, SRCCOPY
, 0x00D3E5F7, __LINE__
);
1478 check_ImageList_DrawIndirect_ILD_ROP(hdcDst
, himl
, bits
, iAlphaImage
, SRCINVERT
, 0x00D3E5F7, __LINE__
);
1480 todo_wine
check_ImageList_DrawIndirect_fState(hdcDst
, himl
, bits
, iImage
, ILD_NORMAL
, ILS_SATURATE
, 0, 0x00CCCCCC, __LINE__
);
1481 todo_wine
check_ImageList_DrawIndirect_broken(hdcDst
, himl
, bits
, iAlphaImage
, ILD_NORMAL
, ILS_SATURATE
, 0, 0x00AFAFAF, 0x00F0F0F0, __LINE__
);
1483 check_ImageList_DrawIndirect_fState(hdcDst
, himl
, bits
, iImage
, ILD_NORMAL
, ILS_GLOW
, 0, 0x00ABCDEF, __LINE__
);
1484 check_ImageList_DrawIndirect_fState(hdcDst
, himl
, bits
, iImage
, ILD_NORMAL
, ILS_SHADOW
, 0, 0x00ABCDEF, __LINE__
);
1486 check_ImageList_DrawIndirect_fState(hdcDst
, himl
, bits
, iImage
, ILD_NORMAL
, ILS_ALPHA
, 127, 0x00D5E6F7, __LINE__
);
1487 check_ImageList_DrawIndirect_broken(hdcDst
, himl
, bits
, iAlphaImage
, ILD_NORMAL
, ILS_ALPHA
, 127, 0x00E9F2FB, 0x00AEB7C0, __LINE__
);
1488 todo_wine
check_ImageList_DrawIndirect_broken(hdcDst
, himl
, bits
, iAlphaImage
, ILD_NORMAL
, ILS_NORMAL
, 127, 0x00E9F2FB, 0x00D3E5F7, __LINE__
);
1493 SelectObject(hdcDst
, hbmOld
);
1495 DeleteObject(hbmDst
);
1501 DeleteObject(hbmMask
);
1503 DeleteObject(hbmInverseMask
);
1506 DeleteObject(hbmImage
);
1508 DeleteObject(hbmAlphaImage
);
1509 if(hbmTransparentImage
)
1510 DeleteObject(hbmTransparentImage
);
1514 ret
= ImageList_Destroy(himl
);
1515 ok(ret
, "ImageList_Destroy failed\n");
1519 static void test_iimagelist(void)
1521 IImageList
*imgl
, *imgl2
;
1522 IImageList2
*imagelist
;
1527 if (!pHIMAGELIST_QueryInterface
)
1529 win_skip("XP imagelist functions not available\n");
1533 /* test reference counting on destruction */
1534 imgl
= (IImageList
*)createImageList(32, 32);
1535 ret
= IImageList_AddRef(imgl
);
1536 ok(ret
== 2, "Expected 2, got %d\n", ret
);
1537 ret
= ImageList_Destroy((HIMAGELIST
)imgl
);
1538 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1539 ret
= ImageList_Destroy((HIMAGELIST
)imgl
);
1540 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1541 ret
= ImageList_Destroy((HIMAGELIST
)imgl
);
1542 ok(ret
== FALSE
, "Expected FALSE, got %d\n", ret
);
1544 imgl
= (IImageList
*)createImageList(32, 32);
1545 ret
= IImageList_AddRef(imgl
);
1546 ok(ret
== 2, "Expected 2, got %d\n", ret
);
1547 ret
= ImageList_Destroy((HIMAGELIST
)imgl
);
1548 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1549 ret
= IImageList_Release(imgl
);
1550 ok(ret
== 0, "Expected 0, got %d\n", ret
);
1551 ret
= ImageList_Destroy((HIMAGELIST
)imgl
);
1552 ok(ret
== FALSE
, "Expected FALSE, got %d\n", ret
);
1554 /* ref counting, HIMAGELIST_QueryInterface adds a reference */
1555 imgl
= (IImageList
*)createImageList(32, 32);
1556 hr
= pHIMAGELIST_QueryInterface((HIMAGELIST
)imgl
, &IID_IImageList
, (void**)&imgl2
);
1557 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1558 ok(imgl2
== imgl
, "got different pointer\n");
1559 ret
= IImageList_Release(imgl
);
1560 ok(ret
== 1, "got %u\n", ret
);
1561 IImageList_Release(imgl
);
1563 if (!pImageList_CoCreateInstance
)
1565 win_skip("Vista imagelist functions not available\n");
1569 hr
= pImageList_CoCreateInstance(&CLSID_ImageList
, NULL
, &IID_IImageList
, (void **) &imgl
);
1570 ok(SUCCEEDED(hr
), "ImageList_CoCreateInstance failed, hr=%x\n", hr
);
1573 IImageList_Release(imgl
);
1575 himl
= createImageList(32, 32);
1580 hr
= (pHIMAGELIST_QueryInterface
)(himl
, &IID_IImageList
, (void **) &imgl
);
1581 ok(SUCCEEDED(hr
), "HIMAGELIST_QueryInterface failed, hr=%x\n", hr
);
1584 IImageList_Release(imgl
);
1586 ImageList_Destroy(himl
);
1589 hr
= pImageList_CoCreateInstance(&CLSID_ImageList
, NULL
, &IID_IImageList2
, (void**)&imagelist
);
1592 win_skip("IImageList2 is not supported.\n");
1595 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1596 IImageList2_Release(imagelist
);
1599 static void test_hotspot_v6(void)
1610 #define HOTSPOTS_MAX 4 /* Number of entries in hotspots */
1611 static const struct hotspot hotspots
[HOTSPOTS_MAX
] = {
1618 HIMAGELIST himl1
= createImageList(SIZEX1
, SIZEY1
);
1619 HIMAGELIST himl2
= createImageList(SIZEX2
, SIZEY2
);
1620 IImageList
*imgl1
, *imgl2
;
1623 /* cast to IImageList */
1624 imgl1
= (IImageList
*) himl1
;
1625 imgl2
= (IImageList
*) himl2
;
1627 for (i
= 0; i
< HOTSPOTS_MAX
; i
++) {
1628 for (j
= 0; j
< HOTSPOTS_MAX
; j
++) {
1629 int dx1
= hotspots
[i
].dx
;
1630 int dy1
= hotspots
[i
].dy
;
1631 int dx2
= hotspots
[j
].dx
;
1632 int dy2
= hotspots
[j
].dy
;
1633 int correctx
, correcty
, newx
, newy
;
1635 IImageList
*imglNew
;
1638 hr
= IImageList_BeginDrag(imgl1
, 0, dx1
, dy1
);
1639 ok(SUCCEEDED(hr
), "BeginDrag failed for { %d, %d }\n", dx1
, dy1
);
1640 sprintf(loc
, "BeginDrag (%d,%d)\n", i
, j
);
1642 /* check merging the dragged image with a second image */
1643 hr
= IImageList_SetDragCursorImage(imgl2
, (IUnknown
*) imgl2
, 0, dx2
, dy2
);
1644 ok(SUCCEEDED(hr
), "SetDragCursorImage failed for {%d, %d}{%d, %d}\n",
1645 dx1
, dy1
, dx2
, dy2
);
1646 sprintf(loc
, "SetDragCursorImage (%d,%d)\n", i
, j
);
1648 /* check new hotspot, it should be the same like the old one */
1649 hr
= IImageList_GetDragImage(imgl2
, NULL
, &ppt
, &IID_IImageList
, (PVOID
*) &imglNew
);
1650 ok(SUCCEEDED(hr
), "GetDragImage failed\n");
1651 ok(ppt
.x
== dx1
&& ppt
.y
== dy1
,
1652 "Expected drag hotspot [%d,%d] got [%d,%d]\n",
1653 dx1
, dy1
, ppt
.x
, ppt
.y
);
1654 /* check size of new dragged image */
1655 IImageList_GetIconSize(imglNew
, &newx
, &newy
);
1656 correctx
= max(SIZEX1
, max(SIZEX2
+ dx2
, SIZEX1
- dx2
));
1657 correcty
= max(SIZEY1
, max(SIZEY2
+ dy2
, SIZEY1
- dy2
));
1658 ok(newx
== correctx
&& newy
== correcty
,
1659 "Expected drag image size [%d,%d] got [%d,%d]\n",
1660 correctx
, correcty
, newx
, newy
);
1661 sprintf(loc
, "GetDragImage (%d,%d)\n", i
, j
);
1662 IImageList_EndDrag(imgl2
);
1670 IImageList_Release(imgl2
);
1671 IImageList_Release(imgl1
);
1674 static void test_IImageList_Add_Remove(void)
1686 /* create an imagelist to play with */
1687 himl
= ImageList_Create(84, 84, ILC_COLOR16
, 0, 3);
1688 ok(himl
!= 0,"failed to create imagelist\n");
1690 imgl
= (IImageList
*) himl
;
1692 /* load the icons to add to the image list */
1693 hicon1
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
1694 ok(hicon1
!= 0, "no hicon1\n");
1695 hicon2
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
1696 ok(hicon2
!= 0, "no hicon2\n");
1697 hicon3
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
1698 ok(hicon3
!= 0, "no hicon3\n");
1700 /* remove when nothing exists */
1701 hr
= IImageList_Remove(imgl
, 0);
1702 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
1704 /* removing everything from an empty imagelist should succeed */
1705 hr
= IImageList_Remove(imgl
, -1);
1706 ok(hr
== S_OK
, "removed nonexistent icon\n");
1710 ok( IImageList_ReplaceIcon(imgl
, -1, hicon1
, &ret
) == S_OK
&& (ret
== 0),"failed to add icon1\n");
1712 ok( IImageList_ReplaceIcon(imgl
, -1, hicon2
, &ret
) == S_OK
&& (ret
== 1),"failed to add icon2\n");
1714 ok( IImageList_ReplaceIcon(imgl
, -1, hicon3
, &ret
) == S_OK
&& (ret
== 2),"failed to add icon3\n");
1716 /* remove an index out of range */
1717 ok( IImageList_Remove(imgl
, 4711) == E_INVALIDARG
, "got 0x%08x\n", hr
);
1720 ok( IImageList_Remove(imgl
,0) == S_OK
, "can't remove 0\n");
1721 ok( IImageList_Remove(imgl
,0) == S_OK
, "can't remove 0\n");
1722 ok( IImageList_Remove(imgl
,0) == S_OK
, "can't remove 0\n");
1724 /* remove one extra */
1725 ok( IImageList_Remove(imgl
, 0) == E_INVALIDARG
, "got 0x%08x\n", hr
);
1727 IImageList_Release(imgl
);
1728 ok(DestroyIcon(hicon1
),"icon 1 wasn't deleted\n");
1729 ok(DestroyIcon(hicon2
),"icon 2 wasn't deleted\n");
1730 ok(DestroyIcon(hicon3
),"icon 3 wasn't deleted\n");
1733 static void test_IImageList_Get_SetImageCount(void)
1740 /* create an imagelist to play with */
1741 himl
= ImageList_Create(84, 84, ILC_COLOR16
, 0, 3);
1742 ok(himl
!= 0,"failed to create imagelist\n");
1744 imgl
= (IImageList
*) himl
;
1746 /* check SetImageCount/GetImageCount */
1747 hr
= IImageList_SetImageCount(imgl
, 3);
1748 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1750 hr
= IImageList_GetImageCount(imgl
, &ret
);
1751 ok(hr
== S_OK
&& ret
== 3, "invalid image count after increase\n");
1752 hr
= IImageList_SetImageCount(imgl
, 1);
1753 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1755 hr
= IImageList_GetImageCount(imgl
, &ret
);
1756 ok(hr
== S_OK
&& ret
== 1, "invalid image count after decrease to 1\n");
1757 hr
= IImageList_SetImageCount(imgl
, 0);
1758 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1760 hr
= IImageList_GetImageCount(imgl
, &ret
);
1761 ok(hr
== S_OK
&& ret
== 0, "invalid image count after decrease to 0\n");
1763 IImageList_Release(imgl
);
1766 static void test_IImageList_Draw(void)
1775 IMAGELISTDRAWPARAMS imldp
;
1781 hwndfortest
= create_a_window();
1782 hdc
= GetDC(hwndfortest
);
1783 ok(hdc
!=NULL
, "couldn't get DC\n");
1785 /* create an imagelist to play with */
1786 himl
= ImageList_Create(48, 48, ILC_COLOR16
, 0, 3);
1787 ok(himl
!=0,"failed to create imagelist\n");
1789 imgl
= (IImageList
*) himl
;
1791 /* load the icons to add to the image list */
1792 hbm1
= CreateBitmap(48, 48, 1, 1, bitmap_bits
);
1793 ok(hbm1
!= 0, "no bitmap 1\n");
1794 hbm2
= CreateBitmap(48, 48, 1, 1, bitmap_bits
);
1795 ok(hbm2
!= 0, "no bitmap 2\n");
1796 hbm3
= CreateBitmap(48, 48, 1, 1, bitmap_bits
);
1797 ok(hbm3
!= 0, "no bitmap 3\n");
1801 ok( IImageList_Add(imgl
, hbm1
, 0, &ret
) == S_OK
&& (ret
== 0), "failed to add bitmap 1\n");
1803 ok( IImageList_Add(imgl
, hbm2
, 0, &ret
) == S_OK
&& (ret
== 1), "failed to add bitmap 2\n");
1805 ok( IImageList_SetImageCount(imgl
, 3) == S_OK
, "Setimage count failed\n");
1806 ok( IImageList_Replace(imgl
, 2, hbm3
, 0) == S_OK
, "failed to replace bitmap 3\n");
1810 /* crashes on native */
1811 IImageList_Draw(imgl
, NULL
);
1814 memset(&imldp
, 0, sizeof (imldp
));
1815 hr
= IImageList_Draw(imgl
, &imldp
);
1816 ok( hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
1818 imldp
.cbSize
= IMAGELISTDRAWPARAMS_V3_SIZE
;
1822 force_redraw(hwndfortest
);
1824 imldp
.fStyle
= SRCCOPY
;
1825 imldp
.rgbBk
= CLR_DEFAULT
;
1826 imldp
.rgbFg
= CLR_DEFAULT
;
1829 ok( IImageList_Draw(imgl
, &imldp
) == S_OK
, "should succeed\n");
1831 ok( IImageList_Draw(imgl
, &imldp
) == S_OK
, "should succeed\n");
1833 ok( IImageList_Draw(imgl
, &imldp
) == S_OK
, "should succeed\n");
1835 ok( IImageList_Draw(imgl
, &imldp
) == E_INVALIDARG
, "should fail\n");
1838 ok( IImageList_Remove(imgl
, 0) == S_OK
, "removing 1st bitmap\n");
1839 ok( IImageList_Remove(imgl
, 0) == S_OK
, "removing 2nd bitmap\n");
1840 ok( IImageList_Remove(imgl
, 0) == S_OK
, "removing 3rd bitmap\n");
1843 IImageList_Release(imgl
);
1845 /* bitmaps should not be deleted by the imagelist */
1846 ok(DeleteObject(hbm1
),"bitmap 1 can't be deleted\n");
1847 ok(DeleteObject(hbm2
),"bitmap 2 can't be deleted\n");
1848 ok(DeleteObject(hbm3
),"bitmap 3 can't be deleted\n");
1850 ReleaseDC(hwndfortest
, hdc
);
1851 DestroyWindow(hwndfortest
);
1854 static void test_IImageList_Merge(void)
1856 HIMAGELIST himl1
, himl2
;
1857 IImageList
*imgl1
, *imgl2
, *merge
;
1859 HWND hwnd
= create_a_window();
1863 himl1
= ImageList_Create(32,32,0,0,3);
1864 ok(himl1
!= NULL
,"failed to create himl1\n");
1866 himl2
= ImageList_Create(32,32,0,0,3);
1867 ok(himl2
!= NULL
,"failed to create himl2\n");
1869 hicon1
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
1870 ok(hicon1
!= NULL
, "failed to create hicon1\n");
1872 if (!himl1
|| !himl2
|| !hicon1
)
1875 /* cast to IImageList */
1876 imgl1
= (IImageList
*) himl1
;
1877 imgl2
= (IImageList
*) himl2
;
1880 ok( IImageList_ReplaceIcon(imgl2
, -1, hicon1
, &ret
) == S_OK
&& (ret
== 0),"add icon1 to himl2 failed\n");
1884 /* null cases that crash on native */
1885 IImageList_Merge(imgl1
, -1, NULL
, 0, 0, 0, &IID_IImageList
, (void**)&merge
);
1886 IImageList_Merge(imgl1
, -1, (IUnknown
*) imgl2
, 0, 0, 0, &IID_IImageList
, NULL
);
1889 /* If himl1 has no images, merge still succeeds */
1890 hr
= IImageList_Merge(imgl1
, -1, (IUnknown
*) imgl2
, 0, 0, 0, &IID_IImageList
, (void **) &merge
);
1891 ok(hr
== S_OK
, "merge himl1,-1 failed\n");
1892 if (hr
== S_OK
) IImageList_Release(merge
);
1894 hr
= IImageList_Merge(imgl1
, 0, (IUnknown
*) imgl2
, 0, 0, 0, &IID_IImageList
, (void **) &merge
);
1895 ok(hr
== S_OK
, "merge himl1,0 failed\n");
1896 if (hr
== S_OK
) IImageList_Release(merge
);
1898 /* Same happens if himl2 is empty */
1899 IImageList_Release(imgl2
);
1900 himl2
= ImageList_Create(32,32,0,0,3);
1901 ok(himl2
!= NULL
,"failed to recreate himl2\n");
1903 imgl2
= (IImageList
*) himl2
;
1905 hr
= IImageList_Merge(imgl1
, -1, (IUnknown
*) imgl2
, -1, 0, 0, &IID_IImageList
, (void **) &merge
);
1906 ok(hr
== S_OK
, "merge himl2,-1 failed\n");
1907 if (hr
== S_OK
) IImageList_Release(merge
);
1909 hr
= IImageList_Merge(imgl1
, -1, (IUnknown
*) imgl2
, 0, 0, 0, &IID_IImageList
, (void **) &merge
);
1910 ok(hr
== S_OK
, "merge himl2,0 failed\n");
1911 if (hr
== S_OK
) IImageList_Release(merge
);
1913 /* Now try merging an image with itself */
1915 ok( IImageList_ReplaceIcon(imgl2
, -1, hicon1
, &ret
) == S_OK
&& (ret
== 0),"re-add icon1 to himl2 failed\n");
1917 hr
= IImageList_Merge(imgl2
, 0, (IUnknown
*) imgl2
, 0, 0, 0, &IID_IImageList
, (void **) &merge
);
1918 ok(hr
== S_OK
, "merge himl2 with itself failed\n");
1919 if (hr
== S_OK
) IImageList_Release(merge
);
1921 /* Try merging 2 different image lists */
1923 ok( IImageList_ReplaceIcon(imgl1
, -1, hicon1
, &ret
) == S_OK
&& (ret
== 0),"add icon1 to himl1 failed\n");
1925 hr
= IImageList_Merge(imgl1
, 0, (IUnknown
*) imgl2
, 0, 0, 0, &IID_IImageList
, (void **) &merge
);
1926 ok(hr
== S_OK
, "merge himl1 with himl2 failed\n");
1927 if (hr
== S_OK
) IImageList_Release(merge
);
1929 hr
= IImageList_Merge(imgl1
, 0, (IUnknown
*) imgl2
, 0, 8, 16, &IID_IImageList
, (void **) &merge
);
1930 ok(hr
== S_OK
, "merge himl1 with himl2 8,16 failed\n");
1931 if (hr
== S_OK
) IImageList_Release(merge
);
1933 IImageList_Release(imgl1
);
1934 IImageList_Release(imgl2
);
1936 DestroyIcon(hicon1
);
1937 DestroyWindow(hwnd
);
1940 static void test_iconsize(void)
1946 himl
= ImageList_Create(16, 16, ILC_COLOR16
, 0, 3);
1947 /* null pointers, not zero imagelist dimensions */
1948 ret
= ImageList_GetIconSize(himl
, NULL
, NULL
);
1949 ok(!ret
, "got %d\n", ret
);
1951 /* doesn't touch return pointers */
1953 ret
= ImageList_GetIconSize(himl
, &cx
, NULL
);
1954 ok(!ret
, "got %d\n", ret
);
1955 ok(cx
== 0x1abe11ed, "got %d\n", cx
);
1958 ret
= ImageList_GetIconSize(himl
, NULL
, &cy
);
1959 ok(!ret
, "got %d\n", ret
);
1960 ok(cy
== 0x1abe11ed, "got %d\n", cy
);
1962 ImageList_Destroy(himl
);
1964 ret
= ImageList_GetIconSize((HIMAGELIST
)0xdeadbeef, &cx
, &cy
);
1965 ok(!ret
, "got %d\n", ret
);
1968 static void test_create_destroy(void)
1977 /* list with zero or negative image dimensions */
1978 himl
= ImageList_Create(0, 0, ILC_COLOR16
, 0, 3);
1979 ok(himl
== NULL
, "got %p\n", himl
);
1981 himl
= ImageList_Create(0, 16, ILC_COLOR16
, 0, 3);
1982 ok(himl
== NULL
, "got %p\n", himl
);
1984 himl
= ImageList_Create(16, 0, ILC_COLOR16
, 0, 3);
1985 ok(himl
== NULL
, "got %p\n", himl
);
1987 himl
= ImageList_Create(16, -1, ILC_COLOR16
, 0, 3);
1988 ok(himl
== NULL
, "got %p\n", himl
);
1990 himl
= ImageList_Create(-1, 16, ILC_COLOR16
, 0, 3);
1991 ok(himl
== NULL
, "got %p\n", himl
);
1993 rc
= ImageList_Destroy((HIMAGELIST
)0xdeadbeef);
1994 ok(rc
== FALSE
, "ImageList_Destroy(0xdeadbeef) should fail and not crash\n");
1996 /* DDB image lists */
1997 himl
= ImageList_Create(0, 14, ILC_COLORDDB
, 4, 4);
1998 ok(himl
!= NULL
, "got %p\n", himl
);
1999 imgl
= (IImageList
*)himl
;
2000 IImageList_GetIconSize(imgl
, &cx
, &cy
);
2001 ok (cx
== 0, "Wrong cx (%i)\n", cx
);
2002 ok (cy
== 14, "Wrong cy (%i)\n", cy
);
2003 ImageList_Destroy(himl
);
2005 himl
= ImageList_Create(0, 0, ILC_COLORDDB
, 4, 4);
2006 ok(himl
!= NULL
, "got %p\n", himl
);
2007 imgl
= (IImageList
*)himl
;
2008 IImageList_GetIconSize(imgl
, &cx
, &cy
);
2009 ok (cx
== 0, "Wrong cx (%i)\n", cx
);
2010 ok (cy
== 0, "Wrong cy (%i)\n", cy
);
2011 ImageList_Destroy(himl
);
2013 himl
= ImageList_Create(0, 0, ILC_COLORDDB
, 0, 4);
2014 ok(himl
!= NULL
, "got %p\n", himl
);
2015 imgl
= (IImageList
*)himl
;
2016 IImageList_GetIconSize(imgl
, &cx
, &cy
);
2017 ok (cx
== 0, "Wrong cx (%i)\n", cx
);
2018 ok (cy
== 0, "Wrong cy (%i)\n", cy
);
2020 hr
= IImageList_SetImageCount(imgl
, 3);
2021 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2022 hr
= IImageList_GetImageCount(imgl
, &ret
);
2023 ok(hr
== S_OK
&& ret
== 3, "invalid image count after increase\n");
2025 /* Trying to actually add an image causes a crash on Windows */
2026 ImageList_Destroy(himl
);
2028 /* Negative values fail */
2029 himl
= ImageList_Create(-1, -1, ILC_COLORDDB
, 4, 4);
2030 ok(himl
== NULL
, "got %p\n", himl
);
2031 himl
= ImageList_Create(-1, 1, ILC_COLORDDB
, 4, 4);
2032 ok(himl
== NULL
, "got %p\n", himl
);
2033 himl
= ImageList_Create(1, -1, ILC_COLORDDB
, 4, 4);
2034 ok(himl
== NULL
, "got %p\n", himl
);
2037 static void test_IImageList_Clone(void)
2039 IImageList
*imgl
, *imgl2
;
2044 himl
= ImageList_Create(16, 16, ILC_COLOR16
, 0, 3);
2045 imgl
= (IImageList
*)himl
;
2049 /* crashes on native */
2050 IImageList_Clone(imgl
, &IID_IImageList
, NULL
);
2053 hr
= IImageList_Clone(imgl
, &IID_IImageList
, (void**)&imgl2
);
2054 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2055 ref
= IImageList_Release(imgl2
);
2056 ok(ref
== 0, "got %u\n", ref
);
2058 IImageList_Release(imgl
);
2061 static void test_IImageList_GetBkColor(void)
2068 himl
= ImageList_Create(16, 16, ILC_COLOR16
, 0, 3);
2069 imgl
= (IImageList
*)himl
;
2073 /* crashes on native */
2074 IImageList_GetBkColor(imgl
, NULL
);
2077 hr
= IImageList_GetBkColor(imgl
, &color
);
2078 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2080 IImageList_Release(imgl
);
2083 static void test_IImageList_SetBkColor(void)
2090 himl
= ImageList_Create(16, 16, ILC_COLOR16
, 0, 3);
2091 imgl
= (IImageList
*)himl
;
2095 /* crashes on native */
2096 IImageList_SetBkColor(imgl
, RGB(0, 0, 0), NULL
);
2099 hr
= IImageList_SetBkColor(imgl
, CLR_NONE
, &color
);
2100 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2102 hr
= IImageList_SetBkColor(imgl
, CLR_NONE
, &color
);
2103 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2106 hr
= IImageList_GetBkColor(imgl
, &color
);
2107 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2108 ok(color
== CLR_NONE
, "got %x\n", color
);
2110 IImageList_Release(imgl
);
2113 static void test_IImageList_GetImageCount(void)
2120 himl
= ImageList_Create(16, 16, ILC_COLOR16
, 0, 3);
2121 imgl
= (IImageList
*)himl
;
2125 /* crashes on native */
2126 IImageList_GetImageCount(imgl
, NULL
);
2130 hr
= IImageList_GetImageCount(imgl
, &count
);
2131 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2132 ok(count
== 0, "got %d\n", count
);
2134 IImageList_Release(imgl
);
2137 static void test_IImageList_GetIconSize(void)
2144 himl
= ImageList_Create(16, 16, ILC_COLOR16
, 0, 3);
2145 imgl
= (IImageList
*)himl
;
2147 hr
= IImageList_GetIconSize(imgl
, NULL
, NULL
);
2148 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
2150 hr
= IImageList_GetIconSize(imgl
, &cx
, NULL
);
2151 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
2153 hr
= IImageList_GetIconSize(imgl
, NULL
, &cy
);
2154 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
2156 IImageList_Release(imgl
);
2159 START_TEST(imagelist
)
2161 ULONG_PTR ctx_cookie
;
2164 HMODULE hComCtl32
= GetModuleHandleA("comctl32.dll");
2165 pImageList_Create
= NULL
; /* These are not needed for non-v6.0 tests*/
2166 pImageList_Add
= NULL
;
2167 pImageList_DrawIndirect
= (void*)GetProcAddress(hComCtl32
, "ImageList_DrawIndirect");
2168 pImageList_SetImageCount
= (void*)GetProcAddress(hComCtl32
, "ImageList_SetImageCount");
2170 hinst
= GetModuleHandleA(NULL
);
2172 InitCommonControls();
2174 test_create_destroy();
2179 test_DrawIndirect();
2181 test_merge_colors();
2182 test_imagelist_storage();
2185 FreeLibrary(hComCtl32
);
2187 /* Now perform v6 tests */
2189 if (!load_v6_module(&ctx_cookie
, &hCtx
))
2192 /* Reload comctl32 */
2193 hComCtl32
= LoadLibraryA("comctl32.dll");
2194 pImageList_Create
= (void*)GetProcAddress(hComCtl32
, "ImageList_Create");
2195 pImageList_Add
= (void*)GetProcAddress(hComCtl32
, "ImageList_Add");
2196 pImageList_DrawIndirect
= (void*)GetProcAddress(hComCtl32
, "ImageList_DrawIndirect");
2197 pImageList_SetImageCount
= (void*)GetProcAddress(hComCtl32
, "ImageList_SetImageCount");
2198 pImageList_CoCreateInstance
= (void*)GetProcAddress(hComCtl32
, "ImageList_CoCreateInstance");
2199 pHIMAGELIST_QueryInterface
= (void*)GetProcAddress(hComCtl32
, "HIMAGELIST_QueryInterface");
2201 CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
2204 test_ImageList_DrawIndirect();
2205 test_shell_imagelist();
2209 test_IImageList_Add_Remove();
2210 test_IImageList_Get_SetImageCount();
2211 test_IImageList_Draw();
2212 test_IImageList_Merge();
2213 test_IImageList_Clone();
2214 test_IImageList_GetBkColor();
2215 test_IImageList_SetBkColor();
2216 test_IImageList_GetImageCount();
2217 test_IImageList_GetIconSize();
2221 unload_v6_module(ctx_cookie
, hCtx
);