kernel32: Update Italian translation.
[wine/testsucceed.git] / dlls / comctl32 / tests / progress.c
blob3083e8ba2e517952e99d3ae7d312af497ead7117
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 /* try to make sure pending X events have been processed before continuing */
37 static void flush_events(void)
39 MSG msg;
40 int diff = 100;
41 DWORD time = GetTickCount() + diff;
43 while (diff > 0)
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)
53 switch(msg) {
55 case WM_DESTROY:
56 PostQuitMessage(0);
57 break;
59 default:
60 return DefWindowProcA(hWnd, msg, wParam, lParam);
63 return 0L;
66 static WNDPROC progress_wndproc;
67 static BOOL erased;
68 static RECT last_paint_rect;
70 static LRESULT CALLBACK ProgressSubclassProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
72 if (msg == WM_PAINT)
74 GetUpdateRect(hWnd, &last_paint_rect, FALSE);
76 else if (msg == WM_ERASEBKGND)
78 erased = TRUE;
80 return CallWindowProc(progress_wndproc, hWnd, msg, wParam, lParam);
84 static void update_window(HWND hWnd)
86 UpdateWindow(hWnd);
87 ok(!GetUpdateRect(hWnd, NULL, FALSE), "GetUpdateRect must return zero after UpdateWindow\n");
91 static void init(void)
93 HMODULE hComctl32;
94 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
95 WNDCLASSA wc;
96 RECT rect;
98 hComctl32 = GetModuleHandleA("comctl32.dll");
99 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
100 if (pInitCommonControlsEx)
102 INITCOMMONCONTROLSEX iccex;
103 iccex.dwSize = sizeof(iccex);
104 iccex.dwICC = ICC_PROGRESS_CLASS;
105 pInitCommonControlsEx(&iccex);
107 else
108 InitCommonControls();
110 wc.style = CS_HREDRAW | CS_VREDRAW;
111 wc.cbClsExtra = 0;
112 wc.cbWndExtra = 0;
113 wc.hInstance = GetModuleHandleA(NULL);
114 wc.hIcon = NULL;
115 wc.hCursor = LoadCursorA(NULL, IDC_ARROW);
116 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
117 wc.lpszMenuName = NULL;
118 wc.lpszClassName = progressTestClass;
119 wc.lpfnWndProc = ProgressTestWndProc;
120 RegisterClassA(&wc);
122 rect.left = 0;
123 rect.top = 0;
124 rect.right = 400;
125 rect.bottom = 20;
126 assert(AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE));
128 hProgressParentWnd = CreateWindowExA(0, progressTestClass, "Progress Bar Test", WS_OVERLAPPEDWINDOW,
129 CW_USEDEFAULT, CW_USEDEFAULT, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, GetModuleHandleA(NULL), 0);
130 assert(hProgressParentWnd != NULL);
132 GetClientRect(hProgressParentWnd, &rect);
133 hProgressWnd = CreateWindowEx(0, PROGRESS_CLASS, "", WS_CHILD | WS_VISIBLE,
134 0, 0, rect.right, rect.bottom, hProgressParentWnd, NULL, GetModuleHandleA(NULL), 0);
135 assert(hProgressWnd != NULL);
136 progress_wndproc = (WNDPROC)SetWindowLongPtr(hProgressWnd, GWLP_WNDPROC, (LPARAM)ProgressSubclassProc);
138 ShowWindow(hProgressParentWnd, SW_SHOWNORMAL);
139 ok(GetUpdateRect(hProgressParentWnd, NULL, FALSE), "GetUpdateRect: There should be a region that needs to be updated\n");
140 flush_events();
141 update_window(hProgressParentWnd);
145 static void cleanup(void)
147 MSG msg;
149 PostMessageA(hProgressParentWnd, WM_CLOSE, 0, 0);
150 while (GetMessageA(&msg,0,0,0)) {
151 TranslateMessage(&msg);
152 DispatchMessageA(&msg);
155 UnregisterClassA(progressTestClass, GetModuleHandleA(NULL));
160 * Tests if a progress bar repaints itself immediately when it receives
161 * some specific messages.
163 static void test_redraw(void)
165 RECT client_rect;
166 LRESULT ret;
168 SendMessageA(hProgressWnd, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
169 SendMessageA(hProgressWnd, PBM_SETPOS, 10, 0);
170 SendMessageA(hProgressWnd, PBM_SETSTEP, 20, 0);
171 update_window(hProgressWnd);
173 /* PBM_SETPOS */
174 ok(SendMessageA(hProgressWnd, PBM_SETPOS, 50, 0) == 10, "PBM_SETPOS must return the previous position\n");
175 ok(!GetUpdateRect(hProgressWnd, NULL, FALSE), "PBM_SETPOS: The progress bar should be redrawn immediately\n");
177 /* PBM_DELTAPOS */
178 ok(SendMessageA(hProgressWnd, PBM_DELTAPOS, 15, 0) == 50, "PBM_DELTAPOS must return the previous position\n");
179 ok(!GetUpdateRect(hProgressWnd, NULL, FALSE), "PBM_DELTAPOS: The progress bar should be redrawn immediately\n");
181 /* PBM_SETPOS */
182 ok(SendMessageA(hProgressWnd, PBM_SETPOS, 80, 0) == 65, "PBM_SETPOS must return the previous position\n");
183 ok(!GetUpdateRect(hProgressWnd, NULL, FALSE), "PBM_SETPOS: The progress bar should be redrawn immediately\n");
185 /* PBM_STEPIT */
186 ok(SendMessageA(hProgressWnd, PBM_STEPIT, 0, 0) == 80, "PBM_STEPIT must return the previous position\n");
187 ok(!GetUpdateRect(hProgressWnd, NULL, FALSE), "PBM_STEPIT: The progress bar should be redrawn immediately\n");
188 ret = SendMessageA(hProgressWnd, PBM_GETPOS, 0, 0);
189 if (ret == 0)
190 win_skip("PBM_GETPOS needs comctl32 > 4.70\n");
191 else
192 ok(ret == 100, "PBM_GETPOS returned a wrong position : %d\n", (UINT)ret);
194 /* PBM_SETRANGE and PBM_SETRANGE32:
195 Usually the progress bar doesn't repaint itself immediately. If the
196 position is not in the new range, it does.
197 Don't test this, it may change in future Windows versions. */
199 SendMessage(hProgressWnd, PBM_SETPOS, 0, 0);
200 update_window(hProgressWnd);
202 /* increase to 10 - no background erase required */
203 erased = FALSE;
204 SetRectEmpty(&last_paint_rect);
205 SendMessage(hProgressWnd, PBM_SETPOS, 10, 0);
206 GetClientRect(hProgressWnd, &client_rect);
207 ok(EqualRect(&last_paint_rect, &client_rect),
208 "last_paint_rect was { %d, %d, %d, %d } instead of { %d, %d, %d, %d }\n",
209 last_paint_rect.left, last_paint_rect.top, last_paint_rect.right, last_paint_rect.bottom,
210 client_rect.left, client_rect.top, client_rect.right, client_rect.bottom);
211 update_window(hProgressWnd);
212 ok(!erased, "Progress bar shouldn't have erased the background\n");
214 /* decrease to 0 - background erase will be required */
215 erased = FALSE;
216 SetRectEmpty(&last_paint_rect);
217 SendMessage(hProgressWnd, PBM_SETPOS, 0, 0);
218 GetClientRect(hProgressWnd, &client_rect);
219 ok(EqualRect(&last_paint_rect, &client_rect),
220 "last_paint_rect was { %d, %d, %d, %d } instead of { %d, %d, %d, %d }\n",
221 last_paint_rect.left, last_paint_rect.top, last_paint_rect.right, last_paint_rect.bottom,
222 client_rect.left, client_rect.top, client_rect.right, client_rect.bottom);
223 update_window(hProgressWnd);
224 ok(erased, "Progress bar should have erased the background\n");
228 START_TEST(progress)
230 init();
232 test_redraw();
234 cleanup();