1 /* Unit tests for the up-down control
3 * Copyright 2005 C. Scott Ananian
4 * Copyright (C) 2007 James Hawkins
5 * Copyright (C) 2007 Leslie Choong
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 * - send click messages to the up-down control, check the current position
24 * - up-down control automatically positions itself next to its buddy window
25 * - up-down control sets the caption of the buddy window
26 * - test CreateUpDownControl API
27 * - check UDS_AUTOBUDDY style, up-down control selects previous window in z-order
28 * - check UDM_SETBUDDY message
29 * - check UDM_GETBUDDY message
30 * - up-down control and buddy control must have the same parent
31 * - check UDS_ALIGN[LEFT,RIGHT]...check that width of buddy window is decreased
32 * - check that UDS_SETBUDDYINT sets the caption of the buddy window when it is changed
33 * - check that the thousands operator is set for large numbers
34 * - check that the thousands operator is not set with UDS_NOTHOUSANDS
35 * - check UDS_ARROWKEYS, control subclasses the buddy window so that it processes the keys when it has focus
37 * - check changing past min/max values
38 * - check UDS_WRAP wraps values past min/max, incrementing past upper value wraps position to lower value
39 * - can change control's position, min/max pos, radix
40 * - check UDM_GETPOS, for up-down control with a buddy window, position is the caption of the buddy window, so change the
41 * caption of the buddy window then call UDM_GETPOS
42 * - check UDM_SETRANGE, max can be less than min, so clicking the up arrow decreases the current position
43 * - more stuff to test
50 #include "wine/test.h"
53 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
55 #define NUM_MSG_SEQUENCES 3
56 #define PARENT_SEQ_INDEX 0
57 #define EDIT_SEQ_INDEX 1
58 #define UPDOWN_SEQ_INDEX 2
63 static HWND parent_wnd
, g_edit
;
65 static HWND (WINAPI
*pCreateUpDownControl
)(DWORD
, INT
, INT
, INT
, INT
,
66 HWND
, INT
, HINSTANCE
, HWND
, INT
, INT
, INT
);
67 static BOOL (WINAPI
*pSetWindowSubclass
)(HWND
, SUBCLASSPROC
, UINT_PTR
, DWORD_PTR
);
69 static struct msg_sequence
*sequences
[NUM_MSG_SEQUENCES
];
71 static const struct message add_updown_with_edit_seq
[] = {
72 { WM_WINDOWPOSCHANGING
, sent
},
73 { WM_NCCALCSIZE
, sent
|wparam
, TRUE
},
74 { WM_WINDOWPOSCHANGED
, sent
},
75 { WM_SIZE
, sent
|wparam
|defwinproc
, SIZE_RESTORED
/*, MAKELONG(91, 75) exact size depends on font */ },
79 static const struct message add_updown_to_parent_seq
[] = {
80 { WM_NOTIFYFORMAT
, sent
|lparam
, 0, NF_QUERY
},
81 { WM_QUERYUISTATE
, sent
|optional
},
82 { WM_PARENTNOTIFY
, sent
|wparam
, MAKELONG(WM_CREATE
, WM_CREATE
) },
86 static const struct message get_edit_text_seq
[] = {
91 static const struct message test_updown_pos_seq
[] = {
92 { UDM_SETRANGE
, sent
|lparam
, 0, MAKELONG(100,0) },
93 { UDM_GETRANGE
, sent
},
94 { UDM_SETPOS
, sent
|lparam
, 0, 5},
96 { UDM_SETPOS
, sent
|lparam
, 0, 0},
98 { UDM_SETPOS
, sent
|lparam
, 0, MAKELONG(-1,0)},
100 { UDM_SETPOS
, sent
|lparam
, 0, 100},
102 { UDM_SETPOS
, sent
|lparam
, 0, 101},
107 static const struct message test_updown_pos32_seq
[] = {
108 { UDM_SETRANGE32
, sent
|lparam
, 0, 1000 },
109 { UDM_GETRANGE32
, sent
}, /* Cannot check wparam and lparam as they are ptrs */
110 { UDM_SETPOS32
, sent
|lparam
, 0, 500 },
111 { UDM_GETPOS32
, sent
},
112 { UDM_SETPOS32
, sent
|lparam
, 0, 0 },
113 { UDM_GETPOS32
, sent
},
114 { UDM_SETPOS32
, sent
|lparam
, 0, -1 },
115 { UDM_GETPOS32
, sent
},
116 { UDM_SETPOS32
, sent
|lparam
, 0, 1000 },
117 { UDM_GETPOS32
, sent
},
118 { UDM_SETPOS32
, sent
|lparam
, 0, 1001 },
119 { UDM_GETPOS32
, sent
},
123 static const struct message test_updown_buddy_seq
[] = {
124 { UDM_GETBUDDY
, sent
},
125 { UDM_SETBUDDY
, sent
},
126 { WM_STYLECHANGING
, sent
|defwinproc
},
127 { WM_STYLECHANGED
, sent
|defwinproc
},
128 { WM_STYLECHANGING
, sent
|defwinproc
},
129 { WM_STYLECHANGED
, sent
|defwinproc
},
130 { WM_WINDOWPOSCHANGING
, sent
|defwinproc
},
131 { WM_NCCALCSIZE
, sent
|wparam
|optional
|defwinproc
, 1 },
132 { WM_WINDOWPOSCHANGED
, sent
|defwinproc
},
133 { WM_MOVE
, sent
|defwinproc
},
134 { UDM_GETBUDDY
, sent
},
138 static const struct message test_updown_base_seq
[] = {
139 { UDM_SETBASE
, sent
|wparam
, 10 },
140 { UDM_GETBASE
, sent
},
141 { UDM_SETBASE
, sent
|wparam
, 80 },
142 { UDM_GETBASE
, sent
},
143 { UDM_SETBASE
, sent
|wparam
, 16 },
144 { UDM_GETBASE
, sent
},
145 { UDM_SETBASE
, sent
|wparam
, 80 },
146 { UDM_GETBASE
, sent
},
147 { UDM_SETBASE
, sent
|wparam
, 10 },
148 { UDM_GETBASE
, sent
},
152 static const struct message test_updown_unicode_seq
[] = {
153 { UDM_SETUNICODEFORMAT
, sent
|wparam
, 0 },
154 { UDM_GETUNICODEFORMAT
, sent
},
155 { UDM_SETUNICODEFORMAT
, sent
|wparam
, 1 },
156 { UDM_GETUNICODEFORMAT
, sent
},
157 { UDM_SETUNICODEFORMAT
, sent
|wparam
, 0 },
158 { UDM_GETUNICODEFORMAT
, sent
},
162 static const struct message test_updown_pos_nochange_seq
[] = {
163 { WM_GETTEXT
, sent
|id
, 0, 0, BUDDY_ID
},
167 static const struct message test_updown_pos_notifications_seq
[] = {
168 { WM_CTLCOLOREDIT
, sent
|optional
},
169 { WM_COMMAND
, sent
|wparam
, MAKELONG(0, EN_SETFOCUS
) },
170 { WM_NOTIFY
, sent
|id
, 0, 0, UDN_DELTAPOS
},
171 { WM_COMMAND
, sent
|wparam
, MAKELONG(0, EN_UPDATE
) },
172 { WM_COMMAND
, sent
|wparam
, MAKELONG(0, EN_CHANGE
) },
173 { WM_VSCROLL
, sent
|wparam
, MAKELONG(SB_THUMBPOSITION
, 51) },
174 { WM_CTLCOLOREDIT
, sent
|optional
},
175 { WM_VSCROLL
, sent
|wparam
, MAKELONG(SB_ENDSCROLL
, 51) },
176 /* no WM_NOTIFY(NM_RELEASEDCAPTURE) message */
180 static const struct message test_updown_pos_notifications_horz_seq
[] = {
181 { WM_CTLCOLOREDIT
, sent
|optional
},
182 { WM_COMMAND
, sent
|wparam
, MAKELONG(0, EN_SETFOCUS
) },
183 { WM_NOTIFY
, sent
|id
, 0, 0, UDN_DELTAPOS
},
184 { WM_COMMAND
, sent
|wparam
, MAKELONG(0, EN_UPDATE
) },
185 { WM_COMMAND
, sent
|wparam
, MAKELONG(0, EN_CHANGE
) },
186 { WM_HSCROLL
, sent
|wparam
, MAKELONG(SB_THUMBPOSITION
, 51) },
187 { WM_CTLCOLOREDIT
, sent
|optional
},
188 { WM_HSCROLL
, sent
|wparam
, MAKELONG(SB_ENDSCROLL
, 51) },
189 /* no WM_NOTIFY(NM_RELEASEDCAPTURE) message */
193 static LRESULT WINAPI
parent_wnd_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
195 static LONG defwndproc_counter
= 0;
196 struct message msg
= { 0 };
199 /* log system messages, except for painting */
200 if (message
< WM_USER
&&
201 message
!= WM_PAINT
&&
202 message
!= WM_ERASEBKGND
&&
203 message
!= WM_NCPAINT
&&
204 message
!= WM_NCHITTEST
&&
205 message
!= WM_GETTEXT
&&
206 message
!= WM_GETICON
&&
207 message
!= WM_DEVICECHANGE
)
209 msg
.message
= message
;
210 msg
.flags
= sent
|wparam
|lparam
;
211 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
214 if (message
== WM_NOTIFY
&& lParam
)
215 msg
.id
= ((NMHDR
*)lParam
)->code
;
216 add_message(sequences
, PARENT_SEQ_INDEX
, &msg
);
219 defwndproc_counter
++;
220 ret
= DefWindowProcA(hwnd
, message
, wParam
, lParam
);
221 defwndproc_counter
--;
226 static BOOL
register_parent_wnd_class(void)
231 cls
.lpfnWndProc
= parent_wnd_proc
;
234 cls
.hInstance
= GetModuleHandleA(NULL
);
236 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
237 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
238 cls
.lpszMenuName
= NULL
;
239 cls
.lpszClassName
= "Up-Down test parent class";
240 return RegisterClassA(&cls
);
243 static HWND
create_parent_window(void)
245 if (!register_parent_wnd_class())
248 return CreateWindowExA(0, "Up-Down test parent class",
249 "Up-Down test parent window",
250 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
251 WS_MAXIMIZEBOX
| WS_VISIBLE
,
253 GetDesktopWindow(), NULL
, GetModuleHandleA(NULL
), NULL
);
256 static LRESULT WINAPI
edit_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
258 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
259 static LONG defwndproc_counter
= 0;
260 struct message msg
= { 0 };
263 msg
.message
= message
;
264 msg
.flags
= sent
|wparam
|lparam
;
265 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
269 add_message(sequences
, EDIT_SEQ_INDEX
, &msg
);
271 defwndproc_counter
++;
272 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
273 defwndproc_counter
--;
277 static HWND
create_edit_control(void)
283 GetClientRect(parent_wnd
, &rect
);
284 hwnd
= CreateWindowExA(0, WC_EDITA
, NULL
, WS_CHILD
| WS_BORDER
| WS_VISIBLE
,
285 0, 0, rect
.right
, rect
.bottom
,
286 parent_wnd
, NULL
, GetModuleHandleA(NULL
), NULL
);
287 if (!hwnd
) return NULL
;
289 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
290 (LONG_PTR
)edit_subclass_proc
);
291 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
296 static LRESULT WINAPI
updown_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
298 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
299 static LONG defwndproc_counter
= 0;
300 struct message msg
= { 0 };
303 msg
.message
= message
;
304 msg
.flags
= sent
|wparam
|lparam
;
305 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
309 add_message(sequences
, UPDOWN_SEQ_INDEX
, &msg
);
311 defwndproc_counter
++;
312 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
313 defwndproc_counter
--;
318 static HWND
create_updown_control(DWORD style
, HWND buddy
)
324 GetClientRect(parent_wnd
, &rect
);
325 updown
= CreateWindowExA(0, UPDOWN_CLASSA
, NULL
, WS_CHILD
| WS_BORDER
| WS_VISIBLE
| style
,
326 0, 0, rect
.right
, rect
.bottom
,
327 parent_wnd
, (HMENU
)1, GetModuleHandleA(NULL
), NULL
);
328 ok(updown
!= NULL
, "Failed to create UpDown control.\n");
329 if (!updown
) return NULL
;
331 SendMessageA(updown
, UDM_SETBUDDY
, (WPARAM
)buddy
, 0);
332 SendMessageA(updown
, UDM_SETRANGE
, 0, MAKELONG(100, 0));
333 SendMessageA(updown
, UDM_SETPOS
, 0, MAKELONG(50, 0));
335 oldproc
= (WNDPROC
)SetWindowLongPtrA(updown
, GWLP_WNDPROC
,
336 (LONG_PTR
)updown_subclass_proc
);
337 SetWindowLongPtrA(updown
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
342 static void test_updown_pos(void)
347 updown
= create_updown_control(UDS_ALIGNRIGHT
, g_edit
);
349 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
351 /* Set Range from 0 to 100 */
352 SendMessageA(updown
, UDM_SETRANGE
, 0 , MAKELONG(100,0) );
353 r
= SendMessageA(updown
, UDM_GETRANGE
, 0,0);
354 expect(100,LOWORD(r
));
357 /* Set the position to 5, return is not checked as it was set before func call */
358 SendMessageA(updown
, UDM_SETPOS
, 0 , MAKELONG(5,0) );
359 /* Since UDM_SETBUDDYINT was not set at creation HIWORD(r) will always be 1 as a return from UDM_GETPOS */
360 /* Get the position, which should be 5 */
361 r
= SendMessageA(updown
, UDM_GETPOS
, 0 , 0 );
365 /* Set the position to 0, return should be 5 */
366 r
= SendMessageA(updown
, UDM_SETPOS
, 0 , MAKELONG(0,0) );
368 /* Get the position, which should be 0 */
369 r
= SendMessageA(updown
, UDM_GETPOS
, 0 , 0 );
373 /* Set the position to -1, return should be 0 */
374 r
= SendMessageA(updown
, UDM_SETPOS
, 0 , MAKELONG(-1,0) );
376 /* Get the position, which should be 0 */
377 r
= SendMessageA(updown
, UDM_GETPOS
, 0 , 0 );
381 /* Set the position to 100, return should be 0 */
382 r
= SendMessageA(updown
, UDM_SETPOS
, 0 , MAKELONG(100,0) );
384 /* Get the position, which should be 100 */
385 r
= SendMessageA(updown
, UDM_GETPOS
, 0 , 0 );
386 expect(100,LOWORD(r
));
389 /* Set the position to 101, return should be 100 */
390 r
= SendMessageA(updown
, UDM_SETPOS
, 0 , MAKELONG(101,0) );
392 /* Get the position, which should be 100 */
393 r
= SendMessageA(updown
, UDM_GETPOS
, 0 , 0 );
394 expect(100,LOWORD(r
));
397 ok_sequence(sequences
, UPDOWN_SEQ_INDEX
, test_updown_pos_seq
, "test updown pos", FALSE
);
399 DestroyWindow(updown
);
401 /* there's no attempt to update buddy Edit if text didn't change */
402 SetWindowTextA(g_edit
, "50");
403 updown
= create_updown_control(UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
| UDS_ARROWKEYS
, g_edit
);
405 /* test sequence only on 5.8x versions */
406 r
= SendMessageA(updown
, UDM_GETPOS32
, 0, 0);
411 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
413 r
= SendMessageA(updown
, UDM_SETPOS
, 0, 50);
416 ok_sequence(sequences
, EDIT_SEQ_INDEX
, test_updown_pos_nochange_seq
,
417 "test updown pos, no change", FALSE
);
419 SendMessageA(updown
, UDM_SETRANGE
, 0, MAKELONG(1, 40));
420 r
= SendMessageA(updown
, UDM_GETRANGE
, 0, 0);
421 expect(1, LOWORD(r
));
422 expect(40, HIWORD(r
));
426 r
= SendMessageA(updown
, UDM_SETACCEL
, 1, (LPARAM
)&accel
);
429 r
= SendMessageA(updown
, UDM_GETPOS
, 0, 0);
430 expect(40, LOWORD(r
));
431 expect(1, HIWORD(r
));
433 r
= SendMessageA(updown
, UDM_SETPOS
, 0, MAKELONG(0, 0));
434 expect(40, LOWORD(r
));
435 expect(0, HIWORD(r
));
437 r
= SendMessageA(updown
, UDM_GETPOS
, 0, 0);
438 expect(1, LOWORD(r
));
439 expect(0, HIWORD(r
));
441 r
= SendMessageA(updown
, UDM_SETPOS
, 0, MAKELONG(2, 0));
442 expect(1, LOWORD(r
));
443 expect(0, HIWORD(r
));
445 r
= SendMessageA(g_edit
, WM_KEYDOWN
, VK_UP
, 0);
447 r
= SendMessageA(updown
, UDM_GETPOS
, 0, 0);
448 expect(1, LOWORD(r
));
449 expect(0, HIWORD(r
));
451 r
= SendMessageA(updown
, UDM_SETPOS
, 0, MAKELONG(50, 0));
452 expect(1, LOWORD(r
));
453 expect(0, HIWORD(r
));
455 r
= SendMessageA(updown
, UDM_GETPOS
, 0, 0);
456 expect(40, LOWORD(r
));
457 expect(0, HIWORD(r
));
460 DestroyWindow(updown
);
463 static void test_updown_pos32(void)
469 updown
= create_updown_control(UDS_ALIGNRIGHT
, g_edit
);
471 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
473 /* Set the position to 0 to 1000 */
474 SendMessageA(updown
, UDM_SETRANGE32
, 0 , 1000 );
477 r
= SendMessageA(updown
, UDM_GETRANGE32
, (WPARAM
) &low
, (LPARAM
) &high
);
481 win_skip("UDM_SETRANGE32/UDM_GETRANGE32 not available\n");
482 DestroyWindow(updown
);
489 /* Set position to 500 */
490 r
= SendMessageA(updown
, UDM_SETPOS32
, 0 , 500 );
493 win_skip("UDM_SETPOS32 and UDM_GETPOS32 need 5.80\n");
494 DestroyWindow(updown
);
499 /* Since UDM_SETBUDDYINT was not set at creation bRet will always be true as a return from UDM_GETPOS32 */
501 r
= SendMessageA(updown
, UDM_GETPOS32
, 0 , (LPARAM
) &high
);
505 /* Set position to 0, return should be 500 */
506 r
= SendMessageA(updown
, UDM_SETPOS32
, 0 , 0 );
508 r
= SendMessageA(updown
, UDM_GETPOS32
, 0 , (LPARAM
) &high
);
512 /* Set position to -1 which should become 0, return should be 0 */
513 r
= SendMessageA(updown
, UDM_SETPOS32
, 0 , -1 );
515 r
= SendMessageA(updown
, UDM_GETPOS32
, 0 , (LPARAM
) &high
);
519 /* Set position to 1000, return should be 0 */
520 r
= SendMessageA(updown
, UDM_SETPOS32
, 0 , 1000 );
522 r
= SendMessageA(updown
, UDM_GETPOS32
, 0 , (LPARAM
) &high
);
526 /* Set position to 1001 which should become 1000, return should be 1000 */
527 r
= SendMessageA(updown
, UDM_SETPOS32
, 0 , 1001 );
529 r
= SendMessageA(updown
, UDM_GETPOS32
, 0 , (LPARAM
) &high
);
533 ok_sequence(sequences
, UPDOWN_SEQ_INDEX
, test_updown_pos32_seq
, "test updown pos32", FALSE
);
535 DestroyWindow(updown
);
537 /* there's no attempt to update buddy Edit if text didn't change */
538 SetWindowTextA(g_edit
, "50");
539 updown
= create_updown_control(UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
, g_edit
);
541 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
543 r
= SendMessageA(updown
, UDM_SETPOS32
, 0, 50);
545 ok_sequence(sequences
, EDIT_SEQ_INDEX
, test_updown_pos_nochange_seq
,
546 "test updown pos, no change", FALSE
);
548 DestroyWindow(updown
);
551 static void test_updown_buddy(void)
553 HWND updown
, buddyReturn
, buddy
;
558 updown
= create_updown_control(UDS_ALIGNRIGHT
, g_edit
);
560 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
562 buddyReturn
= (HWND
)SendMessageA(updown
, UDM_GETBUDDY
, 0 , 0 );
563 ok(buddyReturn
== g_edit
, "Expected edit handle\n");
565 buddyReturn
= (HWND
)SendMessageA(updown
, UDM_SETBUDDY
, (WPARAM
) g_edit
, 0);
566 ok(buddyReturn
== g_edit
, "Expected edit handle\n");
568 buddyReturn
= (HWND
)SendMessageA(updown
, UDM_GETBUDDY
, 0 , 0 );
569 ok(buddyReturn
== g_edit
, "Expected edit handle\n");
571 ok_sequence(sequences
, UPDOWN_SEQ_INDEX
, test_updown_buddy_seq
, "test updown buddy", TRUE
);
572 ok_sequence(sequences
, EDIT_SEQ_INDEX
, add_updown_with_edit_seq
, "test updown buddy_edit", FALSE
);
574 DestroyWindow(updown
);
576 buddy
= create_edit_control();
577 proc
= (WNDPROC
)GetWindowLongPtrA(buddy
, GWLP_WNDPROC
);
579 updown
= create_updown_control(UDS_ALIGNRIGHT
, buddy
);
580 ok(proc
== (WNDPROC
)GetWindowLongPtrA(buddy
, GWLP_WNDPROC
), "No subclassing expected\n");
582 style
= GetWindowLongA(updown
, GWL_STYLE
);
583 SetWindowLongA(updown
, GWL_STYLE
, style
| UDS_ARROWKEYS
);
584 style
= GetWindowLongA(updown
, GWL_STYLE
);
585 ok(style
& UDS_ARROWKEYS
, "Expected UDS_ARROWKEYS\n");
586 /* no subclass if UDS_ARROWKEYS set after creation */
587 ok(proc
== (WNDPROC
)GetWindowLongPtrA(buddy
, GWLP_WNDPROC
), "No subclassing expected\n");
589 DestroyWindow(updown
);
591 updown
= create_updown_control(UDS_ALIGNRIGHT
| UDS_ARROWKEYS
, buddy
);
592 ok(proc
!= (WNDPROC
)GetWindowLongPtrA(buddy
, GWLP_WNDPROC
), "Subclassing expected\n");
594 if (pSetWindowSubclass
)
596 /* updown uses subclass helpers for buddy on >5.8x systems */
597 ok(GetPropA(buddy
, "CC32SubclassInfo") != NULL
, "Expected CC32SubclassInfo property\n");
600 DestroyWindow(updown
);
601 DestroyWindow(buddy
);
603 /* Create with buddy and UDS_HORZ, reset buddy. */
604 updown
= create_updown_control(UDS_HORZ
, g_edit
);
606 buddyReturn
= (HWND
)SendMessageA(updown
, UDM_GETBUDDY
, 0, 0);
607 ok(buddyReturn
== g_edit
, "Unexpected buddy window.\n");
609 GetClientRect(updown
, &rect
);
611 buddyReturn
= (HWND
)SendMessageA(updown
, UDM_SETBUDDY
, 0, 0);
612 ok(buddyReturn
== g_edit
, "Unexpected buddy window.\n");
614 GetClientRect(updown
, &rect2
);
615 ok(EqualRect(&rect
, &rect2
), "Unexpected window rect.\n");
617 /* Remove UDS_HORZ, reset buddy again. */
618 style
= GetWindowLongA(updown
, GWL_STYLE
);
619 SetWindowLongA(updown
, GWL_STYLE
, style
& ~UDS_HORZ
);
620 style
= GetWindowLongA(updown
, GWL_STYLE
);
621 ok(!(style
& UDS_HORZ
), "Unexpected style.\n");
623 buddyReturn
= (HWND
)SendMessageA(updown
, UDM_SETBUDDY
, 0, 0);
624 ok(buddyReturn
== NULL
, "Unexpected buddy window.\n");
626 GetClientRect(updown
, &rect2
);
627 ok(EqualRect(&rect
, &rect2
), "Unexpected window rect.\n");
629 DestroyWindow(updown
);
631 /* Without UDS_HORZ. */
632 updown
= create_updown_control(0, g_edit
);
634 buddyReturn
= (HWND
)SendMessageA(updown
, UDM_GETBUDDY
, 0, 0);
635 ok(buddyReturn
== g_edit
, "Unexpected buddy window.\n");
637 GetClientRect(updown
, &rect
);
639 buddyReturn
= (HWND
)SendMessageA(updown
, UDM_SETBUDDY
, 0, 0);
640 ok(buddyReturn
== g_edit
, "Unexpected buddy window.\n");
642 GetClientRect(updown
, &rect2
);
643 ok(EqualRect(&rect
, &rect2
), "Unexpected window rect.\n");
645 DestroyWindow(updown
);
647 /* Create without buddy. */
648 GetClientRect(parent_wnd
, &rect
);
649 updown
= CreateWindowExA(0, UPDOWN_CLASSA
, NULL
, WS_CHILD
| WS_BORDER
| WS_VISIBLE
| UDS_HORZ
,
650 0, 0, rect
.right
, rect
.bottom
, parent_wnd
, (HMENU
)1, GetModuleHandleA(NULL
), NULL
);
651 ok(updown
!= NULL
, "Failed to create UpDown control.\n");
653 GetClientRect(updown
, &rect
);
654 buddyReturn
= (HWND
)SendMessageA(updown
, UDM_SETBUDDY
, 0, 0);
655 ok(buddyReturn
== NULL
, "Unexpected buddy window.\n");
656 GetClientRect(updown
, &rect2
);
658 ok(EqualRect(&rect
, &rect2
), "Unexpected window rect.\n");
660 style
= GetWindowLongA(updown
, GWL_STYLE
);
661 SetWindowLongA(updown
, GWL_STYLE
, style
& ~UDS_HORZ
);
663 GetClientRect(updown
, &rect2
);
664 ok(EqualRect(&rect
, &rect2
), "Unexpected window rect.\n");
666 buddyReturn
= (HWND
)SendMessageA(updown
, UDM_SETBUDDY
, (WPARAM
)g_edit
, 0);
667 ok(buddyReturn
== NULL
, "Unexpected buddy window.\n");
668 GetClientRect(updown
, &rect
);
670 buddyReturn
= (HWND
)SendMessageA(updown
, UDM_SETBUDDY
, 0, 0);
671 ok(buddyReturn
== g_edit
, "Unexpected buddy window.\n");
672 GetClientRect(updown
, &rect2
);
674 ok(EqualRect(&rect
, &rect2
), "Unexpected window rect.\n");
676 DestroyWindow(updown
);
679 static void test_updown_base(void)
685 updown
= create_updown_control(UDS_ALIGNRIGHT
, g_edit
);
687 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
689 SendMessageA(updown
, UDM_SETBASE
, 10 , 0);
690 r
= SendMessageA(updown
, UDM_GETBASE
, 0 , 0);
693 /* Set base to an invalid value, should return 0 and stay at 10 */
694 r
= SendMessageA(updown
, UDM_SETBASE
, 80 , 0);
696 r
= SendMessageA(updown
, UDM_GETBASE
, 0 , 0);
699 /* Set base to 16 now, should get 16 as the return */
700 r
= SendMessageA(updown
, UDM_SETBASE
, 16 , 0);
702 r
= SendMessageA(updown
, UDM_GETBASE
, 0 , 0);
705 /* Set base to an invalid value, should return 0 and stay at 16 */
706 r
= SendMessageA(updown
, UDM_SETBASE
, 80 , 0);
708 r
= SendMessageA(updown
, UDM_GETBASE
, 0 , 0);
711 /* Set base back to 10, return should be 16 */
712 r
= SendMessageA(updown
, UDM_SETBASE
, 10 , 0);
714 r
= SendMessageA(updown
, UDM_GETBASE
, 0 , 0);
717 ok_sequence(sequences
, UPDOWN_SEQ_INDEX
, test_updown_base_seq
, "test updown base", FALSE
);
719 DestroyWindow(updown
);
721 /* switch base with buddy attached */
722 updown
= create_updown_control(UDS_SETBUDDYINT
| UDS_ALIGNRIGHT
, g_edit
);
724 r
= SendMessageA(updown
, UDM_SETPOS
, 0, 10);
727 GetWindowTextA(g_edit
, text
, ARRAY_SIZE(text
));
728 ok(lstrcmpA(text
, "10") == 0, "Expected '10', got '%s'\n", text
);
730 r
= SendMessageA(updown
, UDM_SETBASE
, 16, 0);
733 GetWindowTextA(g_edit
, text
, ARRAY_SIZE(text
));
734 /* FIXME: currently hex output isn't properly formatted, but for this
735 test only change from initial text matters */
736 ok(lstrcmpA(text
, "10") != 0, "Expected '0x000A', got '%s'\n", text
);
738 DestroyWindow(updown
);
741 static void test_updown_unicode(void)
746 updown
= create_updown_control(UDS_ALIGNRIGHT
, g_edit
);
748 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
750 /* Set it to ANSI, don't check return as we don't know previous state */
751 SendMessageA(updown
, UDM_SETUNICODEFORMAT
, 0 , 0);
752 r
= SendMessageA(updown
, UDM_GETUNICODEFORMAT
, 0 , 0);
755 /* Now set it to Unicode format */
756 r
= SendMessageA(updown
, UDM_SETUNICODEFORMAT
, 1 , 0);
758 r
= SendMessageA(updown
, UDM_GETUNICODEFORMAT
, 0 , 0);
761 win_skip("UDM_SETUNICODEFORMAT not available\n");
762 DestroyWindow(updown
);
767 /* And now set it back to ANSI */
768 r
= SendMessageA(updown
, UDM_SETUNICODEFORMAT
, 0 , 0);
770 r
= SendMessageA(updown
, UDM_GETUNICODEFORMAT
, 0 , 0);
773 ok_sequence(sequences
, UPDOWN_SEQ_INDEX
, test_updown_unicode_seq
, "test updown unicode", FALSE
);
775 DestroyWindow(updown
);
778 static void test_updown_create(void)
784 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
786 updown
= create_updown_control(UDS_ALIGNRIGHT
, g_edit
);
787 ok(updown
!= NULL
, "Failed to create updown control\n");
788 ok_sequence(sequences
, PARENT_SEQ_INDEX
, add_updown_to_parent_seq
, "add updown control to parent", TRUE
);
789 ok_sequence(sequences
, EDIT_SEQ_INDEX
, add_updown_with_edit_seq
, "add updown control with edit", FALSE
);
791 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
793 GetWindowTextA(g_edit
, text
, MAX_PATH
);
794 ok(!*text
, "Expected empty string\n");
795 ok_sequence(sequences
, EDIT_SEQ_INDEX
, get_edit_text_seq
, "get edit text", FALSE
);
797 DestroyWindow(updown
);
799 /* create with zero width */
800 updown
= CreateWindowA (UPDOWN_CLASSA
, 0, WS_CHILD
| WS_BORDER
| WS_VISIBLE
, 0, 0, 0, 0,
801 parent_wnd
, (HMENU
)(DWORD_PTR
)1, GetModuleHandleA(NULL
), 0);
802 ok(updown
!= NULL
, "Failed to create updown control\n");
804 GetClientRect(updown
, &r
);
805 ok(r
.right
> 0, "Expected default width, got %d\n", r
.right
);
806 DestroyWindow(updown
);
807 /* create with really small width */
808 updown
= CreateWindowA (UPDOWN_CLASSA
, 0, WS_CHILD
| WS_BORDER
| WS_VISIBLE
, 0, 0, 2, 0,
809 parent_wnd
, (HMENU
)(DWORD_PTR
)1, GetModuleHandleA(NULL
), 0);
810 ok(updown
!= NULL
, "Failed to create updown control\n");
812 GetClientRect(updown
, &r
);
813 ok(r
.right
!= 2 && r
.right
> 0, "Expected default width, got %d\n", r
.right
);
814 DestroyWindow(updown
);
815 /* create with width greater than default */
816 updown
= CreateWindowA (UPDOWN_CLASSA
, 0, WS_CHILD
| WS_BORDER
| WS_VISIBLE
, 0, 0, 100, 0,
817 parent_wnd
, (HMENU
)(DWORD_PTR
)1, GetModuleHandleA(NULL
), 0);
818 ok(updown
!= NULL
, "Failed to create updown control\n");
820 GetClientRect(updown
, &r
);
821 ok(r
.right
< 100 && r
.right
> 0, "Expected default width, got %d\n", r
.right
);
822 DestroyWindow(updown
);
823 /* create with zero height, UDS_HORZ */
824 updown
= CreateWindowA (UPDOWN_CLASSA
, 0, UDS_HORZ
| WS_CHILD
| WS_BORDER
| WS_VISIBLE
, 0, 0, 0, 0,
825 parent_wnd
, (HMENU
)(DWORD_PTR
)1, GetModuleHandleA(NULL
), 0);
826 ok(updown
!= NULL
, "Failed to create updown control\n");
828 GetClientRect(updown
, &r
);
829 ok(r
.bottom
== 0, "Expected zero height, got %d\n", r
.bottom
);
830 DestroyWindow(updown
);
831 /* create with really small height, UDS_HORZ */
832 updown
= CreateWindowA (UPDOWN_CLASSA
, 0, UDS_HORZ
| WS_CHILD
| WS_BORDER
| WS_VISIBLE
, 0, 0, 0, 2,
833 parent_wnd
, (HMENU
)(DWORD_PTR
)1, GetModuleHandleA(NULL
), 0);
834 ok(updown
!= NULL
, "Failed to create updown control\n");
836 GetClientRect(updown
, &r
);
837 ok(r
.bottom
== 0, "Expected zero height, got %d\n", r
.bottom
);
838 DestroyWindow(updown
);
839 /* create with height greater than default, UDS_HORZ */
840 updown
= CreateWindowA (UPDOWN_CLASSA
, 0, UDS_HORZ
| WS_CHILD
| WS_BORDER
| WS_VISIBLE
, 0, 0, 0, 100,
841 parent_wnd
, (HMENU
)(DWORD_PTR
)1, GetModuleHandleA(NULL
), 0);
842 ok(updown
!= NULL
, "Failed to create updown control\n");
844 GetClientRect(updown
, &r
);
845 ok(r
.bottom
< 100 && r
.bottom
> 0, "Expected default height, got %d\n", r
.bottom
);
846 DestroyWindow(updown
);
849 static void test_UDS_SETBUDDYINT(void)
857 SetWindowTextA(g_edit
, text
);
859 /* creating without UDS_SETBUDDYINT */
860 updown
= create_updown_control(UDS_ALIGNRIGHT
, g_edit
);
861 /* try to set UDS_SETBUDDYINT after creation */
862 style
= GetWindowLongA(updown
, GWL_STYLE
);
863 SetWindowLongA(updown
, GWL_STYLE
, style
| UDS_SETBUDDYINT
);
864 style
= GetWindowLongA(updown
, GWL_STYLE
);
865 ok(style
& UDS_SETBUDDYINT
, "Expected UDS_SETBUDDY to be set\n");
866 SendMessageA(updown
, UDM_SETPOS
, 0, 20);
867 GetWindowTextA(g_edit
, text
, ARRAY_SIZE(text
));
868 ok(!*text
, "Expected empty string\n");
869 DestroyWindow(updown
);
871 /* creating with UDS_SETBUDDYINT */
872 updown
= create_updown_control(UDS_SETBUDDYINT
| UDS_ALIGNRIGHT
, g_edit
);
873 GetWindowTextA(g_edit
, text
, ARRAY_SIZE(text
));
874 /* 50 is initial value here */
875 ok(lstrcmpA(text
, "50") == 0, "Expected '50', got '%s'\n", text
);
876 /* now remove style flag */
877 style
= GetWindowLongA(updown
, GWL_STYLE
);
878 SetWindowLongA(updown
, GWL_STYLE
, style
& ~UDS_SETBUDDYINT
);
879 SendMessageA(updown
, UDM_SETPOS
, 0, 20);
880 GetWindowTextA(g_edit
, text
, ARRAY_SIZE(text
));
881 ok(lstrcmpA(text
, "20") == 0, "Expected '20', got '%s'\n", text
);
882 /* set edit text directly, check position */
884 SetWindowTextA(g_edit
, text
);
885 ret
= SendMessageA(updown
, UDM_GETPOS
, 0, 0);
888 SetWindowTextA(g_edit
, text
);
889 ret
= SendMessageA(updown
, UDM_GETPOS
, 0, 0);
890 expect(11, LOWORD(ret
));
891 expect(0, HIWORD(ret
));
892 /* set to invalid value */
893 strcpy(text
, "21st");
894 SetWindowTextA(g_edit
, text
);
895 ret
= SendMessageA(updown
, UDM_GETPOS
, 0, 0);
896 expect(11, LOWORD(ret
));
897 expect(TRUE
, HIWORD(ret
));
899 style
= GetWindowLongA(updown
, GWL_STYLE
);
900 SetWindowLongA(updown
, GWL_STYLE
, style
| UDS_SETBUDDYINT
);
901 SendMessageA(updown
, UDM_SETPOS
, 0, 30);
902 GetWindowTextA(g_edit
, text
, ARRAY_SIZE(text
));
903 ok(lstrcmpA(text
, "30") == 0, "Expected '30', got '%s'\n", text
);
904 DestroyWindow(updown
);
907 static void test_CreateUpDownControl(void)
913 GetClientRect(parent_wnd
, &rect
);
914 updown
= pCreateUpDownControl(WS_CHILD
| WS_BORDER
| WS_VISIBLE
,
915 0, 0, rect
.right
, rect
.bottom
, parent_wnd
, 1, GetModuleHandleA(NULL
), g_edit
, 100, 10, 50);
916 ok(updown
!= NULL
, "Failed to create control.\n");
918 buddy
= (HWND
)SendMessageA(updown
, UDM_GETBUDDY
, 0, 0);
919 ok(buddy
== g_edit
, "Unexpected buddy window.\n");
921 range
= SendMessageA(updown
, UDM_GETRANGE
, 0, 0);
922 ok(range
== MAKELONG(100, 10), "Unexpected range.\n");
924 pos
= SendMessageA(updown
, UDM_GETPOS
, 0, 0);
925 ok(pos
== MAKELONG(50, 1), "Unexpected position.\n");
927 DestroyWindow(updown
);
930 static void test_updown_pos_notifications(void)
937 /* test updown control notifications without UDS_HORZ style */
938 updown
= create_updown_control(UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
, g_edit
);
940 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
942 /* click on the up-arrow button */
943 GetClientRect(updown
, &rect
);
944 x
= rect
.left
+ (rect
.right
- rect
.left
) / 2;
945 y
= rect
.top
+ (rect
.bottom
- rect
.top
) / 4;
946 result
= SendMessageA(updown
, WM_LBUTTONDOWN
, 0, MAKELPARAM(x
, y
));
948 result
= SendMessageA(updown
, WM_LBUTTONUP
, 0, MAKELPARAM(x
, y
));
951 ok_sequence(sequences
, PARENT_SEQ_INDEX
, test_updown_pos_notifications_seq
,
952 "test updown to parent notify (vertical)", FALSE
);
954 DestroyWindow(updown
);
956 /* test updown control notifications with UDS_HORZ style */
957 updown
= create_updown_control(UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
| UDS_HORZ
, g_edit
);
959 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
961 /* click on the right-arrow button */
962 GetClientRect(updown
, &rect
);
963 x
= rect
.left
+ (rect
.right
- rect
.left
) * 3 / 4;
964 y
= rect
.top
+ (rect
.bottom
- rect
.top
) / 2;
965 result
= SendMessageA(updown
, WM_LBUTTONDOWN
, 0, MAKELPARAM(x
, y
));
967 result
= SendMessageA(updown
, WM_LBUTTONUP
, 0, MAKELPARAM(x
, y
));
970 ok_sequence(sequences
, PARENT_SEQ_INDEX
, test_updown_pos_notifications_horz_seq
,
971 "test updown to parent notify (horizontal)", FALSE
);
973 DestroyWindow(updown
);
976 static void init_functions(void)
978 HMODULE hComCtl32
= LoadLibraryA("comctl32.dll");
980 #define X(f) p##f = (void*)GetProcAddress(hComCtl32, #f);
981 #define X2(f, ord) p##f = (void*)GetProcAddress(hComCtl32, (const char *)ord);
982 X(CreateUpDownControl
);
983 X2(SetWindowSubclass
, 410);
992 init_msg_sequences(sequences
, NUM_MSG_SEQUENCES
);
994 parent_wnd
= create_parent_window();
995 ok(parent_wnd
!= NULL
, "Failed to create parent window!\n");
996 g_edit
= create_edit_control();
997 ok(g_edit
!= NULL
, "Failed to create edit control\n");
999 test_updown_create();
1001 test_updown_pos32();
1002 test_updown_buddy();
1004 test_updown_unicode();
1005 test_UDS_SETBUDDYINT();
1006 test_CreateUpDownControl();
1007 test_updown_pos_notifications();
1009 DestroyWindow(g_edit
);
1010 DestroyWindow(parent_wnd
);