Constify strings.
[wine] / dlls / comctl32 / tests / tab.c
1 /* Unit test suite for tab control.
2  *
3  * Copyright 2003 Vitaliy Margolen
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19
20 #include <assert.h>
21 #include <windows.h>
22 #include <commctrl.h>
23
24 #include "wine/test.h"
25
26 #undef VISIBLE
27
28 #define TAB_DEFAULT_WIDTH 96
29 #define TAB_PADDING_X 2
30 #define TAB_PADDING_Y 2
31
32 #ifdef VISIBLE
33 #define WAIT Sleep (1000)
34 #define REDRAW(hwnd) RedrawWindow (hwnd, NULL, 0, RDW_UPDATENOW)
35 #else
36 #define WAIT
37 #define REDRAW(hwnd)
38 #endif
39
40 HWND
41 create_tabcontrol (DWORD style)
42 {
43     HWND handle;
44     TCITEM tcNewTab;
45
46     handle = CreateWindow (
47         WC_TABCONTROLA,
48         "TestTab",
49         WS_CLIPSIBLINGS | WS_CLIPCHILDREN | TCS_FOCUSNEVER | style,
50         0, 0, 300, 100,
51         NULL, NULL, NULL, 0);
52
53     assert (handle);
54
55     tcNewTab.mask = TCIF_TEXT | TCIF_IMAGE;
56     tcNewTab.pszText = "Tab 1";
57     tcNewTab.iImage = 0;
58     SendMessage (handle, TCM_INSERTITEM, 0, (LPARAM) &tcNewTab);
59     tcNewTab.pszText = "Wide Tab 2";
60     tcNewTab.iImage = 1;
61     SendMessage (handle, TCM_INSERTITEM, 1, (LPARAM) &tcNewTab);
62     tcNewTab.pszText = "T 3";
63     tcNewTab.iImage = 2;
64     SendMessage (handle, TCM_INSERTITEM, 2, (LPARAM) &tcNewTab);
65
66 #ifdef VISIBLE
67     ShowWindow (handle, SW_SHOW);
68 #endif
69     REDRAW(handle);
70     WAIT;
71
72     return handle;
73 }
74
75 void CheckSize(HWND hwnd, INT width, INT height)
76 {
77     RECT rTab;
78
79     SendMessage (hwnd, TCM_GETITEMRECT, 1, (LPARAM) &rTab);
80     /*trace ("Got (%ld,%ld)-(%ld,%ld)\n", rTab.left, rTab.top, rTab.right, rTab.bottom);*/
81     if ((width  >= 0) && (height < 0))
82         ok (width  == rTab.right  - rTab.left, "Expected [%d] got [%ld]",  width,  rTab.right  - rTab.left);
83     else if ((height >= 0) && (width  < 0))
84         ok (height == rTab.bottom - rTab.top,  "Expected [%d] got [%ld]",  height, rTab.bottom - rTab.top);
85     else
86         ok ((width  == rTab.right  - rTab.left) &&
87             (height == rTab.bottom - rTab.top ),
88             "Expected [%d,%d] got [%ld,%ld]", width, height, rTab.right - rTab.left, rTab.bottom - rTab.top);
89 }
90
91 void TabCheckSetSize(HWND hwnd, INT SetWidth, INT SetHeight, INT ExpWidth, INT ExpHeight)
92 {
93     SendMessage (hwnd, TCM_SETITEMSIZE, 0,
94         (LPARAM) MAKELPARAM((SetWidth >= 0) ? SetWidth:0, (SetHeight >= 0) ? SetHeight:0));
95     REDRAW(hwnd);
96     CheckSize(hwnd, ExpWidth, ExpHeight);
97     WAIT;
98 }
99
100 START_TEST(tab)
101 {
102     HWND hwTab;
103     HIMAGELIST himl = ImageList_Create(21, 21, ILC_COLOR, 3, 4);
104
105     InitCommonControls();
106
107
108     hwTab = create_tabcontrol(TCS_FIXEDWIDTH);
109
110     trace ("Testing TCS_FIXEDWIDTH tabs no icon...\n");
111     trace ("  default width...\n");
112     CheckSize(hwTab, TAB_DEFAULT_WIDTH, -1);
113     trace ("  set size...\n");
114     TabCheckSetSize(hwTab, 50, 20, 50, 20);
115     WAIT;
116     trace ("  min size...\n");
117     TabCheckSetSize(hwTab, 0, 1, 0, 1);
118     WAIT;
119
120     SendMessage(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
121
122     trace ("Testing TCS_FIXEDWIDTH tabs with icon...\n");
123     trace ("  set size > icon...\n");
124     TabCheckSetSize(hwTab, 50, 30, 50, 30);
125     WAIT;
126     trace ("  set size < icon...\n");
127     TabCheckSetSize(hwTab, 20, 20, 25, 20);
128     WAIT;
129     trace ("  min size...\n");
130     TabCheckSetSize(hwTab, 0, 1, 25, 1);
131     WAIT;
132
133     DestroyWindow (hwTab);
134
135     trace ("Testing TCS_FIXEDWIDTH buttons no icon...\n");
136     hwTab = create_tabcontrol(TCS_FIXEDWIDTH | TCS_BUTTONS);
137
138     trace ("  default width...\n");
139     CheckSize(hwTab, TAB_DEFAULT_WIDTH, -1);
140     trace ("  set size 1...\n");
141     TabCheckSetSize(hwTab, 20, 20, 20, 20);
142     trace ("  set size 2...\n");
143     TabCheckSetSize(hwTab, 10, 50, 10, 50);
144     trace ("  min size...\n");
145     TabCheckSetSize(hwTab, 0, 1, 0, 1);
146
147     SendMessage(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
148
149     trace ("Testing TCS_FIXEDWIDTH buttons with icon...\n");
150     trace ("  set size > icon...\n");
151     TabCheckSetSize(hwTab, 50, 30, 50, 30);
152     trace ("  set size < icon...\n");
153     TabCheckSetSize(hwTab, 20, 20, 25, 20);
154     trace ("  min size...\n");
155     TabCheckSetSize(hwTab, 0, 1, 25, 1);
156
157     trace (" Add padding...\n");
158     SendMessage(hwTab, TCM_SETPADDING, 0, MAKELPARAM(4,4));
159     trace ("  min size...\n");
160     TabCheckSetSize(hwTab, 0, 1, 25, 1);
161     WAIT;
162     
163     DestroyWindow (hwTab);
164     ImageList_Destroy(himl);
165 }