2 * comctl32 month calendar unit tests
4 * Copyright (C) 2006 Vitaliy Margolen
5 * Copyright (C) 2007 Farshad Agah
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.
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.
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
30 #include "wine/test.h"
34 #define expect(expected, got) ok(expected == got, "Expected %d, got %d\n", expected, got);
36 static void test_monthcal(void)
39 SYSTEMTIME st[2], st1[2];
40 INITCOMMONCONTROLSEX ic = {sizeof(INITCOMMONCONTROLSEX), ICC_DATE_CLASSES};
43 InitCommonControlsEx(&ic);
44 hwnd = CreateWindowA(MONTHCAL_CLASSA, "MonthCal", WS_POPUP | WS_VISIBLE, CW_USEDEFAULT,
45 0, 300, 300, 0, 0, NULL, NULL);
46 ok(hwnd != NULL, "Failed to create MonthCal\n");
47 GetSystemTime(&st[0]);
50 /* Invalid date/time */
52 /* Time should not matter */
53 st[1].wHour = st[1].wMinute = st[1].wSecond = 70;
54 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set MAX limit\n");
55 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
56 ok(st1[0].wYear != 2000, "Lover limit changed\n");
59 ok(!SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Should have failed to set limits\n");
60 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
61 ok(st1[0].wYear != 2000, "Lover limit changed\n");
62 ok(!SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Should have failed to set MAX limit\n");
63 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
64 ok(st1[0].wYear != 2000, "Lover limit changed\n");
66 GetSystemTime(&st[0]);
71 month_range = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
73 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
74 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
75 ok(res == month_range, "Invalid month range (%d)\n", res);
76 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == (GDTR_MIN|GDTR_MAX), "Limits should be set\n");
79 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
80 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
81 ok(res == month_range, "Invalid month range (%d)\n", res);
84 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
86 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
89 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
90 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "Only MAX limit should be set\n");
92 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
94 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
96 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
97 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "Only MAX limit should be set\n");
102 static HWND create_monthcal_control(DWORD style)
105 static const INITCOMMONCONTROLSEX ic = {sizeof(INITCOMMONCONTROLSEX), ICC_DATE_CLASSES};
107 InitCommonControlsEx(&ic);
109 hwnd = CreateWindowEx(0,
113 0, 300, 300, 0, NULL, NULL, NULL, NULL);
119 static void test_monthcal_color(HWND hwnd)
123 /* Setter and Getters for color*/
124 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
125 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(0,0,0));
127 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
128 expect(RGB(0,0,0), temp);
129 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(255,255,255));
131 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
132 expect(RGB(255,255,255), temp);
134 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
135 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(0,0,0));
137 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
138 expect(RGB(0,0,0), temp);
139 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(255,255,255));
141 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
142 expect(RGB(255,255,255), temp);
144 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
145 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(0,0,0));
147 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
148 expect(RGB(0,0,0), temp);
149 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(255,255,255));
151 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
152 expect(RGB(255,255,255), temp);
154 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
155 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(0,0,0));
157 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
158 expect(RGB(0,0,0), temp);
159 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(255,255,255));
161 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
162 expect(RGB(255,255,255), temp);
164 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
165 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(0,0,0));
167 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
168 expect(RGB(0,0,0), temp);
169 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(255,255,255));
171 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
172 expect(RGB(255,255,255), temp);
174 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
175 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(0,0,0));
177 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
178 expect(RGB(0,0,0), temp);
179 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(255,255,255));
181 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
182 expect(RGB(255,255,255), temp);
185 static void test_monthcal_currDate(HWND hwnd)
187 SYSTEMTIME st_original, st_new, st_test;
190 /* Setter and Getters for current date selected */
191 st_original.wYear = 2000;
192 st_original.wMonth = 11;
193 st_original.wDay = 28;
194 st_original.wHour = 11;
195 st_original.wMinute = 59;
196 st_original.wSecond = 30;
197 st_original.wMilliseconds = 0;
198 st_original.wDayOfWeek = 0;
200 st_new = st_test = st_original;
202 /* Should not validate the time */
203 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
206 /* Overflow matters, check for wDay */
208 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
209 todo_wine {expect(0,res);}
211 /* correct wDay before checking for wMonth */
213 expect(st_original.wDay, st_test.wDay);
215 /* Overflow matters, check for wMonth */
217 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
218 todo_wine {expect(0,res);}
220 /* checking if gets the information right, modify st_new */
228 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_new);
231 /* st_new change to st_origin, above settings with overflow */
232 /* should not change the current settings */
233 expect(st_original.wYear, st_new.wYear);
234 todo_wine {expect(st_original.wMonth, st_new.wMonth);}
235 expect(st_original.wDay, st_new.wDay);
236 expect(st_original.wHour, st_new.wHour);
237 expect(st_original.wMinute, st_new.wMinute);
238 expect(st_original.wSecond, st_new.wSecond);
240 /* lparam cannot be NULL */
241 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM) NULL);
245 static void test_monthcal_firstDay(HWND hwnd)
247 int res, fday, i, temp;
249 LCID lcid = LOCALE_USER_DEFAULT;
251 /* Setter and Getters for first day of week */
253 /* check for locale first day */
254 if(GetLocaleInfo(lcid, LOCALE_IFIRSTDAYOFWEEK, b, 128)){
256 res = SendMessage(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
258 res = SendMessage(hwnd, MCM_SETFIRSTDAYOFWEEK, 0, (LPARAM) 0);
261 skip("Cannot retrieve first day of the week\n");
262 SendMessage(hwnd, MCM_SETFIRSTDAYOFWEEK, 0, (LPARAM) 0);
265 /* check for days of the week*/
266 for (i = 1, temp = 0x10000; i < 7; i++, temp++){
267 res = SendMessage(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
269 res = SendMessage(hwnd, MCM_SETFIRSTDAYOFWEEK, 0, (LPARAM) i);
273 /* check for returning to the original first day */
274 res = SendMessage(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
275 todo_wine {expect(temp, res);}
279 static void test_monthcal_unicode(HWND hwnd)
283 /* Setter and Getters for Unicode format */
285 /* getting the current settings */
286 temp = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
288 /* setting to 1, should return previous settings */
289 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 1, 0);
292 /* current setting is 1, so, should return 1 */
293 res = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
294 todo_wine {expect(1, res);}
296 /* setting to 0, should return previous settings */
297 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 0, 0);
298 todo_wine {expect(1, res);}
300 /* current setting is 0, so, it should return 0 */
301 res = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
304 /* should return previous settings */
305 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 1, 0);
309 static void test_monthcal_HitTest(HWND hwnd)
314 memset(&mchit, 0, sizeof(MCHITTESTINFO));
316 /* Setters for HITTEST */
318 /* (0, 0) is the top left of the control and should not be active */
319 mchit.cbSize = sizeof(MCHITTESTINFO);
322 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
323 expect(0, mchit.pt.x);
324 expect(0, mchit.pt.y);
325 expect(mchit.uHit, res);
326 todo_wine {expect(MCHT_NOWHERE, res);}
328 /* (300, 300) is the bottom right of the control and should not be active */
331 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
332 expect(300, mchit.pt.x);
333 expect(300, mchit.pt.y);
334 expect(mchit.uHit, res);
335 todo_wine {expect(MCHT_NOWHERE, res);}
337 /* (500, 500) is completely out of the control and should not be active */
340 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
341 expect(500, mchit.pt.x);
342 expect(500, mchit.pt.y);
343 expect(mchit.uHit, res);
344 todo_wine {expect(MCHT_NOWHERE, res);}
346 /* (150, 200) is in active area */
349 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
350 expect(150, mchit.pt.x);
351 expect(200, mchit.pt.y);
352 expect(mchit.uHit, res);
355 static void test_monthcal_today(HWND hwnd)
357 SYSTEMTIME st_test, st_new;
360 /* Setter and Getters for "today" information */
362 /* check for overflow, should be ok */
369 SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
371 res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
374 /* st_test should not change */
375 expect(38, st_test.wDay);
376 expect(38, st_test.wMonth);
378 /* st_new should change, overflow does not matter */
379 expect(38, st_new.wDay);
380 expect(38, st_new.wMonth);
382 /* check for zero, should be ok*/
386 SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
388 res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
391 /* st_test should not change */
392 expect(0, st_test.wDay);
393 expect(0, st_test.wMonth);
395 /* st_new should change to zero*/
396 expect(0, st_new.wDay);
397 expect(0, st_new.wMonth);
400 static void test_monthcal_scroll(HWND hwnd)
404 /* Setter and Getters for scroll rate */
405 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 2, 0);
408 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 3, 0);
410 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
413 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 12, 0);
415 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
418 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 15, 0);
420 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
423 res = SendMessage(hwnd, MCM_SETMONTHDELTA, -5, 0);
425 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
429 static void test_monthcal_MaxSelDay(HWND hwnd)
433 /* Setter and Getters for max selected days */
434 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 5, 0);
436 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
439 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 15, 0);
441 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
444 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, -1, 0);
445 todo_wine {expect(0, res);}
446 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
447 todo_wine {expect(15, res);}
456 hwnd = create_monthcal_control(0);
457 test_monthcal_color(hwnd);
458 test_monthcal_currDate(hwnd);
459 test_monthcal_firstDay(hwnd);
460 test_monthcal_unicode(hwnd);
461 test_monthcal_HitTest(hwnd);
462 test_monthcal_today(hwnd);
463 test_monthcal_scroll(hwnd);
466 hwnd = create_monthcal_control(MCS_MULTISELECT);
468 test_monthcal_MaxSelDay(hwnd);