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
29 #include "wine/test.h"
32 static HWND hProgressParentWnd, hProgressWnd;
33 static const char progressTestClass[] = "ProgressBarTestClass";
36 /* try to make sure pending X events have been processed before continuing */
37 static void flush_events(void)
41 DWORD time = GetTickCount() + diff;
45 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min(10,diff), QS_ALLINPUT ) == WAIT_TIMEOUT) break;
46 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
47 diff = time - GetTickCount();
51 static LRESULT CALLBACK ProgressTestWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
60 return DefWindowProcA(hWnd, msg, wParam, lParam);
66 static WNDPROC progress_wndproc;
68 static RECT last_paint_rect;
70 static LRESULT CALLBACK ProgressSubclassProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
74 GetUpdateRect(hWnd, &last_paint_rect, FALSE);
76 else if (msg == WM_ERASEBKGND)
80 return CallWindowProc(progress_wndproc, hWnd, msg, wParam, lParam);
84 static void update_window(HWND hWnd)
87 ok(!GetUpdateRect(hWnd, NULL, FALSE), "GetUpdateRect must return zero after UpdateWindow\n");
91 static void init(void)
94 INITCOMMONCONTROLSEX icex;
97 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
98 icex.dwICC = ICC_PROGRESS_CLASS;
99 InitCommonControlsEx(&icex);
101 wc.style = CS_HREDRAW | CS_VREDRAW;
104 wc.hInstance = GetModuleHandleA(NULL);
106 wc.hCursor = LoadCursorA(NULL, IDC_ARROW);
107 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
108 wc.lpszMenuName = NULL;
109 wc.lpszClassName = progressTestClass;
110 wc.lpfnWndProc = ProgressTestWndProc;
117 assert(AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE));
119 hProgressParentWnd = CreateWindowExA(0, progressTestClass, "Progress Bar Test", WS_OVERLAPPEDWINDOW,
120 CW_USEDEFAULT, CW_USEDEFAULT, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, GetModuleHandleA(NULL), 0);
121 assert(hProgressParentWnd != NULL);
123 GetClientRect(hProgressParentWnd, &rect);
124 hProgressWnd = CreateWindowEx(0, PROGRESS_CLASS, "", WS_CHILD | WS_VISIBLE,
125 0, 0, rect.right, rect.bottom, hProgressParentWnd, NULL, GetModuleHandleA(NULL), 0);
126 assert(hProgressWnd != NULL);
127 progress_wndproc = (WNDPROC)SetWindowLongPtr(hProgressWnd, GWLP_WNDPROC, (LPARAM)ProgressSubclassProc);
129 ShowWindow(hProgressParentWnd, SW_SHOWNORMAL);
130 ok(GetUpdateRect(hProgressParentWnd, NULL, FALSE), "GetUpdateRect: There should be a region that needs to be updated\n");
132 update_window(hProgressParentWnd);
136 static void cleanup(void)
140 PostMessageA(hProgressParentWnd, WM_CLOSE, 0, 0);
141 while (GetMessageA(&msg,0,0,0)) {
142 TranslateMessage(&msg);
143 DispatchMessageA(&msg);
146 UnregisterClassA(progressTestClass, GetModuleHandleA(NULL));
151 * Tests if a progress bar repaints itself immediately when it receives
152 * some specific messages.
154 static void test_redraw(void)
158 SendMessageA(hProgressWnd, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
159 SendMessageA(hProgressWnd, PBM_SETPOS, 10, 0);
160 SendMessageA(hProgressWnd, PBM_SETSTEP, 20, 0);
161 update_window(hProgressWnd);
164 ok(SendMessageA(hProgressWnd, PBM_SETPOS, 50, 0) == 10, "PBM_SETPOS must return the previous position\n");
165 ok(!GetUpdateRect(hProgressWnd, NULL, FALSE), "PBM_SETPOS: The progress bar should be redrawn immediately\n");
168 ok(SendMessageA(hProgressWnd, PBM_DELTAPOS, 15, 0) == 50, "PBM_DELTAPOS must return the previous position\n");
169 ok(!GetUpdateRect(hProgressWnd, NULL, FALSE), "PBM_DELTAPOS: The progress bar should be redrawn immediately\n");
172 ok(SendMessageA(hProgressWnd, PBM_SETPOS, 80, 0) == 65, "PBM_SETPOS must return the previous position\n");
173 ok(!GetUpdateRect(hProgressWnd, NULL, FALSE), "PBM_SETPOS: The progress bar should be redrawn immediately\n");
176 ok(SendMessageA(hProgressWnd, PBM_STEPIT, 0, 0) == 80, "PBM_STEPIT must return the previous position\n");
177 ok(!GetUpdateRect(hProgressWnd, NULL, FALSE), "PBM_STEPIT: The progress bar should be redrawn immediately\n");
178 ok((UINT)SendMessageA(hProgressWnd, PBM_GETPOS, 0, 0) == 100, "PBM_GETPOS returned a wrong position\n");
180 /* PBM_SETRANGE and PBM_SETRANGE32:
181 Usually the progress bar doesn't repaint itself immediately. If the
182 position is not in the new range, it does.
183 Don't test this, it may change in future Windows versions. */
185 SendMessage(hProgressWnd, PBM_SETPOS, 0, 0);
186 update_window(hProgressWnd);
188 /* increase to 10 - no background erase required */
190 SetRectEmpty(&last_paint_rect);
191 SendMessage(hProgressWnd, PBM_SETPOS, 10, 0);
192 GetClientRect(hProgressWnd, &client_rect);
193 ok(EqualRect(&last_paint_rect, &client_rect),
194 "last_paint_rect was { %d, %d, %d, %d } instead of { %d, %d, %d, %d }\n",
195 last_paint_rect.left, last_paint_rect.top, last_paint_rect.right, last_paint_rect.bottom,
196 client_rect.left, client_rect.top, client_rect.right, client_rect.bottom);
197 update_window(hProgressWnd);
198 ok(!erased, "Progress bar shouldn't have erased the background\n");
200 /* decrease to 0 - background erase will be required */
202 SetRectEmpty(&last_paint_rect);
203 SendMessage(hProgressWnd, PBM_SETPOS, 0, 0);
204 GetClientRect(hProgressWnd, &client_rect);
205 ok(EqualRect(&last_paint_rect, &client_rect),
206 "last_paint_rect was { %d, %d, %d, %d } instead of { %d, %d, %d, %d }\n",
207 last_paint_rect.left, last_paint_rect.top, last_paint_rect.right, last_paint_rect.bottom,
208 client_rect.left, client_rect.top, client_rect.right, client_rect.bottom);
209 update_window(hProgressWnd);
210 ok(erased, "Progress bar should have erased the background\n");