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
38 #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 **);
73 static int (WINAPI
*pImageList_SetColorTable
)(HIMAGELIST
,int,int,RGBQUAD
*);
75 static HINSTANCE hinst
;
77 /* only used in interactive mode */
78 static void force_redraw(HWND hwnd
)
80 if (!winetest_interactive
)
83 RedrawWindow(hwnd
, NULL
, 0, RDW_UPDATENOW
);
87 /* These macros build cursor/bitmap data in 4x4 pixel blocks */
88 #define B(x,y) ((x?0xf0:0)|(y?0xf:0))
89 #define ROW1(a,b,c,d,e,f,g,h) B(a,b),B(c,d),B(e,f),B(g,h)
90 #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), \
91 ROW1(a,b,c,d,e,f,g,h), ROW1(a,b,c,d,e,f,g,h)
92 #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)
93 #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), \
94 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), \
95 ROW2(a,b,c,d,e,f,g,h,i,j,k,l)
97 static const BYTE empty_bits
[48*48/8];
99 static const BYTE icon_bits
[32*32/8] =
101 ROW32(0,0,0,0,0,0,0,0),
102 ROW32(0,0,1,1,1,1,0,0),
103 ROW32(0,1,1,1,1,1,1,0),
104 ROW32(0,1,1,0,0,1,1,0),
105 ROW32(0,1,1,0,0,1,1,0),
106 ROW32(0,1,1,1,1,1,1,0),
107 ROW32(0,0,1,1,1,1,0,0),
108 ROW32(0,0,0,0,0,0,0,0)
111 static const BYTE bitmap_bits
[48*48/8] =
113 ROW48(0,0,0,0,0,0,0,0,0,0,0,0),
114 ROW48(0,1,1,1,1,1,1,1,1,1,1,0),
115 ROW48(0,1,1,0,0,0,0,0,0,1,1,0),
116 ROW48(0,1,0,0,0,0,0,0,1,0,1,0),
117 ROW48(0,1,0,0,0,0,0,1,0,0,1,0),
118 ROW48(0,1,0,0,0,0,1,0,0,0,1,0),
119 ROW48(0,1,0,0,0,1,0,0,0,0,1,0),
120 ROW48(0,1,0,0,1,0,0,0,0,0,1,0),
121 ROW48(0,1,0,1,0,0,0,0,0,0,1,0),
122 ROW48(0,1,1,0,0,0,0,0,0,1,1,0),
123 ROW48(0,1,1,1,1,1,1,1,1,1,1,0),
124 ROW48(0,0,0,0,0,0,0,0,0,0,0,0)
127 static HIMAGELIST
createImageList(int cx
, int cy
)
129 /* Create an ImageList and put an image into it */
130 HIMAGELIST himl
= ImageList_Create(cx
, cy
, ILC_COLOR
, 1, 1);
131 HBITMAP hbm
= CreateBitmap(48, 48, 1, 1, bitmap_bits
);
132 ImageList_Add(himl
, hbm
, NULL
);
137 static HWND
create_a_window(void)
139 char className
[] = "bmwnd";
140 char winName
[] = "Test Bitmap";
142 static BOOL registered
= FALSE
;
148 cls
.style
= CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
;
149 cls
.lpfnWndProc
= DefWindowProcA
;
153 cls
.hIcon
= LoadIconA(0, (LPCSTR
)IDI_APPLICATION
);
154 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
155 cls
.hbrBackground
= GetStockObject (WHITE_BRUSH
);
156 cls
.lpszMenuName
= 0;
157 cls
.lpszClassName
= className
;
159 RegisterClassA (&cls
);
164 hWnd
= CreateWindowA (className
, winName
,
165 WS_OVERLAPPEDWINDOW
,
166 CW_USEDEFAULT
, CW_USEDEFAULT
, 300, 300, 0,
169 if (winetest_interactive
)
171 ShowWindow (hWnd
, SW_SHOW
);
178 static HDC
show_image(HWND hwnd
, HIMAGELIST himl
, int idx
, int size
,
179 LPCSTR loc
, BOOL clear
)
183 if (!winetest_interactive
|| !himl
) return NULL
;
185 SetWindowTextA(hwnd
, loc
);
187 ImageList_Draw(himl
, idx
, hdc
, 0, 0, ILD_TRANSPARENT
);
193 BitBlt(hdc
, 0, 0, size
, size
, hdc
, size
+1, size
+1, SRCCOPY
);
194 ReleaseDC(hwnd
, hdc
);
201 /* Useful for checking differences */
202 static void dump_bits(const BYTE
*p
, const BYTE
*q
, int size
)
208 for (i
= 0; i
< size
* 2; i
++)
211 for (j
= 0; j
< size
; j
++)
212 printf("%c%c", p
[j
] & 0xf0 ? 'X' : ' ', p
[j
] & 0xf ? 'X' : ' ');
214 for (j
= 0; j
< size
; j
++)
215 printf("%c%c", q
[j
] & 0xf0 ? 'X' : ' ', q
[j
] & 0xf ? 'X' : ' ');
223 static void check_bits(HWND hwnd
, HIMAGELIST himl
, int idx
, int size
,
224 const BYTE
*checkbits
, LPCSTR loc
)
226 BYTE bits
[100*100/8];
231 if (!winetest_interactive
|| !himl
) return;
233 memset(bits
, 0, sizeof(bits
));
234 hdc
= show_image(hwnd
, himl
, idx
, size
, loc
, FALSE
);
236 c
= GetPixel(hdc
, 0, 0);
238 for (y
= 0; y
< size
; y
++)
240 for (x
= 0; x
< size
; x
++)
243 if (GetPixel(hdc
, x
, y
) != c
) bits
[i
] |= (0x80 >> (x
& 0x7));
247 BitBlt(hdc
, 0, 0, size
, size
, hdc
, size
+1, size
+1, SRCCOPY
);
248 ReleaseDC(hwnd
, hdc
);
250 ok (memcmp(bits
, checkbits
, (size
* size
)/8) == 0,
251 "%s: bits different\n", loc
);
252 if (memcmp(bits
, checkbits
, (size
* size
)/8))
253 dump_bits(bits
, checkbits
, size
);
256 static void test_begindrag(void)
258 HIMAGELIST himl
= createImageList(7,13);
264 count
= ImageList_GetImageCount(himl
);
265 ok(count
> 2, "Tests need an ImageList with more than 2 images\n");
267 /* Two BeginDrag() without EndDrag() in between */
268 ret
= ImageList_BeginDrag(himl
, 1, 0, 0);
269 drag
= ImageList_GetDragImage(NULL
, NULL
);
270 ok(ret
&& drag
, "ImageList_BeginDrag() failed\n");
271 ret
= ImageList_BeginDrag(himl
, 0, 3, 5);
272 ok(!ret
, "ImageList_BeginDrag() returned TRUE\n");
273 drag
= ImageList_GetDragImage(NULL
, &hotspot
);
274 ok(!!drag
, "No active ImageList drag left\n");
275 ok(hotspot
.x
== 0 && hotspot
.y
== 0, "New ImageList drag was created\n");
277 drag
= ImageList_GetDragImage(NULL
, NULL
);
278 ok(!drag
, "ImageList drag was not destroyed\n");
280 /* Invalid image index */
281 ImageList_BeginDrag(himl
, 0, 0, 0);
282 ret
= ImageList_BeginDrag(himl
, count
, 3, 5);
283 ok(!ret
, "ImageList_BeginDrag() returned TRUE\n");
284 drag
= ImageList_GetDragImage(NULL
, &hotspot
);
285 ok(drag
&& hotspot
.x
== 0 && hotspot
.y
== 0, "Active drag should not have been canceled\n");
287 drag
= ImageList_GetDragImage(NULL
, NULL
);
288 ok(!drag
, "ImageList drag was not destroyed\n");
289 /* Invalid negative image indexes succeed */
290 ret
= ImageList_BeginDrag(himl
, -17, 0, 0);
291 drag
= ImageList_GetDragImage(NULL
, NULL
);
292 ok(ret
&& drag
, "ImageList drag was created\n");
294 ret
= ImageList_BeginDrag(himl
, -1, 0, 0);
295 drag
= ImageList_GetDragImage(NULL
, NULL
);
296 ok(ret
&& drag
, "ImageList drag was created\n");
298 ImageList_Destroy(himl
);
301 static void test_hotspot(void)
312 #define HOTSPOTS_MAX 4 /* Number of entries in hotspots */
313 static const struct hotspot hotspots
[HOTSPOTS_MAX
] = {
320 HIMAGELIST himl1
= createImageList(SIZEX1
, SIZEY1
);
321 HIMAGELIST himl2
= createImageList(SIZEX2
, SIZEY2
);
322 HWND hwnd
= create_a_window();
325 for (i
= 0; i
< HOTSPOTS_MAX
; i
++) {
326 for (j
= 0; j
< HOTSPOTS_MAX
; j
++) {
327 int dx1
= hotspots
[i
].dx
;
328 int dy1
= hotspots
[i
].dy
;
329 int dx2
= hotspots
[j
].dx
;
330 int dy2
= hotspots
[j
].dy
;
331 int correctx
, correcty
, newx
, newy
;
336 ret
= ImageList_BeginDrag(himl1
, 0, dx1
, dy1
);
337 ok(ret
!= 0, "BeginDrag failed for { %d, %d }\n", dx1
, dy1
);
338 sprintf(loc
, "BeginDrag (%d,%d)\n", i
, j
);
339 show_image(hwnd
, himl1
, 0, max(SIZEX1
, SIZEY1
), loc
, TRUE
);
341 /* check merging the dragged image with a second image */
342 ret
= ImageList_SetDragCursorImage(himl2
, 0, dx2
, dy2
);
343 ok(ret
!= 0, "SetDragCursorImage failed for {%d, %d}{%d, %d}\n",
345 sprintf(loc
, "SetDragCursorImage (%d,%d)\n", i
, j
);
346 show_image(hwnd
, himl2
, 0, max(SIZEX2
, SIZEY2
), loc
, TRUE
);
348 /* check new hotspot, it should be the same like the old one */
349 himlNew
= ImageList_GetDragImage(NULL
, &ppt
);
350 ok(ppt
.x
== dx1
&& ppt
.y
== dy1
,
351 "Expected drag hotspot [%d,%d] got [%d,%d]\n",
352 dx1
, dy1
, ppt
.x
, ppt
.y
);
353 /* check size of new dragged image */
354 ImageList_GetIconSize(himlNew
, &newx
, &newy
);
355 correctx
= max(SIZEX1
, max(SIZEX2
+ dx2
, SIZEX1
- dx2
));
356 correcty
= max(SIZEY1
, max(SIZEY2
+ dy2
, SIZEY1
- dy2
));
357 ok(newx
== correctx
&& newy
== correcty
,
358 "Expected drag image size [%d,%d] got [%d,%d]\n",
359 correctx
, correcty
, newx
, newy
);
360 sprintf(loc
, "GetDragImage (%d,%d)\n", i
, j
);
361 show_image(hwnd
, himlNew
, 0, max(correctx
, correcty
), loc
, TRUE
);
370 ImageList_Destroy(himl2
);
371 ImageList_Destroy(himl1
);
375 static void test_add_remove(void)
383 /* create an imagelist to play with */
384 himl
= ImageList_Create(84, 84, ILC_COLOR16
, 0, 3);
385 ok(himl
!=0,"failed to create imagelist\n");
387 /* load the icons to add to the image list */
388 hicon1
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
389 ok(hicon1
!= 0, "no hicon1\n");
390 hicon2
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
391 ok(hicon2
!= 0, "no hicon2\n");
392 hicon3
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
393 ok(hicon3
!= 0, "no hicon3\n");
395 /* remove when nothing exists */
396 ok(!ImageList_Remove(himl
,0),"removed nonexistent icon\n");
397 /* removing everything from an empty imagelist should succeed */
398 ok(ImageList_RemoveAll(himl
),"removed nonexistent icon\n");
401 ok(0==ImageList_AddIcon(himl
, hicon1
),"failed to add icon1\n");
402 ok(1==ImageList_AddIcon(himl
, hicon2
),"failed to add icon2\n");
403 ok(2==ImageList_AddIcon(himl
, hicon3
),"failed to add icon3\n");
405 /* remove an index out of range */
406 ok(!ImageList_Remove(himl
,4711),"removed nonexistent icon\n");
409 ok(ImageList_Remove(himl
,0),"can't remove 0\n");
410 ok(ImageList_Remove(himl
,0),"can't remove 0\n");
411 ok(ImageList_Remove(himl
,0),"can't remove 0\n");
413 /* remove one extra */
414 ok(!ImageList_Remove(himl
,0),"removed nonexistent icon\n");
417 ok(ImageList_Destroy(himl
),"destroy imagelist failed\n");
419 ok(-1==ImageList_AddIcon((HIMAGELIST
)0xdeadbeef, hicon1
),"don't crash on bad handle\n");
421 ok(DestroyIcon(hicon1
),"icon 1 wasn't deleted\n");
422 ok(DestroyIcon(hicon2
),"icon 2 wasn't deleted\n");
423 ok(DestroyIcon(hicon3
),"icon 3 wasn't deleted\n");
426 static void test_imagecount(void)
430 ok(0==ImageList_GetImageCount((HIMAGELIST
)0xdeadbeef),"don't crash on bad handle\n");
432 if (!pImageList_SetImageCount
)
434 win_skip("ImageList_SetImageCount not available\n");
438 himl
= ImageList_Create(84, 84, ILC_COLOR16
, 0, 3);
439 ok(himl
!=0,"failed to create imagelist\n");
441 ok(pImageList_SetImageCount(himl
, 3), "couldn't increase image count\n");
442 ok(ImageList_GetImageCount(himl
) == 3, "invalid image count after increase\n");
443 ok(pImageList_SetImageCount(himl
, 1), "couldn't decrease image count\n");
444 ok(ImageList_GetImageCount(himl
) == 1, "invalid image count after decrease to 1\n");
445 ok(pImageList_SetImageCount(himl
, 0), "couldn't decrease image count\n");
446 ok(ImageList_GetImageCount(himl
) == 0, "invalid image count after decrease to 0\n");
448 ok(ImageList_Destroy(himl
), "destroy imagelist failed\n");
451 static void test_DrawIndirect(void)
459 IMAGELISTDRAWPARAMS imldp
;
463 if (!pImageList_DrawIndirect
)
465 win_skip("ImageList_DrawIndirect not available, skipping test\n");
469 hwndfortest
= create_a_window();
470 hdc
= GetDC(hwndfortest
);
471 ok(hdc
!=NULL
, "couldn't get DC\n");
473 /* create an imagelist to play with */
474 himl
= ImageList_Create(48, 48, ILC_COLOR16
, 0, 3);
475 ok(himl
!=0,"failed to create imagelist\n");
477 /* load the icons to add to the image list */
478 hbm1
= CreateBitmap(48, 48, 1, 1, bitmap_bits
);
479 ok(hbm1
!= 0, "no bitmap 1\n");
480 hbm2
= CreateBitmap(48, 48, 1, 1, bitmap_bits
);
481 ok(hbm2
!= 0, "no bitmap 2\n");
482 hbm3
= CreateBitmap(48, 48, 1, 1, bitmap_bits
);
483 ok(hbm3
!= 0, "no bitmap 3\n");
486 ok(0==ImageList_Add(himl
, hbm1
, 0),"failed to add bitmap 1\n");
487 ok(1==ImageList_Add(himl
, hbm2
, 0),"failed to add bitmap 2\n");
489 if (pImageList_SetImageCount
)
491 ok(pImageList_SetImageCount(himl
,3),"Setimage count failed\n");
492 /*ok(2==ImageList_Add(himl, hbm3, NULL),"failed to add bitmap 3\n"); */
493 ok(ImageList_Replace(himl
, 2, hbm3
, 0),"failed to replace bitmap 3\n");
496 memset(&imldp
, 0, sizeof (imldp
));
497 ok(!pImageList_DrawIndirect(&imldp
), "zero data succeeded!\n");
498 imldp
.cbSize
= IMAGELISTDRAWPARAMS_V3_SIZE
;
499 ok(!pImageList_DrawIndirect(&imldp
), "zero hdc succeeded!\n");
501 ok(!pImageList_DrawIndirect(&imldp
),"zero himl succeeded!\n");
502 imldp
.himl
= (HIMAGELIST
)0xdeadbeef;
503 ok(!pImageList_DrawIndirect(&imldp
),"bad himl succeeded!\n");
506 force_redraw(hwndfortest
);
508 imldp
.fStyle
= SRCCOPY
;
509 imldp
.rgbBk
= CLR_DEFAULT
;
510 imldp
.rgbFg
= CLR_DEFAULT
;
513 ok(pImageList_DrawIndirect(&imldp
),"should succeed\n");
515 ok(pImageList_DrawIndirect(&imldp
),"should succeed\n");
517 ok(pImageList_DrawIndirect(&imldp
),"should succeed\n");
519 ok(!pImageList_DrawIndirect(&imldp
),"should fail\n");
522 ok(ImageList_Remove(himl
, 0), "removing 1st bitmap\n");
523 ok(ImageList_Remove(himl
, 0), "removing 2nd bitmap\n");
524 ok(ImageList_Remove(himl
, 0), "removing 3rd bitmap\n");
527 ok(ImageList_Destroy(himl
),"destroy imagelist failed\n");
529 /* bitmaps should not be deleted by the imagelist */
530 ok(DeleteObject(hbm1
),"bitmap 1 can't be deleted\n");
531 ok(DeleteObject(hbm2
),"bitmap 2 can't be deleted\n");
532 ok(DeleteObject(hbm3
),"bitmap 3 can't be deleted\n");
534 ReleaseDC(hwndfortest
, hdc
);
535 DestroyWindow(hwndfortest
);
538 static int get_color_format(HBITMAP bmp
)
541 HDC hdc
= CreateCompatibleDC(0);
542 HBITMAP hOldBmp
= SelectObject(hdc
, bmp
);
545 memset(&bmi
, 0, sizeof(bmi
));
546 bmi
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
547 ret
= GetDIBits(hdc
, bmp
, 0, 0, 0, &bmi
, DIB_RGB_COLORS
);
548 ok(ret
, "GetDIBits failed\n");
550 SelectObject(hdc
, hOldBmp
);
552 return bmi
.bmiHeader
.biBitCount
;
555 static void test_merge_colors(void)
557 HIMAGELIST himl
[8], hmerge
;
558 int sizes
[] = { ILC_COLOR
, ILC_COLOR
| ILC_MASK
, ILC_COLOR4
, ILC_COLOR8
, ILC_COLOR16
, ILC_COLOR24
, ILC_COLOR32
, ILC_COLORDDB
};
563 hicon1
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
564 ok(hicon1
!= NULL
, "failed to create hicon1\n");
566 for (i
= 0; i
< 8; i
++)
568 himl
[i
] = ImageList_Create(32, 32, sizes
[i
], 0, 3);
569 ok(himl
[i
] != NULL
, "failed to create himl[%d]\n", i
);
570 ok(0 == ImageList_AddIcon(himl
[i
], hicon1
), "add icon1 to himl[%d] failed\n", i
);
571 if (i
== 0 || i
== 1 || i
== 7)
573 ImageList_GetImageInfo(himl
[i
], 0, &info
);
574 sizes
[i
] = get_color_format(info
.hbmImage
);
578 for (i
= 0; i
< 8; i
++)
579 for (j
= 0; j
< 8; j
++)
581 hmerge
= ImageList_Merge(himl
[i
], 0, himl
[j
], 0, 0, 0);
582 ok(hmerge
!= NULL
, "merge himl[%d], himl[%d] failed\n", i
, j
);
584 ImageList_GetImageInfo(hmerge
, 0, &info
);
585 bpp
= get_color_format(info
.hbmImage
);
586 /* ILC_COLOR[X] is defined as [X] */
587 if (i
== 4 && j
== 7)
588 ok(bpp
== 16, /* merging ILC_COLOR16 with ILC_COLORDDB seems to be a special case */
589 "wrong biBitCount %d when merging lists %d (%d) and %d (%d)\n", bpp
, i
, sizes
[i
], j
, sizes
[j
]);
591 ok(bpp
== (i
> j
? sizes
[i
] : sizes
[j
]),
592 "wrong biBitCount %d when merging lists %d (%d) and %d (%d)\n", bpp
, i
, sizes
[i
], j
, sizes
[j
]);
593 ok(info
.hbmMask
!= 0, "Imagelist merged from %d and %d had no mask\n", i
, j
);
595 if (hmerge
) ImageList_Destroy(hmerge
);
598 for (i
= 0; i
< 8; i
++)
599 ImageList_Destroy(himl
[i
]);
602 static void test_merge(void)
604 HIMAGELIST himl1
, himl2
, hmerge
;
606 HWND hwnd
= create_a_window();
608 himl1
= ImageList_Create(32,32,0,0,3);
609 ok(himl1
!= NULL
,"failed to create himl1\n");
611 himl2
= ImageList_Create(32,32,0,0,3);
612 ok(himl2
!= NULL
,"failed to create himl2\n");
614 hicon1
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
615 ok(hicon1
!= NULL
, "failed to create hicon1\n");
617 if (!himl1
|| !himl2
|| !hicon1
)
620 ok(0==ImageList_AddIcon(himl2
, hicon1
),"add icon1 to himl2 failed\n");
621 check_bits(hwnd
, himl2
, 0, 32, icon_bits
, "add icon1 to himl2");
623 /* If himl1 has no images, merge still succeeds */
624 hmerge
= ImageList_Merge(himl1
, -1, himl2
, 0, 0, 0);
625 ok(hmerge
!= NULL
, "merge himl1,-1 failed\n");
626 check_bits(hwnd
, hmerge
, 0, 32, empty_bits
, "merge himl1,-1");
627 if (hmerge
) ImageList_Destroy(hmerge
);
629 hmerge
= ImageList_Merge(himl1
, 0, himl2
, 0, 0, 0);
630 ok(hmerge
!= NULL
,"merge himl1,0 failed\n");
631 check_bits(hwnd
, hmerge
, 0, 32, empty_bits
, "merge himl1,0");
632 if (hmerge
) ImageList_Destroy(hmerge
);
634 /* Same happens if himl2 is empty */
635 ImageList_Destroy(himl2
);
636 himl2
= ImageList_Create(32,32,0,0,3);
637 ok(himl2
!= NULL
,"failed to recreate himl2\n");
641 hmerge
= ImageList_Merge(himl1
, -1, himl2
, -1, 0, 0);
642 ok(hmerge
!= NULL
, "merge himl2,-1 failed\n");
643 check_bits(hwnd
, hmerge
, 0, 32, empty_bits
, "merge himl2,-1");
644 if (hmerge
) ImageList_Destroy(hmerge
);
646 hmerge
= ImageList_Merge(himl1
, -1, himl2
, 0, 0, 0);
647 ok(hmerge
!= NULL
, "merge himl2,0 failed\n");
648 check_bits(hwnd
, hmerge
, 0, 32, empty_bits
, "merge himl2,0");
649 if (hmerge
) ImageList_Destroy(hmerge
);
651 /* Now try merging an image with itself */
652 ok(0==ImageList_AddIcon(himl2
, hicon1
),"re-add icon1 to himl2 failed\n");
654 hmerge
= ImageList_Merge(himl2
, 0, himl2
, 0, 0, 0);
655 ok(hmerge
!= NULL
, "merge himl2 with itself failed\n");
656 check_bits(hwnd
, hmerge
, 0, 32, empty_bits
, "merge himl2 with itself");
657 if (hmerge
) ImageList_Destroy(hmerge
);
659 /* Try merging 2 different image lists */
660 ok(0==ImageList_AddIcon(himl1
, hicon1
),"add icon1 to himl1 failed\n");
662 hmerge
= ImageList_Merge(himl1
, 0, himl2
, 0, 0, 0);
663 ok(hmerge
!= NULL
, "merge himl1 with himl2 failed\n");
664 check_bits(hwnd
, hmerge
, 0, 32, empty_bits
, "merge himl1 with himl2");
665 if (hmerge
) ImageList_Destroy(hmerge
);
667 hmerge
= ImageList_Merge(himl1
, 0, himl2
, 0, 8, 16);
668 ok(hmerge
!= NULL
, "merge himl1 with himl2 8,16 failed\n");
669 check_bits(hwnd
, hmerge
, 0, 32, empty_bits
, "merge himl1 with himl2, 8,16");
670 if (hmerge
) ImageList_Destroy(hmerge
);
672 ImageList_Destroy(himl1
);
673 ImageList_Destroy(himl2
);
678 /*********************** imagelist storage test ***************************/
684 IStream IStream_iface
;
688 static struct memstream
*impl_from_IStream(IStream
*iface
)
690 return CONTAINING_RECORD(iface
, struct memstream
, 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 struct memstream
*stream
= impl_from_IStream(iface
);
716 return IStream_Read(stream
->stream
, pv
, cb
, pcbRead
);
719 static HRESULT STDMETHODCALLTYPE
Test_Stream_Write(IStream
*iface
, const void *pv
, ULONG cb
,
722 struct memstream
*stream
= impl_from_IStream(iface
);
723 return IStream_Write(stream
->stream
, pv
, cb
, pcbWritten
);
726 static HRESULT STDMETHODCALLTYPE
Test_Stream_Seek(IStream
*iface
, LARGE_INTEGER dlibMove
,
727 DWORD dwOrigin
, ULARGE_INTEGER
*plibNewPosition
)
729 ok(0, "unexpected call\n");
733 static HRESULT STDMETHODCALLTYPE
Test_Stream_SetSize(IStream
*iface
, ULARGE_INTEGER libNewSize
)
735 ok(0, "unexpected call\n");
739 static HRESULT STDMETHODCALLTYPE
Test_Stream_CopyTo(IStream
*iface
, IStream
*pstm
,
740 ULARGE_INTEGER cb
, ULARGE_INTEGER
*pcbRead
,
741 ULARGE_INTEGER
*pcbWritten
)
743 ok(0, "unexpected call\n");
747 static HRESULT STDMETHODCALLTYPE
Test_Stream_Commit(IStream
*iface
, DWORD grfCommitFlags
)
749 ok(0, "unexpected call\n");
753 static HRESULT STDMETHODCALLTYPE
Test_Stream_Revert(IStream
*iface
)
755 ok(0, "unexpected call\n");
759 static HRESULT STDMETHODCALLTYPE
Test_Stream_LockRegion(IStream
*iface
, ULARGE_INTEGER libOffset
,
760 ULARGE_INTEGER cb
, DWORD dwLockType
)
762 ok(0, "unexpected call\n");
766 static HRESULT STDMETHODCALLTYPE
Test_Stream_UnlockRegion(IStream
*iface
, ULARGE_INTEGER libOffset
,
767 ULARGE_INTEGER cb
, DWORD dwLockType
)
769 ok(0, "unexpected call\n");
773 static HRESULT STDMETHODCALLTYPE
Test_Stream_Stat(IStream
*iface
, STATSTG
*pstatstg
,
776 ok(0, "unexpected call\n");
780 static HRESULT STDMETHODCALLTYPE
Test_Stream_Clone(IStream
*iface
, IStream
**ppstm
)
782 ok(0, "unexpected call\n");
786 static const IStreamVtbl Test_Stream_Vtbl
=
788 Test_Stream_QueryInterface
,
798 Test_Stream_LockRegion
,
799 Test_Stream_UnlockRegion
,
804 static void init_memstream(struct memstream
*stream
)
806 stream
->IStream_iface
.lpVtbl
= &Test_Stream_Vtbl
;
807 CreateStreamOnHGlobal(NULL
, TRUE
, &stream
->stream
);
810 static void cleanup_memstream(struct memstream
*stream
)
812 IStream_Release(stream
->stream
);
816 static INT
DIB_GetWidthBytes( int width
, int bpp
)
818 return ((width
* bpp
+ 31) / 8) & ~3;
821 static ULONG
check_bitmap_data(const char *bm_data
, ULONG bm_data_size
,
822 INT width
, INT height
, INT bpp
,
825 const BITMAPFILEHEADER
*bmfh
= (const BITMAPFILEHEADER
*)bm_data
;
826 const BITMAPINFOHEADER
*bmih
= (const BITMAPINFOHEADER
*)(bm_data
+ sizeof(*bmfh
));
827 ULONG hdr_size
, image_size
;
829 hdr_size
= sizeof(*bmfh
) + sizeof(*bmih
);
830 if (bmih
->biBitCount
<= 8) hdr_size
+= (1 << bpp
) * sizeof(RGBQUAD
);
832 ok(bmfh
->bfType
== (('M' << 8) | 'B'), "wrong bfType 0x%02x\n", bmfh
->bfType
);
833 ok(bmfh
->bfSize
== hdr_size
, "wrong bfSize 0x%02x\n", bmfh
->bfSize
);
834 ok(bmfh
->bfReserved1
== 0, "wrong bfReserved1 0x%02x\n", bmfh
->bfReserved1
);
835 ok(bmfh
->bfReserved2
== 0, "wrong bfReserved2 0x%02x\n", bmfh
->bfReserved2
);
836 ok(bmfh
->bfOffBits
== hdr_size
, "wrong bfOffBits 0x%02x\n", bmfh
->bfOffBits
);
838 ok(bmih
->biSize
== sizeof(*bmih
), "wrong biSize %d\n", bmih
->biSize
);
839 ok(bmih
->biWidth
== width
, "wrong biWidth %d (expected %d)\n", bmih
->biWidth
, width
);
840 ok(bmih
->biHeight
== height
, "wrong biHeight %d (expected %d)\n", bmih
->biHeight
, height
);
841 ok(bmih
->biPlanes
== 1, "wrong biPlanes %d\n", bmih
->biPlanes
);
842 ok(bmih
->biBitCount
== bpp
, "wrong biBitCount %d\n", bmih
->biBitCount
);
844 image_size
= DIB_GetWidthBytes(bmih
->biWidth
, bmih
->biBitCount
) * bmih
->biHeight
;
845 ok(bmih
->biSizeImage
== image_size
, "wrong biSizeImage %u\n", bmih
->biSizeImage
);
851 sprintf(fname
, "bmp_%s.bmp", comment
);
852 f
= fopen(fname
, "wb");
853 fwrite(bm_data
, 1, bm_data_size
, f
);
857 return hdr_size
+ image_size
;
860 static void check_ilhead_data(const char *ilh_data
, INT cx
, INT cy
, INT cur
, INT max
, INT grow
, INT flags
)
862 const ILHEAD
*ilh
= (const ILHEAD
*)ilh_data
;
864 ok(ilh
->usMagic
== IMAGELIST_MAGIC
, "wrong usMagic %4x (expected %02x)\n", ilh
->usMagic
, IMAGELIST_MAGIC
);
865 ok(ilh
->usVersion
== 0x101, "wrong usVersion %x (expected 0x101)\n", ilh
->usVersion
);
866 ok(ilh
->cCurImage
== cur
, "wrong cCurImage %d (expected %d)\n", ilh
->cCurImage
, cur
);
867 ok(ilh
->cMaxImage
== max
, "wrong cMaxImage %d (expected %d)\n", ilh
->cMaxImage
, max
);
868 ok(ilh
->cGrow
== grow
, "wrong cGrow %d (expected %d)\n", ilh
->cGrow
, grow
);
869 ok(ilh
->cx
== cx
, "wrong cx %d (expected %d)\n", ilh
->cx
, cx
);
870 ok(ilh
->cy
== cy
, "wrong cy %d (expected %d)\n", ilh
->cy
, cy
);
871 ok(ilh
->bkcolor
== CLR_NONE
, "wrong bkcolor %x\n", ilh
->bkcolor
);
872 ok(ilh
->flags
== flags
|| broken(!(ilh
->flags
& 0xfe) && (flags
& 0xfe) == ILC_COLOR4
), /* <= w2k */
873 "wrong flags %04x\n", ilh
->flags
);
874 ok(ilh
->ovls
[0] == -1, "wrong ovls[0] %04x\n", ilh
->ovls
[0]);
875 ok(ilh
->ovls
[1] == -1, "wrong ovls[1] %04x\n", ilh
->ovls
[1]);
876 ok(ilh
->ovls
[2] == -1, "wrong ovls[2] %04x\n", ilh
->ovls
[2]);
877 ok(ilh
->ovls
[3] == -1, "wrong ovls[3] %04x\n", ilh
->ovls
[3]);
880 static HBITMAP
create_bitmap(INT cx
, INT cy
, COLORREF color
, const char *comment
)
884 HBITMAP hbmp
, hbmp_old
;
886 RECT rc
= { 0, 0, cx
, cy
};
888 hdc
= CreateCompatibleDC(0);
890 memset(&bmi
, 0, sizeof(bmi
));
891 bmi
.bmiHeader
.biSize
= sizeof(bmi
.bmiHeader
);
892 bmi
.bmiHeader
.biHeight
= cx
;
893 bmi
.bmiHeader
.biWidth
= cy
;
894 bmi
.bmiHeader
.biBitCount
= 24;
895 bmi
.bmiHeader
.biPlanes
= 1;
896 bmi
.bmiHeader
.biCompression
= BI_RGB
;
897 hbmp
= CreateDIBSection(hdc
, &bmi
, DIB_RGB_COLORS
, NULL
, NULL
, 0);
899 hbmp_old
= SelectObject(hdc
, hbmp
);
901 hbrush
= CreateSolidBrush(color
);
902 FillRect(hdc
, &rc
, hbrush
);
903 DeleteObject(hbrush
);
905 DrawTextA(hdc
, comment
, -1, &rc
, DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
);
907 SelectObject(hdc
, hbmp_old
);
913 static void check_iml_data(HIMAGELIST himl
, INT cx
, INT cy
, INT cur
, INT max
, INT grow
,
914 INT width
, INT height
, INT flags
, const char *comment
)
916 INT ret
, cxx
, cyy
, size
;
917 struct memstream stream
;
925 trace("%s\n", comment
);
927 ret
= ImageList_GetImageCount(himl
);
928 ok(ret
== cur
, "expected image count %d got %d\n", cur
, ret
);
930 ret
= ImageList_GetIconSize(himl
, &cxx
, &cyy
);
931 ok(ret
, "ImageList_GetIconSize failed\n");
932 ok(cxx
== cx
, "wrong cx %d (expected %d)\n", cxx
, cx
);
933 ok(cyy
== cy
, "wrong cy %d (expected %d)\n", cyy
, cy
);
935 init_memstream(&stream
);
936 ret
= ImageList_Write(himl
, &stream
.IStream_iface
);
937 ok(ret
, "ImageList_Write failed\n");
939 hr
= GetHGlobalFromStream(stream
.stream
, &hglobal
);
940 ok(hr
== S_OK
, "Failed to get hglobal, %#x\n", hr
);
942 IStream_Stat(stream
.stream
, &stat
, STATFLAG_NONAME
);
944 data
= GlobalLock(hglobal
);
946 ok(data
!= 0, "ImageList_Write didn't write any data\n");
947 ok(stat
.cbSize
.LowPart
> sizeof(ILHEAD
), "ImageList_Write wrote not enough data\n");
949 check_ilhead_data(data
, cx
, cy
, cur
, max
, grow
, flags
);
950 size
= check_bitmap_data(data
+ sizeof(ILHEAD
), stat
.cbSize
.LowPart
- sizeof(ILHEAD
),
951 width
, height
, flags
& 0xfe, comment
);
952 if (size
< stat
.cbSize
.LowPart
- sizeof(ILHEAD
)) /* mask is present */
954 ok( flags
& ILC_MASK
, "extra data %u/%u but mask not expected\n", stat
.cbSize
.LowPart
, size
);
955 check_bitmap_data(data
+ sizeof(ILHEAD
) + size
, stat
.cbSize
.LowPart
- sizeof(ILHEAD
) - size
,
956 width
, height
, 1, comment
);
959 /* rewind and reconstruct from stream */
961 IStream_Seek(stream
.stream
, mv
, STREAM_SEEK_SET
, NULL
);
962 himl2
= ImageList_Read(&stream
.IStream_iface
);
963 ok(himl2
!= NULL
, "Failed to deserialize imagelist\n");
964 ImageList_Destroy(himl2
);
966 GlobalUnlock(hglobal
);
967 cleanup_memstream(&stream
);
970 static void image_list_init(HIMAGELIST himl
)
976 static const struct test_data
979 INT cx
, cy
, cur
, max
, grow
, width
, height
, bpp
;
983 { 255, BMP_CX
, BMP_CX
, 1, 2, 4, BMP_CX
* 4, BMP_CX
* 1, 24, "total 1" },
984 { 170, BMP_CX
, BMP_CX
, 2, 7, 4, BMP_CX
* 4, BMP_CX
* 2, 24, "total 2" },
985 { 85, BMP_CX
, BMP_CX
, 3, 7, 4, BMP_CX
* 4, BMP_CX
* 2, 24, "total 3" },
986 { 0, BMP_CX
, BMP_CX
, 4, 7, 4, BMP_CX
* 4, BMP_CX
* 2, 24, "total 4" },
987 { 0, BMP_CX
, BMP_CX
, 5, 7, 4, BMP_CX
* 4, BMP_CX
* 2, 24, "total 5" },
988 { 85, BMP_CX
, BMP_CX
, 6, 7, 4, BMP_CX
* 4, BMP_CX
* 2, 24, "total 6" },
989 { 170, BMP_CX
, BMP_CX
, 7, 12, 4, BMP_CX
* 4, BMP_CX
* 3, 24, "total 7" },
990 { 255, BMP_CX
, BMP_CX
, 8, 12, 4, BMP_CX
* 4, BMP_CX
* 3, 24, "total 8" },
991 { 255, BMP_CX
, BMP_CX
, 9, 12, 4, BMP_CX
* 4, BMP_CX
* 3, 24, "total 9" },
992 { 170, BMP_CX
, BMP_CX
, 10, 12, 4, BMP_CX
* 4, BMP_CX
* 3, 24, "total 10" },
993 { 85, BMP_CX
, BMP_CX
, 11, 12, 4, BMP_CX
* 4, BMP_CX
* 3, 24, "total 11" },
994 { 0, BMP_CX
, BMP_CX
, 12, 17, 4, BMP_CX
* 4, BMP_CX
* 5, 24, "total 12" },
995 { 0, BMP_CX
, BMP_CX
, 13, 17, 4, BMP_CX
* 4, BMP_CX
* 5, 24, "total 13" },
996 { 85, BMP_CX
, BMP_CX
, 14, 17, 4, BMP_CX
* 4, BMP_CX
* 5, 24, "total 14" },
997 { 170, BMP_CX
, BMP_CX
, 15, 17, 4, BMP_CX
* 4, BMP_CX
* 5, 24, "total 15" },
998 { 255, BMP_CX
, BMP_CX
, 16, 17, 4, BMP_CX
* 4, BMP_CX
* 5, 24, "total 16" },
999 { 255, BMP_CX
, BMP_CX
, 17, 22, 4, BMP_CX
* 4, BMP_CX
* 6, 24, "total 17" },
1000 { 170, BMP_CX
, BMP_CX
, 18, 22, 4, BMP_CX
* 4, BMP_CX
* 6, 24, "total 18" },
1001 { 85, BMP_CX
, BMP_CX
, 19, 22, 4, BMP_CX
* 4, BMP_CX
* 6, 24, "total 19" },
1002 { 0, BMP_CX
, BMP_CX
, 20, 22, 4, BMP_CX
* 4, BMP_CX
* 6, 24, "total 20" },
1003 { 0, BMP_CX
, BMP_CX
, 21, 22, 4, BMP_CX
* 4, BMP_CX
* 6, 24, "total 21" },
1004 { 85, BMP_CX
, BMP_CX
, 22, 27, 4, BMP_CX
* 4, BMP_CX
* 7, 24, "total 22" },
1005 { 170, BMP_CX
, BMP_CX
, 23, 27, 4, BMP_CX
* 4, BMP_CX
* 7, 24, "total 23" },
1006 { 255, BMP_CX
, BMP_CX
, 24, 27, 4, BMP_CX
* 4, BMP_CX
* 7, 24, "total 24" }
1009 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 2, 4, BMP_CX
* 4, BMP_CX
* 1, ILC_COLOR24
, "total 0");
1011 #define add_bitmap(grey) \
1012 sprintf(comment, "%d", n++); \
1013 hbm = create_bitmap(BMP_CX, BMP_CX, RGB((grey),(grey),(grey)), comment); \
1014 ImageList_Add(himl, hbm, NULL); \
1017 for (i
= 0; i
< sizeof(td
)/sizeof(td
[0]); i
++)
1019 add_bitmap(td
[i
].grey
);
1020 check_iml_data(himl
, td
[i
].cx
, td
[i
].cy
, td
[i
].cur
, td
[i
].max
, td
[i
].grow
,
1021 td
[i
].width
, td
[i
].height
, td
[i
].bpp
, td
[i
].comment
);
1026 static void test_imagelist_storage(void)
1033 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR24
, 1, 1);
1034 ok(himl
!= 0, "ImageList_Create failed\n");
1036 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 2, 4, BMP_CX
* 4, BMP_CX
* 1, ILC_COLOR24
, "empty");
1038 image_list_init(himl
);
1039 check_iml_data(himl
, BMP_CX
, BMP_CX
, 24, 27, 4, BMP_CX
* 4, BMP_CX
* 7, ILC_COLOR24
, "orig");
1041 ret
= ImageList_Remove(himl
, 4);
1042 ok(ret
, "ImageList_Remove failed\n");
1043 check_iml_data(himl
, BMP_CX
, BMP_CX
, 23, 27, 4, BMP_CX
* 4, BMP_CX
* 7, ILC_COLOR24
, "1");
1045 ret
= ImageList_Remove(himl
, 5);
1046 ok(ret
, "ImageList_Remove failed\n");
1047 check_iml_data(himl
, BMP_CX
, BMP_CX
, 22, 27, 4, BMP_CX
* 4, BMP_CX
* 7, ILC_COLOR24
, "2");
1049 ret
= ImageList_Remove(himl
, 6);
1050 ok(ret
, "ImageList_Remove failed\n");
1051 check_iml_data(himl
, BMP_CX
, BMP_CX
, 21, 27, 4, BMP_CX
* 4, BMP_CX
* 7, ILC_COLOR24
, "3");
1053 ret
= ImageList_Remove(himl
, 7);
1054 ok(ret
, "ImageList_Remove failed\n");
1055 check_iml_data(himl
, BMP_CX
, BMP_CX
, 20, 27, 4, BMP_CX
* 4, BMP_CX
* 7, ILC_COLOR24
, "4");
1057 ret
= ImageList_Remove(himl
, -2);
1058 ok(!ret
, "ImageList_Remove(-2) should fail\n");
1059 check_iml_data(himl
, BMP_CX
, BMP_CX
, 20, 27, 4, BMP_CX
* 4, BMP_CX
* 7, ILC_COLOR24
, "5");
1061 ret
= ImageList_Remove(himl
, 20);
1062 ok(!ret
, "ImageList_Remove(20) should fail\n");
1063 check_iml_data(himl
, BMP_CX
, BMP_CX
, 20, 27, 4, BMP_CX
* 4, BMP_CX
* 7, ILC_COLOR24
, "6");
1065 ret
= ImageList_Remove(himl
, -1);
1066 ok(ret
, "ImageList_Remove(-1) failed\n");
1067 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 4, 4, BMP_CX
* 4, BMP_CX
* 1, ILC_COLOR24
, "7");
1069 ret
= ImageList_Destroy(himl
);
1070 ok(ret
, "ImageList_Destroy failed\n");
1072 /* test ImageList_Create storage allocation */
1074 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR24
, 0, 32);
1075 ok(himl
!= 0, "ImageList_Create failed\n");
1076 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 1, 32, BMP_CX
* 4, BMP_CX
* 1, ILC_COLOR24
, "init 0 grow 32");
1077 hbm
= create_bitmap(BMP_CX
* 9, BMP_CX
, 0, "9");
1078 ret
= ImageList_Add(himl
, hbm
, NULL
);
1079 ok(ret
== 0, "ImageList_Add returned %d, expected 0\n", ret
);
1080 check_iml_data(himl
, BMP_CX
, BMP_CX
, 1, 34, 32, BMP_CX
* 4, BMP_CX
* 9, ILC_COLOR24
, "add 1 x 9");
1082 ret
= ImageList_Destroy(himl
);
1083 ok(ret
, "ImageList_Destroy failed\n");
1085 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR24
, 4, 4);
1086 ok(himl
!= 0, "ImageList_Create failed\n");
1087 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 5, 4, BMP_CX
* 4, BMP_CX
* 2, ILC_COLOR24
, "init 4 grow 4");
1088 hbm
= create_bitmap(BMP_CX
, BMP_CX
* 9, 0, "9");
1089 ret
= ImageList_Add(himl
, hbm
, NULL
);
1090 ok(ret
== 0, "ImageList_Add returned %d, expected 0\n", ret
);
1091 check_iml_data(himl
, BMP_CX
, BMP_CX
, 9, 15, 4, BMP_CX
* 4, BMP_CX
* 4, ILC_COLOR24
, "add 9 x 1");
1092 ret
= ImageList_Add(himl
, hbm
, NULL
);
1093 ok(ret
== 9, "ImageList_Add returned %d, expected 9\n", ret
);
1094 check_iml_data(himl
, BMP_CX
, BMP_CX
, 18, 25, 4, BMP_CX
* 4, BMP_CX
* 7, ILC_COLOR24
, "add 9 x 1");
1096 ret
= ImageList_Destroy(himl
);
1097 ok(ret
, "ImageList_Destroy failed\n");
1099 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR24
, 207, 209);
1100 ok(himl
!= 0, "ImageList_Create failed\n");
1101 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 208, 212, BMP_CX
* 4, BMP_CX
* 52, ILC_COLOR24
, "init 207 grow 209");
1102 ret
= ImageList_Destroy(himl
);
1103 ok(ret
, "ImageList_Destroy failed\n");
1105 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR24
, 209, 207);
1106 ok(himl
!= 0, "ImageList_Create failed\n");
1107 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 210, 208, BMP_CX
* 4, BMP_CX
* 53, ILC_COLOR24
, "init 209 grow 207");
1108 ret
= ImageList_Destroy(himl
);
1109 ok(ret
, "ImageList_Destroy failed\n");
1111 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR24
, 14, 4);
1112 ok(himl
!= 0, "ImageList_Create failed\n");
1113 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 15, 4, BMP_CX
* 4, BMP_CX
* 4, ILC_COLOR24
, "init 14 grow 4");
1114 ret
= ImageList_Destroy(himl
);
1115 ok(ret
, "ImageList_Destroy failed\n");
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");
1123 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR24
, 9, 5);
1124 ok(himl
!= 0, "ImageList_Create failed\n");
1125 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 10, 8, BMP_CX
* 4, BMP_CX
* 3, ILC_COLOR24
, "init 9 grow 5");
1126 ret
= ImageList_Destroy(himl
);
1127 ok(ret
, "ImageList_Destroy failed\n");
1129 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR24
, 2, 4);
1130 ok(himl
!= 0, "ImageList_Create failed\n");
1131 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 3, 4, BMP_CX
* 4, BMP_CX
* 1, ILC_COLOR24
, "init 2 grow 4");
1132 ret
= ImageList_Destroy(himl
);
1133 ok(ret
, "ImageList_Destroy failed\n");
1135 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR24
, 4, 2);
1136 ok(himl
!= 0, "ImageList_Create failed\n");
1137 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 5, 4, BMP_CX
* 4, BMP_CX
* 2, ILC_COLOR24
, "init 4 grow 2");
1138 ret
= ImageList_Destroy(himl
);
1139 ok(ret
, "ImageList_Destroy failed\n");
1141 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR8
, 4, 2);
1142 ok(himl
!= 0, "ImageList_Create failed\n");
1143 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 5, 4, BMP_CX
* 4, BMP_CX
* 2, ILC_COLOR8
, "bpp 8");
1144 ret
= ImageList_Destroy(himl
);
1145 ok(ret
, "ImageList_Destroy failed\n");
1147 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR4
, 4, 2);
1148 ok(himl
!= 0, "ImageList_Create failed\n");
1149 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 5, 4, BMP_CX
* 4, BMP_CX
* 2, ILC_COLOR4
, "bpp 4");
1150 ret
= ImageList_Destroy(himl
);
1151 ok(ret
, "ImageList_Destroy failed\n");
1153 himl
= ImageList_Create(BMP_CX
, BMP_CX
, 0, 4, 2);
1154 ok(himl
!= 0, "ImageList_Create failed\n");
1155 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 5, 4, BMP_CX
* 4, BMP_CX
* 2, ILC_COLOR4
, "bpp default");
1156 icon
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
1157 ok( ImageList_AddIcon(himl
, icon
) == 0,"failed to add icon\n");
1158 ok( ImageList_AddIcon(himl
, icon
) == 1,"failed to add icon\n");
1159 DestroyIcon( icon
);
1160 check_iml_data(himl
, BMP_CX
, BMP_CX
, 2, 5, 4, BMP_CX
* 4, BMP_CX
* 2, ILC_COLOR4
, "bpp default");
1161 ret
= ImageList_Destroy(himl
);
1162 ok(ret
, "ImageList_Destroy failed\n");
1164 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR24
|ILC_MASK
, 4, 2);
1165 ok(himl
!= 0, "ImageList_Create failed\n");
1166 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 5, 4, BMP_CX
* 4, BMP_CX
* 2, ILC_COLOR24
|ILC_MASK
,
1168 icon
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
1169 ok( ImageList_AddIcon(himl
, icon
) == 0,"failed to add icon\n");
1170 ok( ImageList_AddIcon(himl
, icon
) == 1,"failed to add icon\n");
1171 DestroyIcon( icon
);
1172 check_iml_data(himl
, BMP_CX
, BMP_CX
, 2, 5, 4, BMP_CX
* 4, BMP_CX
* 2, ILC_COLOR24
|ILC_MASK
,
1174 ret
= ImageList_Destroy(himl
);
1175 ok(ret
, "ImageList_Destroy failed\n");
1177 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR4
|ILC_MASK
, 4, 2);
1178 ok(himl
!= 0, "ImageList_Create failed\n");
1179 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 5, 4, BMP_CX
* 4, BMP_CX
* 2, ILC_COLOR4
|ILC_MASK
,
1181 icon
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
1182 ok( ImageList_AddIcon(himl
, icon
) == 0,"failed to add icon\n");
1183 ok( ImageList_AddIcon(himl
, icon
) == 1,"failed to add icon\n");
1184 DestroyIcon( icon
);
1185 check_iml_data(himl
, BMP_CX
, BMP_CX
, 2, 5, 4, BMP_CX
* 4, BMP_CX
* 2, ILC_COLOR4
|ILC_MASK
,
1187 ret
= ImageList_Destroy(himl
);
1188 ok(ret
, "ImageList_Destroy failed\n");
1190 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR4
|ILC_MASK
, 2, 99);
1191 ok(himl
!= 0, "ImageList_Create failed\n");
1192 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 3, 100, BMP_CX
* 4, BMP_CX
, ILC_COLOR4
|ILC_MASK
,
1194 icon
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
1195 ok( ImageList_AddIcon(himl
, icon
) == 0,"failed to add icon\n");
1196 ok( ImageList_AddIcon(himl
, icon
) == 1,"failed to add icon\n");
1197 check_iml_data(himl
, BMP_CX
, BMP_CX
, 2, 3, 100, BMP_CX
* 4, BMP_CX
, ILC_COLOR4
|ILC_MASK
,
1198 "init 2 grow 99 2 icons");
1199 ok( ImageList_AddIcon(himl
, icon
) == 2,"failed to add icon\n");
1200 DestroyIcon( icon
);
1201 check_iml_data(himl
, BMP_CX
, BMP_CX
, 3, 104, 100, BMP_CX
* 4, BMP_CX
* 104/4, ILC_COLOR4
|ILC_MASK
,
1202 "init 2 grow 99 3 icons");
1203 ok( ImageList_Remove(himl
, -1) == TRUE
,"failed to remove icon\n");
1204 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 100, 100, BMP_CX
* 4, BMP_CX
* 100/4, ILC_COLOR4
|ILC_MASK
,
1205 "init 2 grow 99 empty");
1206 ok( ImageList_SetImageCount(himl
, 22) == TRUE
,"failed to set image count\n");
1207 check_iml_data(himl
, BMP_CX
, BMP_CX
, 22, 23, 100, BMP_CX
* 4, BMP_CX
* 24/4, ILC_COLOR4
|ILC_MASK
,
1208 "init 2 grow 99 set count 22");
1209 ok( ImageList_SetImageCount(himl
, 0) == TRUE
,"failed to set image count\n");
1210 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 1, 100, BMP_CX
* 4, BMP_CX
, ILC_COLOR4
|ILC_MASK
,
1211 "init 2 grow 99 set count 0");
1212 ok( ImageList_SetImageCount(himl
, 42) == TRUE
,"failed to set image count\n");
1213 check_iml_data(himl
, BMP_CX
, BMP_CX
, 42, 43, 100, BMP_CX
* 4, BMP_CX
* 44/4, ILC_COLOR4
|ILC_MASK
,
1214 "init 2 grow 99 set count 42");
1215 ret
= ImageList_Destroy(himl
);
1216 ok(ret
, "ImageList_Destroy failed\n");
1218 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR4
|ILC_MASK
, 2, 65536+12);
1219 ok(himl
!= 0, "ImageList_Create failed\n");
1220 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 3, 12, BMP_CX
* 4, BMP_CX
, ILC_COLOR4
|ILC_MASK
,
1221 "init 2 grow 65536+12");
1222 ret
= ImageList_Destroy(himl
);
1223 ok(ret
, "ImageList_Destroy failed\n");
1225 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR4
|ILC_MASK
, 2, 65535);
1226 ok(himl
!= 0, "ImageList_Create failed\n");
1227 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 3, 0, BMP_CX
* 4, BMP_CX
, ILC_COLOR4
|ILC_MASK
,
1228 "init 2 grow 65535");
1229 ret
= ImageList_Destroy(himl
);
1230 ok(ret
, "ImageList_Destroy failed\n");
1232 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR4
|ILC_MASK
, 2, -20);
1233 ok(himl
!= 0, "ImageList_Create failed\n");
1234 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 3, 4, BMP_CX
* 4, BMP_CX
, ILC_COLOR4
|ILC_MASK
,
1236 ret
= ImageList_Destroy(himl
);
1237 ok(ret
, "ImageList_Destroy failed\n");
1240 static void test_shell_imagelist(void)
1242 HRESULT (WINAPI
*pSHGetImageList
)(INT
, REFIID
, void**);
1243 IImageList
*iml
= NULL
;
1250 /* Try to load function from shell32 */
1251 hShell32
= LoadLibraryA("shell32.dll");
1252 pSHGetImageList
= (void*)GetProcAddress(hShell32
, (LPCSTR
) 727);
1254 if (!pSHGetImageList
)
1256 win_skip("SHGetImageList not available, skipping test\n");
1257 FreeLibrary(hShell32
);
1261 /* Get system image list */
1262 hr
= pSHGetImageList(SHIL_SYSSMALL
, &IID_IImageList
, (void**)&iml
);
1263 ok(SUCCEEDED(hr
), "SHGetImageList failed, hr=%x\n", hr
);
1266 FreeLibrary(hShell32
);
1270 IImageList_GetImageCount(iml
, &out
);
1271 ok(out
> 0, "IImageList_GetImageCount returned out <= 0\n");
1273 /* Fetch the small icon size */
1274 cx
= GetSystemMetrics(SM_CXSMICON
);
1275 cy
= GetSystemMetrics(SM_CYSMICON
);
1277 /* Check icon size matches */
1278 IImageList_GetImageRect(iml
, 0, &rect
);
1279 ok(((rect
.right
== cx
) && (rect
.bottom
== cy
)),
1280 "IImageList_GetImageRect returned r:%d,b:%d\n",
1281 rect
.right
, rect
.bottom
);
1283 IImageList_Release(iml
);
1284 FreeLibrary(hShell32
);
1287 static HBITMAP
create_test_bitmap(HDC hdc
, int bpp
, UINT32 pixel1
, UINT32 pixel2
)
1290 UINT32
*buffer
= NULL
;
1291 BITMAPINFO bitmapInfo
= {{sizeof(BITMAPINFOHEADER
), 2, 1, 1, bpp
, BI_RGB
,
1294 hBitmap
= CreateDIBSection(hdc
, &bitmapInfo
, DIB_RGB_COLORS
, (void**)&buffer
, NULL
, 0);
1295 ok(hBitmap
!= NULL
&& buffer
!= NULL
, "CreateDIBSection failed.\n");
1297 if(!hBitmap
|| !buffer
)
1299 DeleteObject(hBitmap
);
1309 static BOOL
colour_match(UINT32 x
, UINT32 y
)
1311 const INT32 tolerance
= 8;
1313 const INT32 dr
= abs((INT32
)(x
& 0x000000FF) - (INT32
)(y
& 0x000000FF));
1314 const INT32 dg
= abs((INT32
)((x
& 0x0000FF00) >> 8) - (INT32
)((y
& 0x0000FF00) >> 8));
1315 const INT32 db
= abs((INT32
)((x
& 0x00FF0000) >> 16) - (INT32
)((y
& 0x00FF0000) >> 16));
1317 return (dr
<= tolerance
&& dg
<= tolerance
&& db
<= tolerance
);
1320 static void check_ImageList_DrawIndirect(IMAGELISTDRAWPARAMS
*ildp
, UINT32
*bits
,
1321 UINT32 expected
, int line
)
1323 bits
[0] = 0x00FFFFFF;
1324 pImageList_DrawIndirect(ildp
);
1325 ok(colour_match(bits
[0], expected
),
1326 "ImageList_DrawIndirect: Pixel %08X, Expected a close match to %08X from line %d\n",
1327 bits
[0] & 0x00FFFFFF, expected
, line
);
1331 static void check_ImageList_DrawIndirect_fStyle(HDC hdc
, HIMAGELIST himl
, UINT32
*bits
, int i
,
1332 UINT fStyle
, UINT32 expected
, int line
)
1334 IMAGELISTDRAWPARAMS ildp
= {sizeof(IMAGELISTDRAWPARAMS
), himl
, i
, hdc
,
1335 0, 0, 0, 0, 0, 0, CLR_NONE
, CLR_NONE
, fStyle
, 0, ILS_NORMAL
, 0, 0x00000000};
1336 check_ImageList_DrawIndirect(&ildp
, bits
, expected
, line
);
1339 static void check_ImageList_DrawIndirect_ILD_ROP(HDC hdc
, HIMAGELIST himl
, UINT32
*bits
, int i
,
1340 DWORD dwRop
, UINT32 expected
, int line
)
1342 IMAGELISTDRAWPARAMS ildp
= {sizeof(IMAGELISTDRAWPARAMS
), himl
, i
, hdc
,
1343 0, 0, 0, 0, 0, 0, CLR_NONE
, CLR_NONE
, ILD_IMAGE
| ILD_ROP
, dwRop
, ILS_NORMAL
, 0, 0x00000000};
1344 check_ImageList_DrawIndirect(&ildp
, bits
, expected
, line
);
1347 static void check_ImageList_DrawIndirect_fState(HDC hdc
, HIMAGELIST himl
, UINT32
*bits
, int i
, UINT fStyle
,
1348 UINT fState
, DWORD Frame
, UINT32 expected
, int line
)
1350 IMAGELISTDRAWPARAMS ildp
= {sizeof(IMAGELISTDRAWPARAMS
), himl
, i
, hdc
,
1351 0, 0, 0, 0, 0, 0, CLR_NONE
, CLR_NONE
, fStyle
, 0, fState
, Frame
, 0x00000000};
1352 check_ImageList_DrawIndirect(&ildp
, bits
, expected
, line
);
1355 static void check_ImageList_DrawIndirect_broken(HDC hdc
, HIMAGELIST himl
, UINT32
*bits
, int i
,
1356 UINT fStyle
, UINT fState
, DWORD Frame
, UINT32 expected
,
1357 UINT32 broken_expected
, int line
)
1359 IMAGELISTDRAWPARAMS ildp
= {sizeof(IMAGELISTDRAWPARAMS
), himl
, i
, hdc
,
1360 0, 0, 0, 0, 0, 0, CLR_NONE
, CLR_NONE
, fStyle
, 0, fState
, Frame
, 0x00000000};
1361 bits
[0] = 0x00FFFFFF;
1362 pImageList_DrawIndirect(&ildp
);
1363 ok(colour_match(bits
[0], expected
) ||
1364 broken(colour_match(bits
[0], broken_expected
)),
1365 "ImageList_DrawIndirect: Pixel %08X, Expected a close match to %08X from line %d\n",
1366 bits
[0] & 0x00FFFFFF, expected
, line
);
1369 static void test_ImageList_DrawIndirect(void)
1371 HIMAGELIST himl
= NULL
;
1374 HBITMAP hbmOld
= NULL
, hbmDst
= NULL
;
1375 HBITMAP hbmMask
= NULL
, hbmInverseMask
= NULL
;
1376 HBITMAP hbmImage
= NULL
, hbmAlphaImage
= NULL
, hbmTransparentImage
= NULL
;
1377 int iImage
= -1, iAlphaImage
= -1, iTransparentImage
= -1;
1379 UINT32 maskBits
= 0x00000000, inverseMaskBits
= 0xFFFFFFFF;
1380 int bpp
, broken_value
;
1382 BITMAPINFO bitmapInfo
= {{sizeof(BITMAPINFOHEADER
), 2, 1, 1, 32, BI_RGB
,
1385 hdcDst
= CreateCompatibleDC(0);
1386 ok(hdcDst
!= 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1389 bpp
= GetDeviceCaps(hdcDst
, BITSPIXEL
);
1391 hbmMask
= CreateBitmap(2, 1, 1, 1, &maskBits
);
1392 ok(hbmMask
!= 0, "CreateBitmap failed\n");
1393 if(!hbmMask
) goto cleanup
;
1395 hbmInverseMask
= CreateBitmap(2, 1, 1, 1, &inverseMaskBits
);
1396 ok(hbmInverseMask
!= 0, "CreateBitmap failed\n");
1397 if(!hbmInverseMask
) goto cleanup
;
1399 himl
= pImageList_Create(2, 1, ILC_COLOR32
, 0, 1);
1400 ok(himl
!= 0, "ImageList_Create failed\n");
1401 if(!himl
) goto cleanup
;
1403 /* Add a no-alpha image */
1404 hbmImage
= create_test_bitmap(hdcDst
, 32, 0x00ABCDEF, 0x00ABCDEF);
1405 if(!hbmImage
) goto cleanup
;
1407 iImage
= pImageList_Add(himl
, hbmImage
, hbmMask
);
1408 ok(iImage
!= -1, "ImageList_Add failed\n");
1409 if(iImage
== -1) goto cleanup
;
1411 /* Add an alpha image */
1412 hbmAlphaImage
= create_test_bitmap(hdcDst
, 32, 0x89ABCDEF, 0x89ABCDEF);
1413 if(!hbmAlphaImage
) goto cleanup
;
1415 iAlphaImage
= pImageList_Add(himl
, hbmAlphaImage
, hbmMask
);
1416 ok(iAlphaImage
!= -1, "ImageList_Add failed\n");
1417 if(iAlphaImage
== -1) goto cleanup
;
1419 /* Add a transparent alpha image */
1420 hbmTransparentImage
= create_test_bitmap(hdcDst
, 32, 0x00ABCDEF, 0x89ABCDEF);
1421 if(!hbmTransparentImage
) goto cleanup
;
1423 iTransparentImage
= pImageList_Add(himl
, hbmTransparentImage
, hbmMask
);
1424 ok(iTransparentImage
!= -1, "ImageList_Add failed\n");
1425 if(iTransparentImage
== -1) goto cleanup
;
1428 bitmapInfo
.bmiHeader
.biBitCount
= 32;
1429 hbmDst
= CreateDIBSection(hdcDst
, &bitmapInfo
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
1430 ok (hbmDst
&& bits
, "CreateDIBSection failed to return a valid bitmap and buffer\n");
1431 if (!hbmDst
|| !bits
)
1433 hbmOld
= SelectObject(hdcDst
, hbmDst
);
1435 check_ImageList_DrawIndirect_fStyle(hdcDst
, himl
, bits
, iImage
, ILD_NORMAL
, 0x00ABCDEF, __LINE__
);
1436 check_ImageList_DrawIndirect_fStyle(hdcDst
, himl
, bits
, iImage
, ILD_TRANSPARENT
, 0x00ABCDEF, __LINE__
);
1437 todo_wine
check_ImageList_DrawIndirect_broken(hdcDst
, himl
, bits
, iAlphaImage
, ILD_BLEND25
, ILS_NORMAL
, 0, 0x00E8F1FA, 0x00D4D9DD, __LINE__
);
1438 if (bpp
== 16 || bpp
== 24) broken_value
= 0x00D4D9DD;
1439 else broken_value
= 0x00B4BDC4;
1440 todo_wine
check_ImageList_DrawIndirect_broken(hdcDst
, himl
, bits
, iAlphaImage
, ILD_BLEND50
, ILS_NORMAL
, 0, 0x00E8F1FA, broken_value
, __LINE__
);
1441 check_ImageList_DrawIndirect_fStyle(hdcDst
, himl
, bits
, iImage
, ILD_MASK
, 0x00ABCDEF, __LINE__
);
1442 check_ImageList_DrawIndirect_fStyle(hdcDst
, himl
, bits
, iImage
, ILD_IMAGE
, 0x00ABCDEF, __LINE__
);
1443 check_ImageList_DrawIndirect_fStyle(hdcDst
, himl
, bits
, iImage
, ILD_PRESERVEALPHA
, 0x00ABCDEF, __LINE__
);
1445 check_ImageList_DrawIndirect_fStyle(hdcDst
, himl
, bits
, iAlphaImage
, ILD_NORMAL
, 0x00D3E5F7, __LINE__
);
1446 check_ImageList_DrawIndirect_fStyle(hdcDst
, himl
, bits
, iAlphaImage
, ILD_TRANSPARENT
, 0x00D3E5F7, __LINE__
);
1448 if (bpp
== 16 || bpp
== 24) broken_value
= 0x00D4D9DD;
1449 else broken_value
= 0x009DA8B1;
1450 todo_wine
check_ImageList_DrawIndirect_broken(hdcDst
, himl
, bits
, iAlphaImage
, ILD_BLEND25
, ILS_NORMAL
, 0, 0x00E8F1FA, broken_value
, __LINE__
);
1451 if (bpp
== 16 || bpp
== 24) broken_value
= 0x00D4D9DD;
1452 else broken_value
= 0x008C99A3;
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
, iAlphaImage
, ILD_MASK
, 0x00D3E5F7, __LINE__
);
1455 check_ImageList_DrawIndirect_fStyle(hdcDst
, himl
, bits
, iAlphaImage
, ILD_IMAGE
, 0x00D3E5F7, __LINE__
);
1456 todo_wine
check_ImageList_DrawIndirect_fStyle(hdcDst
, himl
, bits
, iAlphaImage
, ILD_PRESERVEALPHA
, 0x005D6F81, __LINE__
);
1458 check_ImageList_DrawIndirect_fStyle(hdcDst
, himl
, bits
, iTransparentImage
, ILD_NORMAL
, 0x00FFFFFF, __LINE__
);
1460 check_ImageList_DrawIndirect_ILD_ROP(hdcDst
, himl
, bits
, iImage
, SRCCOPY
, 0x00ABCDEF, __LINE__
);
1461 check_ImageList_DrawIndirect_ILD_ROP(hdcDst
, himl
, bits
, iImage
, SRCINVERT
, 0x00543210, __LINE__
);
1463 /* ILD_ROP is ignored when the image has an alpha channel */
1464 check_ImageList_DrawIndirect_ILD_ROP(hdcDst
, himl
, bits
, iAlphaImage
, SRCCOPY
, 0x00D3E5F7, __LINE__
);
1465 check_ImageList_DrawIndirect_ILD_ROP(hdcDst
, himl
, bits
, iAlphaImage
, SRCINVERT
, 0x00D3E5F7, __LINE__
);
1467 todo_wine
check_ImageList_DrawIndirect_fState(hdcDst
, himl
, bits
, iImage
, ILD_NORMAL
, ILS_SATURATE
, 0, 0x00CCCCCC, __LINE__
);
1468 todo_wine
check_ImageList_DrawIndirect_broken(hdcDst
, himl
, bits
, iAlphaImage
, ILD_NORMAL
, ILS_SATURATE
, 0, 0x00AFAFAF, 0x00F0F0F0, __LINE__
);
1470 check_ImageList_DrawIndirect_fState(hdcDst
, himl
, bits
, iImage
, ILD_NORMAL
, ILS_GLOW
, 0, 0x00ABCDEF, __LINE__
);
1471 check_ImageList_DrawIndirect_fState(hdcDst
, himl
, bits
, iImage
, ILD_NORMAL
, ILS_SHADOW
, 0, 0x00ABCDEF, __LINE__
);
1473 check_ImageList_DrawIndirect_fState(hdcDst
, himl
, bits
, iImage
, ILD_NORMAL
, ILS_ALPHA
, 127, 0x00D5E6F7, __LINE__
);
1474 check_ImageList_DrawIndirect_broken(hdcDst
, himl
, bits
, iAlphaImage
, ILD_NORMAL
, ILS_ALPHA
, 127, 0x00E9F2FB, 0x00AEB7C0, __LINE__
);
1475 todo_wine
check_ImageList_DrawIndirect_broken(hdcDst
, himl
, bits
, iAlphaImage
, ILD_NORMAL
, ILS_NORMAL
, 127, 0x00E9F2FB, 0x00D3E5F7, __LINE__
);
1480 SelectObject(hdcDst
, hbmOld
);
1482 DeleteObject(hbmDst
);
1488 DeleteObject(hbmMask
);
1490 DeleteObject(hbmInverseMask
);
1493 DeleteObject(hbmImage
);
1495 DeleteObject(hbmAlphaImage
);
1496 if(hbmTransparentImage
)
1497 DeleteObject(hbmTransparentImage
);
1501 ret
= ImageList_Destroy(himl
);
1502 ok(ret
, "ImageList_Destroy failed\n");
1506 static void test_iimagelist(void)
1508 IImageList
*imgl
, *imgl2
;
1509 IImageList2
*imagelist
;
1514 if (!pHIMAGELIST_QueryInterface
)
1516 win_skip("XP imagelist functions not available\n");
1520 /* test reference counting on destruction */
1521 imgl
= (IImageList
*)createImageList(32, 32);
1522 ret
= IImageList_AddRef(imgl
);
1523 ok(ret
== 2, "Expected 2, got %d\n", ret
);
1524 ret
= ImageList_Destroy((HIMAGELIST
)imgl
);
1525 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1526 ret
= ImageList_Destroy((HIMAGELIST
)imgl
);
1527 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1528 ret
= ImageList_Destroy((HIMAGELIST
)imgl
);
1529 ok(ret
== FALSE
, "Expected FALSE, got %d\n", ret
);
1531 imgl
= (IImageList
*)createImageList(32, 32);
1532 ret
= IImageList_AddRef(imgl
);
1533 ok(ret
== 2, "Expected 2, got %d\n", ret
);
1534 ret
= ImageList_Destroy((HIMAGELIST
)imgl
);
1535 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1536 ret
= IImageList_Release(imgl
);
1537 ok(ret
== 0, "Expected 0, got %d\n", ret
);
1538 ret
= ImageList_Destroy((HIMAGELIST
)imgl
);
1539 ok(ret
== FALSE
, "Expected FALSE, got %d\n", ret
);
1541 /* ref counting, HIMAGELIST_QueryInterface adds a reference */
1542 imgl
= (IImageList
*)createImageList(32, 32);
1543 hr
= pHIMAGELIST_QueryInterface((HIMAGELIST
)imgl
, &IID_IImageList
, (void**)&imgl2
);
1544 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1545 ok(imgl2
== imgl
, "got different pointer\n");
1546 ret
= IImageList_Release(imgl
);
1547 ok(ret
== 1, "got %u\n", ret
);
1548 IImageList_Release(imgl
);
1550 if (!pImageList_CoCreateInstance
)
1552 win_skip("Vista imagelist functions not available\n");
1556 hr
= pImageList_CoCreateInstance(&CLSID_ImageList
, NULL
, &IID_IImageList
, (void **) &imgl
);
1557 ok(SUCCEEDED(hr
), "ImageList_CoCreateInstance failed, hr=%x\n", hr
);
1560 IImageList_Release(imgl
);
1562 himl
= createImageList(32, 32);
1567 hr
= (pHIMAGELIST_QueryInterface
)(himl
, &IID_IImageList
, (void **) &imgl
);
1568 ok(SUCCEEDED(hr
), "HIMAGELIST_QueryInterface failed, hr=%x\n", hr
);
1571 IImageList_Release(imgl
);
1573 ImageList_Destroy(himl
);
1576 hr
= pImageList_CoCreateInstance(&CLSID_ImageList
, NULL
, &IID_IImageList2
, (void**)&imagelist
);
1579 win_skip("IImageList2 is not supported.\n");
1582 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1583 IImageList2_Release(imagelist
);
1586 static void test_hotspot_v6(void)
1597 #define HOTSPOTS_MAX 4 /* Number of entries in hotspots */
1598 static const struct hotspot hotspots
[HOTSPOTS_MAX
] = {
1605 HIMAGELIST himl1
= createImageList(SIZEX1
, SIZEY1
);
1606 HIMAGELIST himl2
= createImageList(SIZEX2
, SIZEY2
);
1607 IImageList
*imgl1
, *imgl2
;
1610 /* cast to IImageList */
1611 imgl1
= (IImageList
*) himl1
;
1612 imgl2
= (IImageList
*) himl2
;
1614 for (i
= 0; i
< HOTSPOTS_MAX
; i
++) {
1615 for (j
= 0; j
< HOTSPOTS_MAX
; j
++) {
1616 int dx1
= hotspots
[i
].dx
;
1617 int dy1
= hotspots
[i
].dy
;
1618 int dx2
= hotspots
[j
].dx
;
1619 int dy2
= hotspots
[j
].dy
;
1620 int correctx
, correcty
, newx
, newy
;
1622 IImageList
*imglNew
;
1625 hr
= IImageList_BeginDrag(imgl1
, 0, dx1
, dy1
);
1626 ok(SUCCEEDED(hr
), "BeginDrag failed for { %d, %d }\n", dx1
, dy1
);
1627 sprintf(loc
, "BeginDrag (%d,%d)\n", i
, j
);
1629 /* check merging the dragged image with a second image */
1630 hr
= IImageList_SetDragCursorImage(imgl2
, (IUnknown
*) imgl2
, 0, dx2
, dy2
);
1631 ok(SUCCEEDED(hr
), "SetDragCursorImage failed for {%d, %d}{%d, %d}\n",
1632 dx1
, dy1
, dx2
, dy2
);
1633 sprintf(loc
, "SetDragCursorImage (%d,%d)\n", i
, j
);
1635 /* check new hotspot, it should be the same like the old one */
1636 hr
= IImageList_GetDragImage(imgl2
, NULL
, &ppt
, &IID_IImageList
, (PVOID
*) &imglNew
);
1637 ok(SUCCEEDED(hr
), "GetDragImage failed\n");
1638 ok(ppt
.x
== dx1
&& ppt
.y
== dy1
,
1639 "Expected drag hotspot [%d,%d] got [%d,%d]\n",
1640 dx1
, dy1
, ppt
.x
, ppt
.y
);
1641 /* check size of new dragged image */
1642 IImageList_GetIconSize(imglNew
, &newx
, &newy
);
1643 correctx
= max(SIZEX1
, max(SIZEX2
+ dx2
, SIZEX1
- dx2
));
1644 correcty
= max(SIZEY1
, max(SIZEY2
+ dy2
, SIZEY1
- dy2
));
1645 ok(newx
== correctx
&& newy
== correcty
,
1646 "Expected drag image size [%d,%d] got [%d,%d]\n",
1647 correctx
, correcty
, newx
, newy
);
1648 sprintf(loc
, "GetDragImage (%d,%d)\n", i
, j
);
1649 IImageList_EndDrag(imgl2
);
1657 IImageList_Release(imgl2
);
1658 IImageList_Release(imgl1
);
1661 static void test_IImageList_Add_Remove(void)
1673 /* create an imagelist to play with */
1674 himl
= ImageList_Create(84, 84, ILC_COLOR16
, 0, 3);
1675 ok(himl
!= 0,"failed to create imagelist\n");
1677 imgl
= (IImageList
*) himl
;
1679 /* load the icons to add to the image list */
1680 hicon1
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
1681 ok(hicon1
!= 0, "no hicon1\n");
1682 hicon2
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
1683 ok(hicon2
!= 0, "no hicon2\n");
1684 hicon3
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
1685 ok(hicon3
!= 0, "no hicon3\n");
1687 /* remove when nothing exists */
1688 hr
= IImageList_Remove(imgl
, 0);
1689 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
1691 /* removing everything from an empty imagelist should succeed */
1692 hr
= IImageList_Remove(imgl
, -1);
1693 ok(hr
== S_OK
, "removed nonexistent icon\n");
1697 ok( IImageList_ReplaceIcon(imgl
, -1, hicon1
, &ret
) == S_OK
&& (ret
== 0),"failed to add icon1\n");
1699 ok( IImageList_ReplaceIcon(imgl
, -1, hicon2
, &ret
) == S_OK
&& (ret
== 1),"failed to add icon2\n");
1701 ok( IImageList_ReplaceIcon(imgl
, -1, hicon3
, &ret
) == S_OK
&& (ret
== 2),"failed to add icon3\n");
1703 /* remove an index out of range */
1704 ok( IImageList_Remove(imgl
, 4711) == E_INVALIDARG
, "got 0x%08x\n", hr
);
1707 ok( IImageList_Remove(imgl
,0) == S_OK
, "can't remove 0\n");
1708 ok( IImageList_Remove(imgl
,0) == S_OK
, "can't remove 0\n");
1709 ok( IImageList_Remove(imgl
,0) == S_OK
, "can't remove 0\n");
1711 /* remove one extra */
1712 ok( IImageList_Remove(imgl
, 0) == E_INVALIDARG
, "got 0x%08x\n", hr
);
1714 IImageList_Release(imgl
);
1715 ok(DestroyIcon(hicon1
),"icon 1 wasn't deleted\n");
1716 ok(DestroyIcon(hicon2
),"icon 2 wasn't deleted\n");
1717 ok(DestroyIcon(hicon3
),"icon 3 wasn't deleted\n");
1720 static void test_IImageList_Get_SetImageCount(void)
1727 /* create an imagelist to play with */
1728 himl
= ImageList_Create(84, 84, ILC_COLOR16
, 0, 3);
1729 ok(himl
!= 0,"failed to create imagelist\n");
1731 imgl
= (IImageList
*) himl
;
1733 /* check SetImageCount/GetImageCount */
1734 hr
= IImageList_SetImageCount(imgl
, 3);
1735 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1737 hr
= IImageList_GetImageCount(imgl
, &ret
);
1738 ok(hr
== S_OK
&& ret
== 3, "invalid image count after increase\n");
1739 hr
= IImageList_SetImageCount(imgl
, 1);
1740 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1742 hr
= IImageList_GetImageCount(imgl
, &ret
);
1743 ok(hr
== S_OK
&& ret
== 1, "invalid image count after decrease to 1\n");
1744 hr
= IImageList_SetImageCount(imgl
, 0);
1745 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1747 hr
= IImageList_GetImageCount(imgl
, &ret
);
1748 ok(hr
== S_OK
&& ret
== 0, "invalid image count after decrease to 0\n");
1750 IImageList_Release(imgl
);
1753 static void test_IImageList_Draw(void)
1762 IMAGELISTDRAWPARAMS imldp
;
1768 hwndfortest
= create_a_window();
1769 hdc
= GetDC(hwndfortest
);
1770 ok(hdc
!=NULL
, "couldn't get DC\n");
1772 /* create an imagelist to play with */
1773 himl
= ImageList_Create(48, 48, ILC_COLOR16
, 0, 3);
1774 ok(himl
!=0,"failed to create imagelist\n");
1776 imgl
= (IImageList
*) himl
;
1778 /* load the icons to add to the image list */
1779 hbm1
= CreateBitmap(48, 48, 1, 1, bitmap_bits
);
1780 ok(hbm1
!= 0, "no bitmap 1\n");
1781 hbm2
= CreateBitmap(48, 48, 1, 1, bitmap_bits
);
1782 ok(hbm2
!= 0, "no bitmap 2\n");
1783 hbm3
= CreateBitmap(48, 48, 1, 1, bitmap_bits
);
1784 ok(hbm3
!= 0, "no bitmap 3\n");
1788 ok( IImageList_Add(imgl
, hbm1
, 0, &ret
) == S_OK
&& (ret
== 0), "failed to add bitmap 1\n");
1790 ok( IImageList_Add(imgl
, hbm2
, 0, &ret
) == S_OK
&& (ret
== 1), "failed to add bitmap 2\n");
1792 ok( IImageList_SetImageCount(imgl
, 3) == S_OK
, "Setimage count failed\n");
1793 ok( IImageList_Replace(imgl
, 2, hbm3
, 0) == S_OK
, "failed to replace bitmap 3\n");
1797 /* crashes on native */
1798 IImageList_Draw(imgl
, NULL
);
1801 memset(&imldp
, 0, sizeof (imldp
));
1802 hr
= IImageList_Draw(imgl
, &imldp
);
1803 ok( hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
1805 imldp
.cbSize
= IMAGELISTDRAWPARAMS_V3_SIZE
;
1809 force_redraw(hwndfortest
);
1811 imldp
.fStyle
= SRCCOPY
;
1812 imldp
.rgbBk
= CLR_DEFAULT
;
1813 imldp
.rgbFg
= CLR_DEFAULT
;
1816 ok( IImageList_Draw(imgl
, &imldp
) == S_OK
, "should succeed\n");
1818 ok( IImageList_Draw(imgl
, &imldp
) == S_OK
, "should succeed\n");
1820 ok( IImageList_Draw(imgl
, &imldp
) == S_OK
, "should succeed\n");
1822 ok( IImageList_Draw(imgl
, &imldp
) == E_INVALIDARG
, "should fail\n");
1825 ok( IImageList_Remove(imgl
, 0) == S_OK
, "removing 1st bitmap\n");
1826 ok( IImageList_Remove(imgl
, 0) == S_OK
, "removing 2nd bitmap\n");
1827 ok( IImageList_Remove(imgl
, 0) == S_OK
, "removing 3rd bitmap\n");
1830 IImageList_Release(imgl
);
1832 /* bitmaps should not be deleted by the imagelist */
1833 ok(DeleteObject(hbm1
),"bitmap 1 can't be deleted\n");
1834 ok(DeleteObject(hbm2
),"bitmap 2 can't be deleted\n");
1835 ok(DeleteObject(hbm3
),"bitmap 3 can't be deleted\n");
1837 ReleaseDC(hwndfortest
, hdc
);
1838 DestroyWindow(hwndfortest
);
1841 static void test_IImageList_Merge(void)
1843 HIMAGELIST himl1
, himl2
;
1844 IImageList
*imgl1
, *imgl2
, *merge
;
1846 HWND hwnd
= create_a_window();
1850 himl1
= ImageList_Create(32,32,0,0,3);
1851 ok(himl1
!= NULL
,"failed to create himl1\n");
1853 himl2
= ImageList_Create(32,32,0,0,3);
1854 ok(himl2
!= NULL
,"failed to create himl2\n");
1856 hicon1
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
1857 ok(hicon1
!= NULL
, "failed to create hicon1\n");
1859 if (!himl1
|| !himl2
|| !hicon1
)
1862 /* cast to IImageList */
1863 imgl1
= (IImageList
*) himl1
;
1864 imgl2
= (IImageList
*) himl2
;
1867 ok( IImageList_ReplaceIcon(imgl2
, -1, hicon1
, &ret
) == S_OK
&& (ret
== 0),"add icon1 to himl2 failed\n");
1871 /* null cases that crash on native */
1872 IImageList_Merge(imgl1
, -1, NULL
, 0, 0, 0, &IID_IImageList
, (void**)&merge
);
1873 IImageList_Merge(imgl1
, -1, (IUnknown
*) imgl2
, 0, 0, 0, &IID_IImageList
, NULL
);
1876 /* If himl1 has no images, merge still succeeds */
1877 hr
= IImageList_Merge(imgl1
, -1, (IUnknown
*) imgl2
, 0, 0, 0, &IID_IImageList
, (void **) &merge
);
1878 ok(hr
== S_OK
, "merge himl1,-1 failed\n");
1879 if (hr
== S_OK
) IImageList_Release(merge
);
1881 hr
= IImageList_Merge(imgl1
, 0, (IUnknown
*) imgl2
, 0, 0, 0, &IID_IImageList
, (void **) &merge
);
1882 ok(hr
== S_OK
, "merge himl1,0 failed\n");
1883 if (hr
== S_OK
) IImageList_Release(merge
);
1885 /* Same happens if himl2 is empty */
1886 IImageList_Release(imgl2
);
1887 himl2
= ImageList_Create(32,32,0,0,3);
1888 ok(himl2
!= NULL
,"failed to recreate himl2\n");
1890 imgl2
= (IImageList
*) himl2
;
1892 hr
= IImageList_Merge(imgl1
, -1, (IUnknown
*) imgl2
, -1, 0, 0, &IID_IImageList
, (void **) &merge
);
1893 ok(hr
== S_OK
, "merge himl2,-1 failed\n");
1894 if (hr
== S_OK
) IImageList_Release(merge
);
1896 hr
= IImageList_Merge(imgl1
, -1, (IUnknown
*) imgl2
, 0, 0, 0, &IID_IImageList
, (void **) &merge
);
1897 ok(hr
== S_OK
, "merge himl2,0 failed\n");
1898 if (hr
== S_OK
) IImageList_Release(merge
);
1900 /* Now try merging an image with itself */
1902 ok( IImageList_ReplaceIcon(imgl2
, -1, hicon1
, &ret
) == S_OK
&& (ret
== 0),"re-add icon1 to himl2 failed\n");
1904 hr
= IImageList_Merge(imgl2
, 0, (IUnknown
*) imgl2
, 0, 0, 0, &IID_IImageList
, (void **) &merge
);
1905 ok(hr
== S_OK
, "merge himl2 with itself failed\n");
1906 if (hr
== S_OK
) IImageList_Release(merge
);
1908 /* Try merging 2 different image lists */
1910 ok( IImageList_ReplaceIcon(imgl1
, -1, hicon1
, &ret
) == S_OK
&& (ret
== 0),"add icon1 to himl1 failed\n");
1912 hr
= IImageList_Merge(imgl1
, 0, (IUnknown
*) imgl2
, 0, 0, 0, &IID_IImageList
, (void **) &merge
);
1913 ok(hr
== S_OK
, "merge himl1 with himl2 failed\n");
1914 if (hr
== S_OK
) IImageList_Release(merge
);
1916 hr
= IImageList_Merge(imgl1
, 0, (IUnknown
*) imgl2
, 0, 8, 16, &IID_IImageList
, (void **) &merge
);
1917 ok(hr
== S_OK
, "merge himl1 with himl2 8,16 failed\n");
1918 if (hr
== S_OK
) IImageList_Release(merge
);
1920 IImageList_Release(imgl1
);
1921 IImageList_Release(imgl2
);
1923 DestroyIcon(hicon1
);
1924 DestroyWindow(hwnd
);
1927 static void test_iconsize(void)
1933 himl
= ImageList_Create(16, 16, ILC_COLOR16
, 0, 3);
1934 /* null pointers, not zero imagelist dimensions */
1935 ret
= ImageList_GetIconSize(himl
, NULL
, NULL
);
1936 ok(!ret
, "got %d\n", ret
);
1938 /* doesn't touch return pointers */
1940 ret
= ImageList_GetIconSize(himl
, &cx
, NULL
);
1941 ok(!ret
, "got %d\n", ret
);
1942 ok(cx
== 0x1abe11ed, "got %d\n", cx
);
1945 ret
= ImageList_GetIconSize(himl
, NULL
, &cy
);
1946 ok(!ret
, "got %d\n", ret
);
1947 ok(cy
== 0x1abe11ed, "got %d\n", cy
);
1949 ImageList_Destroy(himl
);
1951 ret
= ImageList_GetIconSize((HIMAGELIST
)0xdeadbeef, &cx
, &cy
);
1952 ok(!ret
, "got %d\n", ret
);
1955 static void test_create_destroy(void)
1964 /* list with zero or negative image dimensions */
1965 himl
= ImageList_Create(0, 0, ILC_COLOR16
, 0, 3);
1966 ok(himl
== NULL
, "got %p\n", himl
);
1968 himl
= ImageList_Create(0, 16, ILC_COLOR16
, 0, 3);
1969 ok(himl
== NULL
, "got %p\n", himl
);
1971 himl
= ImageList_Create(16, 0, ILC_COLOR16
, 0, 3);
1972 ok(himl
== NULL
, "got %p\n", himl
);
1974 himl
= ImageList_Create(16, -1, ILC_COLOR16
, 0, 3);
1975 ok(himl
== NULL
, "got %p\n", himl
);
1977 himl
= ImageList_Create(-1, 16, ILC_COLOR16
, 0, 3);
1978 ok(himl
== NULL
, "got %p\n", himl
);
1980 rc
= ImageList_Destroy((HIMAGELIST
)0xdeadbeef);
1981 ok(rc
== FALSE
, "ImageList_Destroy(0xdeadbeef) should fail and not crash\n");
1983 /* DDB image lists */
1984 himl
= ImageList_Create(0, 14, ILC_COLORDDB
, 4, 4);
1985 ok(himl
!= NULL
, "got %p\n", himl
);
1986 imgl
= (IImageList
*)himl
;
1987 IImageList_GetIconSize(imgl
, &cx
, &cy
);
1988 ok (cx
== 0, "Wrong cx (%i)\n", cx
);
1989 ok (cy
== 14, "Wrong cy (%i)\n", cy
);
1990 ImageList_Destroy(himl
);
1992 himl
= ImageList_Create(0, 0, ILC_COLORDDB
, 4, 4);
1993 ok(himl
!= NULL
, "got %p\n", himl
);
1994 imgl
= (IImageList
*)himl
;
1995 IImageList_GetIconSize(imgl
, &cx
, &cy
);
1996 ok (cx
== 0, "Wrong cx (%i)\n", cx
);
1997 ok (cy
== 0, "Wrong cy (%i)\n", cy
);
1998 ImageList_Destroy(himl
);
2000 himl
= ImageList_Create(0, 0, ILC_COLORDDB
, 0, 4);
2001 ok(himl
!= NULL
, "got %p\n", himl
);
2002 imgl
= (IImageList
*)himl
;
2003 IImageList_GetIconSize(imgl
, &cx
, &cy
);
2004 ok (cx
== 0, "Wrong cx (%i)\n", cx
);
2005 ok (cy
== 0, "Wrong cy (%i)\n", cy
);
2007 hr
= IImageList_SetImageCount(imgl
, 3);
2008 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2009 hr
= IImageList_GetImageCount(imgl
, &ret
);
2010 ok(hr
== S_OK
&& ret
== 3, "invalid image count after increase\n");
2012 /* Trying to actually add an image causes a crash on Windows */
2013 ImageList_Destroy(himl
);
2015 /* Negative values fail */
2016 himl
= ImageList_Create(-1, -1, ILC_COLORDDB
, 4, 4);
2017 ok(himl
== NULL
, "got %p\n", himl
);
2018 himl
= ImageList_Create(-1, 1, ILC_COLORDDB
, 4, 4);
2019 ok(himl
== NULL
, "got %p\n", himl
);
2020 himl
= ImageList_Create(1, -1, ILC_COLORDDB
, 4, 4);
2021 ok(himl
== NULL
, "got %p\n", himl
);
2024 static void check_color_table(const char *name
, HDC hdc
, HIMAGELIST himl
, UINT ilc
,
2025 RGBQUAD
*expect
, RGBQUAD
*broken_expect
)
2029 char bmi_buffer
[FIELD_OFFSET(BITMAPINFO
, bmiColors
) + 256 * sizeof(RGBQUAD
)];
2030 BITMAPINFO
*bmi
= (BITMAPINFO
*)bmi_buffer
;
2031 int i
, depth
= ilc
& 0xfe;
2033 ret
= ImageList_GetImageInfo(himl
, 0, &info
);
2034 ok(ret
, "got %d\n", ret
);
2035 ok(info
.hbmImage
!= NULL
, "got %p\n", info
.hbmImage
);
2037 memset(bmi_buffer
, 0, sizeof(bmi_buffer
));
2038 bmi
->bmiHeader
.biSize
= sizeof(bmi
->bmiHeader
);
2039 ret
= GetDIBits(hdc
, info
.hbmImage
, 0, 0, NULL
, bmi
, DIB_RGB_COLORS
);
2040 ok(ret
, "got %d\n", ret
);
2041 ok(bmi
->bmiHeader
.biBitCount
== depth
, "got %d\n", bmi
->bmiHeader
.biBitCount
);
2043 ret
= GetDIBits(hdc
, info
.hbmImage
, 0, 0, NULL
, bmi
, DIB_RGB_COLORS
);
2044 ok(ret
, "got %d\n", ret
);
2045 ok(bmi
->bmiHeader
.biBitCount
== depth
, "got %d\n", bmi
->bmiHeader
.biBitCount
);
2047 for (i
= 0; i
< (1 << depth
); i
++)
2048 ok((bmi
->bmiColors
[i
].rgbRed
== expect
[i
].rgbRed
&&
2049 bmi
->bmiColors
[i
].rgbGreen
== expect
[i
].rgbGreen
&&
2050 bmi
->bmiColors
[i
].rgbBlue
== expect
[i
].rgbBlue
) ||
2051 broken(bmi
->bmiColors
[i
].rgbRed
== broken_expect
[i
].rgbRed
&&
2052 bmi
->bmiColors
[i
].rgbGreen
== broken_expect
[i
].rgbGreen
&&
2053 bmi
->bmiColors
[i
].rgbBlue
== broken_expect
[i
].rgbBlue
),
2054 "%d: %s: got color[%d] %02x %02x %02x expect %02x %02x %02x\n", depth
, name
, i
,
2055 bmi
->bmiColors
[i
].rgbRed
, bmi
->bmiColors
[i
].rgbGreen
, bmi
->bmiColors
[i
].rgbBlue
,
2056 expect
[i
].rgbRed
, expect
[i
].rgbGreen
, expect
[i
].rgbBlue
);
2059 static void get_default_color_table(HDC hdc
, int bpp
, RGBQUAD
*table
)
2061 char bmi_buffer
[FIELD_OFFSET(BITMAPINFO
, bmiColors
) + 256 * sizeof(RGBQUAD
)];
2062 BITMAPINFO
*bmi
= (BITMAPINFO
*)bmi_buffer
;
2066 PALETTEENTRY entries
[256];
2071 tmp
= CreateBitmap( 1, 1, 1, 1, NULL
);
2072 memset(bmi_buffer
, 0, sizeof(bmi_buffer
));
2073 bmi
->bmiHeader
.biSize
= sizeof(bmi
->bmiHeader
);
2074 bmi
->bmiHeader
.biHeight
= 1;
2075 bmi
->bmiHeader
.biWidth
= 1;
2076 bmi
->bmiHeader
.biBitCount
= bpp
;
2077 bmi
->bmiHeader
.biPlanes
= 1;
2078 bmi
->bmiHeader
.biCompression
= BI_RGB
;
2079 GetDIBits( hdc
, tmp
, 0, 0, NULL
, bmi
, DIB_RGB_COLORS
);
2081 memcpy(table
, bmi
->bmiColors
, (1 << bpp
) * sizeof(RGBQUAD
));
2082 table
[7] = bmi
->bmiColors
[8];
2083 table
[8] = bmi
->bmiColors
[7];
2084 DeleteObject( tmp
);
2088 pal
= CreateHalftonePalette(hdc
);
2089 GetPaletteEntries(pal
, 0, 256, entries
);
2090 for (i
= 0; i
< 256; i
++)
2092 table
[i
].rgbRed
= entries
[i
].peRed
;
2093 table
[i
].rgbGreen
= entries
[i
].peGreen
;
2094 table
[i
].rgbBlue
= entries
[i
].peBlue
;
2095 table
[i
].rgbReserved
= 0;
2101 ok(0, "unhandled depth %d\n", bpp
);
2105 static void test_color_table(UINT ilc
)
2109 char bmi_buffer
[FIELD_OFFSET(BITMAPINFO
, bmiColors
) + 256 * sizeof(RGBQUAD
)];
2110 BITMAPINFO
*bmi
= (BITMAPINFO
*)bmi_buffer
;
2111 HDC hdc
= CreateCompatibleDC(0);
2112 HBITMAP dib4
, dib8
, dib32
;
2113 RGBQUAD rgb
[256], default_table
[256];
2115 get_default_color_table(hdc
, ilc
& 0xfe, default_table
);
2117 himl
= ImageList_Create(16, 16, ilc
, 0, 3);
2118 ok(himl
!= NULL
, "got %p\n", himl
);
2120 memset(bmi_buffer
, 0, sizeof(bmi_buffer
));
2121 bmi
->bmiHeader
.biSize
= sizeof(bmi
->bmiHeader
);
2122 bmi
->bmiHeader
.biHeight
= 16;
2123 bmi
->bmiHeader
.biWidth
= 16;
2124 bmi
->bmiHeader
.biBitCount
= 8;
2125 bmi
->bmiHeader
.biPlanes
= 1;
2126 bmi
->bmiHeader
.biCompression
= BI_RGB
;
2127 bmi
->bmiColors
[0].rgbRed
= 0xff;
2128 bmi
->bmiColors
[1].rgbGreen
= 0xff;
2129 bmi
->bmiColors
[2].rgbBlue
= 0xff;
2131 dib8
= CreateDIBSection(hdc
, bmi
, DIB_RGB_COLORS
, NULL
, NULL
, 0);
2133 bmi
->bmiHeader
.biBitCount
= 4;
2134 bmi
->bmiColors
[0].rgbRed
= 0xff;
2135 bmi
->bmiColors
[0].rgbGreen
= 0x00;
2136 bmi
->bmiColors
[0].rgbBlue
= 0xff;
2137 bmi
->bmiColors
[1].rgbRed
= 0xff;
2138 bmi
->bmiColors
[1].rgbGreen
= 0xff;
2139 bmi
->bmiColors
[1].rgbBlue
= 0x00;
2140 bmi
->bmiColors
[2].rgbRed
= 0x00;
2141 bmi
->bmiColors
[2].rgbGreen
= 0xff;
2142 bmi
->bmiColors
[2].rgbBlue
= 0xff;
2144 dib4
= CreateDIBSection(hdc
, bmi
, DIB_RGB_COLORS
, NULL
, NULL
, 0);
2146 bmi
->bmiHeader
.biBitCount
= 32;
2148 dib32
= CreateDIBSection(hdc
, bmi
, DIB_RGB_COLORS
, NULL
, NULL
, 0);
2150 /* add 32 first then 8. This won't set the color table */
2151 ret
= ImageList_Add(himl
, dib32
, NULL
);
2152 ok(ret
== 0, "got %d\n", ret
);
2153 ret
= ImageList_Add(himl
, dib8
, NULL
);
2154 ok(ret
== 1, "got %d\n", ret
);
2156 check_color_table("add 32, 8", hdc
, himl
, ilc
, default_table
, NULL
);
2158 /* since the previous _Adds didn't set the color table, this one will */
2159 ret
= ImageList_Remove(himl
, -1);
2160 ok(ret
, "got %d\n", ret
);
2161 ret
= ImageList_Add(himl
, dib8
, NULL
);
2162 ok(ret
== 0, "got %d\n", ret
);
2164 memset(rgb
, 0, sizeof(rgb
));
2165 rgb
[0].rgbRed
= 0xff;
2166 rgb
[1].rgbGreen
= 0xff;
2167 rgb
[2].rgbBlue
= 0xff;
2168 check_color_table("remove all, add 8", hdc
, himl
, ilc
, rgb
, default_table
);
2170 /* remove all, add 4. Color table remains the same since it's inplicitly
2171 been set by the previous _Add */
2172 ret
= ImageList_Remove(himl
, -1);
2173 ok(ret
, "got %d\n", ret
);
2174 ret
= ImageList_Add(himl
, dib4
, NULL
);
2175 ok(ret
== 0, "got %d\n", ret
);
2176 check_color_table("remove all, add 4", hdc
, himl
, ilc
, rgb
, default_table
);
2178 ImageList_Destroy(himl
);
2179 himl
= ImageList_Create(16, 16, ilc
, 0, 3);
2180 ok(himl
!= NULL
, "got %p\n", himl
);
2183 ret
= ImageList_Add(himl
, dib4
, NULL
);
2184 ok(ret
== 0, "got %d\n", ret
);
2186 memset(rgb
, 0, 16 * sizeof(rgb
[0]));
2187 rgb
[0].rgbRed
= 0xff;
2188 rgb
[0].rgbBlue
= 0xff;
2189 rgb
[1].rgbRed
= 0xff;
2190 rgb
[1].rgbGreen
= 0xff;
2191 rgb
[2].rgbGreen
= 0xff;
2192 rgb
[2].rgbBlue
= 0xff;
2193 memcpy(rgb
+ 16, default_table
+ 16, 240 * sizeof(rgb
[0]));
2195 check_color_table("add 4", hdc
, himl
, ilc
, rgb
, default_table
);
2197 ImageList_Destroy(himl
);
2198 himl
= ImageList_Create(16, 16, ilc
, 0, 3);
2199 ok(himl
!= NULL
, "got %p\n", himl
);
2201 /* set color table, add 8 */
2202 ret
= ImageList_Remove(himl
, -1);
2203 ok(ret
, "got %d\n", ret
);
2204 memset(rgb
, 0, sizeof(rgb
));
2205 rgb
[0].rgbRed
= 0xcc;
2206 rgb
[1].rgbBlue
= 0xcc;
2207 ret
= pImageList_SetColorTable(himl
, 0, 2, rgb
);
2208 ok(ret
== 2, "got %d\n", ret
);
2209 /* the table is set, so this doesn't change it */
2210 ret
= ImageList_Add(himl
, dib8
, NULL
);
2211 ok(ret
== 0, "got %d\n", ret
);
2213 memcpy(rgb
+ 2, default_table
+ 2, 254 * sizeof(rgb
[0]));
2214 check_color_table("SetColorTable", hdc
, himl
, ilc
, rgb
, NULL
);
2216 DeleteObject(dib32
);
2220 ImageList_Destroy(himl
);
2223 static void test_IImageList_Clone(void)
2225 IImageList
*imgl
, *imgl2
;
2230 himl
= ImageList_Create(16, 16, ILC_COLOR16
, 0, 3);
2231 imgl
= (IImageList
*)himl
;
2235 /* crashes on native */
2236 IImageList_Clone(imgl
, &IID_IImageList
, NULL
);
2239 hr
= IImageList_Clone(imgl
, &IID_IImageList
, (void**)&imgl2
);
2240 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2241 ref
= IImageList_Release(imgl2
);
2242 ok(ref
== 0, "got %u\n", ref
);
2244 IImageList_Release(imgl
);
2247 static void test_IImageList_GetBkColor(void)
2254 himl
= ImageList_Create(16, 16, ILC_COLOR16
, 0, 3);
2255 imgl
= (IImageList
*)himl
;
2259 /* crashes on native */
2260 IImageList_GetBkColor(imgl
, NULL
);
2263 hr
= IImageList_GetBkColor(imgl
, &color
);
2264 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2266 IImageList_Release(imgl
);
2269 static void test_IImageList_SetBkColor(void)
2276 himl
= ImageList_Create(16, 16, ILC_COLOR16
, 0, 3);
2277 imgl
= (IImageList
*)himl
;
2281 /* crashes on native */
2282 IImageList_SetBkColor(imgl
, RGB(0, 0, 0), NULL
);
2285 hr
= IImageList_SetBkColor(imgl
, CLR_NONE
, &color
);
2286 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2288 hr
= IImageList_SetBkColor(imgl
, CLR_NONE
, &color
);
2289 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2292 hr
= IImageList_GetBkColor(imgl
, &color
);
2293 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2294 ok(color
== CLR_NONE
, "got %x\n", color
);
2296 IImageList_Release(imgl
);
2299 static void test_IImageList_GetImageCount(void)
2306 himl
= ImageList_Create(16, 16, ILC_COLOR16
, 0, 3);
2307 imgl
= (IImageList
*)himl
;
2311 /* crashes on native */
2312 IImageList_GetImageCount(imgl
, NULL
);
2316 hr
= IImageList_GetImageCount(imgl
, &count
);
2317 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2318 ok(count
== 0, "got %d\n", count
);
2320 IImageList_Release(imgl
);
2323 static void test_IImageList_GetIconSize(void)
2330 himl
= ImageList_Create(16, 16, ILC_COLOR16
, 0, 3);
2331 imgl
= (IImageList
*)himl
;
2333 hr
= IImageList_GetIconSize(imgl
, NULL
, NULL
);
2334 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
2336 hr
= IImageList_GetIconSize(imgl
, &cx
, NULL
);
2337 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
2339 hr
= IImageList_GetIconSize(imgl
, NULL
, &cy
);
2340 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
2342 IImageList_Release(imgl
);
2345 START_TEST(imagelist
)
2347 ULONG_PTR ctx_cookie
;
2350 HMODULE hComCtl32
= GetModuleHandleA("comctl32.dll");
2351 pImageList_Create
= NULL
; /* These are not needed for non-v6.0 tests*/
2352 pImageList_Add
= NULL
;
2353 pImageList_DrawIndirect
= (void*)GetProcAddress(hComCtl32
, "ImageList_DrawIndirect");
2354 pImageList_SetImageCount
= (void*)GetProcAddress(hComCtl32
, "ImageList_SetImageCount");
2355 pImageList_SetColorTable
= (void*)GetProcAddress(hComCtl32
, (const char*)390);
2357 hinst
= GetModuleHandleA(NULL
);
2359 InitCommonControls();
2361 test_create_destroy();
2366 test_DrawIndirect();
2368 test_merge_colors();
2369 test_imagelist_storage();
2371 test_color_table(ILC_COLOR4
);
2372 test_color_table(ILC_COLOR8
);
2374 FreeLibrary(hComCtl32
);
2376 /* Now perform v6 tests */
2378 if (!load_v6_module(&ctx_cookie
, &hCtx
))
2381 /* Reload comctl32 */
2382 hComCtl32
= LoadLibraryA("comctl32.dll");
2383 pImageList_Create
= (void*)GetProcAddress(hComCtl32
, "ImageList_Create");
2384 pImageList_Add
= (void*)GetProcAddress(hComCtl32
, "ImageList_Add");
2385 pImageList_DrawIndirect
= (void*)GetProcAddress(hComCtl32
, "ImageList_DrawIndirect");
2386 pImageList_SetImageCount
= (void*)GetProcAddress(hComCtl32
, "ImageList_SetImageCount");
2387 pImageList_CoCreateInstance
= (void*)GetProcAddress(hComCtl32
, "ImageList_CoCreateInstance");
2388 pHIMAGELIST_QueryInterface
= (void*)GetProcAddress(hComCtl32
, "HIMAGELIST_QueryInterface");
2390 CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
2393 test_ImageList_DrawIndirect();
2394 test_shell_imagelist();
2398 test_IImageList_Add_Remove();
2399 test_IImageList_Get_SetImageCount();
2400 test_IImageList_Draw();
2401 test_IImageList_Merge();
2402 test_IImageList_Clone();
2403 test_IImageList_GetBkColor();
2404 test_IImageList_SetBkColor();
2405 test_IImageList_GetImageCount();
2406 test_IImageList_GetIconSize();
2410 unload_v6_module(ctx_cookie
, hCtx
);