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 static LRESULT CALLBACK ProgressTestWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
45 return DefWindowProcA(hWnd, msg, wParam, lParam);
51 static WNDPROC progress_wndproc;
53 static RECT last_paint_rect;
55 static LRESULT CALLBACK ProgressSubclassProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
59 GetUpdateRect(hWnd, &last_paint_rect, FALSE);
61 else if (msg == WM_ERASEBKGND)
65 return CallWindowProc(progress_wndproc, hWnd, msg, wParam, lParam);
69 static void update_window(HWND hWnd)
72 ok(!GetUpdateRect(hWnd, NULL, FALSE), "GetUpdateRect must return zero after UpdateWindow\n");
76 static void init(void)
79 INITCOMMONCONTROLSEX icex;
82 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
83 icex.dwICC = ICC_PROGRESS_CLASS;
84 InitCommonControlsEx(&icex);
86 wc.style = CS_HREDRAW | CS_VREDRAW;
89 wc.hInstance = GetModuleHandleA(NULL);
91 wc.hCursor = LoadCursorA(NULL, MAKEINTRESOURCEA(IDC_ARROW));
92 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
93 wc.lpszMenuName = NULL;
94 wc.lpszClassName = progressTestClass;
95 wc.lpfnWndProc = ProgressTestWndProc;
102 assert(AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE));
104 hProgressParentWnd = CreateWindowExA(0, progressTestClass, "Progress Bar Test", WS_OVERLAPPEDWINDOW,
105 CW_USEDEFAULT, CW_USEDEFAULT, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, GetModuleHandleA(NULL), 0);
106 assert(hProgressParentWnd != NULL);
108 GetClientRect(hProgressParentWnd, &rect);
109 hProgressWnd = CreateWindowEx(0, PROGRESS_CLASS, "", WS_CHILD | WS_VISIBLE,
110 0, 0, rect.right, rect.bottom, hProgressParentWnd, NULL, GetModuleHandleA(NULL), 0);
111 assert(hProgressWnd != NULL);
112 progress_wndproc = (WNDPROC)SetWindowLongPtr(hProgressWnd, GWLP_WNDPROC, (LPARAM)ProgressSubclassProc);
114 ShowWindow(hProgressParentWnd, SW_SHOWNORMAL);
115 ok(GetUpdateRect(hProgressParentWnd, NULL, FALSE), "GetUpdateRect: There should be a region that needs to be updated\n");
116 update_window(hProgressParentWnd);
120 static void cleanup(void)
124 PostMessageA(hProgressParentWnd, WM_CLOSE, 0, 0);
125 while (GetMessageA(&msg,0,0,0)) {
126 TranslateMessage(&msg);
127 DispatchMessageA(&msg);
130 UnregisterClassA(progressTestClass, GetModuleHandleA(NULL));
135 * Tests if a progress bar repaints itself immediately when it receives
136 * some specific messages.
138 static void test_redraw(void)
142 SendMessageA(hProgressWnd, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
143 SendMessageA(hProgressWnd, PBM_SETPOS, 10, 0);
144 SendMessageA(hProgressWnd, PBM_SETSTEP, 20, 0);
145 update_window(hProgressWnd);
148 ok(SendMessageA(hProgressWnd, PBM_SETPOS, 50, 0) == 10, "PBM_SETPOS must return the previous position\n");
149 ok(!GetUpdateRect(hProgressWnd, NULL, FALSE), "PBM_SETPOS: The progress bar should be redrawn immediately\n");
152 ok(SendMessageA(hProgressWnd, PBM_DELTAPOS, 15, 0) == 50, "PBM_DELTAPOS must return the previous position\n");
153 ok(!GetUpdateRect(hProgressWnd, NULL, FALSE), "PBM_DELTAPOS: The progress bar should be redrawn immediately\n");
156 ok(SendMessageA(hProgressWnd, PBM_SETPOS, 80, 0) == 65, "PBM_SETPOS must return the previous position\n");
157 ok(!GetUpdateRect(hProgressWnd, NULL, FALSE), "PBM_SETPOS: The progress bar should be redrawn immediately\n");
160 ok(SendMessageA(hProgressWnd, PBM_STEPIT, 0, 0) == 80, "PBM_STEPIT must return the previous position\n");
161 ok(!GetUpdateRect(hProgressWnd, NULL, FALSE), "PBM_STEPIT: The progress bar should be redrawn immediately\n");
162 ok((UINT)SendMessageA(hProgressWnd, PBM_GETPOS, 0, 0) == 100, "PBM_GETPOS returned a wrong position\n");
164 /* PBM_SETRANGE and PBM_SETRANGE32:
165 Usually the progress bar doesn't repaint itself immediately. If the
166 position is not in the new range, it does.
167 Don't test this, it may change in future Windows versions. */
169 SendMessage(hProgressWnd, PBM_SETPOS, 0, 0);
170 update_window(hProgressWnd);
172 /* increase to 10 - no background erase required */
174 SetRectEmpty(&last_paint_rect);
175 SendMessage(hProgressWnd, PBM_SETPOS, 10, 0);
176 GetClientRect(hProgressWnd, &client_rect);
177 ok(EqualRect(&last_paint_rect, &client_rect),
178 "last_paint_rect was { %d, %d, %d, %d } instead of { %d, %d, %d, %d }\n",
179 last_paint_rect.left, last_paint_rect.top, last_paint_rect.right, last_paint_rect.bottom,
180 client_rect.left, client_rect.top, client_rect.right, client_rect.bottom);
181 update_window(hProgressWnd);
182 ok(!erased, "Progress bar shouldn't have erased the background\n");
184 /* decrease to 0 - background erase will be required */
186 SetRectEmpty(&last_paint_rect);
187 SendMessage(hProgressWnd, PBM_SETPOS, 0, 0);
188 GetClientRect(hProgressWnd, &client_rect);
189 ok(EqualRect(&last_paint_rect, &client_rect),
190 "last_paint_rect was { %d, %d, %d, %d } instead of { %d, %d, %d, %d }\n",
191 last_paint_rect.left, last_paint_rect.top, last_paint_rect.right, last_paint_rect.bottom,
192 client_rect.left, client_rect.top, client_rect.right, client_rect.bottom);
193 update_window(hProgressWnd);
194 ok(erased, "Progress bar should have erased the background\n");