comctl32/monthcal: Check configured selection range max width in MCM_SETSELRANGE...
[wine/hacks.git] / dlls / comctl32 / tests / monthcal.c
blob3b38e822fa61c0fb3c939e4784ebab6cd1d400ba
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 <assert.h>
32 #include <windows.h>
33 #include "msg.h"
35 #define expect(expected, got) ok(expected == got, "Expected %d, got %d\n", expected, got);
36 #define expect_hex(expected, got) ok(expected == got, "Expected %x, got %x\n", expected, got);
38 #define NUM_MSG_SEQUENCES 2
39 #define PARENT_SEQ_INDEX 0
40 #define MONTHCAL_SEQ_INDEX 1
42 struct subclass_info
44 WNDPROC oldproc;
47 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
49 static HWND parent_wnd;
51 static const struct message create_parent_window_seq[] = {
52 { WM_GETMINMAXINFO, sent },
53 { WM_NCCREATE, sent },
54 { WM_NCCALCSIZE, sent|wparam, 0 },
55 { WM_CREATE, sent },
56 { WM_SHOWWINDOW, sent|wparam, 1 },
57 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
58 { WM_QUERYNEWPALETTE, sent|optional },
59 { WM_WINDOWPOSCHANGING, sent|wparam|optional, 0 },
60 { WM_WINDOWPOSCHANGED, sent|optional },
61 { WM_ACTIVATEAPP, sent|wparam, 1 },
62 { WM_NCACTIVATE, sent },
63 { WM_ACTIVATE, sent|wparam, 1 },
64 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
65 { WM_IME_NOTIFY, sent|defwinproc|optional },
66 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
67 /* Win9x adds SWP_NOZORDER below */
68 { WM_WINDOWPOSCHANGED, sent, /*|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ },
69 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
70 { WM_SIZE, sent },
71 { WM_MOVE, sent },
72 { 0 }
75 static const struct message create_monthcal_control_seq[] = {
76 { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
77 { WM_QUERYUISTATE, sent|optional },
78 { WM_GETFONT, sent },
79 { WM_PARENTNOTIFY, sent|wparam, WM_CREATE},
80 { 0 }
83 static const struct message create_monthcal_multi_sel_style_seq[] = {
84 { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
85 { WM_QUERYUISTATE, sent|optional },
86 { WM_GETFONT, sent },
87 { WM_PARENTNOTIFY, sent },
88 { 0 }
91 static const struct message monthcal_color_seq[] = {
92 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, 0},
93 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, RGB(0,0,0)},
94 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, 0},
95 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, RGB(255,255,255)},
96 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, 0},
98 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, 0},
99 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, RGB(0,0,0)},
100 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, 0},
101 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, RGB(255,255,255)},
102 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, 0},
104 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TEXT, 0},
105 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TEXT, RGB(0,0,0)},
106 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TEXT, 0},
107 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TEXT, RGB(255,255,255)},
108 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TEXT, 0},
110 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, 0},
111 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, RGB(0,0,0)},
112 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, 0},
113 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, RGB(255,255,255)},
114 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, 0},
116 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, 0},
117 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, RGB(0,0,0)},
118 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, 0},
119 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, RGB(255,255,255)},
120 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, 0},
122 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, 0},
123 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, RGB(0,0,0)},
124 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, 0},
125 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, RGB(255,255,255)},
126 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, 0},
127 { 0 }
130 static const struct message monthcal_curr_date_seq[] = {
131 { MCM_SETCURSEL, sent|wparam, 0},
132 { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
133 { MCM_SETCURSEL, sent|wparam, 0},
134 { MCM_SETCURSEL, sent|wparam, 0},
135 { MCM_GETCURSEL, sent|wparam, 0},
136 { MCM_GETCURSEL, sent|wparam|lparam, 0, 0},
137 { 0 }
140 static const struct message monthcal_first_day_seq[] = {
141 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
143 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -5},
144 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
146 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -4},
147 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
149 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -3},
150 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
152 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -2},
153 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
155 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -1},
156 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
158 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
159 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
161 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 1},
162 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
164 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 2},
165 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
167 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 3},
168 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
170 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 4},
171 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
173 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 5},
174 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
176 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 6},
177 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
179 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 7},
180 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
182 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 8},
183 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
185 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 9},
186 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
188 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 10},
189 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
191 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 11},
192 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
193 { 0 }
196 static const struct message monthcal_unicode_seq[] = {
197 { MCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
198 { MCM_SETUNICODEFORMAT, sent|wparam|lparam, 1, 0},
199 { MCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
200 { MCM_SETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
201 { MCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
202 { MCM_SETUNICODEFORMAT, sent|wparam|lparam, 1, 0},
203 { 0 }
206 static const struct message monthcal_hit_test_seq[] = {
207 { MCM_SETCURSEL, sent|wparam, 0},
208 { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
209 { MCM_HITTEST, sent|wparam, 0},
210 { MCM_HITTEST, sent|wparam, 0},
211 { MCM_HITTEST, sent|wparam, 0},
212 { MCM_HITTEST, sent|wparam, 0},
213 { MCM_HITTEST, sent|wparam, 0},
214 { MCM_HITTEST, sent|wparam, 0},
215 { MCM_HITTEST, sent|wparam, 0},
216 { MCM_HITTEST, sent|wparam, 0},
217 { MCM_HITTEST, sent|wparam, 0},
218 { MCM_HITTEST, sent|wparam, 0},
219 { 0 }
222 static const struct message monthcal_todaylink_seq[] = {
223 { MCM_HITTEST, sent|wparam, 0},
224 { MCM_SETTODAY, sent|wparam, 0},
225 { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
226 { MCM_GETTODAY, sent|wparam, 0},
227 { WM_LBUTTONDOWN, sent|wparam|lparam, MK_LBUTTON, MAKELONG(70, 370)},
228 { WM_CAPTURECHANGED, sent|wparam|lparam|defwinproc, 0, 0},
229 { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
230 { MCM_GETCURSEL, sent|wparam, 0},
231 { 0 }
234 static const struct message monthcal_today_seq[] = {
235 { MCM_SETTODAY, sent|wparam, 0},
236 { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
237 { MCM_GETTODAY, sent|wparam, 0},
238 { MCM_SETTODAY, sent|wparam, 0},
239 { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
240 { MCM_GETTODAY, sent|wparam, 0},
241 { 0 }
244 static const struct message monthcal_scroll_seq[] = {
245 { MCM_SETMONTHDELTA, sent|wparam|lparam, 2, 0},
246 { MCM_SETMONTHDELTA, sent|wparam|lparam, 3, 0},
247 { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
248 { MCM_SETMONTHDELTA, sent|wparam|lparam, 12, 0},
249 { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
250 { MCM_SETMONTHDELTA, sent|wparam|lparam, 15, 0},
251 { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
252 { MCM_SETMONTHDELTA, sent|wparam|lparam, -5, 0},
253 { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
254 { 0 }
257 static const struct message monthcal_monthrange_seq[] = {
258 { MCM_GETMONTHRANGE, sent|wparam, GMR_VISIBLE},
259 { MCM_GETMONTHRANGE, sent|wparam, GMR_DAYSTATE},
260 { 0 }
263 static const struct message monthcal_max_sel_day_seq[] = {
264 { MCM_SETMAXSELCOUNT, sent|wparam|lparam, 5, 0},
265 { MCM_GETMAXSELCOUNT, sent|wparam|lparam, 0, 0},
266 { MCM_SETMAXSELCOUNT, sent|wparam|lparam, 15, 0},
267 { MCM_GETMAXSELCOUNT, sent|wparam|lparam, 0, 0},
268 { MCM_SETMAXSELCOUNT, sent|wparam|lparam, -1, 0},
269 { MCM_GETMAXSELCOUNT, sent|wparam|lparam, 0, 0},
270 { 0 }
273 /* expected message sequence for parent*/
274 static const struct message destroy_monthcal_parent_msgs_seq[] = {
275 { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY},
276 { 0 }
279 /* expected message sequence for child*/
280 static const struct message destroy_monthcal_child_msgs_seq[] = {
281 { 0x0090, sent|optional }, /* Vista */
282 { WM_SHOWWINDOW, sent|wparam|lparam, 0, 0},
283 { WM_WINDOWPOSCHANGING, sent|wparam, 0},
284 { WM_WINDOWPOSCHANGED, sent|wparam, 0},
285 { WM_DESTROY, sent|wparam|lparam, 0, 0},
286 { WM_NCDESTROY, sent|wparam|lparam, 0, 0},
287 { 0 }
290 static const struct message destroy_monthcal_multi_sel_style_seq[] = {
291 { 0x0090, sent|optional }, /* Vista */
292 { WM_SHOWWINDOW, sent|wparam|lparam, 0, 0},
293 { WM_WINDOWPOSCHANGING, sent|wparam, 0},
294 { WM_WINDOWPOSCHANGED, sent|wparam, 0},
295 { WM_DESTROY, sent|wparam|lparam, 0, 0},
296 { WM_NCDESTROY, sent|wparam|lparam, 0, 0},
297 { 0 }
300 /* expected message sequence for parent window*/
301 static const struct message destroy_parent_seq[] = {
302 { 0x0090, sent|optional }, /* Vista */
303 { WM_WINDOWPOSCHANGING, sent|wparam, 0},
304 { WM_WINDOWPOSCHANGED, sent|wparam, 0},
305 { WM_IME_SETCONTEXT, sent|wparam|optional, 0},
306 { WM_IME_NOTIFY, sent|wparam|lparam|defwinproc|optional, 1, 0},
307 { WM_NCACTIVATE, sent|wparam|optional, 0},
308 { WM_ACTIVATE, sent|wparam|optional, 0},
309 { WM_NCACTIVATE, sent|wparam|lparam|optional, 0, 0},
310 { WM_ACTIVATE, sent|wparam|lparam|optional, 0, 0},
311 { WM_ACTIVATEAPP, sent|wparam|optional, 0},
312 { WM_KILLFOCUS, sent|wparam|lparam|optional, 0, 0},
313 { WM_IME_SETCONTEXT, sent|wparam|optional, 0},
314 { WM_IME_NOTIFY, sent|wparam|lparam|defwinproc|optional, 1, 0},
315 { WM_DESTROY, sent|wparam|lparam, 0, 0},
316 { WM_NCDESTROY, sent|wparam|lparam, 0, 0},
317 { 0 }
320 static void test_monthcal(void)
322 HWND hwnd;
323 SYSTEMTIME st[2], st1[2], today;
324 int res, month_range;
325 DWORD limits;
327 hwnd = CreateWindowA(MONTHCAL_CLASSA, "MonthCal", WS_POPUP | WS_VISIBLE, CW_USEDEFAULT,
328 0, 300, 300, 0, 0, NULL, NULL);
329 ok(hwnd != NULL, "Failed to create MonthCal\n");
331 /* test range just after creation */
332 memset(&st, 0xcc, sizeof(st));
333 limits = SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st);
334 ok(limits == 0 ||
335 broken(limits == GDTR_MIN), /* comctl32 <= 4.70 */
336 "No limits should be set (%d)\n", limits);
337 if (limits == GDTR_MIN)
339 win_skip("comctl32 <= 4.70 is broken\n");
340 DestroyWindow(hwnd);
341 return;
344 ok(0 == st[0].wYear ||
345 broken(1752 == st[0].wYear), /* comctl32 <= 4.72 */
346 "Expected 0, got %d\n", st[0].wYear);
347 ok(0 == st[0].wMonth ||
348 broken(9 == st[0].wMonth), /* comctl32 <= 4.72 */
349 "Expected 0, got %d\n", st[0].wMonth);
350 ok(0 == st[0].wDay ||
351 broken(14 == st[0].wDay), /* comctl32 <= 4.72 */
352 "Expected 0, got %d\n", st[0].wDay);
353 expect(0, st[0].wDayOfWeek);
354 expect(0, st[0].wHour);
355 expect(0, st[0].wMinute);
356 expect(0, st[0].wSecond);
357 expect(0, st[0].wMilliseconds);
359 expect(0, st[1].wYear);
360 expect(0, st[1].wMonth);
361 expect(0, st[1].wDay);
362 expect(0, st[1].wDayOfWeek);
363 expect(0, st[1].wHour);
364 expect(0, st[1].wMinute);
365 expect(0, st[1].wSecond);
366 expect(0, st[1].wMilliseconds);
368 GetSystemTime(&st[0]);
369 st[1] = st[0];
371 SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&today);
373 /* Invalid date/time */
374 st[0].wYear = 2000;
375 /* Time should not matter */
376 st[1].wHour = st[1].wMinute = st[1].wSecond = 70;
377 st[1].wMilliseconds = 1200;
378 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set MAX limit\n");
379 /* invalid timestamp is written back with today data and msecs untouched */
380 expect(today.wHour, st[1].wHour);
381 expect(today.wMinute, st[1].wMinute);
382 expect(today.wSecond, st[1].wSecond);
383 expect(1200, st[1].wMilliseconds);
385 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
386 ok(st1[0].wYear != 2000, "Lover limit changed\n");
387 /* invalid timestamp should be replaced with today data, except msecs */
388 expect(today.wHour, st1[1].wHour);
389 expect(today.wMinute, st1[1].wMinute);
390 expect(today.wSecond, st1[1].wSecond);
391 expect(1200, st1[1].wMilliseconds);
393 /* Invalid date/time with invalid milliseconds only */
394 GetSystemTime(&st[0]);
395 st[1] = st[0];
396 /* Time should not matter */
397 st[1].wMilliseconds = 1200;
398 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set MAX limit\n");
399 /* invalid milliseconds field doesn't lead to invalid timestamp */
400 expect(st[0].wHour, st[1].wHour);
401 expect(st[0].wMinute, st[1].wMinute);
402 expect(st[0].wSecond, st[1].wSecond);
403 expect(1200, st[1].wMilliseconds);
405 GetSystemTime(&st[0]);
407 st[1].wMonth = 0;
408 ok(!SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Should have failed to set limits\n");
409 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
410 ok(st1[0].wYear != 2000, "Lover limit changed\n");
411 ok(!SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Should have failed to set MAX limit\n");
412 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
413 ok(st1[0].wYear != 2000, "Lover limit changed\n");
415 GetSystemTime(&st[0]);
416 st[0].wDay = 20;
417 st[0].wMonth = 5;
418 st[1] = st[0];
420 month_range = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
421 st[1].wMonth--;
422 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
423 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
424 ok(res == month_range, "Invalid month range (%d)\n", res);
425 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == (GDTR_MIN|GDTR_MAX), "Limits should be set\n");
427 st[1].wMonth += 2;
428 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
429 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
430 ok(res == month_range, "Invalid month range (%d)\n", res);
432 st[1].wYear --;
433 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
434 st[1].wYear += 1;
435 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
437 st[1].wMonth -= 3;
438 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
439 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "Only MAX limit should be set\n");
440 st[1].wMonth += 4;
441 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
442 st[1].wYear -= 3;
443 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
444 st[1].wYear += 4;
445 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
446 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "Only MAX limit should be set\n");
448 /* set both limits, then set max < min */
449 GetSystemTime(&st[0]);
450 st[1] = st[0];
451 st[1].wYear++;
452 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN|GDTR_MAX, (LPARAM)st), "Failed to set limits\n");
453 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == (GDTR_MIN|GDTR_MAX), "Min limit expected\n");
454 st[1].wYear -= 2;
455 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set limits\n");
456 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "Max limit expected\n");
458 expect(0, st1[0].wYear);
459 expect(0, st1[0].wMonth);
460 expect(0, st1[0].wDay);
461 expect(0, st1[0].wDayOfWeek);
462 expect(0, st1[0].wHour);
463 expect(0, st1[0].wMinute);
464 expect(0, st1[0].wSecond);
465 expect(0, st1[0].wMilliseconds);
467 expect(st[1].wYear, st1[1].wYear);
468 expect(st[1].wMonth, st1[1].wMonth);
469 expect(st[1].wDay, st1[1].wDay);
470 expect(st[1].wDayOfWeek, st1[1].wDayOfWeek);
471 expect(st[1].wHour, st1[1].wHour);
472 expect(st[1].wMinute, st1[1].wMinute);
473 expect(st[1].wSecond, st1[1].wSecond);
474 expect(st[1].wMilliseconds, st1[1].wMilliseconds);
476 st[1] = st[0];
477 st[1].wYear++;
478 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN|GDTR_MAX, (LPARAM)st), "Failed to set limits\n");
479 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == (GDTR_MIN|GDTR_MAX), "Min limit expected\n");
480 st[0].wYear++; /* start == end now */
481 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN, (LPARAM)st), "Failed to set limits\n");
482 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MIN, "Min limit expected\n");
484 expect(st[0].wYear, st1[0].wYear);
485 expect(st[0].wMonth, st1[0].wMonth);
486 expect(st[0].wDay, st1[0].wDay);
487 expect(st[0].wDayOfWeek, st1[0].wDayOfWeek);
488 expect(st[0].wHour, st1[0].wHour);
489 expect(st[0].wMinute, st1[0].wMinute);
490 expect(st[0].wSecond, st1[0].wSecond);
491 expect(st[0].wMilliseconds, st1[0].wMilliseconds);
493 expect(0, st1[1].wYear);
494 expect(0, st1[1].wMonth);
495 expect(0, st1[1].wDay);
496 expect(0, st1[1].wDayOfWeek);
497 expect(0, st1[1].wHour);
498 expect(0, st1[1].wMinute);
499 expect(0, st1[1].wSecond);
500 expect(0, st1[1].wMilliseconds);
502 DestroyWindow(hwnd);
505 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
507 static LONG defwndproc_counter = 0;
508 LRESULT ret;
509 struct message msg;
511 /* log system messages, except for painting */
512 if (message < WM_USER &&
513 message != WM_PAINT &&
514 message != WM_ERASEBKGND &&
515 message != WM_NCPAINT &&
516 message != WM_NCHITTEST &&
517 message != WM_GETTEXT &&
518 message != WM_GETICON &&
519 message != WM_DEVICECHANGE)
521 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
523 msg.message = message;
524 msg.flags = sent|wparam|lparam;
525 if (defwndproc_counter) msg.flags |= defwinproc;
526 msg.wParam = wParam;
527 msg.lParam = lParam;
528 add_message(sequences, PARENT_SEQ_INDEX, &msg);
531 defwndproc_counter++;
532 ret = DefWindowProcA(hwnd, message, wParam, lParam);
533 defwndproc_counter--;
535 return ret;
538 static BOOL register_parent_wnd_class(void)
540 WNDCLASSA cls;
542 cls.style = 0;
543 cls.lpfnWndProc = parent_wnd_proc;
544 cls.cbClsExtra = 0;
545 cls.cbWndExtra = 0;
546 cls.hInstance = GetModuleHandleA(NULL);
547 cls.hIcon = 0;
548 cls.hCursor = LoadCursorA(0, IDC_ARROW);
549 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
550 cls.lpszMenuName = NULL;
551 cls.lpszClassName = "Month-Cal test parent class";
552 return RegisterClassA(&cls);
555 static HWND create_parent_window(void)
557 HWND hwnd;
559 InitCommonControls();
561 /* flush message sequences, so we can check the new sequence by the end of function */
562 flush_sequences(sequences, NUM_MSG_SEQUENCES);
564 if (!register_parent_wnd_class())
565 return NULL;
567 hwnd = CreateWindowEx(0, "Month-Cal test parent class",
568 "Month-Cal test parent window",
569 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
570 WS_MAXIMIZEBOX | WS_VISIBLE,
571 0, 0, 500, 500,
572 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
574 assert(hwnd);
576 /* check for message sequences */
577 ok_sequence(sequences, PARENT_SEQ_INDEX, create_parent_window_seq, "create parent window", FALSE);
579 return hwnd;
582 static LRESULT WINAPI monthcal_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
584 struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
585 static LONG defwndproc_counter = 0;
586 LRESULT ret;
587 struct message msg;
589 msg.message = message;
590 msg.flags = sent|wparam|lparam;
591 if (defwndproc_counter) msg.flags |= defwinproc;
592 msg.wParam = wParam;
593 msg.lParam = lParam;
594 add_message(sequences, MONTHCAL_SEQ_INDEX, &msg);
596 /* some debug output for style changing */
597 if ((message == WM_STYLECHANGING ||
598 message == WM_STYLECHANGED) && lParam)
600 STYLESTRUCT *style = (STYLESTRUCT*)lParam;
601 trace("\told style: 0x%08x, new style: 0x%08x\n", style->styleOld, style->styleNew);
604 defwndproc_counter++;
605 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
606 defwndproc_counter--;
608 return ret;
611 static HWND create_monthcal_control(DWORD style)
613 struct subclass_info *info;
614 HWND hwnd;
616 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
617 if (!info)
618 return NULL;
620 hwnd = CreateWindowEx(0,
621 MONTHCAL_CLASS,
623 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
624 0, 0, 300, 400,
625 parent_wnd, NULL, GetModuleHandleA(NULL), NULL);
627 if (!hwnd)
629 HeapFree(GetProcessHeap(), 0, info);
630 return NULL;
633 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
634 (LONG_PTR)monthcal_subclass_proc);
635 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
637 SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(SYSTEM_FONT), 0);
639 return hwnd;
643 /* Setter and Getters Tests */
645 static void test_monthcal_color(void)
647 int res, temp;
648 HWND hwnd;
650 hwnd = create_monthcal_control(0);
652 flush_sequences(sequences, NUM_MSG_SEQUENCES);
654 /* Setter and Getters for color*/
655 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
656 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(0,0,0));
657 expect(temp, res);
658 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
659 expect(RGB(0,0,0), temp);
660 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(255,255,255));
661 expect(temp, res);
662 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
663 expect(RGB(255,255,255), temp);
665 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
666 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(0,0,0));
667 expect(temp, res);
668 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
669 expect(RGB(0,0,0), temp);
670 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(255,255,255));
671 expect(temp, res);
672 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
673 expect(RGB(255,255,255), temp);
675 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
676 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(0,0,0));
677 expect(temp, res);
678 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
679 expect(RGB(0,0,0), temp);
680 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(255,255,255));
681 expect(temp, res);
682 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
683 expect(RGB(255,255,255), temp);
685 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
686 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(0,0,0));
687 expect(temp, res);
688 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
689 expect(RGB(0,0,0), temp);
690 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(255,255,255));
691 expect(temp, res);
692 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
693 expect(RGB(255,255,255), temp);
695 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
696 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(0,0,0));
697 expect(temp, res);
698 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
699 expect(RGB(0,0,0), temp);
700 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(255,255,255));
701 expect(temp, res);
702 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
703 expect(RGB(255,255,255), temp);
705 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
706 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(0,0,0));
707 expect(temp, res);
708 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
709 expect(RGB(0,0,0), temp);
710 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(255,255,255));
711 expect(temp, res);
712 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
713 expect(RGB(255,255,255), temp);
715 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_color_seq, "monthcal color", FALSE);
717 DestroyWindow(hwnd);
720 static void test_monthcal_currdate(void)
722 SYSTEMTIME st_original, st_new, st_test;
723 int res;
724 HWND hwnd;
726 hwnd = create_monthcal_control(0);
728 flush_sequences(sequences, NUM_MSG_SEQUENCES);
730 /* Setter and Getters for current date selected */
731 st_original.wYear = 2000;
732 st_original.wMonth = 11;
733 st_original.wDay = 28;
734 st_original.wHour = 11;
735 st_original.wMinute = 59;
736 st_original.wSecond = 30;
737 st_original.wMilliseconds = 0;
738 st_original.wDayOfWeek = 0;
740 st_new = st_test = st_original;
742 /* Should not validate the time */
743 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
744 expect(1,res);
746 /* Overflow matters, check for wDay */
747 st_test.wDay += 4;
748 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
749 expect(0,res);
751 /* correct wDay before checking for wMonth */
752 st_test.wDay -= 4;
753 expect(st_original.wDay, st_test.wDay);
755 /* Overflow matters, check for wMonth */
756 st_test.wMonth += 4;
757 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
758 expect(0,res);
760 /* checking if gets the information right, modify st_new */
761 st_new.wYear += 4;
762 st_new.wMonth += 4;
763 st_new.wDay += 4;
764 st_new.wHour += 4;
765 st_new.wMinute += 4;
766 st_new.wSecond += 4;
768 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_new);
769 expect(1, res);
771 /* st_new change to st_origin, above settings with overflow */
772 /* should not change the current settings */
773 expect(st_original.wYear, st_new.wYear);
774 expect(st_original.wMonth, st_new.wMonth);
775 expect(st_original.wDay, st_new.wDay);
776 ok(st_original.wHour == st_new.wHour ||
777 broken(0 == st_new.wHour), /* comctl32 <= 4.70 */
778 "Expected %d, got %d\n", st_original.wHour, st_new.wHour);
779 ok(st_original.wMinute == st_new.wMinute ||
780 broken(0 == st_new.wMinute), /* comctl32 <= 4.70 */
781 "Expected %d, got %d\n", st_original.wMinute, st_new.wMinute);
782 ok(st_original.wSecond == st_new.wSecond ||
783 broken(0 == st_new.wSecond), /* comctl32 <= 4.70 */
784 "Expected %d, got %d\n", st_original.wSecond, st_new.wSecond);
786 /* lparam cannot be NULL */
787 res = SendMessage(hwnd, MCM_GETCURSEL, 0, 0);
788 expect(0, res);
790 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_curr_date_seq, "monthcal currDate", TRUE);
792 /* December, 31, 9999 is the maximum allowed date */
793 memset(&st_new, 0, sizeof(st_new));
794 st_new.wYear = 9999;
795 st_new.wMonth = 12;
796 st_new.wDay = 31;
797 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
798 expect(1, res);
799 memset(&st_test, 0, sizeof(st_test));
800 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_test);
801 expect(1, res);
802 expect(st_new.wYear, st_test.wYear);
803 expect(st_new.wMonth, st_test.wMonth);
804 expect(st_new.wDay, st_test.wDay);
805 expect(st_new.wHour, st_test.wHour);
806 expect(st_new.wMinute, st_test.wMinute);
807 expect(st_new.wSecond, st_test.wSecond);
808 /* try one day later */
809 st_original = st_new;
810 st_new.wYear = 10000;
811 st_new.wMonth = 1;
812 st_new.wDay = 1;
813 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
814 expect(0, res);
815 memset(&st_test, 0, sizeof(st_test));
816 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_test);
817 expect(1, res);
818 expect(st_original.wYear, st_test.wYear);
819 expect(st_original.wMonth, st_test.wMonth);
820 expect(st_original.wDay, st_test.wDay);
821 expect(st_original.wHour, st_test.wHour);
822 expect(st_original.wMinute, st_test.wMinute);
823 expect(st_original.wSecond, st_test.wSecond);
825 DestroyWindow(hwnd);
828 static void test_monthcal_firstDay(void)
830 int res, fday, i, prev;
831 CHAR b[128];
832 LCID lcid = LOCALE_USER_DEFAULT;
833 HWND hwnd;
835 hwnd = create_monthcal_control(0);
837 flush_sequences(sequences, NUM_MSG_SEQUENCES);
839 /* Setter and Getters for first day of week */
840 /* check for locale first day */
841 if(GetLocaleInfoA(lcid, LOCALE_IFIRSTDAYOFWEEK, b, 128)){
842 fday = atoi(b);
843 trace("fday: %d\n", fday);
844 res = SendMessage(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
845 expect(fday, res);
846 prev = fday;
848 /* checking for the values that actually will be stored as */
849 /* current first day when we set a new value */
850 for (i = -5; i < 12; i++){
851 res = SendMessage(hwnd, MCM_SETFIRSTDAYOFWEEK, 0, (LPARAM) i);
852 expect(prev, res);
853 res = SendMessage(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
854 prev = res;
856 if (i == -1){
857 expect(MAKELONG(fday, FALSE), res);
858 }else if (i >= 7){
859 /* out of range sets max first day of week, locale is ignored */
860 expect(MAKELONG(6, TRUE), res);
861 }else{
862 expect(MAKELONG(i, TRUE), res);
866 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_first_day_seq, "monthcal firstDay", FALSE);
868 }else{
869 skip("Cannot retrieve first day of the week\n");
872 DestroyWindow(hwnd);
875 static void test_monthcal_unicode(void)
877 int res, temp;
878 HWND hwnd;
880 hwnd = create_monthcal_control(0);
882 flush_sequences(sequences, NUM_MSG_SEQUENCES);
884 /* Setter and Getters for Unicode format */
886 /* getting the current settings */
887 temp = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
889 /* setting to 1, should return previous settings */
890 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 1, 0);
891 expect(temp, res);
893 /* current setting is 1, so, should return 1 */
894 res = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
895 todo_wine
896 ok(1 == res ||
897 broken(0 == res), /* comctl32 <= 4.70 */
898 "Expected 1, got %d\n", res);
900 /* setting to 0, should return previous settings */
901 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 0, 0);
902 todo_wine
903 ok(1 == res ||
904 broken(0 == res), /* comctl32 <= 4.70 */
905 "Expected 1, got %d\n", res);
907 /* current setting is 0, so, it should return 0 */
908 res = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
909 expect(0, res);
911 /* should return previous settings */
912 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 1, 0);
913 expect(0, res);
915 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_unicode_seq, "monthcal unicode", FALSE);
917 DestroyWindow(hwnd);
920 static void test_monthcal_hittest(void)
922 typedef struct hittest_test
924 UINT ht;
925 int todo;
926 } hittest_test_t;
928 static const hittest_test_t title_hits[] = {
929 /* Start is the same everywhere */
930 { MCHT_TITLE, 0 },
931 { MCHT_TITLEBTNPREV, 0 },
932 /* The middle piece is only tested for presence of items */
933 /* End is the same everywhere */
934 { MCHT_TITLEBTNNEXT, 0 },
935 { MCHT_TITLE, 0 },
936 { MCHT_NOWHERE, 1 }
939 MCHITTESTINFO mchit;
940 UINT res, old_res;
941 SYSTEMTIME st;
942 LONG x;
943 UINT title_index;
944 HWND hwnd;
945 RECT r;
946 char yearmonth[80], *locale_month, *locale_year;
947 int month_count, year_count;
948 BOOL in_the_middle;
950 memset(&mchit, 0, sizeof(MCHITTESTINFO));
952 hwnd = create_monthcal_control(0);
954 /* test with invalid structure size */
955 mchit.cbSize = MCHITTESTINFO_V1_SIZE - 1;
956 mchit.pt.x = 0;
957 mchit.pt.y = 0;
958 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
959 expect(0, mchit.pt.x);
960 expect(0, mchit.pt.y);
961 expect(-1, res);
962 expect(0, mchit.uHit);
963 /* test with invalid pointer */
964 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)NULL);
965 expect(-1, res);
967 /* resize control to display single Calendar */
968 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
969 if (res == 0)
971 win_skip("Message MCM_GETMINREQRECT unsupported. Skipping.\n");
972 DestroyWindow(hwnd);
973 return;
975 MoveWindow(hwnd, 0, 0, r.right, r.bottom, FALSE);
977 flush_sequences(sequences, NUM_MSG_SEQUENCES);
979 st.wYear = 2007;
980 st.wMonth = 4;
981 st.wDay = 11;
982 st.wHour = 1;
983 st.wMinute = 0;
984 st.wSecond = 0;
985 st.wMilliseconds = 0;
986 st.wDayOfWeek = 0;
988 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st);
989 expect(1,res);
991 /* (0, 0) is the top left of the control - title */
992 mchit.cbSize = MCHITTESTINFO_V1_SIZE;
993 mchit.pt.x = 0;
994 mchit.pt.y = 0;
995 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
996 expect(0, mchit.pt.x);
997 expect(0, mchit.pt.y);
998 expect(mchit.uHit, res);
999 expect_hex(MCHT_TITLE, res);
1001 /* bottom right of the control and should not be active */
1002 mchit.pt.x = r.right;
1003 mchit.pt.y = r.bottom;
1004 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1005 expect(r.right, mchit.pt.x);
1006 expect(r.bottom, mchit.pt.y);
1007 expect(mchit.uHit, res);
1008 todo_wine expect_hex(MCHT_NOWHERE, res);
1010 /* completely out of the control, should not be active */
1011 mchit.pt.x = 2 * r.right;
1012 mchit.pt.y = 2 * r.bottom;
1013 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1014 expect(2 * r.right, mchit.pt.x);
1015 expect(2 * r.bottom, mchit.pt.y);
1016 expect(mchit.uHit, res);
1017 todo_wine expect_hex(MCHT_NOWHERE, res);
1019 /* in active area - day of the week */
1020 mchit.pt.x = r.right / 2;
1021 mchit.pt.y = r.bottom / 2;
1022 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1023 expect(r.right / 2, mchit.pt.x);
1024 expect(r.bottom / 2, mchit.pt.y);
1025 expect(mchit.uHit, res);
1026 expect_hex(MCHT_CALENDARDATE, res);
1028 /* in active area - day of the week #2 */
1029 mchit.pt.x = r.right / 14; /* half of first day rect */
1030 mchit.pt.y = r.bottom / 2;
1031 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1032 expect(r.right / 14, mchit.pt.x);
1033 expect(r.bottom / 2, mchit.pt.y);
1034 expect(mchit.uHit, res);
1035 expect_hex(MCHT_CALENDARDATE, res);
1037 /* in active area - date from prev month */
1038 mchit.pt.x = r.right / 14; /* half of first day rect */
1039 mchit.pt.y = 6 * r.bottom / 19;
1040 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1041 expect(r.right / 14, mchit.pt.x);
1042 expect(6 * r.bottom / 19, mchit.pt.y);
1043 expect(mchit.uHit, res);
1044 expect_hex(MCHT_CALENDARDATEPREV, res);
1046 #if 0
1047 /* (125, 115) is in active area - date from this month */
1048 mchit.pt.x = 125;
1049 mchit.pt.y = 115;
1050 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1051 expect(125, mchit.pt.x);
1052 expect(115, mchit.pt.y);
1053 expect(mchit.uHit, res);
1054 expect(MCHT_CALENDARDATE, res);
1055 #endif
1057 /* in active area - date from next month */
1058 mchit.pt.x = 11 * r.right / 14;
1059 mchit.pt.y = 16 * r.bottom / 19;
1060 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1061 expect(11 * r.right / 14, mchit.pt.x);
1062 expect(16 * r.bottom / 19, mchit.pt.y);
1063 expect(mchit.uHit, res);
1064 expect_hex(MCHT_CALENDARDATENEXT, res);
1066 /* in active area - today link */
1067 mchit.pt.x = r.right / 14;
1068 mchit.pt.y = 18 * r.bottom / 19;
1069 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1070 expect(r.right / 14, mchit.pt.x);
1071 expect(18 * r.bottom / 19, mchit.pt.y);
1072 expect(mchit.uHit, res);
1073 expect_hex(MCHT_TODAYLINK, res);
1075 /* in active area - today link */
1076 mchit.pt.x = r.right / 2;
1077 mchit.pt.y = 18 * r.bottom / 19;
1078 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1079 expect(r.right / 2, mchit.pt.x);
1080 expect(18 * r.bottom / 19, mchit.pt.y);
1081 expect(mchit.uHit, res);
1082 expect_hex(MCHT_TODAYLINK, res);
1084 /* in active area - today link */
1085 mchit.pt.x = r.right / 10;
1086 mchit.pt.y = 18 * r.bottom / 19;
1087 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1088 expect(r.right / 10, mchit.pt.x);
1089 expect(18 * r.bottom / 19, mchit.pt.y);
1090 expect(mchit.uHit, res);
1091 expect_hex(MCHT_TODAYLINK, res);
1093 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_hit_test_seq, "monthcal hit test", TRUE);
1095 /* The horizontal position of title bar elements depends on locale (y pos
1096 is constant), so we sample across a horizontal line and make sure we
1097 find all elements. */
1099 /* Get the format of the title */
1100 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SYEARMONTH, yearmonth, 80);
1101 /* Find out if we have a month and/or year */
1102 locale_year = strstr(yearmonth, "y");
1103 locale_month = strstr(yearmonth, "M");
1105 mchit.pt.x = 0;
1106 mchit.pt.y = (5/2) * r.bottom / 19;
1107 title_index = 0;
1108 old_res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1109 expect_hex(title_hits[title_index].ht, old_res);
1111 in_the_middle = FALSE;
1112 month_count = year_count = 0;
1113 for (x = 0; x < r.right; x++){
1114 mchit.pt.x = x;
1115 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1116 expect(x, mchit.pt.x);
1117 expect((5/2) * r.bottom / 19, mchit.pt.y);
1118 expect(mchit.uHit, res);
1119 if (res != old_res) {
1121 if (old_res == MCHT_TITLEBTNPREV)
1122 in_the_middle = TRUE;
1124 if (res == MCHT_TITLEBTNNEXT)
1125 in_the_middle = FALSE;
1127 if (in_the_middle) {
1128 if (res == MCHT_TITLEMONTH)
1129 month_count++;
1130 else if (res == MCHT_TITLEYEAR)
1131 year_count++;
1132 } else {
1133 title_index++;
1135 if (sizeof(title_hits) / sizeof(title_hits[0]) <= title_index)
1136 break;
1138 if (title_hits[title_index].todo) {
1139 todo_wine
1140 ok(title_hits[title_index].ht == res, "Expected %x, got %x, pos %d\n",
1141 title_hits[title_index].ht, res, x);
1142 } else {
1143 ok(title_hits[title_index].ht == res, "Expected %x, got %x, pos %d\n",
1144 title_hits[title_index].ht, res, x);
1147 old_res = res;
1151 /* There are some limits, even if LOCALE_SYEARMONTH contains rubbish
1152 * or no month/year indicators at all */
1153 if (locale_month)
1154 todo_wine ok(month_count == 1, "Expected 1 month item, got %d\n", month_count);
1155 else
1156 ok(month_count <= 1, "Too many month items: %d\n", month_count);
1158 if (locale_year)
1159 todo_wine ok(year_count == 1, "Expected 1 year item, got %d\n", year_count);
1160 else
1161 ok(year_count <= 1, "Too many year items: %d\n", year_count);
1163 todo_wine ok(month_count + year_count >= 1, "Not enough month and year items\n");
1165 ok(r.right <= x && title_index + 1 == sizeof(title_hits) / sizeof(title_hits[0]),
1166 "Wrong title layout\n");
1168 DestroyWindow(hwnd);
1171 static void test_monthcal_todaylink(void)
1173 MCHITTESTINFO mchit;
1174 SYSTEMTIME st_test, st_new;
1175 BOOL error = FALSE;
1176 UINT res;
1177 HWND hwnd;
1179 memset(&mchit, 0, sizeof(MCHITTESTINFO));
1181 hwnd = create_monthcal_control(0);
1183 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1185 /* (70, 370) is in active area - today link */
1186 mchit.cbSize = MCHITTESTINFO_V1_SIZE;
1187 mchit.pt.x = 70;
1188 mchit.pt.y = 370;
1189 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1190 expect(70, mchit.pt.x);
1191 expect(370, mchit.pt.y);
1192 expect(mchit.uHit, res);
1193 todo_wine {expect(MCHT_TODAYLINK, res);}
1194 if (70 != mchit.pt.x || 370 != mchit.pt.y || mchit.uHit != res
1195 || MCHT_TODAYLINK != res)
1196 error = TRUE;
1198 st_test.wDay = 1;
1199 st_test.wMonth = 1;
1200 st_test.wYear = 2005;
1201 memset(&st_new, 0, sizeof(SYSTEMTIME));
1203 SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
1205 res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
1206 expect(1, res);
1207 expect(1, st_new.wDay);
1208 expect(1, st_new.wMonth);
1209 expect(2005, st_new.wYear);
1210 if (1 != res || 1 != st_new.wDay || 1 != st_new.wMonth
1211 || 2005 != st_new.wYear)
1212 error = TRUE;
1214 if (error) {
1215 skip("cannot perform today link test\n");
1216 return;
1219 res = SendMessage(hwnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELONG(70, 370));
1220 expect(0, res);
1222 memset(&st_new, 0, sizeof(SYSTEMTIME));
1223 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_new);
1224 expect(1, res);
1225 expect(1, st_new.wDay);
1226 expect(1, st_new.wMonth);
1227 expect(2005, st_new.wYear);
1229 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_todaylink_seq, "monthcal hit test", TRUE);
1231 DestroyWindow(hwnd);
1234 static void test_monthcal_today(void)
1236 SYSTEMTIME st_test, st_new;
1237 int res;
1238 HWND hwnd;
1240 hwnd = create_monthcal_control(0);
1242 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1244 /* Setter and Getters for "today" information */
1246 /* check for overflow, should be ok */
1247 st_test.wDay = 38;
1248 st_test.wMonth = 38;
1250 st_new.wDay = 27;
1251 st_new.wMonth = 27;
1253 SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
1255 res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
1256 expect(1, res);
1258 /* st_test should not change */
1259 expect(38, st_test.wDay);
1260 expect(38, st_test.wMonth);
1262 /* st_new should change, overflow does not matter */
1263 expect(38, st_new.wDay);
1264 expect(38, st_new.wMonth);
1266 /* check for zero, should be ok*/
1267 st_test.wDay = 0;
1268 st_test.wMonth = 0;
1270 SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
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_monthcal_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_monthcal_monthrange(void)
1328 int res;
1329 SYSTEMTIME st_visible[2], st_daystate[2], st;
1330 HWND hwnd;
1332 hwnd = create_monthcal_control(0);
1334 st_visible[0].wYear = 0;
1335 st_visible[0].wMonth = 0;
1336 st_visible[0].wDay = 0;
1337 st_daystate[1] = st_daystate[0] = st_visible[1] = st_visible[0];
1339 st.wYear = 2000;
1340 st.wMonth = 11;
1341 st.wDay = 28;
1342 st.wHour = 11;
1343 st.wMinute = 59;
1344 st.wSecond = 30;
1345 st.wMilliseconds = 0;
1346 st.wDayOfWeek = 0;
1348 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st);
1349 expect(1,res);
1351 /* to be locale independent */
1352 SendMessage(hwnd, MCM_SETFIRSTDAYOFWEEK, 0, (LPARAM)6);
1354 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1356 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st_visible);
1357 todo_wine {
1358 expect(2, res);
1360 expect(2000, st_visible[0].wYear);
1361 expect(11, st_visible[0].wMonth);
1362 expect(1, st_visible[0].wDay);
1363 expect(2000, st_visible[1].wYear);
1365 todo_wine {
1366 expect(12, st_visible[1].wMonth);
1367 expect(31, st_visible[1].wDay);
1369 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, (LPARAM)st_daystate);
1370 todo_wine {
1371 expect(4, res);
1372 expect(2000, st_daystate[0].wYear);
1373 expect(10, st_daystate[0].wMonth);
1374 expect(29, st_daystate[0].wDay);
1375 expect(2001, st_daystate[1].wYear);
1376 expect(1, st_daystate[1].wMonth);
1377 expect(6, st_daystate[1].wDay);
1380 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_monthrange_seq, "monthcal monthrange", FALSE);
1382 DestroyWindow(hwnd);
1385 static void test_monthcal_maxselday(void)
1387 int res;
1388 HWND hwnd;
1389 DWORD style;
1391 hwnd = create_monthcal_control(0);
1392 /* if no style specified default to 1 */
1393 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1394 expect(1, res);
1395 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 5, 0);
1396 expect(0, res);
1397 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1398 expect(1, res);
1400 /* try to set style */
1401 style = GetWindowLong(hwnd, GWL_STYLE);
1402 SetWindowLong(hwnd, GWL_STYLE, style | MCS_MULTISELECT);
1403 style = GetWindowLong(hwnd, GWL_STYLE);
1404 ok(!(style & MCS_MULTISELECT), "Expected MCS_MULTISELECT not to be set\n");
1405 DestroyWindow(hwnd);
1407 hwnd = create_monthcal_control(MCS_MULTISELECT);
1408 /* try to remove style */
1409 style = GetWindowLong(hwnd, GWL_STYLE);
1410 SetWindowLong(hwnd, GWL_STYLE, style & ~MCS_MULTISELECT);
1411 style = GetWindowLong(hwnd, GWL_STYLE);
1412 ok(style & MCS_MULTISELECT, "Expected MCS_MULTISELECT to be set\n");
1413 DestroyWindow(hwnd);
1415 hwnd = create_monthcal_control(MCS_MULTISELECT);
1417 /* default width is a week */
1418 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1419 expect(7, res);
1421 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1423 /* Setter and Getters for max selected days */
1424 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 5, 0);
1425 expect(1, res);
1426 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1427 expect(5, res);
1429 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 15, 0);
1430 expect(1, res);
1431 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1432 expect(15, res);
1434 /* test invalid value */
1435 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, -1, 0);
1436 expect(0, res);
1437 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1438 expect(15, res);
1440 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_max_sel_day_seq, "monthcal MaxSelDay", FALSE);
1442 /* zero value is invalid too */
1443 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 0, 0);
1444 expect(0, res);
1445 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1446 expect(15, res);
1448 DestroyWindow(hwnd);
1451 static void test_monthcal_size(void)
1453 int res;
1454 RECT r1, r2;
1455 HFONT hFont1, hFont2;
1456 LOGFONTA logfont;
1457 HWND hwnd;
1459 hwnd = create_monthcal_control(0);
1461 lstrcpyA(logfont.lfFaceName, "Arial");
1462 memset(&logfont, 0, sizeof(logfont));
1463 logfont.lfHeight = 12;
1464 hFont1 = CreateFontIndirectA(&logfont);
1466 logfont.lfHeight = 24;
1467 hFont2 = CreateFontIndirectA(&logfont);
1469 /* initialize to a font we can compare against */
1470 SendMessage(hwnd, WM_SETFONT, (WPARAM)hFont1, 0);
1471 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r1);
1473 /* check that setting a larger font results in an larger rect */
1474 SendMessage(hwnd, WM_SETFONT, (WPARAM)hFont2, 0);
1475 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r2);
1477 OffsetRect(&r1, -r1.left, -r1.top);
1478 OffsetRect(&r2, -r2.left, -r2.top);
1480 ok(r1.bottom < r2.bottom, "Failed to get larger rect with larger font\n");
1482 DestroyWindow(hwnd);
1485 static void test_monthcal_create(void)
1487 HWND hwnd;
1489 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1491 hwnd = create_monthcal_control(0);
1492 ok_sequence(sequences, PARENT_SEQ_INDEX, create_monthcal_control_seq, "create monthcal control", TRUE);
1494 DestroyWindow(hwnd);
1496 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1497 hwnd = create_monthcal_control(MCS_MULTISELECT);
1498 ok_sequence(sequences, PARENT_SEQ_INDEX, create_monthcal_multi_sel_style_seq, "create monthcal (multi sel style)", TRUE);
1499 DestroyWindow(hwnd);
1502 static void test_monthcal_destroy(void)
1504 HWND hwnd;
1506 hwnd = create_monthcal_control(0);
1507 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1508 DestroyWindow(hwnd);
1509 ok_sequence(sequences, PARENT_SEQ_INDEX, destroy_monthcal_parent_msgs_seq, "Destroy monthcal (parent msg)", FALSE);
1510 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, destroy_monthcal_child_msgs_seq, "Destroy monthcal (child msg)", FALSE);
1512 /* MCS_MULTISELECT */
1513 hwnd = create_monthcal_control(MCS_MULTISELECT);
1514 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1515 DestroyWindow(hwnd);
1516 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, destroy_monthcal_multi_sel_style_seq, "Destroy monthcal (multi sel style)", FALSE);
1519 static void test_monthcal_selrange(void)
1521 HWND hwnd;
1522 SYSTEMTIME st, range[2], range2[2];
1523 BOOL ret, old_comctl32 = FALSE;
1525 hwnd = create_monthcal_control(MCS_MULTISELECT);
1527 /* just after creation selection should start and end today */
1528 ret = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st);
1529 expect(TRUE, ret);
1531 memset(range, 0xcc, sizeof(range));
1532 ret = SendMessage(hwnd, MCM_GETSELRANGE, 0, (LPARAM)range);
1533 expect(TRUE, ret);
1534 expect(st.wYear, range[0].wYear);
1535 expect(st.wMonth, range[0].wMonth);
1536 expect(st.wDay, range[0].wDay);
1537 if (range[0].wDayOfWeek == 0)
1539 win_skip("comctl32 <= 4.70 doesn't set some values\n");
1540 old_comctl32 = TRUE;
1542 else
1544 expect(st.wDayOfWeek, range[0].wDayOfWeek);
1545 expect(st.wHour, range[0].wHour);
1546 expect(st.wMinute, range[0].wMinute);
1547 expect(st.wSecond, range[0].wSecond);
1548 expect(st.wMilliseconds, range[0].wMilliseconds);
1551 expect(st.wYear, range[1].wYear);
1552 expect(st.wMonth, range[1].wMonth);
1553 expect(st.wDay, range[1].wDay);
1554 if (!old_comctl32)
1556 expect(st.wDayOfWeek, range[1].wDayOfWeek);
1557 expect(st.wHour, range[1].wHour);
1558 expect(st.wMinute, range[1].wMinute);
1559 expect(st.wSecond, range[1].wSecond);
1560 expect(st.wMilliseconds, range[1].wMilliseconds);
1563 /* bounds are swapped if min > max */
1564 memset(&range[0], 0, sizeof(range[0]));
1565 range[0].wYear = 2009;
1566 range[0].wMonth = 10;
1567 range[0].wDay = 5;
1568 range[1] = range[0];
1569 range[1].wDay = 3;
1571 ret = SendMessage(hwnd, MCM_SETSELRANGE, 0, (LPARAM)range);
1572 expect(TRUE, ret);
1574 ret = SendMessage(hwnd, MCM_GETSELRANGE, 0, (LPARAM)range2);
1575 expect(TRUE, ret);
1577 expect(range[1].wYear, range2[0].wYear);
1578 expect(range[1].wMonth, range2[0].wMonth);
1579 expect(range[1].wDay, range2[0].wDay);
1580 expect(6, range2[0].wDayOfWeek);
1581 expect(range[1].wHour, range2[0].wHour);
1582 expect(range[1].wMinute, range2[0].wMinute);
1583 expect(range[1].wSecond, range2[0].wSecond);
1584 expect(range[1].wMilliseconds, range2[0].wMilliseconds);
1586 expect(range[0].wYear, range2[1].wYear);
1587 expect(range[0].wMonth, range2[1].wMonth);
1588 expect(range[0].wDay, range2[1].wDay);
1589 expect(1, range2[1].wDayOfWeek);
1590 expect(range[0].wHour, range2[1].wHour);
1591 expect(range[0].wMinute, range2[1].wMinute);
1592 expect(range[0].wSecond, range2[1].wSecond);
1593 expect(range[0].wMilliseconds, range2[1].wMilliseconds);
1595 /* try with range larger than maximum configured */
1596 memset(&range[0], 0, sizeof(range[0]));
1597 range[0].wYear = 2009;
1598 range[0].wMonth = 10;
1599 range[0].wDay = 1;
1600 range[1] = range[0];
1602 ret = SendMessage(hwnd, MCM_SETSELRANGE, 0, (LPARAM)range);
1603 expect(TRUE, ret);
1605 range[1] = range[0];
1606 /* default max. range is 7 days */
1607 range[1].wDay = 8;
1609 ret = SendMessage(hwnd, MCM_SETSELRANGE, 0, (LPARAM)range);
1610 expect(FALSE, ret);
1612 ret = SendMessage(hwnd, MCM_GETSELRANGE, 0, (LPARAM)range2);
1613 expect(TRUE, ret);
1615 expect(range[0].wYear, range2[0].wYear);
1616 expect(range[0].wMonth, range2[0].wMonth);
1617 expect(range[0].wDay, range2[0].wDay);
1618 expect(range[0].wYear, range2[1].wYear);
1619 expect(range[0].wMonth, range2[1].wMonth);
1620 expect(range[0].wDay, range2[1].wDay);
1622 DestroyWindow(hwnd);
1625 START_TEST(monthcal)
1627 HMODULE hComctl32;
1628 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
1629 INITCOMMONCONTROLSEX iccex;
1631 hComctl32 = GetModuleHandleA("comctl32.dll");
1632 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
1633 if (!pInitCommonControlsEx)
1635 skip("InitCommonControlsEx() is missing. Skipping the tests\n");
1636 return;
1638 iccex.dwSize = sizeof(iccex);
1639 iccex.dwICC = ICC_DATE_CLASSES;
1640 pInitCommonControlsEx(&iccex);
1642 test_monthcal();
1644 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
1646 parent_wnd = create_parent_window();
1648 test_monthcal_create();
1649 test_monthcal_destroy();
1650 test_monthcal_color();
1651 test_monthcal_currdate();
1652 test_monthcal_firstDay();
1653 test_monthcal_unicode();
1654 test_monthcal_today();
1655 test_monthcal_scroll();
1656 test_monthcal_monthrange();
1657 test_monthcal_hittest();
1658 test_monthcal_todaylink();
1659 test_monthcal_size();
1660 test_monthcal_maxselday();
1661 test_monthcal_selrange();
1663 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1664 DestroyWindow(parent_wnd);
1665 ok_sequence(sequences, PARENT_SEQ_INDEX, destroy_parent_seq, "Destroy parent window", FALSE);