1 /* Unit tests for the progress bar control.
3 * Copyright 2005 Michael Kaufmann
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.
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.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/test.h"
31 static HWND hProgressParentWnd
, hProgressWnd
;
32 static const char progressTestClass
[] = "ProgressBarTestClass";
34 static HWND
create_progress(DWORD style
)
36 return CreateWindowExA(0, PROGRESS_CLASSA
, "", WS_VISIBLE
| style
,
37 0, 0, 100, 20, NULL
, NULL
, GetModuleHandleA(NULL
), 0);
40 /* try to make sure pending X events have been processed before continuing */
41 static void flush_events(void)
45 DWORD time
= GetTickCount() + diff
;
49 if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, min(10,diff
), QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
50 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
51 diff
= time
- GetTickCount();
55 static LRESULT CALLBACK
progress_test_wnd_proc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
64 return DefWindowProcA(hWnd
, msg
, wParam
, lParam
);
70 static WNDPROC progress_wndproc
;
72 static RECT last_paint_rect
;
74 static LRESULT CALLBACK
progress_subclass_proc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
78 GetUpdateRect(hWnd
, &last_paint_rect
, FALSE
);
80 else if (msg
== WM_ERASEBKGND
)
84 return CallWindowProcA(progress_wndproc
, hWnd
, msg
, wParam
, lParam
);
88 static void update_window(HWND hWnd
)
91 ok(!GetUpdateRect(hWnd
, NULL
, FALSE
), "GetUpdateRect must return zero after UpdateWindow\n");
95 static void init(void)
98 BOOL (WINAPI
*pInitCommonControlsEx
)(const INITCOMMONCONTROLSEX
*);
103 hComctl32
= GetModuleHandleA("comctl32.dll");
104 pInitCommonControlsEx
= (void*)GetProcAddress(hComctl32
, "InitCommonControlsEx");
105 if (pInitCommonControlsEx
)
107 INITCOMMONCONTROLSEX iccex
;
108 iccex
.dwSize
= sizeof(iccex
);
109 iccex
.dwICC
= ICC_PROGRESS_CLASS
;
110 pInitCommonControlsEx(&iccex
);
113 InitCommonControls();
115 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
118 wc
.hInstance
= GetModuleHandleA(NULL
);
120 wc
.hCursor
= LoadCursorA(NULL
, (LPCSTR
)IDC_ARROW
);
121 wc
.hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
122 wc
.lpszMenuName
= NULL
;
123 wc
.lpszClassName
= progressTestClass
;
124 wc
.lpfnWndProc
= progress_test_wnd_proc
;
131 ret
= AdjustWindowRect(&rect
, WS_OVERLAPPEDWINDOW
, FALSE
);
132 ok(ret
, "got %d\n", ret
);
134 hProgressParentWnd
= CreateWindowExA(0, progressTestClass
, "Progress Bar Test", WS_OVERLAPPEDWINDOW
,
135 CW_USEDEFAULT
, CW_USEDEFAULT
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, NULL
, NULL
, GetModuleHandleA(NULL
), 0);
136 ok(hProgressParentWnd
!= NULL
, "failed to create parent wnd\n");
138 GetClientRect(hProgressParentWnd
, &rect
);
139 hProgressWnd
= CreateWindowExA(0, PROGRESS_CLASSA
, "", WS_CHILD
| WS_VISIBLE
,
140 0, 0, rect
.right
, rect
.bottom
, hProgressParentWnd
, NULL
, GetModuleHandleA(NULL
), 0);
141 ok(hProgressWnd
!= NULL
, "failed to create parent wnd\n");
142 progress_wndproc
= (WNDPROC
)SetWindowLongPtrA(hProgressWnd
, GWLP_WNDPROC
, (LPARAM
)progress_subclass_proc
);
144 ShowWindow(hProgressParentWnd
, SW_SHOWNORMAL
);
145 ok(GetUpdateRect(hProgressParentWnd
, NULL
, FALSE
), "GetUpdateRect: There should be a region that needs to be updated\n");
147 update_window(hProgressParentWnd
);
150 static void cleanup(void)
154 PostMessageA(hProgressParentWnd
, WM_CLOSE
, 0, 0);
155 while (GetMessageA(&msg
,0,0,0)) {
156 TranslateMessage(&msg
);
157 DispatchMessageA(&msg
);
160 UnregisterClassA(progressTestClass
, GetModuleHandleA(NULL
));
165 * Tests if a progress bar repaints itself immediately when it receives
166 * some specific messages.
168 static void test_redraw(void)
173 SendMessageA(hProgressWnd
, PBM_SETRANGE
, 0, MAKELPARAM(0, 100));
174 SendMessageA(hProgressWnd
, PBM_SETPOS
, 10, 0);
175 SendMessageA(hProgressWnd
, PBM_SETSTEP
, 20, 0);
176 update_window(hProgressWnd
);
179 ok(SendMessageA(hProgressWnd
, PBM_SETPOS
, 50, 0) == 10, "PBM_SETPOS must return the previous position\n");
180 ok(!GetUpdateRect(hProgressWnd
, NULL
, FALSE
), "PBM_SETPOS: The progress bar should be redrawn immediately\n");
183 ok(SendMessageA(hProgressWnd
, PBM_DELTAPOS
, 15, 0) == 50, "PBM_DELTAPOS must return the previous position\n");
184 ok(!GetUpdateRect(hProgressWnd
, NULL
, FALSE
), "PBM_DELTAPOS: The progress bar should be redrawn immediately\n");
187 ok(SendMessageA(hProgressWnd
, PBM_SETPOS
, 80, 0) == 65, "PBM_SETPOS must return the previous position\n");
188 ok(!GetUpdateRect(hProgressWnd
, NULL
, FALSE
), "PBM_SETPOS: The progress bar should be redrawn immediately\n");
191 ok(SendMessageA(hProgressWnd
, PBM_STEPIT
, 0, 0) == 80, "PBM_STEPIT must return the previous position\n");
192 ok(!GetUpdateRect(hProgressWnd
, NULL
, FALSE
), "PBM_STEPIT: The progress bar should be redrawn immediately\n");
193 ret
= SendMessageA(hProgressWnd
, PBM_GETPOS
, 0, 0);
195 win_skip("PBM_GETPOS needs comctl32 > 4.70\n");
197 ok(ret
== 100, "PBM_GETPOS returned a wrong position : %d\n", (UINT
)ret
);
199 /* PBM_SETRANGE and PBM_SETRANGE32:
200 Usually the progress bar doesn't repaint itself immediately. If the
201 position is not in the new range, it does.
202 Don't test this, it may change in future Windows versions. */
204 SendMessageA(hProgressWnd
, PBM_SETPOS
, 0, 0);
205 update_window(hProgressWnd
);
207 /* increase to 10 - no background erase required */
209 SetRectEmpty(&last_paint_rect
);
210 SendMessageA(hProgressWnd
, PBM_SETPOS
, 10, 0);
211 GetClientRect(hProgressWnd
, &client_rect
);
212 ok(EqualRect(&last_paint_rect
, &client_rect
),
213 "last_paint_rect was { %d, %d, %d, %d } instead of { %d, %d, %d, %d }\n",
214 last_paint_rect
.left
, last_paint_rect
.top
, last_paint_rect
.right
, last_paint_rect
.bottom
,
215 client_rect
.left
, client_rect
.top
, client_rect
.right
, client_rect
.bottom
);
216 update_window(hProgressWnd
);
217 ok(!erased
, "Progress bar shouldn't have erased the background\n");
219 /* decrease to 0 - background erase will be required */
221 SetRectEmpty(&last_paint_rect
);
222 SendMessageA(hProgressWnd
, PBM_SETPOS
, 0, 0);
223 GetClientRect(hProgressWnd
, &client_rect
);
224 ok(EqualRect(&last_paint_rect
, &client_rect
),
225 "last_paint_rect was { %d, %d, %d, %d } instead of { %d, %d, %d, %d }\n",
226 last_paint_rect
.left
, last_paint_rect
.top
, last_paint_rect
.right
, last_paint_rect
.bottom
,
227 client_rect
.left
, client_rect
.top
, client_rect
.right
, client_rect
.bottom
);
228 update_window(hProgressWnd
);
229 ok(erased
, "Progress bar should have erased the background\n");
232 static void test_setcolors(void)
237 progress
= create_progress(PBS_SMOOTH
);
239 clr
= SendMessageA(progress
, PBM_SETBARCOLOR
, 0, 0);
240 ok(clr
== CLR_DEFAULT
, "got %x\n", clr
);
242 clr
= SendMessageA(progress
, PBM_SETBARCOLOR
, 0, RGB(0, 255, 0));
243 ok(clr
== 0, "got %x\n", clr
);
245 clr
= SendMessageA(progress
, PBM_SETBARCOLOR
, 0, CLR_DEFAULT
);
246 ok(clr
== RGB(0, 255, 0), "got %x\n", clr
);
248 clr
= SendMessageA(progress
, PBM_SETBKCOLOR
, 0, 0);
249 ok(clr
== CLR_DEFAULT
, "got %x\n", clr
);
251 clr
= SendMessageA(progress
, PBM_SETBKCOLOR
, 0, RGB(255, 0, 0));
252 ok(clr
== 0, "got %x\n", clr
);
254 clr
= SendMessageA(progress
, PBM_SETBKCOLOR
, 0, CLR_DEFAULT
);
255 ok(clr
== RGB(255, 0, 0), "got %x\n", clr
);
257 DestroyWindow(progress
);