Release 1.1.37.
[wine/gsoc-2012-control.git] / dlls / user32 / tests / scroll.c
blob03725b92f48388624a69317f409a7c073bd8cdda
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;
29 static BOOL bThemeActive = FALSE;
31 static LRESULT CALLBACK MyWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
33 switch(msg)
36 case WM_CREATE:
38 hScroll = CreateWindowA( "SCROLLBAR", "", WS_CHILD | WS_VISIBLE, 0, 0, 120, 100, hWnd, (HMENU)100, GetModuleHandleA(0), 0 );
40 return 0;
42 case WM_DESTROY:
43 PostQuitMessage(0);
44 break;
46 default:
47 return DefWindowProcA(hWnd, msg, wParam, lParam);
49 return 0;
52 static void scrollbar_test1(void)
54 BOOL ret;
56 ret = EnableScrollBar( hScroll, SB_CTL, ESB_DISABLE_BOTH );
57 ok( ret, "The scrollbar should be disabled.\n" );
58 ok( !IsWindowEnabled( hScroll ), "The scrollbar window should be disabled.\n" );
60 ret = EnableScrollBar( hScroll, SB_CTL, ESB_ENABLE_BOTH );
61 ok( ret, "The scrollbar should be enabled.\n" );
62 ok( IsWindowEnabled( hScroll ), "The scrollbar window should be enabled.\n" );
64 /* test buttons separately */
65 ret = EnableScrollBar( hScroll, SB_CTL, ESB_DISABLE_LTUP );
66 ok( ret, "The scrollbar LTUP button should be disabled.\n" );
67 ok( IsWindowEnabled( hScroll ), "The scrollbar window should be enabled.\n" );
68 ret = EnableScrollBar( hScroll, SB_CTL, ESB_ENABLE_BOTH );
69 ok( ret, "The scrollbar should be enabled.\n" );
70 ok( IsWindowEnabled( hScroll ), "The scrollbar window should be enabled.\n" );
72 ret = EnableScrollBar( hScroll, SB_CTL, ESB_DISABLE_RTDN );
73 ok( ret, "The scrollbar RTDN button should be disabled.\n" );
74 ok( IsWindowEnabled( hScroll ), "The scrollbar window should be enabled.\n" );
75 ret = EnableScrollBar( hScroll, SB_CTL, ESB_ENABLE_BOTH );
76 ok( ret, "The scrollbar should be enabled.\n" );
77 ok( IsWindowEnabled( hScroll ), "The scrollbar window should be enabled.\n" );
80 static void scrollbar_test2(void)
82 int ret;
84 trace("The scrollbar is disabled.\n");
86 EnableWindow( hScroll, FALSE );
87 ok( !IsWindowEnabled( hScroll ), "The scroll should be disabled.\n" );
89 ret = SetScrollPos( hScroll, SB_CTL, 30, TRUE);
90 ok( !ret, "The position should not be set.\n" );
92 ret = GetScrollPos( hScroll, SB_CTL);
93 ok( !ret, "The position should be equal to zero\n");
95 ret = SetScrollRange( hScroll, SB_CTL, 0, 100, TRUE );
96 ok( ret, "The range should be set.\n" );
98 ret = SetScrollPos( hScroll, SB_CTL, 30, TRUE);
99 ok( !ret , "The position should not be set.\n" );
101 ret = GetScrollPos( hScroll, SB_CTL);
102 ok( ret == 30, "The position should be set!!!\n");
104 trace("The scrollbar is enabled.\n");
106 EnableWindow( hScroll, TRUE );
107 ok( IsWindowEnabled( hScroll ), "The scroll should be enabled.\n" );
109 ret = SetScrollPos( hScroll, SB_CTL, 30, TRUE);
110 ok( ret == 30, "The position should be set.\n" );
112 ret = GetScrollPos( hScroll, SB_CTL);
113 ok( ret == 30, "The position should not be equal to zero\n");
115 ret = SetScrollRange( hScroll, SB_CTL, 0, 100, TRUE );
116 ok( ret, "The range should be set.\n" );
118 ret = SetScrollPos( hScroll, SB_CTL, 30, TRUE);
119 ok( ret == 30, "The position should be set.\n" );
121 ret = GetScrollPos( hScroll, SB_CTL);
122 ok( ret == 30, "The position should not be equal to zero\n");
125 static void scrollbar_test3(void)
127 BOOL ret;
129 ret = ShowScrollBar( hScroll, SB_CTL, FALSE );
130 ok( ret, "The ShowScrollBar() should not failed.\n" );
131 ok( !IsWindowVisible( hScroll ), "The scrollbar window should not be visible\n" );
133 ret = ShowScrollBar( hScroll, SB_CTL, TRUE );
134 ok( ret, "The ShowScrollBar() should not failed.\n" );
135 ok( !IsWindowVisible( hScroll ), "The scrollbar window should be visible\n" );
137 ret = ShowScrollBar( NULL, SB_CTL, TRUE );
138 ok( !ret, "The ShowScrollBar() should failed.\n" );
142 static void scrollbar_test4(void)
144 BOOL ret;
145 SCROLLBARINFO sbi;
146 RECT rect;
147 BOOL (WINAPI *pGetScrollBarInfo)(HWND, LONG, LPSCROLLBARINFO);
149 pGetScrollBarInfo = (void*)GetProcAddress(GetModuleHandleA("user32.dll"), "GetScrollBarInfo");
150 if (!pGetScrollBarInfo)
152 win_skip("GetScrollBarInfo is not available\n");
153 return;
156 /* Test GetScrollBarInfo to make sure it returns rcScrollBar in screen
157 * coordinates. */
158 sbi.cbSize = sizeof(sbi);
159 ret = pGetScrollBarInfo( hScroll, OBJID_CLIENT, &sbi);
160 ok( ret, "The GetScrollBarInfo() call should not fail.\n" );
161 GetWindowRect( hScroll, &rect );
162 ok( ret, "The GetWindowRect() call should not fail.\n" );
163 ok( !(sbi.rgstate[0] & (STATE_SYSTEM_INVISIBLE|STATE_SYSTEM_OFFSCREEN)),
164 "unexpected rgstate(0x%x)\n", sbi.rgstate[0]);
165 ok( EqualRect(&rect, &sbi.rcScrollBar),
166 "WindowRect(%d, %d, %d, %d) != rcScrollBar(%d, %d, %d, %d)\n",
167 rect.top, rect.left, rect.bottom, rect.right,
168 sbi.rcScrollBar.top, sbi.rcScrollBar.left,
169 sbi.rcScrollBar.bottom, sbi.rcScrollBar.right );
171 /* Test windows horizontal and vertical scrollbar to make sure rcScrollBar
172 * is still returned in screen coordinates by moving the window, and
173 * making sure that it shifts the rcScrollBar value. */
174 ShowWindow( hMainWnd, SW_SHOW );
175 sbi.cbSize = sizeof(sbi);
176 ret = pGetScrollBarInfo( hMainWnd, OBJID_HSCROLL, &sbi);
177 ok( ret, "The GetScrollBarInfo() call should not fail.\n" );
178 GetWindowRect( hMainWnd, &rect );
179 ok( ret, "The GetWindowRect() call should not fail.\n" );
180 MoveWindow( hMainWnd, rect.left+5, rect.top+5,
181 rect.right-rect.left, rect.bottom-rect.top, TRUE );
182 rect = sbi.rcScrollBar;
183 OffsetRect(&rect, 5, 5);
184 ret = pGetScrollBarInfo( hMainWnd, OBJID_HSCROLL, &sbi);
185 ok( ret, "The GetScrollBarInfo() call should not fail.\n" );
186 ok( EqualRect(&rect, &sbi.rcScrollBar),
187 "PreviousRect(%d, %d, %d, %d) != CurrentRect(%d, %d, %d, %d)\n",
188 rect.top, rect.left, rect.bottom, rect.right,
189 sbi.rcScrollBar.top, sbi.rcScrollBar.left,
190 sbi.rcScrollBar.bottom, sbi.rcScrollBar.right );
192 sbi.cbSize = sizeof(sbi);
193 ret = pGetScrollBarInfo( hMainWnd, OBJID_VSCROLL, &sbi);
194 ok( ret, "The GetScrollBarInfo() call should not fail.\n" );
195 GetWindowRect( hMainWnd, &rect );
196 ok( ret, "The GetWindowRect() call should not fail.\n" );
197 MoveWindow( hMainWnd, rect.left+5, rect.top+5,
198 rect.right-rect.left, rect.bottom-rect.top, TRUE );
199 rect = sbi.rcScrollBar;
200 OffsetRect(&rect, 5, 5);
201 ret = pGetScrollBarInfo( hMainWnd, OBJID_VSCROLL, &sbi);
202 ok( ret, "The GetScrollBarInfo() call should not fail.\n" );
203 ok( EqualRect(&rect, &sbi.rcScrollBar),
204 "PreviousRect(%d, %d, %d, %d) != CurrentRect(%d, %d, %d, %d)\n",
205 rect.top, rect.left, rect.bottom, rect.right,
206 sbi.rcScrollBar.top, sbi.rcScrollBar.left,
207 sbi.rcScrollBar.bottom, sbi.rcScrollBar.right );
210 /* some tests designed to show that Horizontal and Vertical
211 * window scroll bar info are not created independently */
212 static void scrollbar_test_default( DWORD style)
214 INT min, max, ret;
215 DWORD winstyle;
216 HWND hwnd;
217 SCROLLINFO si = { sizeof( SCROLLINFO), SIF_TRACKPOS };
219 hwnd = CreateWindowExA( 0, "static", "", WS_POPUP | style,
220 0, 0, 10, 10, 0, 0, 0, NULL);
221 assert( hwnd != 0);
223 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
224 ok( ret ||
225 broken( !ret) /* Win 9x/ME */ , "GetScrollRange failed.\n");
226 /* range is 0,0 if there are no H or V scroll bars. 0,100 otherwise */
227 if( !( style & ( WS_VSCROLL | WS_HSCROLL)))
228 ok( min == 0 && max == 0,
229 "Scroll bar range is %d,%d. Expected 0,0. Style %08x\n", min, max, style);
230 else
231 todo_wine
232 ok(( min == 0 && max == 100) ||
233 broken( min == 0 && max == 0), /* Win 9x/ME */
234 "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
235 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
236 ok( ret ||
237 broken( !ret) /* Win 9x/ME */ , "GetScrollRange failed.\n");
238 /* range is 0,0 if there are no H or V scroll bars. 0,100 otherwise */
239 if( !( style & ( WS_VSCROLL | WS_HSCROLL)))
240 ok( min == 0 && max == 0,
241 "Scroll bar range is %d,%d. Expected 0,0. Style %08x\n", min, max, style);
242 else
243 todo_wine
244 ok(( min == 0 && max == 100) ||
245 broken( min == 0 && max == 0), /* Win 9x/ME */
246 "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
247 /* test GetScrollInfo, vist for vertical SB */
248 ret = GetScrollInfo( hwnd, SB_VERT, &si);
249 /* should fail if no H orV scroll bar styles are present. Succeed otherwise */
250 if( !( style & ( WS_VSCROLL | WS_HSCROLL)))
251 ok( !ret, "GetScrollInfo succeeded unexpectedly. Style is %08x\n", style);
252 else
253 todo_wine
254 ok( ret ||
255 broken( !ret), /* Win 9x/ME */
256 "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
257 /* Same for Horizontal SB */
258 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
259 /* should fail if no H orV scroll bar styles are present. Succeed otherwise */
260 if( !( style & ( WS_VSCROLL | WS_HSCROLL)))
261 ok( !ret, "GetScrollInfo succeeded unexpectedly. Style is %08x\n", style);
262 else
263 todo_wine
264 ok( ret ||
265 broken( !ret), /* Win 9x/ME */
266 "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
267 /* now set the Vertical Scroll range to something that could be the default value it
268 * already has */;
269 ret = SetScrollRange( hwnd, SB_VERT, 0, 100, FALSE);
270 ok( ret, "SetScrollRange failed.\n");
271 /* and request the Horizontal range */
272 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
273 ok( ret, "GetScrollRange failed.\n");
274 /* now the range should be 0,100 in ALL cases */
275 ok( min == 0 && max == 100,
276 "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
277 /* See what is different now for GetScrollRange */
278 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
279 /* should succeed in ALL cases */
280 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
281 ret = GetScrollInfo( hwnd, SB_VERT, &si);
282 /* should succeed in ALL cases */
283 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
284 /* report the windows style */
285 winstyle = GetWindowLongA( hwnd, GWL_STYLE );
286 /* WS_VSCROLL added to the window style */
287 if( !(style & WS_VSCROLL))
289 if (bThemeActive || style != WS_HSCROLL)
290 todo_wine
291 ok( (winstyle & (WS_HSCROLL|WS_VSCROLL)) == ( style | WS_VSCROLL),
292 "unexpected style change %8lx expected %8lx\n",
293 (winstyle & (WS_HSCROLL|WS_VSCROLL)), style | WS_VSCROLL);
294 else
295 ok( (winstyle & (WS_HSCROLL|WS_VSCROLL)) == style ||
296 broken((winstyle & (WS_HSCROLL|WS_VSCROLL)) == (WS_HSCROLL|WS_VSCROLL)), /* Win 9x/ME */
297 "unexpected style change %8lx expected %8x\n",
298 (winstyle & (WS_HSCROLL|WS_VSCROLL)), style);
300 /* do the test again with H and V reversed.
301 * Start with a clean window */
302 DestroyWindow( hwnd);
303 hwnd = CreateWindowExA( 0, "static", "", WS_POPUP | style,
304 0, 0, 10, 10, 0, 0, 0, NULL);
305 assert( hwnd != 0);
306 /* Set Horizonta Scroll range to something that could be the default value it
307 * already has */;
308 ret = SetScrollRange( hwnd, SB_HORZ, 0, 100, FALSE);
309 ok( ret, "SetScrollRange failed.\n");
310 /* and request the Vertical range */
311 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
312 ok( ret, "GetScrollRange failed.\n");
313 /* now the range should be 0,100 in ALL cases */
314 ok( min == 0 && max == 100,
315 "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
316 /* See what is different now for GetScrollRange */
317 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
318 /* should succeed in ALL cases */
319 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
320 ret = GetScrollInfo( hwnd, SB_VERT, &si);
321 /* should succeed in ALL cases */
322 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
323 /* report the windows style */
324 winstyle = GetWindowLongA( hwnd, GWL_STYLE );
325 /* WS_HSCROLL added to the window style */
326 if( !(style & WS_HSCROLL))
328 if (bThemeActive || style != WS_VSCROLL)
329 todo_wine
330 ok( (winstyle & (WS_HSCROLL|WS_VSCROLL)) == ( style | WS_HSCROLL),
331 "unexpected style change %8lx expected %8lx\n",
332 (winstyle & (WS_HSCROLL|WS_VSCROLL)), style | WS_HSCROLL);
333 else
334 ok( (winstyle & (WS_HSCROLL|WS_VSCROLL)) == style ||
335 broken((winstyle & (WS_HSCROLL|WS_VSCROLL)) == (WS_HSCROLL|WS_VSCROLL)), /* Win 9x/ME */
336 "unexpected style change %8lx expected %8x\n",
337 (winstyle & (WS_HSCROLL|WS_VSCROLL)), style);
339 /* Slightly change the test to use SetScrollInfo
340 * Start with a clean window */
341 DestroyWindow( hwnd);
342 hwnd = CreateWindowExA( 0, "static", "", WS_POPUP | style,
343 0, 0, 10, 10, 0, 0, 0, NULL);
344 assert( hwnd != 0);
345 /* set Horizontal position with SetScrollInfo */
346 si.nPos = 0;
347 si.nMin = 11;
348 si.nMax = 22;
349 si.fMask |= SIF_RANGE;
350 ret = SetScrollInfo( hwnd, SB_HORZ, &si, FALSE);
351 ok( ret, "SetScrollInfo failed. Style is %08x\n", style);
352 /* and request the Vertical range */
353 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
354 ok( ret, "GetScrollRange failed.\n");
355 /* now the range should be 0,100 in ALL cases */
356 ok( min == 0 && max == 100,
357 "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
358 /* See what is different now for GetScrollRange */
359 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
360 /* should succeed in ALL cases */
361 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
362 ret = GetScrollInfo( hwnd, SB_VERT, &si);
363 /* should succeed in ALL cases */
364 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
365 /* also test if the window scroll bars are enabled */
366 ret = EnableScrollBar( hwnd, SB_VERT, ESB_ENABLE_BOTH);
367 ok( !ret, "Vertical window scroll bar was not enabled\n");
368 ret = EnableScrollBar( hwnd, SB_HORZ, ESB_ENABLE_BOTH);
369 ok( !ret, "Horizontal window scroll bar was not enabled\n");
370 DestroyWindow( hwnd);
371 /* finally, check if adding a WS_[HV]SColl style of a window makes the scroll info
372 * available */
373 if( style & (WS_HSCROLL | WS_VSCROLL)) return;/* only test if not yet set */
374 /* Start with a clean window */
375 DestroyWindow( hwnd);
376 hwnd = CreateWindowExA( 0, "static", "", WS_POPUP ,
377 0, 0, 10, 10, 0, 0, 0, NULL);
378 assert( hwnd != 0);
379 ret = GetScrollInfo( hwnd, SB_VERT, &si);
380 /* should fail */
381 ok( !ret, "GetScrollInfo succeeded unexpectedly. Style is %08x\n", style);
382 /* add scroll styles */
383 winstyle = GetWindowLongA( hwnd, GWL_STYLE );
384 SetWindowLongW( hwnd, GWL_STYLE, winstyle | WS_VSCROLL | WS_HSCROLL);
385 ret = GetScrollInfo( hwnd, SB_VERT, &si);
386 /* should still fail */
387 ok( !ret, "GetScrollInfo succeeded unexpectedly. Style is %08x\n", style);
388 /* clean up */
389 DestroyWindow( hwnd);
392 START_TEST ( scroll )
394 WNDCLASSA wc;
395 HMODULE hUxtheme;
396 BOOL (WINAPI * pIsThemeActive)(VOID);
398 wc.style = CS_HREDRAW | CS_VREDRAW;
399 wc.cbClsExtra = 0;
400 wc.cbWndExtra = 0;
401 wc.hInstance = GetModuleHandleA(NULL);
402 wc.hIcon = NULL;
403 wc.hCursor = LoadCursorA(NULL, IDC_IBEAM);
404 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
405 wc.lpszMenuName = NULL;
406 wc.lpszClassName = "MyTestWnd";
407 wc.lpfnWndProc = MyWndProc;
408 RegisterClassA(&wc);
410 hMainWnd = CreateWindowExA( 0, "MyTestWnd", "Scroll",
411 WS_OVERLAPPEDWINDOW|WS_VSCROLL|WS_HSCROLL,
412 CW_USEDEFAULT, CW_USEDEFAULT, 100, 100, NULL, NULL, GetModuleHandleA(NULL), 0 );
414 if ( !ok( hMainWnd != NULL, "Failed to create parent window. Tests aborted.\n" ) )
415 return;
417 assert( hScroll );
419 scrollbar_test1();
420 scrollbar_test2();
421 scrollbar_test3();
422 scrollbar_test4();
424 /* Some test results vary depending of theming being active or not */
425 hUxtheme = LoadLibraryA("uxtheme.dll");
426 if (hUxtheme)
428 pIsThemeActive = (void*)GetProcAddress(hUxtheme, "IsThemeActive");
429 if (pIsThemeActive)
430 bThemeActive = pIsThemeActive();
431 FreeLibrary(hUxtheme);
434 scrollbar_test_default( 0);
435 scrollbar_test_default( WS_HSCROLL);
436 scrollbar_test_default( WS_VSCROLL);
437 scrollbar_test_default( WS_HSCROLL | WS_VSCROLL);
439 DestroyWindow(hScroll);
440 DestroyWindow(hMainWnd);