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 ret
= ImageList_GetImageCount(himl
);
926 ok(ret
== cur
, "%s: expected image count %d got %d\n", comment
, cur
, ret
);
928 ret
= ImageList_GetIconSize(himl
, &cxx
, &cyy
);
929 ok(ret
, "ImageList_GetIconSize failed\n");
930 ok(cxx
== cx
, "%s: wrong cx %d (expected %d)\n", comment
, cxx
, cx
);
931 ok(cyy
== cy
, "%s: wrong cy %d (expected %d)\n", comment
, cyy
, cy
);
933 init_memstream(&stream
);
934 ret
= ImageList_Write(himl
, &stream
.IStream_iface
);
935 ok(ret
, "%s: ImageList_Write failed\n", comment
);
937 hr
= GetHGlobalFromStream(stream
.stream
, &hglobal
);
938 ok(hr
== S_OK
, "%s: Failed to get hglobal, %#x\n", comment
, hr
);
940 IStream_Stat(stream
.stream
, &stat
, STATFLAG_NONAME
);
942 data
= GlobalLock(hglobal
);
944 ok(data
!= 0, "%s: ImageList_Write didn't write any data\n", comment
);
945 ok(stat
.cbSize
.LowPart
> sizeof(ILHEAD
), "%s: ImageList_Write wrote not enough data\n", comment
);
947 check_ilhead_data(data
, cx
, cy
, cur
, max
, grow
, flags
);
948 size
= check_bitmap_data(data
+ sizeof(ILHEAD
), stat
.cbSize
.LowPart
- sizeof(ILHEAD
),
949 width
, height
, flags
& 0xfe, comment
);
950 if (size
< stat
.cbSize
.LowPart
- sizeof(ILHEAD
)) /* mask is present */
952 ok( flags
& ILC_MASK
, "%s: extra data %u/%u but mask not expected\n", comment
, stat
.cbSize
.LowPart
, size
);
953 check_bitmap_data(data
+ sizeof(ILHEAD
) + size
, stat
.cbSize
.LowPart
- sizeof(ILHEAD
) - size
,
954 width
, height
, 1, comment
);
957 /* rewind and reconstruct from stream */
959 IStream_Seek(stream
.stream
, mv
, STREAM_SEEK_SET
, NULL
);
960 himl2
= ImageList_Read(&stream
.IStream_iface
);
961 ok(himl2
!= NULL
, "%s: Failed to deserialize imagelist\n", comment
);
962 ImageList_Destroy(himl2
);
964 GlobalUnlock(hglobal
);
965 cleanup_memstream(&stream
);
968 static void image_list_init(HIMAGELIST himl
)
974 static const struct test_data
977 INT cx
, cy
, cur
, max
, grow
, width
, height
, bpp
;
981 { 255, BMP_CX
, BMP_CX
, 1, 2, 4, BMP_CX
* 4, BMP_CX
* 1, 24, "total 1" },
982 { 170, BMP_CX
, BMP_CX
, 2, 7, 4, BMP_CX
* 4, BMP_CX
* 2, 24, "total 2" },
983 { 85, BMP_CX
, BMP_CX
, 3, 7, 4, BMP_CX
* 4, BMP_CX
* 2, 24, "total 3" },
984 { 0, BMP_CX
, BMP_CX
, 4, 7, 4, BMP_CX
* 4, BMP_CX
* 2, 24, "total 4" },
985 { 0, BMP_CX
, BMP_CX
, 5, 7, 4, BMP_CX
* 4, BMP_CX
* 2, 24, "total 5" },
986 { 85, BMP_CX
, BMP_CX
, 6, 7, 4, BMP_CX
* 4, BMP_CX
* 2, 24, "total 6" },
987 { 170, BMP_CX
, BMP_CX
, 7, 12, 4, BMP_CX
* 4, BMP_CX
* 3, 24, "total 7" },
988 { 255, BMP_CX
, BMP_CX
, 8, 12, 4, BMP_CX
* 4, BMP_CX
* 3, 24, "total 8" },
989 { 255, BMP_CX
, BMP_CX
, 9, 12, 4, BMP_CX
* 4, BMP_CX
* 3, 24, "total 9" },
990 { 170, BMP_CX
, BMP_CX
, 10, 12, 4, BMP_CX
* 4, BMP_CX
* 3, 24, "total 10" },
991 { 85, BMP_CX
, BMP_CX
, 11, 12, 4, BMP_CX
* 4, BMP_CX
* 3, 24, "total 11" },
992 { 0, BMP_CX
, BMP_CX
, 12, 17, 4, BMP_CX
* 4, BMP_CX
* 5, 24, "total 12" },
993 { 0, BMP_CX
, BMP_CX
, 13, 17, 4, BMP_CX
* 4, BMP_CX
* 5, 24, "total 13" },
994 { 85, BMP_CX
, BMP_CX
, 14, 17, 4, BMP_CX
* 4, BMP_CX
* 5, 24, "total 14" },
995 { 170, BMP_CX
, BMP_CX
, 15, 17, 4, BMP_CX
* 4, BMP_CX
* 5, 24, "total 15" },
996 { 255, BMP_CX
, BMP_CX
, 16, 17, 4, BMP_CX
* 4, BMP_CX
* 5, 24, "total 16" },
997 { 255, BMP_CX
, BMP_CX
, 17, 22, 4, BMP_CX
* 4, BMP_CX
* 6, 24, "total 17" },
998 { 170, BMP_CX
, BMP_CX
, 18, 22, 4, BMP_CX
* 4, BMP_CX
* 6, 24, "total 18" },
999 { 85, BMP_CX
, BMP_CX
, 19, 22, 4, BMP_CX
* 4, BMP_CX
* 6, 24, "total 19" },
1000 { 0, BMP_CX
, BMP_CX
, 20, 22, 4, BMP_CX
* 4, BMP_CX
* 6, 24, "total 20" },
1001 { 0, BMP_CX
, BMP_CX
, 21, 22, 4, BMP_CX
* 4, BMP_CX
* 6, 24, "total 21" },
1002 { 85, BMP_CX
, BMP_CX
, 22, 27, 4, BMP_CX
* 4, BMP_CX
* 7, 24, "total 22" },
1003 { 170, BMP_CX
, BMP_CX
, 23, 27, 4, BMP_CX
* 4, BMP_CX
* 7, 24, "total 23" },
1004 { 255, BMP_CX
, BMP_CX
, 24, 27, 4, BMP_CX
* 4, BMP_CX
* 7, 24, "total 24" }
1007 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 2, 4, BMP_CX
* 4, BMP_CX
* 1, ILC_COLOR24
, "total 0");
1009 #define add_bitmap(grey) \
1010 sprintf(comment, "%d", n++); \
1011 hbm = create_bitmap(BMP_CX, BMP_CX, RGB((grey),(grey),(grey)), comment); \
1012 ImageList_Add(himl, hbm, NULL); \
1015 for (i
= 0; i
< sizeof(td
)/sizeof(td
[0]); i
++)
1017 add_bitmap(td
[i
].grey
);
1018 check_iml_data(himl
, td
[i
].cx
, td
[i
].cy
, td
[i
].cur
, td
[i
].max
, td
[i
].grow
,
1019 td
[i
].width
, td
[i
].height
, td
[i
].bpp
, td
[i
].comment
);
1024 static void test_imagelist_storage(void)
1031 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR24
, 1, 1);
1032 ok(himl
!= 0, "ImageList_Create failed\n");
1034 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 2, 4, BMP_CX
* 4, BMP_CX
* 1, ILC_COLOR24
, "empty");
1036 image_list_init(himl
);
1037 check_iml_data(himl
, BMP_CX
, BMP_CX
, 24, 27, 4, BMP_CX
* 4, BMP_CX
* 7, ILC_COLOR24
, "orig");
1039 ret
= ImageList_Remove(himl
, 4);
1040 ok(ret
, "ImageList_Remove failed\n");
1041 check_iml_data(himl
, BMP_CX
, BMP_CX
, 23, 27, 4, BMP_CX
* 4, BMP_CX
* 7, ILC_COLOR24
, "1");
1043 ret
= ImageList_Remove(himl
, 5);
1044 ok(ret
, "ImageList_Remove failed\n");
1045 check_iml_data(himl
, BMP_CX
, BMP_CX
, 22, 27, 4, BMP_CX
* 4, BMP_CX
* 7, ILC_COLOR24
, "2");
1047 ret
= ImageList_Remove(himl
, 6);
1048 ok(ret
, "ImageList_Remove failed\n");
1049 check_iml_data(himl
, BMP_CX
, BMP_CX
, 21, 27, 4, BMP_CX
* 4, BMP_CX
* 7, ILC_COLOR24
, "3");
1051 ret
= ImageList_Remove(himl
, 7);
1052 ok(ret
, "ImageList_Remove failed\n");
1053 check_iml_data(himl
, BMP_CX
, BMP_CX
, 20, 27, 4, BMP_CX
* 4, BMP_CX
* 7, ILC_COLOR24
, "4");
1055 ret
= ImageList_Remove(himl
, -2);
1056 ok(!ret
, "ImageList_Remove(-2) should fail\n");
1057 check_iml_data(himl
, BMP_CX
, BMP_CX
, 20, 27, 4, BMP_CX
* 4, BMP_CX
* 7, ILC_COLOR24
, "5");
1059 ret
= ImageList_Remove(himl
, 20);
1060 ok(!ret
, "ImageList_Remove(20) should fail\n");
1061 check_iml_data(himl
, BMP_CX
, BMP_CX
, 20, 27, 4, BMP_CX
* 4, BMP_CX
* 7, ILC_COLOR24
, "6");
1063 ret
= ImageList_Remove(himl
, -1);
1064 ok(ret
, "ImageList_Remove(-1) failed\n");
1065 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 4, 4, BMP_CX
* 4, BMP_CX
* 1, ILC_COLOR24
, "7");
1067 ret
= ImageList_Destroy(himl
);
1068 ok(ret
, "ImageList_Destroy failed\n");
1070 /* test ImageList_Create storage allocation */
1072 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR24
, 0, 32);
1073 ok(himl
!= 0, "ImageList_Create failed\n");
1074 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 1, 32, BMP_CX
* 4, BMP_CX
* 1, ILC_COLOR24
, "init 0 grow 32");
1075 hbm
= create_bitmap(BMP_CX
* 9, BMP_CX
, 0, "9");
1076 ret
= ImageList_Add(himl
, hbm
, NULL
);
1077 ok(ret
== 0, "ImageList_Add returned %d, expected 0\n", ret
);
1078 check_iml_data(himl
, BMP_CX
, BMP_CX
, 1, 34, 32, BMP_CX
* 4, BMP_CX
* 9, ILC_COLOR24
, "add 1 x 9");
1080 ret
= ImageList_Destroy(himl
);
1081 ok(ret
, "ImageList_Destroy failed\n");
1083 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR24
, 4, 4);
1084 ok(himl
!= 0, "ImageList_Create failed\n");
1085 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 5, 4, BMP_CX
* 4, BMP_CX
* 2, ILC_COLOR24
, "init 4 grow 4");
1086 hbm
= create_bitmap(BMP_CX
, BMP_CX
* 9, 0, "9");
1087 ret
= ImageList_Add(himl
, hbm
, NULL
);
1088 ok(ret
== 0, "ImageList_Add returned %d, expected 0\n", ret
);
1089 check_iml_data(himl
, BMP_CX
, BMP_CX
, 9, 15, 4, BMP_CX
* 4, BMP_CX
* 4, ILC_COLOR24
, "add 9 x 1");
1090 ret
= ImageList_Add(himl
, hbm
, NULL
);
1091 ok(ret
== 9, "ImageList_Add returned %d, expected 9\n", ret
);
1092 check_iml_data(himl
, BMP_CX
, BMP_CX
, 18, 25, 4, BMP_CX
* 4, BMP_CX
* 7, ILC_COLOR24
, "add 9 x 1");
1094 ret
= ImageList_Destroy(himl
);
1095 ok(ret
, "ImageList_Destroy failed\n");
1097 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR24
, 207, 209);
1098 ok(himl
!= 0, "ImageList_Create failed\n");
1099 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 208, 212, BMP_CX
* 4, BMP_CX
* 52, ILC_COLOR24
, "init 207 grow 209");
1100 ret
= ImageList_Destroy(himl
);
1101 ok(ret
, "ImageList_Destroy failed\n");
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");
1109 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR24
, 14, 4);
1110 ok(himl
!= 0, "ImageList_Create failed\n");
1111 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 15, 4, BMP_CX
* 4, BMP_CX
* 4, ILC_COLOR24
, "init 14 grow 4");
1112 ret
= ImageList_Destroy(himl
);
1113 ok(ret
, "ImageList_Destroy failed\n");
1115 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR24
, 5, 9);
1116 ok(himl
!= 0, "ImageList_Create failed\n");
1117 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 6, 12, BMP_CX
* 4, BMP_CX
* 2, ILC_COLOR24
, "init 5 grow 9");
1118 ret
= ImageList_Destroy(himl
);
1119 ok(ret
, "ImageList_Destroy failed\n");
1121 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR24
, 9, 5);
1122 ok(himl
!= 0, "ImageList_Create failed\n");
1123 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 10, 8, BMP_CX
* 4, BMP_CX
* 3, ILC_COLOR24
, "init 9 grow 5");
1124 ret
= ImageList_Destroy(himl
);
1125 ok(ret
, "ImageList_Destroy failed\n");
1127 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR24
, 2, 4);
1128 ok(himl
!= 0, "ImageList_Create failed\n");
1129 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 3, 4, BMP_CX
* 4, BMP_CX
* 1, ILC_COLOR24
, "init 2 grow 4");
1130 ret
= ImageList_Destroy(himl
);
1131 ok(ret
, "ImageList_Destroy failed\n");
1133 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR24
, 4, 2);
1134 ok(himl
!= 0, "ImageList_Create failed\n");
1135 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 5, 4, BMP_CX
* 4, BMP_CX
* 2, ILC_COLOR24
, "init 4 grow 2");
1136 ret
= ImageList_Destroy(himl
);
1137 ok(ret
, "ImageList_Destroy failed\n");
1139 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR8
, 4, 2);
1140 ok(himl
!= 0, "ImageList_Create failed\n");
1141 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 5, 4, BMP_CX
* 4, BMP_CX
* 2, ILC_COLOR8
, "bpp 8");
1142 ret
= ImageList_Destroy(himl
);
1143 ok(ret
, "ImageList_Destroy failed\n");
1145 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR4
, 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_COLOR4
, "bpp 4");
1148 ret
= ImageList_Destroy(himl
);
1149 ok(ret
, "ImageList_Destroy failed\n");
1151 himl
= ImageList_Create(BMP_CX
, BMP_CX
, 0, 4, 2);
1152 ok(himl
!= 0, "ImageList_Create failed\n");
1153 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 5, 4, BMP_CX
* 4, BMP_CX
* 2, ILC_COLOR4
, "bpp default");
1154 icon
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
1155 ok( ImageList_AddIcon(himl
, icon
) == 0,"failed to add icon\n");
1156 ok( ImageList_AddIcon(himl
, icon
) == 1,"failed to add icon\n");
1157 DestroyIcon( icon
);
1158 check_iml_data(himl
, BMP_CX
, BMP_CX
, 2, 5, 4, BMP_CX
* 4, BMP_CX
* 2, ILC_COLOR4
, "bpp default");
1159 ret
= ImageList_Destroy(himl
);
1160 ok(ret
, "ImageList_Destroy failed\n");
1162 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR24
|ILC_MASK
, 4, 2);
1163 ok(himl
!= 0, "ImageList_Create failed\n");
1164 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 5, 4, BMP_CX
* 4, BMP_CX
* 2, ILC_COLOR24
|ILC_MASK
,
1166 icon
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
1167 ok( ImageList_AddIcon(himl
, icon
) == 0,"failed to add icon\n");
1168 ok( ImageList_AddIcon(himl
, icon
) == 1,"failed to add icon\n");
1169 DestroyIcon( icon
);
1170 check_iml_data(himl
, BMP_CX
, BMP_CX
, 2, 5, 4, BMP_CX
* 4, BMP_CX
* 2, ILC_COLOR24
|ILC_MASK
,
1172 ret
= ImageList_Destroy(himl
);
1173 ok(ret
, "ImageList_Destroy failed\n");
1175 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR4
|ILC_MASK
, 4, 2);
1176 ok(himl
!= 0, "ImageList_Create failed\n");
1177 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 5, 4, BMP_CX
* 4, BMP_CX
* 2, ILC_COLOR4
|ILC_MASK
,
1179 icon
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
1180 ok( ImageList_AddIcon(himl
, icon
) == 0,"failed to add icon\n");
1181 ok( ImageList_AddIcon(himl
, icon
) == 1,"failed to add icon\n");
1182 DestroyIcon( icon
);
1183 check_iml_data(himl
, BMP_CX
, BMP_CX
, 2, 5, 4, BMP_CX
* 4, BMP_CX
* 2, ILC_COLOR4
|ILC_MASK
,
1185 ret
= ImageList_Destroy(himl
);
1186 ok(ret
, "ImageList_Destroy failed\n");
1188 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR4
|ILC_MASK
, 2, 99);
1189 ok(himl
!= 0, "ImageList_Create failed\n");
1190 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 3, 100, BMP_CX
* 4, BMP_CX
, ILC_COLOR4
|ILC_MASK
,
1192 icon
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
1193 ok( ImageList_AddIcon(himl
, icon
) == 0,"failed to add icon\n");
1194 ok( ImageList_AddIcon(himl
, icon
) == 1,"failed to add icon\n");
1195 check_iml_data(himl
, BMP_CX
, BMP_CX
, 2, 3, 100, BMP_CX
* 4, BMP_CX
, ILC_COLOR4
|ILC_MASK
,
1196 "init 2 grow 99 2 icons");
1197 ok( ImageList_AddIcon(himl
, icon
) == 2,"failed to add icon\n");
1198 DestroyIcon( icon
);
1199 check_iml_data(himl
, BMP_CX
, BMP_CX
, 3, 104, 100, BMP_CX
* 4, BMP_CX
* 104/4, ILC_COLOR4
|ILC_MASK
,
1200 "init 2 grow 99 3 icons");
1201 ok( ImageList_Remove(himl
, -1) == TRUE
,"failed to remove icon\n");
1202 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 100, 100, BMP_CX
* 4, BMP_CX
* 100/4, ILC_COLOR4
|ILC_MASK
,
1203 "init 2 grow 99 empty");
1204 ok( ImageList_SetImageCount(himl
, 22) == TRUE
,"failed to set image count\n");
1205 check_iml_data(himl
, BMP_CX
, BMP_CX
, 22, 23, 100, BMP_CX
* 4, BMP_CX
* 24/4, ILC_COLOR4
|ILC_MASK
,
1206 "init 2 grow 99 set count 22");
1207 ok( ImageList_SetImageCount(himl
, 0) == TRUE
,"failed to set image count\n");
1208 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 1, 100, BMP_CX
* 4, BMP_CX
, ILC_COLOR4
|ILC_MASK
,
1209 "init 2 grow 99 set count 0");
1210 ok( ImageList_SetImageCount(himl
, 42) == TRUE
,"failed to set image count\n");
1211 check_iml_data(himl
, BMP_CX
, BMP_CX
, 42, 43, 100, BMP_CX
* 4, BMP_CX
* 44/4, ILC_COLOR4
|ILC_MASK
,
1212 "init 2 grow 99 set count 42");
1213 ret
= ImageList_Destroy(himl
);
1214 ok(ret
, "ImageList_Destroy failed\n");
1216 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR4
|ILC_MASK
, 2, 65536+12);
1217 ok(himl
!= 0, "ImageList_Create failed\n");
1218 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 3, 12, BMP_CX
* 4, BMP_CX
, ILC_COLOR4
|ILC_MASK
,
1219 "init 2 grow 65536+12");
1220 ret
= ImageList_Destroy(himl
);
1221 ok(ret
, "ImageList_Destroy failed\n");
1223 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR4
|ILC_MASK
, 2, 65535);
1224 ok(himl
!= 0, "ImageList_Create failed\n");
1225 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 3, 0, BMP_CX
* 4, BMP_CX
, ILC_COLOR4
|ILC_MASK
,
1226 "init 2 grow 65535");
1227 ret
= ImageList_Destroy(himl
);
1228 ok(ret
, "ImageList_Destroy failed\n");
1230 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR4
|ILC_MASK
, 2, -20);
1231 ok(himl
!= 0, "ImageList_Create failed\n");
1232 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 3, 4, BMP_CX
* 4, BMP_CX
, ILC_COLOR4
|ILC_MASK
,
1234 ret
= ImageList_Destroy(himl
);
1235 ok(ret
, "ImageList_Destroy failed\n");
1238 static void test_shell_imagelist(void)
1240 HRESULT (WINAPI
*pSHGetImageList
)(INT
, REFIID
, void**);
1241 IImageList
*iml
= NULL
;
1248 /* Try to load function from shell32 */
1249 hShell32
= LoadLibraryA("shell32.dll");
1250 pSHGetImageList
= (void*)GetProcAddress(hShell32
, (LPCSTR
) 727);
1252 if (!pSHGetImageList
)
1254 win_skip("SHGetImageList not available, skipping test\n");
1255 FreeLibrary(hShell32
);
1259 /* Get system image list */
1260 hr
= pSHGetImageList(SHIL_SYSSMALL
, &IID_IImageList
, (void**)&iml
);
1261 ok(SUCCEEDED(hr
), "SHGetImageList failed, hr=%x\n", hr
);
1264 FreeLibrary(hShell32
);
1268 IImageList_GetImageCount(iml
, &out
);
1269 ok(out
> 0, "IImageList_GetImageCount returned out <= 0\n");
1271 /* Fetch the small icon size */
1272 cx
= GetSystemMetrics(SM_CXSMICON
);
1273 cy
= GetSystemMetrics(SM_CYSMICON
);
1275 /* Check icon size matches */
1276 IImageList_GetImageRect(iml
, 0, &rect
);
1277 ok(((rect
.right
== cx
) && (rect
.bottom
== cy
)),
1278 "IImageList_GetImageRect returned r:%d,b:%d\n",
1279 rect
.right
, rect
.bottom
);
1281 IImageList_Release(iml
);
1282 FreeLibrary(hShell32
);
1285 static HBITMAP
create_test_bitmap(HDC hdc
, int bpp
, UINT32 pixel1
, UINT32 pixel2
)
1288 UINT32
*buffer
= NULL
;
1289 BITMAPINFO bitmapInfo
= {{sizeof(BITMAPINFOHEADER
), 2, 1, 1, bpp
, BI_RGB
,
1292 hBitmap
= CreateDIBSection(hdc
, &bitmapInfo
, DIB_RGB_COLORS
, (void**)&buffer
, NULL
, 0);
1293 ok(hBitmap
!= NULL
&& buffer
!= NULL
, "CreateDIBSection failed.\n");
1295 if(!hBitmap
|| !buffer
)
1297 DeleteObject(hBitmap
);
1307 static BOOL
colour_match(UINT32 x
, UINT32 y
)
1309 const INT32 tolerance
= 8;
1311 const INT32 dr
= abs((INT32
)(x
& 0x000000FF) - (INT32
)(y
& 0x000000FF));
1312 const INT32 dg
= abs((INT32
)((x
& 0x0000FF00) >> 8) - (INT32
)((y
& 0x0000FF00) >> 8));
1313 const INT32 db
= abs((INT32
)((x
& 0x00FF0000) >> 16) - (INT32
)((y
& 0x00FF0000) >> 16));
1315 return (dr
<= tolerance
&& dg
<= tolerance
&& db
<= tolerance
);
1318 static void check_ImageList_DrawIndirect(IMAGELISTDRAWPARAMS
*ildp
, UINT32
*bits
,
1319 UINT32 expected
, int line
)
1321 bits
[0] = 0x00FFFFFF;
1322 pImageList_DrawIndirect(ildp
);
1323 ok(colour_match(bits
[0], expected
),
1324 "ImageList_DrawIndirect: Pixel %08X, Expected a close match to %08X from line %d\n",
1325 bits
[0] & 0x00FFFFFF, expected
, line
);
1329 static void check_ImageList_DrawIndirect_fStyle(HDC hdc
, HIMAGELIST himl
, UINT32
*bits
, int i
,
1330 UINT fStyle
, UINT32 expected
, int line
)
1332 IMAGELISTDRAWPARAMS ildp
= {sizeof(IMAGELISTDRAWPARAMS
), himl
, i
, hdc
,
1333 0, 0, 0, 0, 0, 0, CLR_NONE
, CLR_NONE
, fStyle
, 0, ILS_NORMAL
, 0, 0x00000000};
1334 check_ImageList_DrawIndirect(&ildp
, bits
, expected
, line
);
1337 static void check_ImageList_DrawIndirect_ILD_ROP(HDC hdc
, HIMAGELIST himl
, UINT32
*bits
, int i
,
1338 DWORD dwRop
, UINT32 expected
, int line
)
1340 IMAGELISTDRAWPARAMS ildp
= {sizeof(IMAGELISTDRAWPARAMS
), himl
, i
, hdc
,
1341 0, 0, 0, 0, 0, 0, CLR_NONE
, CLR_NONE
, ILD_IMAGE
| ILD_ROP
, dwRop
, ILS_NORMAL
, 0, 0x00000000};
1342 check_ImageList_DrawIndirect(&ildp
, bits
, expected
, line
);
1345 static void check_ImageList_DrawIndirect_fState(HDC hdc
, HIMAGELIST himl
, UINT32
*bits
, int i
, UINT fStyle
,
1346 UINT fState
, DWORD Frame
, UINT32 expected
, int line
)
1348 IMAGELISTDRAWPARAMS ildp
= {sizeof(IMAGELISTDRAWPARAMS
), himl
, i
, hdc
,
1349 0, 0, 0, 0, 0, 0, CLR_NONE
, CLR_NONE
, fStyle
, 0, fState
, Frame
, 0x00000000};
1350 check_ImageList_DrawIndirect(&ildp
, bits
, expected
, line
);
1353 static void check_ImageList_DrawIndirect_broken(HDC hdc
, HIMAGELIST himl
, UINT32
*bits
, int i
,
1354 UINT fStyle
, UINT fState
, DWORD Frame
, UINT32 expected
,
1355 UINT32 broken_expected
, int line
)
1357 IMAGELISTDRAWPARAMS ildp
= {sizeof(IMAGELISTDRAWPARAMS
), himl
, i
, hdc
,
1358 0, 0, 0, 0, 0, 0, CLR_NONE
, CLR_NONE
, fStyle
, 0, fState
, Frame
, 0x00000000};
1359 bits
[0] = 0x00FFFFFF;
1360 pImageList_DrawIndirect(&ildp
);
1361 ok(colour_match(bits
[0], expected
) ||
1362 broken(colour_match(bits
[0], broken_expected
)),
1363 "ImageList_DrawIndirect: Pixel %08X, Expected a close match to %08X from line %d\n",
1364 bits
[0] & 0x00FFFFFF, expected
, line
);
1367 static void test_ImageList_DrawIndirect(void)
1369 HIMAGELIST himl
= NULL
;
1372 HBITMAP hbmOld
= NULL
, hbmDst
= NULL
;
1373 HBITMAP hbmMask
= NULL
, hbmInverseMask
= NULL
;
1374 HBITMAP hbmImage
= NULL
, hbmAlphaImage
= NULL
, hbmTransparentImage
= NULL
;
1375 int iImage
= -1, iAlphaImage
= -1, iTransparentImage
= -1;
1377 UINT32 maskBits
= 0x00000000, inverseMaskBits
= 0xFFFFFFFF;
1378 int bpp
, broken_value
;
1380 BITMAPINFO bitmapInfo
= {{sizeof(BITMAPINFOHEADER
), 2, 1, 1, 32, BI_RGB
,
1383 hdcDst
= CreateCompatibleDC(0);
1384 ok(hdcDst
!= 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1387 bpp
= GetDeviceCaps(hdcDst
, BITSPIXEL
);
1389 hbmMask
= CreateBitmap(2, 1, 1, 1, &maskBits
);
1390 ok(hbmMask
!= 0, "CreateBitmap failed\n");
1391 if(!hbmMask
) goto cleanup
;
1393 hbmInverseMask
= CreateBitmap(2, 1, 1, 1, &inverseMaskBits
);
1394 ok(hbmInverseMask
!= 0, "CreateBitmap failed\n");
1395 if(!hbmInverseMask
) goto cleanup
;
1397 himl
= pImageList_Create(2, 1, ILC_COLOR32
, 0, 1);
1398 ok(himl
!= 0, "ImageList_Create failed\n");
1399 if(!himl
) goto cleanup
;
1401 /* Add a no-alpha image */
1402 hbmImage
= create_test_bitmap(hdcDst
, 32, 0x00ABCDEF, 0x00ABCDEF);
1403 if(!hbmImage
) goto cleanup
;
1405 iImage
= pImageList_Add(himl
, hbmImage
, hbmMask
);
1406 ok(iImage
!= -1, "ImageList_Add failed\n");
1407 if(iImage
== -1) goto cleanup
;
1409 /* Add an alpha image */
1410 hbmAlphaImage
= create_test_bitmap(hdcDst
, 32, 0x89ABCDEF, 0x89ABCDEF);
1411 if(!hbmAlphaImage
) goto cleanup
;
1413 iAlphaImage
= pImageList_Add(himl
, hbmAlphaImage
, hbmMask
);
1414 ok(iAlphaImage
!= -1, "ImageList_Add failed\n");
1415 if(iAlphaImage
== -1) goto cleanup
;
1417 /* Add a transparent alpha image */
1418 hbmTransparentImage
= create_test_bitmap(hdcDst
, 32, 0x00ABCDEF, 0x89ABCDEF);
1419 if(!hbmTransparentImage
) goto cleanup
;
1421 iTransparentImage
= pImageList_Add(himl
, hbmTransparentImage
, hbmMask
);
1422 ok(iTransparentImage
!= -1, "ImageList_Add failed\n");
1423 if(iTransparentImage
== -1) goto cleanup
;
1426 bitmapInfo
.bmiHeader
.biBitCount
= 32;
1427 hbmDst
= CreateDIBSection(hdcDst
, &bitmapInfo
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
1428 ok (hbmDst
&& bits
, "CreateDIBSection failed to return a valid bitmap and buffer\n");
1429 if (!hbmDst
|| !bits
)
1431 hbmOld
= SelectObject(hdcDst
, hbmDst
);
1433 check_ImageList_DrawIndirect_fStyle(hdcDst
, himl
, bits
, iImage
, ILD_NORMAL
, 0x00ABCDEF, __LINE__
);
1434 check_ImageList_DrawIndirect_fStyle(hdcDst
, himl
, bits
, iImage
, ILD_TRANSPARENT
, 0x00ABCDEF, __LINE__
);
1435 todo_wine
check_ImageList_DrawIndirect_broken(hdcDst
, himl
, bits
, iAlphaImage
, ILD_BLEND25
, ILS_NORMAL
, 0, 0x00E8F1FA, 0x00D4D9DD, __LINE__
);
1436 if (bpp
== 16 || bpp
== 24) broken_value
= 0x00D4D9DD;
1437 else broken_value
= 0x00B4BDC4;
1438 todo_wine
check_ImageList_DrawIndirect_broken(hdcDst
, himl
, bits
, iAlphaImage
, ILD_BLEND50
, ILS_NORMAL
, 0, 0x00E8F1FA, broken_value
, __LINE__
);
1439 check_ImageList_DrawIndirect_fStyle(hdcDst
, himl
, bits
, iImage
, ILD_MASK
, 0x00ABCDEF, __LINE__
);
1440 check_ImageList_DrawIndirect_fStyle(hdcDst
, himl
, bits
, iImage
, ILD_IMAGE
, 0x00ABCDEF, __LINE__
);
1441 check_ImageList_DrawIndirect_fStyle(hdcDst
, himl
, bits
, iImage
, ILD_PRESERVEALPHA
, 0x00ABCDEF, __LINE__
);
1443 check_ImageList_DrawIndirect_fStyle(hdcDst
, himl
, bits
, iAlphaImage
, ILD_NORMAL
, 0x00D3E5F7, __LINE__
);
1444 check_ImageList_DrawIndirect_fStyle(hdcDst
, himl
, bits
, iAlphaImage
, ILD_TRANSPARENT
, 0x00D3E5F7, __LINE__
);
1446 if (bpp
== 16 || bpp
== 24) broken_value
= 0x00D4D9DD;
1447 else broken_value
= 0x009DA8B1;
1448 todo_wine
check_ImageList_DrawIndirect_broken(hdcDst
, himl
, bits
, iAlphaImage
, ILD_BLEND25
, ILS_NORMAL
, 0, 0x00E8F1FA, broken_value
, __LINE__
);
1449 if (bpp
== 16 || bpp
== 24) broken_value
= 0x00D4D9DD;
1450 else broken_value
= 0x008C99A3;
1451 todo_wine
check_ImageList_DrawIndirect_broken(hdcDst
, himl
, bits
, iAlphaImage
, ILD_BLEND50
, ILS_NORMAL
, 0, 0x00E8F1FA, broken_value
, __LINE__
);
1452 check_ImageList_DrawIndirect_fStyle(hdcDst
, himl
, bits
, iAlphaImage
, ILD_MASK
, 0x00D3E5F7, __LINE__
);
1453 check_ImageList_DrawIndirect_fStyle(hdcDst
, himl
, bits
, iAlphaImage
, ILD_IMAGE
, 0x00D3E5F7, __LINE__
);
1454 todo_wine
check_ImageList_DrawIndirect_fStyle(hdcDst
, himl
, bits
, iAlphaImage
, ILD_PRESERVEALPHA
, 0x005D6F81, __LINE__
);
1456 check_ImageList_DrawIndirect_fStyle(hdcDst
, himl
, bits
, iTransparentImage
, ILD_NORMAL
, 0x00FFFFFF, __LINE__
);
1458 check_ImageList_DrawIndirect_ILD_ROP(hdcDst
, himl
, bits
, iImage
, SRCCOPY
, 0x00ABCDEF, __LINE__
);
1459 check_ImageList_DrawIndirect_ILD_ROP(hdcDst
, himl
, bits
, iImage
, SRCINVERT
, 0x00543210, __LINE__
);
1461 /* ILD_ROP is ignored when the image has an alpha channel */
1462 check_ImageList_DrawIndirect_ILD_ROP(hdcDst
, himl
, bits
, iAlphaImage
, SRCCOPY
, 0x00D3E5F7, __LINE__
);
1463 check_ImageList_DrawIndirect_ILD_ROP(hdcDst
, himl
, bits
, iAlphaImage
, SRCINVERT
, 0x00D3E5F7, __LINE__
);
1465 todo_wine
check_ImageList_DrawIndirect_fState(hdcDst
, himl
, bits
, iImage
, ILD_NORMAL
, ILS_SATURATE
, 0, 0x00CCCCCC, __LINE__
);
1466 todo_wine
check_ImageList_DrawIndirect_broken(hdcDst
, himl
, bits
, iAlphaImage
, ILD_NORMAL
, ILS_SATURATE
, 0, 0x00AFAFAF, 0x00F0F0F0, __LINE__
);
1468 check_ImageList_DrawIndirect_fState(hdcDst
, himl
, bits
, iImage
, ILD_NORMAL
, ILS_GLOW
, 0, 0x00ABCDEF, __LINE__
);
1469 check_ImageList_DrawIndirect_fState(hdcDst
, himl
, bits
, iImage
, ILD_NORMAL
, ILS_SHADOW
, 0, 0x00ABCDEF, __LINE__
);
1471 check_ImageList_DrawIndirect_fState(hdcDst
, himl
, bits
, iImage
, ILD_NORMAL
, ILS_ALPHA
, 127, 0x00D5E6F7, __LINE__
);
1472 check_ImageList_DrawIndirect_broken(hdcDst
, himl
, bits
, iAlphaImage
, ILD_NORMAL
, ILS_ALPHA
, 127, 0x00E9F2FB, 0x00AEB7C0, __LINE__
);
1473 todo_wine
check_ImageList_DrawIndirect_broken(hdcDst
, himl
, bits
, iAlphaImage
, ILD_NORMAL
, ILS_NORMAL
, 127, 0x00E9F2FB, 0x00D3E5F7, __LINE__
);
1478 SelectObject(hdcDst
, hbmOld
);
1480 DeleteObject(hbmDst
);
1486 DeleteObject(hbmMask
);
1488 DeleteObject(hbmInverseMask
);
1491 DeleteObject(hbmImage
);
1493 DeleteObject(hbmAlphaImage
);
1494 if(hbmTransparentImage
)
1495 DeleteObject(hbmTransparentImage
);
1499 ret
= ImageList_Destroy(himl
);
1500 ok(ret
, "ImageList_Destroy failed\n");
1504 static void test_iimagelist(void)
1506 IImageList
*imgl
, *imgl2
;
1507 IImageList2
*imagelist
;
1512 if (!pHIMAGELIST_QueryInterface
)
1514 win_skip("XP imagelist functions not available\n");
1518 /* test reference counting on destruction */
1519 imgl
= (IImageList
*)createImageList(32, 32);
1520 ret
= IImageList_AddRef(imgl
);
1521 ok(ret
== 2, "Expected 2, got %d\n", ret
);
1522 ret
= ImageList_Destroy((HIMAGELIST
)imgl
);
1523 ok(ret
== TRUE
, "Expected TRUE, 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
== FALSE
, "Expected FALSE, got %d\n", ret
);
1529 imgl
= (IImageList
*)createImageList(32, 32);
1530 ret
= IImageList_AddRef(imgl
);
1531 ok(ret
== 2, "Expected 2, got %d\n", ret
);
1532 ret
= ImageList_Destroy((HIMAGELIST
)imgl
);
1533 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1534 ret
= IImageList_Release(imgl
);
1535 ok(ret
== 0, "Expected 0, got %d\n", ret
);
1536 ret
= ImageList_Destroy((HIMAGELIST
)imgl
);
1537 ok(ret
== FALSE
, "Expected FALSE, got %d\n", ret
);
1539 /* ref counting, HIMAGELIST_QueryInterface adds a reference */
1540 imgl
= (IImageList
*)createImageList(32, 32);
1541 hr
= pHIMAGELIST_QueryInterface((HIMAGELIST
)imgl
, &IID_IImageList
, (void**)&imgl2
);
1542 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1543 ok(imgl2
== imgl
, "got different pointer\n");
1544 ret
= IImageList_Release(imgl
);
1545 ok(ret
== 1, "got %u\n", ret
);
1546 IImageList_Release(imgl
);
1548 if (!pImageList_CoCreateInstance
)
1550 win_skip("Vista imagelist functions not available\n");
1554 hr
= pImageList_CoCreateInstance(&CLSID_ImageList
, NULL
, &IID_IImageList
, (void **) &imgl
);
1555 ok(SUCCEEDED(hr
), "ImageList_CoCreateInstance failed, hr=%x\n", hr
);
1558 IImageList_Release(imgl
);
1560 himl
= createImageList(32, 32);
1565 hr
= (pHIMAGELIST_QueryInterface
)(himl
, &IID_IImageList
, (void **) &imgl
);
1566 ok(SUCCEEDED(hr
), "HIMAGELIST_QueryInterface failed, hr=%x\n", hr
);
1569 IImageList_Release(imgl
);
1571 ImageList_Destroy(himl
);
1574 hr
= pImageList_CoCreateInstance(&CLSID_ImageList
, NULL
, &IID_IImageList2
, (void**)&imagelist
);
1577 win_skip("IImageList2 is not supported.\n");
1580 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1581 IImageList2_Release(imagelist
);
1584 static void test_hotspot_v6(void)
1595 #define HOTSPOTS_MAX 4 /* Number of entries in hotspots */
1596 static const struct hotspot hotspots
[HOTSPOTS_MAX
] = {
1603 HIMAGELIST himl1
= createImageList(SIZEX1
, SIZEY1
);
1604 HIMAGELIST himl2
= createImageList(SIZEX2
, SIZEY2
);
1605 IImageList
*imgl1
, *imgl2
;
1608 /* cast to IImageList */
1609 imgl1
= (IImageList
*) himl1
;
1610 imgl2
= (IImageList
*) himl2
;
1612 for (i
= 0; i
< HOTSPOTS_MAX
; i
++) {
1613 for (j
= 0; j
< HOTSPOTS_MAX
; j
++) {
1614 int dx1
= hotspots
[i
].dx
;
1615 int dy1
= hotspots
[i
].dy
;
1616 int dx2
= hotspots
[j
].dx
;
1617 int dy2
= hotspots
[j
].dy
;
1618 int correctx
, correcty
, newx
, newy
;
1620 IImageList
*imglNew
;
1623 hr
= IImageList_BeginDrag(imgl1
, 0, dx1
, dy1
);
1624 ok(SUCCEEDED(hr
), "BeginDrag failed for { %d, %d }\n", dx1
, dy1
);
1625 sprintf(loc
, "BeginDrag (%d,%d)\n", i
, j
);
1627 /* check merging the dragged image with a second image */
1628 hr
= IImageList_SetDragCursorImage(imgl2
, (IUnknown
*) imgl2
, 0, dx2
, dy2
);
1629 ok(SUCCEEDED(hr
), "SetDragCursorImage failed for {%d, %d}{%d, %d}\n",
1630 dx1
, dy1
, dx2
, dy2
);
1631 sprintf(loc
, "SetDragCursorImage (%d,%d)\n", i
, j
);
1633 /* check new hotspot, it should be the same like the old one */
1634 hr
= IImageList_GetDragImage(imgl2
, NULL
, &ppt
, &IID_IImageList
, (PVOID
*) &imglNew
);
1635 ok(SUCCEEDED(hr
), "GetDragImage failed\n");
1636 ok(ppt
.x
== dx1
&& ppt
.y
== dy1
,
1637 "Expected drag hotspot [%d,%d] got [%d,%d]\n",
1638 dx1
, dy1
, ppt
.x
, ppt
.y
);
1639 /* check size of new dragged image */
1640 IImageList_GetIconSize(imglNew
, &newx
, &newy
);
1641 correctx
= max(SIZEX1
, max(SIZEX2
+ dx2
, SIZEX1
- dx2
));
1642 correcty
= max(SIZEY1
, max(SIZEY2
+ dy2
, SIZEY1
- dy2
));
1643 ok(newx
== correctx
&& newy
== correcty
,
1644 "Expected drag image size [%d,%d] got [%d,%d]\n",
1645 correctx
, correcty
, newx
, newy
);
1646 sprintf(loc
, "GetDragImage (%d,%d)\n", i
, j
);
1647 IImageList_EndDrag(imgl2
);
1655 IImageList_Release(imgl2
);
1656 IImageList_Release(imgl1
);
1659 static void test_IImageList_Add_Remove(void)
1671 /* create an imagelist to play with */
1672 himl
= ImageList_Create(84, 84, ILC_COLOR16
, 0, 3);
1673 ok(himl
!= 0,"failed to create imagelist\n");
1675 imgl
= (IImageList
*) himl
;
1677 /* load the icons to add to the image list */
1678 hicon1
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
1679 ok(hicon1
!= 0, "no hicon1\n");
1680 hicon2
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
1681 ok(hicon2
!= 0, "no hicon2\n");
1682 hicon3
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
1683 ok(hicon3
!= 0, "no hicon3\n");
1685 /* remove when nothing exists */
1686 hr
= IImageList_Remove(imgl
, 0);
1687 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
1689 /* removing everything from an empty imagelist should succeed */
1690 hr
= IImageList_Remove(imgl
, -1);
1691 ok(hr
== S_OK
, "removed nonexistent icon\n");
1695 ok( IImageList_ReplaceIcon(imgl
, -1, hicon1
, &ret
) == S_OK
&& (ret
== 0),"failed to add icon1\n");
1697 ok( IImageList_ReplaceIcon(imgl
, -1, hicon2
, &ret
) == S_OK
&& (ret
== 1),"failed to add icon2\n");
1699 ok( IImageList_ReplaceIcon(imgl
, -1, hicon3
, &ret
) == S_OK
&& (ret
== 2),"failed to add icon3\n");
1701 /* remove an index out of range */
1702 ok( IImageList_Remove(imgl
, 4711) == E_INVALIDARG
, "got 0x%08x\n", hr
);
1705 ok( IImageList_Remove(imgl
,0) == S_OK
, "can't remove 0\n");
1706 ok( IImageList_Remove(imgl
,0) == S_OK
, "can't remove 0\n");
1707 ok( IImageList_Remove(imgl
,0) == S_OK
, "can't remove 0\n");
1709 /* remove one extra */
1710 ok( IImageList_Remove(imgl
, 0) == E_INVALIDARG
, "got 0x%08x\n", hr
);
1712 IImageList_Release(imgl
);
1713 ok(DestroyIcon(hicon1
),"icon 1 wasn't deleted\n");
1714 ok(DestroyIcon(hicon2
),"icon 2 wasn't deleted\n");
1715 ok(DestroyIcon(hicon3
),"icon 3 wasn't deleted\n");
1718 static void test_IImageList_Get_SetImageCount(void)
1725 /* create an imagelist to play with */
1726 himl
= ImageList_Create(84, 84, ILC_COLOR16
, 0, 3);
1727 ok(himl
!= 0,"failed to create imagelist\n");
1729 imgl
= (IImageList
*) himl
;
1731 /* check SetImageCount/GetImageCount */
1732 hr
= IImageList_SetImageCount(imgl
, 3);
1733 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1735 hr
= IImageList_GetImageCount(imgl
, &ret
);
1736 ok(hr
== S_OK
&& ret
== 3, "invalid image count after increase\n");
1737 hr
= IImageList_SetImageCount(imgl
, 1);
1738 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1740 hr
= IImageList_GetImageCount(imgl
, &ret
);
1741 ok(hr
== S_OK
&& ret
== 1, "invalid image count after decrease to 1\n");
1742 hr
= IImageList_SetImageCount(imgl
, 0);
1743 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1745 hr
= IImageList_GetImageCount(imgl
, &ret
);
1746 ok(hr
== S_OK
&& ret
== 0, "invalid image count after decrease to 0\n");
1748 IImageList_Release(imgl
);
1751 static void test_IImageList_Draw(void)
1760 IMAGELISTDRAWPARAMS imldp
;
1766 hwndfortest
= create_a_window();
1767 hdc
= GetDC(hwndfortest
);
1768 ok(hdc
!=NULL
, "couldn't get DC\n");
1770 /* create an imagelist to play with */
1771 himl
= ImageList_Create(48, 48, ILC_COLOR16
, 0, 3);
1772 ok(himl
!=0,"failed to create imagelist\n");
1774 imgl
= (IImageList
*) himl
;
1776 /* load the icons to add to the image list */
1777 hbm1
= CreateBitmap(48, 48, 1, 1, bitmap_bits
);
1778 ok(hbm1
!= 0, "no bitmap 1\n");
1779 hbm2
= CreateBitmap(48, 48, 1, 1, bitmap_bits
);
1780 ok(hbm2
!= 0, "no bitmap 2\n");
1781 hbm3
= CreateBitmap(48, 48, 1, 1, bitmap_bits
);
1782 ok(hbm3
!= 0, "no bitmap 3\n");
1786 ok( IImageList_Add(imgl
, hbm1
, 0, &ret
) == S_OK
&& (ret
== 0), "failed to add bitmap 1\n");
1788 ok( IImageList_Add(imgl
, hbm2
, 0, &ret
) == S_OK
&& (ret
== 1), "failed to add bitmap 2\n");
1790 ok( IImageList_SetImageCount(imgl
, 3) == S_OK
, "Setimage count failed\n");
1791 ok( IImageList_Replace(imgl
, 2, hbm3
, 0) == S_OK
, "failed to replace bitmap 3\n");
1795 /* crashes on native */
1796 IImageList_Draw(imgl
, NULL
);
1799 memset(&imldp
, 0, sizeof (imldp
));
1800 hr
= IImageList_Draw(imgl
, &imldp
);
1801 ok( hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
1803 imldp
.cbSize
= IMAGELISTDRAWPARAMS_V3_SIZE
;
1807 force_redraw(hwndfortest
);
1809 imldp
.fStyle
= SRCCOPY
;
1810 imldp
.rgbBk
= CLR_DEFAULT
;
1811 imldp
.rgbFg
= CLR_DEFAULT
;
1814 ok( IImageList_Draw(imgl
, &imldp
) == S_OK
, "should succeed\n");
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
) == E_INVALIDARG
, "should fail\n");
1823 ok( IImageList_Remove(imgl
, 0) == S_OK
, "removing 1st bitmap\n");
1824 ok( IImageList_Remove(imgl
, 0) == S_OK
, "removing 2nd bitmap\n");
1825 ok( IImageList_Remove(imgl
, 0) == S_OK
, "removing 3rd bitmap\n");
1828 IImageList_Release(imgl
);
1830 /* bitmaps should not be deleted by the imagelist */
1831 ok(DeleteObject(hbm1
),"bitmap 1 can't be deleted\n");
1832 ok(DeleteObject(hbm2
),"bitmap 2 can't be deleted\n");
1833 ok(DeleteObject(hbm3
),"bitmap 3 can't be deleted\n");
1835 ReleaseDC(hwndfortest
, hdc
);
1836 DestroyWindow(hwndfortest
);
1839 static void test_IImageList_Merge(void)
1841 HIMAGELIST himl1
, himl2
;
1842 IImageList
*imgl1
, *imgl2
, *merge
;
1844 HWND hwnd
= create_a_window();
1848 himl1
= ImageList_Create(32,32,0,0,3);
1849 ok(himl1
!= NULL
,"failed to create himl1\n");
1851 himl2
= ImageList_Create(32,32,0,0,3);
1852 ok(himl2
!= NULL
,"failed to create himl2\n");
1854 hicon1
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
1855 ok(hicon1
!= NULL
, "failed to create hicon1\n");
1857 if (!himl1
|| !himl2
|| !hicon1
)
1860 /* cast to IImageList */
1861 imgl1
= (IImageList
*) himl1
;
1862 imgl2
= (IImageList
*) himl2
;
1865 ok( IImageList_ReplaceIcon(imgl2
, -1, hicon1
, &ret
) == S_OK
&& (ret
== 0),"add icon1 to himl2 failed\n");
1869 /* null cases that crash on native */
1870 IImageList_Merge(imgl1
, -1, NULL
, 0, 0, 0, &IID_IImageList
, (void**)&merge
);
1871 IImageList_Merge(imgl1
, -1, (IUnknown
*) imgl2
, 0, 0, 0, &IID_IImageList
, NULL
);
1874 /* If himl1 has no images, merge still succeeds */
1875 hr
= IImageList_Merge(imgl1
, -1, (IUnknown
*) imgl2
, 0, 0, 0, &IID_IImageList
, (void **) &merge
);
1876 ok(hr
== S_OK
, "merge himl1,-1 failed\n");
1877 if (hr
== S_OK
) IImageList_Release(merge
);
1879 hr
= IImageList_Merge(imgl1
, 0, (IUnknown
*) imgl2
, 0, 0, 0, &IID_IImageList
, (void **) &merge
);
1880 ok(hr
== S_OK
, "merge himl1,0 failed\n");
1881 if (hr
== S_OK
) IImageList_Release(merge
);
1883 /* Same happens if himl2 is empty */
1884 IImageList_Release(imgl2
);
1885 himl2
= ImageList_Create(32,32,0,0,3);
1886 ok(himl2
!= NULL
,"failed to recreate himl2\n");
1888 imgl2
= (IImageList
*) himl2
;
1890 hr
= IImageList_Merge(imgl1
, -1, (IUnknown
*) imgl2
, -1, 0, 0, &IID_IImageList
, (void **) &merge
);
1891 ok(hr
== S_OK
, "merge himl2,-1 failed\n");
1892 if (hr
== S_OK
) IImageList_Release(merge
);
1894 hr
= IImageList_Merge(imgl1
, -1, (IUnknown
*) imgl2
, 0, 0, 0, &IID_IImageList
, (void **) &merge
);
1895 ok(hr
== S_OK
, "merge himl2,0 failed\n");
1896 if (hr
== S_OK
) IImageList_Release(merge
);
1898 /* Now try merging an image with itself */
1900 ok( IImageList_ReplaceIcon(imgl2
, -1, hicon1
, &ret
) == S_OK
&& (ret
== 0),"re-add icon1 to himl2 failed\n");
1902 hr
= IImageList_Merge(imgl2
, 0, (IUnknown
*) imgl2
, 0, 0, 0, &IID_IImageList
, (void **) &merge
);
1903 ok(hr
== S_OK
, "merge himl2 with itself failed\n");
1904 if (hr
== S_OK
) IImageList_Release(merge
);
1906 /* Try merging 2 different image lists */
1908 ok( IImageList_ReplaceIcon(imgl1
, -1, hicon1
, &ret
) == S_OK
&& (ret
== 0),"add icon1 to himl1 failed\n");
1910 hr
= IImageList_Merge(imgl1
, 0, (IUnknown
*) imgl2
, 0, 0, 0, &IID_IImageList
, (void **) &merge
);
1911 ok(hr
== S_OK
, "merge himl1 with himl2 failed\n");
1912 if (hr
== S_OK
) IImageList_Release(merge
);
1914 hr
= IImageList_Merge(imgl1
, 0, (IUnknown
*) imgl2
, 0, 8, 16, &IID_IImageList
, (void **) &merge
);
1915 ok(hr
== S_OK
, "merge himl1 with himl2 8,16 failed\n");
1916 if (hr
== S_OK
) IImageList_Release(merge
);
1918 IImageList_Release(imgl1
);
1919 IImageList_Release(imgl2
);
1921 DestroyIcon(hicon1
);
1922 DestroyWindow(hwnd
);
1925 static void test_iconsize(void)
1931 himl
= ImageList_Create(16, 16, ILC_COLOR16
, 0, 3);
1932 /* null pointers, not zero imagelist dimensions */
1933 ret
= ImageList_GetIconSize(himl
, NULL
, NULL
);
1934 ok(!ret
, "got %d\n", ret
);
1936 /* doesn't touch return pointers */
1938 ret
= ImageList_GetIconSize(himl
, &cx
, NULL
);
1939 ok(!ret
, "got %d\n", ret
);
1940 ok(cx
== 0x1abe11ed, "got %d\n", cx
);
1943 ret
= ImageList_GetIconSize(himl
, NULL
, &cy
);
1944 ok(!ret
, "got %d\n", ret
);
1945 ok(cy
== 0x1abe11ed, "got %d\n", cy
);
1947 ImageList_Destroy(himl
);
1949 ret
= ImageList_GetIconSize((HIMAGELIST
)0xdeadbeef, &cx
, &cy
);
1950 ok(!ret
, "got %d\n", ret
);
1953 static void test_create_destroy(void)
1962 /* list with zero or negative image dimensions */
1963 himl
= ImageList_Create(0, 0, ILC_COLOR16
, 0, 3);
1964 ok(himl
== NULL
, "got %p\n", himl
);
1966 himl
= ImageList_Create(0, 16, ILC_COLOR16
, 0, 3);
1967 ok(himl
== NULL
, "got %p\n", himl
);
1969 himl
= ImageList_Create(16, 0, ILC_COLOR16
, 0, 3);
1970 ok(himl
== NULL
, "got %p\n", himl
);
1972 himl
= ImageList_Create(16, -1, ILC_COLOR16
, 0, 3);
1973 ok(himl
== NULL
, "got %p\n", himl
);
1975 himl
= ImageList_Create(-1, 16, ILC_COLOR16
, 0, 3);
1976 ok(himl
== NULL
, "got %p\n", himl
);
1978 rc
= ImageList_Destroy((HIMAGELIST
)0xdeadbeef);
1979 ok(rc
== FALSE
, "ImageList_Destroy(0xdeadbeef) should fail and not crash\n");
1981 /* DDB image lists */
1982 himl
= ImageList_Create(0, 14, ILC_COLORDDB
, 4, 4);
1983 ok(himl
!= NULL
, "got %p\n", himl
);
1984 imgl
= (IImageList
*)himl
;
1985 IImageList_GetIconSize(imgl
, &cx
, &cy
);
1986 ok (cx
== 0, "Wrong cx (%i)\n", cx
);
1987 ok (cy
== 14, "Wrong cy (%i)\n", cy
);
1988 ImageList_Destroy(himl
);
1990 himl
= ImageList_Create(0, 0, ILC_COLORDDB
, 4, 4);
1991 ok(himl
!= NULL
, "got %p\n", himl
);
1992 imgl
= (IImageList
*)himl
;
1993 IImageList_GetIconSize(imgl
, &cx
, &cy
);
1994 ok (cx
== 0, "Wrong cx (%i)\n", cx
);
1995 ok (cy
== 0, "Wrong cy (%i)\n", cy
);
1996 ImageList_Destroy(himl
);
1998 himl
= ImageList_Create(0, 0, ILC_COLORDDB
, 0, 4);
1999 ok(himl
!= NULL
, "got %p\n", himl
);
2000 imgl
= (IImageList
*)himl
;
2001 IImageList_GetIconSize(imgl
, &cx
, &cy
);
2002 ok (cx
== 0, "Wrong cx (%i)\n", cx
);
2003 ok (cy
== 0, "Wrong cy (%i)\n", cy
);
2005 hr
= IImageList_SetImageCount(imgl
, 3);
2006 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2007 hr
= IImageList_GetImageCount(imgl
, &ret
);
2008 ok(hr
== S_OK
&& ret
== 3, "invalid image count after increase\n");
2010 /* Trying to actually add an image causes a crash on Windows */
2011 ImageList_Destroy(himl
);
2013 /* Negative values fail */
2014 himl
= ImageList_Create(-1, -1, ILC_COLORDDB
, 4, 4);
2015 ok(himl
== NULL
, "got %p\n", himl
);
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
);
2022 static void check_color_table(const char *name
, HDC hdc
, HIMAGELIST himl
, UINT ilc
,
2023 RGBQUAD
*expect
, RGBQUAD
*broken_expect
)
2027 char bmi_buffer
[FIELD_OFFSET(BITMAPINFO
, bmiColors
) + 256 * sizeof(RGBQUAD
)];
2028 BITMAPINFO
*bmi
= (BITMAPINFO
*)bmi_buffer
;
2029 int i
, depth
= ilc
& 0xfe;
2031 ret
= ImageList_GetImageInfo(himl
, 0, &info
);
2032 ok(ret
, "got %d\n", ret
);
2033 ok(info
.hbmImage
!= NULL
, "got %p\n", info
.hbmImage
);
2035 memset(bmi_buffer
, 0, sizeof(bmi_buffer
));
2036 bmi
->bmiHeader
.biSize
= sizeof(bmi
->bmiHeader
);
2037 ret
= GetDIBits(hdc
, info
.hbmImage
, 0, 0, NULL
, bmi
, DIB_RGB_COLORS
);
2038 ok(ret
, "got %d\n", ret
);
2039 ok(bmi
->bmiHeader
.biBitCount
== depth
, "got %d\n", bmi
->bmiHeader
.biBitCount
);
2041 ret
= GetDIBits(hdc
, info
.hbmImage
, 0, 0, NULL
, bmi
, DIB_RGB_COLORS
);
2042 ok(ret
, "got %d\n", ret
);
2043 ok(bmi
->bmiHeader
.biBitCount
== depth
, "got %d\n", bmi
->bmiHeader
.biBitCount
);
2045 for (i
= 0; i
< (1 << depth
); i
++)
2046 ok((bmi
->bmiColors
[i
].rgbRed
== expect
[i
].rgbRed
&&
2047 bmi
->bmiColors
[i
].rgbGreen
== expect
[i
].rgbGreen
&&
2048 bmi
->bmiColors
[i
].rgbBlue
== expect
[i
].rgbBlue
) ||
2049 broken(bmi
->bmiColors
[i
].rgbRed
== broken_expect
[i
].rgbRed
&&
2050 bmi
->bmiColors
[i
].rgbGreen
== broken_expect
[i
].rgbGreen
&&
2051 bmi
->bmiColors
[i
].rgbBlue
== broken_expect
[i
].rgbBlue
),
2052 "%d: %s: got color[%d] %02x %02x %02x expect %02x %02x %02x\n", depth
, name
, i
,
2053 bmi
->bmiColors
[i
].rgbRed
, bmi
->bmiColors
[i
].rgbGreen
, bmi
->bmiColors
[i
].rgbBlue
,
2054 expect
[i
].rgbRed
, expect
[i
].rgbGreen
, expect
[i
].rgbBlue
);
2057 static void get_default_color_table(HDC hdc
, int bpp
, RGBQUAD
*table
)
2059 char bmi_buffer
[FIELD_OFFSET(BITMAPINFO
, bmiColors
) + 256 * sizeof(RGBQUAD
)];
2060 BITMAPINFO
*bmi
= (BITMAPINFO
*)bmi_buffer
;
2064 PALETTEENTRY entries
[256];
2069 tmp
= CreateBitmap( 1, 1, 1, 1, NULL
);
2070 memset(bmi_buffer
, 0, sizeof(bmi_buffer
));
2071 bmi
->bmiHeader
.biSize
= sizeof(bmi
->bmiHeader
);
2072 bmi
->bmiHeader
.biHeight
= 1;
2073 bmi
->bmiHeader
.biWidth
= 1;
2074 bmi
->bmiHeader
.biBitCount
= bpp
;
2075 bmi
->bmiHeader
.biPlanes
= 1;
2076 bmi
->bmiHeader
.biCompression
= BI_RGB
;
2077 GetDIBits( hdc
, tmp
, 0, 0, NULL
, bmi
, DIB_RGB_COLORS
);
2079 memcpy(table
, bmi
->bmiColors
, (1 << bpp
) * sizeof(RGBQUAD
));
2080 table
[7] = bmi
->bmiColors
[8];
2081 table
[8] = bmi
->bmiColors
[7];
2082 DeleteObject( tmp
);
2086 pal
= CreateHalftonePalette(hdc
);
2087 GetPaletteEntries(pal
, 0, 256, entries
);
2088 for (i
= 0; i
< 256; i
++)
2090 table
[i
].rgbRed
= entries
[i
].peRed
;
2091 table
[i
].rgbGreen
= entries
[i
].peGreen
;
2092 table
[i
].rgbBlue
= entries
[i
].peBlue
;
2093 table
[i
].rgbReserved
= 0;
2099 ok(0, "unhandled depth %d\n", bpp
);
2103 static void test_color_table(UINT ilc
)
2107 char bmi_buffer
[FIELD_OFFSET(BITMAPINFO
, bmiColors
) + 256 * sizeof(RGBQUAD
)];
2108 BITMAPINFO
*bmi
= (BITMAPINFO
*)bmi_buffer
;
2109 HDC hdc
= CreateCompatibleDC(0);
2110 HBITMAP dib4
, dib8
, dib32
;
2111 RGBQUAD rgb
[256], default_table
[256];
2113 get_default_color_table(hdc
, ilc
& 0xfe, default_table
);
2115 himl
= ImageList_Create(16, 16, ilc
, 0, 3);
2116 ok(himl
!= NULL
, "got %p\n", himl
);
2118 memset(bmi_buffer
, 0, sizeof(bmi_buffer
));
2119 bmi
->bmiHeader
.biSize
= sizeof(bmi
->bmiHeader
);
2120 bmi
->bmiHeader
.biHeight
= 16;
2121 bmi
->bmiHeader
.biWidth
= 16;
2122 bmi
->bmiHeader
.biBitCount
= 8;
2123 bmi
->bmiHeader
.biPlanes
= 1;
2124 bmi
->bmiHeader
.biCompression
= BI_RGB
;
2125 bmi
->bmiColors
[0].rgbRed
= 0xff;
2126 bmi
->bmiColors
[1].rgbGreen
= 0xff;
2127 bmi
->bmiColors
[2].rgbBlue
= 0xff;
2129 dib8
= CreateDIBSection(hdc
, bmi
, DIB_RGB_COLORS
, NULL
, NULL
, 0);
2131 bmi
->bmiHeader
.biBitCount
= 4;
2132 bmi
->bmiColors
[0].rgbRed
= 0xff;
2133 bmi
->bmiColors
[0].rgbGreen
= 0x00;
2134 bmi
->bmiColors
[0].rgbBlue
= 0xff;
2135 bmi
->bmiColors
[1].rgbRed
= 0xff;
2136 bmi
->bmiColors
[1].rgbGreen
= 0xff;
2137 bmi
->bmiColors
[1].rgbBlue
= 0x00;
2138 bmi
->bmiColors
[2].rgbRed
= 0x00;
2139 bmi
->bmiColors
[2].rgbGreen
= 0xff;
2140 bmi
->bmiColors
[2].rgbBlue
= 0xff;
2142 dib4
= CreateDIBSection(hdc
, bmi
, DIB_RGB_COLORS
, NULL
, NULL
, 0);
2144 bmi
->bmiHeader
.biBitCount
= 32;
2146 dib32
= CreateDIBSection(hdc
, bmi
, DIB_RGB_COLORS
, NULL
, NULL
, 0);
2148 /* add 32 first then 8. This won't set the color table */
2149 ret
= ImageList_Add(himl
, dib32
, NULL
);
2150 ok(ret
== 0, "got %d\n", ret
);
2151 ret
= ImageList_Add(himl
, dib8
, NULL
);
2152 ok(ret
== 1, "got %d\n", ret
);
2154 check_color_table("add 32, 8", hdc
, himl
, ilc
, default_table
, NULL
);
2156 /* since the previous _Adds didn't set the color table, this one will */
2157 ret
= ImageList_Remove(himl
, -1);
2158 ok(ret
, "got %d\n", ret
);
2159 ret
= ImageList_Add(himl
, dib8
, NULL
);
2160 ok(ret
== 0, "got %d\n", ret
);
2162 memset(rgb
, 0, sizeof(rgb
));
2163 rgb
[0].rgbRed
= 0xff;
2164 rgb
[1].rgbGreen
= 0xff;
2165 rgb
[2].rgbBlue
= 0xff;
2166 check_color_table("remove all, add 8", hdc
, himl
, ilc
, rgb
, default_table
);
2168 /* remove all, add 4. Color table remains the same since it's inplicitly
2169 been set by the previous _Add */
2170 ret
= ImageList_Remove(himl
, -1);
2171 ok(ret
, "got %d\n", ret
);
2172 ret
= ImageList_Add(himl
, dib4
, NULL
);
2173 ok(ret
== 0, "got %d\n", ret
);
2174 check_color_table("remove all, add 4", hdc
, himl
, ilc
, rgb
, default_table
);
2176 ImageList_Destroy(himl
);
2177 himl
= ImageList_Create(16, 16, ilc
, 0, 3);
2178 ok(himl
!= NULL
, "got %p\n", himl
);
2181 ret
= ImageList_Add(himl
, dib4
, NULL
);
2182 ok(ret
== 0, "got %d\n", ret
);
2184 memset(rgb
, 0, 16 * sizeof(rgb
[0]));
2185 rgb
[0].rgbRed
= 0xff;
2186 rgb
[0].rgbBlue
= 0xff;
2187 rgb
[1].rgbRed
= 0xff;
2188 rgb
[1].rgbGreen
= 0xff;
2189 rgb
[2].rgbGreen
= 0xff;
2190 rgb
[2].rgbBlue
= 0xff;
2191 memcpy(rgb
+ 16, default_table
+ 16, 240 * sizeof(rgb
[0]));
2193 check_color_table("add 4", hdc
, himl
, ilc
, rgb
, default_table
);
2195 ImageList_Destroy(himl
);
2196 himl
= ImageList_Create(16, 16, ilc
, 0, 3);
2197 ok(himl
!= NULL
, "got %p\n", himl
);
2199 /* set color table, add 8 */
2200 ret
= ImageList_Remove(himl
, -1);
2201 ok(ret
, "got %d\n", ret
);
2202 memset(rgb
, 0, sizeof(rgb
));
2203 rgb
[0].rgbRed
= 0xcc;
2204 rgb
[1].rgbBlue
= 0xcc;
2205 ret
= pImageList_SetColorTable(himl
, 0, 2, rgb
);
2206 ok(ret
== 2, "got %d\n", ret
);
2207 /* the table is set, so this doesn't change it */
2208 ret
= ImageList_Add(himl
, dib8
, NULL
);
2209 ok(ret
== 0, "got %d\n", ret
);
2211 memcpy(rgb
+ 2, default_table
+ 2, 254 * sizeof(rgb
[0]));
2212 check_color_table("SetColorTable", hdc
, himl
, ilc
, rgb
, NULL
);
2214 DeleteObject(dib32
);
2218 ImageList_Destroy(himl
);
2221 static void test_copy(void)
2223 HIMAGELIST dst
, src
;
2227 dst
= ImageList_Create(5, 11, ILC_COLOR
, 1, 1);
2228 count
= ImageList_GetImageCount(dst
);
2229 ok(!count
, "ImageList not empty.\n");
2230 src
= createImageList(7, 13);
2231 count
= ImageList_GetImageCount(src
);
2232 ok(count
> 2, "Tests need an ImageList with more than 2 images\n");
2234 /* ImageList_Copy() cannot copy between two ImageLists */
2235 ret
= ImageList_Copy(dst
, 0, src
, 2, ILCF_MOVE
);
2236 ok(!ret
, "ImageList_Copy() should have returned FALSE\n");
2237 count
= ImageList_GetImageCount(dst
);
2238 ok(count
== 0, "Expected no image in dst ImageList, got %d\n", count
);
2240 ImageList_Destroy(dst
);
2241 ImageList_Destroy(src
);
2244 static void test_IImageList_Clone(void)
2246 IImageList
*imgl
, *imgl2
;
2251 himl
= ImageList_Create(16, 16, ILC_COLOR16
, 0, 3);
2252 imgl
= (IImageList
*)himl
;
2256 /* crashes on native */
2257 IImageList_Clone(imgl
, &IID_IImageList
, NULL
);
2260 hr
= IImageList_Clone(imgl
, &IID_IImageList
, (void**)&imgl2
);
2261 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2262 ref
= IImageList_Release(imgl2
);
2263 ok(ref
== 0, "got %u\n", ref
);
2265 IImageList_Release(imgl
);
2268 static void test_IImageList_GetBkColor(void)
2275 himl
= ImageList_Create(16, 16, ILC_COLOR16
, 0, 3);
2276 imgl
= (IImageList
*)himl
;
2280 /* crashes on native */
2281 IImageList_GetBkColor(imgl
, NULL
);
2284 hr
= IImageList_GetBkColor(imgl
, &color
);
2285 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2287 IImageList_Release(imgl
);
2290 static void test_IImageList_SetBkColor(void)
2297 himl
= ImageList_Create(16, 16, ILC_COLOR16
, 0, 3);
2298 imgl
= (IImageList
*)himl
;
2302 /* crashes on native */
2303 IImageList_SetBkColor(imgl
, RGB(0, 0, 0), NULL
);
2306 hr
= IImageList_SetBkColor(imgl
, CLR_NONE
, &color
);
2307 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2309 hr
= IImageList_SetBkColor(imgl
, CLR_NONE
, &color
);
2310 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2313 hr
= IImageList_GetBkColor(imgl
, &color
);
2314 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2315 ok(color
== CLR_NONE
, "got %x\n", color
);
2317 IImageList_Release(imgl
);
2320 static void test_IImageList_GetImageCount(void)
2327 himl
= ImageList_Create(16, 16, ILC_COLOR16
, 0, 3);
2328 imgl
= (IImageList
*)himl
;
2332 /* crashes on native */
2333 IImageList_GetImageCount(imgl
, NULL
);
2337 hr
= IImageList_GetImageCount(imgl
, &count
);
2338 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2339 ok(count
== 0, "got %d\n", count
);
2341 IImageList_Release(imgl
);
2344 static void test_IImageList_GetIconSize(void)
2351 himl
= ImageList_Create(16, 16, ILC_COLOR16
, 0, 3);
2352 imgl
= (IImageList
*)himl
;
2354 hr
= IImageList_GetIconSize(imgl
, NULL
, NULL
);
2355 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
2357 hr
= IImageList_GetIconSize(imgl
, &cx
, NULL
);
2358 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
2360 hr
= IImageList_GetIconSize(imgl
, NULL
, &cy
);
2361 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
2363 IImageList_Release(imgl
);
2366 START_TEST(imagelist
)
2368 ULONG_PTR ctx_cookie
;
2371 HMODULE hComCtl32
= GetModuleHandleA("comctl32.dll");
2372 pImageList_Create
= NULL
; /* These are not needed for non-v6.0 tests*/
2373 pImageList_Add
= NULL
;
2374 pImageList_DrawIndirect
= (void*)GetProcAddress(hComCtl32
, "ImageList_DrawIndirect");
2375 pImageList_SetImageCount
= (void*)GetProcAddress(hComCtl32
, "ImageList_SetImageCount");
2376 pImageList_SetColorTable
= (void*)GetProcAddress(hComCtl32
, (const char*)390);
2378 hinst
= GetModuleHandleA(NULL
);
2380 InitCommonControls();
2382 test_create_destroy();
2387 test_DrawIndirect();
2389 test_merge_colors();
2390 test_imagelist_storage();
2392 test_color_table(ILC_COLOR4
);
2393 test_color_table(ILC_COLOR8
);
2396 FreeLibrary(hComCtl32
);
2398 /* Now perform v6 tests */
2400 if (!load_v6_module(&ctx_cookie
, &hCtx
))
2403 /* Reload comctl32 */
2404 hComCtl32
= LoadLibraryA("comctl32.dll");
2405 pImageList_Create
= (void*)GetProcAddress(hComCtl32
, "ImageList_Create");
2406 pImageList_Add
= (void*)GetProcAddress(hComCtl32
, "ImageList_Add");
2407 pImageList_DrawIndirect
= (void*)GetProcAddress(hComCtl32
, "ImageList_DrawIndirect");
2408 pImageList_SetImageCount
= (void*)GetProcAddress(hComCtl32
, "ImageList_SetImageCount");
2409 pImageList_CoCreateInstance
= (void*)GetProcAddress(hComCtl32
, "ImageList_CoCreateInstance");
2410 pHIMAGELIST_QueryInterface
= (void*)GetProcAddress(hComCtl32
, "HIMAGELIST_QueryInterface");
2412 CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
2415 test_ImageList_DrawIndirect();
2416 test_shell_imagelist();
2420 test_IImageList_Add_Remove();
2421 test_IImageList_Get_SetImageCount();
2422 test_IImageList_Draw();
2423 test_IImageList_Merge();
2424 test_IImageList_Clone();
2425 test_IImageList_GetBkColor();
2426 test_IImageList_SetBkColor();
2427 test_IImageList_GetImageCount();
2428 test_IImageList_GetIconSize();
2432 unload_v6_module(ctx_cookie
, hCtx
);