user32: Combine horizontal and vertical window scroll bar info in a single structure.
[wine/multimedia.git] / dlls / user32 / tests / scroll.c
blob6082d6f2986e0a8601629c30ba3e16da2725c8c7
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 DWORD winstyle;
215 HWND hwnd;
216 SCROLLINFO si = { sizeof( SCROLLINFO), SIF_TRACKPOS };
218 hwnd = CreateWindowExA( 0, "static", "", WS_POPUP | style,
219 0, 0, 10, 10, 0, 0, 0, NULL);
220 assert( hwnd != 0);
222 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
223 ok( ret ||
224 broken( !ret) /* Win 98/ME */ , "GetScrollRange failed.\n");
225 /* range is 0,0 if there are no H or V scroll bars. 0,100 otherwise */
226 if( !( style & ( WS_VSCROLL | WS_HSCROLL)))
227 ok( min == 0 && max == 0,
228 "Scroll bar range is %d,%d. Expected 0,0. Style %08x\n", min, max, style);
229 else
230 todo_wine
231 ok( min == 0 && max == 100,
232 "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
233 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
234 ok( ret ||
235 broken( !ret) /* Win 98/ME */ , "GetScrollRange failed.\n");
236 /* range is 0,0 if there are no H or V scroll bars. 0,100 otherwise */
237 if( !( style & ( WS_VSCROLL | WS_HSCROLL)))
238 ok( min == 0 && max == 0,
239 "Scroll bar range is %d,%d. Expected 0,0. Style %08x\n", min, max, style);
240 else
241 todo_wine
242 ok( min == 0 && max == 100,
243 "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
244 /* test GetScrollInfo, vist for vertical SB */
245 ret = GetScrollInfo( hwnd, SB_VERT, &si);
246 /* should fail if no H orV scroll bar styles are present. Succeed otherwise */
247 if( !( style & ( WS_VSCROLL | WS_HSCROLL)))
248 ok( !ret, "GetScrollInfo succeeded unexpectedly. Style is %08x\n", style);
249 else
250 todo_wine
251 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
252 /* Same for Horizontal SB */
253 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
254 /* should fail if no H orV scroll bar styles are present. Succeed otherwise */
255 if( !( style & ( WS_VSCROLL | WS_HSCROLL)))
256 ok( !ret, "GetScrollInfo succeeded unexpectedly. Style is %08x\n", style);
257 else
258 todo_wine
259 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
260 /* now set the Vertical Scroll range to something that could be the default value it
261 * already has */;
262 ret = SetScrollRange( hwnd, SB_VERT, 0, 100, FALSE);
263 ok( ret, "SetScrollRange failed.\n");
264 /* and request the Horizontal range */
265 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
266 ok( ret, "GetScrollRange failed.\n");
267 /* now the range should be 0,100 in ALL cases */
268 ok( min == 0 && max == 100,
269 "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
270 /* See what is different now for GetScrollRange */
271 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
272 /* should succeed in ALL cases */
273 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
274 ret = GetScrollInfo( hwnd, SB_VERT, &si);
275 /* should succeed in ALL cases */
276 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
277 /* report the windows style */
278 winstyle = GetWindowLongW( hwnd, GWL_STYLE );
279 /* WS_VSCROLL added to the window style */
280 todo_wine
281 if( !(style & WS_VSCROLL))
282 ok( (winstyle & (WS_HSCROLL|WS_VSCROLL)) == ( style | WS_VSCROLL),
283 "unexpected style change %8lx expected %8lx\n",
284 (winstyle & (WS_HSCROLL|WS_VSCROLL)), style | WS_VSCROLL);
285 /* do the test again with H and V reversed.
286 * Start with a clean window */
287 DestroyWindow( hwnd);
288 hwnd = CreateWindowExA( 0, "static", "", WS_POPUP | style,
289 0, 0, 10, 10, 0, 0, 0, NULL);
290 assert( hwnd != 0);
291 /* Set Horizonta Scroll range to something that could be the default value it
292 * already has */;
293 ret = SetScrollRange( hwnd, SB_HORZ, 0, 100, FALSE);
294 ok( ret, "SetScrollRange failed.\n");
295 /* and request the Vertical range */
296 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
297 ok( ret, "GetScrollRange failed.\n");
298 /* now the range should be 0,100 in ALL cases */
299 ok( min == 0 && max == 100,
300 "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
301 /* See what is different now for GetScrollRange */
302 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
303 /* should succeed in ALL cases */
304 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
305 ret = GetScrollInfo( hwnd, SB_VERT, &si);
306 /* should succeed in ALL cases */
307 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
308 /* report the windows style */
309 winstyle = GetWindowLongW( hwnd, GWL_STYLE );
310 /* WS_HSCROLL added to the window style */
311 todo_wine
312 if( !(style & WS_HSCROLL))
313 ok( (winstyle & (WS_HSCROLL|WS_VSCROLL)) == ( style | WS_HSCROLL),
314 "unexpected style change %8lx expected %8lx\n",
315 (winstyle & (WS_HSCROLL|WS_VSCROLL)), style | WS_HSCROLL);
316 /* Slightly change the test to use SetScrollInfo
317 * Start with a clean window */
318 DestroyWindow( hwnd);
319 hwnd = CreateWindowExA( 0, "static", "", WS_POPUP | style,
320 0, 0, 10, 10, 0, 0, 0, NULL);
321 assert( hwnd != 0);
322 /* set Horizontal position with SetScrollInfo */
323 si.nPos = 0;
324 si.nMin = 11;
325 si.nMax = 22;
326 si.fMask |= SIF_RANGE;
327 ret = SetScrollInfo( hwnd, SB_HORZ, &si, FALSE);
328 ok( ret, "SetScrollInfo failed. Style is %08x\n", style);
329 /* and request the Vertical range */
330 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
331 ok( ret, "GetScrollRange failed.\n");
332 /* now the range should be 0,100 in ALL cases */
333 ok( min == 0 && max == 100,
334 "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
335 /* See what is different now for GetScrollRange */
336 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
337 /* should succeed in ALL cases */
338 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
339 ret = GetScrollInfo( hwnd, SB_VERT, &si);
340 /* should succeed in ALL cases */
341 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
342 /* also test if the window scroll bars are enabled */
343 ret = EnableScrollBar( hwnd, SB_VERT, ESB_ENABLE_BOTH);
344 ok( !ret, "Vertical window scroll bar was not enabled\n");
345 ret = EnableScrollBar( hwnd, SB_HORZ, ESB_ENABLE_BOTH);
346 ok( !ret, "Horizontal window scroll bar was not enabled\n");
347 DestroyWindow( hwnd);
348 /* finally, check if adding a WS_[HV]SColl style of a window makes the scroll info
349 * available */
350 if( style & (WS_HSCROLL | WS_VSCROLL)) return;/* only test if not yet set */
351 /* Start with a clean window */
352 DestroyWindow( hwnd);
353 hwnd = CreateWindowExA( 0, "static", "", WS_POPUP ,
354 0, 0, 10, 10, 0, 0, 0, NULL);
355 assert( hwnd != 0);
356 ret = GetScrollInfo( hwnd, SB_VERT, &si);
357 /* should fail */
358 ok( !ret, "GetScrollInfo succeeded unexpectedly. Style is %08x\n", style);
359 /* add scroll styles */
360 winstyle = GetWindowLongW( hwnd, GWL_STYLE );
361 SetWindowLongW( hwnd, GWL_STYLE, winstyle | WS_VSCROLL | WS_HSCROLL);
362 ret = GetScrollInfo( hwnd, SB_VERT, &si);
363 /* should still fail */
364 ok( !ret, "GetScrollInfo succeeded unexpectedly. Style is %08x\n", style);
365 /* clean up */
366 DestroyWindow( hwnd);
369 START_TEST ( scroll )
371 WNDCLASSA wc;
373 wc.style = CS_HREDRAW | CS_VREDRAW;
374 wc.cbClsExtra = 0;
375 wc.cbWndExtra = 0;
376 wc.hInstance = GetModuleHandleA(NULL);
377 wc.hIcon = NULL;
378 wc.hCursor = LoadCursorA(NULL, IDC_IBEAM);
379 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
380 wc.lpszMenuName = NULL;
381 wc.lpszClassName = "MyTestWnd";
382 wc.lpfnWndProc = MyWndProc;
383 RegisterClassA(&wc);
385 hMainWnd = CreateWindowExA( 0, "MyTestWnd", "Scroll",
386 WS_OVERLAPPEDWINDOW|WS_VSCROLL|WS_HSCROLL,
387 CW_USEDEFAULT, CW_USEDEFAULT, 100, 100, NULL, NULL, GetModuleHandleA(NULL), 0 );
389 if ( !ok( hMainWnd != NULL, "Failed to create parent window. Tests aborted.\n" ) )
390 return;
392 assert( hScroll );
394 scrollbar_test1();
395 scrollbar_test2();
396 scrollbar_test3();
397 scrollbar_test4();
399 scrollbar_test_default( 0);
400 scrollbar_test_default( WS_HSCROLL);
401 scrollbar_test_default( WS_VSCROLL);
402 scrollbar_test_default( WS_HSCROLL | WS_VSCROLL);
404 DestroyWindow(hScroll);
405 DestroyWindow(hMainWnd);