Release 20050930.
[wine/gsoc-2012-control.git] / dlls / comctl32 / tests / progress.c
blob01b60c544f2c97b38902a515b6c1e152045cdb5b
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 HWND hProgressParentWnd, hProgressWnd;
33 static char progressTestClass[] = "ProgressBarTestClass";
36 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;
52 static void update_window(HWND hWnd)
54 UpdateWindow(hWnd);
55 ok(!GetUpdateRect(hWnd, NULL, FALSE), "GetUpdateRect must return zero after UpdateWindow\n");
59 static void init(void)
61 WNDCLASSA wc;
62 INITCOMMONCONTROLSEX icex;
63 RECT rect;
65 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
66 icex.dwICC = ICC_PROGRESS_CLASS;
67 InitCommonControlsEx(&icex);
69 wc.style = CS_HREDRAW | CS_VREDRAW;
70 wc.cbClsExtra = 0;
71 wc.cbWndExtra = 0;
72 wc.hInstance = GetModuleHandleA(NULL);
73 wc.hIcon = NULL;
74 wc.hCursor = LoadCursorA(NULL, MAKEINTRESOURCEA(IDC_ARROW));
75 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
76 wc.lpszMenuName = NULL;
77 wc.lpszClassName = progressTestClass;
78 wc.lpfnWndProc = ProgressTestWndProc;
79 RegisterClassA(&wc);
81 rect.left = 0;
82 rect.top = 0;
83 rect.right = 400;
84 rect.bottom = 20;
85 assert(AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE));
87 hProgressParentWnd = CreateWindowExA(0, progressTestClass, "Progress Bar Test", WS_OVERLAPPEDWINDOW,
88 CW_USEDEFAULT, CW_USEDEFAULT, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, GetModuleHandleA(NULL), 0);
89 assert(hProgressParentWnd != NULL);
91 GetClientRect(hProgressParentWnd, &rect);
92 hProgressWnd = CreateWindowEx(0, PROGRESS_CLASS, "", WS_CHILD | WS_VISIBLE,
93 0, 0, rect.right, rect.bottom, hProgressParentWnd, NULL, GetModuleHandleA(NULL), 0);
94 assert(hProgressWnd != NULL);
96 ShowWindow(hProgressParentWnd, SW_SHOWNORMAL);
97 ok(GetUpdateRect(hProgressParentWnd, NULL, FALSE), "GetUpdateRect: There should be a region that needs to be updated\n");
98 update_window(hProgressParentWnd);
102 static void cleanup(void)
104 MSG msg;
106 PostMessageA(hProgressParentWnd, WM_CLOSE, 0, 0);
107 while (GetMessageA(&msg,0,0,0)) {
108 TranslateMessage(&msg);
109 DispatchMessageA(&msg);
112 UnregisterClassA(progressTestClass, GetModuleHandleA(NULL));
117 * Tests if a progress bar repaints itself immediately when it receives
118 * some specific messages.
120 static void test_redraw(void)
122 SendMessageA(hProgressWnd, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
123 SendMessageA(hProgressWnd, PBM_SETPOS, 10, 0);
124 SendMessageA(hProgressWnd, PBM_SETSTEP, 20, 0);
125 update_window(hProgressWnd);
127 /* PBM_SETPOS */
128 ok(SendMessageA(hProgressWnd, PBM_SETPOS, 50, 0) == 10, "PBM_SETPOS must return the previous position\n");
129 ok(!GetUpdateRect(hProgressWnd, NULL, FALSE), "PBM_SETPOS: The progress bar should be redrawn immediately\n");
131 /* PBM_DELTAPOS */
132 ok(SendMessageA(hProgressWnd, PBM_DELTAPOS, 15, 0) == 50, "PBM_DELTAPOS must return the previous position\n");
133 ok(!GetUpdateRect(hProgressWnd, NULL, FALSE), "PBM_DELTAPOS: The progress bar should be redrawn immediately\n");
135 /* PBM_SETPOS */
136 ok(SendMessageA(hProgressWnd, PBM_SETPOS, 80, 0) == 65, "PBM_SETPOS must return the previous position\n");
137 ok(!GetUpdateRect(hProgressWnd, NULL, FALSE), "PBM_SETPOS: The progress bar should be redrawn immediately\n");
139 /* PBM_STEPIT */
140 ok(SendMessageA(hProgressWnd, PBM_STEPIT, 0, 0) == 80, "PBM_STEPIT must return the previous position\n");
141 ok(!GetUpdateRect(hProgressWnd, NULL, FALSE), "PBM_STEPIT: The progress bar should be redrawn immediately\n");
142 ok((UINT)SendMessageA(hProgressWnd, PBM_GETPOS, 0, 0) == 100, "PBM_GETPOS returned a wrong position\n");
144 /* PBM_SETRANGE and PBM_SETRANGE32:
145 Usually the progress bar doesn't repaint itself immediately. If the
146 position is not in the new range, it does.
147 Don't test this, it may change in future Windows versions. */
151 START_TEST(progress)
153 init();
155 test_redraw();
157 cleanup();