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
26 #include "wine/test.h"
28 static HWND hScroll
, hMainWnd
;
30 static LRESULT CALLBACK
MyWndProc( HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
37 hScroll
= CreateWindowA( "SCROLLBAR", "", WS_CHILD
| WS_VISIBLE
, 0, 0, 120, 100, hWnd
, (HMENU
)100, GetModuleHandleA(0), 0 );
46 return DefWindowProcA(hWnd
, msg
, wParam
, lParam
);
51 static void scrollbar_test1(void)
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)
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)
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)
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");
155 /* Test GetScrollBarInfo to make sure it returns rcScrollBar in screen
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 START_TEST ( scroll
)
213 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
216 wc
.hInstance
= GetModuleHandleA(NULL
);
218 wc
.hCursor
= LoadCursorA(NULL
, IDC_IBEAM
);
219 wc
.hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
220 wc
.lpszMenuName
= NULL
;
221 wc
.lpszClassName
= "MyTestWnd";
222 wc
.lpfnWndProc
= MyWndProc
;
225 hMainWnd
= CreateWindowExA( 0, "MyTestWnd", "Scroll",
226 WS_OVERLAPPEDWINDOW
|WS_VSCROLL
|WS_HSCROLL
,
227 CW_USEDEFAULT
, CW_USEDEFAULT
, 100, 100, NULL
, NULL
, GetModuleHandleA(NULL
), 0 );
229 if ( !ok( hMainWnd
!= NULL
, "Failed to create parent window. Tests aborted.\n" ) )
239 DestroyWindow(hScroll
);
240 DestroyWindow(hMainWnd
);