fltlib: Add a stub dll.
[wine] / dlls / comctl32 / tests / 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 <assert.h>
48 #include <windows.h>
49 #include <commctrl.h>
50 #include <stdio.h>
51
52 #include "wine/test.h"
53 #include "msg.h"
54
55 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
56
57 #define NUM_MSG_SEQUENCES   3
58 #define PARENT_SEQ_INDEX    0
59 #define EDIT_SEQ_INDEX      1
60 #define UPDOWN_SEQ_INDEX    2
61
62 static HWND parent_wnd, edit;
63
64 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
65
66 static const struct message add_updown_with_edit_seq[] = {
67     { WM_WINDOWPOSCHANGING, sent },
68     { WM_NCCALCSIZE, sent|wparam, TRUE },
69     { WM_WINDOWPOSCHANGED, sent },
70     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED /*, MAKELONG(91, 75) exact size depends on font */ },
71     { 0 }
72 };
73
74 static const struct message add_updown_to_parent_seq[] = {
75     { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
76     { WM_QUERYUISTATE, sent|optional },
77     { WM_PARENTNOTIFY, sent|wparam, MAKELONG(WM_CREATE, WM_CREATE) },
78     { 0 }
79 };
80
81 static const struct message get_edit_text_seq[] = {
82     { WM_GETTEXT, sent },
83     { 0 }
84 };
85
86 static const struct message test_updown_pos_seq[] = {
87     { UDM_SETRANGE, sent|lparam, 0, MAKELONG(100,0) },
88     { UDM_GETRANGE, sent},
89     { UDM_SETPOS, sent|lparam, 0, 5},
90     { UDM_GETPOS, sent},
91     { UDM_SETPOS, sent|lparam, 0, 0},
92     { UDM_GETPOS, sent},
93     { UDM_SETPOS, sent|lparam, 0, MAKELONG(-1,0)},
94     { UDM_GETPOS, sent},
95     { UDM_SETPOS, sent|lparam, 0, 100},
96     { UDM_GETPOS, sent},
97     { UDM_SETPOS, sent|lparam, 0, 101},
98     { UDM_GETPOS, sent},
99     { 0 }
100 };
101
102 static const struct message test_updown_pos32_seq[] = {
103     { UDM_SETRANGE32, sent|lparam, 0, 1000 },
104     { UDM_GETRANGE32, sent}, /* Cannot check wparam and lparam as they are ptrs */
105     { UDM_SETPOS32, sent|lparam, 0, 500 },
106     { UDM_GETPOS32, sent},
107     { UDM_SETPOS32, sent|lparam, 0, 0 },
108     { UDM_GETPOS32, sent},
109     { UDM_SETPOS32, sent|lparam, 0, -1 },
110     { UDM_GETPOS32, sent},
111     { UDM_SETPOS32, sent|lparam, 0, 1000 },
112     { UDM_GETPOS32, sent},
113     { UDM_SETPOS32, sent|lparam, 0, 1001 },
114     { UDM_GETPOS32, sent},
115     { 0 }
116 };
117
118 static const struct message test_updown_buddy_seq[] = {
119     { UDM_GETBUDDY, sent },
120     { UDM_SETBUDDY, sent },
121     { WM_STYLECHANGING, sent|defwinproc },
122     { WM_STYLECHANGED, sent|defwinproc },
123     { WM_STYLECHANGING, sent|defwinproc },
124     { WM_STYLECHANGED, sent|defwinproc },
125     { WM_WINDOWPOSCHANGING, sent|defwinproc },
126     { WM_NCCALCSIZE, sent|wparam|optional|defwinproc, 1 },
127     { WM_WINDOWPOSCHANGED, sent|defwinproc },
128     { WM_MOVE, sent|defwinproc },
129     { UDM_GETBUDDY, sent },
130     { 0 }
131 };
132
133 static const struct message test_updown_base_seq[] = {
134     { UDM_SETBASE, sent|wparam, 10 },
135     { UDM_GETBASE, sent },
136     { UDM_SETBASE, sent|wparam, 80 },
137     { UDM_GETBASE, sent },
138     { UDM_SETBASE, sent|wparam, 16 },
139     { UDM_GETBASE, sent },
140     { UDM_SETBASE, sent|wparam, 80 },
141     { UDM_GETBASE, sent },
142     { UDM_SETBASE, sent|wparam, 10 },
143     { UDM_GETBASE, sent },
144     { 0 }
145 };
146
147 static const struct message test_updown_unicode_seq[] = {
148     { UDM_SETUNICODEFORMAT, sent|wparam, 0 },
149     { UDM_GETUNICODEFORMAT, sent },
150     { UDM_SETUNICODEFORMAT, sent|wparam, 1 },
151     { UDM_GETUNICODEFORMAT, sent },
152     { UDM_SETUNICODEFORMAT, sent|wparam, 0 },
153     { UDM_GETUNICODEFORMAT, sent },
154     { 0 }
155 };
156
157 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
158 {
159     static LONG defwndproc_counter = 0;
160     LRESULT ret;
161     struct message msg;
162
163     /* log system messages, except for painting */
164     if (message < WM_USER &&
165         message != WM_PAINT &&
166         message != WM_ERASEBKGND &&
167         message != WM_NCPAINT &&
168         message != WM_NCHITTEST &&
169         message != WM_GETTEXT &&
170         message != WM_GETICON &&
171         message != WM_DEVICECHANGE)
172     {
173         trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
174
175         msg.message = message;
176         msg.flags = sent|wparam|lparam;
177         if (defwndproc_counter) msg.flags |= defwinproc;
178         msg.wParam = wParam;
179         msg.lParam = lParam;
180         add_message(sequences, PARENT_SEQ_INDEX, &msg);
181     }
182
183     defwndproc_counter++;
184     ret = DefWindowProcA(hwnd, message, wParam, lParam);
185     defwndproc_counter--;
186
187     return ret;
188 }
189
190 static BOOL register_parent_wnd_class(void)
191 {
192     WNDCLASSA cls;
193
194     cls.style = 0;
195     cls.lpfnWndProc = parent_wnd_proc;
196     cls.cbClsExtra = 0;
197     cls.cbWndExtra = 0;
198     cls.hInstance = GetModuleHandleA(NULL);
199     cls.hIcon = 0;
200     cls.hCursor = LoadCursorA(0, IDC_ARROW);
201     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
202     cls.lpszMenuName = NULL;
203     cls.lpszClassName = "Up-Down test parent class";
204     return RegisterClassA(&cls);
205 }
206
207 static HWND create_parent_window(void)
208 {
209     if (!register_parent_wnd_class())
210         return NULL;
211
212     return CreateWindowEx(0, "Up-Down test parent class",
213                           "Up-Down test parent window",
214                           WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
215                           WS_MAXIMIZEBOX | WS_VISIBLE,
216                           0, 0, 100, 100,
217                           GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
218 }
219
220 struct subclass_info
221 {
222     WNDPROC oldproc;
223 };
224
225 static LRESULT WINAPI edit_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
226 {
227     struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
228     static LONG defwndproc_counter = 0;
229     LRESULT ret;
230     struct message msg;
231
232     trace("edit: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
233
234     msg.message = message;
235     msg.flags = sent|wparam|lparam;
236     if (defwndproc_counter) msg.flags |= defwinproc;
237     msg.wParam = wParam;
238     msg.lParam = lParam;
239     add_message(sequences, EDIT_SEQ_INDEX, &msg);
240
241     defwndproc_counter++;
242     ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
243     defwndproc_counter--;
244     return ret;
245 }
246
247 static HWND create_edit_control(void)
248 {
249     struct subclass_info *info;
250     RECT rect;
251
252     info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
253     if (!info)
254         return NULL;
255
256     GetClientRect(parent_wnd, &rect);
257     edit = CreateWindowExA(0, "EDIT", NULL, WS_CHILD | WS_BORDER | WS_VISIBLE,
258                            0, 0, rect.right, rect.bottom,
259                            parent_wnd, NULL, GetModuleHandleA(NULL), NULL);
260     if (!edit)
261     {
262         HeapFree(GetProcessHeap(), 0, info);
263         return NULL;
264     }
265
266     info->oldproc = (WNDPROC)SetWindowLongPtrA(edit, GWLP_WNDPROC,
267                                             (LONG_PTR)edit_subclass_proc);
268     SetWindowLongPtrA(edit, GWLP_USERDATA, (LONG_PTR)info);
269
270     return edit;
271 }
272
273 static LRESULT WINAPI updown_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
274 {
275     struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
276     static LONG defwndproc_counter = 0;
277     LRESULT ret;
278     struct message msg;
279
280     trace("updown: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
281
282     msg.message = message;
283     msg.flags = sent|wparam|lparam;
284     if (defwndproc_counter) msg.flags |= defwinproc;
285     msg.wParam = wParam;
286     msg.lParam = lParam;
287     add_message(sequences, UPDOWN_SEQ_INDEX, &msg);
288
289     defwndproc_counter++;
290     ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
291     defwndproc_counter--;
292
293     return ret;
294 }
295
296 static HWND create_updown_control(DWORD style)
297 {
298     struct subclass_info *info;
299     HWND updown;
300     RECT rect;
301
302     info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
303     if (!info)
304         return NULL;
305
306     GetClientRect(parent_wnd, &rect);
307     updown = CreateUpDownControl(WS_CHILD | WS_BORDER | WS_VISIBLE | UDS_ALIGNRIGHT | style,
308                                  0, 0, rect.right, rect.bottom, parent_wnd, 1, GetModuleHandleA(NULL), edit,
309                                  100, 0, 50);
310     if (!updown)
311     {
312         HeapFree(GetProcessHeap(), 0, info);
313         return NULL;
314     }
315
316     info->oldproc = (WNDPROC)SetWindowLongPtrA(updown, GWLP_WNDPROC,
317                                             (LONG_PTR)updown_subclass_proc);
318     SetWindowLongPtrA(updown, GWLP_USERDATA, (LONG_PTR)info);
319
320     return updown;
321 }
322
323 static void test_updown_pos(void)
324 {
325     HWND updown;
326     int r;
327
328     updown = create_updown_control(0);
329
330     flush_sequences(sequences, NUM_MSG_SEQUENCES);
331
332     /* Set Range from 0 to 100 */
333     SendMessage(updown, UDM_SETRANGE, 0 , MAKELONG(100,0) );
334     r = SendMessage(updown, UDM_GETRANGE, 0,0);
335     expect(100,LOWORD(r));
336     expect(0,HIWORD(r));
337
338     /* Set the position to 5, return is not checked as it was set before func call */
339     SendMessage(updown, UDM_SETPOS, 0 , MAKELONG(5,0) );
340     /* Since UDM_SETBUDDYINT was not set at creation HIWORD(r) will always be 1 as a return from UDM_GETPOS */
341     /* Get the position, which should be 5 */
342     r = SendMessage(updown, UDM_GETPOS, 0 , 0 );
343     expect(5,LOWORD(r));
344     expect(1,HIWORD(r));
345
346     /* Set the position to 0, return should be 5 */
347     r = SendMessage(updown, UDM_SETPOS, 0 , MAKELONG(0,0) );
348     expect(5,r);
349     /* Get the position, which should be 0 */
350     r = SendMessage(updown, UDM_GETPOS, 0 , 0 );
351     expect(0,LOWORD(r));
352     expect(1,HIWORD(r));
353
354     /* Set the position to -1, return should be 0 */
355     r = SendMessage(updown, UDM_SETPOS, 0 , MAKELONG(-1,0) );
356     expect(0,r);
357     /* Get the position, which should be 0 */
358     r = SendMessage(updown, UDM_GETPOS, 0 , 0 );
359     expect(0,LOWORD(r));
360     expect(1,HIWORD(r));
361
362     /* Set the position to 100, return should be 0 */
363     r = SendMessage(updown, UDM_SETPOS, 0 , MAKELONG(100,0) );
364     expect(0,r);
365     /* Get the position, which should be 100 */
366     r = SendMessage(updown, UDM_GETPOS, 0 , 0 );
367     expect(100,LOWORD(r));
368     expect(1,HIWORD(r));
369
370     /* Set the position to 101, return should be 100 */
371     r = SendMessage(updown, UDM_SETPOS, 0 , MAKELONG(101,0) );
372     expect(100,r);
373     /* Get the position, which should be 100 */
374     r = SendMessage(updown, UDM_GETPOS, 0 , 0 );
375     expect(100,LOWORD(r));
376     expect(1,HIWORD(r));
377
378     ok_sequence(sequences, UPDOWN_SEQ_INDEX, test_updown_pos_seq , "test updown pos", FALSE);
379
380     DestroyWindow(updown);
381 }
382
383 static void test_updown_pos32(void)
384 {
385     HWND updown;
386     int r;
387     int low, high;
388
389     updown = create_updown_control(0);
390
391     flush_sequences(sequences, NUM_MSG_SEQUENCES);
392
393     /* Set the position to 0 to 1000 */
394     SendMessage(updown, UDM_SETRANGE32, 0 , 1000 );
395
396     low = high = -1;
397     r = SendMessage(updown, UDM_GETRANGE32, (WPARAM) &low , (LPARAM) &high );
398     if (low == -1)
399     {
400         win_skip("UDM_SETRANGE32/UDM_GETRANGE32 not available\n");
401         DestroyWindow(updown);
402         return;
403     }
404
405     expect(0,low);
406     expect(1000,high);
407
408     /* Set position to 500 */
409     r = SendMessage(updown, UDM_SETPOS32, 0 , 500 );
410     if (!r)
411     {
412         win_skip("UDM_SETPOS32 and UDM_GETPOS32 need 5.80\n");
413         DestroyWindow(updown);
414         return;
415     }
416     expect(50,r);
417
418     /* Since UDM_SETBUDDYINT was not set at creation bRet will always be true as a return from UDM_GETPOS32 */
419
420     r = SendMessage(updown, UDM_GETPOS32, 0 , (LPARAM) &high );
421     expect(500,r);
422     expect(1,high);
423
424     /* Set position to 0, return should be 500 */
425     r = SendMessage(updown, UDM_SETPOS32, 0 , 0 );
426     expect(500,r);
427     r = SendMessage(updown, UDM_GETPOS32, 0 , (LPARAM) &high );
428     expect(0,r);
429     expect(1,high);
430
431     /* Set position to -1 which should become 0, return should be 0 */
432     r = SendMessage(updown, UDM_SETPOS32, 0 , -1 );
433     expect(0,r);
434     r = SendMessage(updown, UDM_GETPOS32, 0 , (LPARAM) &high );
435     expect(0,r);
436     expect(1,high);
437
438     /* Set position to 1000, return should be 0 */
439     r = SendMessage(updown, UDM_SETPOS32, 0 , 1000 );
440     expect(0,r);
441     r = SendMessage(updown, UDM_GETPOS32, 0 , (LPARAM) &high );
442     expect(1000,r);
443     expect(1,high);
444
445     /* Set position to 1001 which should become 1000, return should be 1000 */
446     r = SendMessage(updown, UDM_SETPOS32, 0 , 1001 );
447     expect(1000,r);
448     r = SendMessage(updown, UDM_GETPOS32, 0 , (LPARAM) &high );
449     expect(1000,r);
450     expect(1,high);
451
452     ok_sequence(sequences, UPDOWN_SEQ_INDEX, test_updown_pos32_seq, "test updown pos32", FALSE);
453
454     DestroyWindow(updown);
455 }
456
457 static void test_updown_buddy(void)
458 {
459     HWND updown, buddyReturn;
460
461     updown = create_updown_control(0);
462
463     flush_sequences(sequences, NUM_MSG_SEQUENCES);
464
465     buddyReturn = (HWND)SendMessage(updown, UDM_GETBUDDY, 0 , 0 );
466     ok(buddyReturn == edit, "Expected edit handle\n");
467
468     buddyReturn = (HWND)SendMessage(updown, UDM_SETBUDDY, (WPARAM) edit, 0);
469     ok(buddyReturn == edit, "Expected edit handle\n");
470
471     buddyReturn = (HWND)SendMessage(updown, UDM_GETBUDDY, 0 , 0 );
472     ok(buddyReturn == edit, "Expected edit handle\n");
473
474     ok_sequence(sequences, UPDOWN_SEQ_INDEX, test_updown_buddy_seq, "test updown buddy", TRUE);
475     ok_sequence(sequences, EDIT_SEQ_INDEX, add_updown_with_edit_seq, "test updown buddy_edit", FALSE);
476
477     DestroyWindow(updown);
478 }
479
480 static void test_updown_base(void)
481 {
482     HWND updown;
483     int r;
484     CHAR text[10];
485
486     updown = create_updown_control(0);
487
488     flush_sequences(sequences, NUM_MSG_SEQUENCES);
489
490     SendMessage(updown, UDM_SETBASE, 10 , 0);
491     r = SendMessage(updown, UDM_GETBASE, 0 , 0);
492     expect(10,r);
493
494     /* Set base to an invalid value, should return 0 and stay at 10 */
495     r = SendMessage(updown, UDM_SETBASE, 80 , 0);
496     expect(0,r);
497     r = SendMessage(updown, UDM_GETBASE, 0 , 0);
498     expect(10,r);
499
500     /* Set base to 16 now, should get 16 as the return */
501     r = SendMessage(updown, UDM_SETBASE, 16 , 0);
502     expect(10,r);
503     r = SendMessage(updown, UDM_GETBASE, 0 , 0);
504     expect(16,r);
505
506     /* Set base to an invalid value, should return 0 and stay at 16 */
507     r = SendMessage(updown, UDM_SETBASE, 80 , 0);
508     expect(0,r);
509     r = SendMessage(updown, UDM_GETBASE, 0 , 0);
510     expect(16,r);
511
512     /* Set base back to 10, return should be 16 */
513     r = SendMessage(updown, UDM_SETBASE, 10 , 0);
514     expect(16,r);
515     r = SendMessage(updown, UDM_GETBASE, 0 , 0);
516     expect(10,r);
517
518     ok_sequence(sequences, UPDOWN_SEQ_INDEX, test_updown_base_seq, "test updown base", FALSE);
519
520     DestroyWindow(updown);
521
522     /* switch base with buddy attached */
523     updown = create_updown_control(UDS_SETBUDDYINT);
524
525     r = SendMessage(updown, UDM_SETPOS, 0, 10);
526     expect(50, r);
527
528     GetWindowTextA(edit, text, sizeof(text)/sizeof(CHAR));
529     ok(lstrcmpA(text, "10") == 0, "Expected '10', got '%s'\n", text);
530
531     r = SendMessage(updown, UDM_SETBASE, 16, 0);
532     expect(10, r);
533
534     GetWindowTextA(edit, text, sizeof(text)/sizeof(CHAR));
535     /* FIXME: currently hex output isn't properly formatted, but for this
536        test only change from initial text matters */
537     ok(lstrcmpA(text, "10") != 0, "Expected '0x000A', got '%s'\n", text);
538
539     DestroyWindow(updown);
540 }
541
542 static void test_updown_unicode(void)
543 {
544     HWND updown;
545     int r;
546
547     updown = create_updown_control(0);
548
549     flush_sequences(sequences, NUM_MSG_SEQUENCES);
550
551     /* Set it to ANSI, don't check return as we don't know previous state */
552     SendMessage(updown, UDM_SETUNICODEFORMAT, 0 , 0);
553     r = SendMessage(updown, UDM_GETUNICODEFORMAT, 0 , 0);
554     expect(0,r);
555
556     /* Now set it to Unicode format */
557     r = SendMessage(updown, UDM_SETUNICODEFORMAT, 1 , 0);
558     expect(0,r);
559     r = SendMessage(updown, UDM_GETUNICODEFORMAT, 0 , 0);
560     if (!r)
561     {
562         win_skip("UDM_SETUNICODEFORMAT not available\n");
563         DestroyWindow(updown);
564         return;
565     }
566     expect(1,r);
567
568     /* And now set it back to ANSI */
569     r = SendMessage(updown, UDM_SETUNICODEFORMAT, 0 , 0);
570     expect(1,r);
571     r = SendMessage(updown, UDM_GETUNICODEFORMAT, 0 , 0);
572     expect(0,r);
573
574     ok_sequence(sequences, UPDOWN_SEQ_INDEX, test_updown_unicode_seq, "test updown unicode", FALSE);
575
576     DestroyWindow(updown);
577 }
578
579 static void test_updown_create(void)
580 {
581     CHAR text[MAX_PATH];
582     HWND updown;
583
584     flush_sequences(sequences, NUM_MSG_SEQUENCES);
585
586     updown = create_updown_control(0);
587     ok(updown != NULL, "Failed to create updown control\n");
588     ok_sequence(sequences, PARENT_SEQ_INDEX, add_updown_to_parent_seq, "add updown control to parent", TRUE);
589     ok_sequence(sequences, EDIT_SEQ_INDEX, add_updown_with_edit_seq, "add updown control with edit", FALSE);
590
591     flush_sequences(sequences, NUM_MSG_SEQUENCES);
592
593     GetWindowTextA(edit, text, MAX_PATH);
594     ok(lstrlenA(text) == 0, "Expected empty string\n");
595     ok_sequence(sequences, EDIT_SEQ_INDEX, get_edit_text_seq, "get edit text", FALSE);
596
597     DestroyWindow(updown);
598 }
599
600 static void test_UDS_SETBUDDYINT(void)
601 {
602     HWND updown;
603     DWORD style, ret;
604     CHAR text[10];
605
606     /* cleanup buddy */
607     text[0] = '\0';
608     SetWindowTextA(edit, text);
609
610     /* creating without UDS_SETBUDDYINT */
611     updown = create_updown_control(0);
612     /* try to set UDS_SETBUDDYINT after creation */
613     style = GetWindowLongA(updown, GWL_STYLE);
614     SetWindowLongA(updown, GWL_STYLE, style | UDS_SETBUDDYINT);
615     style = GetWindowLongA(updown, GWL_STYLE);
616     ok(style & UDS_SETBUDDYINT, "Expected UDS_SETBUDDY to be set\n");
617     SendMessage(updown, UDM_SETPOS, 0, 20);
618     GetWindowTextA(edit, text, sizeof(text)/sizeof(CHAR));
619     ok(lstrlenA(text) == 0, "Expected empty string\n");
620     DestroyWindow(updown);
621
622     /* creating with UDS_SETBUDDYINT */
623     updown = create_updown_control(UDS_SETBUDDYINT);
624     GetWindowTextA(edit, text, sizeof(text)/sizeof(CHAR));
625     /* 50 is initial value here */
626     ok(lstrcmpA(text, "50") == 0, "Expected '50', got '%s'\n", text);
627     /* now remove style flag */
628     style = GetWindowLongA(updown, GWL_STYLE);
629     SetWindowLongA(updown, GWL_STYLE, style & ~UDS_SETBUDDYINT);
630     SendMessage(updown, UDM_SETPOS, 0, 20);
631     GetWindowTextA(edit, text, sizeof(text)/sizeof(CHAR));
632     ok(lstrcmpA(text, "20") == 0, "Expected '20', got '%s'\n", text);
633     /* set edit text directly, check position */
634     strcpy(text, "10");
635     SetWindowTextA(edit, text);
636     ret = SendMessageA(updown, UDM_GETPOS, 0, 0);
637     expect(10, ret);
638     strcpy(text, "11");
639     SetWindowTextA(edit, text);
640     ret = SendMessageA(updown, UDM_GETPOS, 0, 0);
641     expect(11, LOWORD(ret));
642     expect(0,  HIWORD(ret));
643     /* set to invalid value */
644     strcpy(text, "21st");
645     SetWindowTextA(edit, text);
646     ret = SendMessageA(updown, UDM_GETPOS, 0, 0);
647     expect(11, LOWORD(ret));
648     expect(TRUE, HIWORD(ret));
649     /* set style back */
650     style = GetWindowLongA(updown, GWL_STYLE);
651     SetWindowLongA(updown, GWL_STYLE, style | UDS_SETBUDDYINT);
652     SendMessage(updown, UDM_SETPOS, 0, 30);
653     GetWindowTextA(edit, text, sizeof(text)/sizeof(CHAR));
654     ok(lstrcmpA(text, "30") == 0, "Expected '30', got '%s'\n", text);
655     DestroyWindow(updown);
656 }
657
658 START_TEST(updown)
659 {
660     InitCommonControls();
661     init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
662
663     parent_wnd = create_parent_window();
664     ok(parent_wnd != NULL, "Failed to create parent window!\n");
665     edit = create_edit_control();
666     ok(edit != NULL, "Failed to create edit control\n");
667
668     test_updown_create();
669     test_updown_pos();
670     test_updown_pos32();
671     test_updown_buddy();
672     test_updown_base();
673     test_updown_unicode();
674     test_UDS_SETBUDDYINT();
675
676     DestroyWindow(edit);
677     DestroyWindow(parent_wnd);
678 }