comctl32: updown: Expect macro and spelling errors.
[wine/wine-gecko.git] / dlls / comctl32 / tests / updown.c
blobc8f944f39d903c6dacf76644b0e111af4b17778e
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
22 /* TO TEST:
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
37 * - check UDS_HORZ
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
47 #include <assert.h>
48 #include <windows.h>
49 #include <commctrl.h>
50 #include <stdio.h>
52 #include "wine/test.h"
53 #include "msg.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 },
70 { WM_CREATE, sent },
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 },
83 { WM_SIZE, sent },
84 { WM_MOVE, sent },
85 { 0 }
88 static const struct message add_edit_to_parent_seq[] = {
89 { WM_PARENTNOTIFY, sent|wparam, WM_CREATE },
90 { 0 }
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 */ },
98 { 0 }
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) },
105 { 0 }
108 static const struct message get_edit_text_seq[] = {
109 { WM_GETTEXT, sent },
110 { 0 }
113 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
115 static long defwndproc_counter = 0;
116 LRESULT ret;
117 struct message msg;
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;
133 msg.wParam = wParam;
134 msg.lParam = lParam;
135 add_message(sequences, PARENT_SEQ_INDEX, &msg);
138 defwndproc_counter++;
139 ret = DefWindowProcA(hwnd, message, wParam, lParam);
140 defwndproc_counter--;
142 return ret;
145 static BOOL register_parent_wnd_class(void)
147 WNDCLASSA cls;
149 cls.style = 0;
150 cls.lpfnWndProc = parent_wnd_proc;
151 cls.cbClsExtra = 0;
152 cls.cbWndExtra = 0;
153 cls.hInstance = GetModuleHandleA(NULL);
154 cls.hIcon = 0;
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())
165 return NULL;
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,
171 0, 0, 100, 100,
172 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
175 struct subclass_info
177 WNDPROC oldproc;
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;
184 LRESULT ret;
185 struct message msg;
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;
192 msg.wParam = wParam;
193 msg.lParam = lParam;
194 add_message(sequences, EDIT_SEQ_INDEX, &msg);
196 defwndproc_counter++;
197 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
198 defwndproc_counter--;
199 return ret;
202 static HWND create_edit_control(void)
204 struct subclass_info *info;
205 RECT rect;
207 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
208 if (!info)
209 return NULL;
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);
215 if (!edit)
217 HeapFree(GetProcessHeap(), 0, info);
218 return NULL;
221 info->oldproc = (WNDPROC)SetWindowLongA(edit, GWL_WNDPROC,
222 (LONG)edit_subclass_proc);
223 SetWindowLongA(edit, GWL_USERDATA, (LONG)info);
225 return edit;
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;
232 LRESULT ret;
233 struct message msg;
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;
240 msg.wParam = wParam;
241 msg.lParam = lParam;
242 add_message(sequences, EDIT_SEQ_INDEX, &msg);
244 defwndproc_counter++;
245 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
246 defwndproc_counter--;
248 return ret;
251 static HWND create_updown_control(void)
253 struct subclass_info *info;
254 HWND updown;
255 RECT rect;
257 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
258 if (!info)
259 return NULL;
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,
264 100, 0, 50);
265 if (!updown)
267 HeapFree(GetProcessHeap(), 0, info);
268 return NULL;
271 info->oldproc = (WNDPROC)SetWindowLongA(updown, GWL_WNDPROC,
272 (LONG)updown_subclass_proc);
273 SetWindowLongA(updown, GWL_USERDATA, (LONG)info);
275 return updown;
278 static void test_updown_pos(void)
280 int r;
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));
286 expect(0,HIWORD(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 );
293 expect(5,LOWORD(r));
294 expect(1,HIWORD(r));
296 /* Set the position to 0, return should be 5 */
297 r = SendMessage(updown, UDM_SETPOS, 0 , MAKELONG(0,0) );
298 expect(5,r);
299 /* Get the position, which should be 0 */
300 r = SendMessage(updown, UDM_GETPOS, 0 , 0 );
301 expect(0,LOWORD(r));
302 expect(1,HIWORD(r));
304 /* Set the position to -1, return should be 0 */
305 r = SendMessage(updown, UDM_SETPOS, 0 , MAKELONG(-1,0) );
306 expect(0,r);
307 /* Get the position, which should be 0 */
308 r = SendMessage(updown, UDM_GETPOS, 0 , 0 );
309 expect(0,LOWORD(r));
310 expect(1,HIWORD(r));
312 /* Set the position to 100, return should be 0 */
313 r = SendMessage(updown, UDM_SETPOS, 0 , MAKELONG(100,0) );
314 expect(0,r);
315 /* Get the position, which should be 100 */
316 r = SendMessage(updown, UDM_GETPOS, 0 , 0 );
317 expect(100,LOWORD(r));
318 expect(1,HIWORD(r));
320 /* Set the position to 101, return should be 100 */
321 r = SendMessage(updown, UDM_SETPOS, 0 , MAKELONG(101,0) );
322 expect(100,r);
323 /* Get the position, which should be 100 */
324 r = SendMessage(updown, UDM_GETPOS, 0 , 0 );
325 expect(100,LOWORD(r));
326 expect(1,HIWORD(r));
329 static void test_updown_pos32(void)
331 int r;
332 int low, high;
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 );
338 expect(0,low);
339 expect(1000,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 );
347 expect(500,r);
348 expect(1,high);
350 /* Set position to 0, return should be 500 */
351 r = SendMessage(updown, UDM_SETPOS32, 0 , 0 );
352 expect(500,r);
353 r = SendMessage(updown, UDM_GETPOS32, 0 , (LPARAM) &high );
354 expect(0,r);
355 expect(1,high);
357 /* Set position to -1 which should become 0, return should be 0 */
358 r = SendMessage(updown, UDM_SETPOS32, 0 , -1 );
359 expect(0,r);
360 r = SendMessage(updown, UDM_GETPOS32, 0 , (LPARAM) &high );
361 expect(0,r);
362 expect(1,high);
364 /* Set position to 1000, return should be 0 */
365 r = SendMessage(updown, UDM_SETPOS32, 0 , 1000 );
366 expect(0,r);
367 r = SendMessage(updown, UDM_GETPOS32, 0 , (LPARAM) &high );
368 expect(1000,r);
369 expect(1,high);
371 /* Set position to 1001 which should become 1000, return should be 1000 */
372 r = SendMessage(updown, UDM_SETPOS32, 0 , 1001 );
373 expect(1000,r);
374 r = SendMessage(updown, UDM_GETPOS32, 0 , (LPARAM) &high );
375 expect(1000,r);
376 expect(1,high);
379 static void test_updown_buddy(void)
381 HWND buddyReturn;
383 buddyReturn = (HWND)SendMessage(updown, UDM_GETBUDDY, 0 , 0 );
384 ok(buddyReturn == edit, "Expected edit handle\n");
387 static void test_updown_base(void)
389 int r;
391 SendMessage(updown, UDM_SETBASE, 10 , 0);
392 r = SendMessage(updown, UDM_GETBASE, 0 , 0);
393 expect(10,r);
395 /* Set base to an invalid value, should return 0 and stay at 10 */
396 r = SendMessage(updown, UDM_SETBASE, 80 , 0);
397 expect(0,r);
398 r = SendMessage(updown, UDM_GETBASE, 0 , 0);
399 expect(10,r);
401 /* Set base to 16 now, should get 16 as the return */
402 r = SendMessage(updown, UDM_SETBASE, 16 , 0);
403 expect(10,r);
404 r = SendMessage(updown, UDM_GETBASE, 0 , 0);
405 expect(16,r);
407 /* Set base to an invalid value, should return 0 and stay at 16 */
408 r = SendMessage(updown, UDM_SETBASE, 80 , 0);
409 expect(0,r);
410 r = SendMessage(updown, UDM_GETBASE, 0 , 0);
411 expect(16,r);
413 /* Set base back to 10, return should be 16 */
414 r = SendMessage(updown, UDM_SETBASE, 10 , 0);
415 expect(16,r);
416 r = SendMessage(updown, UDM_GETBASE, 0 , 0);
417 expect(10,r);
420 static void test_updown_unicode(void)
422 int r;
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);
427 expect(0,r);
429 /* Now set it to Unicode format */
430 r = SendMessage(updown, UDM_SETUNICODEFORMAT, 1 , 0);
431 expect(0,r);
432 r = SendMessage(updown, UDM_GETUNICODEFORMAT, 0 , 0);
433 expect(1,r);
435 /* And now set it back to ANSI */
436 r = SendMessage(updown, UDM_SETUNICODEFORMAT, 0 , 0);
437 expect(1,r);
438 r = SendMessage(updown, UDM_GETUNICODEFORMAT, 0 , 0);
439 expect(0,r);
443 static void test_create_updown_control(void)
445 CHAR text[MAX_PATH];
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);
472 test_updown_pos();
473 test_updown_pos32();
474 test_updown_buddy();
475 test_updown_base();
476 test_updown_unicode();
479 START_TEST(updown)
481 InitCommonControls();
482 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
484 test_create_updown_control();