1 /* Unit tests for the up-down control
3 * Copyright 2005 C. Scott Ananian
4 * Copyright (C) 2007 James Hawkins
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
22 * - send click messages to the up-down control, check the current position
23 * - up-down control automatically positions itself next to its buddy window
24 * - up-down control sets the caption of the buddy window
25 * - test CreateUpDownControl API
26 * - check UDS_AUTOBUDDY style, up-down control selects previous window in z-order
27 * - check UDM_SETBUDDY message
28 * - check UDM_GETBUDDY message
29 * - up-down control and buddy control must have the same parent
30 * - up-down control notifies its parent window when its position changes with UDN_DELTAPOS + WM_VSCROLL or WM_HSCROLL
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 * - check UDM_GETRANGE
44 * - more stuff to test
52 #include "wine/test.h"
54 #define NUM_MSG_SEQUENCES 3
55 #define PARENT_SEQ_INDEX 0
56 #define EDIT_SEQ_INDEX 1
57 #define UPDOWN_SEQ_INDEX 2
59 /* undocumented SWP flags - from SDK 3.1 */
60 #define SWP_NOCLIENTSIZE 0x0800
61 #define SWP_NOCLIENTMOVE 0x1000
63 static HWND parent_wnd, edit, updown;
81 UINT message; /* the WM_* code */
82 msg_flags_t flags; /* message props */
83 WPARAM wParam; /* expected value of wParam */
84 LPARAM lParam; /* expected value of lParam */
91 struct message *sequence;
94 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
96 static const struct message create_parent_wnd_seq[] = {
97 { WM_GETMINMAXINFO, sent },
98 { WM_NCCREATE, sent },
99 { WM_NCCALCSIZE, sent|wparam, 0 },
101 { WM_SHOWWINDOW, sent|wparam, 1 },
102 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
103 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
104 { WM_ACTIVATEAPP, sent|wparam, 1 },
105 { WM_NCACTIVATE, sent|wparam, 1 },
106 { WM_ACTIVATE, sent|wparam, 1 },
107 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
108 { WM_IME_NOTIFY, sent|defwinproc|optional },
109 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
110 /* Win9x adds SWP_NOZORDER below */
111 { WM_WINDOWPOSCHANGED, sent, /*|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ },
112 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
118 static const struct message add_edit_to_parent_seq[] = {
119 { WM_PARENTNOTIFY, sent|wparam, WM_CREATE },
123 static const struct message add_updown_with_edit_seq[] = {
124 { WM_WINDOWPOSCHANGING, sent },
125 { WM_NCCALCSIZE, sent|wparam, TRUE },
126 { WM_WINDOWPOSCHANGED, sent },
127 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED /*, MAKELONG(91, 75) exact size depends on font */ },
131 static const struct message add_updown_to_parent_seq[] = {
132 { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
133 { WM_QUERYUISTATE, sent },
134 { WM_PARENTNOTIFY, sent|wparam, MAKELONG(WM_CREATE, WM_CREATE) },
138 static const struct message get_edit_text_seq[] = {
139 { WM_GETTEXT, sent },
143 static void add_message(int sequence_index, const struct message *msg)
145 struct msg_sequence *msg_seq = sequences[sequence_index];
147 if (!msg_seq->sequence)
150 msg_seq->sequence = HeapAlloc(GetProcessHeap(), 0,
151 msg_seq->size * sizeof (struct message));
154 if (msg_seq->count == msg_seq->size)
157 msg_seq->sequence = HeapReAlloc(GetProcessHeap(), 0,
159 msg_seq->size * sizeof (struct message));
162 assert(msg_seq->sequence);
164 msg_seq->sequence[msg_seq->count].message = msg->message;
165 msg_seq->sequence[msg_seq->count].flags = msg->flags;
166 msg_seq->sequence[msg_seq->count].wParam = msg->wParam;
167 msg_seq->sequence[msg_seq->count].lParam = msg->lParam;
172 static void flush_sequence(int sequence_index)
174 struct msg_sequence *msg_seq = sequences[sequence_index];
175 HeapFree(GetProcessHeap(), 0, msg_seq->sequence);
176 msg_seq->sequence = NULL;
177 msg_seq->count = msg_seq->size = 0;
180 static void flush_sequences(void)
182 flush_sequence(PARENT_SEQ_INDEX);
183 flush_sequence(EDIT_SEQ_INDEX);
184 flush_sequence(UPDOWN_SEQ_INDEX);
187 #define ok_sequence(index, exp, contx, todo) \
188 ok_sequence_(index, (exp), (contx), (todo), __FILE__, __LINE__)
191 static void ok_sequence_(int sequence_index, const struct message *expected,
192 const char *context, int todo, const char *file, int line)
194 struct msg_sequence *msg_seq = sequences[sequence_index];
195 static const struct message end_of_sequence = {0, 0, 0, 0};
196 const struct message *actual, *sequence;
199 add_message(sequence_index, &end_of_sequence);
201 sequence = msg_seq->sequence;
204 while (expected->message && actual->message)
206 trace_( file, line)("expected %04x - actual %04x\n", expected->message, actual->message);
208 if (expected->message == actual->message)
210 if (expected->flags & wparam)
212 if (expected->wParam != actual->wParam && todo)
217 ok_(file, line) (FALSE,
218 "%s: in msg 0x%04x expecting wParam 0x%x got 0x%x\n",
219 context, expected->message, expected->wParam, actual->wParam);
224 ok_(file, line) (expected->wParam == actual->wParam,
225 "%s: in msg 0x%04x expecting wParam 0x%x got 0x%x\n",
226 context, expected->message, expected->wParam, actual->wParam);
230 if (expected->flags & lparam)
232 if (expected->lParam != actual->lParam && todo)
237 ok_(file, line) (FALSE,
238 "%s: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
239 context, expected->message, expected->lParam, actual->lParam);
244 ok_(file, line) (expected->lParam == actual->lParam,
245 "%s: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
246 context, expected->message, expected->lParam, actual->lParam);
250 if ((expected->flags & defwinproc) != (actual->flags & defwinproc) && todo)
255 ok_(file, line) (FALSE,
256 "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
257 context, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
262 ok_(file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
263 "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
264 context, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
267 ok_(file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
268 "%s: the msg 0x%04x should %shave been sent by BeginPaint\n",
269 context, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
270 ok_(file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
271 "%s: the msg 0x%04x should have been %s\n",
272 context, expected->message, (expected->flags & posted) ? "posted" : "sent");
273 ok_(file, line) ((expected->flags & parent) == (actual->flags & parent),
274 "%s: the msg 0x%04x was expected in %s\n",
275 context, expected->message, (expected->flags & parent) ? "parent" : "child");
276 ok_(file, line) ((expected->flags & hook) == (actual->flags & hook),
277 "%s: the msg 0x%04x should have been sent by a hook\n",
278 context, expected->message);
279 ok_(file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
280 "%s: the msg 0x%04x should have been sent by a winevent hook\n",
281 context, expected->message);
285 else if (expected->flags & optional)
292 ok_(file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
293 context, expected->message, actual->message);
296 flush_sequence(sequence_index);
301 ok_(file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
302 context, expected->message, actual->message);
308 /* skip all optional trailing messages */
309 while (expected->message && ((expected->flags & optional)))
316 if (expected->message || actual->message)
319 ok_(file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
320 context, expected->message, actual->message);
324 else if (expected->message || actual->message)
326 ok_(file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
327 context, expected->message, actual->message);
330 if(todo && !failcount) /* succeeded yet marked todo */
334 ok_(file, line)(TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
338 flush_sequence(sequence_index);
341 static void init_msg_sequences(void)
345 for (i = 0; i < NUM_MSG_SEQUENCES; i++)
346 sequences[i] = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct msg_sequence));
349 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
351 static long defwndproc_counter = 0;
355 /* do not log painting messages */
356 if (message != WM_PAINT &&
357 message != WM_ERASEBKGND &&
358 message != WM_NCPAINT &&
359 message != WM_NCHITTEST &&
360 message != WM_GETTEXT &&
361 message != WM_GETICON &&
362 message != WM_DEVICECHANGE)
364 trace("parent: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
366 msg.message = message;
367 msg.flags = sent|wparam|lparam;
368 if (defwndproc_counter) msg.flags |= defwinproc;
371 add_message(PARENT_SEQ_INDEX, &msg);
374 defwndproc_counter++;
375 ret = DefWindowProcA(hwnd, message, wParam, lParam);
376 defwndproc_counter--;
381 static BOOL register_parent_wnd_class(void)
386 cls.lpfnWndProc = parent_wnd_proc;
389 cls.hInstance = GetModuleHandleA(NULL);
391 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
392 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
393 cls.lpszMenuName = NULL;
394 cls.lpszClassName = "Up-Down test parent class";
395 return RegisterClassA(&cls);
398 static HWND create_parent_window(void)
400 if (!register_parent_wnd_class())
403 return CreateWindowEx(0, "Up-Down test parent class",
404 "Up-Down test parent window",
405 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
406 WS_MAXIMIZEBOX | WS_VISIBLE,
408 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
416 static LRESULT WINAPI edit_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
418 struct subclass_info *info = (struct subclass_info *)GetWindowLongA(hwnd, GWL_USERDATA);
419 static long defwndproc_counter = 0;
423 trace("edit: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
425 msg.message = message;
426 msg.flags = sent|wparam|lparam;
427 if (defwndproc_counter) msg.flags |= defwinproc;
430 add_message(EDIT_SEQ_INDEX, &msg);
432 defwndproc_counter++;
433 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
434 defwndproc_counter--;
438 static HWND create_edit_control()
440 struct subclass_info *info;
443 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
447 GetClientRect(parent_wnd, &rect);
448 edit = CreateWindowExA(0, "EDIT", NULL, WS_CHILD | WS_BORDER | WS_VISIBLE,
449 0, 0, rect.right, rect.bottom,
450 parent_wnd, NULL, GetModuleHandleA(NULL), NULL);
453 HeapFree(GetProcessHeap(), 0, info);
457 info->oldproc = (WNDPROC)SetWindowLongA(edit, GWL_WNDPROC,
458 (LONG)edit_subclass_proc);
459 SetWindowLongA(edit, GWL_USERDATA, (LONG)info);
464 static LRESULT WINAPI updown_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
466 struct subclass_info *info = (struct subclass_info *)GetWindowLongA(hwnd, GWL_USERDATA);
467 static long defwndproc_counter = 0;
471 trace("updown: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
473 msg.message = message;
474 msg.flags = sent|wparam|lparam;
475 if (defwndproc_counter) msg.flags |= defwinproc;
478 add_message(EDIT_SEQ_INDEX, &msg);
480 defwndproc_counter++;
481 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
482 defwndproc_counter--;
487 static HWND create_updown_control()
489 struct subclass_info *info;
493 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
497 GetClientRect(parent_wnd, &rect);
498 updown = CreateUpDownControl(WS_CHILD | WS_BORDER | WS_VISIBLE | UDS_ALIGNRIGHT,
499 0, 0, rect.right, rect.bottom, parent_wnd, 1, GetModuleHandleA(NULL), edit,
503 HeapFree(GetProcessHeap(), 0, info);
507 info->oldproc = (WNDPROC)SetWindowLongA(updown, GWL_WNDPROC,
508 (LONG)updown_subclass_proc);
509 SetWindowLongA(updown, GWL_USERDATA, (LONG)info);
514 static void test_create_updown_control(void)
518 parent_wnd = create_parent_window();
519 ok(parent_wnd != NULL, "Failed to create parent window!\n");
520 ok_sequence(PARENT_SEQ_INDEX, create_parent_wnd_seq, "create parent window", TRUE);
524 edit = create_edit_control();
525 ok(edit != NULL, "Failed to create edit control\n");
526 ok_sequence(PARENT_SEQ_INDEX, add_edit_to_parent_seq, "add edit control to parent", FALSE);
530 updown = create_updown_control();
531 ok(updown != NULL, "Failed to create updown control\n");
532 ok_sequence(PARENT_SEQ_INDEX, add_updown_to_parent_seq, "add updown control to parent", TRUE);
533 ok_sequence(EDIT_SEQ_INDEX, add_updown_with_edit_seq, "add updown control with edit", FALSE);
537 GetWindowTextA(edit, text, MAX_PATH);
538 ok(lstrlenA(text) == 0, "Expected empty string\n");
539 ok_sequence(EDIT_SEQ_INDEX, get_edit_text_seq, "get edit text", FALSE);
546 InitCommonControls();
547 init_msg_sequences();
549 test_create_updown_control();