From 14d9a7c1e945afb0de958f13660a5f08cb64dfe4 Mon Sep 17 00:00:00 2001 From: Michael Stefaniuc Date: Sun, 22 Aug 2004 01:59:55 +0000 Subject: [PATCH] Test case for hotspot handling. --- dlls/comctl32/tests/.cvsignore | 1 + dlls/comctl32/tests/Makefile.in | 3 +- dlls/comctl32/tests/imagelist.c | 110 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 dlls/comctl32/tests/imagelist.c diff --git a/dlls/comctl32/tests/.cvsignore b/dlls/comctl32/tests/.cvsignore index dfb3d951d0d..9fdf7e654d5 100644 --- a/dlls/comctl32/tests/.cvsignore +++ b/dlls/comctl32/tests/.cvsignore @@ -1,4 +1,5 @@ Makefile dpa.ok +imagelist.ok tab.ok testlist.c diff --git a/dlls/comctl32/tests/Makefile.in b/dlls/comctl32/tests/Makefile.in index 574b32fb0b8..63a4e01f291 100644 --- a/dlls/comctl32/tests/Makefile.in +++ b/dlls/comctl32/tests/Makefile.in @@ -3,10 +3,11 @@ TOPOBJDIR = ../../.. SRCDIR = @srcdir@ VPATH = @srcdir@ TESTDLL = comctl32.dll -IMPORTS = comctl32 user32 +IMPORTS = comctl32 user32 gdi32 CTESTS = \ dpa.c \ + imagelist.c \ tab.c @MAKE_TEST_RULES@ diff --git a/dlls/comctl32/tests/imagelist.c b/dlls/comctl32/tests/imagelist.c new file mode 100644 index 00000000000..293c21dc4ca --- /dev/null +++ b/dlls/comctl32/tests/imagelist.c @@ -0,0 +1,110 @@ +/* Unit test suite for imagelist control. + * + * Copyright 2004 Michael Stefaniuc + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include + +#include "wine/test.h" + +HDC desktopDC; + +static HIMAGELIST createImageList(cx, cy) +{ + /* Create an ImageList and put an image into it */ + HDC hdc = CreateCompatibleDC(desktopDC); + HIMAGELIST himl = ImageList_Create(cx, cy, ILC_COLOR, 1, 1); + HBITMAP hbm = CreateCompatibleBitmap(hdc, cx, cy); + + SelectObject(hdc, hbm); + ImageList_Add(himl, hbm, NULL); + DeleteObject(hbm); + DeleteDC(hdc); + + return himl; +} + +static void testHotspot (void) +{ + struct hotspot { + int dx; + int dy; + }; + +#define SIZEX1 47 +#define SIZEY1 31 +#define SIZEX2 11 +#define SIZEY2 17 +#define HOTSPOTS_MAX 4 /* Number of entries in hotspots */ + static const struct hotspot hotspots[HOTSPOTS_MAX] = { + { 10, 7 }, + { SIZEX1, SIZEY1 }, + { -9, -8 }, + { -7, 35 } + }; + int i, j, ret; + HIMAGELIST himl1 = createImageList(SIZEX1, SIZEY1); + HIMAGELIST himl2 = createImageList(SIZEX2, SIZEY2); + + for (i = 0; i < HOTSPOTS_MAX; i++) { + for (j = 0; j < HOTSPOTS_MAX; j++) { + int dx1 = hotspots[i].dx; + int dy1 = hotspots[i].dy; + int dx2 = hotspots[j].dx; + int dy2 = hotspots[j].dy; + int correctx, correcty, newx, newy; + HIMAGELIST himlNew; + POINT ppt; + + ret = ImageList_BeginDrag(himl1, 0, dx1, dy1); + ok(ret != 0, "BeginDrag failed for { %d, %d }\n", dx1, dy1); + /* check merging the dragged image with a second image */ + ret = ImageList_SetDragCursorImage(himl2, 0, dx2, dy2); + ok(ret != 0, "SetDragCursorImage failed for {%d, %d}{%d, %d}\n", + dx1, dy1, dx2, dy2); + /* check new hotspot, it should be the same like the old one */ + himlNew = ImageList_GetDragImage(NULL, &ppt); + ok(ppt.x == dx1 && ppt.y == dy1, + "Expected drag hotspot [%d,%d] got [%ld,%ld]\n", + dx1, dy1, ppt.x, ppt.y); + /* check size of new dragged image */ + ImageList_GetIconSize(himlNew, &newx, &newy); + correctx = max(SIZEX1, max(SIZEX2 + dx2, SIZEX1 - dx2)); + correcty = max(SIZEY1, max(SIZEY2 + dy2, SIZEY1 - dy2)); + ok(newx == correctx && newy == correcty, + "Expected drag image size [%d,%d] got [%d,%d]\n", + correctx, correcty, newx, newy); + ImageList_EndDrag(); + } + } +#undef SIZEX1 +#undef SIZEY1 +#undef SIZEX2 +#undef SIZEY2 +#undef HOTSPOTS_MAX +} + +START_TEST(imagelist) +{ + desktopDC=GetDC(NULL); + + InitCommonControls(); + + testHotspot(); +} -- 2.11.4.GIT