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
52 #include "wine/test.h"
55 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
57 #define NUM_MSG_SEQUENCES 3
58 #define PARENT_SEQ_INDEX 0
59 #define EDIT_SEQ_INDEX 1
60 #define UPDOWN_SEQ_INDEX 2
62 static HWND parent_wnd
, edit
, updown
;
64 static struct msg_sequence
*sequences
[NUM_MSG_SEQUENCES
];
66 static const struct message create_parent_wnd_seq
[] = {
67 { WM_GETMINMAXINFO
, sent
},
68 { WM_NCCREATE
, sent
},
69 { WM_NCCALCSIZE
, sent
|wparam
, 0 },
71 { WM_SHOWWINDOW
, sent
|wparam
, 1 },
72 { WM_WINDOWPOSCHANGING
, sent
|wparam
, 0 },
73 { WM_WINDOWPOSCHANGING
, sent
|wparam
, 0 },
74 { WM_ACTIVATEAPP
, sent
|wparam
, 1 },
75 { WM_NCACTIVATE
, sent
|wparam
, 1 },
76 { WM_ACTIVATE
, sent
|wparam
, 1 },
77 { WM_IME_SETCONTEXT
, sent
|wparam
|defwinproc
|optional
, 1 },
78 { WM_IME_NOTIFY
, sent
|defwinproc
|optional
},
79 { WM_SETFOCUS
, sent
|wparam
|defwinproc
, 0 },
80 /* Win9x adds SWP_NOZORDER below */
81 { WM_WINDOWPOSCHANGED
, sent
, /*|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ },
82 { WM_NCCALCSIZE
, sent
|wparam
|optional
, 1 },
88 static const struct message add_edit_to_parent_seq
[] = {
89 { WM_PARENTNOTIFY
, sent
|wparam
, WM_CREATE
},
93 static const struct message add_updown_with_edit_seq
[] = {
94 { WM_WINDOWPOSCHANGING
, sent
},
95 { WM_NCCALCSIZE
, sent
|wparam
, TRUE
},
96 { WM_WINDOWPOSCHANGED
, sent
},
97 { WM_SIZE
, sent
|wparam
|defwinproc
, SIZE_RESTORED
/*, MAKELONG(91, 75) exact size depends on font */ },
101 static const struct message add_updown_to_parent_seq
[] = {
102 { WM_NOTIFYFORMAT
, sent
|lparam
, 0, NF_QUERY
},
103 { WM_QUERYUISTATE
, sent
},
104 { WM_PARENTNOTIFY
, sent
|wparam
, MAKELONG(WM_CREATE
, WM_CREATE
) },
108 static const struct message get_edit_text_seq
[] = {
109 { WM_GETTEXT
, sent
},
113 static LRESULT WINAPI
parent_wnd_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
115 static long defwndproc_counter
= 0;
119 /* do not log painting messages */
120 if (message
!= WM_PAINT
&&
121 message
!= WM_ERASEBKGND
&&
122 message
!= WM_NCPAINT
&&
123 message
!= WM_NCHITTEST
&&
124 message
!= WM_GETTEXT
&&
125 message
!= WM_GETICON
&&
126 message
!= WM_DEVICECHANGE
)
128 trace("parent: %p, %04x, %08x, %08lx\n", hwnd
, message
, wParam
, lParam
);
130 msg
.message
= message
;
131 msg
.flags
= sent
|wparam
|lparam
;
132 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
135 add_message(sequences
, PARENT_SEQ_INDEX
, &msg
);
138 defwndproc_counter
++;
139 ret
= DefWindowProcA(hwnd
, message
, wParam
, lParam
);
140 defwndproc_counter
--;
145 static BOOL
register_parent_wnd_class(void)
150 cls
.lpfnWndProc
= parent_wnd_proc
;
153 cls
.hInstance
= GetModuleHandleA(NULL
);
155 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
156 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
157 cls
.lpszMenuName
= NULL
;
158 cls
.lpszClassName
= "Up-Down test parent class";
159 return RegisterClassA(&cls
);
162 static HWND
create_parent_window(void)
164 if (!register_parent_wnd_class())
167 return CreateWindowEx(0, "Up-Down test parent class",
168 "Up-Down test parent window",
169 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
170 WS_MAXIMIZEBOX
| WS_VISIBLE
,
172 GetDesktopWindow(), NULL
, GetModuleHandleA(NULL
), NULL
);
180 static LRESULT WINAPI
edit_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
182 struct subclass_info
*info
= (struct subclass_info
*)GetWindowLongA(hwnd
, GWL_USERDATA
);
183 static long defwndproc_counter
= 0;
187 trace("edit: %p, %04x, %08x, %08lx\n", hwnd
, message
, wParam
, lParam
);
189 msg
.message
= message
;
190 msg
.flags
= sent
|wparam
|lparam
;
191 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
194 add_message(sequences
, EDIT_SEQ_INDEX
, &msg
);
196 defwndproc_counter
++;
197 ret
= CallWindowProcA(info
->oldproc
, hwnd
, message
, wParam
, lParam
);
198 defwndproc_counter
--;
202 static HWND
create_edit_control(void)
204 struct subclass_info
*info
;
207 info
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info
));
211 GetClientRect(parent_wnd
, &rect
);
212 edit
= CreateWindowExA(0, "EDIT", NULL
, WS_CHILD
| WS_BORDER
| WS_VISIBLE
,
213 0, 0, rect
.right
, rect
.bottom
,
214 parent_wnd
, NULL
, GetModuleHandleA(NULL
), NULL
);
217 HeapFree(GetProcessHeap(), 0, info
);
221 info
->oldproc
= (WNDPROC
)SetWindowLongA(edit
, GWL_WNDPROC
,
222 (LONG
)edit_subclass_proc
);
223 SetWindowLongA(edit
, GWL_USERDATA
, (LONG
)info
);
228 static LRESULT WINAPI
updown_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
230 struct subclass_info
*info
= (struct subclass_info
*)GetWindowLongA(hwnd
, GWL_USERDATA
);
231 static long defwndproc_counter
= 0;
235 trace("updown: %p, %04x, %08x, %08lx\n", hwnd
, message
, wParam
, lParam
);
237 msg
.message
= message
;
238 msg
.flags
= sent
|wparam
|lparam
;
239 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
242 add_message(sequences
, EDIT_SEQ_INDEX
, &msg
);
244 defwndproc_counter
++;
245 ret
= CallWindowProcA(info
->oldproc
, hwnd
, message
, wParam
, lParam
);
246 defwndproc_counter
--;
251 static HWND
create_updown_control(void)
253 struct subclass_info
*info
;
257 info
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info
));
261 GetClientRect(parent_wnd
, &rect
);
262 updown
= CreateUpDownControl(WS_CHILD
| WS_BORDER
| WS_VISIBLE
| UDS_ALIGNRIGHT
,
263 0, 0, rect
.right
, rect
.bottom
, parent_wnd
, 1, GetModuleHandleA(NULL
), edit
,
267 HeapFree(GetProcessHeap(), 0, info
);
271 info
->oldproc
= (WNDPROC
)SetWindowLongA(updown
, GWL_WNDPROC
,
272 (LONG
)updown_subclass_proc
);
273 SetWindowLongA(updown
, GWL_USERDATA
, (LONG
)info
);
278 static void test_updown_pos(void)
282 /* Set Range from 0 to 100 */
283 SendMessage(updown
, UDM_SETRANGE
, 0 , MAKELONG(100,0) );
284 r
= SendMessage(updown
, UDM_GETRANGE
, 0,0);
285 expect(100,LOWORD(r
));
288 /* Set the position to 5, return is not checked as it was set before func call */
289 SendMessage(updown
, UDM_SETPOS
, 0 , MAKELONG(5,0) );
290 /* Since UDM_SETBUDDYINT was not set at creation HIWORD(r) will always be 1 as a return from UDM_GETPOS */
291 /* Get the position, which should be 5 */
292 r
= SendMessage(updown
, UDM_GETPOS
, 0 , 0 );
296 /* Set the position to 0, return should be 5 */
297 r
= SendMessage(updown
, UDM_SETPOS
, 0 , MAKELONG(0,0) );
299 /* Get the position, which should be 0 */
300 r
= SendMessage(updown
, UDM_GETPOS
, 0 , 0 );
304 /* Set the position to -1, return should be 0 */
305 r
= SendMessage(updown
, UDM_SETPOS
, 0 , MAKELONG(-1,0) );
307 /* Get the position, which should be 0 */
308 r
= SendMessage(updown
, UDM_GETPOS
, 0 , 0 );
312 /* Set the position to 100, return should be 0 */
313 r
= SendMessage(updown
, UDM_SETPOS
, 0 , MAKELONG(100,0) );
315 /* Get the position, which should be 100 */
316 r
= SendMessage(updown
, UDM_GETPOS
, 0 , 0 );
317 expect(100,LOWORD(r
));
320 /* Set the position to 101, return should be 100 */
321 r
= SendMessage(updown
, UDM_SETPOS
, 0 , MAKELONG(101,0) );
323 /* Get the position, which should be 100 */
324 r
= SendMessage(updown
, UDM_GETPOS
, 0 , 0 );
325 expect(100,LOWORD(r
));
329 static void test_updown_pos32(void)
334 /* Set the position to 0 to 1000 */
335 SendMessage(updown
, UDM_SETRANGE32
, 0 , 1000 );
337 r
= SendMessage(updown
, UDM_GETRANGE32
, (WPARAM
) &low
, (LPARAM
) &high
);
341 /* Set position to 500, don't check return since it is unset*/
342 SendMessage(updown
, UDM_SETPOS32
, 0 , 500 );
344 /* Since UDM_SETBUDDYINT was not set at creation bRet will always be true as a return from UDM_GETPOS32 */
346 r
= SendMessage(updown
, UDM_GETPOS32
, 0 , (LPARAM
) &high
);
350 /* Set position to 0, return should be 500 */
351 r
= SendMessage(updown
, UDM_SETPOS32
, 0 , 0 );
353 r
= SendMessage(updown
, UDM_GETPOS32
, 0 , (LPARAM
) &high
);
357 /* Set position to -1 which should become 0, return should be 0 */
358 r
= SendMessage(updown
, UDM_SETPOS32
, 0 , -1 );
360 r
= SendMessage(updown
, UDM_GETPOS32
, 0 , (LPARAM
) &high
);
364 /* Set position to 1000, return should be 0 */
365 r
= SendMessage(updown
, UDM_SETPOS32
, 0 , 1000 );
367 r
= SendMessage(updown
, UDM_GETPOS32
, 0 , (LPARAM
) &high
);
371 /* Set position to 1001 which should become 1000, return should be 1000 */
372 r
= SendMessage(updown
, UDM_SETPOS32
, 0 , 1001 );
374 r
= SendMessage(updown
, UDM_GETPOS32
, 0 , (LPARAM
) &high
);
379 static void test_updown_buddy(void)
383 buddyReturn
= (HWND
)SendMessage(updown
, UDM_GETBUDDY
, 0 , 0 );
384 ok(buddyReturn
== edit
, "Expected edit handle\n");
387 static void test_updown_base(void)
391 SendMessage(updown
, UDM_SETBASE
, 10 , 0);
392 r
= SendMessage(updown
, UDM_GETBASE
, 0 , 0);
395 /* Set base to an invalid value, should return 0 and stay at 10 */
396 r
= SendMessage(updown
, UDM_SETBASE
, 80 , 0);
398 r
= SendMessage(updown
, UDM_GETBASE
, 0 , 0);
401 /* Set base to 16 now, should get 16 as the return */
402 r
= SendMessage(updown
, UDM_SETBASE
, 16 , 0);
404 r
= SendMessage(updown
, UDM_GETBASE
, 0 , 0);
407 /* Set base to an invalid value, should return 0 and stay at 16 */
408 r
= SendMessage(updown
, UDM_SETBASE
, 80 , 0);
410 r
= SendMessage(updown
, UDM_GETBASE
, 0 , 0);
413 /* Set base back to 10, return should be 16 */
414 r
= SendMessage(updown
, UDM_SETBASE
, 10 , 0);
416 r
= SendMessage(updown
, UDM_GETBASE
, 0 , 0);
420 static void test_updown_unicode(void)
424 /* Set it to ANSI, don't check return as we don't know previous state */
425 SendMessage(updown
, UDM_SETUNICODEFORMAT
, 0 , 0);
426 r
= SendMessage(updown
, UDM_GETUNICODEFORMAT
, 0 , 0);
429 /* Now set it to Unicode format */
430 r
= SendMessage(updown
, UDM_SETUNICODEFORMAT
, 1 , 0);
432 r
= SendMessage(updown
, UDM_GETUNICODEFORMAT
, 0 , 0);
435 /* And now set it back to ANSI */
436 r
= SendMessage(updown
, UDM_SETUNICODEFORMAT
, 0 , 0);
438 r
= SendMessage(updown
, UDM_GETUNICODEFORMAT
, 0 , 0);
443 static void test_create_updown_control(void)
447 parent_wnd
= create_parent_window();
448 ok(parent_wnd
!= NULL
, "Failed to create parent window!\n");
449 ok_sequence(sequences
, PARENT_SEQ_INDEX
, create_parent_wnd_seq
, "create parent window", TRUE
);
451 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
453 edit
= create_edit_control();
454 ok(edit
!= NULL
, "Failed to create edit control\n");
455 ok_sequence(sequences
, PARENT_SEQ_INDEX
, add_edit_to_parent_seq
, "add edit control to parent", FALSE
);
457 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
459 updown
= create_updown_control();
460 ok(updown
!= NULL
, "Failed to create updown control\n");
461 ok_sequence(sequences
, PARENT_SEQ_INDEX
, add_updown_to_parent_seq
, "add updown control to parent", TRUE
);
462 ok_sequence(sequences
, EDIT_SEQ_INDEX
, add_updown_with_edit_seq
, "add updown control with edit", FALSE
);
464 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
466 GetWindowTextA(edit
, text
, MAX_PATH
);
467 ok(lstrlenA(text
) == 0, "Expected empty string\n");
468 ok_sequence(sequences
, EDIT_SEQ_INDEX
, get_edit_text_seq
, "get edit text", FALSE
);
470 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
476 test_updown_unicode();
481 InitCommonControls();
482 init_msg_sequences(sequences
, NUM_MSG_SEQUENCES
);
484 test_create_updown_control();