comctl32: Proper fix redrawing the trackbar background with themes enabled.
[wine] / dlls / comctl32 / tests / status.c
1 /* Unit test suite for status control.
2  *
3  * Copyright 2007 Google (Lei Zhang)
4  * Copyright 2007 Alex Arazi
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <assert.h>
22 #include <windows.h>
23 #include <commctrl.h>
24
25 #include "wine/test.h"
26
27 #define expect(expected,got) ok (expected == got,"Expected %d, got %d\n",expected,got);
28
29 static HINSTANCE hinst;
30
31 static HWND create_status_control(DWORD style, DWORD exstyle)
32 {
33     HWND hWndStatus;
34
35     /* make the control */
36     hWndStatus = CreateWindowEx(exstyle, STATUSCLASSNAME, NULL, style,
37         /* placement */
38         0, 0, 300, 20,
39         /* parent, etc */
40         NULL, NULL, hinst, NULL);
41     assert (hWndStatus);
42     return hWndStatus;
43 }
44
45 static void test_status_control(void)
46 {
47     HWND hWndStatus;
48     int r;
49     int nParts[] = {50, 150, -1};
50     int checkParts[] = {0, 0, 0};
51     int borders[] = {0, 0, 0};
52     RECT rc;
53     CHAR charArray[20];
54     HICON hIcon;
55
56     hWndStatus = create_status_control(WS_VISIBLE, 0);
57
58     /* Divide into parts and set text */
59     r = SendMessage(hWndStatus, SB_SETPARTS, 3, (long)nParts);
60     expect(TRUE,r);
61     r = SendMessage(hWndStatus, SB_SETTEXT, 0, (LPARAM)"First");
62     expect(TRUE,r);
63     r = SendMessage(hWndStatus, SB_SETTEXT, 1, (LPARAM)"Second");
64     expect(TRUE,r);
65     r = SendMessage(hWndStatus, SB_SETTEXT, 2, (LPARAM)"Third");
66     expect(TRUE,r);
67
68     /* Get RECT Information */
69     r = SendMessage(hWndStatus, SB_GETRECT, 0, (LPARAM)&rc);
70     expect(TRUE,r);
71     expect(2,rc.top);
72     /* The rc.bottom test is system dependent
73     expect(22,rc.bottom); */
74     expect(0,rc.left);
75     expect(50,rc.right);
76     r = SendMessage(hWndStatus, SB_GETRECT, -1, (LPARAM)&rc);
77     expect(FALSE,r);
78     r = SendMessage(hWndStatus, SB_GETRECT, 3, (LPARAM)&rc);
79     expect(FALSE,r);
80     /* Get text length and text */
81     r = SendMessage(hWndStatus, SB_GETTEXTLENGTH, 2, 0);
82     expect(5,LOWORD(r));
83     expect(0,HIWORD(r));
84     r = SendMessage(hWndStatus, SB_GETTEXT, 2, (LPARAM) charArray);
85     ok(strcmp(charArray,"Third") == 0, "Expected Third, got %s\n", charArray);
86     expect(5,LOWORD(r));
87     expect(0,HIWORD(r));
88
89     /* Get parts and borders */
90     r = SendMessage(hWndStatus, SB_GETPARTS, 3, (long)checkParts);
91     ok(r == 3, "Expected 3, got %d\n", r);
92     expect(50,checkParts[0]);
93     expect(150,checkParts[1]);
94     expect(-1,checkParts[2]);
95     r = SendMessage(hWndStatus, SB_GETBORDERS, 0, (long)borders);
96     ok(r == TRUE, "Expected TRUE, got %d\n", r);
97     expect(0,borders[0]);
98     expect(2,borders[1]);
99     expect(2,borders[2]);
100
101     /* Test resetting text with different characters */
102     r = SendMessage(hWndStatus, SB_SETTEXT, 0, (LPARAM)"First@Again");
103     expect(TRUE,r);
104     r = SendMessage(hWndStatus, SB_SETTEXT, 1, (LPARAM)"InvalidChars\\7\7");
105         expect(TRUE,r);
106     r = SendMessage(hWndStatus, SB_SETTEXT, 2, (LPARAM)"InvalidChars\\n\n");
107         expect(TRUE,r);
108
109     /* Get text again */
110     r = SendMessage(hWndStatus, SB_GETTEXT, 0, (LPARAM) charArray);
111     ok(strcmp(charArray,"First@Again") == 0, "Expected First@Again, got %s\n", charArray);
112     expect(11,LOWORD(r));
113     expect(0,HIWORD(r));
114     r = SendMessage(hWndStatus, SB_GETTEXT, 1, (LPARAM) charArray);
115     todo_wine
116     {
117         ok(strcmp(charArray,"InvalidChars\\7 ") == 0, "Expected InvalidChars\\7 , got %s\n", charArray);
118     }
119     expect(15,LOWORD(r));
120     expect(0,HIWORD(r));
121     r = SendMessage(hWndStatus, SB_GETTEXT, 2, (LPARAM) charArray);
122     todo_wine
123     {
124         ok(strcmp(charArray,"InvalidChars\\n ") == 0, "Expected InvalidChars\\n , got %s\n", charArray);
125     }
126     expect(15,LOWORD(r));
127     expect(0,HIWORD(r));
128
129     /* Set background color */
130     r = SendMessage(hWndStatus, SB_SETBKCOLOR , 0, RGB(255,0,0));
131     expect(CLR_DEFAULT,r);
132     r = SendMessage(hWndStatus, SB_SETBKCOLOR , 0, CLR_DEFAULT);
133     expect(RGB(255,0,0),r);
134
135     /* Add an icon to the status bar */
136     hIcon = LoadIcon(NULL, IDI_QUESTION);
137     r = SendMessage(hWndStatus, SB_SETICON, 1, (LPARAM) NULL);
138     ok(r != 0, "Expected non-zero, got %d\n", r);
139     r = SendMessage(hWndStatus, SB_SETICON, 1, (LPARAM) hIcon);
140     ok(r != 0, "Expected non-zero, got %d\n", r);
141     r = SendMessage(hWndStatus, SB_SETICON, 1, (LPARAM) NULL);
142     ok(r != 0, "Expected non-zero, got %d\n", r);
143
144     /* Set the Unicode format */
145     r = SendMessage(hWndStatus, SB_SETUNICODEFORMAT, FALSE, 0);
146     r = SendMessage(hWndStatus, SB_GETUNICODEFORMAT, 0, 0);
147     expect(FALSE,r);
148     r = SendMessage(hWndStatus, SB_SETUNICODEFORMAT, TRUE, 0);
149     expect(FALSE,r);
150     r = SendMessage(hWndStatus, SB_GETUNICODEFORMAT, 0, 0);
151     expect(TRUE,r);
152
153     /* Reset number of parts */
154     r = SendMessage(hWndStatus, SB_SETPARTS, 2, (long)nParts);
155     expect(TRUE,r);
156
157     /* Set the minimum height and get rectangle information again */
158     SendMessage(hWndStatus, SB_SETMINHEIGHT, 50, (LPARAM) 0);
159     r = SendMessage(hWndStatus, WM_SIZE, 0, (LPARAM) 0);
160     expect(0,r);
161     r = SendMessage(hWndStatus, SB_GETRECT, 0, (LPARAM)&rc);
162     expect(TRUE,r);
163     expect(2,rc.top);
164     /* The rc.bottom test is system dependent
165     expect(22,rc.bottom); */
166     expect(0,rc.left);
167     expect(50,rc.right);
168     r = SendMessage(hWndStatus, SB_GETRECT, -1, (LPARAM)&rc);
169     expect(FALSE,r);
170     r = SendMessage(hWndStatus, SB_GETRECT, 3, (LPARAM)&rc);
171     expect(FALSE,r);
172
173     /* Set the ToolTip text */
174     todo_wine
175     {
176         SendMessage(hWndStatus, SB_SETTIPTEXT, 0,(LPARAM) "Tooltip Text");
177         SendMessage(hWndStatus, SB_GETTIPTEXT, MAKEWPARAM (0, 20),(LPARAM) charArray);
178         ok(strcmp(charArray,"Tooltip Text") == 0, "Expected Tooltip Text, got %s\n", charArray);
179     }
180
181     /* Make simple */
182     SendMessage(hWndStatus, SB_SIMPLE, TRUE, 0);
183     r = SendMessage(hWndStatus, SB_ISSIMPLE, 0, 0);
184     expect(TRUE,r);
185
186     DestroyWindow(hWndStatus);
187 }
188
189 START_TEST(status)
190 {
191     hinst = GetModuleHandleA(NULL);
192
193     InitCommonControls();
194
195     test_status_control();
196 }