comctl32/tests: Fix test failures running on February 29.
[wine/multimedia.git] / dlls / comctl32 / tests / monthcal.c
blob1fe2e613e46e2b787fdd8919078be75440822a1e
1 /*
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
22 #include <stdarg.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
28 #include "commctrl.h"
30 #include "wine/test.h"
31 #include "v6util.h"
32 #include <assert.h>
33 #include <windows.h>
34 #include "msg.h"
36 #define expect(expected, got) ok(expected == got, "Expected %d, got %d\n", expected, got);
37 #define expect_hex(expected, got) ok(expected == got, "Expected %x, got %x\n", expected, got);
38 #define expect_d(expected, got) ok(abs((expected) - (got)) <= 2, "Expected %d, got %d\n", expected, got);
40 #define NUM_MSG_SEQUENCES 2
41 #define PARENT_SEQ_INDEX 0
42 #define MONTHCAL_SEQ_INDEX 1
44 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
46 static HWND parent_wnd;
48 static const struct message create_parent_window_seq[] = {
49 { WM_GETMINMAXINFO, sent },
50 { WM_NCCREATE, sent },
51 { WM_NCCALCSIZE, sent|wparam, 0 },
52 { WM_CREATE, sent },
53 { WM_SHOWWINDOW, sent|wparam, 1 },
54 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
55 { WM_QUERYNEWPALETTE, sent|optional },
56 { WM_WINDOWPOSCHANGING, sent|wparam|optional, 0 },
57 { WM_WINDOWPOSCHANGED, sent|optional },
58 { WM_ACTIVATEAPP, sent|wparam, 1 },
59 { WM_NCACTIVATE, sent },
60 { WM_ACTIVATE, sent|wparam, 1 },
61 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
62 { WM_IME_NOTIFY, sent|defwinproc|optional },
63 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
64 /* Win9x adds SWP_NOZORDER below */
65 { WM_WINDOWPOSCHANGED, sent, /*|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ },
66 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
67 { WM_SIZE, sent },
68 { WM_MOVE, sent },
69 { 0 }
72 static const struct message create_monthcal_control_seq[] = {
73 { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
74 { WM_QUERYUISTATE, sent|optional },
75 { WM_GETFONT, sent },
76 { WM_PARENTNOTIFY, sent|wparam, WM_CREATE},
77 { 0 }
80 static const struct message create_monthcal_multi_sel_style_seq[] = {
81 { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
82 { WM_QUERYUISTATE, sent|optional },
83 { WM_GETFONT, sent },
84 { WM_PARENTNOTIFY, sent },
85 { 0 }
88 static const struct message monthcal_curr_date_seq[] = {
89 { MCM_SETCURSEL, sent|wparam, 0},
90 { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
91 { MCM_SETCURSEL, sent|wparam, 0},
92 { MCM_SETCURSEL, sent|wparam, 0},
93 { MCM_GETCURSEL, sent|wparam, 0},
94 { MCM_GETCURSEL, sent|wparam|lparam, 0, 0},
95 { 0 }
98 static const struct message monthcal_first_day_seq[] = {
99 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
101 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -5},
102 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
104 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -4},
105 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
107 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -3},
108 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
110 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -2},
111 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
113 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -1},
114 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
116 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
117 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
119 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 1},
120 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
122 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 2},
123 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
125 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 3},
126 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
128 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 4},
129 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
131 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 5},
132 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
134 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 6},
135 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
137 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 7},
138 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
140 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 8},
141 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
143 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 9},
144 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
146 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 10},
147 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
149 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 11},
150 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
151 { 0 }
154 static const struct message monthcal_unicode_seq[] = {
155 { MCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
156 { MCM_SETUNICODEFORMAT, sent|wparam|lparam, 1, 0},
157 { MCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
158 { MCM_SETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
159 { MCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
160 { MCM_SETUNICODEFORMAT, sent|wparam|lparam, 1, 0},
161 { 0 }
164 static const struct message monthcal_hit_test_seq[] = {
165 { MCM_SETCURSEL, sent|wparam, 0},
166 { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
167 { MCM_HITTEST, sent|wparam, 0},
168 { MCM_HITTEST, sent|wparam, 0},
169 { MCM_HITTEST, sent|wparam, 0},
170 { MCM_HITTEST, sent|wparam, 0},
171 { MCM_HITTEST, sent|wparam, 0},
172 { MCM_HITTEST, sent|wparam, 0},
173 { MCM_HITTEST, sent|wparam, 0},
174 { MCM_HITTEST, sent|wparam, 0},
175 { MCM_HITTEST, sent|wparam, 0},
176 { MCM_HITTEST, sent|wparam, 0},
177 { 0 }
180 static const struct message monthcal_todaylink_seq[] = {
181 { MCM_HITTEST, sent|wparam, 0},
182 { MCM_SETTODAY, sent|wparam, 0},
183 { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
184 { MCM_GETTODAY, sent|wparam, 0},
185 { WM_LBUTTONDOWN, sent|wparam, MK_LBUTTON},
186 { WM_CAPTURECHANGED, sent|wparam|lparam|defwinproc, 0, 0},
187 { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
188 { MCM_GETCURSEL, sent|wparam, 0},
189 { 0 }
192 static const struct message monthcal_today_seq[] = {
193 { MCM_SETTODAY, sent|wparam, 0},
194 { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
195 { MCM_GETTODAY, sent|wparam, 0},
196 { MCM_SETTODAY, sent|wparam, 0},
197 { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
198 { MCM_GETTODAY, sent|wparam, 0},
199 { 0 }
202 static const struct message monthcal_scroll_seq[] = {
203 { MCM_SETMONTHDELTA, sent|wparam|lparam, 2, 0},
204 { MCM_SETMONTHDELTA, sent|wparam|lparam, 3, 0},
205 { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
206 { MCM_SETMONTHDELTA, sent|wparam|lparam, 12, 0},
207 { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
208 { MCM_SETMONTHDELTA, sent|wparam|lparam, 15, 0},
209 { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
210 { MCM_SETMONTHDELTA, sent|wparam|lparam, -5, 0},
211 { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
212 { 0 }
215 static const struct message monthcal_monthrange_seq[] = {
216 { MCM_GETMONTHRANGE, sent|wparam, GMR_VISIBLE},
217 { MCM_GETMONTHRANGE, sent|wparam, GMR_DAYSTATE},
218 { 0 }
221 static const struct message monthcal_max_sel_day_seq[] = {
222 { MCM_SETMAXSELCOUNT, sent|wparam|lparam, 5, 0},
223 { MCM_GETMAXSELCOUNT, sent|wparam|lparam, 0, 0},
224 { MCM_SETMAXSELCOUNT, sent|wparam|lparam, 15, 0},
225 { MCM_GETMAXSELCOUNT, sent|wparam|lparam, 0, 0},
226 { MCM_SETMAXSELCOUNT, sent|wparam|lparam, -1, 0},
227 { MCM_GETMAXSELCOUNT, sent|wparam|lparam, 0, 0},
228 { 0 }
231 /* expected message sequence for parent*/
232 static const struct message destroy_monthcal_parent_msgs_seq[] = {
233 { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY},
234 { 0 }
237 /* expected message sequence for child*/
238 static const struct message destroy_monthcal_child_msgs_seq[] = {
239 { 0x0090, sent|optional }, /* Vista */
240 { WM_SHOWWINDOW, sent|wparam|lparam, 0, 0},
241 { WM_WINDOWPOSCHANGING, sent|wparam, 0},
242 { WM_WINDOWPOSCHANGED, sent|wparam, 0},
243 { WM_DESTROY, sent|wparam|lparam, 0, 0},
244 { WM_NCDESTROY, sent|wparam|lparam, 0, 0},
245 { 0 }
248 static const struct message destroy_monthcal_multi_sel_style_seq[] = {
249 { 0x0090, sent|optional }, /* Vista */
250 { WM_SHOWWINDOW, sent|wparam|lparam, 0, 0},
251 { WM_WINDOWPOSCHANGING, sent|wparam, 0},
252 { WM_WINDOWPOSCHANGED, sent|wparam, 0},
253 { WM_DESTROY, sent|wparam|lparam, 0, 0},
254 { WM_NCDESTROY, sent|wparam|lparam, 0, 0},
255 { 0 }
258 static void test_monthcal(void)
260 HWND hwnd;
261 SYSTEMTIME st[2], st1[2], today;
262 int res, month_range;
263 DWORD limits;
265 hwnd = CreateWindowA(MONTHCAL_CLASSA, "MonthCal", WS_POPUP | WS_VISIBLE, CW_USEDEFAULT,
266 0, 300, 300, 0, 0, NULL, NULL);
267 ok(hwnd != NULL, "Failed to create MonthCal\n");
269 /* test range just after creation */
270 memset(&st, 0xcc, sizeof(st));
271 limits = SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st);
272 ok(limits == 0 ||
273 broken(limits == GDTR_MIN), /* comctl32 <= 4.70 */
274 "No limits should be set (%d)\n", limits);
275 if (limits == GDTR_MIN)
277 win_skip("comctl32 <= 4.70 is broken\n");
278 DestroyWindow(hwnd);
279 return;
282 ok(0 == st[0].wYear ||
283 broken(1752 == st[0].wYear), /* comctl32 <= 4.72 */
284 "Expected 0, got %d\n", st[0].wYear);
285 ok(0 == st[0].wMonth ||
286 broken(9 == st[0].wMonth), /* comctl32 <= 4.72 */
287 "Expected 0, got %d\n", st[0].wMonth);
288 ok(0 == st[0].wDay ||
289 broken(14 == st[0].wDay), /* comctl32 <= 4.72 */
290 "Expected 0, got %d\n", st[0].wDay);
291 expect(0, st[0].wDayOfWeek);
292 expect(0, st[0].wHour);
293 expect(0, st[0].wMinute);
294 expect(0, st[0].wSecond);
295 expect(0, st[0].wMilliseconds);
297 expect(0, st[1].wYear);
298 expect(0, st[1].wMonth);
299 expect(0, st[1].wDay);
300 expect(0, st[1].wDayOfWeek);
301 expect(0, st[1].wHour);
302 expect(0, st[1].wMinute);
303 expect(0, st[1].wSecond);
304 expect(0, st[1].wMilliseconds);
306 GetSystemTime(&st[0]);
307 st[1] = st[0];
309 SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&today);
311 /* Invalid date/time */
312 st[0].wYear = 2000;
313 /* Time should not matter */
314 st[1].wHour = st[1].wMinute = st[1].wSecond = 70;
315 st[1].wMilliseconds = 1200;
316 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set MAX limit\n");
317 /* invalid timestamp is written back with today data and msecs untouched */
318 expect(today.wHour, st[1].wHour);
319 expect(today.wMinute, st[1].wMinute);
320 expect(today.wSecond, st[1].wSecond);
321 expect(1200, st[1].wMilliseconds);
323 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
324 ok(st1[0].wYear != 2000, "Lower limit changed\n");
325 /* invalid timestamp should be replaced with today data, except msecs */
326 expect(today.wHour, st1[1].wHour);
327 expect(today.wMinute, st1[1].wMinute);
328 expect(today.wSecond, st1[1].wSecond);
329 expect(1200, st1[1].wMilliseconds);
331 /* Invalid date/time with invalid milliseconds only */
332 GetSystemTime(&st[0]);
333 st[1] = st[0];
334 /* Time should not matter */
335 st[1].wMilliseconds = 1200;
336 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set MAX limit\n");
337 /* invalid milliseconds field doesn't lead to invalid timestamp */
338 expect(st[0].wHour, st[1].wHour);
339 expect(st[0].wMinute, st[1].wMinute);
340 expect(st[0].wSecond, st[1].wSecond);
341 expect(1200, st[1].wMilliseconds);
343 GetSystemTime(&st[0]);
345 st[1].wMonth = 0;
346 ok(!SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Should have failed to set limits\n");
347 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
348 ok(st1[0].wYear != 2000, "Lower limit changed\n");
349 ok(!SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Should have failed to set MAX limit\n");
350 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
351 ok(st1[0].wYear != 2000, "Lower limit changed\n");
353 GetSystemTime(&st[0]);
354 st[0].wDay = 20;
355 st[0].wMonth = 5;
356 st[1] = st[0];
358 month_range = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
359 st[1].wMonth--;
360 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
361 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
362 ok(res == month_range, "Invalid month range (%d)\n", res);
363 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == (GDTR_MIN|GDTR_MAX), "Limits should be set\n");
365 st[1].wMonth += 2;
366 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
367 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
368 ok(res == month_range, "Invalid month range (%d)\n", res);
370 st[1].wYear --;
371 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
372 st[1].wYear += 1;
373 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
375 st[1].wMonth -= 3;
376 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
377 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "Only MAX limit should be set\n");
378 st[1].wMonth += 4;
379 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
380 st[1].wYear -= 3;
381 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
382 st[1].wYear += 4;
383 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
384 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "Only MAX limit should be set\n");
386 /* set both limits, then set max < min */
387 GetSystemTime(&st[0]);
388 st[0].wDay = 25;
389 st[1] = st[0];
390 st[1].wYear++;
391 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN|GDTR_MAX, (LPARAM)st), "Failed to set limits\n");
392 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == (GDTR_MIN|GDTR_MAX), "Min limit expected\n");
393 st[1].wYear -= 2;
394 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set limits\n");
395 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "Max limit expected\n");
397 expect(0, st1[0].wYear);
398 expect(0, st1[0].wMonth);
399 expect(0, st1[0].wDay);
400 expect(0, st1[0].wDayOfWeek);
401 expect(0, st1[0].wHour);
402 expect(0, st1[0].wMinute);
403 expect(0, st1[0].wSecond);
404 expect(0, st1[0].wMilliseconds);
406 expect(st[1].wYear, st1[1].wYear);
407 expect(st[1].wMonth, st1[1].wMonth);
408 expect(st[1].wDay, st1[1].wDay);
409 expect(st[1].wDayOfWeek, st1[1].wDayOfWeek);
410 expect(st[1].wHour, st1[1].wHour);
411 expect(st[1].wMinute, st1[1].wMinute);
412 expect(st[1].wSecond, st1[1].wSecond);
413 expect(st[1].wMilliseconds, st1[1].wMilliseconds);
415 st[1] = st[0];
416 st[1].wYear++;
417 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN|GDTR_MAX, (LPARAM)st), "Failed to set limits\n");
418 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == (GDTR_MIN|GDTR_MAX), "Min limit expected\n");
419 st[0].wYear++; /* start == end now */
420 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN, (LPARAM)st), "Failed to set limits\n");
421 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MIN, "Min limit expected\n");
423 expect(st[0].wYear, st1[0].wYear);
424 expect(st[0].wMonth, st1[0].wMonth);
425 expect(st[0].wDay, st1[0].wDay);
426 expect(st[0].wDayOfWeek, st1[0].wDayOfWeek);
427 expect(st[0].wHour, st1[0].wHour);
428 expect(st[0].wMinute, st1[0].wMinute);
429 expect(st[0].wSecond, st1[0].wSecond);
430 expect(st[0].wMilliseconds, st1[0].wMilliseconds);
432 expect(0, st1[1].wYear);
433 expect(0, st1[1].wMonth);
434 expect(0, st1[1].wDay);
435 expect(0, st1[1].wDayOfWeek);
436 expect(0, st1[1].wHour);
437 expect(0, st1[1].wMinute);
438 expect(0, st1[1].wSecond);
439 expect(0, st1[1].wMilliseconds);
441 DestroyWindow(hwnd);
444 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
446 static LONG defwndproc_counter = 0;
447 LRESULT ret;
448 struct message msg;
450 /* log system messages, except for painting */
451 if (message < WM_USER &&
452 message != WM_PAINT &&
453 message != WM_ERASEBKGND &&
454 message != WM_NCPAINT &&
455 message != WM_NCHITTEST &&
456 message != WM_GETTEXT &&
457 message != WM_GETICON &&
458 message != WM_DEVICECHANGE)
460 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
462 msg.message = message;
463 msg.flags = sent|wparam|lparam;
464 if (defwndproc_counter) msg.flags |= defwinproc;
465 msg.wParam = wParam;
466 msg.lParam = lParam;
467 add_message(sequences, PARENT_SEQ_INDEX, &msg);
470 if (message == WM_NOTIFY)
472 NMHDR *hdr = (NMHDR*)lParam;
473 switch (hdr->code)
475 case MCN_GETDAYSTATE:
477 NMDAYSTATE *nmstate = (NMDAYSTATE*)lParam;
478 static MONTHDAYSTATE months[14] = { 0 };
480 ok(nmstate->cDayState > 0, "got %d\n", nmstate->cDayState);
481 ok(nmstate->cDayState <= 14, "got %d\n", nmstate->cDayState);
482 ok(nmstate->prgDayState != NULL, "got %p\n", nmstate->prgDayState);
484 nmstate->prgDayState = months;
486 return TRUE;
488 default:
489 break;
493 defwndproc_counter++;
494 ret = DefWindowProcA(hwnd, message, wParam, lParam);
495 defwndproc_counter--;
497 return ret;
500 static BOOL register_parent_wnd_class(void)
502 WNDCLASSA cls;
504 cls.style = 0;
505 cls.lpfnWndProc = parent_wnd_proc;
506 cls.cbClsExtra = 0;
507 cls.cbWndExtra = 0;
508 cls.hInstance = GetModuleHandleA(NULL);
509 cls.hIcon = 0;
510 cls.hCursor = LoadCursorA(0, IDC_ARROW);
511 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
512 cls.lpszMenuName = NULL;
513 cls.lpszClassName = "Month-Cal test parent class";
514 return RegisterClassA(&cls);
517 static HWND create_parent_window(void)
519 HWND hwnd;
521 InitCommonControls();
523 /* flush message sequences, so we can check the new sequence by the end of function */
524 flush_sequences(sequences, NUM_MSG_SEQUENCES);
526 if (!register_parent_wnd_class())
527 return NULL;
529 hwnd = CreateWindowEx(0, "Month-Cal test parent class",
530 "Month-Cal test parent window",
531 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
532 WS_MAXIMIZEBOX | WS_VISIBLE,
533 0, 0, 500, 500,
534 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
536 assert(hwnd);
538 /* check for message sequences */
539 ok_sequence(sequences, PARENT_SEQ_INDEX, create_parent_window_seq, "create parent window", FALSE);
541 return hwnd;
544 static LRESULT WINAPI monthcal_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
546 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
547 static LONG defwndproc_counter = 0;
548 LRESULT ret;
549 struct message msg;
551 msg.message = message;
552 msg.flags = sent|wparam|lparam;
553 if (defwndproc_counter) msg.flags |= defwinproc;
554 msg.wParam = wParam;
555 msg.lParam = lParam;
556 add_message(sequences, MONTHCAL_SEQ_INDEX, &msg);
558 /* some debug output for style changing */
559 if ((message == WM_STYLECHANGING ||
560 message == WM_STYLECHANGED) && lParam)
562 STYLESTRUCT *style = (STYLESTRUCT*)lParam;
563 trace("\told style: 0x%08x, new style: 0x%08x\n", style->styleOld, style->styleNew);
566 defwndproc_counter++;
567 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
568 defwndproc_counter--;
570 return ret;
573 static HWND create_monthcal_control(DWORD style)
575 WNDPROC oldproc;
576 HWND hwnd;
578 hwnd = CreateWindowEx(0,
579 MONTHCAL_CLASS,
581 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
582 0, 0, 300, 400,
583 parent_wnd, NULL, GetModuleHandleA(NULL), NULL);
585 if (!hwnd) return NULL;
587 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
588 (LONG_PTR)monthcal_subclass_proc);
589 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
591 SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(SYSTEM_FONT), 0);
593 return hwnd;
597 /* Setter and Getters Tests */
599 static void test_color(void)
601 COLORREF color, prev;
602 HWND hwnd;
604 hwnd = create_monthcal_control(0);
606 /* invalid color index */
607 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT + 1, 0);
608 expect(~0u, color);
609 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT + 1, RGB(255,255,255));
610 expect(~0u, prev);
612 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
613 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(0,0,0));
614 expect(color, prev);
615 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
616 expect(RGB(0,0,0), color);
617 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(255,255,255));
618 expect(color, prev);
619 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
620 expect(RGB(255,255,255), color);
622 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
623 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(0,0,0));
624 expect(color, prev);
625 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
626 expect(RGB(0,0,0), color);
627 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(255,255,255));
628 expect(color, prev);
629 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
630 expect(RGB(255,255,255), color);
632 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
633 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(0,0,0));
634 expect(color, prev);
635 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
636 expect(RGB(0,0,0), color);
637 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(255,255,255));
638 expect(color, prev);
639 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
640 expect(RGB(255,255,255), color);
642 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
643 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(0,0,0));
644 expect(color, prev);
645 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
646 expect(RGB(0,0,0), color);
647 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(255,255,255));
648 expect(color, prev);
649 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
650 expect(RGB(255,255,255), color);
652 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
653 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(0,0,0));
654 expect(color, prev);
655 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
656 expect(RGB(0,0,0), color);
657 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(255,255,255));
658 expect(color, prev);
659 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
660 expect(RGB(255,255,255), color);
662 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
663 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(0,0,0));
664 expect(color, prev);
665 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
666 expect(RGB(0,0,0), color);
667 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(255,255,255));
668 expect(color, prev);
669 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
670 expect(RGB(255,255,255), color);
672 DestroyWindow(hwnd);
675 static void test_currdate(void)
677 SYSTEMTIME st_original, st_new, st_test;
678 int res;
679 HWND hwnd;
681 hwnd = create_monthcal_control(0);
683 flush_sequences(sequences, NUM_MSG_SEQUENCES);
685 /* Setter and Getters for current date selected */
686 st_original.wYear = 2000;
687 st_original.wMonth = 11;
688 st_original.wDay = 28;
689 st_original.wHour = 11;
690 st_original.wMinute = 59;
691 st_original.wSecond = 30;
692 st_original.wMilliseconds = 0;
693 st_original.wDayOfWeek = 0;
695 st_new = st_test = st_original;
697 /* Should not validate the time */
698 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
699 expect(1,res);
701 /* Overflow matters, check for wDay */
702 st_test.wDay += 4;
703 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
704 expect(0,res);
706 /* correct wDay before checking for wMonth */
707 st_test.wDay -= 4;
708 expect(st_original.wDay, st_test.wDay);
710 /* Overflow matters, check for wMonth */
711 st_test.wMonth += 4;
712 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
713 expect(0,res);
715 /* checking if gets the information right, modify st_new */
716 st_new.wYear += 4;
717 st_new.wMonth += 4;
718 st_new.wDay += 4;
719 st_new.wHour += 4;
720 st_new.wMinute += 4;
721 st_new.wSecond += 4;
723 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_new);
724 expect(1, res);
726 /* st_new change to st_origin, above settings with overflow */
727 /* should not change the current settings */
728 expect(st_original.wYear, st_new.wYear);
729 expect(st_original.wMonth, st_new.wMonth);
730 expect(st_original.wDay, st_new.wDay);
731 ok(st_original.wHour == st_new.wHour ||
732 broken(0 == st_new.wHour), /* comctl32 <= 4.70 */
733 "Expected %d, got %d\n", st_original.wHour, st_new.wHour);
734 ok(st_original.wMinute == st_new.wMinute ||
735 broken(0 == st_new.wMinute), /* comctl32 <= 4.70 */
736 "Expected %d, got %d\n", st_original.wMinute, st_new.wMinute);
737 ok(st_original.wSecond == st_new.wSecond ||
738 broken(0 == st_new.wSecond), /* comctl32 <= 4.70 */
739 "Expected %d, got %d\n", st_original.wSecond, st_new.wSecond);
741 /* lparam cannot be NULL */
742 res = SendMessage(hwnd, MCM_GETCURSEL, 0, 0);
743 expect(0, res);
745 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_curr_date_seq, "monthcal currDate", TRUE);
747 /* December, 31, 9999 is the maximum allowed date */
748 memset(&st_new, 0, sizeof(st_new));
749 st_new.wYear = 9999;
750 st_new.wMonth = 12;
751 st_new.wDay = 31;
752 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
753 expect(1, res);
754 memset(&st_test, 0, sizeof(st_test));
755 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_test);
756 expect(1, res);
757 expect(st_new.wYear, st_test.wYear);
758 expect(st_new.wMonth, st_test.wMonth);
759 expect(st_new.wDay, st_test.wDay);
760 expect(st_new.wHour, st_test.wHour);
761 expect(st_new.wMinute, st_test.wMinute);
762 expect(st_new.wSecond, st_test.wSecond);
763 /* try one day later */
764 st_original = st_new;
765 st_new.wYear = 10000;
766 st_new.wMonth = 1;
767 st_new.wDay = 1;
768 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
769 ok(0 == res ||
770 broken(1 == res), /* comctl32 <= 4.72 */
771 "Expected 0, got %d\n", res);
772 if (0 == res)
774 memset(&st_test, 0, sizeof(st_test));
775 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_test);
776 expect(1, res);
777 expect(st_original.wYear, st_test.wYear);
778 expect(st_original.wMonth, st_test.wMonth);
779 expect(st_original.wDay, st_test.wDay);
780 expect(st_original.wHour, st_test.wHour);
781 expect(st_original.wMinute, st_test.wMinute);
782 expect(st_original.wSecond, st_test.wSecond);
785 /* setting selection equal to current reports success even if out range */
786 memset(&st_new, 0, sizeof(st_new));
787 st_new.wYear = 2009;
788 st_new.wDay = 5;
789 st_new.wMonth = 10;
790 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
791 expect(1, res);
792 memset(&st_test, 0, sizeof(st_test));
793 st_test.wYear = 2009;
794 st_test.wDay = 6;
795 st_test.wMonth = 10;
796 res = SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN, (LPARAM)&st_test);
797 expect(1, res);
798 /* set to current again */
799 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
800 expect(1, res);
802 /* set with invalid day of week */
803 memset(&st_test, 0, sizeof(st_test));
804 st_test.wYear = 2009;
805 st_test.wDay = 7;
806 st_test.wMonth = 10;
807 st_test.wDayOfWeek = 100;
808 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
809 expect(1, res);
811 memset(&st_test, 0, sizeof(st_test));
812 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_test);
813 expect(1, res);
814 expect(2009, st_test.wYear);
815 expect(7, st_test.wDay);
816 expect(10, st_test.wMonth);
817 expect(3, st_test.wDayOfWeek);
819 DestroyWindow(hwnd);
822 static void test_firstDay(void)
824 int res, fday, i, prev;
825 CHAR b[128], caltype[3];
826 LCID lcid = LOCALE_USER_DEFAULT;
827 HWND hwnd;
828 LRESULT ret;
830 SetLastError(0xdeadbeef);
831 ret = GetLocaleInfoA(lcid, LOCALE_ICALENDARTYPE, caltype, 3);
832 if (ret == 0) {
833 skip("Must know local calendar type (%x)\n", GetLastError());
834 return;
835 } else if (atoi(caltype) != CAL_GREGORIAN) {
836 skip("MonthCalendar Control only supports Gregorian calendar (type: %s)\n", caltype);
837 return;
840 hwnd = create_monthcal_control(0);
842 flush_sequences(sequences, NUM_MSG_SEQUENCES);
844 /* Setter and Getters for first day of week */
845 /* check for locale first day */
846 if(GetLocaleInfoA(lcid, LOCALE_IFIRSTDAYOFWEEK, b, 128)){
847 fday = atoi(b);
848 trace("fday: %d\n", fday);
849 res = SendMessage(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
850 expect(fday, res);
851 prev = fday;
853 /* checking for the values that actually will be stored as */
854 /* current first day when we set a new value */
855 for (i = -5; i < 12; i++){
856 res = SendMessage(hwnd, MCM_SETFIRSTDAYOFWEEK, 0, i);
857 expect(prev, res);
858 res = SendMessage(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
859 prev = res;
861 if (i == -1){
862 expect(MAKELONG(fday, FALSE), res);
863 }else if (i >= 7){
864 /* out of range sets max first day of week, locale is ignored */
865 expect(MAKELONG(6, TRUE), res);
866 }else{
867 expect(MAKELONG(i, TRUE), res);
871 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_first_day_seq, "monthcal firstDay", FALSE);
873 }else{
874 skip("Cannot retrieve first day of the week\n");
877 DestroyWindow(hwnd);
880 static void test_unicode(void)
882 int res, temp;
883 HWND hwnd;
885 hwnd = create_monthcal_control(0);
887 flush_sequences(sequences, NUM_MSG_SEQUENCES);
889 /* Setter and Getters for Unicode format */
891 /* getting the current settings */
892 temp = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
894 /* setting to 1, should return previous settings */
895 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 1, 0);
896 expect(temp, res);
898 /* current setting is 1, so, should return 1 */
899 res = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
900 ok(1 == res ||
901 broken(0 == res), /* comctl32 <= 4.70 */
902 "Expected 1, got %d\n", res);
904 /* setting to 0, should return previous settings */
905 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 0, 0);
906 ok(1 == res ||
907 broken(0 == res), /* comctl32 <= 4.70 */
908 "Expected 1, got %d\n", res);
910 /* current setting is 0, so, it should return 0 */
911 res = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
912 expect(0, res);
914 /* should return previous settings */
915 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 1, 0);
916 expect(0, res);
918 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_unicode_seq, "monthcal unicode", FALSE);
920 DestroyWindow(hwnd);
923 static void test_hittest(void)
925 typedef struct hittest_test
927 UINT ht;
928 int todo;
929 } hittest_test_t;
931 static const hittest_test_t title_hits[] = {
932 /* Start is the same everywhere */
933 { MCHT_TITLE, 0 },
934 { MCHT_TITLEBTNPREV, 0 },
935 /* The middle piece is only tested for presence of items */
936 /* End is the same everywhere */
937 { MCHT_TITLEBTNNEXT, 0 },
938 { MCHT_TITLE, 0 },
939 { MCHT_NOWHERE, 1 }
942 MCHITTESTINFO mchit;
943 UINT res, old_res;
944 SYSTEMTIME st;
945 LONG x;
946 UINT title_index;
947 HWND hwnd;
948 RECT r;
949 char yearmonth[80], *locale_month, *locale_year;
950 int month_count, year_count;
951 BOOL in_the_middle;
953 memset(&mchit, 0, sizeof(MCHITTESTINFO));
955 hwnd = create_monthcal_control(0);
957 /* test with invalid structure size */
958 mchit.cbSize = MCHITTESTINFO_V1_SIZE - 1;
959 mchit.pt.x = 0;
960 mchit.pt.y = 0;
961 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
962 expect(0, mchit.pt.x);
963 expect(0, mchit.pt.y);
964 expect(~0u, res);
965 expect(0, mchit.uHit);
966 /* test with invalid pointer */
967 res = SendMessage(hwnd, MCM_HITTEST, 0, 0);
968 expect(~0u, res);
970 /* resize control to display single Calendar */
971 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
972 if (res == 0)
974 win_skip("Message MCM_GETMINREQRECT unsupported. Skipping.\n");
975 DestroyWindow(hwnd);
976 return;
978 MoveWindow(hwnd, 0, 0, r.right, r.bottom, FALSE);
980 flush_sequences(sequences, NUM_MSG_SEQUENCES);
982 st.wYear = 2007;
983 st.wMonth = 4;
984 st.wDay = 11;
985 st.wHour = 1;
986 st.wMinute = 0;
987 st.wSecond = 0;
988 st.wMilliseconds = 0;
989 st.wDayOfWeek = 0;
991 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st);
992 expect(1,res);
994 /* (0, 0) is the top left of the control - title */
995 mchit.cbSize = MCHITTESTINFO_V1_SIZE;
996 mchit.pt.x = 0;
997 mchit.pt.y = 0;
998 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
999 expect(0, mchit.pt.x);
1000 expect(0, mchit.pt.y);
1001 expect(mchit.uHit, res);
1002 expect_hex(MCHT_TITLE, res);
1004 /* bottom right of the control and should not be active */
1005 mchit.pt.x = r.right;
1006 mchit.pt.y = r.bottom;
1007 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1008 expect(r.right, mchit.pt.x);
1009 expect(r.bottom, mchit.pt.y);
1010 expect(mchit.uHit, res);
1011 todo_wine expect_hex(MCHT_NOWHERE, res);
1013 /* completely out of the control, should not be active */
1014 mchit.pt.x = 2 * r.right;
1015 mchit.pt.y = 2 * r.bottom;
1016 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1017 expect(2 * r.right, mchit.pt.x);
1018 expect(2 * r.bottom, mchit.pt.y);
1019 expect(mchit.uHit, res);
1020 todo_wine expect_hex(MCHT_NOWHERE, res);
1022 /* in active area - day of the week */
1023 mchit.pt.x = r.right / 2;
1024 mchit.pt.y = r.bottom / 2;
1025 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1026 expect(r.right / 2, mchit.pt.x);
1027 expect(r.bottom / 2, mchit.pt.y);
1028 expect(mchit.uHit, res);
1029 expect_hex(MCHT_CALENDARDATE, res);
1031 /* in active area - day of the week #2 */
1032 mchit.pt.x = r.right / 14; /* half of first day rect */
1033 mchit.pt.y = r.bottom / 2;
1034 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1035 expect(r.right / 14, mchit.pt.x);
1036 expect(r.bottom / 2, mchit.pt.y);
1037 expect(mchit.uHit, res);
1038 expect_hex(MCHT_CALENDARDATE, res);
1040 /* in active area - date from prev month */
1041 mchit.pt.x = r.right / 14; /* half of first day rect */
1042 mchit.pt.y = 6 * r.bottom / 19;
1043 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1044 expect(r.right / 14, mchit.pt.x);
1045 expect(6 * r.bottom / 19, mchit.pt.y);
1046 expect(mchit.uHit, res);
1047 expect_hex(MCHT_CALENDARDATEPREV, res);
1049 #if 0
1050 /* (125, 115) is in active area - date from this month */
1051 mchit.pt.x = 125;
1052 mchit.pt.y = 115;
1053 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1054 expect(125, mchit.pt.x);
1055 expect(115, mchit.pt.y);
1056 expect(mchit.uHit, res);
1057 expect(MCHT_CALENDARDATE, res);
1058 #endif
1060 /* in active area - date from next month */
1061 mchit.pt.x = 11 * r.right / 14;
1062 mchit.pt.y = 16 * r.bottom / 19;
1063 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1064 expect(11 * r.right / 14, mchit.pt.x);
1065 expect(16 * r.bottom / 19, mchit.pt.y);
1066 expect(mchit.uHit, res);
1067 expect_hex(MCHT_CALENDARDATENEXT, res);
1069 /* in active area - today link */
1070 mchit.pt.x = r.right / 14;
1071 mchit.pt.y = 18 * r.bottom / 19;
1072 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1073 expect(r.right / 14, mchit.pt.x);
1074 expect(18 * r.bottom / 19, mchit.pt.y);
1075 expect(mchit.uHit, res);
1076 expect_hex(MCHT_TODAYLINK, res);
1078 /* in active area - today link */
1079 mchit.pt.x = r.right / 2;
1080 mchit.pt.y = 18 * r.bottom / 19;
1081 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1082 expect(r.right / 2, mchit.pt.x);
1083 expect(18 * r.bottom / 19, mchit.pt.y);
1084 expect(mchit.uHit, res);
1085 expect_hex(MCHT_TODAYLINK, res);
1087 /* in active area - today link */
1088 mchit.pt.x = r.right / 10;
1089 mchit.pt.y = 18 * r.bottom / 19;
1090 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1091 expect(r.right / 10, mchit.pt.x);
1092 expect(18 * r.bottom / 19, mchit.pt.y);
1093 expect(mchit.uHit, res);
1094 expect_hex(MCHT_TODAYLINK, res);
1096 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_hit_test_seq, "monthcal hit test", TRUE);
1098 /* The horizontal position of title bar elements depends on locale (y pos
1099 is constant), so we sample across a horizontal line and make sure we
1100 find all elements. */
1102 /* Get the format of the title */
1103 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SYEARMONTH, yearmonth, 80);
1104 /* Find out if we have a month and/or year */
1105 locale_year = strstr(yearmonth, "y");
1106 locale_month = strstr(yearmonth, "M");
1108 mchit.pt.x = 0;
1109 mchit.pt.y = (5/2) * r.bottom / 19;
1110 title_index = 0;
1111 old_res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1112 expect_hex(title_hits[title_index].ht, old_res);
1114 in_the_middle = FALSE;
1115 month_count = year_count = 0;
1116 for (x = 0; x < r.right; x++){
1117 mchit.pt.x = x;
1118 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1119 expect(x, mchit.pt.x);
1120 expect((5/2) * r.bottom / 19, mchit.pt.y);
1121 expect(mchit.uHit, res);
1122 if (res != old_res) {
1124 if (old_res == MCHT_TITLEBTNPREV)
1125 in_the_middle = TRUE;
1127 if (res == MCHT_TITLEBTNNEXT)
1128 in_the_middle = FALSE;
1130 if (in_the_middle) {
1131 if (res == MCHT_TITLEMONTH)
1132 month_count++;
1133 else if (res == MCHT_TITLEYEAR)
1134 year_count++;
1135 } else {
1136 title_index++;
1138 if (sizeof(title_hits) / sizeof(title_hits[0]) <= title_index)
1139 break;
1141 if (title_hits[title_index].todo) {
1142 todo_wine
1143 ok(title_hits[title_index].ht == res, "Expected %x, got %x, pos %d\n",
1144 title_hits[title_index].ht, res, x);
1145 } else {
1146 ok(title_hits[title_index].ht == res, "Expected %x, got %x, pos %d\n",
1147 title_hits[title_index].ht, res, x);
1150 old_res = res;
1154 /* There are some limits, even if LOCALE_SYEARMONTH contains rubbish
1155 * or no month/year indicators at all */
1156 if (locale_month)
1157 todo_wine ok(month_count == 1, "Expected 1 month item, got %d\n", month_count);
1158 else
1159 ok(month_count <= 1, "Too many month items: %d\n", month_count);
1161 if (locale_year)
1162 todo_wine ok(year_count == 1, "Expected 1 year item, got %d\n", year_count);
1163 else
1164 ok(year_count <= 1, "Too many year items: %d\n", year_count);
1166 todo_wine ok(month_count + year_count >= 1, "Not enough month and year items\n");
1168 ok(r.right <= x && title_index + 1 == sizeof(title_hits) / sizeof(title_hits[0]),
1169 "Wrong title layout\n");
1171 DestroyWindow(hwnd);
1174 static void test_todaylink(void)
1176 MCHITTESTINFO mchit;
1177 SYSTEMTIME st_test, st_new;
1178 UINT res;
1179 HWND hwnd;
1180 RECT r;
1182 memset(&mchit, 0, sizeof(MCHITTESTINFO));
1184 hwnd = create_monthcal_control(0);
1186 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
1187 expect(1, res);
1188 MoveWindow(hwnd, 0, 0, r.right, r.bottom, FALSE);
1190 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1192 /* hit active area - today link */
1193 mchit.cbSize = MCHITTESTINFO_V1_SIZE;
1194 mchit.pt.x = r.right / 14;
1195 mchit.pt.y = 18 * r.bottom / 19;
1196 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1197 expect(r.right / 14, mchit.pt.x);
1198 expect(18 * r.bottom / 19, mchit.pt.y);
1199 expect(mchit.uHit, res);
1200 expect(MCHT_TODAYLINK, res);
1202 st_test.wDay = 1;
1203 st_test.wMonth = 1;
1204 st_test.wYear = 2005;
1206 res = SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
1207 expect(0, res);
1209 memset(&st_new, 0, sizeof(st_new));
1210 res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
1211 expect(1, res);
1212 expect(1, st_new.wDay);
1213 expect(1, st_new.wMonth);
1214 expect(2005, st_new.wYear);
1216 res = SendMessage(hwnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELONG(mchit.pt.x, mchit.pt.y));
1217 expect(0, res);
1219 memset(&st_new, 0, sizeof(st_new));
1220 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_new);
1221 expect(1, res);
1222 expect(1, st_new.wDay);
1223 expect(1, st_new.wMonth);
1224 expect(2005, st_new.wYear);
1226 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_todaylink_seq, "monthcal hit test", TRUE);
1228 DestroyWindow(hwnd);
1231 static void test_today(void)
1233 SYSTEMTIME st_test, st_new;
1234 int res;
1235 HWND hwnd;
1237 hwnd = create_monthcal_control(0);
1239 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1241 /* Setter and Getters for "today" information */
1243 /* check for overflow, should be ok */
1244 memset(&st_test, 0, sizeof(st_test));
1245 st_test.wDay = 38;
1246 st_test.wMonth = 38;
1248 st_new.wDay = 27;
1249 st_new.wMonth = 27;
1251 res = SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
1252 expect(0, res);
1254 res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
1255 expect(1, res);
1257 /* st_test should not change */
1258 expect(38, st_test.wDay);
1259 expect(38, st_test.wMonth);
1261 /* st_new should change, overflow does not matter */
1262 expect(38, st_new.wDay);
1263 expect(38, st_new.wMonth);
1265 /* check for zero, should be ok*/
1266 st_test.wDay = 0;
1267 st_test.wMonth = 0;
1269 res = SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
1270 expect(0, res);
1272 res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
1273 expect(1, res);
1275 /* st_test should not change */
1276 expect(0, st_test.wDay);
1277 expect(0, st_test.wMonth);
1279 /* st_new should change to zero*/
1280 expect(0, st_new.wDay);
1281 expect(0, st_new.wMonth);
1283 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_today_seq, "monthcal today", TRUE);
1285 DestroyWindow(hwnd);
1288 static void test_scroll(void)
1290 int res;
1291 HWND hwnd;
1293 hwnd = create_monthcal_control(0);
1295 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1297 /* Setter and Getters for scroll rate */
1298 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 2, 0);
1299 expect(0, res);
1301 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 3, 0);
1302 expect(2, res);
1303 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1304 expect(3, res);
1306 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 12, 0);
1307 expect(3, res);
1308 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1309 expect(12, res);
1311 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 15, 0);
1312 expect(12, res);
1313 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1314 expect(15, res);
1316 res = SendMessage(hwnd, MCM_SETMONTHDELTA, -5, 0);
1317 expect(15, res);
1318 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1319 expect(-5, res);
1321 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_scroll_seq, "monthcal scroll", FALSE);
1323 DestroyWindow(hwnd);
1326 static void test_monthrange(void)
1328 int res;
1329 SYSTEMTIME st_visible[2], st_daystate[2], st;
1330 HWND hwnd;
1331 RECT r;
1333 hwnd = create_monthcal_control(0);
1335 st_visible[0].wYear = 0;
1336 st_visible[0].wMonth = 0;
1337 st_visible[0].wDay = 0;
1338 st_daystate[1] = st_daystate[0] = st_visible[1] = st_visible[0];
1340 st.wYear = 2000;
1341 st.wMonth = 11;
1342 st.wDay = 28;
1343 st.wHour = 11;
1344 st.wMinute = 59;
1345 st.wSecond = 30;
1346 st.wMilliseconds = 0;
1347 st.wDayOfWeek = 0;
1349 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st);
1350 expect(1,res);
1352 /* to be locale independent */
1353 SendMessage(hwnd, MCM_SETFIRSTDAYOFWEEK, 0, (LPARAM)6);
1355 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
1356 expect(TRUE, res);
1357 /* resize control to display two Calendars */
1358 MoveWindow(hwnd, 0, 0, r.right, (5/2)*r.bottom, FALSE);
1360 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1362 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st_visible);
1363 expect(2, res);
1364 expect(2000, st_visible[0].wYear);
1365 expect(11, st_visible[0].wMonth);
1366 expect(1, st_visible[0].wDay);
1367 expect(2000, st_visible[1].wYear);
1368 expect(12, st_visible[1].wMonth);
1369 expect(31, st_visible[1].wDay);
1371 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, (LPARAM)st_daystate);
1372 expect(4, res);
1373 expect(2000, st_daystate[0].wYear);
1374 expect(10, st_daystate[0].wMonth);
1375 expect(29, st_daystate[0].wDay);
1376 expect(2001, st_daystate[1].wYear);
1377 expect(1, st_daystate[1].wMonth);
1378 expect(6, st_daystate[1].wDay);
1380 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_monthrange_seq, "monthcal monthrange", FALSE);
1382 /* with null date array parameter */
1383 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, 0);
1384 expect(2, res);
1386 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, 0);
1387 expect(4, res);
1389 /* resize control to display single Calendar */
1390 MoveWindow(hwnd, 0, 0, r.right, r.bottom, FALSE);
1392 memset(&st, 0, sizeof(st));
1393 st.wMonth = 9;
1394 st.wYear = 1752;
1395 st.wDay = 14;
1397 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st);
1398 expect(1, res);
1400 /* September 1752 has 19 days */
1401 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st_visible);
1402 expect(1, res);
1404 expect(1752, st_visible[0].wYear);
1405 expect(9, st_visible[0].wMonth);
1406 ok(14 == st_visible[0].wDay ||
1407 broken(1 == st_visible[0].wDay), /* comctl32 <= 4.72 */
1408 "Expected 14, got %d\n", st_visible[0].wDay);
1410 expect(1752, st_visible[1].wYear);
1411 expect(9, st_visible[1].wMonth);
1412 expect(19, st_visible[1].wDay);
1414 DestroyWindow(hwnd);
1417 static void test_maxselday(void)
1419 int res;
1420 HWND hwnd;
1421 DWORD style;
1423 hwnd = create_monthcal_control(0);
1424 /* if no style specified default to 1 */
1425 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1426 expect(1, res);
1427 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 5, 0);
1428 expect(0, res);
1429 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1430 expect(1, res);
1432 /* try to set style */
1433 style = GetWindowLong(hwnd, GWL_STYLE);
1434 SetWindowLong(hwnd, GWL_STYLE, style | MCS_MULTISELECT);
1435 style = GetWindowLong(hwnd, GWL_STYLE);
1436 ok(!(style & MCS_MULTISELECT), "Expected MCS_MULTISELECT not to be set\n");
1437 DestroyWindow(hwnd);
1439 hwnd = create_monthcal_control(MCS_MULTISELECT);
1440 /* try to remove style */
1441 style = GetWindowLong(hwnd, GWL_STYLE);
1442 SetWindowLong(hwnd, GWL_STYLE, style & ~MCS_MULTISELECT);
1443 style = GetWindowLong(hwnd, GWL_STYLE);
1444 ok(style & MCS_MULTISELECT, "Expected MCS_MULTISELECT to be set\n");
1445 DestroyWindow(hwnd);
1447 hwnd = create_monthcal_control(MCS_MULTISELECT);
1449 /* default width is a week */
1450 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1451 expect(7, res);
1453 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1455 /* Setter and Getters for max selected days */
1456 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 5, 0);
1457 expect(1, res);
1458 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1459 expect(5, res);
1461 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 15, 0);
1462 expect(1, res);
1463 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1464 expect(15, res);
1466 /* test invalid value */
1467 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, -1, 0);
1468 expect(0, res);
1469 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1470 expect(15, res);
1472 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_max_sel_day_seq, "monthcal MaxSelDay", FALSE);
1474 /* zero value is invalid too */
1475 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 0, 0);
1476 expect(0, res);
1477 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1478 expect(15, res);
1480 DestroyWindow(hwnd);
1483 static void test_size(void)
1485 int res;
1486 RECT r1, r2;
1487 HFONT hFont1, hFont2;
1488 LOGFONTA logfont;
1489 HWND hwnd;
1491 hwnd = create_monthcal_control(0);
1493 lstrcpyA(logfont.lfFaceName, "Arial");
1494 memset(&logfont, 0, sizeof(logfont));
1495 logfont.lfHeight = 12;
1496 hFont1 = CreateFontIndirectA(&logfont);
1498 logfont.lfHeight = 24;
1499 hFont2 = CreateFontIndirectA(&logfont);
1501 /* initialize to a font we can compare against */
1502 SendMessage(hwnd, WM_SETFONT, (WPARAM)hFont1, 0);
1503 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r1);
1504 ok(res, "SendMessage(MCM_GETMINREQRECT) failed\n");
1506 /* check that setting a larger font results in an larger rect */
1507 SendMessage(hwnd, WM_SETFONT, (WPARAM)hFont2, 0);
1508 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r2);
1509 ok(res, "SendMessage(MCM_GETMINREQRECT) failed\n");
1511 OffsetRect(&r1, -r1.left, -r1.top);
1512 OffsetRect(&r2, -r2.left, -r2.top);
1514 ok(r1.bottom < r2.bottom, "Failed to get larger rect with larger font\n");
1516 DestroyWindow(hwnd);
1519 static void test_create(void)
1521 HWND hwnd;
1523 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1525 hwnd = create_monthcal_control(0);
1526 ok_sequence(sequences, PARENT_SEQ_INDEX, create_monthcal_control_seq, "create monthcal control", TRUE);
1528 DestroyWindow(hwnd);
1530 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1531 hwnd = create_monthcal_control(MCS_MULTISELECT);
1532 ok_sequence(sequences, PARENT_SEQ_INDEX, create_monthcal_multi_sel_style_seq, "create monthcal (multi sel style)", TRUE);
1533 DestroyWindow(hwnd);
1536 static void test_destroy(void)
1538 HWND hwnd;
1540 hwnd = create_monthcal_control(0);
1541 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1542 DestroyWindow(hwnd);
1543 ok_sequence(sequences, PARENT_SEQ_INDEX, destroy_monthcal_parent_msgs_seq, "Destroy monthcal (parent msg)", FALSE);
1544 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, destroy_monthcal_child_msgs_seq, "Destroy monthcal (child msg)", FALSE);
1546 /* MCS_MULTISELECT */
1547 hwnd = create_monthcal_control(MCS_MULTISELECT);
1548 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1549 DestroyWindow(hwnd);
1550 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, destroy_monthcal_multi_sel_style_seq, "Destroy monthcal (multi sel style)", FALSE);
1553 static void test_selrange(void)
1555 HWND hwnd;
1556 SYSTEMTIME st, range[2], range2[2];
1557 BOOL ret, old_comctl32 = FALSE;
1559 hwnd = create_monthcal_control(MCS_MULTISELECT);
1561 /* just after creation selection should start and end today */
1562 ret = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st);
1563 expect(TRUE, ret);
1565 memset(range, 0xcc, sizeof(range));
1566 ret = SendMessage(hwnd, MCM_GETSELRANGE, 0, (LPARAM)range);
1567 expect(TRUE, ret);
1568 expect(st.wYear, range[0].wYear);
1569 expect(st.wMonth, range[0].wMonth);
1570 expect(st.wDay, range[0].wDay);
1571 if (range[0].wDayOfWeek != st.wDayOfWeek)
1573 win_skip("comctl32 <= 4.70 doesn't set some values\n");
1574 old_comctl32 = TRUE;
1576 else
1578 expect(st.wDayOfWeek, range[0].wDayOfWeek);
1579 expect(st.wHour, range[0].wHour);
1580 expect(st.wMinute, range[0].wMinute);
1581 expect(st.wSecond, range[0].wSecond);
1582 expect(st.wMilliseconds, range[0].wMilliseconds);
1585 expect(st.wYear, range[1].wYear);
1586 expect(st.wMonth, range[1].wMonth);
1587 expect(st.wDay, range[1].wDay);
1588 if (!old_comctl32)
1590 expect(st.wDayOfWeek, range[1].wDayOfWeek);
1591 expect(st.wHour, range[1].wHour);
1592 expect(st.wMinute, range[1].wMinute);
1593 expect(st.wSecond, range[1].wSecond);
1594 expect(st.wMilliseconds, range[1].wMilliseconds);
1597 /* bounds are swapped if min > max */
1598 memset(&range[0], 0, sizeof(range[0]));
1599 range[0].wYear = 2009;
1600 range[0].wMonth = 10;
1601 range[0].wDay = 5;
1602 range[1] = range[0];
1603 range[1].wDay = 3;
1605 ret = SendMessage(hwnd, MCM_SETSELRANGE, 0, (LPARAM)range);
1606 expect(TRUE, ret);
1608 ret = SendMessage(hwnd, MCM_GETSELRANGE, 0, (LPARAM)range2);
1609 expect(TRUE, ret);
1611 expect(range[1].wYear, range2[0].wYear);
1612 expect(range[1].wMonth, range2[0].wMonth);
1613 expect(range[1].wDay, range2[0].wDay);
1614 expect(6, range2[0].wDayOfWeek);
1615 expect(range[1].wHour, range2[0].wHour);
1616 expect(range[1].wMinute, range2[0].wMinute);
1617 expect(range[1].wSecond, range2[0].wSecond);
1618 expect(range[1].wMilliseconds, range2[0].wMilliseconds);
1620 expect(range[0].wYear, range2[1].wYear);
1621 expect(range[0].wMonth, range2[1].wMonth);
1622 expect(range[0].wDay, range2[1].wDay);
1623 expect(1, range2[1].wDayOfWeek);
1624 expect(range[0].wHour, range2[1].wHour);
1625 expect(range[0].wMinute, range2[1].wMinute);
1626 expect(range[0].wSecond, range2[1].wSecond);
1627 expect(range[0].wMilliseconds, range2[1].wMilliseconds);
1629 /* try with range larger than maximum configured */
1630 memset(&range[0], 0, sizeof(range[0]));
1631 range[0].wYear = 2009;
1632 range[0].wMonth = 10;
1633 range[0].wDay = 1;
1634 range[1] = range[0];
1636 ret = SendMessage(hwnd, MCM_SETSELRANGE, 0, (LPARAM)range);
1637 expect(TRUE, ret);
1639 range[1] = range[0];
1640 /* default max. range is 7 days */
1641 range[1].wDay = 8;
1643 ret = SendMessage(hwnd, MCM_SETSELRANGE, 0, (LPARAM)range);
1644 expect(FALSE, ret);
1646 ret = SendMessage(hwnd, MCM_GETSELRANGE, 0, (LPARAM)range2);
1647 expect(TRUE, ret);
1649 expect(range[0].wYear, range2[0].wYear);
1650 expect(range[0].wMonth, range2[0].wMonth);
1651 expect(range[0].wDay, range2[0].wDay);
1652 expect(range[0].wYear, range2[1].wYear);
1653 expect(range[0].wMonth, range2[1].wMonth);
1654 expect(range[0].wDay, range2[1].wDay);
1656 DestroyWindow(hwnd);
1659 static void test_killfocus(void)
1661 HWND hwnd;
1662 DWORD style;
1664 hwnd = create_monthcal_control(0);
1666 /* make parent invisible */
1667 style = GetWindowLong(parent_wnd, GWL_STYLE);
1668 SetWindowLong(parent_wnd, GWL_STYLE, style &~ WS_VISIBLE);
1670 SendMessage(hwnd, WM_KILLFOCUS, (WPARAM)GetDesktopWindow(), 0);
1672 style = GetWindowLong(hwnd, GWL_STYLE);
1673 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
1675 style = GetWindowLong(parent_wnd, GWL_STYLE);
1676 SetWindowLong(parent_wnd, GWL_STYLE, style | WS_VISIBLE);
1678 DestroyWindow(hwnd);
1681 static void test_hittest_v6(void)
1683 MCHITTESTINFO mchit;
1684 DWORD ret;
1685 HWND hwnd;
1686 RECT r;
1688 hwnd = create_monthcal_control(0);
1689 SendMessage(hwnd, MCM_SETCALENDARBORDER, TRUE, 0);
1691 SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
1692 /* reserving some area around calendar */
1693 MoveWindow(hwnd, 0, 0, r.right * 3 / 2, r.bottom * 3 / 2, FALSE);
1694 mchit.cbSize = sizeof(MCHITTESTINFO);
1695 mchit.pt.x = mchit.pt.y = 0;
1696 mchit.iOffset = -1;
1697 mchit.iRow = -1;
1698 mchit.iCol = -1;
1699 ret = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1700 if (ret == ~0u)
1702 win_skip("Only MCHITTESTINFO_V1 supported\n");
1703 DestroyWindow(hwnd);
1704 return;
1706 todo_wine expect_hex(MCHT_NOWHERE, ret);
1707 expect(-1, mchit.iOffset);
1708 expect(-1, mchit.iRow);
1709 expect(-1, mchit.iCol);
1711 MoveWindow(hwnd, 0, 0, r.right, r.bottom, FALSE);
1712 mchit.pt.x = r.right / 2;
1713 mchit.pt.y = r.bottom / 2;
1714 mchit.iOffset = -1;
1715 ret = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1716 expect_hex(MCHT_CALENDARDATE, ret);
1717 expect(0, mchit.iOffset);
1719 /* over day area */
1720 mchit.pt.x = r.right / (7*2);
1721 mchit.pt.y = r.bottom / 2;
1722 mchit.iOffset = -1;
1723 mchit.iCol = mchit.iRow = -1;
1724 mchit.uHit = 0;
1725 mchit.rc.left = mchit.rc.right = mchit.rc.top = mchit.rc.bottom = -1;
1726 ret = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1727 expect_hex(MCHT_CALENDARDATE, ret);
1728 expect_hex(MCHT_CALENDARDATE, mchit.uHit);
1729 expect(0, mchit.iOffset);
1730 expect(2, mchit.iRow);
1731 expect(0, mchit.iCol);
1732 /* returned a one day rectangle */
1733 expect_d(r.right / 7, mchit.rc.right - mchit.rc.left);
1734 expect_d(r.bottom / 10, mchit.rc.bottom - mchit.rc.top);
1736 /* title */
1737 mchit.pt.x = 1;
1738 mchit.pt.y = 1;
1739 mchit.iOffset = -1;
1740 mchit.iCol = mchit.iRow = -1;
1741 mchit.uHit = 0;
1742 mchit.rc.left = mchit.rc.right = mchit.rc.top = mchit.rc.bottom = -1;
1743 ret = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1744 expect_hex(MCHT_TITLE, ret);
1745 expect_hex(MCHT_TITLE, mchit.uHit);
1746 expect(0, mchit.iOffset);
1747 expect(-1, mchit.iRow);
1748 expect(-1, mchit.iCol);
1749 expect(0, mchit.rc.left);
1750 expect(0, mchit.rc.top);
1751 expect_d(r.right, mchit.rc.right);
1752 ok(mchit.rc.bottom > 0, "got %d\n", mchit.rc.bottom);
1754 /* between two calendars */
1755 MoveWindow(hwnd, 0, 0, r.right * 5/2, r.bottom, FALSE);
1756 mchit.pt.x = r.right / (5*4);
1757 mchit.pt.y = r.bottom / 2;
1758 mchit.iOffset = -2;
1759 mchit.iCol = mchit.iRow = -2;
1760 mchit.uHit = ~0;
1761 mchit.rc.left = mchit.rc.right = mchit.rc.top = mchit.rc.bottom = -1;
1762 ret = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1763 todo_wine expect_hex(MCHT_NOWHERE, ret);
1764 todo_wine expect_hex(MCHT_NOWHERE, mchit.uHit);
1765 expect(-2, mchit.iOffset);
1766 expect(-2, mchit.iRow);
1767 expect(-2, mchit.iCol);
1768 todo_wine expect(0, mchit.rc.left);
1769 todo_wine expect(0, mchit.rc.top);
1770 todo_wine expect_d(r.right * 5/2, mchit.rc.right);
1771 todo_wine expect_d(r.bottom, mchit.rc.bottom);
1773 DestroyWindow(hwnd);
1776 static void test_get_set_border(void)
1778 HWND hwnd;
1779 DWORD ret;
1781 hwnd = create_monthcal_control(0);
1783 /* a non-default value */
1784 ret = SendMessage(hwnd, MCM_SETCALENDARBORDER, TRUE, 10);
1785 expect(0, ret);
1787 ret = SendMessage(hwnd, MCM_GETCALENDARBORDER, 0, 0);
1789 if (ret != 10)
1791 skip("MCM_GET/SETCALENDARBORDER not supported\n");
1792 DestroyWindow(hwnd);
1793 return;
1796 expect(10, ret);
1798 DestroyWindow(hwnd);
1801 static void test_MCM_SIZERECTTOMIN(void)
1803 HWND hwnd;
1804 DWORD ret;
1805 RECT r, r2;
1807 hwnd = create_monthcal_control(0);
1809 ret = SendMessageA(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r2);
1810 if (ret == 0)
1812 win_skip("Message MCM_GETMINREQRECT unsupported. Skipping.\n");
1813 DestroyWindow(hwnd);
1814 return;
1817 ret = SendMessageA(hwnd, MCM_SIZERECTTOMIN, 0, 0);
1818 ok(ret == 0, "got %d\n", ret);
1820 r.left = r.right = r.top = r.bottom = 0;
1821 ret = SendMessageA(hwnd, MCM_SIZERECTTOMIN, 0, (LPARAM)&r);
1822 if (ret == 0)
1824 skip("Message MCM_SIZERECTTOMIN unsupported. Skipping.\n");
1825 DestroyWindow(hwnd);
1826 return;
1828 ok(ret == 1, "got %d\n", ret);
1829 ok(r.left == 0 && r.right > 0, "got %d, %d\n", r.left, r.right);
1831 r = r2;
1832 ret = SendMessageA(hwnd, MCM_SIZERECTTOMIN, 0, (LPARAM)&r);
1833 ok(ret == 1, "got %d\n", ret);
1835 r2.right = (r2.right - r2.left) * 3;
1836 r2.bottom = (r2.bottom - r2.top) * 3;
1837 r2.left = r2.top = 0;
1838 ret = SendMessageA(hwnd, MCM_SIZERECTTOMIN, 0, (LPARAM)&r2);
1839 ok(ret == 1, "got %d\n", ret);
1841 DestroyWindow(hwnd);
1844 static void test_MCM_GETCALENDARCOUNT(void)
1846 HWND hwnd;
1847 DWORD ret;
1849 hwnd = create_monthcal_control(0);
1851 ret = SendMessageA(hwnd, MCM_GETCALENDARCOUNT, 0, 0);
1852 if (ret == 0)
1854 win_skip("Message MCM_GETCALENDARCOUNT unsupported. Skipping.\n");
1855 DestroyWindow(hwnd);
1856 return;
1859 expect(2, ret);
1861 DestroyWindow(hwnd);
1864 static void test_daystate(void)
1866 MONTHDAYSTATE state[4];
1867 DWORD ret, style;
1868 HWND hwnd;
1869 RECT r;
1871 /* without MCS_DAYSTATE */
1872 hwnd = create_monthcal_control(0);
1874 ret = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
1875 expect(TRUE, ret);
1877 /* resize control to display two Calendars */
1878 MoveWindow(hwnd, 0, 0, r.right, (5/2)*r.bottom, FALSE);
1880 ret = SendMessageA(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, 0);
1881 expect(4, ret);
1883 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 4, (LPARAM)&state);
1884 expect(0, ret);
1886 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 2, (LPARAM)&state);
1887 expect(0, ret);
1889 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 0, 0);
1890 expect(0, ret);
1892 /* try to switch on */
1893 SetWindowLongA(hwnd, GWL_STYLE, GetWindowLongA(hwnd, GWL_STYLE) | MCS_DAYSTATE);
1894 style = GetWindowLongA(hwnd, GWL_STYLE);
1895 ok((style & MCS_DAYSTATE) == 0, "got 0x%08x\n", style);
1897 DestroyWindow(hwnd);
1899 /* with MCS_DAYSTATE */
1900 hwnd = create_monthcal_control(MCS_DAYSTATE);
1902 ret = SendMessageA(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, 0);
1903 expect(4, ret);
1905 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 4, (LPARAM)&state);
1906 expect(1, ret);
1908 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 2, (LPARAM)&state);
1909 expect(0, ret);
1911 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 0, 0);
1912 expect(0, ret);
1914 /* try to switch off */
1915 SetWindowLongA(hwnd, GWL_STYLE, GetWindowLongA(hwnd, GWL_STYLE) & ~MCS_DAYSTATE);
1916 style = GetWindowLongA(hwnd, GWL_STYLE);
1917 ok((style & MCS_DAYSTATE) == MCS_DAYSTATE, "got 0x%08x\n", style);
1919 DestroyWindow(hwnd);
1922 START_TEST(monthcal)
1924 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
1925 INITCOMMONCONTROLSEX iccex;
1926 HMODULE hComctl32;
1927 HWND hwnd;
1929 ULONG_PTR ctx_cookie;
1930 HANDLE hCtx;
1932 hComctl32 = GetModuleHandleA("comctl32.dll");
1933 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
1934 if (!pInitCommonControlsEx)
1936 skip("InitCommonControlsEx() is missing. Skipping the tests\n");
1937 return;
1939 iccex.dwSize = sizeof(iccex);
1940 iccex.dwICC = ICC_DATE_CLASSES;
1941 pInitCommonControlsEx(&iccex);
1943 test_monthcal();
1945 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
1947 parent_wnd = create_parent_window();
1949 test_create();
1950 test_destroy();
1951 test_color();
1952 test_currdate();
1953 test_firstDay();
1954 test_unicode();
1955 test_today();
1956 test_scroll();
1957 test_monthrange();
1958 test_hittest();
1959 test_todaylink();
1960 test_size();
1961 test_maxselday();
1962 test_selrange();
1963 test_killfocus();
1964 test_daystate();
1966 if (!load_v6_module(&ctx_cookie, &hCtx))
1968 DestroyWindow(parent_wnd);
1969 return;
1972 /* this is a XP SP3 failure workaround */
1973 hwnd = CreateWindowExA(0, MONTHCAL_CLASSA, "foo",
1974 WS_CHILD | WS_BORDER | WS_VISIBLE,
1975 0, 0, 100, 100,
1976 parent_wnd, NULL, GetModuleHandleA(NULL), NULL);
1977 if (!IsWindow(hwnd))
1979 win_skip("FIXME: failed to create Monthcal window.\n");
1980 unload_v6_module(ctx_cookie, hCtx);
1981 DestroyWindow(parent_wnd);
1982 return;
1984 else
1985 DestroyWindow(hwnd);
1987 test_hittest_v6();
1988 test_get_set_border();
1989 test_MCM_SIZERECTTOMIN();
1990 test_MCM_GETCALENDARCOUNT();
1992 unload_v6_module(ctx_cookie, hCtx);
1994 DestroyWindow(parent_wnd);