Added a few more Unicode digits from Unicode version 4.1.
[wine] / dlls / comctl32 / tests / progress.c
1 /* Unit tests for the progress bar control.
2  *
3  * Copyright 2005 Michael Kaufmann
4  *
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.
9  *
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.
14  *
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
18  */
19
20 #include <assert.h>
21 #include <stdarg.h>
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wingdi.h"
26 #include "winuser.h"
27 #include "commctrl.h" 
28
29 #include "wine/test.h"
30
31
32 HWND hProgressParentWnd, hProgressWnd;
33 static char progressTestClass[] = "ProgressBarTestClass";
34
35
36 LRESULT CALLBACK ProgressTestWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
37 {
38     switch(msg) {
39     
40     case WM_DESTROY:
41         PostQuitMessage(0);
42         break;
43   
44     default:
45         return DefWindowProcA(hWnd, msg, wParam, lParam);
46     }
47     
48     return 0L;
49 }
50
51
52 static void update_window(HWND hWnd)
53 {
54     UpdateWindow(hWnd);
55     ok(!GetUpdateRect(hWnd, NULL, FALSE), "GetUpdateRect must return zero after UpdateWindow\n");    
56 }
57
58
59 static void init(void)
60 {
61     WNDCLASSA wc;
62     INITCOMMONCONTROLSEX icex;
63     RECT rect;
64     
65     icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
66     icex.dwICC   = ICC_PROGRESS_CLASS;
67     InitCommonControlsEx(&icex);
68   
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);
80     
81     rect.left = 0;
82     rect.top = 0;
83     rect.right = 400;
84     rect.bottom = 20;
85     assert(AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE));
86     
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);
90     
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);
95     
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);    
99 }
100
101
102 static void cleanup(void)
103 {
104     MSG msg;
105     
106     PostMessageA(hProgressParentWnd, WM_CLOSE, 0, 0);
107     while (GetMessageA(&msg,0,0,0)) {
108         TranslateMessage(&msg);
109         DispatchMessageA(&msg);
110     }
111     
112     UnregisterClassA(progressTestClass, GetModuleHandleA(NULL));
113 }
114
115
116 /*
117  * Tests if a progress bar repaints itself immediately when it receives
118  * some specific messages.
119  */
120 static void test_redraw(void)
121 {
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);
126
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");
130     
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");
134     
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");
138     
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");
143     
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. */
148 }
149
150
151 START_TEST(progress)
152 {
153     init();
154     
155     test_redraw();
156     
157     cleanup();
158 }