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
;
127 SetRect(&rect
, 0, 0, 400, 20);
128 ret
= AdjustWindowRect(&rect
, WS_OVERLAPPEDWINDOW
, FALSE
);
129 ok(ret
, "got %d\n", ret
);
131 hProgressParentWnd
= CreateWindowExA(0, progressTestClass
, "Progress Bar Test", WS_OVERLAPPEDWINDOW
,
132 CW_USEDEFAULT
, CW_USEDEFAULT
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, NULL
, NULL
, GetModuleHandleA(NULL
), 0);
133 ok(hProgressParentWnd
!= NULL
, "failed to create parent wnd\n");
135 GetClientRect(hProgressParentWnd
, &rect
);
136 hProgressWnd
= CreateWindowExA(0, PROGRESS_CLASSA
, "", WS_CHILD
| WS_VISIBLE
,
137 0, 0, rect
.right
, rect
.bottom
, hProgressParentWnd
, NULL
, GetModuleHandleA(NULL
), 0);
138 ok(hProgressWnd
!= NULL
, "failed to create parent wnd\n");
139 progress_wndproc
= (WNDPROC
)SetWindowLongPtrA(hProgressWnd
, GWLP_WNDPROC
, (LPARAM
)progress_subclass_proc
);
141 ShowWindow(hProgressParentWnd
, SW_SHOWNORMAL
);
142 ok(GetUpdateRect(hProgressParentWnd
, NULL
, FALSE
), "GetUpdateRect: There should be a region that needs to be updated\n");
144 update_window(hProgressParentWnd
);
147 static void cleanup(void)
151 PostMessageA(hProgressParentWnd
, WM_CLOSE
, 0, 0);
152 while (GetMessageA(&msg
,0,0,0)) {
153 TranslateMessage(&msg
);
154 DispatchMessageA(&msg
);
157 UnregisterClassA(progressTestClass
, GetModuleHandleA(NULL
));
162 * Tests if a progress bar repaints itself immediately when it receives
163 * some specific messages.
165 static void test_redraw(void)
170 SendMessageA(hProgressWnd
, PBM_SETRANGE
, 0, MAKELPARAM(0, 100));
171 SendMessageA(hProgressWnd
, PBM_SETPOS
, 10, 0);
172 SendMessageA(hProgressWnd
, PBM_SETSTEP
, 20, 0);
173 update_window(hProgressWnd
);
176 ok(SendMessageA(hProgressWnd
, PBM_SETPOS
, 50, 0) == 10, "PBM_SETPOS must return the previous position\n");
177 ok(!GetUpdateRect(hProgressWnd
, NULL
, FALSE
), "PBM_SETPOS: The progress bar should be redrawn immediately\n");
180 ok(SendMessageA(hProgressWnd
, PBM_DELTAPOS
, 15, 0) == 50, "PBM_DELTAPOS must return the previous position\n");
181 ok(!GetUpdateRect(hProgressWnd
, NULL
, FALSE
), "PBM_DELTAPOS: The progress bar should be redrawn immediately\n");
184 ok(SendMessageA(hProgressWnd
, PBM_SETPOS
, 80, 0) == 65, "PBM_SETPOS must return the previous position\n");
185 ok(!GetUpdateRect(hProgressWnd
, NULL
, FALSE
), "PBM_SETPOS: The progress bar should be redrawn immediately\n");
188 ok(SendMessageA(hProgressWnd
, PBM_STEPIT
, 0, 0) == 80, "PBM_STEPIT must return the previous position\n");
189 ok(!GetUpdateRect(hProgressWnd
, NULL
, FALSE
), "PBM_STEPIT: The progress bar should be redrawn immediately\n");
190 ret
= SendMessageA(hProgressWnd
, PBM_GETPOS
, 0, 0);
192 win_skip("PBM_GETPOS needs comctl32 > 4.70\n");
194 ok(ret
== 100, "PBM_GETPOS returned a wrong position : %d\n", (UINT
)ret
);
196 /* PBM_SETRANGE and PBM_SETRANGE32:
197 Usually the progress bar doesn't repaint itself immediately. If the
198 position is not in the new range, it does.
199 Don't test this, it may change in future Windows versions. */
201 SendMessageA(hProgressWnd
, PBM_SETPOS
, 0, 0);
202 update_window(hProgressWnd
);
204 /* increase to 10 - no background erase required */
206 SetRectEmpty(&last_paint_rect
);
207 SendMessageA(hProgressWnd
, PBM_SETPOS
, 10, 0);
208 GetClientRect(hProgressWnd
, &client_rect
);
209 ok(EqualRect(&last_paint_rect
, &client_rect
),
210 "last_paint_rect was { %d, %d, %d, %d } instead of { %d, %d, %d, %d }\n",
211 last_paint_rect
.left
, last_paint_rect
.top
, last_paint_rect
.right
, last_paint_rect
.bottom
,
212 client_rect
.left
, client_rect
.top
, client_rect
.right
, client_rect
.bottom
);
213 update_window(hProgressWnd
);
214 ok(!erased
, "Progress bar shouldn't have erased the background\n");
216 /* decrease to 0 - background erase will be required */
218 SetRectEmpty(&last_paint_rect
);
219 SendMessageA(hProgressWnd
, PBM_SETPOS
, 0, 0);
220 GetClientRect(hProgressWnd
, &client_rect
);
221 ok(EqualRect(&last_paint_rect
, &client_rect
),
222 "last_paint_rect was { %d, %d, %d, %d } instead of { %d, %d, %d, %d }\n",
223 last_paint_rect
.left
, last_paint_rect
.top
, last_paint_rect
.right
, last_paint_rect
.bottom
,
224 client_rect
.left
, client_rect
.top
, client_rect
.right
, client_rect
.bottom
);
225 update_window(hProgressWnd
);
226 ok(erased
, "Progress bar should have erased the background\n");
229 static void test_setcolors(void)
234 progress
= create_progress(PBS_SMOOTH
);
236 clr
= SendMessageA(progress
, PBM_SETBARCOLOR
, 0, 0);
237 ok(clr
== CLR_DEFAULT
, "got %x\n", clr
);
239 clr
= SendMessageA(progress
, PBM_SETBARCOLOR
, 0, RGB(0, 255, 0));
240 ok(clr
== 0, "got %x\n", clr
);
242 clr
= SendMessageA(progress
, PBM_SETBARCOLOR
, 0, CLR_DEFAULT
);
243 ok(clr
== RGB(0, 255, 0), "got %x\n", clr
);
245 clr
= SendMessageA(progress
, PBM_SETBKCOLOR
, 0, 0);
246 ok(clr
== CLR_DEFAULT
, "got %x\n", clr
);
248 clr
= SendMessageA(progress
, PBM_SETBKCOLOR
, 0, RGB(255, 0, 0));
249 ok(clr
== 0, "got %x\n", clr
);
251 clr
= SendMessageA(progress
, PBM_SETBKCOLOR
, 0, CLR_DEFAULT
);
252 ok(clr
== RGB(255, 0, 0), "got %x\n", clr
);
254 DestroyWindow(progress
);