push 20d539bd3127e997ce79233e3988ba5740356ce5
[wine/hacks.git] / dlls / user32 / tests / scroll.c
blob0c36ff82bd34178b2ba7f0720c8a30298c1ce0bb
1 /*
2 * Unit tests for scrollbar
4 * Copyright 2008 Lyutin Anatoly (Etersoft)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <assert.h>
22 #include <stdarg.h>
23 #include <stdio.h>
24 #include <windows.h>
26 #include "wine/test.h"
28 static HWND hScroll, hMainWnd;
30 static LRESULT CALLBACK MyWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
32 switch(msg)
35 case WM_CREATE:
37 hScroll = CreateWindowA( "SCROLLBAR", "", WS_CHILD | WS_VISIBLE, 0, 0, 120, 100, hWnd, (HMENU)100, GetModuleHandleA(0), 0 );
39 return 0;
41 case WM_DESTROY:
42 PostQuitMessage(0);
43 break;
45 default:
46 return DefWindowProcA(hWnd, msg, wParam, lParam);
48 return 0;
51 static void scrollbar_test1(void)
53 BOOL ret;
55 ret = EnableScrollBar( hScroll, SB_CTL, ESB_DISABLE_BOTH );
56 ok( ret, "The scrollbar should be disabled.\n" );
57 ok( !IsWindowEnabled( hScroll ), "The scrollbar window should be disabled.\n" );
59 ret = EnableScrollBar( hScroll, SB_CTL, ESB_ENABLE_BOTH );
60 ok( ret, "The scrollbar should be enabled.\n" );
61 ok( IsWindowEnabled( hScroll ), "The scrollbar window should be enabled.\n" );
63 /* test buttons separately */
64 ret = EnableScrollBar( hScroll, SB_CTL, ESB_DISABLE_LTUP );
65 ok( ret, "The scrollbar LTUP button should be disabled.\n" );
66 ok( IsWindowEnabled( hScroll ), "The scrollbar window should be enabled.\n" );
67 ret = EnableScrollBar( hScroll, SB_CTL, ESB_ENABLE_BOTH );
68 ok( ret, "The scrollbar should be enabled.\n" );
69 ok( IsWindowEnabled( hScroll ), "The scrollbar window should be enabled.\n" );
71 ret = EnableScrollBar( hScroll, SB_CTL, ESB_DISABLE_RTDN );
72 ok( ret, "The scrollbar RTDN button should be disabled.\n" );
73 ok( IsWindowEnabled( hScroll ), "The scrollbar window should be enabled.\n" );
74 ret = EnableScrollBar( hScroll, SB_CTL, ESB_ENABLE_BOTH );
75 ok( ret, "The scrollbar should be enabled.\n" );
76 ok( IsWindowEnabled( hScroll ), "The scrollbar window should be enabled.\n" );
79 static void scrollbar_test2(void)
81 int ret;
83 trace("The scrollbar is disabled.\n");
85 EnableWindow( hScroll, FALSE );
86 ok( !IsWindowEnabled( hScroll ), "The scroll should be disabled.\n" );
88 ret = SetScrollPos( hScroll, SB_CTL, 30, TRUE);
89 ok( !ret, "The position should not be set.\n" );
91 ret = GetScrollPos( hScroll, SB_CTL);
92 ok( !ret, "The position should be equal to zero\n");
94 ret = SetScrollRange( hScroll, SB_CTL, 0, 100, TRUE );
95 ok( ret, "The range should be set.\n" );
97 ret = SetScrollPos( hScroll, SB_CTL, 30, TRUE);
98 ok( !ret , "The position should not be set.\n" );
100 ret = GetScrollPos( hScroll, SB_CTL);
101 ok( ret == 30, "The position should be set!!!\n");
103 trace("The scrollbar is enabled.\n");
105 EnableWindow( hScroll, TRUE );
106 ok( IsWindowEnabled( hScroll ), "The scroll should be enabled.\n" );
108 ret = SetScrollPos( hScroll, SB_CTL, 30, TRUE);
109 ok( ret == 30, "The position should be set.\n" );
111 ret = GetScrollPos( hScroll, SB_CTL);
112 ok( ret == 30, "The position should not be equal to zero\n");
114 ret = SetScrollRange( hScroll, SB_CTL, 0, 100, TRUE );
115 ok( ret, "The range should be set.\n" );
117 ret = SetScrollPos( hScroll, SB_CTL, 30, TRUE);
118 ok( ret == 30, "The position should be set.\n" );
120 ret = GetScrollPos( hScroll, SB_CTL);
121 ok( ret == 30, "The position should not be equal to zero\n");
124 static void scrollbar_test3(void)
126 BOOL ret;
128 ret = ShowScrollBar( hScroll, SB_CTL, FALSE );
129 ok( ret, "The ShowScrollBar() should not failed.\n" );
130 ok( !IsWindowVisible( hScroll ), "The scrollbar window should not be visible\n" );
132 ret = ShowScrollBar( hScroll, SB_CTL, TRUE );
133 ok( ret, "The ShowScrollBar() should not failed.\n" );
134 ok( !IsWindowVisible( hScroll ), "The scrollbar window should be visible\n" );
136 ret = ShowScrollBar( NULL, SB_CTL, TRUE );
137 ok( !ret, "The ShowScrollBar() should failed.\n" );
141 static void scrollbar_test4(void)
143 BOOL ret;
144 SCROLLBARINFO sbi;
145 RECT rect;
146 BOOL (WINAPI *pGetScrollBarInfo)(HWND, LONG, LPSCROLLBARINFO);
148 pGetScrollBarInfo = (void*)GetProcAddress(GetModuleHandleA("user32.dll"), "GetScrollBarInfo");
149 if (!pGetScrollBarInfo)
151 win_skip("GetScrollBarInfo is not available\n");
152 return;
155 /* Test GetScrollBarInfo to make sure it returns rcScrollBar in screen
156 * coordinates. */
157 sbi.cbSize = sizeof(sbi);
158 ret = pGetScrollBarInfo( hScroll, OBJID_CLIENT, &sbi);
159 ok( ret, "The GetScrollBarInfo() call should not fail.\n" );
160 GetWindowRect( hScroll, &rect );
161 ok( ret, "The GetWindowRect() call should not fail.\n" );
162 ok( !(sbi.rgstate[0] & (STATE_SYSTEM_INVISIBLE|STATE_SYSTEM_OFFSCREEN)),
163 "unexpected rgstate(0x%x)\n", sbi.rgstate[0]);
164 ok( EqualRect(&rect, &sbi.rcScrollBar),
165 "WindowRect(%d, %d, %d, %d) != rcScrollBar(%d, %d, %d, %d)\n",
166 rect.top, rect.left, rect.bottom, rect.right,
167 sbi.rcScrollBar.top, sbi.rcScrollBar.left,
168 sbi.rcScrollBar.bottom, sbi.rcScrollBar.right );
170 /* Test windows horizontal and vertical scrollbar to make sure rcScrollBar
171 * is still returned in screen coordinates by moving the window, and
172 * making sure that it shifts the rcScrollBar value. */
173 ShowWindow( hMainWnd, SW_SHOW );
174 sbi.cbSize = sizeof(sbi);
175 ret = pGetScrollBarInfo( hMainWnd, OBJID_HSCROLL, &sbi);
176 ok( ret, "The GetScrollBarInfo() call should not fail.\n" );
177 GetWindowRect( hMainWnd, &rect );
178 ok( ret, "The GetWindowRect() call should not fail.\n" );
179 MoveWindow( hMainWnd, rect.left+5, rect.top+5,
180 rect.right-rect.left, rect.bottom-rect.top, TRUE );
181 rect = sbi.rcScrollBar;
182 OffsetRect(&rect, 5, 5);
183 ret = pGetScrollBarInfo( hMainWnd, OBJID_HSCROLL, &sbi);
184 ok( ret, "The GetScrollBarInfo() call should not fail.\n" );
185 ok( EqualRect(&rect, &sbi.rcScrollBar),
186 "PreviousRect(%d, %d, %d, %d) != CurrentRect(%d, %d, %d, %d)\n",
187 rect.top, rect.left, rect.bottom, rect.right,
188 sbi.rcScrollBar.top, sbi.rcScrollBar.left,
189 sbi.rcScrollBar.bottom, sbi.rcScrollBar.right );
191 sbi.cbSize = sizeof(sbi);
192 ret = pGetScrollBarInfo( hMainWnd, OBJID_VSCROLL, &sbi);
193 ok( ret, "The GetScrollBarInfo() call should not fail.\n" );
194 GetWindowRect( hMainWnd, &rect );
195 ok( ret, "The GetWindowRect() call should not fail.\n" );
196 MoveWindow( hMainWnd, rect.left+5, rect.top+5,
197 rect.right-rect.left, rect.bottom-rect.top, TRUE );
198 rect = sbi.rcScrollBar;
199 OffsetRect(&rect, 5, 5);
200 ret = pGetScrollBarInfo( hMainWnd, OBJID_VSCROLL, &sbi);
201 ok( ret, "The GetScrollBarInfo() call should not fail.\n" );
202 ok( EqualRect(&rect, &sbi.rcScrollBar),
203 "PreviousRect(%d, %d, %d, %d) != CurrentRect(%d, %d, %d, %d)\n",
204 rect.top, rect.left, rect.bottom, rect.right,
205 sbi.rcScrollBar.top, sbi.rcScrollBar.left,
206 sbi.rcScrollBar.bottom, sbi.rcScrollBar.right );
209 /* some tests designed to show that Horizontal and Vertical
210 * window scroll bar info are not created independently */
211 static void scrollbar_test_default( DWORD style)
213 INT min, max, ret;
214 HWND hwnd;
215 SCROLLINFO si = { sizeof( SCROLLINFO), SIF_TRACKPOS };
217 hwnd = CreateWindowExA( 0, "static", "", WS_POPUP | style,
218 0, 0, 10, 10, 0, 0, 0, NULL);
219 assert( hwnd != 0);
221 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
222 ok( ret ||
223 broken( !ret) /* Win 98/ME */ , "GetScrollRange failed.\n");
224 /* range is 0,0 if there are no H or V scroll bars. 0,100 otherwise */
225 if( !( style & ( WS_VSCROLL | WS_HSCROLL)))
226 ok( min == 0 && max == 0,
227 "Scroll bar range is %d,%d. Expected 0,0. Style %08x\n", min, max, style);
228 else
229 ok( min == 0 && max == 100,
230 "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
231 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
232 ok( ret ||
233 broken( !ret) /* Win 98/ME */ , "GetScrollRange failed.\n");
234 /* range is 0,0 if there are no H or V scroll bars. 0,100 otherwise */
235 if( !( style & ( WS_VSCROLL | WS_HSCROLL)))
236 ok( min == 0 && max == 0,
237 "Scroll bar range is %d,%d. Expected 0,0. Style %08x\n", min, max, style);
238 else
239 ok( min == 0 && max == 100,
240 "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
241 /* test GetScrollInfo, vist for vertical SB */
242 ret = GetScrollInfo( hwnd, SB_VERT, &si);
243 /* should fail if no H orV scroll bar styles are present. Succeed otherwise */
244 if( !( style & ( WS_VSCROLL | WS_HSCROLL)))
245 ok( !ret, "GetScrollInfo succeeded unexpectedly. Style is %08x\n", style);
246 else
247 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
248 /* Same for Horizontal SB */
249 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
250 /* should fail if no H orV scroll bar styles are present. Succeed otherwise */
251 if( !( style & ( WS_VSCROLL | WS_HSCROLL)))
252 ok( !ret, "GetScrollInfo succeeded unexpectedly. Style is %08x\n", style);
253 else
254 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
255 /* now set the Vertical Scroll range to something that could be the default value it
256 * already has */;
257 ret = SetScrollRange( hwnd, SB_VERT, 0, 100, FALSE);
258 ok( ret, "SetScrollRange failed.\n");
259 /* and request the Horizontal range */
260 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
261 ok( ret, "GetScrollRange failed.\n");
262 /* now the range should be 0,100 in ALL cases */
263 todo_wine
264 ok( min == 0 && max == 100,
265 "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
266 /* See what is different now for GetScrollRange */
267 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
268 /* should succeed in ALL cases */
269 todo_wine
270 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
271 ret = GetScrollInfo( hwnd, SB_VERT, &si);
272 /* should succeed in ALL cases */
273 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
274 /* do the test again with H and V reversed.
275 * Start with a clean window */
276 DestroyWindow( hwnd);
277 hwnd = CreateWindowExA( 0, "static", "", WS_POPUP | style,
278 0, 0, 10, 10, 0, 0, 0, NULL);
279 assert( hwnd != 0);
280 /* Set Horizonta Scroll range to something that could be the default value it
281 * already has */;
282 ret = SetScrollRange( hwnd, SB_HORZ, 0, 100, FALSE);
283 ok( ret, "SetScrollRange failed.\n");
284 /* and request the Vertical range */
285 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
286 ok( ret, "GetScrollRange failed.\n");
287 /* now the range should be 0,100 in ALL cases */
288 todo_wine
289 ok( min == 0 && max == 100,
290 "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
291 /* See what is different now for GetScrollRange */
292 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
293 /* should succeed in ALL cases */
294 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
295 ret = GetScrollInfo( hwnd, SB_VERT, &si);
296 /* should succeed in ALL cases */
297 todo_wine
298 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
299 /* Slightly change the test to muse SetScrollInfo
300 * Start with a clean window */
301 DestroyWindow( hwnd);
302 hwnd = CreateWindowExA( 0, "static", "", WS_POPUP | style,
303 0, 0, 10, 10, 0, 0, 0, NULL);
304 assert( hwnd != 0);
305 /* set Horizontal position with SetScrollInfo */
306 si.nPos = 0;
307 si.nMin = 11;
308 si.nMax = 22;
309 si.fMask |= SIF_RANGE;
310 ret = SetScrollInfo( hwnd, SB_HORZ, &si, FALSE);
311 ok( ret, "SetScrollInfo failed. Style is %08x\n", style);
312 /* and request the Vertical range */
313 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
314 ok( ret, "GetScrollRange failed.\n");
315 /* now the range should be 0,100 in ALL cases */
316 todo_wine
317 ok( min == 0 && max == 100,
318 "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
319 /* See what is different now for GetScrollRange */
320 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
321 /* should succeed in ALL cases */
322 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
323 ret = GetScrollInfo( hwnd, SB_VERT, &si);
324 /* should succeed in ALL cases */
325 todo_wine
326 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
327 /* clean up */
328 DestroyWindow( hwnd);
331 START_TEST ( scroll )
333 WNDCLASSA wc;
335 wc.style = CS_HREDRAW | CS_VREDRAW;
336 wc.cbClsExtra = 0;
337 wc.cbWndExtra = 0;
338 wc.hInstance = GetModuleHandleA(NULL);
339 wc.hIcon = NULL;
340 wc.hCursor = LoadCursorA(NULL, IDC_IBEAM);
341 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
342 wc.lpszMenuName = NULL;
343 wc.lpszClassName = "MyTestWnd";
344 wc.lpfnWndProc = MyWndProc;
345 RegisterClassA(&wc);
347 hMainWnd = CreateWindowExA( 0, "MyTestWnd", "Scroll",
348 WS_OVERLAPPEDWINDOW|WS_VSCROLL|WS_HSCROLL,
349 CW_USEDEFAULT, CW_USEDEFAULT, 100, 100, NULL, NULL, GetModuleHandleA(NULL), 0 );
351 if ( !ok( hMainWnd != NULL, "Failed to create parent window. Tests aborted.\n" ) )
352 return;
354 assert( hScroll );
356 scrollbar_test1();
357 scrollbar_test2();
358 scrollbar_test3();
359 scrollbar_test4();
361 scrollbar_test_default( 0);
362 if( 0) { /* enable this when the todo's in scrollbar_test_default are fixed */
363 scrollbar_test_default( WS_HSCROLL);
364 scrollbar_test_default( WS_VSCROLL);
365 scrollbar_test_default( WS_HSCROLL | WS_VSCROLL);
367 DestroyWindow(hScroll);
368 DestroyWindow(hMainWnd);