2 * comctl32 month calendar unit tests
4 * Copyright (C) 2006 Vitaliy Margolen
5 * Copyright (C) 2007 Farshad Agah
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wine/test.h"
35 #define expect(expected, got) ok(expected == got, "Expected %d, got %d\n", expected, got);
37 #define NUM_MSG_SEQUENCES 2
38 #define PARENT_SEQ_INDEX 0
39 #define MONTHCAL_SEQ_INDEX 1
46 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
48 static const struct message create_parent_window_seq[] = {
49 { WM_GETMINMAXINFO, sent },
50 { WM_NCCREATE, sent },
51 { WM_NCCALCSIZE, sent|wparam, 0 },
53 { WM_SHOWWINDOW, sent|wparam, 1 },
54 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
55 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
56 { WM_ACTIVATEAPP, sent|wparam, 1 },
57 { WM_NCACTIVATE, sent|wparam, 1 },
58 { WM_ACTIVATE, sent|wparam, 1 },
59 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
60 { WM_IME_NOTIFY, sent|defwinproc|optional },
61 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
62 /* Win9x adds SWP_NOZORDER below */
63 { WM_WINDOWPOSCHANGED, sent, /*|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ },
64 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
70 static const struct message create_monthcal_control_seq[] = {
71 { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
72 { WM_QUERYUISTATE, sent },
74 { WM_PARENTNOTIFY, sent|wparam, WM_CREATE},
78 static const struct message create_monthcal_multi_sel_style_seq[] = {
79 { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
80 { WM_QUERYUISTATE, sent },
85 static const struct message monthcal_color_seq[] = {
86 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, 0},
87 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, RGB(0,0,0)},
88 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, 0},
89 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, RGB(255,255,255)},
90 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, 0},
92 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, 0},
93 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, RGB(0,0,0)},
94 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, 0},
95 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, RGB(255,255,255)},
96 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, 0},
98 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TEXT, 0},
99 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TEXT, RGB(0,0,0)},
100 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TEXT, 0},
101 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TEXT, RGB(255,255,255)},
102 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TEXT, 0},
104 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, 0},
105 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, RGB(0,0,0)},
106 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, 0},
107 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, RGB(255,255,255)},
108 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, 0},
110 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, 0},
111 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, RGB(0,0,0)},
112 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, 0},
113 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, RGB(255,255,255)},
114 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, 0},
116 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, 0},
117 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, RGB(0,0,0)},
118 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, 0},
119 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, RGB(255,255,255)},
120 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, 0},
124 static const struct message monthcal_curr_date_seq[] = {
125 { MCM_SETCURSEL, sent|wparam, 0},
126 { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
127 { WM_NCPAINT, sent|wparam|lparam|defwinproc, 1, 0},
128 { WM_ERASEBKGND, sent|lparam|defwinproc, 0},
129 { MCM_SETCURSEL, sent|wparam, 0},
130 { MCM_SETCURSEL, sent|wparam, 0},
131 { MCM_GETCURSEL, sent|wparam, 0},
132 { MCM_GETCURSEL, sent|wparam|lparam, 0, 0},
136 static const struct message monthcal_first_day_seq[] = {
137 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
139 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -5},
140 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
142 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -4},
143 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
145 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -3},
146 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
148 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -2},
149 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
151 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -1},
152 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
154 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
155 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
157 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 1},
158 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
160 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 2},
161 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
163 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 3},
164 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
166 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 4},
167 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
169 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 5},
170 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
172 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 6},
173 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
175 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 7},
176 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
178 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 8},
179 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
181 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 9},
182 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
184 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 10},
185 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
187 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 11},
188 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
192 static const struct message monthcal_unicode_seq[] = {
193 { MCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
194 { MCM_SETUNICODEFORMAT, sent|wparam|lparam, 1, 0},
195 { MCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
196 { MCM_SETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
197 { MCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
198 { MCM_SETUNICODEFORMAT, sent|wparam|lparam, 1, 0},
202 static const struct message monthcal_hit_test_seq[] = {
203 { MCM_SETCURSEL, sent|wparam, 0},
204 { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
205 { WM_NCPAINT, sent|wparam|lparam|defwinproc, 1, 0},
206 { WM_ERASEBKGND, sent|lparam|defwinproc, 0},
207 { WM_SETFONT, sent|lparam, 0, 0},
208 { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
209 { WM_ERASEBKGND, sent|lparam|defwinproc, 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 { MCM_HITTEST, sent|wparam, 0},
220 { MCM_HITTEST, sent|wparam, 0},
221 { MCM_HITTEST, sent|wparam, 0},
222 { MCM_HITTEST, sent|wparam, 0},
223 { MCM_HITTEST, sent|wparam, 0},
224 { MCM_HITTEST, sent|wparam, 0},
225 { MCM_HITTEST, sent|wparam, 0},
226 { MCM_HITTEST, sent|wparam, 0},
230 static const struct message monthcal_today_seq[] = {
231 { MCM_SETTODAY, sent|wparam, 0},
232 { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
233 { WM_NCPAINT, sent|wparam|lparam|defwinproc, 1, 0},
234 { WM_ERASEBKGND, sent|lparam|defwinproc, 0},
235 { MCM_GETTODAY, sent|wparam, 0},
236 { MCM_SETTODAY, sent|wparam, 0},
237 { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
238 { MCM_GETTODAY, sent|wparam, 0},
242 static const struct message monthcal_scroll_seq[] = {
243 { MCM_SETMONTHDELTA, sent|wparam|lparam, 2, 0},
244 { MCM_SETMONTHDELTA, sent|wparam|lparam, 3, 0},
245 { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
246 { MCM_SETMONTHDELTA, sent|wparam|lparam, 12, 0},
247 { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
248 { MCM_SETMONTHDELTA, sent|wparam|lparam, 15, 0},
249 { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
250 { MCM_SETMONTHDELTA, sent|wparam|lparam, -5, 0},
251 { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
255 static const struct message monthcal_monthrange_seq[] = {
256 { MCM_GETMONTHRANGE, sent|wparam, GMR_VISIBLE},
257 { MCM_GETMONTHRANGE, sent|wparam, GMR_DAYSTATE},
261 static const struct message monthcal_max_sel_day_seq[] = {
262 { MCM_SETMAXSELCOUNT, sent|wparam|lparam, 5, 0},
263 { MCM_GETMAXSELCOUNT, sent|wparam|lparam, 0, 0},
264 { MCM_SETMAXSELCOUNT, sent|wparam|lparam, 15, 0},
265 { MCM_GETMAXSELCOUNT, sent|wparam|lparam, 0, 0},
266 { MCM_SETMAXSELCOUNT, sent|wparam|lparam, -1, 0},
267 { MCM_GETMAXSELCOUNT, sent|wparam|lparam, 0, 0},
271 /* expected message sequence for parent*/
272 static const struct message destroy_monthcal_parent_msgs_seq[] = {
273 { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY},
277 /* expected message sequence for child*/
278 static const struct message destroy_monthcal_child_msgs_seq[] = {
279 { WM_SHOWWINDOW, sent|wparam|lparam, 0, 0},
280 { WM_WINDOWPOSCHANGING, sent|wparam, 0},
281 { WM_WINDOWPOSCHANGED, sent|wparam, 0},
282 { WM_DESTROY, sent|wparam|lparam, 0, 0},
283 { WM_NCDESTROY, sent|wparam|lparam, 0, 0},
287 static const struct message destroy_monthcal_multi_sel_style_seq[] = {
288 { WM_DESTROY, sent|wparam|lparam, 0, 0},
289 { WM_NCDESTROY, sent|wparam|lparam, 0, 0},
293 /* expected message sequence for parent window*/
294 static const struct message destroy_parent_seq[] = {
295 { WM_WINDOWPOSCHANGING, sent|wparam, 0},
296 { WM_WINDOWPOSCHANGED, sent|wparam, 0},
297 { WM_NCACTIVATE, sent|wparam|lparam, 0, 0},
298 { WM_ACTIVATE, sent|wparam|lparam, 0, 0},
299 { WM_ACTIVATEAPP, sent|wparam, 0},
300 { WM_KILLFOCUS, sent|wparam|lparam, 0, 0},
301 { WM_IME_SETCONTEXT, sent|wparam|optional, 0},
302 { WM_IME_NOTIFY, sent|wparam|lparam|defwinproc|optional, 1, 0},
303 { WM_DESTROY, sent|wparam|lparam, 0, 0},
304 { WM_NCDESTROY, sent|wparam|lparam, 0, 0},
308 static void test_monthcal(void)
311 SYSTEMTIME st[2], st1[2];
312 INITCOMMONCONTROLSEX ic = {sizeof(INITCOMMONCONTROLSEX), ICC_DATE_CLASSES};
313 int res, month_range;
315 InitCommonControlsEx(&ic);
316 hwnd = CreateWindowA(MONTHCAL_CLASSA, "MonthCal", WS_POPUP | WS_VISIBLE, CW_USEDEFAULT,
317 0, 300, 300, 0, 0, NULL, NULL);
318 ok(hwnd != NULL, "Failed to create MonthCal\n");
319 GetSystemTime(&st[0]);
322 /* Invalid date/time */
324 /* Time should not matter */
325 st[1].wHour = st[1].wMinute = st[1].wSecond = 70;
326 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set MAX limit\n");
327 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
328 ok(st1[0].wYear != 2000, "Lover limit changed\n");
331 ok(!SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Should have failed to set limits\n");
332 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
333 ok(st1[0].wYear != 2000, "Lover limit changed\n");
334 ok(!SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Should have failed to set MAX limit\n");
335 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
336 ok(st1[0].wYear != 2000, "Lover limit changed\n");
338 GetSystemTime(&st[0]);
343 month_range = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
345 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
346 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
347 ok(res == month_range, "Invalid month range (%d)\n", res);
348 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == (GDTR_MIN|GDTR_MAX), "Limits should be set\n");
351 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
352 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
353 ok(res == month_range, "Invalid month range (%d)\n", res);
356 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
358 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
361 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
362 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "Only MAX limit should be set\n");
364 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
366 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
368 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
369 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "Only MAX limit should be set\n");
374 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
376 static long defwndproc_counter = 0;
380 /* do not log painting messages */
381 if (message != WM_PAINT &&
382 message != WM_ERASEBKGND &&
383 message != WM_NCPAINT &&
384 message != WM_NCHITTEST &&
385 message != WM_GETTEXT &&
386 message != WM_GETICON &&
387 message != WM_DEVICECHANGE)
389 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
391 msg.message = message;
392 msg.flags = sent|wparam|lparam;
393 if (defwndproc_counter) msg.flags |= defwinproc;
396 add_message(sequences, PARENT_SEQ_INDEX, &msg);
399 defwndproc_counter++;
400 ret = DefWindowProcA(hwnd, message, wParam, lParam);
401 defwndproc_counter--;
406 static BOOL register_parent_wnd_class(void)
411 cls.lpfnWndProc = parent_wnd_proc;
414 cls.hInstance = GetModuleHandleA(NULL);
416 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
417 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
418 cls.lpszMenuName = NULL;
419 cls.lpszClassName = "Month-Cal test parent class";
420 return RegisterClassA(&cls);
423 static HWND create_parent_window(void)
427 InitCommonControls();
429 /* flush message sequences, so we can check the new sequence by the end of function */
430 flush_sequences(sequences, NUM_MSG_SEQUENCES);
432 if (!register_parent_wnd_class())
435 hwnd = CreateWindowEx(0, "Month-Cal test parent class",
436 "Month-Cal test parent window",
437 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
438 WS_MAXIMIZEBOX | WS_VISIBLE,
440 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
444 /* check for message sequences */
445 ok_sequence(sequences, PARENT_SEQ_INDEX, create_parent_window_seq, "create parent window", TRUE);
450 static LRESULT WINAPI monthcal_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
452 struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
453 static long defwndproc_counter = 0;
457 trace("monthcal: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
459 msg.message = message;
460 msg.flags = sent|wparam|lparam;
461 if (defwndproc_counter) msg.flags |= defwinproc;
464 add_message(sequences, MONTHCAL_SEQ_INDEX, &msg);
466 defwndproc_counter++;
467 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
468 defwndproc_counter--;
473 static HWND create_monthcal_control(DWORD style, HWND parent_window)
475 struct subclass_info *info;
477 static const INITCOMMONCONTROLSEX ic = {sizeof(INITCOMMONCONTROLSEX), ICC_DATE_CLASSES};
479 InitCommonControlsEx(&ic);
481 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
485 hwnd = CreateWindowEx(0,
490 parent_window, NULL, GetModuleHandleA(NULL), NULL);
494 HeapFree(GetProcessHeap(), 0, info);
498 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
499 (LONG_PTR)monthcal_subclass_proc);
500 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
506 /* Setter and Getters Tests */
508 static void test_monthcal_color(HWND hwnd)
512 flush_sequences(sequences, NUM_MSG_SEQUENCES);
514 /* Setter and Getters for color*/
515 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
516 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(0,0,0));
518 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
519 expect(RGB(0,0,0), temp);
520 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(255,255,255));
522 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
523 expect(RGB(255,255,255), temp);
525 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
526 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(0,0,0));
528 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
529 expect(RGB(0,0,0), temp);
530 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(255,255,255));
532 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
533 expect(RGB(255,255,255), temp);
535 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
536 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(0,0,0));
538 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
539 expect(RGB(0,0,0), temp);
540 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(255,255,255));
542 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
543 expect(RGB(255,255,255), temp);
545 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
546 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(0,0,0));
548 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
549 expect(RGB(0,0,0), temp);
550 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(255,255,255));
552 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
553 expect(RGB(255,255,255), temp);
555 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
556 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(0,0,0));
558 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
559 expect(RGB(0,0,0), temp);
560 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(255,255,255));
562 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
563 expect(RGB(255,255,255), temp);
565 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
566 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(0,0,0));
568 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
569 expect(RGB(0,0,0), temp);
570 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(255,255,255));
572 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
573 expect(RGB(255,255,255), temp);
575 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_color_seq, "monthcal color", FALSE);
578 static void test_monthcal_currDate(HWND hwnd)
580 SYSTEMTIME st_original, st_new, st_test;
583 flush_sequences(sequences, NUM_MSG_SEQUENCES);
585 /* Setter and Getters for current date selected */
586 st_original.wYear = 2000;
587 st_original.wMonth = 11;
588 st_original.wDay = 28;
589 st_original.wHour = 11;
590 st_original.wMinute = 59;
591 st_original.wSecond = 30;
592 st_original.wMilliseconds = 0;
593 st_original.wDayOfWeek = 0;
595 st_new = st_test = st_original;
597 /* Should not validate the time */
598 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
601 /* Overflow matters, check for wDay */
603 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
606 /* correct wDay before checking for wMonth */
608 expect(st_original.wDay, st_test.wDay);
610 /* Overflow matters, check for wMonth */
612 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
615 /* checking if gets the information right, modify st_new */
623 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_new);
626 /* st_new change to st_origin, above settings with overflow */
627 /* should not change the current settings */
628 expect(st_original.wYear, st_new.wYear);
629 expect(st_original.wMonth, st_new.wMonth);
630 expect(st_original.wDay, st_new.wDay);
631 expect(st_original.wHour, st_new.wHour);
632 expect(st_original.wMinute, st_new.wMinute);
633 expect(st_original.wSecond, st_new.wSecond);
635 /* lparam cannot be NULL */
636 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM) NULL);
639 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_curr_date_seq, "monthcal currDate", TRUE);
642 static void test_monthcal_firstDay(HWND hwnd)
644 int res, fday, i, prev;
646 LCID lcid = LOCALE_USER_DEFAULT;
648 flush_sequences(sequences, NUM_MSG_SEQUENCES);
650 /* Setter and Getters for first day of week */
651 /* check for locale first day */
652 if(GetLocaleInfo(lcid, LOCALE_IFIRSTDAYOFWEEK, b, 128)){
654 res = SendMessage(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
658 /* checking for the values that actually will be stored as */
659 /* current first day when we set a new value */
660 for (i = -5; i < 12; i++){
661 res = SendMessage(hwnd, MCM_SETFIRSTDAYOFWEEK, 0, (LPARAM) i);
663 res = SendMessage(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
667 expect(MAKELONG(fday, FALSE), res);
669 expect(MAKELONG(fday, TRUE), res);
671 expect(MAKELONG(i, TRUE), res);
675 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_first_day_seq, "monthcal firstDay", FALSE);
678 skip("Cannot retrieve first day of the week\n");
683 static void test_monthcal_unicode(HWND hwnd)
687 flush_sequences(sequences, NUM_MSG_SEQUENCES);
689 /* Setter and Getters for Unicode format */
691 /* getting the current settings */
692 temp = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
694 /* setting to 1, should return previous settings */
695 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 1, 0);
698 /* current setting is 1, so, should return 1 */
699 res = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
700 todo_wine {expect(1, res);}
702 /* setting to 0, should return previous settings */
703 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 0, 0);
704 todo_wine {expect(1, res);}
706 /* current setting is 0, so, it should return 0 */
707 res = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
710 /* should return previous settings */
711 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 1, 0);
714 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_unicode_seq, "monthcal unicode", FALSE);
717 static void test_monthcal_HitTest(HWND parent_wnd)
724 hwnd = create_monthcal_control(WS_CHILD | WS_BORDER | WS_VISIBLE, parent_wnd);
726 memset(&mchit, 0, sizeof(MCHITTESTINFO));
728 flush_sequences(sequences, NUM_MSG_SEQUENCES);
736 st.wMilliseconds = 0;
739 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st);
742 SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(SYSTEM_FONT), 0);
744 /* (0, 0) is the top left of the control and should not be active */
745 mchit.cbSize = sizeof(MCHITTESTINFO);
748 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
749 expect(0, mchit.pt.x);
750 expect(0, mchit.pt.y);
751 expect(mchit.uHit, res);
752 todo_wine {expect(MCHT_NOWHERE, res);}
754 /* (300, 400) is the bottom right of the control and should not be active */
757 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
758 expect(300, mchit.pt.x);
759 expect(400, mchit.pt.y);
760 expect(mchit.uHit, res);
761 todo_wine {expect(MCHT_NOWHERE, res);}
763 /* (500, 500) is completely out of the control and should not be active */
766 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
767 expect(500, mchit.pt.x);
768 expect(500, mchit.pt.y);
769 expect(mchit.uHit, res);
770 todo_wine {expect(MCHT_NOWHERE, res);}
772 /* (120, 180) is in active area - calendar background */
775 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
776 expect(120, mchit.pt.x);
777 expect(180, mchit.pt.y);
778 expect(mchit.uHit, res);
779 expect(MCHT_CALENDARBK, res);
781 /* (50, 40) is in active area - previous month button */
784 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
785 expect(50, mchit.pt.x);
786 expect(40, mchit.pt.y);
787 expect(mchit.uHit, res);
788 todo_wine {expect(MCHT_TITLEBTNPREV, res);}
790 /* (90, 40) is in active area - background section of the title */
793 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
794 expect(90, mchit.pt.x);
795 expect(40, mchit.pt.y);
796 expect(mchit.uHit, res);
797 todo_wine {expect(MCHT_TITLE, res);}
799 /* (140, 40) is in active area - month section of the title */
802 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
803 expect(140, mchit.pt.x);
804 expect(40, mchit.pt.y);
805 expect(mchit.uHit, res);
806 todo_wine {expect(MCHT_TITLEMONTH, res);}
808 /* (250, 40) is in active area - next month button */
811 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
812 expect(250, mchit.pt.x);
813 expect(40, mchit.pt.y);
814 expect(mchit.uHit, res);
815 todo_wine {expect(MCHT_TITLEBTNNEXT, res);}
817 /* (70, 70) is in active area - day of the week */
820 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
821 expect(70, mchit.pt.x);
822 expect(70, mchit.pt.y);
823 expect(mchit.uHit, res);
824 todo_wine {expect(MCHT_CALENDARDAY, res);}
826 /* (70, 90) is in active area - date from prev month */
829 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
830 expect(70, mchit.pt.x);
831 expect(90, mchit.pt.y);
832 expect(mchit.uHit, res);
833 todo_wine {expect(MCHT_CALENDARDATEPREV, res);}
836 /* (125, 115) is in active area - date from this month */
839 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
840 expect(125, mchit.pt.x);
841 expect(115, mchit.pt.y);
842 expect(mchit.uHit, res);
843 expect(MCHT_CALENDARDATE, res);
846 /* (80, 220) is in active area - background section of the title */
849 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
850 expect(80, mchit.pt.x);
851 expect(220, mchit.pt.y);
852 expect(mchit.uHit, res);
853 todo_wine {expect(MCHT_TITLEBK, res);}
855 /* (140, 215) is in active area - month section of the title */
858 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
859 expect(140, mchit.pt.x);
860 expect(215, mchit.pt.y);
861 expect(mchit.uHit, res);
862 todo_wine {expect(MCHT_TITLEMONTH, res);}
864 /* (170, 215) is in active area - year section of the title */
867 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
868 expect(170, mchit.pt.x);
869 expect(215, mchit.pt.y);
870 expect(mchit.uHit, res);
871 todo_wine {expect(MCHT_TITLEYEAR, res);}
873 /* (150, 260) is in active area - date from this month */
876 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
877 expect(150, mchit.pt.x);
878 expect(260, mchit.pt.y);
879 expect(mchit.uHit, res);
880 todo_wine {expect(MCHT_CALENDARDATE, res);}
882 /* (150, 350) is in active area - date from next month */
885 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
886 expect(150, mchit.pt.x);
887 expect(350, mchit.pt.y);
888 expect(mchit.uHit, res);
889 todo_wine {expect(MCHT_CALENDARDATENEXT, res);}
891 /* (150, 370) is in active area - today link */
894 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
895 expect(150, mchit.pt.x);
896 expect(370, mchit.pt.y);
897 expect(mchit.uHit, res);
898 todo_wine {expect(MCHT_TODAYLINK, res);}
900 /* (70, 370) is in active area - today link */
903 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
904 expect(70, mchit.pt.x);
905 expect(370, mchit.pt.y);
906 expect(mchit.uHit, res);
907 todo_wine {expect(MCHT_TODAYLINK, res);}
909 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_hit_test_seq, "monthcal hit test", TRUE);
914 static void test_monthcal_today(HWND hwnd)
916 SYSTEMTIME st_test, st_new;
919 flush_sequences(sequences, NUM_MSG_SEQUENCES);
921 /* Setter and Getters for "today" information */
923 /* check for overflow, should be ok */
930 SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
932 res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
935 /* st_test should not change */
936 expect(38, st_test.wDay);
937 expect(38, st_test.wMonth);
939 /* st_new should change, overflow does not matter */
940 expect(38, st_new.wDay);
941 expect(38, st_new.wMonth);
943 /* check for zero, should be ok*/
947 SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
949 res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
952 /* st_test should not change */
953 expect(0, st_test.wDay);
954 expect(0, st_test.wMonth);
956 /* st_new should change to zero*/
957 expect(0, st_new.wDay);
958 expect(0, st_new.wMonth);
960 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_today_seq, "monthcal today", TRUE);
963 static void test_monthcal_scroll(HWND hwnd)
967 flush_sequences(sequences, NUM_MSG_SEQUENCES);
969 /* Setter and Getters for scroll rate */
970 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 2, 0);
973 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 3, 0);
975 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
978 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 12, 0);
980 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
983 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 15, 0);
985 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
988 res = SendMessage(hwnd, MCM_SETMONTHDELTA, -5, 0);
990 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
993 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_scroll_seq, "monthcal scroll", FALSE);
996 static void test_monthcal_monthrange(HWND hwnd)
999 SYSTEMTIME st_visible[2], st_daystate[2];
1001 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1002 st_visible[0].wYear = 0;
1003 st_visible[0].wMonth = 0;
1004 st_visible[0].wDay = 0;
1005 st_daystate[1] = st_daystate[0] = st_visible[1] = st_visible[0];
1007 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st_visible);
1010 expect(2000, st_visible[0].wYear);
1011 expect(11, st_visible[0].wMonth);
1012 expect(1, st_visible[0].wDay);
1013 expect(2000, st_visible[1].wYear);
1014 expect(12, st_visible[1].wMonth);
1015 expect(31, st_visible[1].wDay);
1017 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, (LPARAM)st_daystate);
1020 expect(2000, st_daystate[0].wYear);
1021 expect(10, st_daystate[0].wMonth);
1022 expect(29, st_daystate[0].wDay);
1023 expect(2001, st_daystate[1].wYear);
1024 expect(1, st_daystate[1].wMonth);
1025 expect(6, st_daystate[1].wDay);
1028 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_monthrange_seq, "monthcal monthrange", FALSE);
1031 static void test_monthcal_MaxSelDay(HWND hwnd)
1035 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1037 /* Setter and Getters for max selected days */
1038 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 5, 0);
1040 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1043 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 15, 0);
1045 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1048 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, -1, 0);
1049 todo_wine {expect(0, res);}
1050 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1051 todo_wine {expect(15, res);}
1053 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_max_sel_day_seq, "monthcal MaxSelDay", FALSE);
1057 START_TEST(monthcal)
1059 HWND hwnd, parent_wnd;
1062 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
1064 parent_wnd = create_parent_window();
1066 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1067 hwnd = create_monthcal_control(WS_CHILD | WS_BORDER | WS_VISIBLE, parent_wnd);
1069 ok_sequence(sequences, PARENT_SEQ_INDEX, create_monthcal_control_seq, "create monthcal control", TRUE);
1071 test_monthcal_color(hwnd);
1072 test_monthcal_currDate(hwnd);
1073 test_monthcal_firstDay(hwnd);
1074 test_monthcal_unicode(hwnd);
1075 test_monthcal_HitTest(parent_wnd);
1076 test_monthcal_today(hwnd);
1077 test_monthcal_scroll(hwnd);
1078 test_monthcal_monthrange(hwnd);
1080 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1081 DestroyWindow(hwnd);
1082 ok_sequence(sequences, PARENT_SEQ_INDEX, destroy_monthcal_parent_msgs_seq, "Destroy monthcal (parent msg)", FALSE);
1083 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, destroy_monthcal_child_msgs_seq, "Destroy monthcal (child msg)", FALSE);
1085 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1086 hwnd = create_monthcal_control(MCS_MULTISELECT, parent_wnd);
1088 ok_sequence(sequences, PARENT_SEQ_INDEX, create_monthcal_multi_sel_style_seq, "create monthcal (multi sel style)", TRUE);
1090 test_monthcal_MaxSelDay(hwnd);
1092 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1093 DestroyWindow(hwnd);
1094 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, destroy_monthcal_multi_sel_style_seq, "Destroy monthcal (multi sel style)", FALSE);
1096 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1097 DestroyWindow(parent_wnd);
1098 ok_sequence(sequences, PARENT_SEQ_INDEX, destroy_parent_seq, "Destroy parent window", FALSE);