push eb25bf65c4616aa55a810ed5c29198b1a080b208
[wine/hacks.git] / dlls / comctl32 / tests / monthcal.c
blobf116da52ec1ffcdef4b34be142ee8e1f30a12c6d
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);
37 #define NUM_MSG_SEQUENCES 2
38 #define PARENT_SEQ_INDEX 0
39 #define MONTHCAL_SEQ_INDEX 1
41 struct subclass_info
43 WNDPROC oldproc;
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 },
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|wparam, 1 },
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 { 0 }
87 static const struct message monthcal_color_seq[] = {
88 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, 0},
89 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, RGB(0,0,0)},
90 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, 0},
91 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, RGB(255,255,255)},
92 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, 0},
94 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, 0},
95 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, RGB(0,0,0)},
96 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, 0},
97 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, RGB(255,255,255)},
98 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, 0},
100 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TEXT, 0},
101 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TEXT, RGB(0,0,0)},
102 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TEXT, 0},
103 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TEXT, RGB(255,255,255)},
104 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TEXT, 0},
106 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, 0},
107 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, RGB(0,0,0)},
108 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, 0},
109 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, RGB(255,255,255)},
110 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, 0},
112 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, 0},
113 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, RGB(0,0,0)},
114 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, 0},
115 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, RGB(255,255,255)},
116 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, 0},
118 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, 0},
119 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, RGB(0,0,0)},
120 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, 0},
121 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, RGB(255,255,255)},
122 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, 0},
123 { 0 }
126 static const struct message monthcal_curr_date_seq[] = {
127 { MCM_SETCURSEL, sent|wparam, 0},
128 { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
129 { WM_ERASEBKGND, sent|lparam|defwinproc, 0},
130 { MCM_SETCURSEL, sent|wparam, 0},
131 { MCM_SETCURSEL, sent|wparam, 0},
132 { MCM_GETCURSEL, sent|wparam, 0},
133 { MCM_GETCURSEL, sent|wparam|lparam, 0, 0},
134 { 0 }
137 static const struct message monthcal_first_day_seq[] = {
138 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
140 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -5},
141 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
143 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -4},
144 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
146 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -3},
147 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
149 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -2},
150 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
152 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -1},
153 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
155 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
156 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
158 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 1},
159 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
161 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 2},
162 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
164 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 3},
165 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
167 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 4},
168 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
170 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 5},
171 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
173 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 6},
174 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
176 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 7},
177 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
179 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 8},
180 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
182 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 9},
183 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
185 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 10},
186 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
188 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 11},
189 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
190 { 0 }
193 static const struct message monthcal_unicode_seq[] = {
194 { MCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
195 { MCM_SETUNICODEFORMAT, sent|wparam|lparam, 1, 0},
196 { MCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
197 { MCM_SETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
198 { MCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
199 { MCM_SETUNICODEFORMAT, sent|wparam|lparam, 1, 0},
200 { 0 }
203 static const struct message monthcal_hit_test_seq[] = {
204 { MCM_SETCURSEL, sent|wparam, 0},
205 { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
206 { MCM_HITTEST, sent|wparam, 0},
207 { MCM_HITTEST, sent|wparam, 0},
208 { MCM_HITTEST, sent|wparam, 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_DESTROY, sent|wparam|lparam, 0, 0},
293 { WM_NCDESTROY, sent|wparam|lparam, 0, 0},
294 { 0 }
297 /* expected message sequence for parent window*/
298 static const struct message destroy_parent_seq[] = {
299 { 0x0090, sent|optional }, /* Vista */
300 { WM_WINDOWPOSCHANGING, sent|wparam, 0},
301 { WM_WINDOWPOSCHANGED, sent|wparam, 0},
302 { WM_NCACTIVATE, sent|wparam, 0},
303 { WM_ACTIVATE, sent|wparam, 0},
304 { WM_NCACTIVATE, sent|wparam|lparam|optional, 0, 0},
305 { WM_ACTIVATE, sent|wparam|lparam|optional, 0, 0},
306 { WM_ACTIVATEAPP, sent|wparam, 0},
307 { WM_KILLFOCUS, sent|wparam|lparam, 0, 0},
308 { WM_IME_SETCONTEXT, sent|wparam|optional, 0},
309 { WM_IME_NOTIFY, sent|wparam|lparam|defwinproc|optional, 1, 0},
310 { WM_DESTROY, sent|wparam|lparam, 0, 0},
311 { WM_NCDESTROY, sent|wparam|lparam, 0, 0},
312 { 0 }
315 static void test_monthcal(void)
317 HWND hwnd;
318 SYSTEMTIME st[2], st1[2];
319 int res, month_range;
321 hwnd = CreateWindowA(MONTHCAL_CLASSA, "MonthCal", WS_POPUP | WS_VISIBLE, CW_USEDEFAULT,
322 0, 300, 300, 0, 0, NULL, NULL);
323 ok(hwnd != NULL, "Failed to create MonthCal\n");
324 GetSystemTime(&st[0]);
325 st[1] = st[0];
327 /* Invalid date/time */
328 st[0].wYear = 2000;
329 /* Time should not matter */
330 st[1].wHour = st[1].wMinute = st[1].wSecond = 70;
331 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set MAX limit\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");
335 st[1].wMonth = 0;
336 ok(!SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Should have failed to set limits\n");
337 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
338 ok(st1[0].wYear != 2000, "Lover limit changed\n");
339 ok(!SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Should have failed to set MAX limit\n");
340 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
341 ok(st1[0].wYear != 2000, "Lover limit changed\n");
343 GetSystemTime(&st[0]);
344 st[0].wDay = 20;
345 st[0].wMonth = 5;
346 st[1] = st[0];
348 month_range = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
349 st[1].wMonth--;
350 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
351 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
352 ok(res == month_range, "Invalid month range (%d)\n", res);
353 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == (GDTR_MIN|GDTR_MAX), "Limits should be set\n");
355 st[1].wMonth += 2;
356 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
357 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
358 ok(res == month_range, "Invalid month range (%d)\n", res);
360 st[1].wYear --;
361 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
362 st[1].wYear += 1;
363 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
365 st[1].wMonth -= 3;
366 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
367 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "Only MAX limit should be set\n");
368 st[1].wMonth += 4;
369 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
370 st[1].wYear -= 3;
371 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
372 st[1].wYear += 4;
373 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
374 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "Only MAX limit should be set\n");
376 DestroyWindow(hwnd);
379 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
381 static long defwndproc_counter = 0;
382 LRESULT ret;
383 struct message msg;
385 /* log system messages, except for painting */
386 if (message < WM_USER &&
387 message != WM_PAINT &&
388 message != WM_ERASEBKGND &&
389 message != WM_NCPAINT &&
390 message != WM_NCHITTEST &&
391 message != WM_GETTEXT &&
392 message != WM_GETICON &&
393 message != WM_DEVICECHANGE)
395 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
397 msg.message = message;
398 msg.flags = sent|wparam|lparam;
399 if (defwndproc_counter) msg.flags |= defwinproc;
400 msg.wParam = wParam;
401 msg.lParam = lParam;
402 add_message(sequences, PARENT_SEQ_INDEX, &msg);
405 defwndproc_counter++;
406 ret = DefWindowProcA(hwnd, message, wParam, lParam);
407 defwndproc_counter--;
409 return ret;
412 static BOOL register_parent_wnd_class(void)
414 WNDCLASSA cls;
416 cls.style = 0;
417 cls.lpfnWndProc = parent_wnd_proc;
418 cls.cbClsExtra = 0;
419 cls.cbWndExtra = 0;
420 cls.hInstance = GetModuleHandleA(NULL);
421 cls.hIcon = 0;
422 cls.hCursor = LoadCursorA(0, IDC_ARROW);
423 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
424 cls.lpszMenuName = NULL;
425 cls.lpszClassName = "Month-Cal test parent class";
426 return RegisterClassA(&cls);
429 static HWND create_parent_window(void)
431 HWND hwnd;
433 InitCommonControls();
435 /* flush message sequences, so we can check the new sequence by the end of function */
436 flush_sequences(sequences, NUM_MSG_SEQUENCES);
438 if (!register_parent_wnd_class())
439 return NULL;
441 hwnd = CreateWindowEx(0, "Month-Cal test parent class",
442 "Month-Cal test parent window",
443 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
444 WS_MAXIMIZEBOX | WS_VISIBLE,
445 0, 0, 500, 500,
446 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
448 assert(hwnd);
450 /* check for message sequences */
451 ok_sequence(sequences, PARENT_SEQ_INDEX, create_parent_window_seq, "create parent window", FALSE);
453 return hwnd;
456 static LRESULT WINAPI monthcal_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
458 struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
459 static long defwndproc_counter = 0;
460 LRESULT ret;
461 struct message msg;
463 msg.message = message;
464 msg.flags = sent|wparam|lparam;
465 if (defwndproc_counter) msg.flags |= defwinproc;
466 msg.wParam = wParam;
467 msg.lParam = lParam;
468 add_message(sequences, MONTHCAL_SEQ_INDEX, &msg);
470 defwndproc_counter++;
471 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
472 defwndproc_counter--;
474 return ret;
477 static HWND create_monthcal_control(DWORD style, HWND parent_window)
479 struct subclass_info *info;
480 HWND hwnd;
482 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
483 if (!info)
484 return NULL;
486 hwnd = CreateWindowEx(0,
487 MONTHCAL_CLASS,
489 style,
490 0, 0, 300, 400,
491 parent_window, NULL, GetModuleHandleA(NULL), NULL);
493 if (!hwnd)
495 HeapFree(GetProcessHeap(), 0, info);
496 return NULL;
499 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
500 (LONG_PTR)monthcal_subclass_proc);
501 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
503 return hwnd;
507 /* Setter and Getters Tests */
509 static void test_monthcal_color(HWND hwnd)
511 int res, temp;
513 flush_sequences(sequences, NUM_MSG_SEQUENCES);
515 /* Setter and Getters for color*/
516 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
517 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(0,0,0));
518 expect(temp, res);
519 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
520 expect(RGB(0,0,0), temp);
521 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(255,255,255));
522 expect(temp, res);
523 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
524 expect(RGB(255,255,255), temp);
526 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
527 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(0,0,0));
528 expect(temp, res);
529 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
530 expect(RGB(0,0,0), temp);
531 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(255,255,255));
532 expect(temp, res);
533 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
534 expect(RGB(255,255,255), temp);
536 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
537 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(0,0,0));
538 expect(temp, res);
539 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
540 expect(RGB(0,0,0), temp);
541 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(255,255,255));
542 expect(temp, res);
543 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
544 expect(RGB(255,255,255), temp);
546 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
547 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(0,0,0));
548 expect(temp, res);
549 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
550 expect(RGB(0,0,0), temp);
551 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(255,255,255));
552 expect(temp, res);
553 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
554 expect(RGB(255,255,255), temp);
556 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
557 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(0,0,0));
558 expect(temp, res);
559 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
560 expect(RGB(0,0,0), temp);
561 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(255,255,255));
562 expect(temp, res);
563 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
564 expect(RGB(255,255,255), temp);
566 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
567 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(0,0,0));
568 expect(temp, res);
569 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
570 expect(RGB(0,0,0), temp);
571 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(255,255,255));
572 expect(temp, res);
573 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
574 expect(RGB(255,255,255), temp);
576 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_color_seq, "monthcal color", FALSE);
579 static void test_monthcal_currDate(HWND hwnd)
581 SYSTEMTIME st_original, st_new, st_test;
582 int res;
584 flush_sequences(sequences, NUM_MSG_SEQUENCES);
586 /* Setter and Getters for current date selected */
587 st_original.wYear = 2000;
588 st_original.wMonth = 11;
589 st_original.wDay = 28;
590 st_original.wHour = 11;
591 st_original.wMinute = 59;
592 st_original.wSecond = 30;
593 st_original.wMilliseconds = 0;
594 st_original.wDayOfWeek = 0;
596 st_new = st_test = st_original;
598 /* Should not validate the time */
599 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
600 expect(1,res);
602 /* Overflow matters, check for wDay */
603 st_test.wDay += 4;
604 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
605 expect(0,res);
607 /* correct wDay before checking for wMonth */
608 st_test.wDay -= 4;
609 expect(st_original.wDay, st_test.wDay);
611 /* Overflow matters, check for wMonth */
612 st_test.wMonth += 4;
613 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
614 expect(0,res);
616 /* checking if gets the information right, modify st_new */
617 st_new.wYear += 4;
618 st_new.wMonth += 4;
619 st_new.wDay += 4;
620 st_new.wHour += 4;
621 st_new.wMinute += 4;
622 st_new.wSecond += 4;
624 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_new);
625 expect(1, res);
627 /* st_new change to st_origin, above settings with overflow */
628 /* should not change the current settings */
629 expect(st_original.wYear, st_new.wYear);
630 expect(st_original.wMonth, st_new.wMonth);
631 expect(st_original.wDay, st_new.wDay);
632 expect(st_original.wHour, st_new.wHour);
633 expect(st_original.wMinute, st_new.wMinute);
634 expect(st_original.wSecond, st_new.wSecond);
636 /* lparam cannot be NULL */
637 res = SendMessage(hwnd, MCM_GETCURSEL, 0, 0);
638 expect(0, res);
640 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_curr_date_seq, "monthcal currDate", TRUE);
643 static void test_monthcal_firstDay(HWND hwnd)
645 int res, fday, i, prev;
646 TCHAR b[128];
647 LCID lcid = LOCALE_USER_DEFAULT;
649 flush_sequences(sequences, NUM_MSG_SEQUENCES);
651 /* Setter and Getters for first day of week */
652 /* check for locale first day */
653 if(GetLocaleInfo(lcid, LOCALE_IFIRSTDAYOFWEEK, b, 128)){
654 fday = atoi(b);
655 trace("fday: %d\n", fday);
656 res = SendMessage(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
657 expect(fday, res);
658 prev = fday;
660 /* checking for the values that actually will be stored as */
661 /* current first day when we set a new value */
662 for (i = -5; i < 12; i++){
663 res = SendMessage(hwnd, MCM_SETFIRSTDAYOFWEEK, 0, (LPARAM) i);
664 expect(prev, res);
665 res = SendMessage(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
666 prev = res;
668 if (i == -1){
669 expect(MAKELONG(fday, FALSE), res);
670 }else if (i >= 7){
671 /* out of range sets max first day of week, locale is ignored */
672 expect(MAKELONG(6, TRUE), res);
673 }else{
674 expect(MAKELONG(i, TRUE), res);
678 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_first_day_seq, "monthcal firstDay", FALSE);
680 }else{
681 skip("Cannot retrieve first day of the week\n");
686 static void test_monthcal_unicode(HWND hwnd)
688 int res, temp;
690 flush_sequences(sequences, NUM_MSG_SEQUENCES);
692 /* Setter and Getters for Unicode format */
694 /* getting the current settings */
695 temp = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
697 /* setting to 1, should return previous settings */
698 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 1, 0);
699 expect(temp, res);
701 /* current setting is 1, so, should return 1 */
702 res = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
703 todo_wine {expect(1, res);}
705 /* setting to 0, should return previous settings */
706 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 0, 0);
707 todo_wine {expect(1, res);}
709 /* current setting is 0, so, it should return 0 */
710 res = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
711 expect(0, res);
713 /* should return previous settings */
714 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 1, 0);
715 expect(0, res);
717 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_unicode_seq, "monthcal unicode", FALSE);
720 static void test_monthcal_HitTest(HWND hwnd)
722 MCHITTESTINFO mchit;
723 UINT res;
724 SYSTEMTIME st;
725 LONG x;
726 UINT title_index;
727 static const UINT title_hits[] =
728 { MCHT_NOWHERE, MCHT_TITLEBK, MCHT_TITLEBTNPREV, MCHT_TITLEBK,
729 MCHT_TITLEMONTH, MCHT_TITLEBK, MCHT_TITLEYEAR, MCHT_TITLEBK,
730 MCHT_TITLEBTNNEXT, MCHT_TITLEBK, MCHT_NOWHERE };
732 memset(&mchit, 0, sizeof(MCHITTESTINFO));
734 flush_sequences(sequences, NUM_MSG_SEQUENCES);
736 st.wYear = 2007;
737 st.wMonth = 4;
738 st.wDay = 11;
739 st.wHour = 1;
740 st.wMinute = 0;
741 st.wSecond = 0;
742 st.wMilliseconds = 0;
743 st.wDayOfWeek = 0;
745 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st);
746 expect(1,res);
748 /* (0, 0) is the top left of the control and should not be active */
749 mchit.cbSize = sizeof(MCHITTESTINFO);
750 mchit.pt.x = 0;
751 mchit.pt.y = 0;
752 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
753 expect(0, mchit.pt.x);
754 expect(0, mchit.pt.y);
755 expect(mchit.uHit, res);
756 todo_wine {expect(MCHT_NOWHERE, res);}
758 /* (300, 400) is the bottom right of the control and should not be active */
759 mchit.pt.x = 300;
760 mchit.pt.y = 400;
761 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
762 expect(300, mchit.pt.x);
763 expect(400, mchit.pt.y);
764 expect(mchit.uHit, res);
765 todo_wine {expect(MCHT_NOWHERE, res);}
767 /* (500, 500) is completely out of the control and should not be active */
768 mchit.pt.x = 500;
769 mchit.pt.y = 500;
770 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
771 expect(500, mchit.pt.x);
772 expect(500, mchit.pt.y);
773 expect(mchit.uHit, res);
774 todo_wine {expect(MCHT_NOWHERE, res);}
776 /* (120, 180) is in active area - calendar background */
777 mchit.pt.x = 120;
778 mchit.pt.y = 180;
779 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
780 expect(120, mchit.pt.x);
781 expect(180, mchit.pt.y);
782 expect(mchit.uHit, res);
783 expect(MCHT_CALENDARBK, res);
785 /* (70, 70) is in active area - day of the week */
786 mchit.pt.x = 70;
787 mchit.pt.y = 70;
788 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
789 expect(70, mchit.pt.x);
790 expect(70, mchit.pt.y);
791 expect(mchit.uHit, res);
792 todo_wine {expect(MCHT_CALENDARDAY, res);}
794 /* (70, 90) is in active area - date from prev month */
795 mchit.pt.x = 70;
796 mchit.pt.y = 90;
797 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
798 expect(70, mchit.pt.x);
799 expect(90, mchit.pt.y);
800 expect(mchit.uHit, res);
801 todo_wine {expect(MCHT_CALENDARDATEPREV, res);}
803 #if 0
804 /* (125, 115) is in active area - date from this month */
805 mchit.pt.x = 125;
806 mchit.pt.y = 115;
807 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
808 expect(125, mchit.pt.x);
809 expect(115, mchit.pt.y);
810 expect(mchit.uHit, res);
811 expect(MCHT_CALENDARDATE, res);
812 #endif
814 /* (80, 220) is in active area - background section of the title */
815 mchit.pt.x = 80;
816 mchit.pt.y = 220;
817 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
818 expect(80, mchit.pt.x);
819 expect(220, mchit.pt.y);
820 expect(mchit.uHit, res);
821 todo_wine {expect(MCHT_TITLEBK, res);}
823 /* (140, 215) is in active area - month section of the title */
824 mchit.pt.x = 140;
825 mchit.pt.y = 215;
826 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
827 expect(140, mchit.pt.x);
828 expect(215, mchit.pt.y);
829 expect(mchit.uHit, res);
830 todo_wine {expect(MCHT_TITLEMONTH, res);}
832 /* (170, 215) is in active area - year section of the title */
833 mchit.pt.x = 170;
834 mchit.pt.y = 215;
835 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
836 expect(170, mchit.pt.x);
837 expect(215, mchit.pt.y);
838 expect(mchit.uHit, res);
839 todo_wine {expect(MCHT_TITLEYEAR, res);}
841 /* (150, 260) is in active area - date from this month */
842 mchit.pt.x = 150;
843 mchit.pt.y = 260;
844 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
845 expect(150, mchit.pt.x);
846 expect(260, mchit.pt.y);
847 expect(mchit.uHit, res);
848 todo_wine {expect(MCHT_CALENDARDATE, res);}
850 /* (150, 350) is in active area - date from next month */
851 mchit.pt.x = 150;
852 mchit.pt.y = 350;
853 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
854 expect(150, mchit.pt.x);
855 expect(350, mchit.pt.y);
856 expect(mchit.uHit, res);
857 todo_wine {expect(MCHT_CALENDARDATENEXT, res);}
859 /* (150, 370) is in active area - today link */
860 mchit.pt.x = 150;
861 mchit.pt.y = 370;
862 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
863 expect(150, mchit.pt.x);
864 expect(370, mchit.pt.y);
865 expect(mchit.uHit, res);
866 todo_wine {expect(MCHT_TODAYLINK, res);}
868 /* (70, 370) is in active area - today link */
869 mchit.pt.x = 70;
870 mchit.pt.y = 370;
871 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
872 expect(70, mchit.pt.x);
873 expect(370, mchit.pt.y);
874 expect(mchit.uHit, res);
875 todo_wine {expect(MCHT_TODAYLINK, res);}
877 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_hit_test_seq, "monthcal hit test", TRUE);
879 /* The horizontal position of title bar elements depends on locale (y pos
880 is constant), so we sample across a horizontal line and make sure we
881 find all elements. */
882 mchit.pt.y = 40;
883 title_index = 0;
884 for (x = 0; x < 300; x++){
885 mchit.pt.x = x;
886 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
887 expect(x, mchit.pt.x);
888 expect(40, mchit.pt.y);
889 expect(mchit.uHit, res);
890 if (res != title_hits[title_index]){
891 title_index++;
892 if (sizeof(title_hits) / sizeof(title_hits[0]) <= title_index)
893 break;
894 todo_wine {expect(title_hits[title_index], res);}
897 todo_wine {ok(300 <= x && title_index + 1 == sizeof(title_hits) / sizeof(title_hits[0]),
898 "Wrong title layout\n");}
901 static void test_monthcal_todaylink(HWND hwnd)
903 MCHITTESTINFO mchit;
904 SYSTEMTIME st_test, st_new;
905 BOOL error = FALSE;
906 UINT res;
908 memset(&mchit, 0, sizeof(MCHITTESTINFO));
910 flush_sequences(sequences, NUM_MSG_SEQUENCES);
912 /* (70, 370) is in active area - today link */
913 mchit.cbSize = sizeof(MCHITTESTINFO);
914 mchit.pt.x = 70;
915 mchit.pt.y = 370;
916 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
917 expect(70, mchit.pt.x);
918 expect(370, mchit.pt.y);
919 expect(mchit.uHit, res);
920 todo_wine {expect(MCHT_TODAYLINK, res);}
921 if (70 != mchit.pt.x || 370 != mchit.pt.y || mchit.uHit != res
922 || MCHT_TODAYLINK != res)
923 error = TRUE;
925 st_test.wDay = 1;
926 st_test.wMonth = 1;
927 st_test.wYear = 2005;
928 memset(&st_new, 0, sizeof(SYSTEMTIME));
930 SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
932 res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
933 expect(1, res);
934 expect(1, st_new.wDay);
935 expect(1, st_new.wMonth);
936 expect(2005, st_new.wYear);
937 if (1 != res || 1 != st_new.wDay || 1 != st_new.wMonth
938 || 2005 != st_new.wYear)
939 error = TRUE;
941 if (error) {
942 skip("cannot perform today link test\n");
943 return;
946 res = SendMessage(hwnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELONG(70, 370));
947 expect(0, res);
949 memset(&st_new, 0, sizeof(SYSTEMTIME));
950 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_new);
951 expect(1, res);
952 expect(1, st_new.wDay);
953 expect(1, st_new.wMonth);
954 expect(2005, st_new.wYear);
956 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_todaylink_seq, "monthcal hit test", TRUE);
959 static void test_monthcal_today(HWND hwnd)
961 SYSTEMTIME st_test, st_new;
962 int res;
964 flush_sequences(sequences, NUM_MSG_SEQUENCES);
966 /* Setter and Getters for "today" information */
968 /* check for overflow, should be ok */
969 st_test.wDay = 38;
970 st_test.wMonth = 38;
972 st_new.wDay = 27;
973 st_new.wMonth = 27;
975 SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
977 res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
978 expect(1, res);
980 /* st_test should not change */
981 expect(38, st_test.wDay);
982 expect(38, st_test.wMonth);
984 /* st_new should change, overflow does not matter */
985 expect(38, st_new.wDay);
986 expect(38, st_new.wMonth);
988 /* check for zero, should be ok*/
989 st_test.wDay = 0;
990 st_test.wMonth = 0;
992 SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
994 res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
995 expect(1, res);
997 /* st_test should not change */
998 expect(0, st_test.wDay);
999 expect(0, st_test.wMonth);
1001 /* st_new should change to zero*/
1002 expect(0, st_new.wDay);
1003 expect(0, st_new.wMonth);
1005 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_today_seq, "monthcal today", TRUE);
1008 static void test_monthcal_scroll(HWND hwnd)
1010 int res;
1012 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1014 /* Setter and Getters for scroll rate */
1015 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 2, 0);
1016 expect(0, res);
1018 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 3, 0);
1019 expect(2, res);
1020 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1021 expect(3, res);
1023 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 12, 0);
1024 expect(3, res);
1025 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1026 expect(12, res);
1028 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 15, 0);
1029 expect(12, res);
1030 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1031 expect(15, res);
1033 res = SendMessage(hwnd, MCM_SETMONTHDELTA, -5, 0);
1034 expect(15, res);
1035 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1036 expect(-5, res);
1038 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_scroll_seq, "monthcal scroll", FALSE);
1041 static void test_monthcal_monthrange(HWND hwnd)
1043 int res;
1044 SYSTEMTIME st_visible[2], st_daystate[2];
1046 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1047 st_visible[0].wYear = 0;
1048 st_visible[0].wMonth = 0;
1049 st_visible[0].wDay = 0;
1050 st_daystate[1] = st_daystate[0] = st_visible[1] = st_visible[0];
1052 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st_visible);
1053 todo_wine {
1054 expect(2, res);
1055 expect(2000, st_visible[0].wYear);
1056 expect(11, st_visible[0].wMonth);
1057 expect(1, st_visible[0].wDay);
1058 expect(2000, st_visible[1].wYear);
1059 expect(12, st_visible[1].wMonth);
1060 expect(31, st_visible[1].wDay);
1062 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, (LPARAM)st_daystate);
1063 todo_wine {
1064 expect(4, res);
1065 expect(2000, st_daystate[0].wYear);
1066 expect(10, st_daystate[0].wMonth);
1067 expect(29, st_daystate[0].wDay);
1068 expect(2001, st_daystate[1].wYear);
1069 expect(1, st_daystate[1].wMonth);
1070 expect(6, st_daystate[1].wDay);
1073 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_monthrange_seq, "monthcal monthrange", FALSE);
1076 static void test_monthcal_MaxSelDay(HWND hwnd)
1078 int res;
1080 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1082 /* Setter and Getters for max selected days */
1083 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 5, 0);
1084 expect(1, res);
1085 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1086 expect(5, res);
1088 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 15, 0);
1089 expect(1, res);
1090 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1091 expect(15, res);
1093 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, -1, 0);
1094 todo_wine {expect(0, res);}
1095 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1096 todo_wine {expect(15, res);}
1098 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_max_sel_day_seq, "monthcal MaxSelDay", FALSE);
1101 static void test_monthcal_size(HWND hwnd)
1103 int res;
1104 RECT r1, r2;
1105 HFONT hFont1, hFont2;
1106 LOGFONTA logfont;
1108 lstrcpyA(logfont.lfFaceName, "Arial");
1109 memset(&logfont, 0, sizeof(logfont));
1110 logfont.lfHeight = 12;
1111 hFont1 = CreateFontIndirectA(&logfont);
1113 logfont.lfHeight = 24;
1114 hFont2 = CreateFontIndirectA(&logfont);
1116 /* initialize to a font we can compare against */
1117 SendMessage(hwnd, WM_SETFONT, (WPARAM)hFont1, 0);
1118 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r1);
1120 /* check that setting a larger font results in an larger rect */
1121 SendMessage(hwnd, WM_SETFONT, (WPARAM)hFont2, 0);
1122 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r2);
1124 OffsetRect(&r1, -r1.left, -r1.top);
1125 OffsetRect(&r2, -r2.left, -r2.top);
1127 ok(r1.bottom < r2.bottom, "Failed to get larger rect with larger font\n");
1130 START_TEST(monthcal)
1132 HMODULE hComctl32;
1133 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
1134 INITCOMMONCONTROLSEX iccex;
1135 HWND hwnd, parent_wnd;
1137 hComctl32 = GetModuleHandleA("comctl32.dll");
1138 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
1139 if (!pInitCommonControlsEx)
1141 skip("InitCommonControlsEx() is missing. Skipping the tests\n");
1142 return;
1144 iccex.dwSize = sizeof(iccex);
1145 iccex.dwICC = ICC_DATE_CLASSES;
1146 pInitCommonControlsEx(&iccex);
1148 test_monthcal();
1150 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
1152 parent_wnd = create_parent_window();
1154 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1155 hwnd = create_monthcal_control(WS_CHILD | WS_BORDER | WS_VISIBLE, parent_wnd);
1156 assert(hwnd);
1157 ok_sequence(sequences, PARENT_SEQ_INDEX, create_monthcal_control_seq, "create monthcal control", TRUE);
1159 SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(SYSTEM_FONT), 0);
1161 test_monthcal_color(hwnd);
1162 test_monthcal_currDate(hwnd);
1163 test_monthcal_firstDay(hwnd);
1164 test_monthcal_unicode(hwnd);
1165 test_monthcal_today(hwnd);
1166 test_monthcal_scroll(hwnd);
1167 test_monthcal_monthrange(hwnd);
1168 test_monthcal_HitTest(hwnd);
1169 test_monthcal_todaylink(hwnd);
1170 test_monthcal_size(hwnd);
1172 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1173 DestroyWindow(hwnd);
1174 ok_sequence(sequences, PARENT_SEQ_INDEX, destroy_monthcal_parent_msgs_seq, "Destroy monthcal (parent msg)", FALSE);
1175 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, destroy_monthcal_child_msgs_seq, "Destroy monthcal (child msg)", FALSE);
1177 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1178 hwnd = create_monthcal_control(MCS_MULTISELECT, parent_wnd);
1179 assert(hwnd);
1180 ok_sequence(sequences, PARENT_SEQ_INDEX, create_monthcal_multi_sel_style_seq, "create monthcal (multi sel style)", TRUE);
1182 test_monthcal_MaxSelDay(hwnd);
1184 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1185 DestroyWindow(hwnd);
1186 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, destroy_monthcal_multi_sel_style_seq, "Destroy monthcal (multi sel style)", FALSE);
1188 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1189 DestroyWindow(parent_wnd);
1190 ok_sequence(sequences, PARENT_SEQ_INDEX, destroy_parent_seq, "Destroy parent window", FALSE);