new 818051de2c8769029049ce3d36c6b856f47496c9
[wine/hacks.git] / dlls / comctl32 / tests / progress.c
blobcfc039350e0c434baa253a0c680ffea43e936a05
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
20 #include <assert.h>
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wingdi.h"
26 #include "winuser.h"
27 #include "commctrl.h"
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)
38 switch(msg) {
40 case WM_DESTROY:
41 PostQuitMessage(0);
42 break;
44 default:
45 return DefWindowProcA(hWnd, msg, wParam, lParam);
48 return 0L;
51 static WNDPROC progress_wndproc;
52 static BOOL erased;
53 static RECT last_paint_rect;
55 static LRESULT CALLBACK ProgressSubclassProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
57 if (msg == WM_PAINT)
59 GetUpdateRect(hWnd, &last_paint_rect, FALSE);
61 else if (msg == WM_ERASEBKGND)
63 erased = TRUE;
65 return CallWindowProc(progress_wndproc, hWnd, msg, wParam, lParam);
69 static void update_window(HWND hWnd)
71 UpdateWindow(hWnd);
72 ok(!GetUpdateRect(hWnd, NULL, FALSE), "GetUpdateRect must return zero after UpdateWindow\n");
76 static void init(void)
78 WNDCLASSA wc;
79 INITCOMMONCONTROLSEX icex;
80 RECT rect;
82 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
83 icex.dwICC = ICC_PROGRESS_CLASS;
84 InitCommonControlsEx(&icex);
86 wc.style = CS_HREDRAW | CS_VREDRAW;
87 wc.cbClsExtra = 0;
88 wc.cbWndExtra = 0;
89 wc.hInstance = GetModuleHandleA(NULL);
90 wc.hIcon = 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;
96 RegisterClassA(&wc);
98 rect.left = 0;
99 rect.top = 0;
100 rect.right = 400;
101 rect.bottom = 20;
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)
122 MSG msg;
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)
140 RECT client_rect;
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);
147 /* PBM_SETPOS */
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");
151 /* PBM_DELTAPOS */
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");
155 /* PBM_SETPOS */
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");
159 /* PBM_STEPIT */
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 */
173 erased = FALSE;
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 */
185 erased = FALSE;
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");
198 START_TEST(progress)
200 init();
202 test_redraw();
204 cleanup();