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 * - check UDM_GETRANGE
45 * - more stuff to test
53 #include "wine/test.h"
56 #define NUM_MSG_SEQUENCES 3
57 #define PARENT_SEQ_INDEX 0
58 #define EDIT_SEQ_INDEX 1
59 #define UPDOWN_SEQ_INDEX 2
61 static HWND parent_wnd, edit, updown;
63 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
65 static const struct message create_parent_wnd_seq[] = {
66 { WM_GETMINMAXINFO, sent },
67 { WM_NCCREATE, sent },
68 { WM_NCCALCSIZE, sent|wparam, 0 },
70 { WM_SHOWWINDOW, sent|wparam, 1 },
71 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
72 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
73 { WM_ACTIVATEAPP, sent|wparam, 1 },
74 { WM_NCACTIVATE, sent|wparam, 1 },
75 { WM_ACTIVATE, sent|wparam, 1 },
76 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
77 { WM_IME_NOTIFY, sent|defwinproc|optional },
78 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
79 /* Win9x adds SWP_NOZORDER below */
80 { WM_WINDOWPOSCHANGED, sent, /*|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ },
81 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
87 static const struct message add_edit_to_parent_seq[] = {
88 { WM_PARENTNOTIFY, sent|wparam, WM_CREATE },
92 static const struct message add_updown_with_edit_seq[] = {
93 { WM_WINDOWPOSCHANGING, sent },
94 { WM_NCCALCSIZE, sent|wparam, TRUE },
95 { WM_WINDOWPOSCHANGED, sent },
96 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED /*, MAKELONG(91, 75) exact size depends on font */ },
100 static const struct message add_updown_to_parent_seq[] = {
101 { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
102 { WM_QUERYUISTATE, sent },
103 { WM_PARENTNOTIFY, sent|wparam, MAKELONG(WM_CREATE, WM_CREATE) },
107 static const struct message get_edit_text_seq[] = {
108 { WM_GETTEXT, sent },
112 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
114 static long defwndproc_counter = 0;
118 /* do not log painting messages */
119 if (message != WM_PAINT &&
120 message != WM_ERASEBKGND &&
121 message != WM_NCPAINT &&
122 message != WM_NCHITTEST &&
123 message != WM_GETTEXT &&
124 message != WM_GETICON &&
125 message != WM_DEVICECHANGE)
127 trace("parent: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
129 msg.message = message;
130 msg.flags = sent|wparam|lparam;
131 if (defwndproc_counter) msg.flags |= defwinproc;
134 add_message(sequences, PARENT_SEQ_INDEX, &msg);
137 defwndproc_counter++;
138 ret = DefWindowProcA(hwnd, message, wParam, lParam);
139 defwndproc_counter--;
144 static BOOL register_parent_wnd_class(void)
149 cls.lpfnWndProc = parent_wnd_proc;
152 cls.hInstance = GetModuleHandleA(NULL);
154 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
155 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
156 cls.lpszMenuName = NULL;
157 cls.lpszClassName = "Up-Down test parent class";
158 return RegisterClassA(&cls);
161 static HWND create_parent_window(void)
163 if (!register_parent_wnd_class())
166 return CreateWindowEx(0, "Up-Down test parent class",
167 "Up-Down test parent window",
168 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
169 WS_MAXIMIZEBOX | WS_VISIBLE,
171 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
179 static LRESULT WINAPI edit_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
181 struct subclass_info *info = (struct subclass_info *)GetWindowLongA(hwnd, GWL_USERDATA);
182 static long defwndproc_counter = 0;
186 trace("edit: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
188 msg.message = message;
189 msg.flags = sent|wparam|lparam;
190 if (defwndproc_counter) msg.flags |= defwinproc;
193 add_message(sequences, EDIT_SEQ_INDEX, &msg);
195 defwndproc_counter++;
196 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
197 defwndproc_counter--;
201 static HWND create_edit_control()
203 struct subclass_info *info;
206 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
210 GetClientRect(parent_wnd, &rect);
211 edit = CreateWindowExA(0, "EDIT", NULL, WS_CHILD | WS_BORDER | WS_VISIBLE,
212 0, 0, rect.right, rect.bottom,
213 parent_wnd, NULL, GetModuleHandleA(NULL), NULL);
216 HeapFree(GetProcessHeap(), 0, info);
220 info->oldproc = (WNDPROC)SetWindowLongA(edit, GWL_WNDPROC,
221 (LONG)edit_subclass_proc);
222 SetWindowLongA(edit, GWL_USERDATA, (LONG)info);
227 static LRESULT WINAPI updown_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
229 struct subclass_info *info = (struct subclass_info *)GetWindowLongA(hwnd, GWL_USERDATA);
230 static long defwndproc_counter = 0;
234 trace("updown: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
236 msg.message = message;
237 msg.flags = sent|wparam|lparam;
238 if (defwndproc_counter) msg.flags |= defwinproc;
241 add_message(sequences, EDIT_SEQ_INDEX, &msg);
243 defwndproc_counter++;
244 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
245 defwndproc_counter--;
250 static HWND create_updown_control()
252 struct subclass_info *info;
256 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
260 GetClientRect(parent_wnd, &rect);
261 updown = CreateUpDownControl(WS_CHILD | WS_BORDER | WS_VISIBLE | UDS_ALIGNRIGHT,
262 0, 0, rect.right, rect.bottom, parent_wnd, 1, GetModuleHandleA(NULL), edit,
266 HeapFree(GetProcessHeap(), 0, info);
270 info->oldproc = (WNDPROC)SetWindowLongA(updown, GWL_WNDPROC,
271 (LONG)updown_subclass_proc);
272 SetWindowLongA(updown, GWL_USERDATA, (LONG)info);
277 static void test_updown_pos(void)
281 /* Set Range from 0 to 100 */
282 SendMessage(updown, UDM_SETRANGE, 0 , MAKELONG(100,0) );
283 r = SendMessage(updown, UDM_GETRANGE, 0,0);
284 ok(LOWORD(r) == 100, "Expected 100, got %d\n", LOWORD(r));
285 ok(HIWORD(r) == 0, "Expected 0, got %d\n", HIWORD(r));
287 /* Set the position to 5, return is not checked as it was set before func call */
288 SendMessage(updown, UDM_SETPOS, 0 , MAKELONG(5,0) );
289 /* Since UDM_SETBUDDYINT was not set at creation HIWORD(r) will always be 1 as a return from UDM_GETPOS */
290 /* Get the position, which should be 5 */
291 r = SendMessage(updown, UDM_GETPOS, 0 , 0 );
292 ok(LOWORD(r) == 5, "Expected 5, got %d\n", LOWORD(r));
293 ok(HIWORD(r) == 1, "Expected 1, got %d\n", HIWORD(r));
295 /* Set the position to 0, return should be 5 */
296 r = SendMessage(updown, UDM_SETPOS, 0 , MAKELONG(0,0) );
297 ok(r == 5, "Expected 5, got %d\n", r);
298 /* Get the position, which should be 0 */
299 r = SendMessage(updown, UDM_GETPOS, 0 , 0 );
300 ok(LOWORD(r) == 0, "Expected 0, got %d\n", LOWORD(r));
301 ok(HIWORD(r) == 1, "Expected 1, got %d\n", HIWORD(r));
303 /* Set the position to -1, return should be 0 */
304 r = SendMessage(updown, UDM_SETPOS, 0 , MAKELONG(-1,0) );
305 ok(r == 0, "Expected 0, got %d\n", r);
306 /* Get the position, which should be 0 */
307 r = SendMessage(updown, UDM_GETPOS, 0 , 0 );
308 ok(LOWORD(r) == 0, "Expected 0, got %d\n", LOWORD(r));
309 ok(HIWORD(r) == 1, "Expected 1, got %d\n", HIWORD(r));
311 /* Set the position to 100, return should be 0 */
312 r = SendMessage(updown, UDM_SETPOS, 0 , MAKELONG(100,0) );
313 ok(r == 0, "Expected 0, got %d\n", r);
314 /* Get the position, which should be 100 */
315 r = SendMessage(updown, UDM_GETPOS, 0 , 0 );
316 ok(LOWORD(r) == 100, "Expected 100, got %d\n", LOWORD(r));
317 ok(HIWORD(r) == 1, "Expected 1, got %d\n", HIWORD(r));
319 /* Set the position to 101, return should be 100 */
320 r = SendMessage(updown, UDM_SETPOS, 0 , MAKELONG(101,0) );
321 ok(r == 100, "Expected 100, got %d\n", r);
322 /* Get the position, which should be 100 */
323 r = SendMessage(updown, UDM_GETPOS, 0 , 0 );
324 ok(LOWORD(r) == 100, "Expected 100, got %d\n", LOWORD(r));
325 ok(HIWORD(r) == 1, "Expected 1, got %d\n", HIWORD(r));
328 static void test_updown_pos32(void)
333 /* Set the position to 0 to 1000 */
334 SendMessage(updown, UDM_SETRANGE32, 0 , 1000 );
336 r = SendMessage(updown, UDM_GETRANGE32, (WPARAM) &low , (LPARAM) &high );
337 ok(low == 0, "Expected 0, got %d\n", low);
338 ok(high == 1000, "Expected 1000, got %d\n", high);
340 /* Set position to 500, don't check return since it is unset*/
341 r = SendMessage(updown, UDM_SETPOS32, 0 , 500 );
343 /* Since UDM_SETBUDDYINT was not set at creation bRet will always be true as a return from UDM_GETPOS32 */
345 r = SendMessage(updown, UDM_GETPOS32, 0 , (LPARAM) &high );
346 ok(r == 500, "Expected 500, got %d\n", r);
347 ok(high == 1 , "Expected 0, got %d\n", high);
349 /* Set position to 0, return should be 500 */
350 r = SendMessage(updown, UDM_SETPOS32, 0 , 0 );
351 ok(r == 500, "Expected 500, got %d\n", r);
352 r = SendMessage(updown, UDM_GETPOS32, 0 , (LPARAM) &high );
353 ok(r == 0, "Expected 0, got %d\n", r);
354 ok(high == 1 , "Expected 0, got %d\n", high);
356 /* Set position to -1 which sohuld become 0, return should be 0 */
357 r = SendMessage(updown, UDM_SETPOS32, 0 , -1 );
358 ok(r == 0, "Expected 0, got %d\n", r);
359 r = SendMessage(updown, UDM_GETPOS32, 0 , (LPARAM) &high );
360 ok(r == 0, "Expected 0, got %d\n", r);
361 ok(high == 1 , "Expected 0, got %d\n", high);
363 /* Set position to 1000, return should be 0 */
364 r = SendMessage(updown, UDM_SETPOS32, 0 , 1000 );
365 ok(r == 0, "Expected 0, got %d\n", r);
366 r = SendMessage(updown, UDM_GETPOS32, 0 , (LPARAM) &high );
367 ok(r == 1000, "Expected 1000, got %d\n", r);
368 ok(high == 1 , "Expected 0, got %d\n", high);
370 /* Set position to 1001 which sohuld become 1000, return should be 1000 */
371 r = SendMessage(updown, UDM_SETPOS32, 0 , 1001 );
372 ok(r == 1000, "Expected 1000, got %d\n", r);
373 r = SendMessage(updown, UDM_GETPOS32, 0 , (LPARAM) &high );
374 ok(r == 1000, "Expected 0, got %d\n", r);
375 ok(high == 1 , "Expected 0, got %d\n", high);
378 static void test_updown_buddy(void)
382 buddyReturn = (HWND)SendMessage(updown, UDM_GETBUDDY, 0 , 0 );
383 ok(buddyReturn == edit, "Expected edit handle\n");
386 static void test_updown_base(void)
390 SendMessage(updown, UDM_SETBASE, 10 , 0);
391 r = SendMessage(updown, UDM_GETBASE, 0 , 0);
392 ok(r == 10, "Expected 10, got %d\n", r);
394 /* Set base to an invalid value, should return 0 and stay at 10 */
395 r = SendMessage(updown, UDM_SETBASE, 80 , 0);
396 ok(r == 0, "Expected 0, got %d\n", r);
397 r = SendMessage(updown, UDM_GETBASE, 0 , 0);
398 ok(r == 10, "Expected 10, got %d\n", r);
400 /* Set base to 16 now, should get 16 as the return */
401 r = SendMessage(updown, UDM_SETBASE, 16 , 0);
402 ok(r == 10, "Expected 10, got %d\n", r);
403 r = SendMessage(updown, UDM_GETBASE, 0 , 0);
404 ok(r == 16, "Expected 16, got %d\n", r);
406 /* Set base to an invalid value, should return 0 and stay at 16 */
407 r = SendMessage(updown, UDM_SETBASE, 80 , 0);
408 ok(r == 0, "Expected 0, got %d\n", r);
409 r = SendMessage(updown, UDM_GETBASE, 0 , 0);
410 ok(r == 16, "Expected 16, got %d\n", r);
412 /* Set base back to 10, return should be 16 */
413 r = SendMessage(updown, UDM_SETBASE, 10 , 0);
414 ok(r == 16, "Expected 16, got %d\n", r);
415 r = SendMessage(updown, UDM_GETBASE, 0 , 0);
416 ok(r == 10, "Expected 10, got %d\n", r);
419 static void test_updown_unicode(void)
423 /* Set it to ANSI, don't check return as we don't know previous state */
424 SendMessage(updown, UDM_SETUNICODEFORMAT, 0 , 0);
425 r = SendMessage(updown, UDM_GETUNICODEFORMAT, 0 , 0);
426 ok(r == 0, "Expected 0, got %d\n", r);
428 /* Now set it to Unicode format */
429 r = SendMessage(updown, UDM_SETUNICODEFORMAT, 1 , 0);
430 ok(r == 0, "Expected 0, got %d\n", r);
431 r = SendMessage(updown, UDM_GETUNICODEFORMAT, 0 , 0);
432 ok(r == 1, "Expected 1, got %d\n", r);
434 /* And now set it back to ANSI */
435 r = SendMessage(updown, UDM_SETUNICODEFORMAT, 0 , 0);
436 ok(r == 1, "Expected 1, got %d\n", r);
437 r = SendMessage(updown, UDM_GETUNICODEFORMAT, 0 , 0);
438 ok(r == 0, "Expected 0, got %d\n", r);
442 static void test_create_updown_control(void)
446 parent_wnd = create_parent_window();
447 ok(parent_wnd != NULL, "Failed to create parent window!\n");
448 ok_sequence(sequences, PARENT_SEQ_INDEX, create_parent_wnd_seq, "create parent window", TRUE);
450 flush_sequences(sequences, NUM_MSG_SEQUENCES);
452 edit = create_edit_control();
453 ok(edit != NULL, "Failed to create edit control\n");
454 ok_sequence(sequences, PARENT_SEQ_INDEX, add_edit_to_parent_seq, "add edit control to parent", FALSE);
456 flush_sequences(sequences, NUM_MSG_SEQUENCES);
458 updown = create_updown_control();
459 ok(updown != NULL, "Failed to create updown control\n");
460 ok_sequence(sequences, PARENT_SEQ_INDEX, add_updown_to_parent_seq, "add updown control to parent", TRUE);
461 ok_sequence(sequences, EDIT_SEQ_INDEX, add_updown_with_edit_seq, "add updown control with edit", FALSE);
463 flush_sequences(sequences, NUM_MSG_SEQUENCES);
465 GetWindowTextA(edit, text, MAX_PATH);
466 ok(lstrlenA(text) == 0, "Expected empty string\n");
467 ok_sequence(sequences, EDIT_SEQ_INDEX, get_edit_text_seq, "get edit text", FALSE);
469 flush_sequences(sequences, NUM_MSG_SEQUENCES);
475 test_updown_unicode();
480 InitCommonControls();
481 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
483 test_create_updown_control();