1c2c66affSColin Finck /* Unit tests for the up-down control 2c2c66affSColin Finck * 3c2c66affSColin Finck * Copyright 2005 C. Scott Ananian 4c2c66affSColin Finck * Copyright (C) 2007 James Hawkins 5c2c66affSColin Finck * Copyright (C) 2007 Leslie Choong 6c2c66affSColin Finck * 7c2c66affSColin Finck * This library is free software; you can redistribute it and/or 8c2c66affSColin Finck * modify it under the terms of the GNU Lesser General Public 9c2c66affSColin Finck * License as published by the Free Software Foundation; either 10c2c66affSColin Finck * version 2.1 of the License, or (at your option) any later version. 11c2c66affSColin Finck * 12c2c66affSColin Finck * This library is distributed in the hope that it will be useful, 13c2c66affSColin Finck * but WITHOUT ANY WARRANTY; without even the implied warranty of 14c2c66affSColin Finck * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15c2c66affSColin Finck * Lesser General Public License for more details. 16c2c66affSColin Finck * 17c2c66affSColin Finck * You should have received a copy of the GNU Lesser General Public 18c2c66affSColin Finck * License along with this library; if not, write to the Free Software 19c2c66affSColin Finck * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 20c2c66affSColin Finck */ 21c2c66affSColin Finck 22c2c66affSColin Finck /* TO TEST: 23c2c66affSColin Finck * - send click messages to the up-down control, check the current position 24c2c66affSColin Finck * - up-down control automatically positions itself next to its buddy window 25c2c66affSColin Finck * - up-down control sets the caption of the buddy window 26c2c66affSColin Finck * - test CreateUpDownControl API 27c2c66affSColin Finck * - check UDS_AUTOBUDDY style, up-down control selects previous window in z-order 28c2c66affSColin Finck * - check UDM_SETBUDDY message 29c2c66affSColin Finck * - check UDM_GETBUDDY message 30c2c66affSColin Finck * - up-down control and buddy control must have the same parent 31c2c66affSColin Finck * - up-down control notifies its parent window when its position changes with UDN_DELTAPOS + WM_VSCROLL or WM_HSCROLL 32c2c66affSColin Finck * - check UDS_ALIGN[LEFT,RIGHT]...check that width of buddy window is decreased 33c2c66affSColin Finck * - check that UDS_SETBUDDYINT sets the caption of the buddy window when it is changed 34c2c66affSColin Finck * - check that the thousands operator is set for large numbers 35c2c66affSColin Finck * - check that the thousands operator is not set with UDS_NOTHOUSANDS 36c2c66affSColin Finck * - check UDS_ARROWKEYS, control subclasses the buddy window so that it processes the keys when it has focus 37c2c66affSColin Finck * - check UDS_HORZ 38c2c66affSColin Finck * - check changing past min/max values 39c2c66affSColin Finck * - check UDS_WRAP wraps values past min/max, incrementing past upper value wraps position to lower value 40c2c66affSColin Finck * - can change control's position, min/max pos, radix 41c2c66affSColin Finck * - check UDM_GETPOS, for up-down control with a buddy window, position is the caption of the buddy window, so change the 42c2c66affSColin Finck * caption of the buddy window then call UDM_GETPOS 43c2c66affSColin Finck * - check UDM_SETRANGE, max can be less than min, so clicking the up arrow decreases the current position 44c2c66affSColin Finck * - more stuff to test 45c2c66affSColin Finck */ 46c2c66affSColin Finck 47284a839dSAmine Khaldi #include "precomp.h" 48c2c66affSColin Finck 49c2c66affSColin Finck #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT)) 50c2c66affSColin Finck 51c2c66affSColin Finck #define NUM_MSG_SEQUENCES 3 52c2c66affSColin Finck #define PARENT_SEQ_INDEX 0 53c2c66affSColin Finck #define EDIT_SEQ_INDEX 1 54c2c66affSColin Finck #define UPDOWN_SEQ_INDEX 2 55c2c66affSColin Finck 56c2c66affSColin Finck #define UPDOWN_ID 0 57c2c66affSColin Finck #define BUDDY_ID 1 58c2c66affSColin Finck 59c2c66affSColin Finck static HWND parent_wnd, g_edit; 60c2c66affSColin Finck 61c2c66affSColin Finck static BOOL (WINAPI *pSetWindowSubclass)(HWND, SUBCLASSPROC, UINT_PTR, DWORD_PTR); 62c2c66affSColin Finck 63c2c66affSColin Finck static struct msg_sequence *sequences[NUM_MSG_SEQUENCES]; 64c2c66affSColin Finck 65c2c66affSColin Finck static const struct message add_updown_with_edit_seq[] = { 66c2c66affSColin Finck { WM_WINDOWPOSCHANGING, sent }, 67c2c66affSColin Finck { WM_NCCALCSIZE, sent|wparam, TRUE }, 68c2c66affSColin Finck { WM_WINDOWPOSCHANGED, sent }, 69c2c66affSColin Finck { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED /*, MAKELONG(91, 75) exact size depends on font */ }, 70c2c66affSColin Finck { 0 } 71c2c66affSColin Finck }; 72c2c66affSColin Finck 73c2c66affSColin Finck static const struct message add_updown_to_parent_seq[] = { 74c2c66affSColin Finck { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY }, 75c2c66affSColin Finck { WM_QUERYUISTATE, sent|optional }, 76c2c66affSColin Finck { WM_PARENTNOTIFY, sent|wparam, MAKELONG(WM_CREATE, WM_CREATE) }, 77c2c66affSColin Finck { 0 } 78c2c66affSColin Finck }; 79c2c66affSColin Finck 80c2c66affSColin Finck static const struct message get_edit_text_seq[] = { 81c2c66affSColin Finck { WM_GETTEXT, sent }, 82c2c66affSColin Finck { 0 } 83c2c66affSColin Finck }; 84c2c66affSColin Finck 85c2c66affSColin Finck static const struct message test_updown_pos_seq[] = { 86c2c66affSColin Finck { UDM_SETRANGE, sent|lparam, 0, MAKELONG(100,0) }, 87c2c66affSColin Finck { UDM_GETRANGE, sent}, 88c2c66affSColin Finck { UDM_SETPOS, sent|lparam, 0, 5}, 89c2c66affSColin Finck { UDM_GETPOS, sent}, 90c2c66affSColin Finck { UDM_SETPOS, sent|lparam, 0, 0}, 91c2c66affSColin Finck { UDM_GETPOS, sent}, 92c2c66affSColin Finck { UDM_SETPOS, sent|lparam, 0, MAKELONG(-1,0)}, 93c2c66affSColin Finck { UDM_GETPOS, sent}, 94c2c66affSColin Finck { UDM_SETPOS, sent|lparam, 0, 100}, 95c2c66affSColin Finck { UDM_GETPOS, sent}, 96c2c66affSColin Finck { UDM_SETPOS, sent|lparam, 0, 101}, 97c2c66affSColin Finck { UDM_GETPOS, sent}, 98c2c66affSColin Finck { 0 } 99c2c66affSColin Finck }; 100c2c66affSColin Finck 101c2c66affSColin Finck static const struct message test_updown_pos32_seq[] = { 102c2c66affSColin Finck { UDM_SETRANGE32, sent|lparam, 0, 1000 }, 103c2c66affSColin Finck { UDM_GETRANGE32, sent}, /* Cannot check wparam and lparam as they are ptrs */ 104c2c66affSColin Finck { UDM_SETPOS32, sent|lparam, 0, 500 }, 105c2c66affSColin Finck { UDM_GETPOS32, sent}, 106c2c66affSColin Finck { UDM_SETPOS32, sent|lparam, 0, 0 }, 107c2c66affSColin Finck { UDM_GETPOS32, sent}, 108c2c66affSColin Finck { UDM_SETPOS32, sent|lparam, 0, -1 }, 109c2c66affSColin Finck { UDM_GETPOS32, sent}, 110c2c66affSColin Finck { UDM_SETPOS32, sent|lparam, 0, 1000 }, 111c2c66affSColin Finck { UDM_GETPOS32, sent}, 112c2c66affSColin Finck { UDM_SETPOS32, sent|lparam, 0, 1001 }, 113c2c66affSColin Finck { UDM_GETPOS32, sent}, 114c2c66affSColin Finck { 0 } 115c2c66affSColin Finck }; 116c2c66affSColin Finck 117c2c66affSColin Finck static const struct message test_updown_buddy_seq[] = { 118c2c66affSColin Finck { UDM_GETBUDDY, sent }, 119c2c66affSColin Finck { UDM_SETBUDDY, sent }, 120c2c66affSColin Finck { WM_STYLECHANGING, sent|defwinproc }, 121c2c66affSColin Finck { WM_STYLECHANGED, sent|defwinproc }, 122c2c66affSColin Finck { WM_STYLECHANGING, sent|defwinproc }, 123c2c66affSColin Finck { WM_STYLECHANGED, sent|defwinproc }, 124c2c66affSColin Finck { WM_WINDOWPOSCHANGING, sent|defwinproc }, 125c2c66affSColin Finck { WM_NCCALCSIZE, sent|wparam|optional|defwinproc, 1 }, 126c2c66affSColin Finck { WM_WINDOWPOSCHANGED, sent|defwinproc }, 127c2c66affSColin Finck { WM_MOVE, sent|defwinproc }, 128c2c66affSColin Finck { UDM_GETBUDDY, sent }, 129c2c66affSColin Finck { 0 } 130c2c66affSColin Finck }; 131c2c66affSColin Finck 132c2c66affSColin Finck static const struct message test_updown_base_seq[] = { 133c2c66affSColin Finck { UDM_SETBASE, sent|wparam, 10 }, 134c2c66affSColin Finck { UDM_GETBASE, sent }, 135c2c66affSColin Finck { UDM_SETBASE, sent|wparam, 80 }, 136c2c66affSColin Finck { UDM_GETBASE, sent }, 137c2c66affSColin Finck { UDM_SETBASE, sent|wparam, 16 }, 138c2c66affSColin Finck { UDM_GETBASE, sent }, 139c2c66affSColin Finck { UDM_SETBASE, sent|wparam, 80 }, 140c2c66affSColin Finck { UDM_GETBASE, sent }, 141c2c66affSColin Finck { UDM_SETBASE, sent|wparam, 10 }, 142c2c66affSColin Finck { UDM_GETBASE, sent }, 143c2c66affSColin Finck { 0 } 144c2c66affSColin Finck }; 145c2c66affSColin Finck 146c2c66affSColin Finck static const struct message test_updown_unicode_seq[] = { 147c2c66affSColin Finck { UDM_SETUNICODEFORMAT, sent|wparam, 0 }, 148c2c66affSColin Finck { UDM_GETUNICODEFORMAT, sent }, 149c2c66affSColin Finck { UDM_SETUNICODEFORMAT, sent|wparam, 1 }, 150c2c66affSColin Finck { UDM_GETUNICODEFORMAT, sent }, 151c2c66affSColin Finck { UDM_SETUNICODEFORMAT, sent|wparam, 0 }, 152c2c66affSColin Finck { UDM_GETUNICODEFORMAT, sent }, 153c2c66affSColin Finck { 0 } 154c2c66affSColin Finck }; 155c2c66affSColin Finck 156c2c66affSColin Finck static const struct message test_updown_pos_nochange_seq[] = { 157c2c66affSColin Finck { WM_GETTEXT, sent|id, 0, 0, BUDDY_ID }, 158c2c66affSColin Finck { 0 } 159c2c66affSColin Finck }; 160c2c66affSColin Finck 161c2c66affSColin Finck static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) 162c2c66affSColin Finck { 163c2c66affSColin Finck static LONG defwndproc_counter = 0; 164c2c66affSColin Finck struct message msg = { 0 }; 165c2c66affSColin Finck LRESULT ret; 166c2c66affSColin Finck 167c2c66affSColin Finck /* log system messages, except for painting */ 168c2c66affSColin Finck if (message < WM_USER && 169c2c66affSColin Finck message != WM_PAINT && 170c2c66affSColin Finck message != WM_ERASEBKGND && 171c2c66affSColin Finck message != WM_NCPAINT && 172c2c66affSColin Finck message != WM_NCHITTEST && 173c2c66affSColin Finck message != WM_GETTEXT && 174c2c66affSColin Finck message != WM_GETICON && 175c2c66affSColin Finck message != WM_DEVICECHANGE) 176c2c66affSColin Finck { 177c2c66affSColin Finck msg.message = message; 178c2c66affSColin Finck msg.flags = sent|wparam|lparam; 179c2c66affSColin Finck if (defwndproc_counter) msg.flags |= defwinproc; 180c2c66affSColin Finck msg.wParam = wParam; 181c2c66affSColin Finck msg.lParam = lParam; 182c2c66affSColin Finck add_message(sequences, PARENT_SEQ_INDEX, &msg); 183c2c66affSColin Finck } 184c2c66affSColin Finck 185c2c66affSColin Finck defwndproc_counter++; 186c2c66affSColin Finck ret = DefWindowProcA(hwnd, message, wParam, lParam); 187c2c66affSColin Finck defwndproc_counter--; 188c2c66affSColin Finck 189c2c66affSColin Finck return ret; 190c2c66affSColin Finck } 191c2c66affSColin Finck 192c2c66affSColin Finck static BOOL register_parent_wnd_class(void) 193c2c66affSColin Finck { 194c2c66affSColin Finck WNDCLASSA cls; 195c2c66affSColin Finck 196c2c66affSColin Finck cls.style = 0; 197c2c66affSColin Finck cls.lpfnWndProc = parent_wnd_proc; 198c2c66affSColin Finck cls.cbClsExtra = 0; 199c2c66affSColin Finck cls.cbWndExtra = 0; 200c2c66affSColin Finck cls.hInstance = GetModuleHandleA(NULL); 201c2c66affSColin Finck cls.hIcon = 0; 202c2c66affSColin Finck cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW); 203c2c66affSColin Finck cls.hbrBackground = GetStockObject(WHITE_BRUSH); 204c2c66affSColin Finck cls.lpszMenuName = NULL; 205c2c66affSColin Finck cls.lpszClassName = "Up-Down test parent class"; 206c2c66affSColin Finck return RegisterClassA(&cls); 207c2c66affSColin Finck } 208c2c66affSColin Finck 209c2c66affSColin Finck static HWND create_parent_window(void) 210c2c66affSColin Finck { 211c2c66affSColin Finck if (!register_parent_wnd_class()) 212c2c66affSColin Finck return NULL; 213c2c66affSColin Finck 214c2c66affSColin Finck return CreateWindowExA(0, "Up-Down test parent class", 215c2c66affSColin Finck "Up-Down test parent window", 216c2c66affSColin Finck WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | 217c2c66affSColin Finck WS_MAXIMIZEBOX | WS_VISIBLE, 218c2c66affSColin Finck 0, 0, 100, 100, 219c2c66affSColin Finck GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL); 220c2c66affSColin Finck } 221c2c66affSColin Finck 222c2c66affSColin Finck static LRESULT WINAPI edit_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) 223c2c66affSColin Finck { 224c2c66affSColin Finck WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA); 225c2c66affSColin Finck static LONG defwndproc_counter = 0; 226c2c66affSColin Finck struct message msg = { 0 }; 227c2c66affSColin Finck LRESULT ret; 228c2c66affSColin Finck 229c2c66affSColin Finck msg.message = message; 230c2c66affSColin Finck msg.flags = sent|wparam|lparam; 231c2c66affSColin Finck if (defwndproc_counter) msg.flags |= defwinproc; 232c2c66affSColin Finck msg.wParam = wParam; 233c2c66affSColin Finck msg.lParam = lParam; 234c2c66affSColin Finck msg.id = BUDDY_ID; 235c2c66affSColin Finck add_message(sequences, EDIT_SEQ_INDEX, &msg); 236c2c66affSColin Finck 237c2c66affSColin Finck defwndproc_counter++; 238c2c66affSColin Finck ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam); 239c2c66affSColin Finck defwndproc_counter--; 240c2c66affSColin Finck return ret; 241c2c66affSColin Finck } 242c2c66affSColin Finck 243c2c66affSColin Finck static HWND create_edit_control(void) 244c2c66affSColin Finck { 245c2c66affSColin Finck WNDPROC oldproc; 246c2c66affSColin Finck HWND hwnd; 247c2c66affSColin Finck RECT rect; 248c2c66affSColin Finck 249c2c66affSColin Finck GetClientRect(parent_wnd, &rect); 250c2c66affSColin Finck hwnd = CreateWindowExA(0, WC_EDITA, NULL, WS_CHILD | WS_BORDER | WS_VISIBLE, 251c2c66affSColin Finck 0, 0, rect.right, rect.bottom, 252c2c66affSColin Finck parent_wnd, NULL, GetModuleHandleA(NULL), NULL); 253c2c66affSColin Finck if (!hwnd) return NULL; 254c2c66affSColin Finck 255c2c66affSColin Finck oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC, 256c2c66affSColin Finck (LONG_PTR)edit_subclass_proc); 257c2c66affSColin Finck SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc); 258c2c66affSColin Finck 259c2c66affSColin Finck return hwnd; 260c2c66affSColin Finck } 261c2c66affSColin Finck 262c2c66affSColin Finck static LRESULT WINAPI updown_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) 263c2c66affSColin Finck { 264c2c66affSColin Finck WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA); 265c2c66affSColin Finck static LONG defwndproc_counter = 0; 266c2c66affSColin Finck struct message msg = { 0 }; 267c2c66affSColin Finck LRESULT ret; 268c2c66affSColin Finck 269c2c66affSColin Finck msg.message = message; 270c2c66affSColin Finck msg.flags = sent|wparam|lparam; 271c2c66affSColin Finck if (defwndproc_counter) msg.flags |= defwinproc; 272c2c66affSColin Finck msg.wParam = wParam; 273c2c66affSColin Finck msg.lParam = lParam; 274c2c66affSColin Finck msg.id = UPDOWN_ID; 275c2c66affSColin Finck add_message(sequences, UPDOWN_SEQ_INDEX, &msg); 276c2c66affSColin Finck 277c2c66affSColin Finck defwndproc_counter++; 278c2c66affSColin Finck ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam); 279c2c66affSColin Finck defwndproc_counter--; 280c2c66affSColin Finck 281c2c66affSColin Finck return ret; 282c2c66affSColin Finck } 283c2c66affSColin Finck 284c2c66affSColin Finck static HWND create_updown_control(DWORD style, HWND buddy) 285c2c66affSColin Finck { 286c2c66affSColin Finck WNDPROC oldproc; 287c2c66affSColin Finck HWND updown; 288c2c66affSColin Finck RECT rect; 289c2c66affSColin Finck 290c2c66affSColin Finck GetClientRect(parent_wnd, &rect); 291*0d320bc2SAmine Khaldi updown = CreateWindowExA(0, UPDOWN_CLASSA, NULL, WS_CHILD | WS_BORDER | WS_VISIBLE | style, 292*0d320bc2SAmine Khaldi 0, 0, rect.right, rect.bottom, 293*0d320bc2SAmine Khaldi parent_wnd, (HMENU)1, GetModuleHandleA(NULL), NULL); 294*0d320bc2SAmine Khaldi ok(updown != NULL, "Failed to create UpDown control.\n"); 295c2c66affSColin Finck if (!updown) return NULL; 296c2c66affSColin Finck 297*0d320bc2SAmine Khaldi SendMessageA(updown, UDM_SETBUDDY, (WPARAM)buddy, 0); 298*0d320bc2SAmine Khaldi SendMessageA(updown, UDM_SETRANGE, 0, MAKELONG(100, 0)); 299*0d320bc2SAmine Khaldi SendMessageA(updown, UDM_SETPOS, 0, MAKELONG(50, 0)); 300*0d320bc2SAmine Khaldi 301c2c66affSColin Finck oldproc = (WNDPROC)SetWindowLongPtrA(updown, GWLP_WNDPROC, 302c2c66affSColin Finck (LONG_PTR)updown_subclass_proc); 303c2c66affSColin Finck SetWindowLongPtrA(updown, GWLP_USERDATA, (LONG_PTR)oldproc); 304c2c66affSColin Finck 305c2c66affSColin Finck return updown; 306c2c66affSColin Finck } 307c2c66affSColin Finck 308c2c66affSColin Finck static void test_updown_pos(void) 309c2c66affSColin Finck { 310c2c66affSColin Finck HWND updown; 311c2c66affSColin Finck int r; 312c2c66affSColin Finck 313c2c66affSColin Finck updown = create_updown_control(UDS_ALIGNRIGHT, g_edit); 314c2c66affSColin Finck 315c2c66affSColin Finck flush_sequences(sequences, NUM_MSG_SEQUENCES); 316c2c66affSColin Finck 317c2c66affSColin Finck /* Set Range from 0 to 100 */ 318c2c66affSColin Finck SendMessageA(updown, UDM_SETRANGE, 0 , MAKELONG(100,0) ); 319c2c66affSColin Finck r = SendMessageA(updown, UDM_GETRANGE, 0,0); 320c2c66affSColin Finck expect(100,LOWORD(r)); 321c2c66affSColin Finck expect(0,HIWORD(r)); 322c2c66affSColin Finck 323c2c66affSColin Finck /* Set the position to 5, return is not checked as it was set before func call */ 324c2c66affSColin Finck SendMessageA(updown, UDM_SETPOS, 0 , MAKELONG(5,0) ); 325c2c66affSColin Finck /* Since UDM_SETBUDDYINT was not set at creation HIWORD(r) will always be 1 as a return from UDM_GETPOS */ 326c2c66affSColin Finck /* Get the position, which should be 5 */ 327c2c66affSColin Finck r = SendMessageA(updown, UDM_GETPOS, 0 , 0 ); 328c2c66affSColin Finck expect(5,LOWORD(r)); 329c2c66affSColin Finck expect(1,HIWORD(r)); 330c2c66affSColin Finck 331c2c66affSColin Finck /* Set the position to 0, return should be 5 */ 332c2c66affSColin Finck r = SendMessageA(updown, UDM_SETPOS, 0 , MAKELONG(0,0) ); 333c2c66affSColin Finck expect(5,r); 334c2c66affSColin Finck /* Get the position, which should be 0 */ 335c2c66affSColin Finck r = SendMessageA(updown, UDM_GETPOS, 0 , 0 ); 336c2c66affSColin Finck expect(0,LOWORD(r)); 337c2c66affSColin Finck expect(1,HIWORD(r)); 338c2c66affSColin Finck 339c2c66affSColin Finck /* Set the position to -1, return should be 0 */ 340c2c66affSColin Finck r = SendMessageA(updown, UDM_SETPOS, 0 , MAKELONG(-1,0) ); 341c2c66affSColin Finck expect(0,r); 342c2c66affSColin Finck /* Get the position, which should be 0 */ 343c2c66affSColin Finck r = SendMessageA(updown, UDM_GETPOS, 0 , 0 ); 344c2c66affSColin Finck expect(0,LOWORD(r)); 345c2c66affSColin Finck expect(1,HIWORD(r)); 346c2c66affSColin Finck 347c2c66affSColin Finck /* Set the position to 100, return should be 0 */ 348c2c66affSColin Finck r = SendMessageA(updown, UDM_SETPOS, 0 , MAKELONG(100,0) ); 349c2c66affSColin Finck expect(0,r); 350c2c66affSColin Finck /* Get the position, which should be 100 */ 351c2c66affSColin Finck r = SendMessageA(updown, UDM_GETPOS, 0 , 0 ); 352c2c66affSColin Finck expect(100,LOWORD(r)); 353c2c66affSColin Finck expect(1,HIWORD(r)); 354c2c66affSColin Finck 355c2c66affSColin Finck /* Set the position to 101, return should be 100 */ 356c2c66affSColin Finck r = SendMessageA(updown, UDM_SETPOS, 0 , MAKELONG(101,0) ); 357c2c66affSColin Finck expect(100,r); 358c2c66affSColin Finck /* Get the position, which should be 100 */ 359c2c66affSColin Finck r = SendMessageA(updown, UDM_GETPOS, 0 , 0 ); 360c2c66affSColin Finck expect(100,LOWORD(r)); 361c2c66affSColin Finck expect(1,HIWORD(r)); 362c2c66affSColin Finck 363c2c66affSColin Finck ok_sequence(sequences, UPDOWN_SEQ_INDEX, test_updown_pos_seq , "test updown pos", FALSE); 364c2c66affSColin Finck 365c2c66affSColin Finck DestroyWindow(updown); 366c2c66affSColin Finck 367c2c66affSColin Finck /* there's no attempt to update buddy Edit if text didn't change */ 368c2c66affSColin Finck SetWindowTextA(g_edit, "50"); 369c2c66affSColin Finck updown = create_updown_control(UDS_ALIGNRIGHT | UDS_SETBUDDYINT | UDS_ARROWKEYS, g_edit); 370c2c66affSColin Finck 371c2c66affSColin Finck /* test sequence only on 5.8x versions */ 372c2c66affSColin Finck r = SendMessageA(updown, UDM_GETPOS32, 0, 0); 373c2c66affSColin Finck if (r) 374c2c66affSColin Finck { 375c2c66affSColin Finck UDACCEL accel; 376c2c66affSColin Finck 377c2c66affSColin Finck flush_sequences(sequences, NUM_MSG_SEQUENCES); 378c2c66affSColin Finck 379c2c66affSColin Finck r = SendMessageA(updown, UDM_SETPOS, 0, 50); 380c2c66affSColin Finck expect(50,r); 381c2c66affSColin Finck 382c2c66affSColin Finck ok_sequence(sequences, EDIT_SEQ_INDEX, test_updown_pos_nochange_seq, 383c2c66affSColin Finck "test updown pos, no change", FALSE); 384c2c66affSColin Finck 385c2c66affSColin Finck SendMessageA(updown, UDM_SETRANGE, 0, MAKELONG(1, 40)); 386c2c66affSColin Finck r = SendMessageA(updown, UDM_GETRANGE, 0, 0); 387c2c66affSColin Finck expect(1, LOWORD(r)); 388c2c66affSColin Finck expect(40, HIWORD(r)); 389c2c66affSColin Finck 390c2c66affSColin Finck accel.nSec = 0; 391c2c66affSColin Finck accel.nInc = 5; 392c2c66affSColin Finck r = SendMessageA(updown, UDM_SETACCEL, 1, (LPARAM)&accel); 393c2c66affSColin Finck expect(TRUE, r); 394c2c66affSColin Finck 395c2c66affSColin Finck r = SendMessageA(updown, UDM_GETPOS, 0, 0); 396c2c66affSColin Finck expect(40, LOWORD(r)); 397c2c66affSColin Finck expect(1, HIWORD(r)); 398c2c66affSColin Finck 399c2c66affSColin Finck r = SendMessageA(updown, UDM_SETPOS, 0, MAKELONG(0, 0)); 400c2c66affSColin Finck expect(40, LOWORD(r)); 401c2c66affSColin Finck expect(0, HIWORD(r)); 402c2c66affSColin Finck 403c2c66affSColin Finck r = SendMessageA(updown, UDM_GETPOS, 0, 0); 404c2c66affSColin Finck expect(1, LOWORD(r)); 405c2c66affSColin Finck expect(0, HIWORD(r)); 406c2c66affSColin Finck 407c2c66affSColin Finck r = SendMessageA(updown, UDM_SETPOS, 0, MAKELONG(2, 0)); 408c2c66affSColin Finck expect(1, LOWORD(r)); 409c2c66affSColin Finck expect(0, HIWORD(r)); 410c2c66affSColin Finck 411c2c66affSColin Finck r = SendMessageA(g_edit, WM_KEYDOWN, VK_UP, 0); 412c2c66affSColin Finck expect(0, r); 413c2c66affSColin Finck r = SendMessageA(updown, UDM_GETPOS, 0, 0); 414c2c66affSColin Finck expect(1, LOWORD(r)); 415c2c66affSColin Finck expect(0, HIWORD(r)); 416c2c66affSColin Finck 417c2c66affSColin Finck r = SendMessageA(updown, UDM_SETPOS, 0, MAKELONG(50, 0)); 418c2c66affSColin Finck expect(1, LOWORD(r)); 419c2c66affSColin Finck expect(0, HIWORD(r)); 420c2c66affSColin Finck 421c2c66affSColin Finck r = SendMessageA(updown, UDM_GETPOS, 0, 0); 422c2c66affSColin Finck expect(40, LOWORD(r)); 423c2c66affSColin Finck expect(0, HIWORD(r)); 424c2c66affSColin Finck } 425c2c66affSColin Finck 426c2c66affSColin Finck DestroyWindow(updown); 427c2c66affSColin Finck } 428c2c66affSColin Finck 429c2c66affSColin Finck static void test_updown_pos32(void) 430c2c66affSColin Finck { 431c2c66affSColin Finck HWND updown; 432c2c66affSColin Finck int r; 433c2c66affSColin Finck int low, high; 434c2c66affSColin Finck 435c2c66affSColin Finck updown = create_updown_control(UDS_ALIGNRIGHT, g_edit); 436c2c66affSColin Finck 437c2c66affSColin Finck flush_sequences(sequences, NUM_MSG_SEQUENCES); 438c2c66affSColin Finck 439c2c66affSColin Finck /* Set the position to 0 to 1000 */ 440c2c66affSColin Finck SendMessageA(updown, UDM_SETRANGE32, 0 , 1000 ); 441c2c66affSColin Finck 442c2c66affSColin Finck low = high = -1; 443c2c66affSColin Finck r = SendMessageA(updown, UDM_GETRANGE32, (WPARAM) &low , (LPARAM) &high ); 444c2c66affSColin Finck expect(0,r); 445c2c66affSColin Finck if (low == -1) 446c2c66affSColin Finck { 447c2c66affSColin Finck win_skip("UDM_SETRANGE32/UDM_GETRANGE32 not available\n"); 448c2c66affSColin Finck DestroyWindow(updown); 449c2c66affSColin Finck return; 450c2c66affSColin Finck } 451c2c66affSColin Finck 452c2c66affSColin Finck expect(0,low); 453c2c66affSColin Finck expect(1000,high); 454c2c66affSColin Finck 455c2c66affSColin Finck /* Set position to 500 */ 456c2c66affSColin Finck r = SendMessageA(updown, UDM_SETPOS32, 0 , 500 ); 457c2c66affSColin Finck if (!r) 458c2c66affSColin Finck { 459c2c66affSColin Finck win_skip("UDM_SETPOS32 and UDM_GETPOS32 need 5.80\n"); 460c2c66affSColin Finck DestroyWindow(updown); 461c2c66affSColin Finck return; 462c2c66affSColin Finck } 463c2c66affSColin Finck expect(50,r); 464c2c66affSColin Finck 465c2c66affSColin Finck /* Since UDM_SETBUDDYINT was not set at creation bRet will always be true as a return from UDM_GETPOS32 */ 466c2c66affSColin Finck 467c2c66affSColin Finck r = SendMessageA(updown, UDM_GETPOS32, 0 , (LPARAM) &high ); 468c2c66affSColin Finck expect(500,r); 469c2c66affSColin Finck expect(1,high); 470c2c66affSColin Finck 471c2c66affSColin Finck /* Set position to 0, return should be 500 */ 472c2c66affSColin Finck r = SendMessageA(updown, UDM_SETPOS32, 0 , 0 ); 473c2c66affSColin Finck expect(500,r); 474c2c66affSColin Finck r = SendMessageA(updown, UDM_GETPOS32, 0 , (LPARAM) &high ); 475c2c66affSColin Finck expect(0,r); 476c2c66affSColin Finck expect(1,high); 477c2c66affSColin Finck 478c2c66affSColin Finck /* Set position to -1 which should become 0, return should be 0 */ 479c2c66affSColin Finck r = SendMessageA(updown, UDM_SETPOS32, 0 , -1 ); 480c2c66affSColin Finck expect(0,r); 481c2c66affSColin Finck r = SendMessageA(updown, UDM_GETPOS32, 0 , (LPARAM) &high ); 482c2c66affSColin Finck expect(0,r); 483c2c66affSColin Finck expect(1,high); 484c2c66affSColin Finck 485c2c66affSColin Finck /* Set position to 1000, return should be 0 */ 486c2c66affSColin Finck r = SendMessageA(updown, UDM_SETPOS32, 0 , 1000 ); 487c2c66affSColin Finck expect(0,r); 488c2c66affSColin Finck r = SendMessageA(updown, UDM_GETPOS32, 0 , (LPARAM) &high ); 489c2c66affSColin Finck expect(1000,r); 490c2c66affSColin Finck expect(1,high); 491c2c66affSColin Finck 492c2c66affSColin Finck /* Set position to 1001 which should become 1000, return should be 1000 */ 493c2c66affSColin Finck r = SendMessageA(updown, UDM_SETPOS32, 0 , 1001 ); 494c2c66affSColin Finck expect(1000,r); 495c2c66affSColin Finck r = SendMessageA(updown, UDM_GETPOS32, 0 , (LPARAM) &high ); 496c2c66affSColin Finck expect(1000,r); 497c2c66affSColin Finck expect(1,high); 498c2c66affSColin Finck 499c2c66affSColin Finck ok_sequence(sequences, UPDOWN_SEQ_INDEX, test_updown_pos32_seq, "test updown pos32", FALSE); 500c2c66affSColin Finck 501c2c66affSColin Finck DestroyWindow(updown); 502c2c66affSColin Finck 503c2c66affSColin Finck /* there's no attempt to update buddy Edit if text didn't change */ 504c2c66affSColin Finck SetWindowTextA(g_edit, "50"); 505c2c66affSColin Finck updown = create_updown_control(UDS_ALIGNRIGHT | UDS_SETBUDDYINT, g_edit); 506c2c66affSColin Finck 507c2c66affSColin Finck flush_sequences(sequences, NUM_MSG_SEQUENCES); 508c2c66affSColin Finck 509c2c66affSColin Finck r = SendMessageA(updown, UDM_SETPOS32, 0, 50); 510c2c66affSColin Finck expect(50,r); 511c2c66affSColin Finck ok_sequence(sequences, EDIT_SEQ_INDEX, test_updown_pos_nochange_seq, 512c2c66affSColin Finck "test updown pos, no change", FALSE); 513c2c66affSColin Finck 514c2c66affSColin Finck DestroyWindow(updown); 515c2c66affSColin Finck } 516c2c66affSColin Finck 517c2c66affSColin Finck static void test_updown_buddy(void) 518c2c66affSColin Finck { 519c2c66affSColin Finck HWND updown, buddyReturn, buddy; 520*0d320bc2SAmine Khaldi RECT rect, rect2; 521c2c66affSColin Finck WNDPROC proc; 522c2c66affSColin Finck DWORD style; 523c2c66affSColin Finck 524c2c66affSColin Finck updown = create_updown_control(UDS_ALIGNRIGHT, g_edit); 525c2c66affSColin Finck 526c2c66affSColin Finck flush_sequences(sequences, NUM_MSG_SEQUENCES); 527c2c66affSColin Finck 528c2c66affSColin Finck buddyReturn = (HWND)SendMessageA(updown, UDM_GETBUDDY, 0 , 0 ); 529c2c66affSColin Finck ok(buddyReturn == g_edit, "Expected edit handle\n"); 530c2c66affSColin Finck 531c2c66affSColin Finck buddyReturn = (HWND)SendMessageA(updown, UDM_SETBUDDY, (WPARAM) g_edit, 0); 532c2c66affSColin Finck ok(buddyReturn == g_edit, "Expected edit handle\n"); 533c2c66affSColin Finck 534c2c66affSColin Finck buddyReturn = (HWND)SendMessageA(updown, UDM_GETBUDDY, 0 , 0 ); 535c2c66affSColin Finck ok(buddyReturn == g_edit, "Expected edit handle\n"); 536c2c66affSColin Finck 537c2c66affSColin Finck ok_sequence(sequences, UPDOWN_SEQ_INDEX, test_updown_buddy_seq, "test updown buddy", TRUE); 538c2c66affSColin Finck ok_sequence(sequences, EDIT_SEQ_INDEX, add_updown_with_edit_seq, "test updown buddy_edit", FALSE); 539c2c66affSColin Finck 540c2c66affSColin Finck DestroyWindow(updown); 541c2c66affSColin Finck 542c2c66affSColin Finck buddy = create_edit_control(); 543c2c66affSColin Finck proc = (WNDPROC)GetWindowLongPtrA(buddy, GWLP_WNDPROC); 544c2c66affSColin Finck 545c2c66affSColin Finck updown= create_updown_control(UDS_ALIGNRIGHT, buddy); 546c2c66affSColin Finck ok(proc == (WNDPROC)GetWindowLongPtrA(buddy, GWLP_WNDPROC), "No subclassing expected\n"); 547c2c66affSColin Finck 548c2c66affSColin Finck style = GetWindowLongA(updown, GWL_STYLE); 549c2c66affSColin Finck SetWindowLongA(updown, GWL_STYLE, style | UDS_ARROWKEYS); 550c2c66affSColin Finck style = GetWindowLongA(updown, GWL_STYLE); 551c2c66affSColin Finck ok(style & UDS_ARROWKEYS, "Expected UDS_ARROWKEYS\n"); 552c2c66affSColin Finck /* no subclass if UDS_ARROWKEYS set after creation */ 553c2c66affSColin Finck ok(proc == (WNDPROC)GetWindowLongPtrA(buddy, GWLP_WNDPROC), "No subclassing expected\n"); 554c2c66affSColin Finck 555c2c66affSColin Finck DestroyWindow(updown); 556c2c66affSColin Finck 557c2c66affSColin Finck updown= create_updown_control(UDS_ALIGNRIGHT | UDS_ARROWKEYS, buddy); 558c2c66affSColin Finck ok(proc != (WNDPROC)GetWindowLongPtrA(buddy, GWLP_WNDPROC), "Subclassing expected\n"); 559c2c66affSColin Finck 560c2c66affSColin Finck if (pSetWindowSubclass) 561c2c66affSColin Finck { 562c2c66affSColin Finck /* updown uses subclass helpers for buddy on >5.8x systems */ 563c2c66affSColin Finck ok(GetPropA(buddy, "CC32SubclassInfo") != NULL, "Expected CC32SubclassInfo property\n"); 564c2c66affSColin Finck } 565c2c66affSColin Finck 566c2c66affSColin Finck DestroyWindow(updown); 567c2c66affSColin Finck DestroyWindow(buddy); 568*0d320bc2SAmine Khaldi 569*0d320bc2SAmine Khaldi /* Create with buddy and UDS_HORZ, reset buddy. */ 570*0d320bc2SAmine Khaldi updown = create_updown_control(UDS_HORZ, g_edit); 571*0d320bc2SAmine Khaldi 572*0d320bc2SAmine Khaldi buddyReturn = (HWND)SendMessageA(updown, UDM_GETBUDDY, 0, 0); 573*0d320bc2SAmine Khaldi ok(buddyReturn == g_edit, "Unexpected buddy window.\n"); 574*0d320bc2SAmine Khaldi 575*0d320bc2SAmine Khaldi GetClientRect(updown, &rect); 576*0d320bc2SAmine Khaldi 577*0d320bc2SAmine Khaldi buddyReturn = (HWND)SendMessageA(updown, UDM_SETBUDDY, 0, 0); 578*0d320bc2SAmine Khaldi ok(buddyReturn == g_edit, "Unexpected buddy window.\n"); 579*0d320bc2SAmine Khaldi 580*0d320bc2SAmine Khaldi GetClientRect(updown, &rect2); 581*0d320bc2SAmine Khaldi ok(EqualRect(&rect, &rect2), "Unexpected window rect.\n"); 582*0d320bc2SAmine Khaldi 583*0d320bc2SAmine Khaldi /* Remove UDS_HORZ, reset buddy again. */ 584*0d320bc2SAmine Khaldi style = GetWindowLongA(updown, GWL_STYLE); 585*0d320bc2SAmine Khaldi SetWindowLongA(updown, GWL_STYLE, style & ~UDS_HORZ); 586*0d320bc2SAmine Khaldi style = GetWindowLongA(updown, GWL_STYLE); 587*0d320bc2SAmine Khaldi ok(!(style & UDS_HORZ), "Unexpected style.\n"); 588*0d320bc2SAmine Khaldi 589*0d320bc2SAmine Khaldi buddyReturn = (HWND)SendMessageA(updown, UDM_SETBUDDY, 0, 0); 590*0d320bc2SAmine Khaldi ok(buddyReturn == NULL, "Unexpected buddy window.\n"); 591*0d320bc2SAmine Khaldi 592*0d320bc2SAmine Khaldi GetClientRect(updown, &rect2); 593*0d320bc2SAmine Khaldi ok(EqualRect(&rect, &rect2), "Unexpected window rect.\n"); 594*0d320bc2SAmine Khaldi 595*0d320bc2SAmine Khaldi DestroyWindow(updown); 596*0d320bc2SAmine Khaldi 597*0d320bc2SAmine Khaldi /* Without UDS_HORZ. */ 598*0d320bc2SAmine Khaldi updown = create_updown_control(0, g_edit); 599*0d320bc2SAmine Khaldi 600*0d320bc2SAmine Khaldi buddyReturn = (HWND)SendMessageA(updown, UDM_GETBUDDY, 0, 0); 601*0d320bc2SAmine Khaldi ok(buddyReturn == g_edit, "Unexpected buddy window.\n"); 602*0d320bc2SAmine Khaldi 603*0d320bc2SAmine Khaldi GetClientRect(updown, &rect); 604*0d320bc2SAmine Khaldi 605*0d320bc2SAmine Khaldi buddyReturn = (HWND)SendMessageA(updown, UDM_SETBUDDY, 0, 0); 606*0d320bc2SAmine Khaldi ok(buddyReturn == g_edit, "Unexpected buddy window.\n"); 607*0d320bc2SAmine Khaldi 608*0d320bc2SAmine Khaldi GetClientRect(updown, &rect2); 609*0d320bc2SAmine Khaldi ok(EqualRect(&rect, &rect2), "Unexpected window rect.\n"); 610*0d320bc2SAmine Khaldi 611*0d320bc2SAmine Khaldi DestroyWindow(updown); 612*0d320bc2SAmine Khaldi 613*0d320bc2SAmine Khaldi /* Create without buddy. */ 614*0d320bc2SAmine Khaldi GetClientRect(parent_wnd, &rect); 615*0d320bc2SAmine Khaldi updown = CreateWindowExA(0, UPDOWN_CLASSA, NULL, WS_CHILD | WS_BORDER | WS_VISIBLE | UDS_HORZ, 616*0d320bc2SAmine Khaldi 0, 0, rect.right, rect.bottom, parent_wnd, (HMENU)1, GetModuleHandleA(NULL), NULL); 617*0d320bc2SAmine Khaldi ok(updown != NULL, "Failed to create UpDown control.\n"); 618*0d320bc2SAmine Khaldi 619*0d320bc2SAmine Khaldi GetClientRect(updown, &rect); 620*0d320bc2SAmine Khaldi buddyReturn = (HWND)SendMessageA(updown, UDM_SETBUDDY, 0, 0); 621*0d320bc2SAmine Khaldi ok(buddyReturn == NULL, "Unexpected buddy window.\n"); 622*0d320bc2SAmine Khaldi GetClientRect(updown, &rect2); 623*0d320bc2SAmine Khaldi 624*0d320bc2SAmine Khaldi ok(EqualRect(&rect, &rect2), "Unexpected window rect.\n"); 625*0d320bc2SAmine Khaldi 626*0d320bc2SAmine Khaldi style = GetWindowLongA(updown, GWL_STYLE); 627*0d320bc2SAmine Khaldi SetWindowLongA(updown, GWL_STYLE, style & ~UDS_HORZ); 628*0d320bc2SAmine Khaldi 629*0d320bc2SAmine Khaldi GetClientRect(updown, &rect2); 630*0d320bc2SAmine Khaldi ok(EqualRect(&rect, &rect2), "Unexpected window rect.\n"); 631*0d320bc2SAmine Khaldi 632*0d320bc2SAmine Khaldi buddyReturn = (HWND)SendMessageA(updown, UDM_SETBUDDY, (WPARAM)g_edit, 0); 633*0d320bc2SAmine Khaldi ok(buddyReturn == NULL, "Unexpected buddy window.\n"); 634*0d320bc2SAmine Khaldi GetClientRect(updown, &rect); 635*0d320bc2SAmine Khaldi 636*0d320bc2SAmine Khaldi buddyReturn = (HWND)SendMessageA(updown, UDM_SETBUDDY, 0, 0); 637*0d320bc2SAmine Khaldi ok(buddyReturn == g_edit, "Unexpected buddy window.\n"); 638*0d320bc2SAmine Khaldi GetClientRect(updown, &rect2); 639*0d320bc2SAmine Khaldi todo_wine 640*0d320bc2SAmine Khaldi ok(EqualRect(&rect, &rect2), "Unexpected window rect.\n"); 641*0d320bc2SAmine Khaldi 642*0d320bc2SAmine Khaldi DestroyWindow(updown); 643c2c66affSColin Finck } 644c2c66affSColin Finck 645c2c66affSColin Finck static void test_updown_base(void) 646c2c66affSColin Finck { 647c2c66affSColin Finck HWND updown; 648c2c66affSColin Finck int r; 649c2c66affSColin Finck CHAR text[10]; 650c2c66affSColin Finck 651c2c66affSColin Finck updown = create_updown_control(UDS_ALIGNRIGHT, g_edit); 652c2c66affSColin Finck 653c2c66affSColin Finck flush_sequences(sequences, NUM_MSG_SEQUENCES); 654c2c66affSColin Finck 655c2c66affSColin Finck SendMessageA(updown, UDM_SETBASE, 10 , 0); 656c2c66affSColin Finck r = SendMessageA(updown, UDM_GETBASE, 0 , 0); 657c2c66affSColin Finck expect(10,r); 658c2c66affSColin Finck 659c2c66affSColin Finck /* Set base to an invalid value, should return 0 and stay at 10 */ 660c2c66affSColin Finck r = SendMessageA(updown, UDM_SETBASE, 80 , 0); 661c2c66affSColin Finck expect(0,r); 662c2c66affSColin Finck r = SendMessageA(updown, UDM_GETBASE, 0 , 0); 663c2c66affSColin Finck expect(10,r); 664c2c66affSColin Finck 665c2c66affSColin Finck /* Set base to 16 now, should get 16 as the return */ 666c2c66affSColin Finck r = SendMessageA(updown, UDM_SETBASE, 16 , 0); 667c2c66affSColin Finck expect(10,r); 668c2c66affSColin Finck r = SendMessageA(updown, UDM_GETBASE, 0 , 0); 669c2c66affSColin Finck expect(16,r); 670c2c66affSColin Finck 671c2c66affSColin Finck /* Set base to an invalid value, should return 0 and stay at 16 */ 672c2c66affSColin Finck r = SendMessageA(updown, UDM_SETBASE, 80 , 0); 673c2c66affSColin Finck expect(0,r); 674c2c66affSColin Finck r = SendMessageA(updown, UDM_GETBASE, 0 , 0); 675c2c66affSColin Finck expect(16,r); 676c2c66affSColin Finck 677c2c66affSColin Finck /* Set base back to 10, return should be 16 */ 678c2c66affSColin Finck r = SendMessageA(updown, UDM_SETBASE, 10 , 0); 679c2c66affSColin Finck expect(16,r); 680c2c66affSColin Finck r = SendMessageA(updown, UDM_GETBASE, 0 , 0); 681c2c66affSColin Finck expect(10,r); 682c2c66affSColin Finck 683c2c66affSColin Finck ok_sequence(sequences, UPDOWN_SEQ_INDEX, test_updown_base_seq, "test updown base", FALSE); 684c2c66affSColin Finck 685c2c66affSColin Finck DestroyWindow(updown); 686c2c66affSColin Finck 687c2c66affSColin Finck /* switch base with buddy attached */ 688c2c66affSColin Finck updown = create_updown_control(UDS_SETBUDDYINT | UDS_ALIGNRIGHT, g_edit); 689c2c66affSColin Finck 690c2c66affSColin Finck r = SendMessageA(updown, UDM_SETPOS, 0, 10); 691c2c66affSColin Finck expect(50, r); 692c2c66affSColin Finck 693c2c66affSColin Finck GetWindowTextA(g_edit, text, sizeof(text)/sizeof(CHAR)); 694c2c66affSColin Finck ok(lstrcmpA(text, "10") == 0, "Expected '10', got '%s'\n", text); 695c2c66affSColin Finck 696c2c66affSColin Finck r = SendMessageA(updown, UDM_SETBASE, 16, 0); 697c2c66affSColin Finck expect(10, r); 698c2c66affSColin Finck 699c2c66affSColin Finck GetWindowTextA(g_edit, text, sizeof(text)/sizeof(CHAR)); 700c2c66affSColin Finck /* FIXME: currently hex output isn't properly formatted, but for this 701c2c66affSColin Finck test only change from initial text matters */ 702c2c66affSColin Finck ok(lstrcmpA(text, "10") != 0, "Expected '0x000A', got '%s'\n", text); 703c2c66affSColin Finck 704c2c66affSColin Finck DestroyWindow(updown); 705c2c66affSColin Finck } 706c2c66affSColin Finck 707c2c66affSColin Finck static void test_updown_unicode(void) 708c2c66affSColin Finck { 709c2c66affSColin Finck HWND updown; 710c2c66affSColin Finck int r; 711c2c66affSColin Finck 712c2c66affSColin Finck updown = create_updown_control(UDS_ALIGNRIGHT, g_edit); 713c2c66affSColin Finck 714c2c66affSColin Finck flush_sequences(sequences, NUM_MSG_SEQUENCES); 715c2c66affSColin Finck 716c2c66affSColin Finck /* Set it to ANSI, don't check return as we don't know previous state */ 717c2c66affSColin Finck SendMessageA(updown, UDM_SETUNICODEFORMAT, 0 , 0); 718c2c66affSColin Finck r = SendMessageA(updown, UDM_GETUNICODEFORMAT, 0 , 0); 719c2c66affSColin Finck expect(0,r); 720c2c66affSColin Finck 721c2c66affSColin Finck /* Now set it to Unicode format */ 722c2c66affSColin Finck r = SendMessageA(updown, UDM_SETUNICODEFORMAT, 1 , 0); 723c2c66affSColin Finck expect(0,r); 724c2c66affSColin Finck r = SendMessageA(updown, UDM_GETUNICODEFORMAT, 0 , 0); 725c2c66affSColin Finck if (!r) 726c2c66affSColin Finck { 727c2c66affSColin Finck win_skip("UDM_SETUNICODEFORMAT not available\n"); 728c2c66affSColin Finck DestroyWindow(updown); 729c2c66affSColin Finck return; 730c2c66affSColin Finck } 731c2c66affSColin Finck expect(1,r); 732c2c66affSColin Finck 733c2c66affSColin Finck /* And now set it back to ANSI */ 734c2c66affSColin Finck r = SendMessageA(updown, UDM_SETUNICODEFORMAT, 0 , 0); 735c2c66affSColin Finck expect(1,r); 736c2c66affSColin Finck r = SendMessageA(updown, UDM_GETUNICODEFORMAT, 0 , 0); 737c2c66affSColin Finck expect(0,r); 738c2c66affSColin Finck 739c2c66affSColin Finck ok_sequence(sequences, UPDOWN_SEQ_INDEX, test_updown_unicode_seq, "test updown unicode", FALSE); 740c2c66affSColin Finck 741c2c66affSColin Finck DestroyWindow(updown); 742c2c66affSColin Finck } 743c2c66affSColin Finck 744c2c66affSColin Finck static void test_updown_create(void) 745c2c66affSColin Finck { 746c2c66affSColin Finck CHAR text[MAX_PATH]; 747c2c66affSColin Finck HWND updown; 748c2c66affSColin Finck RECT r; 749c2c66affSColin Finck 750c2c66affSColin Finck flush_sequences(sequences, NUM_MSG_SEQUENCES); 751c2c66affSColin Finck 752c2c66affSColin Finck updown = create_updown_control(UDS_ALIGNRIGHT, g_edit); 753c2c66affSColin Finck ok(updown != NULL, "Failed to create updown control\n"); 754c2c66affSColin Finck ok_sequence(sequences, PARENT_SEQ_INDEX, add_updown_to_parent_seq, "add updown control to parent", TRUE); 755c2c66affSColin Finck ok_sequence(sequences, EDIT_SEQ_INDEX, add_updown_with_edit_seq, "add updown control with edit", FALSE); 756c2c66affSColin Finck 757c2c66affSColin Finck flush_sequences(sequences, NUM_MSG_SEQUENCES); 758c2c66affSColin Finck 759c2c66affSColin Finck GetWindowTextA(g_edit, text, MAX_PATH); 760c2c66affSColin Finck ok(lstrlenA(text) == 0, "Expected empty string\n"); 761c2c66affSColin Finck ok_sequence(sequences, EDIT_SEQ_INDEX, get_edit_text_seq, "get edit text", FALSE); 762c2c66affSColin Finck 763c2c66affSColin Finck DestroyWindow(updown); 764c2c66affSColin Finck 765c2c66affSColin Finck /* create with zero width */ 766c2c66affSColin Finck updown = CreateWindowA (UPDOWN_CLASSA, 0, WS_CHILD | WS_BORDER | WS_VISIBLE, 0, 0, 0, 0, 767c2c66affSColin Finck parent_wnd, (HMENU)(DWORD_PTR)1, GetModuleHandleA(NULL), 0); 768c2c66affSColin Finck ok(updown != NULL, "Failed to create updown control\n"); 769c2c66affSColin Finck r.right = 0; 770c2c66affSColin Finck GetClientRect(updown, &r); 771c2c66affSColin Finck ok(r.right > 0, "Expected default width, got %d\n", r.right); 772c2c66affSColin Finck DestroyWindow(updown); 773c2c66affSColin Finck /* create with really small width */ 774c2c66affSColin Finck updown = CreateWindowA (UPDOWN_CLASSA, 0, WS_CHILD | WS_BORDER | WS_VISIBLE, 0, 0, 2, 0, 775c2c66affSColin Finck parent_wnd, (HMENU)(DWORD_PTR)1, GetModuleHandleA(NULL), 0); 776c2c66affSColin Finck ok(updown != NULL, "Failed to create updown control\n"); 777c2c66affSColin Finck r.right = 0; 778c2c66affSColin Finck GetClientRect(updown, &r); 779c2c66affSColin Finck ok(r.right != 2 && r.right > 0, "Expected default width, got %d\n", r.right); 780c2c66affSColin Finck DestroyWindow(updown); 781c2c66affSColin Finck /* create with width greater than default */ 782c2c66affSColin Finck updown = CreateWindowA (UPDOWN_CLASSA, 0, WS_CHILD | WS_BORDER | WS_VISIBLE, 0, 0, 100, 0, 783c2c66affSColin Finck parent_wnd, (HMENU)(DWORD_PTR)1, GetModuleHandleA(NULL), 0); 784c2c66affSColin Finck ok(updown != NULL, "Failed to create updown control\n"); 785c2c66affSColin Finck r.right = 0; 786c2c66affSColin Finck GetClientRect(updown, &r); 787c2c66affSColin Finck ok(r.right < 100 && r.right > 0, "Expected default width, got %d\n", r.right); 788c2c66affSColin Finck DestroyWindow(updown); 789c2c66affSColin Finck /* create with zero height, UDS_HORZ */ 790c2c66affSColin Finck updown = CreateWindowA (UPDOWN_CLASSA, 0, UDS_HORZ | WS_CHILD | WS_BORDER | WS_VISIBLE, 0, 0, 0, 0, 791c2c66affSColin Finck parent_wnd, (HMENU)(DWORD_PTR)1, GetModuleHandleA(NULL), 0); 792c2c66affSColin Finck ok(updown != NULL, "Failed to create updown control\n"); 793c2c66affSColin Finck r.bottom = 0; 794c2c66affSColin Finck GetClientRect(updown, &r); 795c2c66affSColin Finck ok(r.bottom == 0, "Expected zero height, got %d\n", r.bottom); 796c2c66affSColin Finck DestroyWindow(updown); 797c2c66affSColin Finck /* create with really small height, UDS_HORZ */ 798c2c66affSColin Finck updown = CreateWindowA (UPDOWN_CLASSA, 0, UDS_HORZ | WS_CHILD | WS_BORDER | WS_VISIBLE, 0, 0, 0, 2, 799c2c66affSColin Finck parent_wnd, (HMENU)(DWORD_PTR)1, GetModuleHandleA(NULL), 0); 800c2c66affSColin Finck ok(updown != NULL, "Failed to create updown control\n"); 801c2c66affSColin Finck r.bottom = 0; 802c2c66affSColin Finck GetClientRect(updown, &r); 803c2c66affSColin Finck ok(r.bottom == 0, "Expected zero height, got %d\n", r.bottom); 804c2c66affSColin Finck DestroyWindow(updown); 805c2c66affSColin Finck /* create with height greater than default, UDS_HORZ */ 806c2c66affSColin Finck updown = CreateWindowA (UPDOWN_CLASSA, 0, UDS_HORZ | WS_CHILD | WS_BORDER | WS_VISIBLE, 0, 0, 0, 100, 807c2c66affSColin Finck parent_wnd, (HMENU)(DWORD_PTR)1, GetModuleHandleA(NULL), 0); 808c2c66affSColin Finck ok(updown != NULL, "Failed to create updown control\n"); 809c2c66affSColin Finck r.bottom = 0; 810c2c66affSColin Finck GetClientRect(updown, &r); 811c2c66affSColin Finck ok(r.bottom < 100 && r.bottom > 0, "Expected default height, got %d\n", r.bottom); 812c2c66affSColin Finck DestroyWindow(updown); 813c2c66affSColin Finck } 814c2c66affSColin Finck 815c2c66affSColin Finck static void test_UDS_SETBUDDYINT(void) 816c2c66affSColin Finck { 817c2c66affSColin Finck HWND updown; 818c2c66affSColin Finck DWORD style, ret; 819c2c66affSColin Finck CHAR text[10]; 820c2c66affSColin Finck 821c2c66affSColin Finck /* cleanup buddy */ 822c2c66affSColin Finck text[0] = '\0'; 823c2c66affSColin Finck SetWindowTextA(g_edit, text); 824c2c66affSColin Finck 825c2c66affSColin Finck /* creating without UDS_SETBUDDYINT */ 826c2c66affSColin Finck updown = create_updown_control(UDS_ALIGNRIGHT, g_edit); 827c2c66affSColin Finck /* try to set UDS_SETBUDDYINT after creation */ 828c2c66affSColin Finck style = GetWindowLongA(updown, GWL_STYLE); 829c2c66affSColin Finck SetWindowLongA(updown, GWL_STYLE, style | UDS_SETBUDDYINT); 830c2c66affSColin Finck style = GetWindowLongA(updown, GWL_STYLE); 831c2c66affSColin Finck ok(style & UDS_SETBUDDYINT, "Expected UDS_SETBUDDY to be set\n"); 832c2c66affSColin Finck SendMessageA(updown, UDM_SETPOS, 0, 20); 833c2c66affSColin Finck GetWindowTextA(g_edit, text, sizeof(text)/sizeof(CHAR)); 834c2c66affSColin Finck ok(lstrlenA(text) == 0, "Expected empty string\n"); 835c2c66affSColin Finck DestroyWindow(updown); 836c2c66affSColin Finck 837c2c66affSColin Finck /* creating with UDS_SETBUDDYINT */ 838c2c66affSColin Finck updown = create_updown_control(UDS_SETBUDDYINT | UDS_ALIGNRIGHT, g_edit); 839c2c66affSColin Finck GetWindowTextA(g_edit, text, sizeof(text)/sizeof(CHAR)); 840c2c66affSColin Finck /* 50 is initial value here */ 841c2c66affSColin Finck ok(lstrcmpA(text, "50") == 0, "Expected '50', got '%s'\n", text); 842c2c66affSColin Finck /* now remove style flag */ 843c2c66affSColin Finck style = GetWindowLongA(updown, GWL_STYLE); 844c2c66affSColin Finck SetWindowLongA(updown, GWL_STYLE, style & ~UDS_SETBUDDYINT); 845c2c66affSColin Finck SendMessageA(updown, UDM_SETPOS, 0, 20); 846c2c66affSColin Finck GetWindowTextA(g_edit, text, sizeof(text)/sizeof(CHAR)); 847c2c66affSColin Finck ok(lstrcmpA(text, "20") == 0, "Expected '20', got '%s'\n", text); 848c2c66affSColin Finck /* set edit text directly, check position */ 849c2c66affSColin Finck strcpy(text, "10"); 850c2c66affSColin Finck SetWindowTextA(g_edit, text); 851c2c66affSColin Finck ret = SendMessageA(updown, UDM_GETPOS, 0, 0); 852c2c66affSColin Finck expect(10, ret); 853c2c66affSColin Finck strcpy(text, "11"); 854c2c66affSColin Finck SetWindowTextA(g_edit, text); 855c2c66affSColin Finck ret = SendMessageA(updown, UDM_GETPOS, 0, 0); 856c2c66affSColin Finck expect(11, LOWORD(ret)); 857c2c66affSColin Finck expect(0, HIWORD(ret)); 858c2c66affSColin Finck /* set to invalid value */ 859c2c66affSColin Finck strcpy(text, "21st"); 860c2c66affSColin Finck SetWindowTextA(g_edit, text); 861c2c66affSColin Finck ret = SendMessageA(updown, UDM_GETPOS, 0, 0); 862c2c66affSColin Finck expect(11, LOWORD(ret)); 863c2c66affSColin Finck expect(TRUE, HIWORD(ret)); 864c2c66affSColin Finck /* set style back */ 865c2c66affSColin Finck style = GetWindowLongA(updown, GWL_STYLE); 866c2c66affSColin Finck SetWindowLongA(updown, GWL_STYLE, style | UDS_SETBUDDYINT); 867c2c66affSColin Finck SendMessageA(updown, UDM_SETPOS, 0, 30); 868c2c66affSColin Finck GetWindowTextA(g_edit, text, sizeof(text)/sizeof(CHAR)); 869c2c66affSColin Finck ok(lstrcmpA(text, "30") == 0, "Expected '30', got '%s'\n", text); 870c2c66affSColin Finck DestroyWindow(updown); 871c2c66affSColin Finck } 872c2c66affSColin Finck 873*0d320bc2SAmine Khaldi static void test_CreateUpDownControl(void) 874*0d320bc2SAmine Khaldi { 875*0d320bc2SAmine Khaldi HWND updown, buddy; 876*0d320bc2SAmine Khaldi DWORD range, pos; 877*0d320bc2SAmine Khaldi RECT rect; 878*0d320bc2SAmine Khaldi 879*0d320bc2SAmine Khaldi GetClientRect(parent_wnd, &rect); 880*0d320bc2SAmine Khaldi updown = CreateUpDownControl(WS_CHILD | WS_BORDER | WS_VISIBLE, 881*0d320bc2SAmine Khaldi 0, 0, rect.right, rect.bottom, parent_wnd, 1, GetModuleHandleA(NULL), g_edit, 100, 10, 50); 882*0d320bc2SAmine Khaldi ok(updown != NULL, "Failed to create control.\n"); 883*0d320bc2SAmine Khaldi 884*0d320bc2SAmine Khaldi buddy = (HWND)SendMessageA(updown, UDM_GETBUDDY, 0, 0); 885*0d320bc2SAmine Khaldi ok(buddy == g_edit, "Unexpected buddy window.\n"); 886*0d320bc2SAmine Khaldi 887*0d320bc2SAmine Khaldi range = SendMessageA(updown, UDM_GETRANGE, 0, 0); 888*0d320bc2SAmine Khaldi ok(range == MAKELONG(100, 10), "Unexpected range.\n"); 889*0d320bc2SAmine Khaldi 890*0d320bc2SAmine Khaldi pos = SendMessageA(updown, UDM_GETPOS, 0, 0); 891*0d320bc2SAmine Khaldi ok(pos == MAKELONG(50, 1), "Unexpected position.\n"); 892*0d320bc2SAmine Khaldi 893*0d320bc2SAmine Khaldi DestroyWindow(updown); 894*0d320bc2SAmine Khaldi } 895*0d320bc2SAmine Khaldi 896c2c66affSColin Finck START_TEST(updown) 897c2c66affSColin Finck { 898c2c66affSColin Finck HMODULE mod = GetModuleHandleA("comctl32.dll"); 899c2c66affSColin Finck 900c2c66affSColin Finck pSetWindowSubclass = (void*)GetProcAddress(mod, (LPSTR)410); 901c2c66affSColin Finck 902c2c66affSColin Finck InitCommonControls(); 903c2c66affSColin Finck init_msg_sequences(sequences, NUM_MSG_SEQUENCES); 904c2c66affSColin Finck 905c2c66affSColin Finck parent_wnd = create_parent_window(); 906c2c66affSColin Finck ok(parent_wnd != NULL, "Failed to create parent window!\n"); 907c2c66affSColin Finck g_edit = create_edit_control(); 908c2c66affSColin Finck ok(g_edit != NULL, "Failed to create edit control\n"); 909c2c66affSColin Finck 910c2c66affSColin Finck test_updown_create(); 911c2c66affSColin Finck test_updown_pos(); 912c2c66affSColin Finck test_updown_pos32(); 913c2c66affSColin Finck test_updown_buddy(); 914c2c66affSColin Finck test_updown_base(); 915c2c66affSColin Finck test_updown_unicode(); 916c2c66affSColin Finck test_UDS_SETBUDDYINT(); 917*0d320bc2SAmine Khaldi test_CreateUpDownControl(); 918c2c66affSColin Finck 919c2c66affSColin Finck DestroyWindow(g_edit); 920c2c66affSColin Finck DestroyWindow(parent_wnd); 921c2c66affSColin Finck } 922