1 /* Unit test suite for tab control.
3 * Copyright 2003 Vitaliy Margolen
4 * Copyright 2007 Hagop Hagopian
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/test.h"
28 #define DEFAULT_MIN_TAB_WIDTH 54
29 #define TAB_DEFAULT_WIDTH 96
30 #define TAB_PADDING_X 6
31 #define EXTRA_ICON_PADDING 3
34 #define expect(expected, got) ok ( expected == got, "Expected %d, got %d\n", expected, got)
35 #define expect_str(expected, got)\
36 ok ( strcmp(expected, got) == 0, "Expected '%s', got '%s'\n", expected, got)
38 #define TabWidthPadded(padd_x, num) (DEFAULT_MIN_TAB_WIDTH - (TAB_PADDING_X - (padd_x)) * num)
40 #define TabCheckSetSize(hwnd, SetWidth, SetHeight, ExpWidth, ExpHeight, Msg)\
41 SendMessage (hwnd, TCM_SETITEMSIZE, 0,\
42 (LPARAM) MAKELPARAM((SetWidth >= 0) ? SetWidth:0, (SetHeight >= 0) ? SetHeight:0));\
43 if (winetest_interactive) RedrawWindow (hwnd, NULL, 0, RDW_UPDATENOW);\
44 CheckSize(hwnd, ExpWidth, ExpHeight, Msg);
46 #define CheckSize(hwnd,width,height,msg)\
47 SendMessage (hwnd, TCM_GETITEMRECT, 0, (LPARAM) &rTab);\
48 if ((width >= 0) && (height < 0))\
49 ok (width == rTab.right - rTab.left, "%s: Expected width [%d] got [%d]\n",\
50 msg, (int)width, rTab.right - rTab.left);\
51 else if ((height >= 0) && (width < 0))\
52 ok (height == rTab.bottom - rTab.top, "%s: Expected height [%d] got [%d]\n",\
53 msg, (int)height, rTab.bottom - rTab.top);\
55 ok ((width == rTab.right - rTab.left) &&\
56 (height == rTab.bottom - rTab.top ),\
57 "%s: Expected [%d,%d] got [%d,%d]\n", msg, (int)width, (int)height,\
58 rTab.right - rTab.left, rTab.bottom - rTab.top);
60 static HFONT hFont = 0;
63 create_tabcontrol (DWORD style, DWORD mask)
67 static char text1[] = "Tab 1",
68 text2[] = "Wide Tab 2",
71 handle = CreateWindow (
74 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | TCS_FOCUSNEVER | style,
80 SetWindowLong(handle, GWL_STYLE, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | TCS_FOCUSNEVER | style);
81 SendMessage (handle, WM_SETFONT, 0, (LPARAM) hFont);
84 tcNewTab.pszText = text1;
86 SendMessage (handle, TCM_INSERTITEM, 0, (LPARAM) &tcNewTab);
87 tcNewTab.pszText = text2;
89 SendMessage (handle, TCM_INSERTITEM, 1, (LPARAM) &tcNewTab);
90 tcNewTab.pszText = text3;
92 SendMessage (handle, TCM_INSERTITEM, 2, (LPARAM) &tcNewTab);
94 if (winetest_interactive)
96 ShowWindow (handle, SW_SHOW);
97 RedrawWindow (handle, NULL, 0, RDW_UPDATENOW);
104 static HWND createFilledTabControl(DWORD style, DWORD mask, INT nTabs)
110 tabHandle = CreateWindow (
113 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | TCS_FOCUSNEVER | style,
115 NULL, NULL, NULL, 0);
119 SetWindowLong(tabHandle, GWL_STYLE, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | TCS_FOCUSNEVER | style);
120 SendMessage (tabHandle, WM_SETFONT, 0, (LPARAM) hFont);
122 tcNewTab.mask = mask;
124 for (i = 0; i < nTabs; i++)
126 char tabName[MAX_TABLEN];
128 sprintf(tabName, "Tab %d", i+1);
129 tcNewTab.pszText = tabName;
131 SendMessage (tabHandle, TCM_INSERTITEM, i, (LPARAM) &tcNewTab);
134 if (winetest_interactive)
136 ShowWindow (tabHandle, SW_SHOW);
137 RedrawWindow (tabHandle, NULL, 0, RDW_UPDATENOW);
144 static HWND create_tooltip (HWND hTab, char toolTipText[])
149 LPTSTR lptstr = toolTipText;
152 /* Creating a tooltip window*/
153 hwndTT = CreateWindowEx(
157 WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
158 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
159 hTab, NULL, 0, NULL);
165 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
167 GetClientRect (hTab, &rect);
169 /* Initialize members of toolinfo*/
170 ti.cbSize = sizeof(TOOLINFO);
171 ti.uFlags = TTF_SUBCLASS;
175 ti.lpszText = lptstr;
179 /* Add toolinfo structure to the tooltip control */
180 SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
185 static void test_tab(INT nMinTabWidth)
189 HIMAGELIST himl = ImageList_Create(21, 21, ILC_COLOR, 3, 4);
195 hwTab = create_tabcontrol(TCS_FIXEDWIDTH, TCIF_TEXT|TCIF_IMAGE);
196 SendMessage(hwTab, TCM_SETMINTABWIDTH, 0, nMinTabWidth);
199 hOldFont = SelectObject(hdc, (HFONT)SendMessage(hwTab, WM_GETFONT, 0, 0));
200 GetTextExtentPoint32A(hdc, "Tab 1", strlen("Tab 1"), &size);
201 trace("Tab1 text size: size.cx=%d size.cy=%d\n", size.cx, size.cy);
202 SelectObject(hdc, hOldFont);
203 ReleaseDC(hwTab, hdc);
205 trace (" TCS_FIXEDWIDTH tabs no icon...\n");
206 CheckSize(hwTab, TAB_DEFAULT_WIDTH, -1, "default width");
207 TabCheckSetSize(hwTab, 50, 20, 50, 20, "set size");
208 TabCheckSetSize(hwTab, 0, 1, 0, 1, "min size");
210 SendMessage(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
212 trace (" TCS_FIXEDWIDTH tabs with icon...\n");
213 TabCheckSetSize(hwTab, 50, 30, 50, 30, "set size > icon");
214 TabCheckSetSize(hwTab, 20, 20, 25, 20, "set size < icon");
215 TabCheckSetSize(hwTab, 0, 1, 25, 1, "min size");
217 DestroyWindow (hwTab);
219 hwTab = create_tabcontrol(TCS_FIXEDWIDTH | TCS_BUTTONS, TCIF_TEXT|TCIF_IMAGE);
220 SendMessage(hwTab, TCM_SETMINTABWIDTH, 0, nMinTabWidth);
222 trace (" TCS_FIXEDWIDTH buttons no icon...\n");
223 CheckSize(hwTab, TAB_DEFAULT_WIDTH, -1, "default width");
224 TabCheckSetSize(hwTab, 20, 20, 20, 20, "set size 1");
225 TabCheckSetSize(hwTab, 10, 50, 10, 50, "set size 2");
226 TabCheckSetSize(hwTab, 0, 1, 0, 1, "min size");
228 SendMessage(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
230 trace (" TCS_FIXEDWIDTH buttons with icon...\n");
231 TabCheckSetSize(hwTab, 50, 30, 50, 30, "set size > icon");
232 TabCheckSetSize(hwTab, 20, 20, 25, 20, "set size < icon");
233 TabCheckSetSize(hwTab, 0, 1, 25, 1, "min size");
234 SendMessage(hwTab, TCM_SETPADDING, 0, MAKELPARAM(4,4));
235 TabCheckSetSize(hwTab, 0, 1, 25, 1, "set padding, min size");
237 DestroyWindow (hwTab);
239 hwTab = create_tabcontrol(TCS_FIXEDWIDTH | TCS_BOTTOM, TCIF_TEXT|TCIF_IMAGE);
240 SendMessage(hwTab, TCM_SETMINTABWIDTH, 0, nMinTabWidth);
242 trace (" TCS_FIXEDWIDTH | TCS_BOTTOM tabs...\n");
243 CheckSize(hwTab, TAB_DEFAULT_WIDTH, -1, "no icon, default width");
245 TabCheckSetSize(hwTab, 20, 20, 20, 20, "no icon, set size 1");
246 TabCheckSetSize(hwTab, 10, 50, 10, 50, "no icon, set size 2");
247 TabCheckSetSize(hwTab, 0, 1, 0, 1, "no icon, min size");
249 SendMessage(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
251 TabCheckSetSize(hwTab, 50, 30, 50, 30, "with icon, set size > icon");
252 TabCheckSetSize(hwTab, 20, 20, 25, 20, "with icon, set size < icon");
253 TabCheckSetSize(hwTab, 0, 1, 25, 1, "with icon, min size");
254 SendMessage(hwTab, TCM_SETPADDING, 0, MAKELPARAM(4,4));
255 TabCheckSetSize(hwTab, 0, 1, 25, 1, "set padding, min size");
257 DestroyWindow (hwTab);
259 hwTab = create_tabcontrol(0, TCIF_TEXT|TCIF_IMAGE);
260 SendMessage(hwTab, TCM_SETMINTABWIDTH, 0, nMinTabWidth);
262 trace (" non fixed width, with text...\n");
263 CheckSize(hwTab, max(size.cx +TAB_PADDING_X*2, (nMinTabWidth < 0) ? DEFAULT_MIN_TAB_WIDTH : nMinTabWidth), -1,
264 "no icon, default width");
267 INT nTabWidth = (nMinTabWidth < 0) ? TabWidthPadded(i, 2) : nMinTabWidth;
269 SendMessage(hwTab, TCM_SETIMAGELIST, 0, 0);
270 SendMessage(hwTab, TCM_SETPADDING, 0, MAKELPARAM(i,i));
272 TabCheckSetSize(hwTab, 50, 20, max(size.cx + i*2, nTabWidth), 20, "no icon, set size");
273 TabCheckSetSize(hwTab, 0, 1, max(size.cx + i*2, nTabWidth), 1, "no icon, min size");
275 SendMessage(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
276 nTabWidth = (nMinTabWidth < 0) ? TabWidthPadded(i, 3) : nMinTabWidth;
278 TabCheckSetSize(hwTab, 50, 30, max(size.cx + 21 + i*3, nTabWidth), 30, "with icon, set size > icon");
279 TabCheckSetSize(hwTab, 20, 20, max(size.cx + 21 + i*3, nTabWidth), 20, "with icon, set size < icon");
280 TabCheckSetSize(hwTab, 0, 1, max(size.cx + 21 + i*3, nTabWidth), 1, "with icon, min size");
282 DestroyWindow (hwTab);
284 hwTab = create_tabcontrol(0, TCIF_IMAGE);
285 SendMessage(hwTab, TCM_SETMINTABWIDTH, 0, nMinTabWidth);
287 trace (" non fixed width, no text...\n");
288 CheckSize(hwTab, (nMinTabWidth < 0) ? DEFAULT_MIN_TAB_WIDTH : nMinTabWidth, -1, "no icon, default width");
291 INT nTabWidth = (nMinTabWidth < 0) ? TabWidthPadded(i, 2) : nMinTabWidth;
293 SendMessage(hwTab, TCM_SETIMAGELIST, 0, 0);
294 SendMessage(hwTab, TCM_SETPADDING, 0, MAKELPARAM(i,i));
296 TabCheckSetSize(hwTab, 50, 20, nTabWidth, 20, "no icon, set size");
297 TabCheckSetSize(hwTab, 0, 1, nTabWidth, 1, "no icon, min size");
299 SendMessage(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
300 if (i > 1 && nMinTabWidth > 0 && nMinTabWidth < DEFAULT_MIN_TAB_WIDTH)
301 nTabWidth += EXTRA_ICON_PADDING *(i-1);
303 TabCheckSetSize(hwTab, 50, 30, nTabWidth, 30, "with icon, set size > icon");
304 TabCheckSetSize(hwTab, 20, 20, nTabWidth, 20, "with icon, set size < icon");
305 TabCheckSetSize(hwTab, 0, 1, nTabWidth, 1, "with icon, min size");
308 DestroyWindow (hwTab);
310 ImageList_Destroy(himl);
314 static void test_getters_setters(INT nTabs)
321 hTab = createFilledTabControl(TCS_FIXEDWIDTH, TCIF_TEXT|TCIF_IMAGE, nTabs);
322 ok(hTab != NULL, "Failed to create tab control\n");
325 expect(DEFAULT_MIN_TAB_WIDTH, (int)SendMessage(hTab, TCM_SETMINTABWIDTH, 0, -1));
327 /* Testing GetItemCount */
328 nTabsRetrieved = SendMessage(hTab, TCM_GETITEMCOUNT, 0, 0);
329 expect(nTabs, nTabsRetrieved);
331 /* Testing GetRowCount */
332 rowCount = SendMessage(hTab, TCM_GETROWCOUNT, 0, 0);
335 /* Testing GetItemRect */
336 ok(SendMessage(hTab, TCM_GETITEMRECT, 0, (LPARAM) &rTab), "GetItemRect failed.\n");
337 CheckSize(hTab, TAB_DEFAULT_WIDTH, -1 , "Default Width");
339 /* Testing CurFocus */
343 /* Testing CurFocus with largest appropriate value */
344 SendMessage(hTab, TCM_SETCURFOCUS, nTabs-1, 0);
345 focusIndex = SendMessage(hTab, TCM_GETCURFOCUS, 0, 0);
346 expect(nTabs-1, focusIndex);
348 /* Testing CurFocus with negative value */
349 SendMessage(hTab, TCM_SETCURFOCUS, -10, 0);
350 focusIndex = SendMessage(hTab, TCM_GETCURFOCUS, 0, 0);
352 expect(-1, focusIndex);
355 /* Testing CurFocus with value larger than number of tabs */
356 focusIndex = SendMessage(hTab, TCM_SETCURSEL, 1, 0);
358 expect(-1, focusIndex);
360 SendMessage(hTab, TCM_SETCURFOCUS, nTabs+1, 0);
361 focusIndex = SendMessage(hTab, TCM_GETCURFOCUS, 0, 0);
363 expect(1, focusIndex);
371 /* Testing CurSel with largest appropriate value */
372 selectionIndex = SendMessage(hTab, TCM_SETCURSEL, nTabs-1, 0);
373 expect(1, selectionIndex);
374 selectionIndex = SendMessage(hTab, TCM_GETCURSEL, 0, 0);
375 expect(nTabs-1, selectionIndex);
377 /* Testing CurSel with negative value */
378 SendMessage(hTab, TCM_SETCURSEL, -10, 0);
379 selectionIndex = SendMessage(hTab, TCM_GETCURSEL, 0, 0);
381 expect(-1, selectionIndex);
384 /* Testing CurSel with value larger than number of tabs */
385 selectionIndex = SendMessage(hTab, TCM_SETCURSEL, 1, 0);
387 expect(-1, selectionIndex);
389 selectionIndex = SendMessage(hTab, TCM_SETCURSEL, nTabs+1, 0);
390 expect(-1, selectionIndex);
391 selectionIndex = SendMessage(hTab, TCM_GETCURFOCUS, 0, 0);
393 expect(1, selectionIndex);
397 /* Testing ExtendedStyle */
399 DWORD prevExtendedStyle;
402 /* Testing Flat Seperators */
403 extendedStyle = SendMessage(hTab, TCM_GETEXTENDEDSTYLE, 0, 0);
404 prevExtendedStyle = SendMessage(hTab, TCM_SETEXTENDEDSTYLE, 0, TCS_EX_FLATSEPARATORS);
405 expect(extendedStyle, prevExtendedStyle);
407 extendedStyle = SendMessage(hTab, TCM_GETEXTENDEDSTYLE, 0, 0);
409 expect(TCS_EX_FLATSEPARATORS, extendedStyle);
412 /* Testing Register Drop */
413 prevExtendedStyle = SendMessage(hTab, TCM_SETEXTENDEDSTYLE, 0, TCS_EX_REGISTERDROP);
414 expect(extendedStyle, prevExtendedStyle);
416 extendedStyle = SendMessage(hTab, TCM_GETEXTENDEDSTYLE, 0, 0);
418 expect(TCS_EX_REGISTERDROP, extendedStyle);
422 /* Testing UnicodeFormat */
426 unicodeFormat = SendMessage(hTab, TCM_SETUNICODEFORMAT, TRUE, 0);
428 expect(0, unicodeFormat);
430 unicodeFormat = SendMessage(hTab, TCM_GETUNICODEFORMAT, 0, 0);
431 expect(1, unicodeFormat);
433 unicodeFormat = SendMessage(hTab, TCM_SETUNICODEFORMAT, FALSE, 0);
434 expect(1, unicodeFormat);
435 unicodeFormat = SendMessage(hTab, TCM_GETUNICODEFORMAT, 0, 0);
436 expect(0, unicodeFormat);
438 unicodeFormat = SendMessage(hTab, TCM_SETUNICODEFORMAT, TRUE, 0);
439 expect(0, unicodeFormat);
442 /* Testing GetSet Item */
445 char szText[32] = "New Label";
447 tcItem.mask = TCIF_TEXT;
448 tcItem.pszText = &szText[0];
449 tcItem.cchTextMax = sizeof(szText);
451 ok ( SendMessage(hTab, TCM_SETITEM, 0, (LPARAM) &tcItem), "Setting new item failed.\n");
452 ok ( SendMessage(hTab, TCM_GETITEM, 0, (LPARAM) &tcItem), "Getting item failed.\n");
453 expect_str("New Label", tcItem.pszText);
455 ok ( SendMessage(hTab, TCM_GETITEM, 1, (LPARAM) &tcItem), "Getting item failed.\n");
456 expect_str("Tab 2", tcItem.pszText);
459 /* Testing GetSet ToolTip */
462 char toolTipText[32] = "ToolTip Text Test";
464 toolTip = create_tooltip(hTab, toolTipText);
465 SendMessage(hTab, TCM_SETTOOLTIPS, (LPARAM) toolTip, 0);
466 ok (toolTip == (HWND) SendMessage(hTab,TCM_GETTOOLTIPS,0,0), "ToolTip was set incorrectly.");
468 SendMessage(hTab, TCM_SETTOOLTIPS, (LPARAM) NULL, 0);
469 ok (NULL == (HWND) SendMessage(hTab,TCM_GETTOOLTIPS,0,0), "ToolTip was set incorrectly.");
479 lstrcpyA(logfont.lfFaceName, "Arial");
480 memset(&logfont, 0, sizeof(logfont));
481 logfont.lfHeight = -12;
482 logfont.lfWeight = FW_NORMAL;
483 logfont.lfCharSet = ANSI_CHARSET;
484 hFont = CreateFontIndirectA(&logfont);
486 InitCommonControls();
488 trace ("Testing with default MinWidth\n");
490 trace ("Testing with MinWidth set to -3\n");
492 trace ("Testing with MinWidth set to 24\n");
494 trace ("Testing with MinWidth set to 54\n");
496 trace ("Testing with MinWidth set to 94\n");
499 /* Testing getters and setters with 5 tabs */
500 test_getters_setters(5);