comctl32/tests: Add ability to create any number of edit buddies.
[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, g_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 static LRESULT WINAPI edit_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
221 {
222     WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
223     static LONG defwndproc_counter = 0;
224     LRESULT ret;
225     struct message msg;
226
227     trace("edit: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
228
229     msg.message = message;
230     msg.flags = sent|wparam|lparam;
231     if (defwndproc_counter) msg.flags |= defwinproc;
232     msg.wParam = wParam;
233     msg.lParam = lParam;
234     add_message(sequences, EDIT_SEQ_INDEX, &msg);
235
236     defwndproc_counter++;
237     ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
238     defwndproc_counter--;
239     return ret;
240 }
241
242 static HWND create_edit_control(void)
243 {
244     WNDPROC oldproc;
245     HWND hwnd;
246     RECT rect;
247
248     GetClientRect(parent_wnd, &rect);
249     hwnd = CreateWindowExA(0, WC_EDITA, NULL, WS_CHILD | WS_BORDER | WS_VISIBLE,
250                            0, 0, rect.right, rect.bottom,
251                            parent_wnd, NULL, GetModuleHandleA(NULL), NULL);
252     if (!hwnd) return NULL;
253
254     oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
255                                          (LONG_PTR)edit_subclass_proc);
256     SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
257
258     return hwnd;
259 }
260
261 static LRESULT WINAPI updown_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
262 {
263     WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
264     static LONG defwndproc_counter = 0;
265     LRESULT ret;
266     struct message msg;
267
268     trace("updown: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
269
270     msg.message = message;
271     msg.flags = sent|wparam|lparam;
272     if (defwndproc_counter) msg.flags |= defwinproc;
273     msg.wParam = wParam;
274     msg.lParam = lParam;
275     add_message(sequences, UPDOWN_SEQ_INDEX, &msg);
276
277     defwndproc_counter++;
278     ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
279     defwndproc_counter--;
280
281     return ret;
282 }
283
284 static HWND create_updown_control(DWORD style, HWND buddy)
285 {
286     WNDPROC oldproc;
287     HWND updown;
288     RECT rect;
289
290     GetClientRect(parent_wnd, &rect);
291     updown = CreateUpDownControl(WS_CHILD | WS_BORDER | WS_VISIBLE | style,
292                                  0, 0, rect.right, rect.bottom, parent_wnd, 1, GetModuleHandleA(NULL), buddy,
293                                  100, 0, 50);
294     if (!updown) return NULL;
295
296     oldproc = (WNDPROC)SetWindowLongPtrA(updown, GWLP_WNDPROC,
297                                          (LONG_PTR)updown_subclass_proc);
298     SetWindowLongPtrA(updown, GWLP_USERDATA, (LONG_PTR)oldproc);
299
300     return updown;
301 }
302
303 static void test_updown_pos(void)
304 {
305     HWND updown;
306     int r;
307
308     updown = create_updown_control(UDS_ALIGNRIGHT, g_edit);
309
310     flush_sequences(sequences, NUM_MSG_SEQUENCES);
311
312     /* Set Range from 0 to 100 */
313     SendMessage(updown, UDM_SETRANGE, 0 , MAKELONG(100,0) );
314     r = SendMessage(updown, UDM_GETRANGE, 0,0);
315     expect(100,LOWORD(r));
316     expect(0,HIWORD(r));
317
318     /* Set the position to 5, return is not checked as it was set before func call */
319     SendMessage(updown, UDM_SETPOS, 0 , MAKELONG(5,0) );
320     /* Since UDM_SETBUDDYINT was not set at creation HIWORD(r) will always be 1 as a return from UDM_GETPOS */
321     /* Get the position, which should be 5 */
322     r = SendMessage(updown, UDM_GETPOS, 0 , 0 );
323     expect(5,LOWORD(r));
324     expect(1,HIWORD(r));
325
326     /* Set the position to 0, return should be 5 */
327     r = SendMessage(updown, UDM_SETPOS, 0 , MAKELONG(0,0) );
328     expect(5,r);
329     /* Get the position, which should be 0 */
330     r = SendMessage(updown, UDM_GETPOS, 0 , 0 );
331     expect(0,LOWORD(r));
332     expect(1,HIWORD(r));
333
334     /* Set the position to -1, return should be 0 */
335     r = SendMessage(updown, UDM_SETPOS, 0 , MAKELONG(-1,0) );
336     expect(0,r);
337     /* Get the position, which should be 0 */
338     r = SendMessage(updown, UDM_GETPOS, 0 , 0 );
339     expect(0,LOWORD(r));
340     expect(1,HIWORD(r));
341
342     /* Set the position to 100, return should be 0 */
343     r = SendMessage(updown, UDM_SETPOS, 0 , MAKELONG(100,0) );
344     expect(0,r);
345     /* Get the position, which should be 100 */
346     r = SendMessage(updown, UDM_GETPOS, 0 , 0 );
347     expect(100,LOWORD(r));
348     expect(1,HIWORD(r));
349
350     /* Set the position to 101, return should be 100 */
351     r = SendMessage(updown, UDM_SETPOS, 0 , MAKELONG(101,0) );
352     expect(100,r);
353     /* Get the position, which should be 100 */
354     r = SendMessage(updown, UDM_GETPOS, 0 , 0 );
355     expect(100,LOWORD(r));
356     expect(1,HIWORD(r));
357
358     ok_sequence(sequences, UPDOWN_SEQ_INDEX, test_updown_pos_seq , "test updown pos", FALSE);
359
360     DestroyWindow(updown);
361 }
362
363 static void test_updown_pos32(void)
364 {
365     HWND updown;
366     int r;
367     int low, high;
368
369     updown = create_updown_control(UDS_ALIGNRIGHT, g_edit);
370
371     flush_sequences(sequences, NUM_MSG_SEQUENCES);
372
373     /* Set the position to 0 to 1000 */
374     SendMessage(updown, UDM_SETRANGE32, 0 , 1000 );
375
376     low = high = -1;
377     r = SendMessage(updown, UDM_GETRANGE32, (WPARAM) &low , (LPARAM) &high );
378     if (low == -1)
379     {
380         win_skip("UDM_SETRANGE32/UDM_GETRANGE32 not available\n");
381         DestroyWindow(updown);
382         return;
383     }
384
385     expect(0,low);
386     expect(1000,high);
387
388     /* Set position to 500 */
389     r = SendMessage(updown, UDM_SETPOS32, 0 , 500 );
390     if (!r)
391     {
392         win_skip("UDM_SETPOS32 and UDM_GETPOS32 need 5.80\n");
393         DestroyWindow(updown);
394         return;
395     }
396     expect(50,r);
397
398     /* Since UDM_SETBUDDYINT was not set at creation bRet will always be true as a return from UDM_GETPOS32 */
399
400     r = SendMessage(updown, UDM_GETPOS32, 0 , (LPARAM) &high );
401     expect(500,r);
402     expect(1,high);
403
404     /* Set position to 0, return should be 500 */
405     r = SendMessage(updown, UDM_SETPOS32, 0 , 0 );
406     expect(500,r);
407     r = SendMessage(updown, UDM_GETPOS32, 0 , (LPARAM) &high );
408     expect(0,r);
409     expect(1,high);
410
411     /* Set position to -1 which should become 0, return should be 0 */
412     r = SendMessage(updown, UDM_SETPOS32, 0 , -1 );
413     expect(0,r);
414     r = SendMessage(updown, UDM_GETPOS32, 0 , (LPARAM) &high );
415     expect(0,r);
416     expect(1,high);
417
418     /* Set position to 1000, return should be 0 */
419     r = SendMessage(updown, UDM_SETPOS32, 0 , 1000 );
420     expect(0,r);
421     r = SendMessage(updown, UDM_GETPOS32, 0 , (LPARAM) &high );
422     expect(1000,r);
423     expect(1,high);
424
425     /* Set position to 1001 which should become 1000, return should be 1000 */
426     r = SendMessage(updown, UDM_SETPOS32, 0 , 1001 );
427     expect(1000,r);
428     r = SendMessage(updown, UDM_GETPOS32, 0 , (LPARAM) &high );
429     expect(1000,r);
430     expect(1,high);
431
432     ok_sequence(sequences, UPDOWN_SEQ_INDEX, test_updown_pos32_seq, "test updown pos32", FALSE);
433
434     DestroyWindow(updown);
435 }
436
437 static void test_updown_buddy(void)
438 {
439     HWND updown, buddyReturn;
440
441     updown = create_updown_control(UDS_ALIGNRIGHT, g_edit);
442
443     flush_sequences(sequences, NUM_MSG_SEQUENCES);
444
445     buddyReturn = (HWND)SendMessage(updown, UDM_GETBUDDY, 0 , 0 );
446     ok(buddyReturn == g_edit, "Expected edit handle\n");
447
448     buddyReturn = (HWND)SendMessage(updown, UDM_SETBUDDY, (WPARAM) g_edit, 0);
449     ok(buddyReturn == g_edit, "Expected edit handle\n");
450
451     buddyReturn = (HWND)SendMessage(updown, UDM_GETBUDDY, 0 , 0 );
452     ok(buddyReturn == g_edit, "Expected edit handle\n");
453
454     ok_sequence(sequences, UPDOWN_SEQ_INDEX, test_updown_buddy_seq, "test updown buddy", TRUE);
455     ok_sequence(sequences, EDIT_SEQ_INDEX, add_updown_with_edit_seq, "test updown buddy_edit", FALSE);
456
457     DestroyWindow(updown);
458 }
459
460 static void test_updown_base(void)
461 {
462     HWND updown;
463     int r;
464     CHAR text[10];
465
466     updown = create_updown_control(UDS_ALIGNRIGHT, g_edit);
467
468     flush_sequences(sequences, NUM_MSG_SEQUENCES);
469
470     SendMessage(updown, UDM_SETBASE, 10 , 0);
471     r = SendMessage(updown, UDM_GETBASE, 0 , 0);
472     expect(10,r);
473
474     /* Set base to an invalid value, should return 0 and stay at 10 */
475     r = SendMessage(updown, UDM_SETBASE, 80 , 0);
476     expect(0,r);
477     r = SendMessage(updown, UDM_GETBASE, 0 , 0);
478     expect(10,r);
479
480     /* Set base to 16 now, should get 16 as the return */
481     r = SendMessage(updown, UDM_SETBASE, 16 , 0);
482     expect(10,r);
483     r = SendMessage(updown, UDM_GETBASE, 0 , 0);
484     expect(16,r);
485
486     /* Set base to an invalid value, should return 0 and stay at 16 */
487     r = SendMessage(updown, UDM_SETBASE, 80 , 0);
488     expect(0,r);
489     r = SendMessage(updown, UDM_GETBASE, 0 , 0);
490     expect(16,r);
491
492     /* Set base back to 10, return should be 16 */
493     r = SendMessage(updown, UDM_SETBASE, 10 , 0);
494     expect(16,r);
495     r = SendMessage(updown, UDM_GETBASE, 0 , 0);
496     expect(10,r);
497
498     ok_sequence(sequences, UPDOWN_SEQ_INDEX, test_updown_base_seq, "test updown base", FALSE);
499
500     DestroyWindow(updown);
501
502     /* switch base with buddy attached */
503     updown = create_updown_control(UDS_SETBUDDYINT | UDS_ALIGNRIGHT, g_edit);
504
505     r = SendMessage(updown, UDM_SETPOS, 0, 10);
506     expect(50, r);
507
508     GetWindowTextA(g_edit, text, sizeof(text)/sizeof(CHAR));
509     ok(lstrcmpA(text, "10") == 0, "Expected '10', got '%s'\n", text);
510
511     r = SendMessage(updown, UDM_SETBASE, 16, 0);
512     expect(10, r);
513
514     GetWindowTextA(g_edit, text, sizeof(text)/sizeof(CHAR));
515     /* FIXME: currently hex output isn't properly formatted, but for this
516        test only change from initial text matters */
517     ok(lstrcmpA(text, "10") != 0, "Expected '0x000A', got '%s'\n", text);
518
519     DestroyWindow(updown);
520 }
521
522 static void test_updown_unicode(void)
523 {
524     HWND updown;
525     int r;
526
527     updown = create_updown_control(UDS_ALIGNRIGHT, g_edit);
528
529     flush_sequences(sequences, NUM_MSG_SEQUENCES);
530
531     /* Set it to ANSI, don't check return as we don't know previous state */
532     SendMessage(updown, UDM_SETUNICODEFORMAT, 0 , 0);
533     r = SendMessage(updown, UDM_GETUNICODEFORMAT, 0 , 0);
534     expect(0,r);
535
536     /* Now set it to Unicode format */
537     r = SendMessage(updown, UDM_SETUNICODEFORMAT, 1 , 0);
538     expect(0,r);
539     r = SendMessage(updown, UDM_GETUNICODEFORMAT, 0 , 0);
540     if (!r)
541     {
542         win_skip("UDM_SETUNICODEFORMAT not available\n");
543         DestroyWindow(updown);
544         return;
545     }
546     expect(1,r);
547
548     /* And now set it back to ANSI */
549     r = SendMessage(updown, UDM_SETUNICODEFORMAT, 0 , 0);
550     expect(1,r);
551     r = SendMessage(updown, UDM_GETUNICODEFORMAT, 0 , 0);
552     expect(0,r);
553
554     ok_sequence(sequences, UPDOWN_SEQ_INDEX, test_updown_unicode_seq, "test updown unicode", FALSE);
555
556     DestroyWindow(updown);
557 }
558
559 static void test_updown_create(void)
560 {
561     CHAR text[MAX_PATH];
562     HWND updown;
563     RECT r;
564
565     flush_sequences(sequences, NUM_MSG_SEQUENCES);
566
567     updown = create_updown_control(UDS_ALIGNRIGHT, g_edit);
568     ok(updown != NULL, "Failed to create updown control\n");
569     ok_sequence(sequences, PARENT_SEQ_INDEX, add_updown_to_parent_seq, "add updown control to parent", TRUE);
570     ok_sequence(sequences, EDIT_SEQ_INDEX, add_updown_with_edit_seq, "add updown control with edit", FALSE);
571
572     flush_sequences(sequences, NUM_MSG_SEQUENCES);
573
574     GetWindowTextA(g_edit, text, MAX_PATH);
575     ok(lstrlenA(text) == 0, "Expected empty string\n");
576     ok_sequence(sequences, EDIT_SEQ_INDEX, get_edit_text_seq, "get edit text", FALSE);
577
578     DestroyWindow(updown);
579
580     /* create with zero width */
581     updown = CreateWindowA (UPDOWN_CLASSA, 0, WS_CHILD | WS_BORDER | WS_VISIBLE, 0, 0, 0, 0,
582                    parent_wnd, (HMENU)(DWORD_PTR)1, GetModuleHandleA(NULL), 0);
583     ok(updown != NULL, "Failed to create updown control\n");
584     r.right = 0;
585     GetClientRect(updown, &r);
586     ok(r.right > 0, "Expected default width, got %d\n", r.right);
587     DestroyWindow(updown);
588     /* create with really small width */
589     updown = CreateWindowA (UPDOWN_CLASSA, 0, WS_CHILD | WS_BORDER | WS_VISIBLE, 0, 0, 2, 0,
590                    parent_wnd, (HMENU)(DWORD_PTR)1, GetModuleHandleA(NULL), 0);
591     ok(updown != NULL, "Failed to create updown control\n");
592     r.right = 0;
593     GetClientRect(updown, &r);
594     ok(r.right != 2 && r.right > 0, "Expected default width, got %d\n", r.right);
595     DestroyWindow(updown);
596     /* create with width greater than default */
597     updown = CreateWindowA (UPDOWN_CLASSA, 0, WS_CHILD | WS_BORDER | WS_VISIBLE, 0, 0, 100, 0,
598                    parent_wnd, (HMENU)(DWORD_PTR)1, GetModuleHandleA(NULL), 0);
599     ok(updown != NULL, "Failed to create updown control\n");
600     r.right = 0;
601     GetClientRect(updown, &r);
602     ok(r.right < 100 && r.right > 0, "Expected default width, got %d\n", r.right);
603     DestroyWindow(updown);
604     /* create with zero height, UDS_HORZ */
605     updown = CreateWindowA (UPDOWN_CLASSA, 0, UDS_HORZ | WS_CHILD | WS_BORDER | WS_VISIBLE, 0, 0, 0, 0,
606                    parent_wnd, (HMENU)(DWORD_PTR)1, GetModuleHandleA(NULL), 0);
607     ok(updown != NULL, "Failed to create updown control\n");
608     r.bottom = 0;
609     GetClientRect(updown, &r);
610     ok(r.bottom == 0, "Expected zero height, got %d\n", r.bottom);
611     DestroyWindow(updown);
612     /* create with really small height, UDS_HORZ */
613     updown = CreateWindowA (UPDOWN_CLASSA, 0, UDS_HORZ | WS_CHILD | WS_BORDER | WS_VISIBLE, 0, 0, 0, 2,
614                    parent_wnd, (HMENU)(DWORD_PTR)1, GetModuleHandleA(NULL), 0);
615     ok(updown != NULL, "Failed to create updown control\n");
616     r.bottom = 0;
617     GetClientRect(updown, &r);
618     ok(r.bottom == 0, "Expected zero height, got %d\n", r.bottom);
619     DestroyWindow(updown);
620     /* create with height greater than default, UDS_HORZ */
621     updown = CreateWindowA (UPDOWN_CLASSA, 0, UDS_HORZ | WS_CHILD | WS_BORDER | WS_VISIBLE, 0, 0, 0, 100,
622                    parent_wnd, (HMENU)(DWORD_PTR)1, GetModuleHandleA(NULL), 0);
623     ok(updown != NULL, "Failed to create updown control\n");
624     r.bottom = 0;
625     GetClientRect(updown, &r);
626     ok(r.bottom < 100 && r.bottom > 0, "Expected default height, got %d\n", r.bottom);
627     DestroyWindow(updown);
628 }
629
630 static void test_UDS_SETBUDDYINT(void)
631 {
632     HWND updown;
633     DWORD style, ret;
634     CHAR text[10];
635
636     /* cleanup buddy */
637     text[0] = '\0';
638     SetWindowTextA(g_edit, text);
639
640     /* creating without UDS_SETBUDDYINT */
641     updown = create_updown_control(UDS_ALIGNRIGHT, g_edit);
642     /* try to set UDS_SETBUDDYINT after creation */
643     style = GetWindowLongA(updown, GWL_STYLE);
644     SetWindowLongA(updown, GWL_STYLE, style | UDS_SETBUDDYINT);
645     style = GetWindowLongA(updown, GWL_STYLE);
646     ok(style & UDS_SETBUDDYINT, "Expected UDS_SETBUDDY to be set\n");
647     SendMessage(updown, UDM_SETPOS, 0, 20);
648     GetWindowTextA(g_edit, text, sizeof(text)/sizeof(CHAR));
649     ok(lstrlenA(text) == 0, "Expected empty string\n");
650     DestroyWindow(updown);
651
652     /* creating with UDS_SETBUDDYINT */
653     updown = create_updown_control(UDS_SETBUDDYINT | UDS_ALIGNRIGHT, g_edit);
654     GetWindowTextA(g_edit, text, sizeof(text)/sizeof(CHAR));
655     /* 50 is initial value here */
656     ok(lstrcmpA(text, "50") == 0, "Expected '50', got '%s'\n", text);
657     /* now remove style flag */
658     style = GetWindowLongA(updown, GWL_STYLE);
659     SetWindowLongA(updown, GWL_STYLE, style & ~UDS_SETBUDDYINT);
660     SendMessage(updown, UDM_SETPOS, 0, 20);
661     GetWindowTextA(g_edit, text, sizeof(text)/sizeof(CHAR));
662     ok(lstrcmpA(text, "20") == 0, "Expected '20', got '%s'\n", text);
663     /* set edit text directly, check position */
664     strcpy(text, "10");
665     SetWindowTextA(g_edit, text);
666     ret = SendMessageA(updown, UDM_GETPOS, 0, 0);
667     expect(10, ret);
668     strcpy(text, "11");
669     SetWindowTextA(g_edit, text);
670     ret = SendMessageA(updown, UDM_GETPOS, 0, 0);
671     expect(11, LOWORD(ret));
672     expect(0,  HIWORD(ret));
673     /* set to invalid value */
674     strcpy(text, "21st");
675     SetWindowTextA(g_edit, text);
676     ret = SendMessageA(updown, UDM_GETPOS, 0, 0);
677     expect(11, LOWORD(ret));
678     expect(TRUE, HIWORD(ret));
679     /* set style back */
680     style = GetWindowLongA(updown, GWL_STYLE);
681     SetWindowLongA(updown, GWL_STYLE, style | UDS_SETBUDDYINT);
682     SendMessage(updown, UDM_SETPOS, 0, 30);
683     GetWindowTextA(g_edit, text, sizeof(text)/sizeof(CHAR));
684     ok(lstrcmpA(text, "30") == 0, "Expected '30', got '%s'\n", text);
685     DestroyWindow(updown);
686 }
687
688 START_TEST(updown)
689 {
690     InitCommonControls();
691     init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
692
693     parent_wnd = create_parent_window();
694     ok(parent_wnd != NULL, "Failed to create parent window!\n");
695     g_edit = create_edit_control();
696     ok(g_edit != NULL, "Failed to create edit control\n");
697
698     test_updown_create();
699     test_updown_pos();
700     test_updown_pos32();
701     test_updown_buddy();
702     test_updown_base();
703     test_updown_unicode();
704     test_UDS_SETBUDDYINT();
705
706     DestroyWindow(g_edit);
707     DestroyWindow(parent_wnd);
708 }