2 * Unit test suite for imagelist control.
4 * Copyright 2004 Michael Stefaniuc
5 * Copyright 2002 Mike McCormack for CodeWeavers
6 * Copyright 2007 Dmitry Timoshkov
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
35 #include "commctrl.h" /* must be included after objbase.h to get ImageList_Write */
37 #include "wine/test.h"
42 #define WAIT Sleep (1000)
43 #define REDRAW(hwnd) RedrawWindow (hwnd, NULL, 0, RDW_UPDATENOW)
49 #define IMAGELIST_MAGIC (('L' << 8) | 'I')
52 /* Header used by ImageList_Read() and ImageList_Write() */
53 typedef struct _ILHEAD
68 static BOOL (WINAPI
*pImageList_DrawIndirect
)(IMAGELISTDRAWPARAMS
*) = NULL
;
71 static HINSTANCE hinst
;
73 /* These macros build cursor/bitmap data in 4x4 pixel blocks */
74 #define B(x,y) ((x?0xf0:0)|(y?0xf:0))
75 #define ROW1(a,b,c,d,e,f,g,h) B(a,b),B(c,d),B(e,f),B(g,h)
76 #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), \
77 ROW1(a,b,c,d,e,f,g,h), ROW1(a,b,c,d,e,f,g,h)
78 #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)
79 #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), \
80 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), \
81 ROW2(a,b,c,d,e,f,g,h,i,j,k,l)
83 static const BYTE empty_bits
[48*48/8];
85 static const BYTE icon_bits
[32*32/8] =
87 ROW32(0,0,0,0,0,0,0,0),
88 ROW32(0,0,1,1,1,1,0,0),
89 ROW32(0,1,1,1,1,1,1,0),
90 ROW32(0,1,1,0,0,1,1,0),
91 ROW32(0,1,1,0,0,1,1,0),
92 ROW32(0,1,1,1,1,1,1,0),
93 ROW32(0,0,1,1,1,1,0,0),
94 ROW32(0,0,0,0,0,0,0,0)
97 static const BYTE bitmap_bits
[48*48/8] =
99 ROW48(0,0,0,0,0,0,0,0,0,0,0,0),
100 ROW48(0,1,1,1,1,1,1,1,1,1,1,0),
101 ROW48(0,1,1,0,0,0,0,0,0,1,1,0),
102 ROW48(0,1,0,0,0,0,0,0,1,0,1,0),
103 ROW48(0,1,0,0,0,0,0,1,0,0,1,0),
104 ROW48(0,1,0,0,0,0,1,0,0,0,1,0),
105 ROW48(0,1,0,0,0,1,0,0,0,0,1,0),
106 ROW48(0,1,0,0,1,0,0,0,0,0,1,0),
107 ROW48(0,1,0,1,0,0,0,0,0,0,1,0),
108 ROW48(0,1,1,0,0,0,0,0,0,1,1,0),
109 ROW48(0,1,1,1,1,1,1,1,1,1,1,0),
110 ROW48(0,0,0,0,0,0,0,0,0,0,0,0)
113 static HIMAGELIST
createImageList(int cx
, int cy
)
115 /* Create an ImageList and put an image into it */
116 HIMAGELIST himl
= ImageList_Create(cx
, cy
, ILC_COLOR
, 1, 1);
117 HBITMAP hbm
= CreateBitmap(48, 48, 1, 1, bitmap_bits
);
118 ImageList_Add(himl
, hbm
, NULL
);
122 static HWND
create_a_window(void)
124 char className
[] = "bmwnd";
125 char winName
[] = "Test Bitmap";
127 static int registered
= 0;
133 cls
.style
= CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
;
134 cls
.lpfnWndProc
= DefWindowProcA
;
138 cls
.hIcon
= LoadIconA (0, (LPSTR
)IDI_APPLICATION
);
139 cls
.hCursor
= LoadCursorA (0, (LPSTR
)IDC_ARROW
);
140 cls
.hbrBackground
= (HBRUSH
) GetStockObject (WHITE_BRUSH
);
141 cls
.lpszMenuName
= 0;
142 cls
.lpszClassName
= className
;
144 RegisterClassA (&cls
);
149 hWnd
= CreateWindowA (className
, winName
,
150 WS_OVERLAPPEDWINDOW
,
151 CW_USEDEFAULT
, CW_USEDEFAULT
, 300, 300, 0,
155 ShowWindow (hWnd
, SW_SHOW
);
163 static HDC
show_image(HWND hwnd
, HIMAGELIST himl
, int idx
, int size
,
164 LPCSTR loc
, BOOL clear
)
168 if (!himl
) return NULL
;
170 SetWindowText(hwnd
, loc
);
172 ImageList_Draw(himl
, idx
, hdc
, 0, 0, ILD_TRANSPARENT
);
179 BitBlt(hdc
, 0, 0, size
, size
, hdc
, size
+1, size
+1, SRCCOPY
);
180 ReleaseDC(hwnd
, hdc
);
187 /* Useful for checking differences */
189 static void dump_bits(const BYTE
*p
, const BYTE
*q
, int size
)
195 for (i
= 0; i
< size
* 2; i
++)
198 for (j
= 0; j
< size
; j
++)
199 printf("%c%c", p
[j
] & 0xf0 ? 'X' : ' ', p
[j
] & 0xf ? 'X' : ' ');
201 for (j
= 0; j
< size
; j
++)
202 printf("%c%c", q
[j
] & 0xf0 ? 'X' : ' ', q
[j
] & 0xf ? 'X' : ' ');
211 static void check_bits(HWND hwnd
, HIMAGELIST himl
, int idx
, int size
,
212 const BYTE
*checkbits
, LPCSTR loc
)
215 BYTE bits
[100*100/8];
222 memset(bits
, 0, sizeof(bits
));
223 hdc
= show_image(hwnd
, himl
, idx
, size
, loc
, FALSE
);
225 c
= GetPixel(hdc
, 0, 0);
227 for (y
= 0; y
< size
; y
++)
229 for (x
= 0; x
< size
; x
++)
232 if (GetPixel(hdc
, x
, y
) != c
) bits
[i
] |= (0x80 >> (x
& 0x7));
236 BitBlt(hdc
, 0, 0, size
, size
, hdc
, size
+1, size
+1, SRCCOPY
);
237 ReleaseDC(hwnd
, hdc
);
239 ok (memcmp(bits
, checkbits
, (size
* size
)/8) == 0,
240 "%s: bits different\n", loc
);
241 if (memcmp(bits
, checkbits
, (size
* size
)/8))
242 dump_bits(bits
, checkbits
, size
);
246 static void testHotspot (void)
257 #define HOTSPOTS_MAX 4 /* Number of entries in hotspots */
258 static const struct hotspot hotspots
[HOTSPOTS_MAX
] = {
265 HIMAGELIST himl1
= createImageList(SIZEX1
, SIZEY1
);
266 HIMAGELIST himl2
= createImageList(SIZEX2
, SIZEY2
);
267 HWND hwnd
= create_a_window();
270 for (i
= 0; i
< HOTSPOTS_MAX
; i
++) {
271 for (j
= 0; j
< HOTSPOTS_MAX
; j
++) {
272 int dx1
= hotspots
[i
].dx
;
273 int dy1
= hotspots
[i
].dy
;
274 int dx2
= hotspots
[j
].dx
;
275 int dy2
= hotspots
[j
].dy
;
276 int correctx
, correcty
, newx
, newy
;
281 ret
= ImageList_BeginDrag(himl1
, 0, dx1
, dy1
);
282 ok(ret
!= 0, "BeginDrag failed for { %d, %d }\n", dx1
, dy1
);
283 sprintf(loc
, "BeginDrag (%d,%d)\n", i
, j
);
284 show_image(hwnd
, himl1
, 0, max(SIZEX1
, SIZEY1
), loc
, TRUE
);
286 /* check merging the dragged image with a second image */
287 ret
= ImageList_SetDragCursorImage(himl2
, 0, dx2
, dy2
);
288 ok(ret
!= 0, "SetDragCursorImage failed for {%d, %d}{%d, %d}\n",
290 sprintf(loc
, "SetDragCursorImage (%d,%d)\n", i
, j
);
291 show_image(hwnd
, himl2
, 0, max(SIZEX2
, SIZEY2
), loc
, TRUE
);
293 /* check new hotspot, it should be the same like the old one */
294 himlNew
= ImageList_GetDragImage(NULL
, &ppt
);
295 ok(ppt
.x
== dx1
&& ppt
.y
== dy1
,
296 "Expected drag hotspot [%d,%d] got [%d,%d]\n",
297 dx1
, dy1
, ppt
.x
, ppt
.y
);
298 /* check size of new dragged image */
299 ImageList_GetIconSize(himlNew
, &newx
, &newy
);
300 correctx
= max(SIZEX1
, max(SIZEX2
+ dx2
, SIZEX1
- dx2
));
301 correcty
= max(SIZEY1
, max(SIZEY2
+ dy2
, SIZEY1
- dy2
));
302 ok(newx
== correctx
&& newy
== correcty
,
303 "Expected drag image size [%d,%d] got [%d,%d]\n",
304 correctx
, correcty
, newx
, newy
);
305 sprintf(loc
, "GetDragImage (%d,%d)\n", i
, j
);
306 show_image(hwnd
, himlNew
, 0, max(correctx
, correcty
), loc
, TRUE
);
315 ImageList_Destroy(himl2
);
316 ImageList_Destroy(himl1
);
320 static BOOL
DoTest1(void)
328 /* create an imagelist to play with */
329 himl
= ImageList_Create(84,84,0x10,0,3);
330 ok(himl
!=0,"failed to create imagelist\n");
332 /* load the icons to add to the image list */
333 hicon1
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
334 ok(hicon1
!= 0, "no hicon1\n");
335 hicon2
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
336 ok(hicon2
!= 0, "no hicon2\n");
337 hicon3
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
338 ok(hicon3
!= 0, "no hicon3\n");
340 /* remove when nothing exists */
341 ok(!ImageList_Remove(himl
,0),"removed nonexistent icon\n");
342 /* removing everything from an empty imagelist should succeed */
343 ok(ImageList_RemoveAll(himl
),"removed nonexistent icon\n");
346 ok(0==ImageList_AddIcon(himl
, hicon1
),"failed to add icon1\n");
347 ok(1==ImageList_AddIcon(himl
, hicon2
),"failed to add icon2\n");
348 ok(2==ImageList_AddIcon(himl
, hicon3
),"failed to add icon3\n");
350 /* remove an index out of range */
351 ok(!ImageList_Remove(himl
,4711),"removed nonexistent icon\n");
354 ok(ImageList_Remove(himl
,0),"can't remove 0\n");
355 ok(ImageList_Remove(himl
,0),"can't remove 0\n");
356 ok(ImageList_Remove(himl
,0),"can't remove 0\n");
358 /* remove one extra */
359 ok(!ImageList_Remove(himl
,0),"removed nonexistent icon\n");
361 /* check SetImageCount/GetImageCount */
362 ok(ImageList_SetImageCount(himl
, 3), "couldn't increase image count\n");
363 ok(ImageList_GetImageCount(himl
) == 3, "invalid image count after increase\n");
364 ok(ImageList_SetImageCount(himl
, 1), "couldn't decrease image count\n");
365 ok(ImageList_GetImageCount(himl
) == 1, "invalid image count after decrease to 1\n");
366 ok(ImageList_SetImageCount(himl
, 0), "couldn't decrease image count\n");
367 ok(ImageList_GetImageCount(himl
) == 0, "invalid image count after decrease to 0\n");
370 ok(ImageList_Destroy(himl
),"destroy imagelist failed\n");
372 ok(DestroyIcon(hicon1
),"icon 1 wasn't deleted\n");
373 ok(DestroyIcon(hicon2
),"icon 2 wasn't deleted\n");
374 ok(DestroyIcon(hicon3
),"icon 3 wasn't deleted\n");
379 static BOOL
DoTest2(void)
387 /* create an imagelist to play with */
388 himl
= ImageList_Create(84,84,0x10,0,3);
389 ok(himl
!=0,"failed to create imagelist\n");
391 /* load the icons to add to the image list */
392 hicon1
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
393 ok(hicon1
!= 0, "no hicon1\n");
394 hicon2
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
395 ok(hicon2
!= 0, "no hicon2\n");
396 hicon3
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
397 ok(hicon3
!= 0, "no hicon3\n");
400 ok(0==ImageList_AddIcon(himl
, hicon1
),"failed to add icon1\n");
401 ok(1==ImageList_AddIcon(himl
, hicon2
),"failed to add icon2\n");
402 ok(2==ImageList_AddIcon(himl
, hicon3
),"failed to add icon3\n");
405 ok(ImageList_Destroy(himl
),"destroy imagelist failed\n");
407 ok(DestroyIcon(hicon1
),"icon 1 wasn't deleted\n");
408 ok(DestroyIcon(hicon2
),"icon 2 wasn't deleted\n");
409 ok(DestroyIcon(hicon3
),"icon 3 wasn't deleted\n");
414 static BOOL
DoTest3(void)
422 IMAGELISTDRAWPARAMS imldp
;
426 if (!pImageList_DrawIndirect
)
428 HMODULE hComCtl32
= LoadLibraryA("comctl32.dll");
429 pImageList_DrawIndirect
= (void*)GetProcAddress(hComCtl32
, "ImageList_DrawIndirect");
430 if (!pImageList_DrawIndirect
)
432 trace("ImageList_DrawIndirect not available, skipping test\n");
437 hwndfortest
= create_a_window();
438 hdc
= GetDC(hwndfortest
);
439 ok(hdc
!=NULL
, "couldn't get DC\n");
441 /* create an imagelist to play with */
442 himl
= ImageList_Create(48,48,0x10,0,3);
443 ok(himl
!=0,"failed to create imagelist\n");
445 /* load the icons to add to the image list */
446 hbm1
= CreateBitmap(48, 48, 1, 1, bitmap_bits
);
447 ok(hbm1
!= 0, "no bitmap 1\n");
448 hbm2
= CreateBitmap(48, 48, 1, 1, bitmap_bits
);
449 ok(hbm2
!= 0, "no bitmap 2\n");
450 hbm3
= CreateBitmap(48, 48, 1, 1, bitmap_bits
);
451 ok(hbm3
!= 0, "no bitmap 3\n");
454 ok(0==ImageList_Add(himl
, hbm1
, 0),"failed to add bitmap 1\n");
455 ok(1==ImageList_Add(himl
, hbm2
, 0),"failed to add bitmap 2\n");
457 ok(ImageList_SetImageCount(himl
,3),"Setimage count failed\n");
458 /*ok(2==ImageList_Add(himl, hbm3, NULL),"failed to add bitmap 3\n"); */
459 ok(ImageList_Replace(himl
, 2, hbm3
, 0),"failed to replace bitmap 3\n");
461 memset(&imldp
, 0, sizeof (imldp
));
462 ok(!pImageList_DrawIndirect(&imldp
), "zero data succeeded!\n");
463 imldp
.cbSize
= sizeof (imldp
);
464 ok(!pImageList_DrawIndirect(&imldp
), "zero hdc succeeded!\n");
466 ok(!pImageList_DrawIndirect(&imldp
),"zero himl succeeded!\n");
468 if (!pImageList_DrawIndirect(&imldp
))
470 /* Earlier versions of native comctl32 use a smaller structure */
471 imldp
.cbSize
-= 3 * sizeof(DWORD
);
472 ok(pImageList_DrawIndirect(&imldp
),"DrawIndirect should succeed\n");
477 imldp
.fStyle
= SRCCOPY
;
478 imldp
.rgbBk
= CLR_DEFAULT
;
479 imldp
.rgbFg
= CLR_DEFAULT
;
482 ok(pImageList_DrawIndirect(&imldp
),"should succeed\n");
484 ok(pImageList_DrawIndirect(&imldp
),"should succeed\n");
486 ok(pImageList_DrawIndirect(&imldp
),"should succeed\n");
488 ok(!pImageList_DrawIndirect(&imldp
),"should fail\n");
491 ok(ImageList_Remove(himl
, 0), "removing 1st bitmap\n");
492 ok(ImageList_Remove(himl
, 0), "removing 2nd bitmap\n");
493 ok(ImageList_Remove(himl
, 0), "removing 3rd bitmap\n");
496 ok(ImageList_Destroy(himl
),"destroy imagelist failed\n");
498 /* bitmaps should not be deleted by the imagelist */
499 ok(DeleteObject(hbm1
),"bitmap 1 can't be deleted\n");
500 ok(DeleteObject(hbm2
),"bitmap 2 can't be deleted\n");
501 ok(DeleteObject(hbm3
),"bitmap 3 can't be deleted\n");
503 ReleaseDC(hwndfortest
, hdc
);
504 DestroyWindow(hwndfortest
);
509 static void testMerge(void)
511 HIMAGELIST himl1
, himl2
, hmerge
;
513 HWND hwnd
= create_a_window();
515 himl1
= ImageList_Create(32,32,0,0,3);
516 ok(himl1
!= NULL
,"failed to create himl1\n");
518 himl2
= ImageList_Create(32,32,0,0,3);
519 ok(himl2
!= NULL
,"failed to create himl2\n");
521 hicon1
= CreateIcon(hinst
, 32, 32, 1, 1, icon_bits
, icon_bits
);
522 ok(hicon1
!= NULL
, "failed to create hicon1\n");
524 if (!himl1
|| !himl2
|| !hicon1
)
527 ok(0==ImageList_AddIcon(himl2
, hicon1
),"add icon1 to himl2 failed\n");
528 check_bits(hwnd
, himl2
, 0, 32, icon_bits
, "add icon1 to himl2");
530 /* If himl1 has no images, merge still succeeds */
531 hmerge
= ImageList_Merge(himl1
, -1, himl2
, 0, 0, 0);
532 ok(hmerge
!= NULL
, "merge himl1,-1 failed\n");
533 check_bits(hwnd
, hmerge
, 0, 32, empty_bits
, "merge himl1,-1");
534 if (hmerge
) ImageList_Destroy(hmerge
);
536 hmerge
= ImageList_Merge(himl1
, 0, himl2
, 0, 0, 0);
537 ok(hmerge
!= NULL
,"merge himl1,0 failed\n");
538 check_bits(hwnd
, hmerge
, 0, 32, empty_bits
, "merge himl1,0");
539 if (hmerge
) ImageList_Destroy(hmerge
);
541 /* Same happens if himl2 is empty */
542 ImageList_Destroy(himl2
);
543 himl2
= ImageList_Create(32,32,0,0,3);
544 ok(himl2
!= NULL
,"failed to recreate himl2\n");
548 hmerge
= ImageList_Merge(himl1
, -1, himl2
, -1, 0, 0);
549 ok(hmerge
!= NULL
, "merge himl2,-1 failed\n");
550 check_bits(hwnd
, hmerge
, 0, 32, empty_bits
, "merge himl2,-1");
551 if (hmerge
) ImageList_Destroy(hmerge
);
553 hmerge
= ImageList_Merge(himl1
, -1, himl2
, 0, 0, 0);
554 ok(hmerge
!= NULL
, "merge himl2,0 failed\n");
555 check_bits(hwnd
, hmerge
, 0, 32, empty_bits
, "merge himl2,0");
556 if (hmerge
) ImageList_Destroy(hmerge
);
558 /* Now try merging an image with itself */
559 ok(0==ImageList_AddIcon(himl2
, hicon1
),"re-add icon1 to himl2 failed\n");
561 hmerge
= ImageList_Merge(himl2
, 0, himl2
, 0, 0, 0);
562 ok(hmerge
!= NULL
, "merge himl2 with itself failed\n");
563 check_bits(hwnd
, hmerge
, 0, 32, empty_bits
, "merge himl2 with itself");
564 if (hmerge
) ImageList_Destroy(hmerge
);
566 /* Try merging 2 different image lists */
567 ok(0==ImageList_AddIcon(himl1
, hicon1
),"add icon1 to himl1 failed\n");
569 hmerge
= ImageList_Merge(himl1
, 0, himl2
, 0, 0, 0);
570 ok(hmerge
!= NULL
, "merge himl1 with himl2 failed\n");
571 check_bits(hwnd
, hmerge
, 0, 32, empty_bits
, "merge himl1 with himl2");
572 if (hmerge
) ImageList_Destroy(hmerge
);
574 hmerge
= ImageList_Merge(himl1
, 0, himl2
, 0, 8, 16);
575 ok(hmerge
!= NULL
, "merge himl1 with himl2 8,16 failed\n");
576 check_bits(hwnd
, hmerge
, 0, 32, empty_bits
, "merge himl1 with himl2, 8,16");
577 if (hmerge
) ImageList_Destroy(hmerge
);
579 ImageList_Destroy(himl1
);
580 ImageList_Destroy(himl2
);
585 /*********************** imagelist storage test ***************************/
592 char *iml_data
; /* written imagelist data */
596 static HRESULT STDMETHODCALLTYPE
Test_Stream_QueryInterface(
605 static ULONG STDMETHODCALLTYPE
Test_Stream_AddRef(
612 static ULONG STDMETHODCALLTYPE
Test_Stream_Release(
619 static HRESULT STDMETHODCALLTYPE
Test_Stream_Read(
629 static BOOL
allocate_storage(struct my_IStream
*my_is
, ULONG add
)
631 my_is
->iml_data_size
+= add
;
633 if (!my_is
->iml_data
)
634 my_is
->iml_data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, my_is
->iml_data_size
);
636 my_is
->iml_data
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, my_is
->iml_data
, my_is
->iml_data_size
);
638 return my_is
->iml_data
? TRUE
: FALSE
;
641 static HRESULT STDMETHODCALLTYPE
Test_Stream_Write(
647 struct my_IStream
*my_is
= (struct my_IStream
*)This
;
648 ULONG current_iml_data_size
= my_is
->iml_data_size
;
650 if (!allocate_storage(my_is
, cb
)) return E_FAIL
;
652 memcpy(my_is
->iml_data
+ current_iml_data_size
, pv
, cb
);
653 if (pcbWritten
) *pcbWritten
= cb
;
658 static HRESULT STDMETHODCALLTYPE
Test_Stream_Seek(
660 LARGE_INTEGER dlibMove
,
662 ULARGE_INTEGER
* plibNewPosition
)
668 static HRESULT STDMETHODCALLTYPE
Test_Stream_SetSize(
670 ULARGE_INTEGER libNewSize
)
676 static HRESULT STDMETHODCALLTYPE
Test_Stream_CopyTo(
680 ULARGE_INTEGER
* pcbRead
,
681 ULARGE_INTEGER
* pcbWritten
)
687 static HRESULT STDMETHODCALLTYPE
Test_Stream_Commit(
689 DWORD grfCommitFlags
)
695 static HRESULT STDMETHODCALLTYPE
Test_Stream_Revert(
702 static HRESULT STDMETHODCALLTYPE
Test_Stream_LockRegion(
704 ULARGE_INTEGER libOffset
,
712 static HRESULT STDMETHODCALLTYPE
Test_Stream_UnlockRegion(
714 ULARGE_INTEGER libOffset
,
722 static HRESULT STDMETHODCALLTYPE
Test_Stream_Stat(
731 static HRESULT STDMETHODCALLTYPE
Test_Stream_Clone(
739 static const IStreamVtbl Test_Stream_Vtbl
=
741 Test_Stream_QueryInterface
,
751 Test_Stream_LockRegion
,
752 Test_Stream_UnlockRegion
,
757 static struct my_IStream Test_Stream
= { { &Test_Stream_Vtbl
}, 0, 0 };
759 static INT
DIB_GetWidthBytes( int width
, int bpp
)
765 case 1: words
= (width
+ 31) / 32; break;
766 case 4: words
= (width
+ 7) / 8; break;
767 case 8: words
= (width
+ 3) / 4; break;
769 case 16: words
= (width
+ 1) / 2; break;
770 case 24: words
= (width
* 3 + 3)/4; break;
771 case 32: words
= width
; break;
775 trace("Unknown depth %d, please report.\n", bpp
);
782 static void check_bitmap_data(const char *bm_data
, ULONG bm_data_size
,
783 INT width
, INT height
, INT bpp
,
786 const BITMAPFILEHEADER
*bmfh
= (const BITMAPFILEHEADER
*)bm_data
;
787 const BITMAPINFOHEADER
*bmih
= (const BITMAPINFOHEADER
*)(bm_data
+ sizeof(*bmfh
));
788 ULONG hdr_size
, image_size
;
790 hdr_size
= sizeof(*bmfh
) + sizeof(*bmih
);
791 if (bmih
->biBitCount
<= 8) hdr_size
+= (1 << bpp
) * sizeof(RGBQUAD
);
793 ok(bmfh
->bfType
== (('M' << 8) | 'B'), "wrong bfType 0x%02x\n", bmfh
->bfType
);
794 ok(bmfh
->bfSize
== hdr_size
, "wrong bfSize 0x%02x\n", bmfh
->bfSize
);
795 ok(bmfh
->bfReserved1
== 0, "wrong bfReserved1 0x%02x\n", bmfh
->bfReserved1
);
796 ok(bmfh
->bfReserved2
== 0, "wrong bfReserved2 0x%02x\n", bmfh
->bfReserved2
);
797 ok(bmfh
->bfOffBits
== hdr_size
, "wrong bfOffBits 0x%02x\n", bmfh
->bfOffBits
);
799 ok(bmih
->biSize
== sizeof(*bmih
), "wrong biSize %d\n", bmih
->biSize
);
800 ok(bmih
->biWidth
== width
, "wrong biWidth %d (expected %d)\n", bmih
->biWidth
, width
);
801 ok(bmih
->biHeight
== height
, "wrong biHeight %d (expected %d)\n", bmih
->biHeight
, height
);
802 ok(bmih
->biPlanes
== 1, "wrong biPlanes %d\n", bmih
->biPlanes
);
803 ok(bmih
->biBitCount
== bpp
, "wrong biBitCount %d\n", bmih
->biBitCount
);
805 image_size
= DIB_GetWidthBytes(bmih
->biWidth
, bmih
->biBitCount
) * bmih
->biHeight
;
806 ok(bmih
->biSizeImage
== image_size
, "wrong biSizeImage %u\n", bmih
->biSizeImage
);
811 sprintf(fname
, "bmp_%s.bmp", comment
);
812 f
= fopen(fname
, "wb");
813 fwrite(bm_data
, 1, bm_data_size
, f
);
819 static void check_ilhead_data(const char *ilh_data
, INT cx
, INT cy
, INT cur
, INT max
)
821 ILHEAD
*ilh
= (ILHEAD
*)ilh_data
;
823 ok(ilh
->usMagic
== IMAGELIST_MAGIC
, "wrong usMagic %4x (expected %02x)\n", ilh
->usMagic
, IMAGELIST_MAGIC
);
824 ok(ilh
->usVersion
== 0x101, "wrong usVersion %x (expected 0x101)\n", ilh
->usVersion
);
825 ok(ilh
->cCurImage
== cur
, "wrong cCurImage %d (expected %d)\n", ilh
->cCurImage
, cur
);
826 ok(ilh
->cMaxImage
== max
, "wrong cMaxImage %d (expected %d)\n", ilh
->cMaxImage
, max
);
827 ok(ilh
->cGrow
== 4, "wrong cGrow %d (expected 4)\n", ilh
->cGrow
);
828 ok(ilh
->cx
== cx
, "wrong cx %d (expected %d)\n", ilh
->cx
, cx
);
829 ok(ilh
->cy
== cy
, "wrong cy %d (expected %d)\n", ilh
->cy
, cy
);
830 ok(ilh
->bkcolor
== CLR_NONE
, "wrong bkcolor %x\n", ilh
->bkcolor
);
831 ok(ilh
->flags
== ILC_COLOR24
, "wrong flags %04x\n", ilh
->flags
);
832 ok(ilh
->ovls
[0] == -1, "wrong ovls[0] %04x\n", ilh
->ovls
[0]);
833 ok(ilh
->ovls
[1] == -1, "wrong ovls[1] %04x\n", ilh
->ovls
[1]);
834 ok(ilh
->ovls
[2] == -1, "wrong ovls[2] %04x\n", ilh
->ovls
[2]);
835 ok(ilh
->ovls
[3] == -1, "wrong ovls[3] %04x\n", ilh
->ovls
[3]);
838 static HBITMAP
create_bitmap(INT cx
, INT cy
, COLORREF color
, const char *comment
)
841 char bmibuf
[sizeof(BITMAPINFO
) + 256 * sizeof(RGBQUAD
)];
842 BITMAPINFO
*bmi
= (BITMAPINFO
*)bmibuf
;
843 HBITMAP hbmp
, hbmp_old
;
845 RECT rc
= { 0, 0, cx
, cy
};
847 hdc
= CreateCompatibleDC(0);
849 memset(bmi
, 0, sizeof(*bmi
));
850 bmi
->bmiHeader
.biSize
= sizeof(bmi
->bmiHeader
);
851 bmi
->bmiHeader
.biHeight
= cx
;
852 bmi
->bmiHeader
.biWidth
= cy
;
853 bmi
->bmiHeader
.biBitCount
= 24;
854 bmi
->bmiHeader
.biPlanes
= 1;
855 bmi
->bmiHeader
.biCompression
= BI_RGB
;
856 hbmp
= CreateDIBSection(hdc
, bmi
, DIB_RGB_COLORS
, NULL
, NULL
, 0);
858 hbmp_old
= SelectObject(hdc
, hbmp
);
860 hbrush
= CreateSolidBrush(color
);
861 FillRect(hdc
, &rc
, hbrush
);
862 DeleteObject(hbrush
);
864 DrawText(hdc
, comment
, -1, &rc
, DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
);
866 SelectObject(hdc
, hbmp_old
);
872 static void image_list_init(HIMAGELIST himl
)
878 #define add_bitmap(grey) \
879 sprintf(comment, "%d", n++); \
880 hbm = create_bitmap(BMP_CX, BMP_CX, RGB((grey),(grey),(grey)), comment); \
881 ImageList_Add(himl, hbm, NULL);
883 add_bitmap(255); add_bitmap(170); add_bitmap(85); add_bitmap(0);
884 add_bitmap(0); add_bitmap(85); add_bitmap(170); add_bitmap(255);
885 add_bitmap(255); add_bitmap(170); add_bitmap(85); add_bitmap(0);
886 add_bitmap(0); add_bitmap(85); add_bitmap(170); add_bitmap(255);
887 add_bitmap(255); add_bitmap(170); add_bitmap(85); add_bitmap(0);
888 add_bitmap(0); add_bitmap(85); add_bitmap(170); add_bitmap(255);
892 #define iml_clear_stream_data() \
893 HeapFree(GetProcessHeap(), 0, Test_Stream.iml_data); \
894 Test_Stream.iml_data = NULL; \
895 Test_Stream.iml_data_size = 0;
897 static void check_iml_data(HIMAGELIST himl
, INT cx
, INT cy
, INT cur
, INT max
,
898 INT width
, INT height
, INT bpp
, const char *comment
)
902 ret
= ImageList_GetImageCount(himl
);
903 ok(ret
== cur
, "expected cur %d got %d\n", cur
, ret
);
905 ret
= ImageList_GetIconSize(himl
, &cxx
, &cyy
);
906 ok(ret
, "ImageList_GetIconSize failed\n");
907 ok(cxx
== cx
, "wrong cx %d (expected %d)\n", cxx
, cx
);
908 ok(cyy
== cy
, "wrong cy %d (expected %d)\n", cyy
, cy
);
910 iml_clear_stream_data();
911 ret
= ImageList_Write(himl
, &Test_Stream
.is
);
912 ok(ret
, "ImageList_Write failed\n");
914 ok(Test_Stream
.iml_data
!= 0, "ImageList_Write didn't write any data\n");
915 ok(Test_Stream
.iml_data_size
> sizeof(ILHEAD
), "ImageList_Write wrote not enough data\n");
917 check_ilhead_data(Test_Stream
.iml_data
, cx
, cy
, cur
, max
);
918 check_bitmap_data(Test_Stream
.iml_data
+ sizeof(ILHEAD
),
919 Test_Stream
.iml_data_size
- sizeof(ILHEAD
),
920 width
, height
, bpp
, comment
);
923 static void test_imagelist_storage(void)
928 himl
= ImageList_Create(BMP_CX
, BMP_CX
, ILC_COLOR24
, 1, 1);
929 ok(himl
!= 0, "ImageList_Create failed\n");
931 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 2, BMP_CX
* 4, BMP_CX
* 1, 24, "empty");
933 image_list_init(himl
);
934 check_iml_data(himl
, BMP_CX
, BMP_CX
, 24, 27, BMP_CX
* 4, BMP_CX
* 7, 24, "orig");
936 ret
= ImageList_Remove(himl
, 4);
937 ok(ret
, "ImageList_Remove failed\n");
938 check_iml_data(himl
, BMP_CX
, BMP_CX
, 23, 27, BMP_CX
* 4, BMP_CX
* 7, 24, "1");
940 ret
= ImageList_Remove(himl
, 5);
941 ok(ret
, "ImageList_Remove failed\n");
942 check_iml_data(himl
, BMP_CX
, BMP_CX
, 22, 27, BMP_CX
* 4, BMP_CX
* 7, 24, "2");
944 ret
= ImageList_Remove(himl
, 6);
945 ok(ret
, "ImageList_Remove failed\n");
946 check_iml_data(himl
, BMP_CX
, BMP_CX
, 21, 27, BMP_CX
* 4, BMP_CX
* 7, 24, "3");
948 ret
= ImageList_Remove(himl
, 7);
949 ok(ret
, "ImageList_Remove failed\n");
950 check_iml_data(himl
, BMP_CX
, BMP_CX
, 20, 27, BMP_CX
* 4, BMP_CX
* 7, 24, "4");
952 ret
= ImageList_Remove(himl
, -2);
953 ok(!ret
, "ImageList_Remove(-2) should fail\n");
954 check_iml_data(himl
, BMP_CX
, BMP_CX
, 20, 27, BMP_CX
* 4, BMP_CX
* 7, 24, "5");
956 ret
= ImageList_Remove(himl
, 20);
957 ok(!ret
, "ImageList_Remove(20) should fail\n");
958 check_iml_data(himl
, BMP_CX
, BMP_CX
, 20, 27, BMP_CX
* 4, BMP_CX
* 7, 24, "6");
960 ret
= ImageList_Remove(himl
, -1);
961 ok(ret
, "ImageList_Remove(-1) failed\n");
962 check_iml_data(himl
, BMP_CX
, BMP_CX
, 0, 4, BMP_CX
* 4, BMP_CX
* 1, 24, "7");
964 ret
= ImageList_Destroy(himl
);
965 ok(ret
, "ImageList_Destroy failed\n");
967 iml_clear_stream_data();
970 START_TEST(imagelist
)
972 desktopDC
=GetDC(NULL
);
973 hinst
= GetModuleHandleA(NULL
);
975 InitCommonControls();
982 test_imagelist_storage();