comctl32/monthcal: Fix some day state problems.
[wine/multimedia.git] / dlls / comctl32 / tests / monthcal.c
blobf661242d34175c48f8527a5bc43aedd547129668
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[1] = st[0];
389 st[1].wYear++;
390 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN|GDTR_MAX, (LPARAM)st), "Failed to set limits\n");
391 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == (GDTR_MIN|GDTR_MAX), "Min limit expected\n");
392 st[1].wYear -= 2;
393 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set limits\n");
394 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "Max limit expected\n");
396 expect(0, st1[0].wYear);
397 expect(0, st1[0].wMonth);
398 expect(0, st1[0].wDay);
399 expect(0, st1[0].wDayOfWeek);
400 expect(0, st1[0].wHour);
401 expect(0, st1[0].wMinute);
402 expect(0, st1[0].wSecond);
403 expect(0, st1[0].wMilliseconds);
405 expect(st[1].wYear, st1[1].wYear);
406 expect(st[1].wMonth, st1[1].wMonth);
407 expect(st[1].wDay, st1[1].wDay);
408 expect(st[1].wDayOfWeek, st1[1].wDayOfWeek);
409 expect(st[1].wHour, st1[1].wHour);
410 expect(st[1].wMinute, st1[1].wMinute);
411 expect(st[1].wSecond, st1[1].wSecond);
412 expect(st[1].wMilliseconds, st1[1].wMilliseconds);
414 st[1] = st[0];
415 st[1].wYear++;
416 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN|GDTR_MAX, (LPARAM)st), "Failed to set limits\n");
417 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == (GDTR_MIN|GDTR_MAX), "Min limit expected\n");
418 st[0].wYear++; /* start == end now */
419 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN, (LPARAM)st), "Failed to set limits\n");
420 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MIN, "Min limit expected\n");
422 expect(st[0].wYear, st1[0].wYear);
423 expect(st[0].wMonth, st1[0].wMonth);
424 expect(st[0].wDay, st1[0].wDay);
425 expect(st[0].wDayOfWeek, st1[0].wDayOfWeek);
426 expect(st[0].wHour, st1[0].wHour);
427 expect(st[0].wMinute, st1[0].wMinute);
428 expect(st[0].wSecond, st1[0].wSecond);
429 expect(st[0].wMilliseconds, st1[0].wMilliseconds);
431 expect(0, st1[1].wYear);
432 expect(0, st1[1].wMonth);
433 expect(0, st1[1].wDay);
434 expect(0, st1[1].wDayOfWeek);
435 expect(0, st1[1].wHour);
436 expect(0, st1[1].wMinute);
437 expect(0, st1[1].wSecond);
438 expect(0, st1[1].wMilliseconds);
440 DestroyWindow(hwnd);
443 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
445 static LONG defwndproc_counter = 0;
446 LRESULT ret;
447 struct message msg;
449 /* log system messages, except for painting */
450 if (message < WM_USER &&
451 message != WM_PAINT &&
452 message != WM_ERASEBKGND &&
453 message != WM_NCPAINT &&
454 message != WM_NCHITTEST &&
455 message != WM_GETTEXT &&
456 message != WM_GETICON &&
457 message != WM_DEVICECHANGE)
459 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
461 msg.message = message;
462 msg.flags = sent|wparam|lparam;
463 if (defwndproc_counter) msg.flags |= defwinproc;
464 msg.wParam = wParam;
465 msg.lParam = lParam;
466 add_message(sequences, PARENT_SEQ_INDEX, &msg);
469 defwndproc_counter++;
470 ret = DefWindowProcA(hwnd, message, wParam, lParam);
471 defwndproc_counter--;
473 return ret;
476 static BOOL register_parent_wnd_class(void)
478 WNDCLASSA cls;
480 cls.style = 0;
481 cls.lpfnWndProc = parent_wnd_proc;
482 cls.cbClsExtra = 0;
483 cls.cbWndExtra = 0;
484 cls.hInstance = GetModuleHandleA(NULL);
485 cls.hIcon = 0;
486 cls.hCursor = LoadCursorA(0, IDC_ARROW);
487 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
488 cls.lpszMenuName = NULL;
489 cls.lpszClassName = "Month-Cal test parent class";
490 return RegisterClassA(&cls);
493 static HWND create_parent_window(void)
495 HWND hwnd;
497 InitCommonControls();
499 /* flush message sequences, so we can check the new sequence by the end of function */
500 flush_sequences(sequences, NUM_MSG_SEQUENCES);
502 if (!register_parent_wnd_class())
503 return NULL;
505 hwnd = CreateWindowEx(0, "Month-Cal test parent class",
506 "Month-Cal test parent window",
507 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
508 WS_MAXIMIZEBOX | WS_VISIBLE,
509 0, 0, 500, 500,
510 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
512 assert(hwnd);
514 /* check for message sequences */
515 ok_sequence(sequences, PARENT_SEQ_INDEX, create_parent_window_seq, "create parent window", FALSE);
517 return hwnd;
520 static LRESULT WINAPI monthcal_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
522 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
523 static LONG defwndproc_counter = 0;
524 LRESULT ret;
525 struct message msg;
527 msg.message = message;
528 msg.flags = sent|wparam|lparam;
529 if (defwndproc_counter) msg.flags |= defwinproc;
530 msg.wParam = wParam;
531 msg.lParam = lParam;
532 add_message(sequences, MONTHCAL_SEQ_INDEX, &msg);
534 /* some debug output for style changing */
535 if ((message == WM_STYLECHANGING ||
536 message == WM_STYLECHANGED) && lParam)
538 STYLESTRUCT *style = (STYLESTRUCT*)lParam;
539 trace("\told style: 0x%08x, new style: 0x%08x\n", style->styleOld, style->styleNew);
542 defwndproc_counter++;
543 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
544 defwndproc_counter--;
546 return ret;
549 static HWND create_monthcal_control(DWORD style)
551 WNDPROC oldproc;
552 HWND hwnd;
554 hwnd = CreateWindowEx(0,
555 MONTHCAL_CLASS,
557 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
558 0, 0, 300, 400,
559 parent_wnd, NULL, GetModuleHandleA(NULL), NULL);
561 if (!hwnd) return NULL;
563 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
564 (LONG_PTR)monthcal_subclass_proc);
565 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
567 SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(SYSTEM_FONT), 0);
569 return hwnd;
573 /* Setter and Getters Tests */
575 static void test_color(void)
577 COLORREF color, prev;
578 HWND hwnd;
580 hwnd = create_monthcal_control(0);
582 /* invalid color index */
583 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT + 1, 0);
584 expect(~0u, color);
585 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT + 1, RGB(255,255,255));
586 expect(~0u, prev);
588 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
589 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(0,0,0));
590 expect(color, prev);
591 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
592 expect(RGB(0,0,0), color);
593 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(255,255,255));
594 expect(color, prev);
595 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
596 expect(RGB(255,255,255), color);
598 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
599 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(0,0,0));
600 expect(color, prev);
601 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
602 expect(RGB(0,0,0), color);
603 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(255,255,255));
604 expect(color, prev);
605 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
606 expect(RGB(255,255,255), color);
608 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
609 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(0,0,0));
610 expect(color, prev);
611 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
612 expect(RGB(0,0,0), color);
613 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(255,255,255));
614 expect(color, prev);
615 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
616 expect(RGB(255,255,255), color);
618 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
619 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(0,0,0));
620 expect(color, prev);
621 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
622 expect(RGB(0,0,0), color);
623 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(255,255,255));
624 expect(color, prev);
625 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
626 expect(RGB(255,255,255), color);
628 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
629 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(0,0,0));
630 expect(color, prev);
631 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
632 expect(RGB(0,0,0), color);
633 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(255,255,255));
634 expect(color, prev);
635 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
636 expect(RGB(255,255,255), color);
638 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
639 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(0,0,0));
640 expect(color, prev);
641 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
642 expect(RGB(0,0,0), color);
643 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(255,255,255));
644 expect(color, prev);
645 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
646 expect(RGB(255,255,255), color);
648 DestroyWindow(hwnd);
651 static void test_currdate(void)
653 SYSTEMTIME st_original, st_new, st_test;
654 int res;
655 HWND hwnd;
657 hwnd = create_monthcal_control(0);
659 flush_sequences(sequences, NUM_MSG_SEQUENCES);
661 /* Setter and Getters for current date selected */
662 st_original.wYear = 2000;
663 st_original.wMonth = 11;
664 st_original.wDay = 28;
665 st_original.wHour = 11;
666 st_original.wMinute = 59;
667 st_original.wSecond = 30;
668 st_original.wMilliseconds = 0;
669 st_original.wDayOfWeek = 0;
671 st_new = st_test = st_original;
673 /* Should not validate the time */
674 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
675 expect(1,res);
677 /* Overflow matters, check for wDay */
678 st_test.wDay += 4;
679 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
680 expect(0,res);
682 /* correct wDay before checking for wMonth */
683 st_test.wDay -= 4;
684 expect(st_original.wDay, st_test.wDay);
686 /* Overflow matters, check for wMonth */
687 st_test.wMonth += 4;
688 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
689 expect(0,res);
691 /* checking if gets the information right, modify st_new */
692 st_new.wYear += 4;
693 st_new.wMonth += 4;
694 st_new.wDay += 4;
695 st_new.wHour += 4;
696 st_new.wMinute += 4;
697 st_new.wSecond += 4;
699 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_new);
700 expect(1, res);
702 /* st_new change to st_origin, above settings with overflow */
703 /* should not change the current settings */
704 expect(st_original.wYear, st_new.wYear);
705 expect(st_original.wMonth, st_new.wMonth);
706 expect(st_original.wDay, st_new.wDay);
707 ok(st_original.wHour == st_new.wHour ||
708 broken(0 == st_new.wHour), /* comctl32 <= 4.70 */
709 "Expected %d, got %d\n", st_original.wHour, st_new.wHour);
710 ok(st_original.wMinute == st_new.wMinute ||
711 broken(0 == st_new.wMinute), /* comctl32 <= 4.70 */
712 "Expected %d, got %d\n", st_original.wMinute, st_new.wMinute);
713 ok(st_original.wSecond == st_new.wSecond ||
714 broken(0 == st_new.wSecond), /* comctl32 <= 4.70 */
715 "Expected %d, got %d\n", st_original.wSecond, st_new.wSecond);
717 /* lparam cannot be NULL */
718 res = SendMessage(hwnd, MCM_GETCURSEL, 0, 0);
719 expect(0, res);
721 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_curr_date_seq, "monthcal currDate", TRUE);
723 /* December, 31, 9999 is the maximum allowed date */
724 memset(&st_new, 0, sizeof(st_new));
725 st_new.wYear = 9999;
726 st_new.wMonth = 12;
727 st_new.wDay = 31;
728 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
729 expect(1, res);
730 memset(&st_test, 0, sizeof(st_test));
731 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_test);
732 expect(1, res);
733 expect(st_new.wYear, st_test.wYear);
734 expect(st_new.wMonth, st_test.wMonth);
735 expect(st_new.wDay, st_test.wDay);
736 expect(st_new.wHour, st_test.wHour);
737 expect(st_new.wMinute, st_test.wMinute);
738 expect(st_new.wSecond, st_test.wSecond);
739 /* try one day later */
740 st_original = st_new;
741 st_new.wYear = 10000;
742 st_new.wMonth = 1;
743 st_new.wDay = 1;
744 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
745 ok(0 == res ||
746 broken(1 == res), /* comctl32 <= 4.72 */
747 "Expected 0, got %d\n", res);
748 if (0 == res)
750 memset(&st_test, 0, sizeof(st_test));
751 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_test);
752 expect(1, res);
753 expect(st_original.wYear, st_test.wYear);
754 expect(st_original.wMonth, st_test.wMonth);
755 expect(st_original.wDay, st_test.wDay);
756 expect(st_original.wHour, st_test.wHour);
757 expect(st_original.wMinute, st_test.wMinute);
758 expect(st_original.wSecond, st_test.wSecond);
761 /* setting selection equal to current reports success even if out range */
762 memset(&st_new, 0, sizeof(st_new));
763 st_new.wYear = 2009;
764 st_new.wDay = 5;
765 st_new.wMonth = 10;
766 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
767 expect(1, res);
768 memset(&st_test, 0, sizeof(st_test));
769 st_test.wYear = 2009;
770 st_test.wDay = 6;
771 st_test.wMonth = 10;
772 res = SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN, (LPARAM)&st_test);
773 expect(1, res);
774 /* set to current again */
775 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
776 expect(1, res);
778 DestroyWindow(hwnd);
781 static void test_firstDay(void)
783 int res, fday, i, prev;
784 CHAR b[128], caltype[3];
785 LCID lcid = LOCALE_USER_DEFAULT;
786 HWND hwnd;
787 LRESULT ret;
789 SetLastError(0xdeadbeef);
790 ret = GetLocaleInfoA(lcid, LOCALE_ICALENDARTYPE, caltype, 3);
791 if (ret == 0) {
792 skip("Must know local calendar type (%x)\n", GetLastError());
793 return;
794 } else if (atoi(caltype) != CAL_GREGORIAN) {
795 skip("MonthCalendar Control only supports Gregorian calendar (type: %s)\n", caltype);
796 return;
799 hwnd = create_monthcal_control(0);
801 flush_sequences(sequences, NUM_MSG_SEQUENCES);
803 /* Setter and Getters for first day of week */
804 /* check for locale first day */
805 if(GetLocaleInfoA(lcid, LOCALE_IFIRSTDAYOFWEEK, b, 128)){
806 fday = atoi(b);
807 trace("fday: %d\n", fday);
808 res = SendMessage(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
809 expect(fday, res);
810 prev = fday;
812 /* checking for the values that actually will be stored as */
813 /* current first day when we set a new value */
814 for (i = -5; i < 12; i++){
815 res = SendMessage(hwnd, MCM_SETFIRSTDAYOFWEEK, 0, i);
816 expect(prev, res);
817 res = SendMessage(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
818 prev = res;
820 if (i == -1){
821 expect(MAKELONG(fday, FALSE), res);
822 }else if (i >= 7){
823 /* out of range sets max first day of week, locale is ignored */
824 expect(MAKELONG(6, TRUE), res);
825 }else{
826 expect(MAKELONG(i, TRUE), res);
830 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_first_day_seq, "monthcal firstDay", FALSE);
832 }else{
833 skip("Cannot retrieve first day of the week\n");
836 DestroyWindow(hwnd);
839 static void test_unicode(void)
841 int res, temp;
842 HWND hwnd;
844 hwnd = create_monthcal_control(0);
846 flush_sequences(sequences, NUM_MSG_SEQUENCES);
848 /* Setter and Getters for Unicode format */
850 /* getting the current settings */
851 temp = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
853 /* setting to 1, should return previous settings */
854 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 1, 0);
855 expect(temp, res);
857 /* current setting is 1, so, should return 1 */
858 res = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
859 ok(1 == res ||
860 broken(0 == res), /* comctl32 <= 4.70 */
861 "Expected 1, got %d\n", res);
863 /* setting to 0, should return previous settings */
864 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 0, 0);
865 ok(1 == res ||
866 broken(0 == res), /* comctl32 <= 4.70 */
867 "Expected 1, got %d\n", res);
869 /* current setting is 0, so, it should return 0 */
870 res = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
871 expect(0, res);
873 /* should return previous settings */
874 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 1, 0);
875 expect(0, res);
877 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_unicode_seq, "monthcal unicode", FALSE);
879 DestroyWindow(hwnd);
882 static void test_hittest(void)
884 typedef struct hittest_test
886 UINT ht;
887 int todo;
888 } hittest_test_t;
890 static const hittest_test_t title_hits[] = {
891 /* Start is the same everywhere */
892 { MCHT_TITLE, 0 },
893 { MCHT_TITLEBTNPREV, 0 },
894 /* The middle piece is only tested for presence of items */
895 /* End is the same everywhere */
896 { MCHT_TITLEBTNNEXT, 0 },
897 { MCHT_TITLE, 0 },
898 { MCHT_NOWHERE, 1 }
901 MCHITTESTINFO mchit;
902 UINT res, old_res;
903 SYSTEMTIME st;
904 LONG x;
905 UINT title_index;
906 HWND hwnd;
907 RECT r;
908 char yearmonth[80], *locale_month, *locale_year;
909 int month_count, year_count;
910 BOOL in_the_middle;
912 memset(&mchit, 0, sizeof(MCHITTESTINFO));
914 hwnd = create_monthcal_control(0);
916 /* test with invalid structure size */
917 mchit.cbSize = MCHITTESTINFO_V1_SIZE - 1;
918 mchit.pt.x = 0;
919 mchit.pt.y = 0;
920 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
921 expect(0, mchit.pt.x);
922 expect(0, mchit.pt.y);
923 expect(~0u, res);
924 expect(0, mchit.uHit);
925 /* test with invalid pointer */
926 res = SendMessage(hwnd, MCM_HITTEST, 0, 0);
927 expect(~0u, res);
929 /* resize control to display single Calendar */
930 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
931 if (res == 0)
933 win_skip("Message MCM_GETMINREQRECT unsupported. Skipping.\n");
934 DestroyWindow(hwnd);
935 return;
937 MoveWindow(hwnd, 0, 0, r.right, r.bottom, FALSE);
939 flush_sequences(sequences, NUM_MSG_SEQUENCES);
941 st.wYear = 2007;
942 st.wMonth = 4;
943 st.wDay = 11;
944 st.wHour = 1;
945 st.wMinute = 0;
946 st.wSecond = 0;
947 st.wMilliseconds = 0;
948 st.wDayOfWeek = 0;
950 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st);
951 expect(1,res);
953 /* (0, 0) is the top left of the control - title */
954 mchit.cbSize = MCHITTESTINFO_V1_SIZE;
955 mchit.pt.x = 0;
956 mchit.pt.y = 0;
957 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
958 expect(0, mchit.pt.x);
959 expect(0, mchit.pt.y);
960 expect(mchit.uHit, res);
961 expect_hex(MCHT_TITLE, res);
963 /* bottom right of the control and should not be active */
964 mchit.pt.x = r.right;
965 mchit.pt.y = r.bottom;
966 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
967 expect(r.right, mchit.pt.x);
968 expect(r.bottom, mchit.pt.y);
969 expect(mchit.uHit, res);
970 todo_wine expect_hex(MCHT_NOWHERE, res);
972 /* completely out of the control, should not be active */
973 mchit.pt.x = 2 * r.right;
974 mchit.pt.y = 2 * r.bottom;
975 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
976 expect(2 * r.right, mchit.pt.x);
977 expect(2 * r.bottom, mchit.pt.y);
978 expect(mchit.uHit, res);
979 todo_wine expect_hex(MCHT_NOWHERE, res);
981 /* in active area - day of the week */
982 mchit.pt.x = r.right / 2;
983 mchit.pt.y = r.bottom / 2;
984 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
985 expect(r.right / 2, mchit.pt.x);
986 expect(r.bottom / 2, mchit.pt.y);
987 expect(mchit.uHit, res);
988 expect_hex(MCHT_CALENDARDATE, res);
990 /* in active area - day of the week #2 */
991 mchit.pt.x = r.right / 14; /* half of first day rect */
992 mchit.pt.y = r.bottom / 2;
993 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
994 expect(r.right / 14, mchit.pt.x);
995 expect(r.bottom / 2, mchit.pt.y);
996 expect(mchit.uHit, res);
997 expect_hex(MCHT_CALENDARDATE, res);
999 /* in active area - date from prev month */
1000 mchit.pt.x = r.right / 14; /* half of first day rect */
1001 mchit.pt.y = 6 * r.bottom / 19;
1002 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1003 expect(r.right / 14, mchit.pt.x);
1004 expect(6 * r.bottom / 19, mchit.pt.y);
1005 expect(mchit.uHit, res);
1006 expect_hex(MCHT_CALENDARDATEPREV, res);
1008 #if 0
1009 /* (125, 115) is in active area - date from this month */
1010 mchit.pt.x = 125;
1011 mchit.pt.y = 115;
1012 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1013 expect(125, mchit.pt.x);
1014 expect(115, mchit.pt.y);
1015 expect(mchit.uHit, res);
1016 expect(MCHT_CALENDARDATE, res);
1017 #endif
1019 /* in active area - date from next month */
1020 mchit.pt.x = 11 * r.right / 14;
1021 mchit.pt.y = 16 * r.bottom / 19;
1022 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1023 expect(11 * r.right / 14, mchit.pt.x);
1024 expect(16 * r.bottom / 19, mchit.pt.y);
1025 expect(mchit.uHit, res);
1026 expect_hex(MCHT_CALENDARDATENEXT, res);
1028 /* in active area - today link */
1029 mchit.pt.x = r.right / 14;
1030 mchit.pt.y = 18 * r.bottom / 19;
1031 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1032 expect(r.right / 14, mchit.pt.x);
1033 expect(18 * r.bottom / 19, mchit.pt.y);
1034 expect(mchit.uHit, res);
1035 expect_hex(MCHT_TODAYLINK, res);
1037 /* in active area - today link */
1038 mchit.pt.x = r.right / 2;
1039 mchit.pt.y = 18 * r.bottom / 19;
1040 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1041 expect(r.right / 2, mchit.pt.x);
1042 expect(18 * r.bottom / 19, mchit.pt.y);
1043 expect(mchit.uHit, res);
1044 expect_hex(MCHT_TODAYLINK, res);
1046 /* in active area - today link */
1047 mchit.pt.x = r.right / 10;
1048 mchit.pt.y = 18 * r.bottom / 19;
1049 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1050 expect(r.right / 10, mchit.pt.x);
1051 expect(18 * r.bottom / 19, mchit.pt.y);
1052 expect(mchit.uHit, res);
1053 expect_hex(MCHT_TODAYLINK, res);
1055 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_hit_test_seq, "monthcal hit test", TRUE);
1057 /* The horizontal position of title bar elements depends on locale (y pos
1058 is constant), so we sample across a horizontal line and make sure we
1059 find all elements. */
1061 /* Get the format of the title */
1062 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SYEARMONTH, yearmonth, 80);
1063 /* Find out if we have a month and/or year */
1064 locale_year = strstr(yearmonth, "y");
1065 locale_month = strstr(yearmonth, "M");
1067 mchit.pt.x = 0;
1068 mchit.pt.y = (5/2) * r.bottom / 19;
1069 title_index = 0;
1070 old_res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1071 expect_hex(title_hits[title_index].ht, old_res);
1073 in_the_middle = FALSE;
1074 month_count = year_count = 0;
1075 for (x = 0; x < r.right; x++){
1076 mchit.pt.x = x;
1077 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1078 expect(x, mchit.pt.x);
1079 expect((5/2) * r.bottom / 19, mchit.pt.y);
1080 expect(mchit.uHit, res);
1081 if (res != old_res) {
1083 if (old_res == MCHT_TITLEBTNPREV)
1084 in_the_middle = TRUE;
1086 if (res == MCHT_TITLEBTNNEXT)
1087 in_the_middle = FALSE;
1089 if (in_the_middle) {
1090 if (res == MCHT_TITLEMONTH)
1091 month_count++;
1092 else if (res == MCHT_TITLEYEAR)
1093 year_count++;
1094 } else {
1095 title_index++;
1097 if (sizeof(title_hits) / sizeof(title_hits[0]) <= title_index)
1098 break;
1100 if (title_hits[title_index].todo) {
1101 todo_wine
1102 ok(title_hits[title_index].ht == res, "Expected %x, got %x, pos %d\n",
1103 title_hits[title_index].ht, res, x);
1104 } else {
1105 ok(title_hits[title_index].ht == res, "Expected %x, got %x, pos %d\n",
1106 title_hits[title_index].ht, res, x);
1109 old_res = res;
1113 /* There are some limits, even if LOCALE_SYEARMONTH contains rubbish
1114 * or no month/year indicators at all */
1115 if (locale_month)
1116 todo_wine ok(month_count == 1, "Expected 1 month item, got %d\n", month_count);
1117 else
1118 ok(month_count <= 1, "Too many month items: %d\n", month_count);
1120 if (locale_year)
1121 todo_wine ok(year_count == 1, "Expected 1 year item, got %d\n", year_count);
1122 else
1123 ok(year_count <= 1, "Too many year items: %d\n", year_count);
1125 todo_wine ok(month_count + year_count >= 1, "Not enough month and year items\n");
1127 ok(r.right <= x && title_index + 1 == sizeof(title_hits) / sizeof(title_hits[0]),
1128 "Wrong title layout\n");
1130 DestroyWindow(hwnd);
1133 static void test_todaylink(void)
1135 MCHITTESTINFO mchit;
1136 SYSTEMTIME st_test, st_new;
1137 UINT res;
1138 HWND hwnd;
1139 RECT r;
1141 memset(&mchit, 0, sizeof(MCHITTESTINFO));
1143 hwnd = create_monthcal_control(0);
1145 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
1146 expect(1, res);
1147 MoveWindow(hwnd, 0, 0, r.right, r.bottom, FALSE);
1149 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1151 /* hit active area - today link */
1152 mchit.cbSize = MCHITTESTINFO_V1_SIZE;
1153 mchit.pt.x = r.right / 14;
1154 mchit.pt.y = 18 * r.bottom / 19;
1155 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1156 expect(r.right / 14, mchit.pt.x);
1157 expect(18 * r.bottom / 19, mchit.pt.y);
1158 expect(mchit.uHit, res);
1159 expect(MCHT_TODAYLINK, res);
1161 st_test.wDay = 1;
1162 st_test.wMonth = 1;
1163 st_test.wYear = 2005;
1165 SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
1167 memset(&st_new, 0, sizeof(st_new));
1168 res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
1169 expect(1, res);
1170 expect(1, st_new.wDay);
1171 expect(1, st_new.wMonth);
1172 expect(2005, st_new.wYear);
1174 res = SendMessage(hwnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELONG(mchit.pt.x, mchit.pt.y));
1175 expect(0, res);
1177 memset(&st_new, 0, sizeof(st_new));
1178 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_new);
1179 expect(1, res);
1180 expect(1, st_new.wDay);
1181 expect(1, st_new.wMonth);
1182 expect(2005, st_new.wYear);
1184 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_todaylink_seq, "monthcal hit test", TRUE);
1186 DestroyWindow(hwnd);
1189 static void test_today(void)
1191 SYSTEMTIME st_test, st_new;
1192 int res;
1193 HWND hwnd;
1195 hwnd = create_monthcal_control(0);
1197 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1199 /* Setter and Getters for "today" information */
1201 /* check for overflow, should be ok */
1202 memset(&st_test, 0, sizeof(st_test));
1203 st_test.wDay = 38;
1204 st_test.wMonth = 38;
1206 st_new.wDay = 27;
1207 st_new.wMonth = 27;
1209 SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
1211 res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
1212 expect(1, res);
1214 /* st_test should not change */
1215 expect(38, st_test.wDay);
1216 expect(38, st_test.wMonth);
1218 /* st_new should change, overflow does not matter */
1219 expect(38, st_new.wDay);
1220 expect(38, st_new.wMonth);
1222 /* check for zero, should be ok*/
1223 st_test.wDay = 0;
1224 st_test.wMonth = 0;
1226 SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
1228 res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
1229 expect(1, res);
1231 /* st_test should not change */
1232 expect(0, st_test.wDay);
1233 expect(0, st_test.wMonth);
1235 /* st_new should change to zero*/
1236 expect(0, st_new.wDay);
1237 expect(0, st_new.wMonth);
1239 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_today_seq, "monthcal today", TRUE);
1241 DestroyWindow(hwnd);
1244 static void test_scroll(void)
1246 int res;
1247 HWND hwnd;
1249 hwnd = create_monthcal_control(0);
1251 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1253 /* Setter and Getters for scroll rate */
1254 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 2, 0);
1255 expect(0, res);
1257 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 3, 0);
1258 expect(2, res);
1259 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1260 expect(3, res);
1262 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 12, 0);
1263 expect(3, res);
1264 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1265 expect(12, res);
1267 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 15, 0);
1268 expect(12, res);
1269 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1270 expect(15, res);
1272 res = SendMessage(hwnd, MCM_SETMONTHDELTA, -5, 0);
1273 expect(15, res);
1274 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1275 expect(-5, res);
1277 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_scroll_seq, "monthcal scroll", FALSE);
1279 DestroyWindow(hwnd);
1282 static void test_monthrange(void)
1284 int res;
1285 SYSTEMTIME st_visible[2], st_daystate[2], st;
1286 HWND hwnd;
1287 RECT r;
1289 hwnd = create_monthcal_control(0);
1291 st_visible[0].wYear = 0;
1292 st_visible[0].wMonth = 0;
1293 st_visible[0].wDay = 0;
1294 st_daystate[1] = st_daystate[0] = st_visible[1] = st_visible[0];
1296 st.wYear = 2000;
1297 st.wMonth = 11;
1298 st.wDay = 28;
1299 st.wHour = 11;
1300 st.wMinute = 59;
1301 st.wSecond = 30;
1302 st.wMilliseconds = 0;
1303 st.wDayOfWeek = 0;
1305 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st);
1306 expect(1,res);
1308 /* to be locale independent */
1309 SendMessage(hwnd, MCM_SETFIRSTDAYOFWEEK, 0, (LPARAM)6);
1311 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
1312 expect(TRUE, res);
1313 /* resize control to display two Calendars */
1314 MoveWindow(hwnd, 0, 0, r.right, (5/2)*r.bottom, FALSE);
1316 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1318 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st_visible);
1319 expect(2, res);
1320 expect(2000, st_visible[0].wYear);
1321 expect(11, st_visible[0].wMonth);
1322 expect(1, st_visible[0].wDay);
1323 expect(2000, st_visible[1].wYear);
1324 expect(12, st_visible[1].wMonth);
1325 expect(31, st_visible[1].wDay);
1327 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, (LPARAM)st_daystate);
1328 expect(4, res);
1329 expect(2000, st_daystate[0].wYear);
1330 expect(10, st_daystate[0].wMonth);
1331 expect(29, st_daystate[0].wDay);
1332 expect(2001, st_daystate[1].wYear);
1333 expect(1, st_daystate[1].wMonth);
1334 expect(6, st_daystate[1].wDay);
1336 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_monthrange_seq, "monthcal monthrange", FALSE);
1338 /* with null date array parameter */
1339 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, 0);
1340 expect(2, res);
1342 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, 0);
1343 expect(4, res);
1345 /* resize control to display single Calendar */
1346 MoveWindow(hwnd, 0, 0, r.right, r.bottom, FALSE);
1348 memset(&st, 0, sizeof(st));
1349 st.wMonth = 9;
1350 st.wYear = 1752;
1351 st.wDay = 14;
1353 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st);
1354 expect(1, res);
1356 /* September 1752 has 19 days */
1357 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st_visible);
1358 expect(1, res);
1360 expect(1752, st_visible[0].wYear);
1361 expect(9, st_visible[0].wMonth);
1362 ok(14 == st_visible[0].wDay ||
1363 broken(1 == st_visible[0].wDay), /* comctl32 <= 4.72 */
1364 "Expected 14, got %d\n", st_visible[0].wDay);
1366 expect(1752, st_visible[1].wYear);
1367 expect(9, st_visible[1].wMonth);
1368 expect(19, st_visible[1].wDay);
1370 DestroyWindow(hwnd);
1373 static void test_maxselday(void)
1375 int res;
1376 HWND hwnd;
1377 DWORD style;
1379 hwnd = create_monthcal_control(0);
1380 /* if no style specified default to 1 */
1381 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1382 expect(1, res);
1383 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 5, 0);
1384 expect(0, res);
1385 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1386 expect(1, res);
1388 /* try to set style */
1389 style = GetWindowLong(hwnd, GWL_STYLE);
1390 SetWindowLong(hwnd, GWL_STYLE, style | MCS_MULTISELECT);
1391 style = GetWindowLong(hwnd, GWL_STYLE);
1392 ok(!(style & MCS_MULTISELECT), "Expected MCS_MULTISELECT not to be set\n");
1393 DestroyWindow(hwnd);
1395 hwnd = create_monthcal_control(MCS_MULTISELECT);
1396 /* try to remove style */
1397 style = GetWindowLong(hwnd, GWL_STYLE);
1398 SetWindowLong(hwnd, GWL_STYLE, style & ~MCS_MULTISELECT);
1399 style = GetWindowLong(hwnd, GWL_STYLE);
1400 ok(style & MCS_MULTISELECT, "Expected MCS_MULTISELECT to be set\n");
1401 DestroyWindow(hwnd);
1403 hwnd = create_monthcal_control(MCS_MULTISELECT);
1405 /* default width is a week */
1406 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1407 expect(7, res);
1409 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1411 /* Setter and Getters for max selected days */
1412 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 5, 0);
1413 expect(1, res);
1414 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1415 expect(5, res);
1417 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 15, 0);
1418 expect(1, res);
1419 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1420 expect(15, res);
1422 /* test invalid value */
1423 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, -1, 0);
1424 expect(0, res);
1425 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1426 expect(15, res);
1428 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_max_sel_day_seq, "monthcal MaxSelDay", FALSE);
1430 /* zero value is invalid too */
1431 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 0, 0);
1432 expect(0, res);
1433 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1434 expect(15, res);
1436 DestroyWindow(hwnd);
1439 static void test_size(void)
1441 int res;
1442 RECT r1, r2;
1443 HFONT hFont1, hFont2;
1444 LOGFONTA logfont;
1445 HWND hwnd;
1447 hwnd = create_monthcal_control(0);
1449 lstrcpyA(logfont.lfFaceName, "Arial");
1450 memset(&logfont, 0, sizeof(logfont));
1451 logfont.lfHeight = 12;
1452 hFont1 = CreateFontIndirectA(&logfont);
1454 logfont.lfHeight = 24;
1455 hFont2 = CreateFontIndirectA(&logfont);
1457 /* initialize to a font we can compare against */
1458 SendMessage(hwnd, WM_SETFONT, (WPARAM)hFont1, 0);
1459 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r1);
1460 ok(res, "SendMessage(MCM_GETMINREQRECT) failed\n");
1462 /* check that setting a larger font results in an larger rect */
1463 SendMessage(hwnd, WM_SETFONT, (WPARAM)hFont2, 0);
1464 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r2);
1465 ok(res, "SendMessage(MCM_GETMINREQRECT) failed\n");
1467 OffsetRect(&r1, -r1.left, -r1.top);
1468 OffsetRect(&r2, -r2.left, -r2.top);
1470 ok(r1.bottom < r2.bottom, "Failed to get larger rect with larger font\n");
1472 DestroyWindow(hwnd);
1475 static void test_create(void)
1477 HWND hwnd;
1479 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1481 hwnd = create_monthcal_control(0);
1482 ok_sequence(sequences, PARENT_SEQ_INDEX, create_monthcal_control_seq, "create monthcal control", TRUE);
1484 DestroyWindow(hwnd);
1486 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1487 hwnd = create_monthcal_control(MCS_MULTISELECT);
1488 ok_sequence(sequences, PARENT_SEQ_INDEX, create_monthcal_multi_sel_style_seq, "create monthcal (multi sel style)", TRUE);
1489 DestroyWindow(hwnd);
1492 static void test_destroy(void)
1494 HWND hwnd;
1496 hwnd = create_monthcal_control(0);
1497 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1498 DestroyWindow(hwnd);
1499 ok_sequence(sequences, PARENT_SEQ_INDEX, destroy_monthcal_parent_msgs_seq, "Destroy monthcal (parent msg)", FALSE);
1500 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, destroy_monthcal_child_msgs_seq, "Destroy monthcal (child msg)", FALSE);
1502 /* MCS_MULTISELECT */
1503 hwnd = create_monthcal_control(MCS_MULTISELECT);
1504 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1505 DestroyWindow(hwnd);
1506 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, destroy_monthcal_multi_sel_style_seq, "Destroy monthcal (multi sel style)", FALSE);
1509 static void test_selrange(void)
1511 HWND hwnd;
1512 SYSTEMTIME st, range[2], range2[2];
1513 BOOL ret, old_comctl32 = FALSE;
1515 hwnd = create_monthcal_control(MCS_MULTISELECT);
1517 /* just after creation selection should start and end today */
1518 ret = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st);
1519 expect(TRUE, ret);
1521 memset(range, 0xcc, sizeof(range));
1522 ret = SendMessage(hwnd, MCM_GETSELRANGE, 0, (LPARAM)range);
1523 expect(TRUE, ret);
1524 expect(st.wYear, range[0].wYear);
1525 expect(st.wMonth, range[0].wMonth);
1526 expect(st.wDay, range[0].wDay);
1527 if (range[0].wDayOfWeek != st.wDayOfWeek)
1529 win_skip("comctl32 <= 4.70 doesn't set some values\n");
1530 old_comctl32 = TRUE;
1532 else
1534 expect(st.wDayOfWeek, range[0].wDayOfWeek);
1535 expect(st.wHour, range[0].wHour);
1536 expect(st.wMinute, range[0].wMinute);
1537 expect(st.wSecond, range[0].wSecond);
1538 expect(st.wMilliseconds, range[0].wMilliseconds);
1541 expect(st.wYear, range[1].wYear);
1542 expect(st.wMonth, range[1].wMonth);
1543 expect(st.wDay, range[1].wDay);
1544 if (!old_comctl32)
1546 expect(st.wDayOfWeek, range[1].wDayOfWeek);
1547 expect(st.wHour, range[1].wHour);
1548 expect(st.wMinute, range[1].wMinute);
1549 expect(st.wSecond, range[1].wSecond);
1550 expect(st.wMilliseconds, range[1].wMilliseconds);
1553 /* bounds are swapped if min > max */
1554 memset(&range[0], 0, sizeof(range[0]));
1555 range[0].wYear = 2009;
1556 range[0].wMonth = 10;
1557 range[0].wDay = 5;
1558 range[1] = range[0];
1559 range[1].wDay = 3;
1561 ret = SendMessage(hwnd, MCM_SETSELRANGE, 0, (LPARAM)range);
1562 expect(TRUE, ret);
1564 ret = SendMessage(hwnd, MCM_GETSELRANGE, 0, (LPARAM)range2);
1565 expect(TRUE, ret);
1567 expect(range[1].wYear, range2[0].wYear);
1568 expect(range[1].wMonth, range2[0].wMonth);
1569 expect(range[1].wDay, range2[0].wDay);
1570 expect(6, range2[0].wDayOfWeek);
1571 expect(range[1].wHour, range2[0].wHour);
1572 expect(range[1].wMinute, range2[0].wMinute);
1573 expect(range[1].wSecond, range2[0].wSecond);
1574 expect(range[1].wMilliseconds, range2[0].wMilliseconds);
1576 expect(range[0].wYear, range2[1].wYear);
1577 expect(range[0].wMonth, range2[1].wMonth);
1578 expect(range[0].wDay, range2[1].wDay);
1579 expect(1, range2[1].wDayOfWeek);
1580 expect(range[0].wHour, range2[1].wHour);
1581 expect(range[0].wMinute, range2[1].wMinute);
1582 expect(range[0].wSecond, range2[1].wSecond);
1583 expect(range[0].wMilliseconds, range2[1].wMilliseconds);
1585 /* try with range larger than maximum configured */
1586 memset(&range[0], 0, sizeof(range[0]));
1587 range[0].wYear = 2009;
1588 range[0].wMonth = 10;
1589 range[0].wDay = 1;
1590 range[1] = range[0];
1592 ret = SendMessage(hwnd, MCM_SETSELRANGE, 0, (LPARAM)range);
1593 expect(TRUE, ret);
1595 range[1] = range[0];
1596 /* default max. range is 7 days */
1597 range[1].wDay = 8;
1599 ret = SendMessage(hwnd, MCM_SETSELRANGE, 0, (LPARAM)range);
1600 expect(FALSE, ret);
1602 ret = SendMessage(hwnd, MCM_GETSELRANGE, 0, (LPARAM)range2);
1603 expect(TRUE, ret);
1605 expect(range[0].wYear, range2[0].wYear);
1606 expect(range[0].wMonth, range2[0].wMonth);
1607 expect(range[0].wDay, range2[0].wDay);
1608 expect(range[0].wYear, range2[1].wYear);
1609 expect(range[0].wMonth, range2[1].wMonth);
1610 expect(range[0].wDay, range2[1].wDay);
1612 DestroyWindow(hwnd);
1615 static void test_killfocus(void)
1617 HWND hwnd;
1618 DWORD style;
1620 hwnd = create_monthcal_control(0);
1622 /* make parent invisible */
1623 style = GetWindowLong(parent_wnd, GWL_STYLE);
1624 SetWindowLong(parent_wnd, GWL_STYLE, style &~ WS_VISIBLE);
1626 SendMessage(hwnd, WM_KILLFOCUS, (WPARAM)GetDesktopWindow(), 0);
1628 style = GetWindowLong(hwnd, GWL_STYLE);
1629 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
1631 style = GetWindowLong(parent_wnd, GWL_STYLE);
1632 SetWindowLong(parent_wnd, GWL_STYLE, style | WS_VISIBLE);
1634 DestroyWindow(hwnd);
1637 static void test_hittest_v6(void)
1639 MCHITTESTINFO mchit;
1640 DWORD ret;
1641 HWND hwnd;
1642 RECT r;
1644 hwnd = create_monthcal_control(0);
1645 SendMessage(hwnd, MCM_SETCALENDARBORDER, TRUE, 0);
1647 SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
1648 /* reserving some area around calendar */
1649 MoveWindow(hwnd, 0, 0, r.right * 3 / 2, r.bottom * 3 / 2, FALSE);
1650 mchit.cbSize = sizeof(MCHITTESTINFO);
1651 mchit.pt.x = mchit.pt.y = 0;
1652 mchit.iOffset = -1;
1653 mchit.iRow = -1;
1654 mchit.iCol = -1;
1655 ret = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1656 if (ret == ~0u)
1658 win_skip("Only MCHITTESTINFO_V1 supported\n");
1659 DestroyWindow(hwnd);
1660 return;
1662 todo_wine expect_hex(MCHT_NOWHERE, ret);
1663 expect(-1, mchit.iOffset);
1664 expect(-1, mchit.iRow);
1665 expect(-1, mchit.iCol);
1667 MoveWindow(hwnd, 0, 0, r.right, r.bottom, FALSE);
1668 mchit.pt.x = r.right / 2;
1669 mchit.pt.y = r.bottom / 2;
1670 mchit.iOffset = -1;
1671 ret = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1672 expect_hex(MCHT_CALENDARDATE, ret);
1673 expect(0, mchit.iOffset);
1675 /* over day area */
1676 mchit.pt.x = r.right / (7*2);
1677 mchit.pt.y = r.bottom / 2;
1678 mchit.iOffset = -1;
1679 mchit.iCol = mchit.iRow = -1;
1680 mchit.uHit = 0;
1681 mchit.rc.left = mchit.rc.right = mchit.rc.top = mchit.rc.bottom = -1;
1682 ret = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1683 expect_hex(MCHT_CALENDARDATE, ret);
1684 expect_hex(MCHT_CALENDARDATE, mchit.uHit);
1685 expect(0, mchit.iOffset);
1686 expect(2, mchit.iRow);
1687 expect(0, mchit.iCol);
1688 /* returned a one day rectangle */
1689 expect_d(r.right / 7, mchit.rc.right - mchit.rc.left);
1690 expect_d(r.bottom / 10, mchit.rc.bottom - mchit.rc.top);
1692 /* title */
1693 mchit.pt.x = 1;
1694 mchit.pt.y = 1;
1695 mchit.iOffset = -1;
1696 mchit.iCol = mchit.iRow = -1;
1697 mchit.uHit = 0;
1698 mchit.rc.left = mchit.rc.right = mchit.rc.top = mchit.rc.bottom = -1;
1699 ret = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1700 expect_hex(MCHT_TITLE, ret);
1701 expect_hex(MCHT_TITLE, mchit.uHit);
1702 expect(0, mchit.iOffset);
1703 expect(-1, mchit.iRow);
1704 expect(-1, mchit.iCol);
1705 expect(0, mchit.rc.left);
1706 expect(0, mchit.rc.top);
1707 expect_d(r.right, mchit.rc.right);
1708 ok(mchit.rc.bottom > 0, "got %d\n", mchit.rc.bottom);
1710 /* between two calendars */
1711 MoveWindow(hwnd, 0, 0, r.right * 5/2, r.bottom, FALSE);
1712 mchit.pt.x = r.right / (5*4);
1713 mchit.pt.y = r.bottom / 2;
1714 mchit.iOffset = -2;
1715 mchit.iCol = mchit.iRow = -2;
1716 mchit.uHit = ~0;
1717 mchit.rc.left = mchit.rc.right = mchit.rc.top = mchit.rc.bottom = -1;
1718 ret = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1719 todo_wine expect_hex(MCHT_NOWHERE, ret);
1720 todo_wine expect_hex(MCHT_NOWHERE, mchit.uHit);
1721 expect(-2, mchit.iOffset);
1722 expect(-2, mchit.iRow);
1723 expect(-2, mchit.iCol);
1724 todo_wine expect(0, mchit.rc.left);
1725 todo_wine expect(0, mchit.rc.top);
1726 todo_wine expect_d(r.right * 5/2, mchit.rc.right);
1727 todo_wine expect_d(r.bottom, mchit.rc.bottom);
1729 DestroyWindow(hwnd);
1732 static void test_get_set_border(void)
1734 HWND hwnd;
1735 DWORD ret;
1737 hwnd = create_monthcal_control(0);
1739 /* a non-default value */
1740 ret = SendMessage(hwnd, MCM_SETCALENDARBORDER, TRUE, 10);
1741 expect(0, ret);
1743 ret = SendMessage(hwnd, MCM_GETCALENDARBORDER, 0, 0);
1745 if (ret != 10)
1747 skip("MCM_GET/SETCALENDARBORDER not supported\n");
1748 DestroyWindow(hwnd);
1749 return;
1752 expect(10, ret);
1754 DestroyWindow(hwnd);
1757 static void test_MCM_SIZERECTTOMIN(void)
1759 HWND hwnd;
1760 DWORD ret;
1761 RECT r, r2;
1763 hwnd = create_monthcal_control(0);
1765 ret = SendMessageA(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r2);
1766 if (ret == 0)
1768 win_skip("Message MCM_GETMINREQRECT unsupported. Skipping.\n");
1769 DestroyWindow(hwnd);
1770 return;
1773 ret = SendMessageA(hwnd, MCM_SIZERECTTOMIN, 0, 0);
1774 ok(ret == 0, "got %d\n", ret);
1776 r.left = r.right = r.top = r.bottom = 0;
1777 ret = SendMessageA(hwnd, MCM_SIZERECTTOMIN, 0, (LPARAM)&r);
1778 if (ret == 0)
1780 skip("Message MCM_SIZERECTTOMIN unsupported. Skipping.\n");
1781 DestroyWindow(hwnd);
1782 return;
1784 ok(ret == 1, "got %d\n", ret);
1785 ok(r.left == 0 && r.right > 0, "got %d, %d\n", r.left, r.right);
1787 r = r2;
1788 ret = SendMessageA(hwnd, MCM_SIZERECTTOMIN, 0, (LPARAM)&r);
1789 ok(ret == 1, "got %d\n", ret);
1791 r2.right = (r2.right - r2.left) * 3;
1792 r2.bottom = (r2.bottom - r2.top) * 3;
1793 r2.left = r2.top = 0;
1794 ret = SendMessageA(hwnd, MCM_SIZERECTTOMIN, 0, (LPARAM)&r2);
1795 ok(ret == 1, "got %d\n", ret);
1797 DestroyWindow(hwnd);
1800 static void test_MCM_GETCALENDARCOUNT(void)
1802 HWND hwnd;
1803 DWORD ret;
1805 hwnd = create_monthcal_control(0);
1807 ret = SendMessageA(hwnd, MCM_GETCALENDARCOUNT, 0, 0);
1808 if (ret == 0)
1810 win_skip("Message MCM_GETCALENDARCOUNT unsupported. Skipping.\n");
1811 DestroyWindow(hwnd);
1812 return;
1815 expect(2, ret);
1817 DestroyWindow(hwnd);
1820 static void test_daystate(void)
1822 MONTHDAYSTATE state[4];
1823 DWORD ret, style;
1824 HWND hwnd;
1826 /* without MCS_DAYSTATE */
1827 hwnd = create_monthcal_control(0);
1829 ret = SendMessageA(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, 0);
1830 expect(4, ret);
1832 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 4, (LPARAM)&state);
1833 expect(0, ret);
1835 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 2, (LPARAM)&state);
1836 expect(0, ret);
1838 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 0, 0);
1839 expect(0, ret);
1841 /* try to switch on */
1842 SetWindowLongA(hwnd, GWL_STYLE, GetWindowLongA(hwnd, GWL_STYLE) | MCS_DAYSTATE);
1843 style = GetWindowLongA(hwnd, GWL_STYLE);
1844 ok((style & MCS_DAYSTATE) == 0, "got 0x%08x\n", style);
1846 DestroyWindow(hwnd);
1848 /* with MCS_DAYSTATE */
1849 hwnd = create_monthcal_control(MCS_DAYSTATE);
1851 ret = SendMessageA(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, 0);
1852 expect(4, ret);
1854 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 4, (LPARAM)&state);
1855 expect(1, ret);
1857 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 2, (LPARAM)&state);
1858 expect(0, ret);
1860 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 0, 0);
1861 expect(0, ret);
1863 /* try to switch off */
1864 SetWindowLongA(hwnd, GWL_STYLE, GetWindowLongA(hwnd, GWL_STYLE) & ~MCS_DAYSTATE);
1865 style = GetWindowLongA(hwnd, GWL_STYLE);
1866 ok((style & MCS_DAYSTATE) == MCS_DAYSTATE, "got 0x%08x\n", style);
1868 DestroyWindow(hwnd);
1871 START_TEST(monthcal)
1873 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
1874 INITCOMMONCONTROLSEX iccex;
1875 HMODULE hComctl32;
1876 HWND hwnd;
1878 ULONG_PTR ctx_cookie;
1879 HANDLE hCtx;
1881 hComctl32 = GetModuleHandleA("comctl32.dll");
1882 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
1883 if (!pInitCommonControlsEx)
1885 skip("InitCommonControlsEx() is missing. Skipping the tests\n");
1886 return;
1888 iccex.dwSize = sizeof(iccex);
1889 iccex.dwICC = ICC_DATE_CLASSES;
1890 pInitCommonControlsEx(&iccex);
1892 test_monthcal();
1894 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
1896 parent_wnd = create_parent_window();
1898 test_create();
1899 test_destroy();
1900 test_color();
1901 test_currdate();
1902 test_firstDay();
1903 test_unicode();
1904 test_today();
1905 test_scroll();
1906 test_monthrange();
1907 test_hittest();
1908 test_todaylink();
1909 test_size();
1910 test_maxselday();
1911 test_selrange();
1912 test_killfocus();
1913 test_daystate();
1915 if (!load_v6_module(&ctx_cookie, &hCtx))
1917 DestroyWindow(parent_wnd);
1918 return;
1921 /* this is a XP SP3 failure workaround */
1922 hwnd = CreateWindowExA(0, MONTHCAL_CLASSA, "foo",
1923 WS_CHILD | WS_BORDER | WS_VISIBLE,
1924 0, 0, 100, 100,
1925 parent_wnd, NULL, GetModuleHandleA(NULL), NULL);
1926 if (!IsWindow(hwnd))
1928 win_skip("FIXME: failed to create Monthcal window.\n");
1929 unload_v6_module(ctx_cookie, hCtx);
1930 DestroyWindow(parent_wnd);
1931 return;
1933 else
1934 DestroyWindow(hwnd);
1936 test_hittest_v6();
1937 test_get_set_border();
1938 test_MCM_SIZERECTTOMIN();
1939 test_MCM_GETCALENDARCOUNT();
1941 unload_v6_module(ctx_cookie, hCtx);
1943 DestroyWindow(parent_wnd);