comctl32: Add trackbar tests.
[wine] / dlls / comctl32 / tests / trackbar.c
1 /* Unit tests for the track bar control.
2  *
3  * Copyright 2007 Keith Stevens
4  *
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.
9  *
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.
14 */
15
16 #include <assert.h>
17 #include <windows.h>
18 #include <commctrl.h>
19 #include <stdio.h>
20
21 #include "wine/test.h"
22 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
23
24 static HWND create_trackbar(DWORD style)
25 {
26     HWND hWndTrack;
27
28     hWndTrack = CreateWindowEx(
29       0, TRACKBAR_CLASS,"Trackbar Control", style,
30       10, 10, 200, 200, NULL, NULL,NULL ,NULL);
31
32     return hWndTrack;
33 }
34
35 static void test_trackbar_control(void)
36 {
37     HWND hWndTrackbar;
38     DWORD style = WS_VISIBLE | TBS_TOOLTIPS | TBS_ENABLESELRANGE | TBS_FIXEDLENGTH | TBS_AUTOTICKS;
39     int r;
40     HWND hWndLeftBuddy;
41     HWND hWndRightBuddy;
42     HWND hWndCurrentBuddy;
43     HWND hWndTooltip;
44     HWND rTest;
45     DWORD *rPTics;
46
47     hWndTrackbar = create_trackbar(style);
48
49     ok(hWndTrackbar != NULL, "Expected non NULL value");
50
51     if (hWndTrackbar == NULL){
52       skip("trackbar control not present?\n");
53       return;
54     }
55
56     /* TEST OF ALL SETTER and GETTER MESSAGES with required styles turned on*/
57
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");
62
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");
69     } else
70         skip ("left buddy control not present?\n");
71
72     hWndRightBuddy = (HWND) CreateWindowEx(0, STATUSCLASSNAME, NULL, 0,
73         0,0,300,20,NULL,NULL, NULL, NULL);
74
75     ok(hWndRightBuddy != NULL, "expected non NULL value");
76
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");
83      } else
84         skip("Right buddy control not present?\n");
85
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);
91     }
92     if (hWndRightBuddy != NULL){
93         rTest = (HWND) SendMessage(hWndTrackbar, TBM_GETBUDDY, TRUE,0);
94         ok(rTest == hWndRightBuddy, "Expected hWndRightBuddy\n");
95         DestroyWindow(hWndRightBuddy);
96     }
97
98     /* test TBM_SETLINESIZE */
99     r = SendMessage(hWndTrackbar, TBM_SETLINESIZE, 0, 10);
100     r = SendMessage(hWndTrackbar, TBM_SETLINESIZE, 0, 4);
101     expect(10, r);
102
103     /* test TBM_GETLINESIZE */
104     r = SendMessage(hWndTrackbar, TBM_GETLINESIZE, 0,0);
105     expect(4, r);
106
107     /* test TBM_SETPAGESIZE */
108     r = SendMessage(hWndTrackbar, TBM_SETPAGESIZE, 0, 10);
109     expect(20, r);
110     r = SendMessage(hWndTrackbar, TBM_SETPAGESIZE, 0, -1);
111     expect(10, r);
112
113     /* test TBM_GETPAGESIZE */
114     todo_wine{
115         r = SendMessage(hWndTrackbar, TBM_GETPAGESIZE, 0,0);
116         expect(20, r);
117     }
118
119     /* test TBM_SETPOS */
120     SendMessage(hWndTrackbar, TBM_SETPOS, TRUE, -1);
121     r = SendMessage(hWndTrackbar, TBM_GETPOS, 0, 0);
122     expect(0, r);
123     SendMessage(hWndTrackbar, TBM_SETPOS, TRUE, 5);
124     r = SendMessage(hWndTrackbar, TBM_GETPOS, 0,0);
125     expect(5, r);
126     SendMessage(hWndTrackbar, TBM_SETPOS, TRUE, 1000);
127     r = SendMessage(hWndTrackbar, TBM_GETPOS, 0,0);
128     expect(100, r);
129     SendMessage(hWndTrackbar, TBM_SETPOS, FALSE, 20);
130     r = SendMessage(hWndTrackbar, TBM_GETPOS, 0,0);
131     expect(20, r);
132
133     /* test TBM_GETPOS */
134     r = SendMessage(hWndTrackbar, TBM_GETPOS, 0,0);
135     expect(20, r);
136
137     /* test TBM_SETRANGE */
138     SendMessage(hWndTrackbar, TBM_SETRANGE, TRUE, MAKELONG(0, 10));
139     r = SendMessage(hWndTrackbar, TBM_GETRANGEMAX, 0,0);
140     expect(10, r);
141     r = SendMessage(hWndTrackbar, TBM_GETRANGEMIN, 0,0);
142     expect(0, r);
143     SendMessage(hWndTrackbar, TBM_SETRANGE, TRUE, MAKELONG(-1, 1000));
144     r = SendMessage(hWndTrackbar, TBM_GETRANGEMAX, 0,0);
145     expect(1000, r);
146     r = SendMessage(hWndTrackbar, TBM_GETRANGEMIN, 0,0);
147     expect(-1, r);
148     SendMessage(hWndTrackbar, TBM_SETRANGE, TRUE, MAKELONG(10, 0));
149     r = SendMessage(hWndTrackbar, TBM_GETRANGEMAX, 0,0);
150     expect(0, r);
151     r = SendMessage(hWndTrackbar, TBM_GETRANGEMIN, 0,0);
152     expect(10, r);
153     SendMessage(hWndTrackbar, TBM_SETRANGE, FALSE, MAKELONG(0,10));
154     r = SendMessage(hWndTrackbar, TBM_GETRANGEMAX, 0,0);
155     expect(10, r);
156     r = SendMessage(hWndTrackbar, TBM_GETRANGEMIN, 0,0);
157     expect(0, r);
158
159     /*test TBM_SETRANGEMAX */
160     SendMessage(hWndTrackbar, TBM_SETRANGEMAX, TRUE, 10);
161     r = SendMessage(hWndTrackbar, TBM_GETRANGEMAX, 0,0);
162     expect(10, r);
163     SendMessage(hWndTrackbar, TBM_SETRANGEMAX, TRUE, -1);
164     r = SendMessage(hWndTrackbar, TBM_GETRANGEMAX, 0,0);
165     expect(-1, r);
166     SendMessage(hWndTrackbar, TBM_SETRANGEMAX, FALSE, 10);
167     r = SendMessage(hWndTrackbar, TBM_GETRANGEMAX, 0,0);
168     expect(10, r);
169
170     /* testing TBM_SETRANGEMIN */
171     SendMessage(hWndTrackbar, TBM_SETRANGEMIN, TRUE, 0);
172     r = SendMessage(hWndTrackbar, TBM_GETRANGEMIN, 0,0);
173     expect(0, r);
174     SendMessage(hWndTrackbar, TBM_SETRANGEMIN, TRUE, 10);
175     r = SendMessage(hWndTrackbar, TBM_GETRANGEMIN, 0,0);
176     expect(10, r);
177     SendMessage(hWndTrackbar, TBM_SETRANGEMIN, TRUE, -10);
178     r = SendMessage(hWndTrackbar, TBM_GETRANGEMIN, 0,0);
179     expect(-10, r);
180     SendMessage(hWndTrackbar, TBM_SETRANGEMIN, FALSE, 5);
181     r = SendMessage(hWndTrackbar, TBM_GETRANGEMIN, 0,0);
182     expect(5, r);
183
184     /* test TBM_GETRANGEMAX */
185     r = SendMessage(hWndTrackbar, TBM_GETRANGEMAX, 0,0);
186     expect(10, r);
187
188     /* test TBM_GETRANGEMIN */
189     r = SendMessage(hWndTrackbar, TBM_GETRANGEMIN, 0,0);
190     expect(5, r);
191
192     /* test TBM_SETSEL */
193     SendMessage(hWndTrackbar, TBM_SETSEL, TRUE, MAKELONG(0,10));
194     r = SendMessage(hWndTrackbar, TBM_GETSELEND, 0,0);
195     expect(10, r);
196     r = SendMessage(hWndTrackbar, TBM_GETSELSTART, 0,0);
197     expect(5, r);
198     SendMessage(hWndTrackbar, TBM_SETSEL, TRUE, MAKELONG(5, 20));
199     r = SendMessage(hWndTrackbar, TBM_GETSELEND, 0,0);
200     expect(10, r);
201     r = SendMessage(hWndTrackbar, TBM_GETSELSTART, 0,0);
202     expect(5, r);
203     SendMessage(hWndTrackbar, TBM_SETSEL, FALSE, MAKELONG(5, 10));
204     r = SendMessage(hWndTrackbar, TBM_GETSELEND, 0,0);
205     expect(10, r);
206     r = SendMessage(hWndTrackbar, TBM_GETSELSTART, 0,0);
207     expect(5, r);
208
209     /* test TBM_SETSELEND */
210     SendMessage(hWndTrackbar, TBM_SETSELEND, TRUE, 10);
211     r = SendMessage(hWndTrackbar, TBM_GETSELEND, 0,0);
212     expect(10, r);
213     SendMessage(hWndTrackbar, TBM_SETSELEND, TRUE, 20);
214     r = SendMessage(hWndTrackbar, TBM_GETSELEND, 0,0);
215     expect(10, r);
216     SendMessage(hWndTrackbar, TBM_SETSELEND, TRUE, 4);
217     r = SendMessage(hWndTrackbar, TBM_GETSELEND, 0,0);
218     expect(4, r);
219     SendMessage(hWndTrackbar, TBM_SETSELEND, FALSE, 2);
220     r = SendMessage(hWndTrackbar, TBM_GETSELEND, 0,0);
221     expect(2, r);
222
223     /* test TBM_GETSELEND */
224     r = SendMessage(hWndTrackbar, TBM_GETSELEND, 0,0);
225     expect(2, r);
226
227     /* testing TBM_SETSELSTART */
228     SendMessage(hWndTrackbar, TBM_SETSELSTART, TRUE, 5);
229     r = SendMessage(hWndTrackbar, TBM_GETSELSTART, 0,0);
230     expect(5, r);
231     SendMessage(hWndTrackbar, TBM_SETSELSTART, TRUE, 0);
232     r = SendMessage(hWndTrackbar, TBM_GETSELSTART, 0,0);
233     expect(5, r);
234     SendMessage(hWndTrackbar, TBM_SETSELSTART, TRUE, 20);
235     r = SendMessage(hWndTrackbar, TBM_GETSELSTART, 0,0);
236     expect(20, r);
237     SendMessage(hWndTrackbar, TBM_SETSELSTART, FALSE, 8);
238     r = SendMessage(hWndTrackbar, TBM_GETSELSTART, 0,0);
239     expect(8, r);
240
241     /* test TBM_GETSELSTART */
242     r = SendMessage(hWndTrackbar, TBM_GETSELSTART, 0,0);
243     expect(8, r);
244
245     /* testing TBM_SETTHUMBLENGTH */
246     SendMessage(hWndTrackbar, TBM_SETTHUMBLENGTH, 15, 0);
247     r = SendMessage(hWndTrackbar, TBM_GETTHUMBLENGTH, 0,0);
248     expect(15, r);
249     SendMessage(hWndTrackbar, TBM_SETTHUMBLENGTH, 20, 0);
250     r = SendMessage(hWndTrackbar, TBM_GETTHUMBLENGTH, 0,0);
251     expect(20, r);
252
253     /* test TBM_GETTHUMBLENGTH */
254     r = SendMessage(hWndTrackbar, TBM_GETTHUMBLENGTH, 0,0);
255     expect(20, r);
256
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);
262     todo_wine{
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);
267     }
268     r = SendMessage(hWndTrackbar, TBM_SETTIC, 0, 20);
269     ok(r == FALSE, "Expected False, got %d\n", r);
270
271     /* test TBM_SETTICFREQ */
272     SendMessage(hWndTrackbar, TBM_SETRANGE, TRUE, MAKELONG(0, 10));
273     todo_wine{
274         SendMessage(hWndTrackbar, TBM_SETTICFREQ, 2, 0);
275         r = SendMessage(hWndTrackbar, TBM_GETNUMTICS, 0,0);
276         expect(6, r);
277         SendMessage(hWndTrackbar, TBM_SETTICFREQ, 5, 0);
278         r = SendMessage(hWndTrackbar, TBM_GETNUMTICS, 0,0);
279         expect(3, r);
280     }
281     SendMessage(hWndTrackbar, TBM_SETTICFREQ, 15, 0);
282     r = SendMessage(hWndTrackbar, TBM_GETNUMTICS, 0,0);
283     expect(2, r);
284
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);
288     expect(2, r);
289
290     /* test TBM_GETPTICS */
291     todo_wine{
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]);
297     }
298
299     /* test TBM_GETTIC */
300     todo_wine{
301         r = SendMessage(hWndTrackbar, TBM_GETTIC, 0,0);
302         expect(1, r);
303         r = SendMessage(hWndTrackbar, TBM_GETTIC, 4,0);
304         expect(5, r);
305     }
306     r = SendMessage(hWndTrackbar, TBM_GETTIC, 11,0);
307     expect(-1, r);
308
309     /* test TBM_GETTICPIC */
310     todo_wine{
311         r = SendMessage(hWndTrackbar, TBM_GETTICPOS, 0, 0);
312         expect(28, r);
313         r = SendMessage(hWndTrackbar, TBM_GETTICPOS, 4, 0);
314         expect(97, r);
315     }
316
317     /* testing TBM_SETTIPSIDE */
318     todo_wine{
319         r = SendMessage(hWndTrackbar, TBM_SETTIPSIDE, TBTS_TOP, 0);
320         expect(0, r);
321     }
322     r = SendMessage(hWndTrackbar, TBM_SETTIPSIDE, TBTS_LEFT, 0);
323     expect(0, r);
324     r = SendMessage(hWndTrackbar, TBM_SETTIPSIDE, TBTS_BOTTOM, 0);
325     expect(1, r);
326     r = SendMessage(hWndTrackbar, TBM_SETTIPSIDE, TBTS_RIGHT, 0);
327     expect(2, r);
328
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);
333
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");
345     } else
346         skip("tool tip control not present?\n");
347
348     /* test TBM_GETTOOLTIPS */
349     rTest = (HWND) SendMessage(hWndTrackbar, TBM_GETTOOLTIPS, 0,0);
350     ok(rTest == hWndTooltip, "Expected hWndTooltip\n");
351
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);
357
358     /* test TBM_GETUNICODEFORMAT */
359     r = SendMessage(hWndTrackbar, TBM_GETUNICODEFORMAT, 0,0);
360     ok(r == FALSE, "Expected FALSE, got %d\n",r);
361
362     DestroyWindow(hWndTrackbar);
363
364     /* test getters and setters without styles set */
365     hWndTrackbar = create_trackbar(0);
366
367     ok(hWndTrackbar != NULL, "Expected non NULL value");
368
369     if (hWndTrackbar == NULL){
370       skip("trackbar control not present?\n");
371       return;
372     }
373
374     /* test TBM_SETSEL  ensure that it is ignored */
375     todo_wine{
376         SendMessage(hWndTrackbar, TBM_SETSEL, TRUE, MAKELONG(0,10));
377         r = SendMessage(hWndTrackbar, TBM_GETSELEND, 0,0);
378         expect(0, r);
379     }
380     r = SendMessage(hWndTrackbar, TBM_GETSELSTART, 0,0);
381     expect(0, r);
382     todo_wine{
383         SendMessage(hWndTrackbar, TBM_SETSEL, FALSE, MAKELONG(0,10));
384         r = SendMessage(hWndTrackbar, TBM_GETSELEND, 0,0);
385         expect(0, r);
386     }
387     r = SendMessage(hWndTrackbar, TBM_GETSELSTART, 0,0);
388     expect(0, r);
389
390     /* test TBM_SETSELEND, ensure that it is ignored */
391     SendMessage(hWndTrackbar, TBM_SETSELEND, TRUE, 0);
392     r = SendMessage(hWndTrackbar, TBM_GETSELEND, 0,0);
393     expect(0, r);
394     SendMessage(hWndTrackbar, TBM_SETSELEND, FALSE, 0);
395     r = SendMessage(hWndTrackbar, TBM_GETSELEND, 0,0);
396     expect(0, r);
397
398     /* test TBM_SETSELSTART, ensure that it is ignored */
399     SendMessage(hWndTrackbar, TBM_SETSELSTART, TRUE, 0);
400     r = SendMessage(hWndTrackbar, TBM_GETSELSTART, 0,0);
401     expect(0, r);
402     SendMessage(hWndTrackbar, TBM_SETSELSTART, FALSE, 0);
403     r = SendMessage(hWndTrackbar, TBM_GETSELSTART, 0,0);
404     expect(0, r);
405
406     DestroyWindow(hWndTrackbar);
407 }
408
409
410
411 START_TEST(trackbar)
412 {
413     InitCommonControls();
414
415     test_trackbar_control();
416 }