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 * - up-down control notifies its parent window when its position changes with UDN_DELTAPOS + WM_VSCROLL or WM_HSCROLL
32 * - check UDS_ALIGN[LEFT,RIGHT]...check that width of buddy window is decreased
33 * - check that UDS_SETBUDDYINT sets the caption of the buddy window when it is changed
34 * - check that the thousands operator is set for large numbers
35 * - check that the thousands operator is not set with UDS_NOTHOUSANDS
36 * - check UDS_ARROWKEYS, control subclasses the buddy window so that it processes the keys when it has focus
38 * - check changing past min/max values
39 * - check UDS_WRAP wraps values past min/max, incrementing past upper value wraps position to lower value
40 * - can change control's position, min/max pos, radix
41 * - check UDM_GETPOS, for up-down control with a buddy window, position is the caption of the buddy window, so change the
42 * caption of the buddy window then call UDM_GETPOS
43 * - check UDM_SETRANGE, max can be less than min, so clicking the up arrow decreases the current position
44 * - more stuff to test
51 #include "wine/test.h"
54 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
56 #define NUM_MSG_SEQUENCES 3
57 #define PARENT_SEQ_INDEX 0
58 #define EDIT_SEQ_INDEX 1
59 #define UPDOWN_SEQ_INDEX 2
64 static HWND parent_wnd
, g_edit
;
66 static BOOL (WINAPI
*pSetWindowSubclass
)(HWND
, SUBCLASSPROC
, UINT_PTR
, DWORD_PTR
);
68 static struct msg_sequence
*sequences
[NUM_MSG_SEQUENCES
];
70 static const struct message add_updown_with_edit_seq
[] = {
71 { WM_WINDOWPOSCHANGING
, sent
},
72 { WM_NCCALCSIZE
, sent
|wparam
, TRUE
},
73 { WM_WINDOWPOSCHANGED
, sent
},
74 { WM_SIZE
, sent
|wparam
|defwinproc
, SIZE_RESTORED
/*, MAKELONG(91, 75) exact size depends on font */ },
78 static const struct message add_updown_to_parent_seq
[] = {
79 { WM_NOTIFYFORMAT
, sent
|lparam
, 0, NF_QUERY
},
80 { WM_QUERYUISTATE
, sent
|optional
},
81 { WM_PARENTNOTIFY
, sent
|wparam
, MAKELONG(WM_CREATE
, WM_CREATE
) },
85 static const struct message get_edit_text_seq
[] = {
90 static const struct message test_updown_pos_seq
[] = {
91 { UDM_SETRANGE
, sent
|lparam
, 0, MAKELONG(100,0) },
92 { UDM_GETRANGE
, sent
},
93 { UDM_SETPOS
, sent
|lparam
, 0, 5},
95 { UDM_SETPOS
, sent
|lparam
, 0, 0},
97 { UDM_SETPOS
, sent
|lparam
, 0, MAKELONG(-1,0)},
99 { UDM_SETPOS
, sent
|lparam
, 0, 100},
101 { UDM_SETPOS
, sent
|lparam
, 0, 101},
106 static const struct message test_updown_pos32_seq
[] = {
107 { UDM_SETRANGE32
, sent
|lparam
, 0, 1000 },
108 { UDM_GETRANGE32
, sent
}, /* Cannot check wparam and lparam as they are ptrs */
109 { UDM_SETPOS32
, sent
|lparam
, 0, 500 },
110 { UDM_GETPOS32
, sent
},
111 { UDM_SETPOS32
, sent
|lparam
, 0, 0 },
112 { UDM_GETPOS32
, sent
},
113 { UDM_SETPOS32
, sent
|lparam
, 0, -1 },
114 { UDM_GETPOS32
, sent
},
115 { UDM_SETPOS32
, sent
|lparam
, 0, 1000 },
116 { UDM_GETPOS32
, sent
},
117 { UDM_SETPOS32
, sent
|lparam
, 0, 1001 },
118 { UDM_GETPOS32
, sent
},
122 static const struct message test_updown_buddy_seq
[] = {
123 { UDM_GETBUDDY
, sent
},
124 { UDM_SETBUDDY
, sent
},
125 { WM_STYLECHANGING
, sent
|defwinproc
},
126 { WM_STYLECHANGED
, sent
|defwinproc
},
127 { WM_STYLECHANGING
, sent
|defwinproc
},
128 { WM_STYLECHANGED
, sent
|defwinproc
},
129 { WM_WINDOWPOSCHANGING
, sent
|defwinproc
},
130 { WM_NCCALCSIZE
, sent
|wparam
|optional
|defwinproc
, 1 },
131 { WM_WINDOWPOSCHANGED
, sent
|defwinproc
},
132 { WM_MOVE
, sent
|defwinproc
},
133 { UDM_GETBUDDY
, sent
},
137 static const struct message test_updown_base_seq
[] = {
138 { UDM_SETBASE
, sent
|wparam
, 10 },
139 { UDM_GETBASE
, sent
},
140 { UDM_SETBASE
, sent
|wparam
, 80 },
141 { UDM_GETBASE
, sent
},
142 { UDM_SETBASE
, sent
|wparam
, 16 },
143 { UDM_GETBASE
, sent
},
144 { UDM_SETBASE
, sent
|wparam
, 80 },
145 { UDM_GETBASE
, sent
},
146 { UDM_SETBASE
, sent
|wparam
, 10 },
147 { UDM_GETBASE
, sent
},
151 static const struct message test_updown_unicode_seq
[] = {
152 { UDM_SETUNICODEFORMAT
, sent
|wparam
, 0 },
153 { UDM_GETUNICODEFORMAT
, sent
},
154 { UDM_SETUNICODEFORMAT
, sent
|wparam
, 1 },
155 { UDM_GETUNICODEFORMAT
, sent
},
156 { UDM_SETUNICODEFORMAT
, sent
|wparam
, 0 },
157 { UDM_GETUNICODEFORMAT
, sent
},
161 static const struct message test_updown_pos_nochange_seq
[] = {
162 { WM_GETTEXT
, sent
|id
, 0, 0, BUDDY_ID
},
166 static LRESULT WINAPI
parent_wnd_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
168 static LONG defwndproc_counter
= 0;
172 /* log system messages, except for painting */
173 if (message
< WM_USER
&&
174 message
!= WM_PAINT
&&
175 message
!= WM_ERASEBKGND
&&
176 message
!= WM_NCPAINT
&&
177 message
!= WM_NCHITTEST
&&
178 message
!= WM_GETTEXT
&&
179 message
!= WM_GETICON
&&
180 message
!= WM_DEVICECHANGE
)
182 msg
.message
= message
;
183 msg
.flags
= sent
|wparam
|lparam
;
184 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
188 add_message(sequences
, PARENT_SEQ_INDEX
, &msg
);
191 defwndproc_counter
++;
192 ret
= DefWindowProcA(hwnd
, message
, wParam
, lParam
);
193 defwndproc_counter
--;
198 static BOOL
register_parent_wnd_class(void)
203 cls
.lpfnWndProc
= parent_wnd_proc
;
206 cls
.hInstance
= GetModuleHandleA(NULL
);
208 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
209 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
210 cls
.lpszMenuName
= NULL
;
211 cls
.lpszClassName
= "Up-Down test parent class";
212 return RegisterClassA(&cls
);
215 static HWND
create_parent_window(void)
217 if (!register_parent_wnd_class())
220 return CreateWindowExA(0, "Up-Down test parent class",
221 "Up-Down test parent window",
222 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
223 WS_MAXIMIZEBOX
| WS_VISIBLE
,
225 GetDesktopWindow(), NULL
, GetModuleHandleA(NULL
), NULL
);
228 static LRESULT WINAPI
edit_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
230 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
231 static LONG defwndproc_counter
= 0;
235 msg
.message
= message
;
236 msg
.flags
= sent
|wparam
|lparam
;
237 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
241 add_message(sequences
, EDIT_SEQ_INDEX
, &msg
);
243 defwndproc_counter
++;
244 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
245 defwndproc_counter
--;
249 static HWND
create_edit_control(void)
255 GetClientRect(parent_wnd
, &rect
);
256 hwnd
= CreateWindowExA(0, WC_EDITA
, NULL
, WS_CHILD
| WS_BORDER
| WS_VISIBLE
,
257 0, 0, rect
.right
, rect
.bottom
,
258 parent_wnd
, NULL
, GetModuleHandleA(NULL
), NULL
);
259 if (!hwnd
) return NULL
;
261 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
262 (LONG_PTR
)edit_subclass_proc
);
263 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
268 static LRESULT WINAPI
updown_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
270 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
271 static LONG defwndproc_counter
= 0;
275 msg
.message
= message
;
276 msg
.flags
= sent
|wparam
|lparam
;
277 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
281 add_message(sequences
, UPDOWN_SEQ_INDEX
, &msg
);
283 defwndproc_counter
++;
284 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
285 defwndproc_counter
--;
290 static HWND
create_updown_control(DWORD style
, HWND buddy
)
296 GetClientRect(parent_wnd
, &rect
);
297 updown
= CreateUpDownControl(WS_CHILD
| WS_BORDER
| WS_VISIBLE
| style
,
298 0, 0, rect
.right
, rect
.bottom
, parent_wnd
, 1, GetModuleHandleA(NULL
), buddy
,
300 if (!updown
) return NULL
;
302 oldproc
= (WNDPROC
)SetWindowLongPtrA(updown
, GWLP_WNDPROC
,
303 (LONG_PTR
)updown_subclass_proc
);
304 SetWindowLongPtrA(updown
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
309 static void test_updown_pos(void)
314 updown
= create_updown_control(UDS_ALIGNRIGHT
, g_edit
);
316 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
318 /* Set Range from 0 to 100 */
319 SendMessageA(updown
, UDM_SETRANGE
, 0 , MAKELONG(100,0) );
320 r
= SendMessageA(updown
, UDM_GETRANGE
, 0,0);
321 expect(100,LOWORD(r
));
324 /* Set the position to 5, return is not checked as it was set before func call */
325 SendMessageA(updown
, UDM_SETPOS
, 0 , MAKELONG(5,0) );
326 /* Since UDM_SETBUDDYINT was not set at creation HIWORD(r) will always be 1 as a return from UDM_GETPOS */
327 /* Get the position, which should be 5 */
328 r
= SendMessageA(updown
, UDM_GETPOS
, 0 , 0 );
332 /* Set the position to 0, return should be 5 */
333 r
= SendMessageA(updown
, UDM_SETPOS
, 0 , MAKELONG(0,0) );
335 /* Get the position, which should be 0 */
336 r
= SendMessageA(updown
, UDM_GETPOS
, 0 , 0 );
340 /* Set the position to -1, return should be 0 */
341 r
= SendMessageA(updown
, UDM_SETPOS
, 0 , MAKELONG(-1,0) );
343 /* Get the position, which should be 0 */
344 r
= SendMessageA(updown
, UDM_GETPOS
, 0 , 0 );
348 /* Set the position to 100, return should be 0 */
349 r
= SendMessageA(updown
, UDM_SETPOS
, 0 , MAKELONG(100,0) );
351 /* Get the position, which should be 100 */
352 r
= SendMessageA(updown
, UDM_GETPOS
, 0 , 0 );
353 expect(100,LOWORD(r
));
356 /* Set the position to 101, return should be 100 */
357 r
= SendMessageA(updown
, UDM_SETPOS
, 0 , MAKELONG(101,0) );
359 /* Get the position, which should be 100 */
360 r
= SendMessageA(updown
, UDM_GETPOS
, 0 , 0 );
361 expect(100,LOWORD(r
));
364 ok_sequence(sequences
, UPDOWN_SEQ_INDEX
, test_updown_pos_seq
, "test updown pos", FALSE
);
366 DestroyWindow(updown
);
368 /* there's no attempt to update buddy Edit if text didn't change */
369 SetWindowTextA(g_edit
, "50");
370 updown
= create_updown_control(UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
| UDS_ARROWKEYS
, g_edit
);
372 /* test sequence only on 5.8x versions */
373 r
= SendMessageA(updown
, UDM_GETPOS32
, 0, 0);
378 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
380 r
= SendMessageA(updown
, UDM_SETPOS
, 0, 50);
383 ok_sequence(sequences
, EDIT_SEQ_INDEX
, test_updown_pos_nochange_seq
,
384 "test updown pos, no change", FALSE
);
386 SendMessageA(updown
, UDM_SETRANGE
, 0, MAKELONG(1, 40));
387 r
= SendMessageA(updown
, UDM_GETRANGE
, 0, 0);
388 expect(1, LOWORD(r
));
389 expect(40, HIWORD(r
));
393 r
= SendMessageA(updown
, UDM_SETACCEL
, 1, (LPARAM
)&accel
);
396 r
= SendMessageA(updown
, UDM_GETPOS
, 0, 0);
397 expect(40, LOWORD(r
));
398 expect(1, HIWORD(r
));
400 r
= SendMessageA(updown
, UDM_SETPOS
, 0, MAKELONG(0, 0));
401 expect(40, LOWORD(r
));
402 expect(0, HIWORD(r
));
404 r
= SendMessageA(updown
, UDM_GETPOS
, 0, 0);
405 expect(1, LOWORD(r
));
406 expect(0, HIWORD(r
));
408 r
= SendMessageA(updown
, UDM_SETPOS
, 0, MAKELONG(2, 0));
409 expect(1, LOWORD(r
));
410 expect(0, HIWORD(r
));
412 r
= SendMessageA(g_edit
, WM_KEYDOWN
, VK_UP
, 0);
414 r
= SendMessageA(updown
, UDM_GETPOS
, 0, 0);
415 expect(1, LOWORD(r
));
416 expect(0, HIWORD(r
));
418 r
= SendMessageA(updown
, UDM_SETPOS
, 0, MAKELONG(50, 0));
419 expect(1, LOWORD(r
));
420 expect(0, HIWORD(r
));
422 r
= SendMessageA(updown
, UDM_GETPOS
, 0, 0);
423 expect(40, LOWORD(r
));
424 expect(0, HIWORD(r
));
427 DestroyWindow(updown
);
430 static void test_updown_pos32(void)
436 updown
= create_updown_control(UDS_ALIGNRIGHT
, g_edit
);
438 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
440 /* Set the position to 0 to 1000 */
441 SendMessageA(updown
, UDM_SETRANGE32
, 0 , 1000 );
444 r
= SendMessageA(updown
, UDM_GETRANGE32
, (WPARAM
) &low
, (LPARAM
) &high
);
448 win_skip("UDM_SETRANGE32/UDM_GETRANGE32 not available\n");
449 DestroyWindow(updown
);
456 /* Set position to 500 */
457 r
= SendMessageA(updown
, UDM_SETPOS32
, 0 , 500 );
460 win_skip("UDM_SETPOS32 and UDM_GETPOS32 need 5.80\n");
461 DestroyWindow(updown
);
466 /* Since UDM_SETBUDDYINT was not set at creation bRet will always be true as a return from UDM_GETPOS32 */
468 r
= SendMessageA(updown
, UDM_GETPOS32
, 0 , (LPARAM
) &high
);
472 /* Set position to 0, return should be 500 */
473 r
= SendMessageA(updown
, UDM_SETPOS32
, 0 , 0 );
475 r
= SendMessageA(updown
, UDM_GETPOS32
, 0 , (LPARAM
) &high
);
479 /* Set position to -1 which should become 0, return should be 0 */
480 r
= SendMessageA(updown
, UDM_SETPOS32
, 0 , -1 );
482 r
= SendMessageA(updown
, UDM_GETPOS32
, 0 , (LPARAM
) &high
);
486 /* Set position to 1000, return should be 0 */
487 r
= SendMessageA(updown
, UDM_SETPOS32
, 0 , 1000 );
489 r
= SendMessageA(updown
, UDM_GETPOS32
, 0 , (LPARAM
) &high
);
493 /* Set position to 1001 which should become 1000, return should be 1000 */
494 r
= SendMessageA(updown
, UDM_SETPOS32
, 0 , 1001 );
496 r
= SendMessageA(updown
, UDM_GETPOS32
, 0 , (LPARAM
) &high
);
500 ok_sequence(sequences
, UPDOWN_SEQ_INDEX
, test_updown_pos32_seq
, "test updown pos32", FALSE
);
502 DestroyWindow(updown
);
504 /* there's no attempt to update buddy Edit if text didn't change */
505 SetWindowTextA(g_edit
, "50");
506 updown
= create_updown_control(UDS_ALIGNRIGHT
| UDS_SETBUDDYINT
, g_edit
);
508 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
510 r
= SendMessageA(updown
, UDM_SETPOS32
, 0, 50);
512 ok_sequence(sequences
, EDIT_SEQ_INDEX
, test_updown_pos_nochange_seq
,
513 "test updown pos, no change", FALSE
);
515 DestroyWindow(updown
);
518 static void test_updown_buddy(void)
520 HWND updown
, buddyReturn
, buddy
;
524 updown
= create_updown_control(UDS_ALIGNRIGHT
, g_edit
);
526 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
528 buddyReturn
= (HWND
)SendMessageA(updown
, UDM_GETBUDDY
, 0 , 0 );
529 ok(buddyReturn
== g_edit
, "Expected edit handle\n");
531 buddyReturn
= (HWND
)SendMessageA(updown
, UDM_SETBUDDY
, (WPARAM
) g_edit
, 0);
532 ok(buddyReturn
== g_edit
, "Expected edit handle\n");
534 buddyReturn
= (HWND
)SendMessageA(updown
, UDM_GETBUDDY
, 0 , 0 );
535 ok(buddyReturn
== g_edit
, "Expected edit handle\n");
537 ok_sequence(sequences
, UPDOWN_SEQ_INDEX
, test_updown_buddy_seq
, "test updown buddy", TRUE
);
538 ok_sequence(sequences
, EDIT_SEQ_INDEX
, add_updown_with_edit_seq
, "test updown buddy_edit", FALSE
);
540 DestroyWindow(updown
);
542 buddy
= create_edit_control();
543 proc
= (WNDPROC
)GetWindowLongPtrA(buddy
, GWLP_WNDPROC
);
545 updown
= create_updown_control(UDS_ALIGNRIGHT
, buddy
);
546 ok(proc
== (WNDPROC
)GetWindowLongPtrA(buddy
, GWLP_WNDPROC
), "No subclassing expected\n");
548 style
= GetWindowLongA(updown
, GWL_STYLE
);
549 SetWindowLongA(updown
, GWL_STYLE
, style
| UDS_ARROWKEYS
);
550 style
= GetWindowLongA(updown
, GWL_STYLE
);
551 ok(style
& UDS_ARROWKEYS
, "Expected UDS_ARROWKEYS\n");
552 /* no subclass if UDS_ARROWKEYS set after creation */
553 ok(proc
== (WNDPROC
)GetWindowLongPtrA(buddy
, GWLP_WNDPROC
), "No subclassing expected\n");
555 DestroyWindow(updown
);
557 updown
= create_updown_control(UDS_ALIGNRIGHT
| UDS_ARROWKEYS
, buddy
);
558 ok(proc
!= (WNDPROC
)GetWindowLongPtrA(buddy
, GWLP_WNDPROC
), "Subclassing expected\n");
560 if (pSetWindowSubclass
)
562 /* updown uses subclass helpers for buddy on >5.8x systems */
563 ok(GetPropA(buddy
, "CC32SubclassInfo") != NULL
, "Expected CC32SubclassInfo property\n");
566 DestroyWindow(updown
);
568 DestroyWindow(buddy
);
571 static void test_updown_base(void)
577 updown
= create_updown_control(UDS_ALIGNRIGHT
, g_edit
);
579 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
581 SendMessageA(updown
, UDM_SETBASE
, 10 , 0);
582 r
= SendMessageA(updown
, UDM_GETBASE
, 0 , 0);
585 /* Set base to an invalid value, should return 0 and stay at 10 */
586 r
= SendMessageA(updown
, UDM_SETBASE
, 80 , 0);
588 r
= SendMessageA(updown
, UDM_GETBASE
, 0 , 0);
591 /* Set base to 16 now, should get 16 as the return */
592 r
= SendMessageA(updown
, UDM_SETBASE
, 16 , 0);
594 r
= SendMessageA(updown
, UDM_GETBASE
, 0 , 0);
597 /* Set base to an invalid value, should return 0 and stay at 16 */
598 r
= SendMessageA(updown
, UDM_SETBASE
, 80 , 0);
600 r
= SendMessageA(updown
, UDM_GETBASE
, 0 , 0);
603 /* Set base back to 10, return should be 16 */
604 r
= SendMessageA(updown
, UDM_SETBASE
, 10 , 0);
606 r
= SendMessageA(updown
, UDM_GETBASE
, 0 , 0);
609 ok_sequence(sequences
, UPDOWN_SEQ_INDEX
, test_updown_base_seq
, "test updown base", FALSE
);
611 DestroyWindow(updown
);
613 /* switch base with buddy attached */
614 updown
= create_updown_control(UDS_SETBUDDYINT
| UDS_ALIGNRIGHT
, g_edit
);
616 r
= SendMessageA(updown
, UDM_SETPOS
, 0, 10);
619 GetWindowTextA(g_edit
, text
, sizeof(text
)/sizeof(CHAR
));
620 ok(lstrcmpA(text
, "10") == 0, "Expected '10', got '%s'\n", text
);
622 r
= SendMessageA(updown
, UDM_SETBASE
, 16, 0);
625 GetWindowTextA(g_edit
, text
, sizeof(text
)/sizeof(CHAR
));
626 /* FIXME: currently hex output isn't properly formatted, but for this
627 test only change from initial text matters */
628 ok(lstrcmpA(text
, "10") != 0, "Expected '0x000A', got '%s'\n", text
);
630 DestroyWindow(updown
);
633 static void test_updown_unicode(void)
638 updown
= create_updown_control(UDS_ALIGNRIGHT
, g_edit
);
640 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
642 /* Set it to ANSI, don't check return as we don't know previous state */
643 SendMessageA(updown
, UDM_SETUNICODEFORMAT
, 0 , 0);
644 r
= SendMessageA(updown
, UDM_GETUNICODEFORMAT
, 0 , 0);
647 /* Now set it to Unicode format */
648 r
= SendMessageA(updown
, UDM_SETUNICODEFORMAT
, 1 , 0);
650 r
= SendMessageA(updown
, UDM_GETUNICODEFORMAT
, 0 , 0);
653 win_skip("UDM_SETUNICODEFORMAT not available\n");
654 DestroyWindow(updown
);
659 /* And now set it back to ANSI */
660 r
= SendMessageA(updown
, UDM_SETUNICODEFORMAT
, 0 , 0);
662 r
= SendMessageA(updown
, UDM_GETUNICODEFORMAT
, 0 , 0);
665 ok_sequence(sequences
, UPDOWN_SEQ_INDEX
, test_updown_unicode_seq
, "test updown unicode", FALSE
);
667 DestroyWindow(updown
);
670 static void test_updown_create(void)
676 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
678 updown
= create_updown_control(UDS_ALIGNRIGHT
, g_edit
);
679 ok(updown
!= NULL
, "Failed to create updown control\n");
680 ok_sequence(sequences
, PARENT_SEQ_INDEX
, add_updown_to_parent_seq
, "add updown control to parent", TRUE
);
681 ok_sequence(sequences
, EDIT_SEQ_INDEX
, add_updown_with_edit_seq
, "add updown control with edit", FALSE
);
683 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
685 GetWindowTextA(g_edit
, text
, MAX_PATH
);
686 ok(lstrlenA(text
) == 0, "Expected empty string\n");
687 ok_sequence(sequences
, EDIT_SEQ_INDEX
, get_edit_text_seq
, "get edit text", FALSE
);
689 DestroyWindow(updown
);
691 /* create with zero width */
692 updown
= CreateWindowA (UPDOWN_CLASSA
, 0, WS_CHILD
| WS_BORDER
| WS_VISIBLE
, 0, 0, 0, 0,
693 parent_wnd
, (HMENU
)(DWORD_PTR
)1, GetModuleHandleA(NULL
), 0);
694 ok(updown
!= NULL
, "Failed to create updown control\n");
696 GetClientRect(updown
, &r
);
697 ok(r
.right
> 0, "Expected default width, got %d\n", r
.right
);
698 DestroyWindow(updown
);
699 /* create with really small width */
700 updown
= CreateWindowA (UPDOWN_CLASSA
, 0, WS_CHILD
| WS_BORDER
| WS_VISIBLE
, 0, 0, 2, 0,
701 parent_wnd
, (HMENU
)(DWORD_PTR
)1, GetModuleHandleA(NULL
), 0);
702 ok(updown
!= NULL
, "Failed to create updown control\n");
704 GetClientRect(updown
, &r
);
705 ok(r
.right
!= 2 && r
.right
> 0, "Expected default width, got %d\n", r
.right
);
706 DestroyWindow(updown
);
707 /* create with width greater than default */
708 updown
= CreateWindowA (UPDOWN_CLASSA
, 0, WS_CHILD
| WS_BORDER
| WS_VISIBLE
, 0, 0, 100, 0,
709 parent_wnd
, (HMENU
)(DWORD_PTR
)1, GetModuleHandleA(NULL
), 0);
710 ok(updown
!= NULL
, "Failed to create updown control\n");
712 GetClientRect(updown
, &r
);
713 ok(r
.right
< 100 && r
.right
> 0, "Expected default width, got %d\n", r
.right
);
714 DestroyWindow(updown
);
715 /* create with zero height, UDS_HORZ */
716 updown
= CreateWindowA (UPDOWN_CLASSA
, 0, UDS_HORZ
| WS_CHILD
| WS_BORDER
| WS_VISIBLE
, 0, 0, 0, 0,
717 parent_wnd
, (HMENU
)(DWORD_PTR
)1, GetModuleHandleA(NULL
), 0);
718 ok(updown
!= NULL
, "Failed to create updown control\n");
720 GetClientRect(updown
, &r
);
721 ok(r
.bottom
== 0, "Expected zero height, got %d\n", r
.bottom
);
722 DestroyWindow(updown
);
723 /* create with really small height, UDS_HORZ */
724 updown
= CreateWindowA (UPDOWN_CLASSA
, 0, UDS_HORZ
| WS_CHILD
| WS_BORDER
| WS_VISIBLE
, 0, 0, 0, 2,
725 parent_wnd
, (HMENU
)(DWORD_PTR
)1, GetModuleHandleA(NULL
), 0);
726 ok(updown
!= NULL
, "Failed to create updown control\n");
728 GetClientRect(updown
, &r
);
729 ok(r
.bottom
== 0, "Expected zero height, got %d\n", r
.bottom
);
730 DestroyWindow(updown
);
731 /* create with height greater than default, UDS_HORZ */
732 updown
= CreateWindowA (UPDOWN_CLASSA
, 0, UDS_HORZ
| WS_CHILD
| WS_BORDER
| WS_VISIBLE
, 0, 0, 0, 100,
733 parent_wnd
, (HMENU
)(DWORD_PTR
)1, GetModuleHandleA(NULL
), 0);
734 ok(updown
!= NULL
, "Failed to create updown control\n");
736 GetClientRect(updown
, &r
);
737 ok(r
.bottom
< 100 && r
.bottom
> 0, "Expected default height, got %d\n", r
.bottom
);
738 DestroyWindow(updown
);
741 static void test_UDS_SETBUDDYINT(void)
749 SetWindowTextA(g_edit
, text
);
751 /* creating without UDS_SETBUDDYINT */
752 updown
= create_updown_control(UDS_ALIGNRIGHT
, g_edit
);
753 /* try to set UDS_SETBUDDYINT after creation */
754 style
= GetWindowLongA(updown
, GWL_STYLE
);
755 SetWindowLongA(updown
, GWL_STYLE
, style
| UDS_SETBUDDYINT
);
756 style
= GetWindowLongA(updown
, GWL_STYLE
);
757 ok(style
& UDS_SETBUDDYINT
, "Expected UDS_SETBUDDY to be set\n");
758 SendMessageA(updown
, UDM_SETPOS
, 0, 20);
759 GetWindowTextA(g_edit
, text
, sizeof(text
)/sizeof(CHAR
));
760 ok(lstrlenA(text
) == 0, "Expected empty string\n");
761 DestroyWindow(updown
);
763 /* creating with UDS_SETBUDDYINT */
764 updown
= create_updown_control(UDS_SETBUDDYINT
| UDS_ALIGNRIGHT
, g_edit
);
765 GetWindowTextA(g_edit
, text
, sizeof(text
)/sizeof(CHAR
));
766 /* 50 is initial value here */
767 ok(lstrcmpA(text
, "50") == 0, "Expected '50', got '%s'\n", text
);
768 /* now remove style flag */
769 style
= GetWindowLongA(updown
, GWL_STYLE
);
770 SetWindowLongA(updown
, GWL_STYLE
, style
& ~UDS_SETBUDDYINT
);
771 SendMessageA(updown
, UDM_SETPOS
, 0, 20);
772 GetWindowTextA(g_edit
, text
, sizeof(text
)/sizeof(CHAR
));
773 ok(lstrcmpA(text
, "20") == 0, "Expected '20', got '%s'\n", text
);
774 /* set edit text directly, check position */
776 SetWindowTextA(g_edit
, text
);
777 ret
= SendMessageA(updown
, UDM_GETPOS
, 0, 0);
780 SetWindowTextA(g_edit
, text
);
781 ret
= SendMessageA(updown
, UDM_GETPOS
, 0, 0);
782 expect(11, LOWORD(ret
));
783 expect(0, HIWORD(ret
));
784 /* set to invalid value */
785 strcpy(text
, "21st");
786 SetWindowTextA(g_edit
, text
);
787 ret
= SendMessageA(updown
, UDM_GETPOS
, 0, 0);
788 expect(11, LOWORD(ret
));
789 expect(TRUE
, HIWORD(ret
));
791 style
= GetWindowLongA(updown
, GWL_STYLE
);
792 SetWindowLongA(updown
, GWL_STYLE
, style
| UDS_SETBUDDYINT
);
793 SendMessageA(updown
, UDM_SETPOS
, 0, 30);
794 GetWindowTextA(g_edit
, text
, sizeof(text
)/sizeof(CHAR
));
795 ok(lstrcmpA(text
, "30") == 0, "Expected '30', got '%s'\n", text
);
796 DestroyWindow(updown
);
801 HMODULE mod
= GetModuleHandleA("comctl32.dll");
803 pSetWindowSubclass
= (void*)GetProcAddress(mod
, (LPSTR
)410);
805 InitCommonControls();
806 init_msg_sequences(sequences
, NUM_MSG_SEQUENCES
);
808 parent_wnd
= create_parent_window();
809 ok(parent_wnd
!= NULL
, "Failed to create parent window!\n");
810 g_edit
= create_edit_control();
811 ok(g_edit
!= NULL
, "Failed to create edit control\n");
813 test_updown_create();
818 test_updown_unicode();
819 test_UDS_SETBUDDYINT();
821 DestroyWindow(g_edit
);
822 DestroyWindow(parent_wnd
);