1 /* Unit tests for the track bar control.
3 * Copyright 2007 Keith Stevens
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
21 #include "wine/test.h"
22 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
24 static HWND create_trackbar(DWORD style)
28 hWndTrack = CreateWindowEx(
29 0, TRACKBAR_CLASS,"Trackbar Control", style,
30 10, 10, 200, 200, NULL, NULL,NULL ,NULL);
35 static void test_trackbar_control(void)
38 DWORD style = WS_VISIBLE | TBS_TOOLTIPS | TBS_ENABLESELRANGE | TBS_FIXEDLENGTH | TBS_AUTOTICKS;
42 HWND hWndCurrentBuddy;
47 hWndTrackbar = create_trackbar(style);
49 ok(hWndTrackbar != NULL, "Expected non NULL value\n");
51 if (hWndTrackbar == NULL){
52 skip("trackbar control not present?\n");
56 /* TEST OF ALL SETTER and GETTER MESSAGES with required styles turned on*/
58 /* test TBM_SETBUDDY */
59 hWndLeftBuddy = (HWND) CreateWindowEx(0, STATUSCLASSNAME, NULL, 0,
60 0,0,300,20, NULL, NULL, NULL, NULL);
61 ok(hWndLeftBuddy != NULL, "Expected non NULL value\n");
63 if (hWndLeftBuddy != NULL){
64 hWndCurrentBuddy = (HWND) SendMessage(hWndTrackbar, TBM_GETBUDDY, TRUE, 0);
65 rTest = (HWND) SendMessage(hWndTrackbar, TBM_SETBUDDY, FALSE, (LPARAM) hWndLeftBuddy);
66 ok(rTest == hWndCurrentBuddy, "Expected hWndCurrentBuddy\n");
67 rTest = (HWND) SendMessage(hWndTrackbar, TBM_SETBUDDY, FALSE, (LPARAM) hWndLeftBuddy);
68 ok(rTest == hWndLeftBuddy, "Expected hWndLeftBuddy\n");
70 skip ("left buddy control not present?\n");
72 hWndRightBuddy = (HWND) CreateWindowEx(0, STATUSCLASSNAME, NULL, 0,
73 0,0,300,20,NULL,NULL, NULL, NULL);
75 ok(hWndRightBuddy != NULL, "expected non NULL value\n");
77 if (hWndRightBuddy != NULL){
78 hWndCurrentBuddy = (HWND) SendMessage(hWndTrackbar, TBM_GETBUDDY, TRUE, 0);
79 rTest = (HWND) SendMessage(hWndTrackbar, TBM_SETBUDDY, TRUE, (LPARAM) hWndRightBuddy);
80 ok(rTest == hWndCurrentBuddy, "Expected hWndCurrentBuddy\n");
81 rTest = (HWND) SendMessage(hWndTrackbar, TBM_SETBUDDY, TRUE, (LPARAM) hWndRightBuddy);
82 ok(rTest == hWndRightBuddy, "Expected hWndRightbuddy\n");
84 skip("Right buddy control not present?\n");
86 /* test TBM_GETBUDDY */
87 if (hWndLeftBuddy != NULL){
88 rTest = (HWND) SendMessage(hWndTrackbar, TBM_GETBUDDY, FALSE, 0);
89 ok(rTest == hWndLeftBuddy, "Expected hWndLeftBuddy\n");
90 DestroyWindow(hWndLeftBuddy);
92 if (hWndRightBuddy != NULL){
93 rTest = (HWND) SendMessage(hWndTrackbar, TBM_GETBUDDY, TRUE,0);
94 ok(rTest == hWndRightBuddy, "Expected hWndRightBuddy\n");
95 DestroyWindow(hWndRightBuddy);
98 /* test TBM_SETLINESIZE */
99 r = SendMessage(hWndTrackbar, TBM_SETLINESIZE, 0, 10);
100 r = SendMessage(hWndTrackbar, TBM_SETLINESIZE, 0, 4);
103 /* test TBM_GETLINESIZE */
104 r = SendMessage(hWndTrackbar, TBM_GETLINESIZE, 0,0);
107 /* test TBM_SETPAGESIZE */
108 r = SendMessage(hWndTrackbar, TBM_SETPAGESIZE, 0, 10);
110 r = SendMessage(hWndTrackbar, TBM_SETPAGESIZE, 0, -1);
113 /* test TBM_GETPAGESIZE */
115 r = SendMessage(hWndTrackbar, TBM_GETPAGESIZE, 0,0);
119 /* test TBM_SETPOS */
120 SendMessage(hWndTrackbar, TBM_SETPOS, TRUE, -1);
121 r = SendMessage(hWndTrackbar, TBM_GETPOS, 0, 0);
123 SendMessage(hWndTrackbar, TBM_SETPOS, TRUE, 5);
124 r = SendMessage(hWndTrackbar, TBM_GETPOS, 0,0);
126 SendMessage(hWndTrackbar, TBM_SETPOS, TRUE, 1000);
127 r = SendMessage(hWndTrackbar, TBM_GETPOS, 0,0);
129 SendMessage(hWndTrackbar, TBM_SETPOS, FALSE, 20);
130 r = SendMessage(hWndTrackbar, TBM_GETPOS, 0,0);
133 /* test TBM_GETPOS */
134 r = SendMessage(hWndTrackbar, TBM_GETPOS, 0,0);
137 /* test TBM_SETRANGE */
138 SendMessage(hWndTrackbar, TBM_SETRANGE, TRUE, MAKELONG(0, 10));
139 r = SendMessage(hWndTrackbar, TBM_GETRANGEMAX, 0,0);
141 r = SendMessage(hWndTrackbar, TBM_GETRANGEMIN, 0,0);
143 SendMessage(hWndTrackbar, TBM_SETRANGE, TRUE, MAKELONG(-1, 1000));
144 r = SendMessage(hWndTrackbar, TBM_GETRANGEMAX, 0,0);
146 r = SendMessage(hWndTrackbar, TBM_GETRANGEMIN, 0,0);
148 SendMessage(hWndTrackbar, TBM_SETRANGE, TRUE, MAKELONG(10, 0));
149 r = SendMessage(hWndTrackbar, TBM_GETRANGEMAX, 0,0);
151 r = SendMessage(hWndTrackbar, TBM_GETRANGEMIN, 0,0);
153 SendMessage(hWndTrackbar, TBM_SETRANGE, FALSE, MAKELONG(0,10));
154 r = SendMessage(hWndTrackbar, TBM_GETRANGEMAX, 0,0);
156 r = SendMessage(hWndTrackbar, TBM_GETRANGEMIN, 0,0);
159 /*test TBM_SETRANGEMAX */
160 SendMessage(hWndTrackbar, TBM_SETRANGEMAX, TRUE, 10);
161 r = SendMessage(hWndTrackbar, TBM_GETRANGEMAX, 0,0);
163 SendMessage(hWndTrackbar, TBM_SETRANGEMAX, TRUE, -1);
164 r = SendMessage(hWndTrackbar, TBM_GETRANGEMAX, 0,0);
166 SendMessage(hWndTrackbar, TBM_SETRANGEMAX, FALSE, 10);
167 r = SendMessage(hWndTrackbar, TBM_GETRANGEMAX, 0,0);
170 /* testing TBM_SETRANGEMIN */
171 SendMessage(hWndTrackbar, TBM_SETRANGEMIN, TRUE, 0);
172 r = SendMessage(hWndTrackbar, TBM_GETRANGEMIN, 0,0);
174 SendMessage(hWndTrackbar, TBM_SETRANGEMIN, TRUE, 10);
175 r = SendMessage(hWndTrackbar, TBM_GETRANGEMIN, 0,0);
177 SendMessage(hWndTrackbar, TBM_SETRANGEMIN, TRUE, -10);
178 r = SendMessage(hWndTrackbar, TBM_GETRANGEMIN, 0,0);
180 SendMessage(hWndTrackbar, TBM_SETRANGEMIN, FALSE, 5);
181 r = SendMessage(hWndTrackbar, TBM_GETRANGEMIN, 0,0);
184 /* test TBM_GETRANGEMAX */
185 r = SendMessage(hWndTrackbar, TBM_GETRANGEMAX, 0,0);
188 /* test TBM_GETRANGEMIN */
189 r = SendMessage(hWndTrackbar, TBM_GETRANGEMIN, 0,0);
192 /* test TBM_SETSEL */
193 SendMessage(hWndTrackbar, TBM_SETSEL, TRUE, MAKELONG(0,10));
194 r = SendMessage(hWndTrackbar, TBM_GETSELEND, 0,0);
196 r = SendMessage(hWndTrackbar, TBM_GETSELSTART, 0,0);
198 SendMessage(hWndTrackbar, TBM_SETSEL, TRUE, MAKELONG(5, 20));
199 r = SendMessage(hWndTrackbar, TBM_GETSELEND, 0,0);
201 r = SendMessage(hWndTrackbar, TBM_GETSELSTART, 0,0);
203 SendMessage(hWndTrackbar, TBM_SETSEL, FALSE, MAKELONG(5, 10));
204 r = SendMessage(hWndTrackbar, TBM_GETSELEND, 0,0);
206 r = SendMessage(hWndTrackbar, TBM_GETSELSTART, 0,0);
209 /* test TBM_SETSELEND */
210 SendMessage(hWndTrackbar, TBM_SETSELEND, TRUE, 10);
211 r = SendMessage(hWndTrackbar, TBM_GETSELEND, 0,0);
213 SendMessage(hWndTrackbar, TBM_SETSELEND, TRUE, 20);
214 r = SendMessage(hWndTrackbar, TBM_GETSELEND, 0,0);
216 SendMessage(hWndTrackbar, TBM_SETSELEND, TRUE, 4);
217 r = SendMessage(hWndTrackbar, TBM_GETSELEND, 0,0);
219 SendMessage(hWndTrackbar, TBM_SETSELEND, FALSE, 2);
220 r = SendMessage(hWndTrackbar, TBM_GETSELEND, 0,0);
223 /* test TBM_GETSELEND */
224 r = SendMessage(hWndTrackbar, TBM_GETSELEND, 0,0);
227 /* testing TBM_SETSELSTART */
228 SendMessage(hWndTrackbar, TBM_SETSELSTART, TRUE, 5);
229 r = SendMessage(hWndTrackbar, TBM_GETSELSTART, 0,0);
231 SendMessage(hWndTrackbar, TBM_SETSELSTART, TRUE, 0);
232 r = SendMessage(hWndTrackbar, TBM_GETSELSTART, 0,0);
234 SendMessage(hWndTrackbar, TBM_SETSELSTART, TRUE, 20);
235 r = SendMessage(hWndTrackbar, TBM_GETSELSTART, 0,0);
237 SendMessage(hWndTrackbar, TBM_SETSELSTART, FALSE, 8);
238 r = SendMessage(hWndTrackbar, TBM_GETSELSTART, 0,0);
241 /* test TBM_GETSELSTART */
242 r = SendMessage(hWndTrackbar, TBM_GETSELSTART, 0,0);
245 /* testing TBM_SETTHUMBLENGTH */
246 SendMessage(hWndTrackbar, TBM_SETTHUMBLENGTH, 15, 0);
247 r = SendMessage(hWndTrackbar, TBM_GETTHUMBLENGTH, 0,0);
249 SendMessage(hWndTrackbar, TBM_SETTHUMBLENGTH, 20, 0);
250 r = SendMessage(hWndTrackbar, TBM_GETTHUMBLENGTH, 0,0);
253 /* test TBM_GETTHUMBLENGTH */
254 r = SendMessage(hWndTrackbar, TBM_GETTHUMBLENGTH, 0,0);
257 /* testing TBM_SETTIC */
258 /* Set tics at 5 and 10 */
259 /* 0 and 20 are out of range and should not be set */
260 r = SendMessage(hWndTrackbar, TBM_SETTIC, 0, 0);
261 ok(r == FALSE, "Expected FALSE, got %d\n", r);
263 r = SendMessage(hWndTrackbar, TBM_SETTIC, 0, 5);
264 ok(r == TRUE, "Expected TRUE, got %d\n", r);
265 r = SendMessage(hWndTrackbar, TBM_SETTIC, 0, 10);
266 ok(r == TRUE, "Expected TRUE, got %d\n", r);
268 r = SendMessage(hWndTrackbar, TBM_SETTIC, 0, 20);
269 ok(r == FALSE, "Expected False, got %d\n", r);
271 /* test TBM_SETTICFREQ */
272 SendMessage(hWndTrackbar, TBM_SETRANGE, TRUE, MAKELONG(0, 10));
274 SendMessage(hWndTrackbar, TBM_SETTICFREQ, 2, 0);
275 r = SendMessage(hWndTrackbar, TBM_GETNUMTICS, 0,0);
277 SendMessage(hWndTrackbar, TBM_SETTICFREQ, 5, 0);
278 r = SendMessage(hWndTrackbar, TBM_GETNUMTICS, 0,0);
281 SendMessage(hWndTrackbar, TBM_SETTICFREQ, 15, 0);
282 r = SendMessage(hWndTrackbar, TBM_GETNUMTICS, 0,0);
285 /* test TBM_GETNUMTICS */
286 /* since TIC FREQ is 15, there should be only 2 tics now */
287 r = SendMessage(hWndTrackbar, TBM_GETNUMTICS, 0,0);
290 /* test TBM_GETPTICS */
292 rPTics = (DWORD *) SendMessage(hWndTrackbar, TBM_GETPTICS, 0,0);
293 expect(1, rPTics[0]);
294 expect(2, rPTics[1]);
295 expect(3, rPTics[2]);
296 expect(4, rPTics[3]);
299 /* test TBM_GETTIC */
301 r = SendMessage(hWndTrackbar, TBM_GETTIC, 0,0);
303 r = SendMessage(hWndTrackbar, TBM_GETTIC, 4,0);
306 r = SendMessage(hWndTrackbar, TBM_GETTIC, 11,0);
309 /* test TBM_GETTICPIC */
311 r = SendMessage(hWndTrackbar, TBM_GETTICPOS, 0, 0);
313 r = SendMessage(hWndTrackbar, TBM_GETTICPOS, 4, 0);
317 /* testing TBM_SETTIPSIDE */
319 r = SendMessage(hWndTrackbar, TBM_SETTIPSIDE, TBTS_TOP, 0);
322 r = SendMessage(hWndTrackbar, TBM_SETTIPSIDE, TBTS_LEFT, 0);
324 r = SendMessage(hWndTrackbar, TBM_SETTIPSIDE, TBTS_BOTTOM, 0);
326 r = SendMessage(hWndTrackbar, TBM_SETTIPSIDE, TBTS_RIGHT, 0);
329 /* testing TBM_SETTOOLTIPS */
330 hWndTooltip = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, 0,
331 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
332 NULL, NULL, NULL, NULL);
334 ok(hWndTooltip != NULL, "Expected non NULL value\n");
335 if (hWndTooltip != NULL){
336 SendMessage(hWndTrackbar, TBM_SETTOOLTIPS, (LPARAM) hWndTooltip, 0);
337 rTest = (HWND) SendMessage(hWndTrackbar, TBM_GETTOOLTIPS, 0,0);
338 ok(rTest == hWndTooltip, "Expected hWndToolTip, got\n");
339 SendMessage(hWndTrackbar, TBM_SETTOOLTIPS, (LPARAM) NULL, 0);
340 rTest = (HWND) SendMessage(hWndTrackbar, TBM_GETTOOLTIPS, 0,0);
341 ok(rTest == NULL, "Expected NULL\n");
342 SendMessage(hWndTrackbar, TBM_SETTOOLTIPS, (LPARAM) hWndTooltip, 5);
343 rTest = (HWND) SendMessage(hWndTrackbar, TBM_GETTOOLTIPS, 0,0);
344 ok(rTest == hWndTooltip, "Expected hWndTooltip, got\n");
346 skip("tool tip control not present?\n");
348 /* test TBM_GETTOOLTIPS */
349 rTest = (HWND) SendMessage(hWndTrackbar, TBM_GETTOOLTIPS, 0,0);
350 ok(rTest == hWndTooltip, "Expected hWndTooltip\n");
352 /* testing TBM_SETUNICODEFORMAT */
353 r = SendMessage(hWndTrackbar, TBM_SETUNICODEFORMAT, TRUE, 0);
354 ok(r == FALSE, "Expected FALSE, got %d\n",r);
355 r = SendMessage(hWndTrackbar, TBM_SETUNICODEFORMAT, FALSE, 0);
356 ok(r == TRUE, "Expected TRUE, got %d\n",r);
358 /* test TBM_GETUNICODEFORMAT */
359 r = SendMessage(hWndTrackbar, TBM_GETUNICODEFORMAT, 0,0);
360 ok(r == FALSE, "Expected FALSE, got %d\n",r);
362 DestroyWindow(hWndTrackbar);
364 /* test getters and setters without styles set */
365 hWndTrackbar = create_trackbar(0);
367 ok(hWndTrackbar != NULL, "Expected non NULL value\n");
369 if (hWndTrackbar == NULL){
370 skip("trackbar control not present?\n");
374 /* test TBM_SETSEL ensure that it is ignored */
376 SendMessage(hWndTrackbar, TBM_SETSEL, TRUE, MAKELONG(0,10));
377 r = SendMessage(hWndTrackbar, TBM_GETSELEND, 0,0);
380 r = SendMessage(hWndTrackbar, TBM_GETSELSTART, 0,0);
383 SendMessage(hWndTrackbar, TBM_SETSEL, FALSE, MAKELONG(0,10));
384 r = SendMessage(hWndTrackbar, TBM_GETSELEND, 0,0);
387 r = SendMessage(hWndTrackbar, TBM_GETSELSTART, 0,0);
390 /* test TBM_SETSELEND, ensure that it is ignored */
391 SendMessage(hWndTrackbar, TBM_SETSELEND, TRUE, 0);
392 r = SendMessage(hWndTrackbar, TBM_GETSELEND, 0,0);
394 SendMessage(hWndTrackbar, TBM_SETSELEND, FALSE, 0);
395 r = SendMessage(hWndTrackbar, TBM_GETSELEND, 0,0);
398 /* test TBM_SETSELSTART, ensure that it is ignored */
399 SendMessage(hWndTrackbar, TBM_SETSELSTART, TRUE, 0);
400 r = SendMessage(hWndTrackbar, TBM_GETSELSTART, 0,0);
402 SendMessage(hWndTrackbar, TBM_SETSELSTART, FALSE, 0);
403 r = SendMessage(hWndTrackbar, TBM_GETSELSTART, 0,0);
406 DestroyWindow(hWndTrackbar);
413 InitCommonControls();
415 test_trackbar_control();