Git conversion: Make reactos the root directory, move rosapps, rostests, wallpapers...
[reactos.git] / modules / rostests / winetests / comctl32 / updown.c
1 /* Unit tests for the up-down control
2 *
3 * Copyright 2005 C. Scott Ananian
4 * Copyright (C) 2007 James Hawkins
5 * Copyright (C) 2007 Leslie Choong
6 *
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.
11 *
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.
16 *
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
20 */
21
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
45 */
46
47 #include <wine/test.h>
48
49 //#include <windows.h>
50 #include <wingdi.h>
51 #include <winuser.h>
52 #include <commctrl.h>
53 #include <stdio.h>
54
55 #include "msg.h"
56
57 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
58
59 #define NUM_MSG_SEQUENCES 3
60 #define PARENT_SEQ_INDEX 0
61 #define EDIT_SEQ_INDEX 1
62 #define UPDOWN_SEQ_INDEX 2
63
64 #define UPDOWN_ID 0
65 #define BUDDY_ID 1
66
67 static HWND parent_wnd, g_edit;
68
69 static BOOL (WINAPI *pSetWindowSubclass)(HWND, SUBCLASSPROC, UINT_PTR, DWORD_PTR);
70
71 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
72
73 static const struct message add_updown_with_edit_seq[] = {
74 { WM_WINDOWPOSCHANGING, sent },
75 { WM_NCCALCSIZE, sent|wparam, TRUE },
76 { WM_WINDOWPOSCHANGED, sent },
77 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED /*, MAKELONG(91, 75) exact size depends on font */ },
78 { 0 }
79 };
80
81 static const struct message add_updown_to_parent_seq[] = {
82 { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
83 { WM_QUERYUISTATE, sent|optional },
84 { WM_PARENTNOTIFY, sent|wparam, MAKELONG(WM_CREATE, WM_CREATE) },
85 { 0 }
86 };
87
88 static const struct message get_edit_text_seq[] = {
89 { WM_GETTEXT, sent },
90 { 0 }
91 };
92
93 static const struct message test_updown_pos_seq[] = {
94 { UDM_SETRANGE, sent|lparam, 0, MAKELONG(100,0) },
95 { UDM_GETRANGE, sent},
96 { UDM_SETPOS, sent|lparam, 0, 5},
97 { UDM_GETPOS, sent},
98 { UDM_SETPOS, sent|lparam, 0, 0},
99 { UDM_GETPOS, sent},
100 { UDM_SETPOS, sent|lparam, 0, MAKELONG(-1,0)},
101 { UDM_GETPOS, sent},
102 { UDM_SETPOS, sent|lparam, 0, 100},
103 { UDM_GETPOS, sent},
104 { UDM_SETPOS, sent|lparam, 0, 101},
105 { UDM_GETPOS, sent},
106 { 0 }
107 };
108
109 static const struct message test_updown_pos32_seq[] = {
110 { UDM_SETRANGE32, sent|lparam, 0, 1000 },
111 { UDM_GETRANGE32, sent}, /* Cannot check wparam and lparam as they are ptrs */
112 { UDM_SETPOS32, sent|lparam, 0, 500 },
113 { UDM_GETPOS32, sent},
114 { UDM_SETPOS32, sent|lparam, 0, 0 },
115 { UDM_GETPOS32, sent},
116 { UDM_SETPOS32, sent|lparam, 0, -1 },
117 { UDM_GETPOS32, sent},
118 { UDM_SETPOS32, sent|lparam, 0, 1000 },
119 { UDM_GETPOS32, sent},
120 { UDM_SETPOS32, sent|lparam, 0, 1001 },
121 { UDM_GETPOS32, sent},
122 { 0 }
123 };
124
125 static const struct message test_updown_buddy_seq[] = {
126 { UDM_GETBUDDY, sent },
127 { UDM_SETBUDDY, sent },
128 { WM_STYLECHANGING, sent|defwinproc },
129 { WM_STYLECHANGED, sent|defwinproc },
130 { WM_STYLECHANGING, sent|defwinproc },
131 { WM_STYLECHANGED, sent|defwinproc },
132 { WM_WINDOWPOSCHANGING, sent|defwinproc },
133 { WM_NCCALCSIZE, sent|wparam|optional|defwinproc, 1 },
134 { WM_WINDOWPOSCHANGED, sent|defwinproc },
135 { WM_MOVE, sent|defwinproc },
136 { UDM_GETBUDDY, sent },
137 { 0 }
138 };
139
140 static const struct message test_updown_base_seq[] = {
141 { UDM_SETBASE, sent|wparam, 10 },
142 { UDM_GETBASE, sent },
143 { UDM_SETBASE, sent|wparam, 80 },
144 { UDM_GETBASE, sent },
145 { UDM_SETBASE, sent|wparam, 16 },
146 { UDM_GETBASE, sent },
147 { UDM_SETBASE, sent|wparam, 80 },
148 { UDM_GETBASE, sent },
149 { UDM_SETBASE, sent|wparam, 10 },
150 { UDM_GETBASE, sent },
151 { 0 }
152 };
153
154 static const struct message test_updown_unicode_seq[] = {
155 { UDM_SETUNICODEFORMAT, sent|wparam, 0 },
156 { UDM_GETUNICODEFORMAT, sent },
157 { UDM_SETUNICODEFORMAT, sent|wparam, 1 },
158 { UDM_GETUNICODEFORMAT, sent },
159 { UDM_SETUNICODEFORMAT, sent|wparam, 0 },
160 { UDM_GETUNICODEFORMAT, sent },
161 { 0 }
162 };
163
164 static const struct message test_updown_pos_nochange_seq[] = {
165 { WM_GETTEXT, sent|id, 0, 0, BUDDY_ID },
166 { 0 }
167 };
168
169 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
170 {
171 static LONG defwndproc_counter = 0;
172 struct message msg = { 0 };
173 LRESULT ret;
174
175 /* log system messages, except for painting */
176 if (message < WM_USER &&
177 message != WM_PAINT &&
178 message != WM_ERASEBKGND &&
179 message != WM_NCPAINT &&
180 message != WM_NCHITTEST &&
181 message != WM_GETTEXT &&
182 message != WM_GETICON &&
183 message != WM_DEVICECHANGE)
184 {
185 msg.message = message;
186 msg.flags = sent|wparam|lparam;
187 if (defwndproc_counter) msg.flags |= defwinproc;
188 msg.wParam = wParam;
189 msg.lParam = lParam;
190 add_message(sequences, PARENT_SEQ_INDEX, &msg);
191 }
192
193 defwndproc_counter++;
194 ret = DefWindowProcA(hwnd, message, wParam, lParam);
195 defwndproc_counter--;
196
197 return ret;
198 }
199
200 static BOOL register_parent_wnd_class(void)
201 {
202 WNDCLASSA cls;
203
204 cls.style = 0;
205 cls.lpfnWndProc = parent_wnd_proc;
206 cls.cbClsExtra = 0;
207 cls.cbWndExtra = 0;
208 cls.hInstance = GetModuleHandleA(NULL);
209 cls.hIcon = 0;
210 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
211 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
212 cls.lpszMenuName = NULL;
213 cls.lpszClassName = "Up-Down test parent class";
214 return RegisterClassA(&cls);
215 }
216
217 static HWND create_parent_window(void)
218 {
219 if (!register_parent_wnd_class())
220 return NULL;
221
222 return CreateWindowExA(0, "Up-Down test parent class",
223 "Up-Down test parent window",
224 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
225 WS_MAXIMIZEBOX | WS_VISIBLE,
226 0, 0, 100, 100,
227 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
228 }
229
230 static LRESULT WINAPI edit_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
231 {
232 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
233 static LONG defwndproc_counter = 0;
234 struct message msg = { 0 };
235 LRESULT ret;
236
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 msg.id = BUDDY_ID;
243 add_message(sequences, EDIT_SEQ_INDEX, &msg);
244
245 defwndproc_counter++;
246 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
247 defwndproc_counter--;
248 return ret;
249 }
250
251 static HWND create_edit_control(void)
252 {
253 WNDPROC oldproc;
254 HWND hwnd;
255 RECT rect;
256
257 GetClientRect(parent_wnd, &rect);
258 hwnd = CreateWindowExA(0, WC_EDITA, NULL, WS_CHILD | WS_BORDER | WS_VISIBLE,
259 0, 0, rect.right, rect.bottom,
260 parent_wnd, NULL, GetModuleHandleA(NULL), NULL);
261 if (!hwnd) return NULL;
262
263 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
264 (LONG_PTR)edit_subclass_proc);
265 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
266
267 return hwnd;
268 }
269
270 static LRESULT WINAPI updown_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
271 {
272 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
273 static LONG defwndproc_counter = 0;
274 struct message msg = { 0 };
275 LRESULT ret;
276
277 msg.message = message;
278 msg.flags = sent|wparam|lparam;
279 if (defwndproc_counter) msg.flags |= defwinproc;
280 msg.wParam = wParam;
281 msg.lParam = lParam;
282 msg.id = UPDOWN_ID;
283 add_message(sequences, UPDOWN_SEQ_INDEX, &msg);
284
285 defwndproc_counter++;
286 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
287 defwndproc_counter--;
288
289 return ret;
290 }
291
292 static HWND create_updown_control(DWORD style, HWND buddy)
293 {
294 WNDPROC oldproc;
295 HWND updown;
296 RECT rect;
297
298 GetClientRect(parent_wnd, &rect);
299 updown = CreateUpDownControl(WS_CHILD | WS_BORDER | WS_VISIBLE | style,
300 0, 0, rect.right, rect.bottom, parent_wnd, 1, GetModuleHandleA(NULL), buddy,
301 100, 0, 50);
302 if (!updown) return NULL;
303
304 oldproc = (WNDPROC)SetWindowLongPtrA(updown, GWLP_WNDPROC,
305 (LONG_PTR)updown_subclass_proc);
306 SetWindowLongPtrA(updown, GWLP_USERDATA, (LONG_PTR)oldproc);
307
308 return updown;
309 }
310
311 static void test_updown_pos(void)
312 {
313 HWND updown;
314 int r;
315
316 updown = create_updown_control(UDS_ALIGNRIGHT, g_edit);
317
318 flush_sequences(sequences, NUM_MSG_SEQUENCES);
319
320 /* Set Range from 0 to 100 */
321 SendMessageA(updown, UDM_SETRANGE, 0 , MAKELONG(100,0) );
322 r = SendMessageA(updown, UDM_GETRANGE, 0,0);
323 expect(100,LOWORD(r));
324 expect(0,HIWORD(r));
325
326 /* Set the position to 5, return is not checked as it was set before func call */
327 SendMessageA(updown, UDM_SETPOS, 0 , MAKELONG(5,0) );
328 /* Since UDM_SETBUDDYINT was not set at creation HIWORD(r) will always be 1 as a return from UDM_GETPOS */
329 /* Get the position, which should be 5 */
330 r = SendMessageA(updown, UDM_GETPOS, 0 , 0 );
331 expect(5,LOWORD(r));
332 expect(1,HIWORD(r));
333
334 /* Set the position to 0, return should be 5 */
335 r = SendMessageA(updown, UDM_SETPOS, 0 , MAKELONG(0,0) );
336 expect(5,r);
337 /* Get the position, which should be 0 */
338 r = SendMessageA(updown, UDM_GETPOS, 0 , 0 );
339 expect(0,LOWORD(r));
340 expect(1,HIWORD(r));
341
342 /* Set the position to -1, return should be 0 */
343 r = SendMessageA(updown, UDM_SETPOS, 0 , MAKELONG(-1,0) );
344 expect(0,r);
345 /* Get the position, which should be 0 */
346 r = SendMessageA(updown, UDM_GETPOS, 0 , 0 );
347 expect(0,LOWORD(r));
348 expect(1,HIWORD(r));
349
350 /* Set the position to 100, return should be 0 */
351 r = SendMessageA(updown, UDM_SETPOS, 0 , MAKELONG(100,0) );
352 expect(0,r);
353 /* Get the position, which should be 100 */
354 r = SendMessageA(updown, UDM_GETPOS, 0 , 0 );
355 expect(100,LOWORD(r));
356 expect(1,HIWORD(r));
357
358 /* Set the position to 101, return should be 100 */
359 r = SendMessageA(updown, UDM_SETPOS, 0 , MAKELONG(101,0) );
360 expect(100,r);
361 /* Get the position, which should be 100 */
362 r = SendMessageA(updown, UDM_GETPOS, 0 , 0 );
363 expect(100,LOWORD(r));
364 expect(1,HIWORD(r));
365
366 ok_sequence(sequences, UPDOWN_SEQ_INDEX, test_updown_pos_seq , "test updown pos", FALSE);
367
368 DestroyWindow(updown);
369
370 /* there's no attempt to update buddy Edit if text didn't change */
371 SetWindowTextA(g_edit, "50");
372 updown = create_updown_control(UDS_ALIGNRIGHT | UDS_SETBUDDYINT | UDS_ARROWKEYS, g_edit);
373
374 /* test sequence only on 5.8x versions */
375 r = SendMessageA(updown, UDM_GETPOS32, 0, 0);
376 if (r)
377 {
378 UDACCEL accel;
379
380 flush_sequences(sequences, NUM_MSG_SEQUENCES);
381
382 r = SendMessageA(updown, UDM_SETPOS, 0, 50);
383 expect(50,r);
384
385 ok_sequence(sequences, EDIT_SEQ_INDEX, test_updown_pos_nochange_seq,
386 "test updown pos, no change", FALSE);
387
388 SendMessageA(updown, UDM_SETRANGE, 0, MAKELONG(1, 40));
389 r = SendMessageA(updown, UDM_GETRANGE, 0, 0);
390 expect(1, LOWORD(r));
391 expect(40, HIWORD(r));
392
393 accel.nSec = 0;
394 accel.nInc = 5;
395 r = SendMessageA(updown, UDM_SETACCEL, 1, (LPARAM)&accel);
396 expect(TRUE, r);
397
398 r = SendMessageA(updown, UDM_GETPOS, 0, 0);
399 expect(40, LOWORD(r));
400 expect(1, HIWORD(r));
401
402 r = SendMessageA(updown, UDM_SETPOS, 0, MAKELONG(0, 0));
403 expect(40, LOWORD(r));
404 expect(0, HIWORD(r));
405
406 r = SendMessageA(updown, UDM_GETPOS, 0, 0);
407 expect(1, LOWORD(r));
408 expect(0, HIWORD(r));
409
410 r = SendMessageA(updown, UDM_SETPOS, 0, MAKELONG(2, 0));
411 expect(1, LOWORD(r));
412 expect(0, HIWORD(r));
413
414 r = SendMessageA(g_edit, WM_KEYDOWN, VK_UP, 0);
415 expect(0, r);
416 r = SendMessageA(updown, UDM_GETPOS, 0, 0);
417 expect(1, LOWORD(r));
418 expect(0, HIWORD(r));
419
420 r = SendMessageA(updown, UDM_SETPOS, 0, MAKELONG(50, 0));
421 expect(1, LOWORD(r));
422 expect(0, HIWORD(r));
423
424 r = SendMessageA(updown, UDM_GETPOS, 0, 0);
425 expect(40, LOWORD(r));
426 expect(0, HIWORD(r));
427 }
428
429 DestroyWindow(updown);
430 }
431
432 static void test_updown_pos32(void)
433 {
434 HWND updown;
435 int r;
436 int low, high;
437
438 updown = create_updown_control(UDS_ALIGNRIGHT, g_edit);
439
440 flush_sequences(sequences, NUM_MSG_SEQUENCES);
441
442 /* Set the position to 0 to 1000 */
443 SendMessageA(updown, UDM_SETRANGE32, 0 , 1000 );
444
445 low = high = -1;
446 r = SendMessageA(updown, UDM_GETRANGE32, (WPARAM) &low , (LPARAM) &high );
447 expect(0,r);
448 if (low == -1)
449 {
450 win_skip("UDM_SETRANGE32/UDM_GETRANGE32 not available\n");
451 DestroyWindow(updown);
452 return;
453 }
454
455 expect(0,low);
456 expect(1000,high);
457
458 /* Set position to 500 */
459 r = SendMessageA(updown, UDM_SETPOS32, 0 , 500 );
460 if (!r)
461 {
462 win_skip("UDM_SETPOS32 and UDM_GETPOS32 need 5.80\n");
463 DestroyWindow(updown);
464 return;
465 }
466 expect(50,r);
467
468 /* Since UDM_SETBUDDYINT was not set at creation bRet will always be true as a return from UDM_GETPOS32 */
469
470 r = SendMessageA(updown, UDM_GETPOS32, 0 , (LPARAM) &high );
471 expect(500,r);
472 expect(1,high);
473
474 /* Set position to 0, return should be 500 */
475 r = SendMessageA(updown, UDM_SETPOS32, 0 , 0 );
476 expect(500,r);
477 r = SendMessageA(updown, UDM_GETPOS32, 0 , (LPARAM) &high );
478 expect(0,r);
479 expect(1,high);
480
481 /* Set position to -1 which should become 0, return should be 0 */
482 r = SendMessageA(updown, UDM_SETPOS32, 0 , -1 );
483 expect(0,r);
484 r = SendMessageA(updown, UDM_GETPOS32, 0 , (LPARAM) &high );
485 expect(0,r);
486 expect(1,high);
487
488 /* Set position to 1000, return should be 0 */
489 r = SendMessageA(updown, UDM_SETPOS32, 0 , 1000 );
490 expect(0,r);
491 r = SendMessageA(updown, UDM_GETPOS32, 0 , (LPARAM) &high );
492 expect(1000,r);
493 expect(1,high);
494
495 /* Set position to 1001 which should become 1000, return should be 1000 */
496 r = SendMessageA(updown, UDM_SETPOS32, 0 , 1001 );
497 expect(1000,r);
498 r = SendMessageA(updown, UDM_GETPOS32, 0 , (LPARAM) &high );
499 expect(1000,r);
500 expect(1,high);
501
502 ok_sequence(sequences, UPDOWN_SEQ_INDEX, test_updown_pos32_seq, "test updown pos32", FALSE);
503
504 DestroyWindow(updown);
505
506 /* there's no attempt to update buddy Edit if text didn't change */
507 SetWindowTextA(g_edit, "50");
508 updown = create_updown_control(UDS_ALIGNRIGHT | UDS_SETBUDDYINT, g_edit);
509
510 flush_sequences(sequences, NUM_MSG_SEQUENCES);
511
512 r = SendMessageA(updown, UDM_SETPOS32, 0, 50);
513 expect(50,r);
514 ok_sequence(sequences, EDIT_SEQ_INDEX, test_updown_pos_nochange_seq,
515 "test updown pos, no change", FALSE);
516
517 DestroyWindow(updown);
518 }
519
520 static void test_updown_buddy(void)
521 {
522 HWND updown, buddyReturn, buddy;
523 WNDPROC proc;
524 DWORD style;
525
526 updown = create_updown_control(UDS_ALIGNRIGHT, g_edit);
527
528 flush_sequences(sequences, NUM_MSG_SEQUENCES);
529
530 buddyReturn = (HWND)SendMessageA(updown, UDM_GETBUDDY, 0 , 0 );
531 ok(buddyReturn == g_edit, "Expected edit handle\n");
532
533 buddyReturn = (HWND)SendMessageA(updown, UDM_SETBUDDY, (WPARAM) g_edit, 0);
534 ok(buddyReturn == g_edit, "Expected edit handle\n");
535
536 buddyReturn = (HWND)SendMessageA(updown, UDM_GETBUDDY, 0 , 0 );
537 ok(buddyReturn == g_edit, "Expected edit handle\n");
538
539 ok_sequence(sequences, UPDOWN_SEQ_INDEX, test_updown_buddy_seq, "test updown buddy", TRUE);
540 ok_sequence(sequences, EDIT_SEQ_INDEX, add_updown_with_edit_seq, "test updown buddy_edit", FALSE);
541
542 DestroyWindow(updown);
543
544 buddy = create_edit_control();
545 proc = (WNDPROC)GetWindowLongPtrA(buddy, GWLP_WNDPROC);
546
547 updown= create_updown_control(UDS_ALIGNRIGHT, buddy);
548 ok(proc == (WNDPROC)GetWindowLongPtrA(buddy, GWLP_WNDPROC), "No subclassing expected\n");
549
550 style = GetWindowLongA(updown, GWL_STYLE);
551 SetWindowLongA(updown, GWL_STYLE, style | UDS_ARROWKEYS);
552 style = GetWindowLongA(updown, GWL_STYLE);
553 ok(style & UDS_ARROWKEYS, "Expected UDS_ARROWKEYS\n");
554 /* no subclass if UDS_ARROWKEYS set after creation */
555 ok(proc == (WNDPROC)GetWindowLongPtrA(buddy, GWLP_WNDPROC), "No subclassing expected\n");
556
557 DestroyWindow(updown);
558
559 updown= create_updown_control(UDS_ALIGNRIGHT | UDS_ARROWKEYS, buddy);
560 ok(proc != (WNDPROC)GetWindowLongPtrA(buddy, GWLP_WNDPROC), "Subclassing expected\n");
561
562 if (pSetWindowSubclass)
563 {
564 /* updown uses subclass helpers for buddy on >5.8x systems */
565 ok(GetPropA(buddy, "CC32SubclassInfo") != NULL, "Expected CC32SubclassInfo property\n");
566 }
567
568 DestroyWindow(updown);
569
570 DestroyWindow(buddy);
571 }
572
573 static void test_updown_base(void)
574 {
575 HWND updown;
576 int r;
577 CHAR text[10];
578
579 updown = create_updown_control(UDS_ALIGNRIGHT, g_edit);
580
581 flush_sequences(sequences, NUM_MSG_SEQUENCES);
582
583 SendMessageA(updown, UDM_SETBASE, 10 , 0);
584 r = SendMessageA(updown, UDM_GETBASE, 0 , 0);
585 expect(10,r);
586
587 /* Set base to an invalid value, should return 0 and stay at 10 */
588 r = SendMessageA(updown, UDM_SETBASE, 80 , 0);
589 expect(0,r);
590 r = SendMessageA(updown, UDM_GETBASE, 0 , 0);
591 expect(10,r);
592
593 /* Set base to 16 now, should get 16 as the return */
594 r = SendMessageA(updown, UDM_SETBASE, 16 , 0);
595 expect(10,r);
596 r = SendMessageA(updown, UDM_GETBASE, 0 , 0);
597 expect(16,r);
598
599 /* Set base to an invalid value, should return 0 and stay at 16 */
600 r = SendMessageA(updown, UDM_SETBASE, 80 , 0);
601 expect(0,r);
602 r = SendMessageA(updown, UDM_GETBASE, 0 , 0);
603 expect(16,r);
604
605 /* Set base back to 10, return should be 16 */
606 r = SendMessageA(updown, UDM_SETBASE, 10 , 0);
607 expect(16,r);
608 r = SendMessageA(updown, UDM_GETBASE, 0 , 0);
609 expect(10,r);
610
611 ok_sequence(sequences, UPDOWN_SEQ_INDEX, test_updown_base_seq, "test updown base", FALSE);
612
613 DestroyWindow(updown);
614
615 /* switch base with buddy attached */
616 updown = create_updown_control(UDS_SETBUDDYINT | UDS_ALIGNRIGHT, g_edit);
617
618 r = SendMessageA(updown, UDM_SETPOS, 0, 10);
619 expect(50, r);
620
621 GetWindowTextA(g_edit, text, sizeof(text)/sizeof(CHAR));
622 ok(lstrcmpA(text, "10") == 0, "Expected '10', got '%s'\n", text);
623
624 r = SendMessageA(updown, UDM_SETBASE, 16, 0);
625 expect(10, r);
626
627 GetWindowTextA(g_edit, text, sizeof(text)/sizeof(CHAR));
628 /* FIXME: currently hex output isn't properly formatted, but for this
629 test only change from initial text matters */
630 ok(lstrcmpA(text, "10") != 0, "Expected '0x000A', got '%s'\n", text);
631
632 DestroyWindow(updown);
633 }
634
635 static void test_updown_unicode(void)
636 {
637 HWND updown;
638 int r;
639
640 updown = create_updown_control(UDS_ALIGNRIGHT, g_edit);
641
642 flush_sequences(sequences, NUM_MSG_SEQUENCES);
643
644 /* Set it to ANSI, don't check return as we don't know previous state */
645 SendMessageA(updown, UDM_SETUNICODEFORMAT, 0 , 0);
646 r = SendMessageA(updown, UDM_GETUNICODEFORMAT, 0 , 0);
647 expect(0,r);
648
649 /* Now set it to Unicode format */
650 r = SendMessageA(updown, UDM_SETUNICODEFORMAT, 1 , 0);
651 expect(0,r);
652 r = SendMessageA(updown, UDM_GETUNICODEFORMAT, 0 , 0);
653 if (!r)
654 {
655 win_skip("UDM_SETUNICODEFORMAT not available\n");
656 DestroyWindow(updown);
657 return;
658 }
659 expect(1,r);
660
661 /* And now set it back to ANSI */
662 r = SendMessageA(updown, UDM_SETUNICODEFORMAT, 0 , 0);
663 expect(1,r);
664 r = SendMessageA(updown, UDM_GETUNICODEFORMAT, 0 , 0);
665 expect(0,r);
666
667 ok_sequence(sequences, UPDOWN_SEQ_INDEX, test_updown_unicode_seq, "test updown unicode", FALSE);
668
669 DestroyWindow(updown);
670 }
671
672 static void test_updown_create(void)
673 {
674 CHAR text[MAX_PATH];
675 HWND updown;
676 RECT r;
677
678 flush_sequences(sequences, NUM_MSG_SEQUENCES);
679
680 updown = create_updown_control(UDS_ALIGNRIGHT, g_edit);
681 ok(updown != NULL, "Failed to create updown control\n");
682 ok_sequence(sequences, PARENT_SEQ_INDEX, add_updown_to_parent_seq, "add updown control to parent", TRUE);
683 ok_sequence(sequences, EDIT_SEQ_INDEX, add_updown_with_edit_seq, "add updown control with edit", FALSE);
684
685 flush_sequences(sequences, NUM_MSG_SEQUENCES);
686
687 GetWindowTextA(g_edit, text, MAX_PATH);
688 ok(lstrlenA(text) == 0, "Expected empty string\n");
689 ok_sequence(sequences, EDIT_SEQ_INDEX, get_edit_text_seq, "get edit text", FALSE);
690
691 DestroyWindow(updown);
692
693 /* create with zero width */
694 updown = CreateWindowA (UPDOWN_CLASSA, 0, WS_CHILD | WS_BORDER | WS_VISIBLE, 0, 0, 0, 0,
695 parent_wnd, (HMENU)(DWORD_PTR)1, GetModuleHandleA(NULL), 0);
696 ok(updown != NULL, "Failed to create updown control\n");
697 r.right = 0;
698 GetClientRect(updown, &r);
699 ok(r.right > 0, "Expected default width, got %d\n", r.right);
700 DestroyWindow(updown);
701 /* create with really small width */
702 updown = CreateWindowA (UPDOWN_CLASSA, 0, WS_CHILD | WS_BORDER | WS_VISIBLE, 0, 0, 2, 0,
703 parent_wnd, (HMENU)(DWORD_PTR)1, GetModuleHandleA(NULL), 0);
704 ok(updown != NULL, "Failed to create updown control\n");
705 r.right = 0;
706 GetClientRect(updown, &r);
707 ok(r.right != 2 && r.right > 0, "Expected default width, got %d\n", r.right);
708 DestroyWindow(updown);
709 /* create with width greater than default */
710 updown = CreateWindowA (UPDOWN_CLASSA, 0, WS_CHILD | WS_BORDER | WS_VISIBLE, 0, 0, 100, 0,
711 parent_wnd, (HMENU)(DWORD_PTR)1, GetModuleHandleA(NULL), 0);
712 ok(updown != NULL, "Failed to create updown control\n");
713 r.right = 0;
714 GetClientRect(updown, &r);
715 ok(r.right < 100 && r.right > 0, "Expected default width, got %d\n", r.right);
716 DestroyWindow(updown);
717 /* create with zero height, UDS_HORZ */
718 updown = CreateWindowA (UPDOWN_CLASSA, 0, UDS_HORZ | WS_CHILD | WS_BORDER | WS_VISIBLE, 0, 0, 0, 0,
719 parent_wnd, (HMENU)(DWORD_PTR)1, GetModuleHandleA(NULL), 0);
720 ok(updown != NULL, "Failed to create updown control\n");
721 r.bottom = 0;
722 GetClientRect(updown, &r);
723 ok(r.bottom == 0, "Expected zero height, got %d\n", r.bottom);
724 DestroyWindow(updown);
725 /* create with really small height, UDS_HORZ */
726 updown = CreateWindowA (UPDOWN_CLASSA, 0, UDS_HORZ | WS_CHILD | WS_BORDER | WS_VISIBLE, 0, 0, 0, 2,
727 parent_wnd, (HMENU)(DWORD_PTR)1, GetModuleHandleA(NULL), 0);
728 ok(updown != NULL, "Failed to create updown control\n");
729 r.bottom = 0;
730 GetClientRect(updown, &r);
731 ok(r.bottom == 0, "Expected zero height, got %d\n", r.bottom);
732 DestroyWindow(updown);
733 /* create with height greater than default, UDS_HORZ */
734 updown = CreateWindowA (UPDOWN_CLASSA, 0, UDS_HORZ | WS_CHILD | WS_BORDER | WS_VISIBLE, 0, 0, 0, 100,
735 parent_wnd, (HMENU)(DWORD_PTR)1, GetModuleHandleA(NULL), 0);
736 ok(updown != NULL, "Failed to create updown control\n");
737 r.bottom = 0;
738 GetClientRect(updown, &r);
739 ok(r.bottom < 100 && r.bottom > 0, "Expected default height, got %d\n", r.bottom);
740 DestroyWindow(updown);
741 }
742
743 static void test_UDS_SETBUDDYINT(void)
744 {
745 HWND updown;
746 DWORD style, ret;
747 CHAR text[10];
748
749 /* cleanup buddy */
750 text[0] = '\0';
751 SetWindowTextA(g_edit, text);
752
753 /* creating without UDS_SETBUDDYINT */
754 updown = create_updown_control(UDS_ALIGNRIGHT, g_edit);
755 /* try to set UDS_SETBUDDYINT after creation */
756 style = GetWindowLongA(updown, GWL_STYLE);
757 SetWindowLongA(updown, GWL_STYLE, style | UDS_SETBUDDYINT);
758 style = GetWindowLongA(updown, GWL_STYLE);
759 ok(style & UDS_SETBUDDYINT, "Expected UDS_SETBUDDY to be set\n");
760 SendMessageA(updown, UDM_SETPOS, 0, 20);
761 GetWindowTextA(g_edit, text, sizeof(text)/sizeof(CHAR));
762 ok(lstrlenA(text) == 0, "Expected empty string\n");
763 DestroyWindow(updown);
764
765 /* creating with UDS_SETBUDDYINT */
766 updown = create_updown_control(UDS_SETBUDDYINT | UDS_ALIGNRIGHT, g_edit);
767 GetWindowTextA(g_edit, text, sizeof(text)/sizeof(CHAR));
768 /* 50 is initial value here */
769 ok(lstrcmpA(text, "50") == 0, "Expected '50', got '%s'\n", text);
770 /* now remove style flag */
771 style = GetWindowLongA(updown, GWL_STYLE);
772 SetWindowLongA(updown, GWL_STYLE, style & ~UDS_SETBUDDYINT);
773 SendMessageA(updown, UDM_SETPOS, 0, 20);
774 GetWindowTextA(g_edit, text, sizeof(text)/sizeof(CHAR));
775 ok(lstrcmpA(text, "20") == 0, "Expected '20', got '%s'\n", text);
776 /* set edit text directly, check position */
777 strcpy(text, "10");
778 SetWindowTextA(g_edit, text);
779 ret = SendMessageA(updown, UDM_GETPOS, 0, 0);
780 expect(10, ret);
781 strcpy(text, "11");
782 SetWindowTextA(g_edit, text);
783 ret = SendMessageA(updown, UDM_GETPOS, 0, 0);
784 expect(11, LOWORD(ret));
785 expect(0, HIWORD(ret));
786 /* set to invalid value */
787 strcpy(text, "21st");
788 SetWindowTextA(g_edit, text);
789 ret = SendMessageA(updown, UDM_GETPOS, 0, 0);
790 expect(11, LOWORD(ret));
791 expect(TRUE, HIWORD(ret));
792 /* set style back */
793 style = GetWindowLongA(updown, GWL_STYLE);
794 SetWindowLongA(updown, GWL_STYLE, style | UDS_SETBUDDYINT);
795 SendMessageA(updown, UDM_SETPOS, 0, 30);
796 GetWindowTextA(g_edit, text, sizeof(text)/sizeof(CHAR));
797 ok(lstrcmpA(text, "30") == 0, "Expected '30', got '%s'\n", text);
798 DestroyWindow(updown);
799 }
800
801 START_TEST(updown)
802 {
803 HMODULE mod = GetModuleHandleA("comctl32.dll");
804
805 pSetWindowSubclass = (void*)GetProcAddress(mod, (LPSTR)410);
806
807 InitCommonControls();
808 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
809
810 parent_wnd = create_parent_window();
811 ok(parent_wnd != NULL, "Failed to create parent window!\n");
812 g_edit = create_edit_control();
813 ok(g_edit != NULL, "Failed to create edit control\n");
814
815 test_updown_create();
816 test_updown_pos();
817 test_updown_pos32();
818 test_updown_buddy();
819 test_updown_base();
820 test_updown_unicode();
821 test_UDS_SETBUDDYINT();
822
823 DestroyWindow(g_edit);
824 DestroyWindow(parent_wnd);
825 }