jscript: Added String.charAt implementation.
[wine] / dlls / comctl32 / tests / monthcal.c
1 /*
2  * comctl32 month calendar unit tests
3  *
4  * Copyright (C) 2006 Vitaliy Margolen
5  * Copyright (C) 2007 Farshad Agah
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #include <stdarg.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27
28 #include "commctrl.h"
29
30 #include "wine/test.h"
31 #include <assert.h>
32 #include <windows.h>
33 #include "msg.h"
34
35 #define expect(expected, got) ok(expected == got, "Expected %d, got %d\n", expected, got);
36
37 #define NUM_MSG_SEQUENCES   2
38 #define PARENT_SEQ_INDEX    0
39 #define MONTHCAL_SEQ_INDEX  1
40
41 struct subclass_info
42 {
43     WNDPROC oldproc;
44 };
45
46 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
47
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, 0 },
57     { WM_ACTIVATEAPP, sent|wparam, 1 },
58     { WM_NCACTIVATE, sent|wparam, 1 },
59     { WM_ACTIVATE, sent|wparam, 1 },
60     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
61     { WM_IME_NOTIFY, sent|defwinproc|optional },
62     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
63     /* Win9x adds SWP_NOZORDER below */
64     { WM_WINDOWPOSCHANGED, sent, /*|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ },
65     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
66     { WM_SIZE, sent },
67     { WM_MOVE, sent },
68     { 0 }
69 };
70
71 static const struct message create_monthcal_control_seq[] = {
72     { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
73     { WM_QUERYUISTATE, sent|optional },
74     { WM_GETFONT, sent },
75     { WM_PARENTNOTIFY, sent|wparam, WM_CREATE},
76     { 0 }
77 };
78
79 static const struct message create_monthcal_multi_sel_style_seq[] = {
80     { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
81     { WM_QUERYUISTATE, sent|optional },
82     { WM_GETFONT, sent },
83     { 0 }
84 };
85
86 static const struct message monthcal_color_seq[] = {
87     { MCM_GETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, 0},
88     { MCM_SETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, RGB(0,0,0)},
89     { MCM_GETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, 0},
90     { MCM_SETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, RGB(255,255,255)},
91     { MCM_GETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, 0},
92
93     { MCM_GETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, 0},
94     { MCM_SETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, RGB(0,0,0)},
95     { MCM_GETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, 0},
96     { MCM_SETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, RGB(255,255,255)},
97     { MCM_GETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, 0},
98
99     { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TEXT, 0},
100     { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TEXT, RGB(0,0,0)},
101     { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TEXT, 0},
102     { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TEXT, RGB(255,255,255)},
103     { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TEXT, 0},
104
105     { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, 0},
106     { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, RGB(0,0,0)},
107     { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, 0},
108     { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, RGB(255,255,255)},
109     { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, 0},
110
111     { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, 0},
112     { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, RGB(0,0,0)},
113     { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, 0},
114     { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, RGB(255,255,255)},
115     { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, 0},
116
117     { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, 0},
118     { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, RGB(0,0,0)},
119     { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, 0},
120     { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, RGB(255,255,255)},
121     { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, 0},
122     { 0 }
123 };
124
125 static const struct message monthcal_curr_date_seq[] = {
126     { MCM_SETCURSEL, sent|wparam, 0},
127     { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 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},
133     { 0 }
134 };
135
136 static const struct message monthcal_first_day_seq[] = {
137     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
138
139     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -5},
140     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
141
142     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -4},
143     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
144
145     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -3},
146     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
147
148     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -2},
149     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
150
151     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -1},
152     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
153
154     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
155     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
156
157     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 1},
158     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
159
160     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 2},
161     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
162
163     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 3},
164     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
165
166     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 4},
167     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
168
169     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 5},
170     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
171
172     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 6},
173     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
174
175     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 7},
176     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
177
178     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 8},
179     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
180
181     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 9},
182     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
183
184     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 10},
185     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
186
187     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 11},
188     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
189     { 0 }
190 };
191
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},
199     { 0 }
200 };
201
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     { MCM_HITTEST, sent|wparam, 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     { MCM_HITTEST, sent|wparam, 0},
220     { MCM_HITTEST, sent|wparam, 0},
221     { MCM_HITTEST, sent|wparam, 0},
222     { 0 }
223 };
224
225 static const struct message monthcal_todaylink_seq[] = {
226     { MCM_HITTEST, sent|wparam, 0},
227     { MCM_SETTODAY, sent|wparam, 0},
228     { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
229     { MCM_GETTODAY, sent|wparam, 0},
230     { WM_LBUTTONDOWN, sent|wparam|lparam, MK_LBUTTON, MAKELONG(70, 370)},
231     { WM_CAPTURECHANGED, sent|wparam|lparam|defwinproc, 0, 0},
232     { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
233     { MCM_GETCURSEL, sent|wparam, 0},
234     { 0 }
235 };
236
237 static const struct message monthcal_today_seq[] = {
238     { MCM_SETTODAY, sent|wparam, 0},
239     { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
240     { MCM_GETTODAY, sent|wparam, 0},
241     { MCM_SETTODAY, sent|wparam, 0},
242     { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
243     { MCM_GETTODAY, sent|wparam, 0},
244     { 0 }
245 };
246
247 static const struct message monthcal_scroll_seq[] = {
248     { MCM_SETMONTHDELTA, sent|wparam|lparam, 2, 0},
249     { MCM_SETMONTHDELTA, sent|wparam|lparam, 3, 0},
250     { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
251     { MCM_SETMONTHDELTA, sent|wparam|lparam, 12, 0},
252     { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
253     { MCM_SETMONTHDELTA, sent|wparam|lparam, 15, 0},
254     { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
255     { MCM_SETMONTHDELTA, sent|wparam|lparam, -5, 0},
256     { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
257     { 0 }
258 };
259
260 static const struct message monthcal_monthrange_seq[] = {
261     { MCM_GETMONTHRANGE, sent|wparam, GMR_VISIBLE},
262     { MCM_GETMONTHRANGE, sent|wparam, GMR_DAYSTATE},
263     { 0 }
264 };
265
266 static const struct message monthcal_max_sel_day_seq[] = {
267     { MCM_SETMAXSELCOUNT, sent|wparam|lparam, 5, 0},
268     { MCM_GETMAXSELCOUNT, sent|wparam|lparam, 0, 0},
269     { MCM_SETMAXSELCOUNT, sent|wparam|lparam, 15, 0},
270     { MCM_GETMAXSELCOUNT, sent|wparam|lparam, 0, 0},
271     { MCM_SETMAXSELCOUNT, sent|wparam|lparam, -1, 0},
272     { MCM_GETMAXSELCOUNT, sent|wparam|lparam, 0, 0},
273     { 0 }
274 };
275
276 /* expected message sequence for parent*/
277 static const struct message destroy_monthcal_parent_msgs_seq[] = {
278     { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY},
279     { 0 }
280 };
281
282 /* expected message sequence for child*/
283 static const struct message destroy_monthcal_child_msgs_seq[] = {
284     { 0x0090, sent|optional }, /* Vista */
285     { WM_SHOWWINDOW, sent|wparam|lparam, 0, 0},
286     { WM_WINDOWPOSCHANGING, sent|wparam, 0},
287     { WM_WINDOWPOSCHANGED, sent|wparam, 0},
288     { WM_DESTROY, sent|wparam|lparam, 0, 0},
289     { WM_NCDESTROY, sent|wparam|lparam, 0, 0},
290     { 0 }
291 };
292
293 static const struct message destroy_monthcal_multi_sel_style_seq[] = {
294     { 0x0090, sent|optional }, /* Vista */
295     { WM_DESTROY, sent|wparam|lparam, 0, 0},
296     { WM_NCDESTROY, sent|wparam|lparam, 0, 0},
297     { 0 }
298 };
299
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_NCACTIVATE, sent|wparam|lparam, 0, 0},
306     { WM_ACTIVATE, sent|wparam|lparam, 0, 0},
307     { WM_ACTIVATEAPP, sent|wparam, 0},
308     { WM_KILLFOCUS, sent|wparam|lparam, 0, 0},
309     { WM_IME_SETCONTEXT, sent|wparam|optional, 0},
310     { WM_IME_NOTIFY, sent|wparam|lparam|defwinproc|optional, 1, 0},
311     { WM_DESTROY, sent|wparam|lparam, 0, 0},
312     { WM_NCDESTROY, sent|wparam|lparam, 0, 0},
313     { 0 }
314 };
315
316 static void test_monthcal(void)
317 {
318     HWND hwnd;
319     SYSTEMTIME st[2], st1[2];
320     int res, month_range;
321
322     hwnd = CreateWindowA(MONTHCAL_CLASSA, "MonthCal", WS_POPUP | WS_VISIBLE, CW_USEDEFAULT,
323                          0, 300, 300, 0, 0, NULL, NULL);
324     ok(hwnd != NULL, "Failed to create MonthCal\n");
325     GetSystemTime(&st[0]);
326     st[1] = st[0];
327
328     /* Invalid date/time */
329     st[0].wYear  = 2000;
330     /* Time should not matter */
331     st[1].wHour = st[1].wMinute = st[1].wSecond = 70;
332     ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set MAX limit\n");
333     ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
334     ok(st1[0].wYear != 2000, "Lover limit changed\n");
335
336     st[1].wMonth = 0;
337     ok(!SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Should have failed to set limits\n");
338     ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
339     ok(st1[0].wYear != 2000, "Lover limit changed\n");
340     ok(!SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Should have failed to set MAX limit\n");
341     ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
342     ok(st1[0].wYear != 2000, "Lover limit changed\n");
343
344     GetSystemTime(&st[0]);
345     st[0].wDay = 20;
346     st[0].wMonth = 5;
347     st[1] = st[0];
348
349     month_range = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
350     st[1].wMonth--;
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);
354     ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == (GDTR_MIN|GDTR_MAX), "Limits should be set\n");
355
356     st[1].wMonth += 2;
357     ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
358     res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
359     ok(res == month_range, "Invalid month range (%d)\n", res);
360
361     st[1].wYear --;
362     ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
363     st[1].wYear += 1;
364     ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
365
366     st[1].wMonth -= 3;
367     ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
368     ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "Only MAX limit should be set\n");
369     st[1].wMonth += 4;
370     ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
371     st[1].wYear -= 3;
372     ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
373     st[1].wYear += 4;
374     ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
375     ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "Only MAX limit should be set\n");
376
377     DestroyWindow(hwnd);
378 }
379
380 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
381 {
382     static long defwndproc_counter = 0;
383     LRESULT ret;
384     struct message msg;
385
386     /* log system messages, except for painting */
387     if (message < WM_USER &&
388         message != WM_PAINT &&
389         message != WM_ERASEBKGND &&
390         message != WM_NCPAINT &&
391         message != WM_NCHITTEST &&
392         message != WM_GETTEXT &&
393         message != WM_GETICON &&
394         message != WM_DEVICECHANGE)
395     {
396         trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
397
398         msg.message = message;
399         msg.flags = sent|wparam|lparam;
400         if (defwndproc_counter) msg.flags |= defwinproc;
401         msg.wParam = wParam;
402         msg.lParam = lParam;
403         add_message(sequences, PARENT_SEQ_INDEX, &msg);
404     }
405
406     defwndproc_counter++;
407     ret = DefWindowProcA(hwnd, message, wParam, lParam);
408     defwndproc_counter--;
409
410     return ret;
411 }
412
413 static BOOL register_parent_wnd_class(void)
414 {
415     WNDCLASSA cls;
416
417     cls.style = 0;
418     cls.lpfnWndProc = parent_wnd_proc;
419     cls.cbClsExtra = 0;
420     cls.cbWndExtra = 0;
421     cls.hInstance = GetModuleHandleA(NULL);
422     cls.hIcon = 0;
423     cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
424     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
425     cls.lpszMenuName = NULL;
426     cls.lpszClassName = "Month-Cal test parent class";
427     return RegisterClassA(&cls);
428 }
429
430 static HWND create_parent_window(void)
431 {
432     HWND hwnd;
433
434     InitCommonControls();
435
436     /* flush message sequences, so we can check the new sequence by the end of function */
437     flush_sequences(sequences, NUM_MSG_SEQUENCES);
438
439     if (!register_parent_wnd_class())
440         return NULL;
441
442     hwnd = CreateWindowEx(0, "Month-Cal test parent class",
443                           "Month-Cal test parent window",
444                           WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
445                           WS_MAXIMIZEBOX | WS_VISIBLE,
446                           0, 0, 500, 500,
447                           GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
448
449     assert(hwnd);
450
451     /* check for message sequences */
452     ok_sequence(sequences, PARENT_SEQ_INDEX, create_parent_window_seq, "create parent window", TRUE);
453
454     return hwnd;
455 }
456
457 static LRESULT WINAPI monthcal_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
458 {
459     struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
460     static long defwndproc_counter = 0;
461     LRESULT ret;
462     struct message msg;
463
464     trace("monthcal: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
465
466     msg.message = message;
467     msg.flags = sent|wparam|lparam;
468     if (defwndproc_counter) msg.flags |= defwinproc;
469     msg.wParam = wParam;
470     msg.lParam = lParam;
471     add_message(sequences, MONTHCAL_SEQ_INDEX, &msg);
472
473     defwndproc_counter++;
474     ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
475     defwndproc_counter--;
476
477     return ret;
478 }
479
480 static HWND create_monthcal_control(DWORD style, HWND parent_window)
481 {
482     struct subclass_info *info;
483     HWND hwnd;
484
485     info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
486     if (!info)
487         return NULL;
488
489     hwnd = CreateWindowEx(0,
490                     MONTHCAL_CLASS,
491                     "",
492                     style,
493                     0, 0, 300, 400,
494                     parent_window, NULL, GetModuleHandleA(NULL), NULL);
495
496     if (!hwnd)
497     {
498         HeapFree(GetProcessHeap(), 0, info);
499         return NULL;
500     }
501
502     info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
503                                             (LONG_PTR)monthcal_subclass_proc);
504     SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
505
506     return hwnd;
507 }
508
509
510 /* Setter and Getters Tests */
511
512 static void test_monthcal_color(HWND hwnd)
513 {
514     int res, temp;
515
516     flush_sequences(sequences, NUM_MSG_SEQUENCES);
517
518     /* Setter and Getters for color*/
519     temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
520     res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(0,0,0));
521     expect(temp, res);
522     temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
523     expect(RGB(0,0,0), temp);
524     res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(255,255,255));
525     expect(temp, res);
526     temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
527     expect(RGB(255,255,255), temp);
528
529     temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
530     res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(0,0,0));
531     expect(temp, res);
532     temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
533     expect(RGB(0,0,0), temp);
534     res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(255,255,255));
535     expect(temp, res);
536     temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
537     expect(RGB(255,255,255), temp);
538
539     temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
540     res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(0,0,0));
541     expect(temp, res);
542     temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
543     expect(RGB(0,0,0), temp);
544     res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(255,255,255));
545     expect(temp, res);
546     temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
547     expect(RGB(255,255,255), temp);
548
549     temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
550     res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(0,0,0));
551     expect(temp, res);
552     temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
553     expect(RGB(0,0,0), temp);
554     res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(255,255,255));
555     expect(temp, res);
556     temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
557     expect(RGB(255,255,255), temp);
558
559     temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
560     res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(0,0,0));
561     expect(temp, res);
562     temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
563     expect(RGB(0,0,0), temp);
564     res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(255,255,255));
565     expect(temp, res);
566     temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
567     expect(RGB(255,255,255), temp);
568
569     temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
570     res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(0,0,0));
571     expect(temp, res);
572     temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
573     expect(RGB(0,0,0), temp);
574     res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(255,255,255));
575     expect(temp, res);
576     temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
577     expect(RGB(255,255,255), temp);
578
579     ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_color_seq, "monthcal color", FALSE);
580 }
581
582 static void test_monthcal_currDate(HWND hwnd)
583 {
584     SYSTEMTIME st_original, st_new, st_test;
585     int res;
586
587     flush_sequences(sequences, NUM_MSG_SEQUENCES);
588
589     /* Setter and Getters for current date selected */
590     st_original.wYear = 2000;
591     st_original.wMonth = 11;
592     st_original.wDay = 28;
593     st_original.wHour = 11;
594     st_original.wMinute = 59;
595     st_original.wSecond = 30;
596     st_original.wMilliseconds = 0;
597     st_original.wDayOfWeek = 0;
598
599     st_new = st_test = st_original;
600
601     /* Should not validate the time */
602     res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
603     expect(1,res);
604
605     /* Overflow matters, check for wDay */
606     st_test.wDay += 4;
607     res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
608     expect(0,res);
609
610     /* correct wDay before checking for wMonth */
611     st_test.wDay -= 4;
612     expect(st_original.wDay, st_test.wDay);
613
614     /* Overflow matters, check for wMonth */
615     st_test.wMonth += 4;
616     res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
617     expect(0,res);
618
619     /* checking if gets the information right, modify st_new */
620     st_new.wYear += 4;
621     st_new.wMonth += 4;
622     st_new.wDay += 4;
623     st_new.wHour += 4;
624     st_new.wMinute += 4;
625     st_new.wSecond += 4;
626
627     res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_new);
628     expect(1, res);
629
630     /* st_new change to st_origin, above settings with overflow */
631     /* should not change the current settings */
632     expect(st_original.wYear, st_new.wYear);
633     expect(st_original.wMonth, st_new.wMonth);
634     expect(st_original.wDay, st_new.wDay);
635     expect(st_original.wHour, st_new.wHour);
636     expect(st_original.wMinute, st_new.wMinute);
637     expect(st_original.wSecond, st_new.wSecond);
638
639     /* lparam cannot be NULL */
640     res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM) NULL);
641     expect(0, res);
642
643     ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_curr_date_seq, "monthcal currDate", TRUE);
644 }
645
646 static void test_monthcal_firstDay(HWND hwnd)
647 {
648     int res, fday, i, prev;
649     TCHAR b[128];
650     LCID lcid = LOCALE_USER_DEFAULT;
651
652     flush_sequences(sequences, NUM_MSG_SEQUENCES);
653
654     /* Setter and Getters for first day of week */
655     /* check for locale first day */
656     if(GetLocaleInfo(lcid, LOCALE_IFIRSTDAYOFWEEK, b, 128)){
657         fday = atoi(b);
658         trace("fday: %d\n", fday);
659         res = SendMessage(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
660         expect(fday, res);
661         prev = fday;
662
663         /* checking for the values that actually will be stored as */
664         /* current first day when we set a new value */
665         for (i = -5; i < 12; i++){
666             res = SendMessage(hwnd, MCM_SETFIRSTDAYOFWEEK, 0, (LPARAM) i);
667             expect(prev, res);
668             res = SendMessage(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
669             prev = res;
670
671             if (i == -1){
672                 expect(MAKELONG(fday, FALSE), res);
673             }else if (i >= 7){
674                 expect(MAKELONG(fday, TRUE), res);
675             }else{
676                 expect(MAKELONG(i, TRUE), res);
677             }
678         }
679
680         ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_first_day_seq, "monthcal firstDay", FALSE);
681
682     }else{
683         skip("Cannot retrieve first day of the week\n");
684     }
685
686 }
687
688 static void test_monthcal_unicode(HWND hwnd)
689 {
690     int res, temp;
691
692     flush_sequences(sequences, NUM_MSG_SEQUENCES);
693
694     /* Setter and Getters for Unicode format */
695
696     /* getting the current settings */
697     temp = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
698
699     /* setting to 1, should return previous settings */
700     res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 1, 0);
701     expect(temp, res);
702
703     /* current setting is 1, so, should return 1 */
704     res = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
705     todo_wine {expect(1, res);}
706
707     /* setting to 0, should return previous settings */
708     res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 0, 0);
709     todo_wine {expect(1, res);}
710
711     /* current setting is 0, so, it should return 0 */
712     res = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
713     expect(0, res);
714
715     /* should return previous settings */
716     res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 1, 0);
717     expect(0, res);
718
719     ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_unicode_seq, "monthcal unicode", FALSE);
720 }
721
722 static void test_monthcal_HitTest(HWND hwnd)
723 {
724     MCHITTESTINFO mchit;
725     UINT res;
726     SYSTEMTIME st;
727
728     memset(&mchit, 0, sizeof(MCHITTESTINFO));
729
730     flush_sequences(sequences, NUM_MSG_SEQUENCES);
731
732     st.wYear = 2007;
733     st.wMonth = 4;
734     st.wDay = 11;
735     st.wHour = 1;
736     st.wMinute = 0;
737     st.wSecond = 0;
738     st.wMilliseconds = 0;
739     st.wDayOfWeek = 0;
740
741     res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st);
742     expect(1,res);
743
744     /* (0, 0) is the top left of the control and should not be active */
745     mchit.cbSize = sizeof(MCHITTESTINFO);
746     mchit.pt.x = 0;
747     mchit.pt.y = 0;
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);}
753
754     /* (300, 400) is the bottom right of the control and should not be active */
755     mchit.pt.x = 300;
756     mchit.pt.y = 400;
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);}
762
763     /* (500, 500) is completely out of the control and should not be active */
764     mchit.pt.x = 500;
765     mchit.pt.y = 500;
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);}
771
772     /* (120, 180) is in active area - calendar background */
773     mchit.pt.x = 120;
774     mchit.pt.y = 180;
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);
780
781     /* (50, 40) is in active area - previous month button */
782     mchit.pt.x = 50;
783     mchit.pt.y = 40;
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);}
789
790     /* (90, 40) is in active area - background section of the title */
791     mchit.pt.x = 90;
792     mchit.pt.y = 40;
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);}
798
799     /* (140, 40) is in active area - month section of the title */
800     mchit.pt.x = 140;
801     mchit.pt.y = 40;
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);}
807
808     /* (250, 40) is in active area - next month button */
809     mchit.pt.x = 250;
810     mchit.pt.y = 40;
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);}
816
817     /* (70, 70) is in active area - day of the week */
818     mchit.pt.x = 70;
819     mchit.pt.y = 70;
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);}
825
826     /* (70, 90) is in active area - date from prev month */
827     mchit.pt.x = 70;
828     mchit.pt.y = 90;
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);}
834
835 #if 0
836     /* (125, 115) is in active area - date from this month */
837     mchit.pt.x = 125;
838     mchit.pt.y = 115;
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);
844 #endif
845
846     /* (80, 220) is in active area - background section of the title */
847     mchit.pt.x = 80;
848     mchit.pt.y = 220;
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);}
854
855     /* (140, 215) is in active area - month section of the title */
856     mchit.pt.x = 140;
857     mchit.pt.y = 215;
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);}
863
864     /* (170, 215) is in active area - year section of the title */
865     mchit.pt.x = 170;
866     mchit.pt.y = 215;
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);}
872
873     /* (150, 260) is in active area - date from this month */
874     mchit.pt.x = 150;
875     mchit.pt.y = 260;
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);}
881
882     /* (150, 350) is in active area - date from next month */
883     mchit.pt.x = 150;
884     mchit.pt.y = 350;
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);}
890
891     /* (150, 370) is in active area - today link */
892     mchit.pt.x = 150;
893     mchit.pt.y = 370;
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);}
899
900     /* (70, 370) is in active area - today link */
901     mchit.pt.x = 70;
902     mchit.pt.y = 370;
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);}
908
909     ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_hit_test_seq, "monthcal hit test", TRUE);
910 }
911
912 static void test_monthcal_todaylink(HWND hwnd)
913 {
914     MCHITTESTINFO mchit;
915     SYSTEMTIME st_test, st_new;
916     BOOL error = FALSE;
917     UINT res;
918
919     memset(&mchit, 0, sizeof(MCHITTESTINFO));
920
921     flush_sequences(sequences, NUM_MSG_SEQUENCES);
922
923     /* (70, 370) is in active area - today link */
924     mchit.cbSize = sizeof(MCHITTESTINFO);
925     mchit.pt.x = 70;
926     mchit.pt.y = 370;
927     res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
928     expect(70, mchit.pt.x);
929     expect(370, mchit.pt.y);
930     expect(mchit.uHit, res);
931     todo_wine {expect(MCHT_TODAYLINK, res);}
932     if (70 != mchit.pt.x || 370 != mchit.pt.y || mchit.uHit != res
933         || MCHT_TODAYLINK != res)
934         error = TRUE;
935
936     st_test.wDay = 1;
937     st_test.wMonth = 1;
938     st_test.wYear = 2005;
939     memset(&st_new, 0, sizeof(SYSTEMTIME));
940
941     SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
942
943     res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
944     expect(1, res);
945     expect(1, st_new.wDay);
946     expect(1, st_new.wMonth);
947     expect(2005, st_new.wYear);
948     if (1 != res || 1 != st_new.wDay || 1 != st_new.wMonth
949         || 2005 != st_new.wYear)
950         error = TRUE;
951
952     if (error) {
953         skip("cannot perform today link test\n");
954         return;
955     }
956
957     res = SendMessage(hwnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELONG(70, 370));
958     expect(0, res);
959
960     memset(&st_new, 0, sizeof(SYSTEMTIME));
961     res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_new);
962     expect(1, res);
963     expect(1, st_new.wDay);
964     expect(1, st_new.wMonth);
965     expect(2005, st_new.wYear);
966
967     ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_todaylink_seq, "monthcal hit test", TRUE);
968 }
969
970 static void test_monthcal_today(HWND hwnd)
971 {
972     SYSTEMTIME st_test, st_new;
973     int res;
974
975     flush_sequences(sequences, NUM_MSG_SEQUENCES);
976
977     /* Setter and Getters for "today" information */
978
979     /* check for overflow, should be ok */
980     st_test.wDay = 38;
981     st_test.wMonth = 38;
982
983     st_new.wDay = 27;
984     st_new.wMonth = 27;
985
986     SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
987
988     res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
989     expect(1, res);
990
991     /* st_test should not change */
992     expect(38, st_test.wDay);
993     expect(38, st_test.wMonth);
994
995     /* st_new should change, overflow does not matter */
996     expect(38, st_new.wDay);
997     expect(38, st_new.wMonth);
998
999     /* check for zero, should be ok*/
1000     st_test.wDay = 0;
1001     st_test.wMonth = 0;
1002
1003     SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
1004
1005     res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
1006     expect(1, res);
1007
1008     /* st_test should not change */
1009     expect(0, st_test.wDay);
1010     expect(0, st_test.wMonth);
1011
1012     /* st_new should change to zero*/
1013     expect(0, st_new.wDay);
1014     expect(0, st_new.wMonth);
1015
1016     ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_today_seq, "monthcal today", TRUE);
1017 }
1018
1019 static void test_monthcal_scroll(HWND hwnd)
1020 {
1021     int res;
1022
1023     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1024
1025     /* Setter and Getters for scroll rate */
1026     res = SendMessage(hwnd, MCM_SETMONTHDELTA, 2, 0);
1027     expect(0, res);
1028
1029     res = SendMessage(hwnd, MCM_SETMONTHDELTA, 3, 0);
1030     expect(2, res);
1031     res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1032     expect(3, res);
1033
1034     res = SendMessage(hwnd, MCM_SETMONTHDELTA, 12, 0);
1035     expect(3, res);
1036     res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1037     expect(12, res);
1038
1039     res = SendMessage(hwnd, MCM_SETMONTHDELTA, 15, 0);
1040     expect(12, res);
1041     res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1042     expect(15, res);
1043
1044     res = SendMessage(hwnd, MCM_SETMONTHDELTA, -5, 0);
1045     expect(15, res);
1046     res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1047     expect(-5, res);
1048
1049     ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_scroll_seq, "monthcal scroll", FALSE);
1050 }
1051
1052 static void test_monthcal_monthrange(HWND hwnd)
1053 {
1054     int res;
1055     SYSTEMTIME st_visible[2], st_daystate[2];
1056
1057     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1058     st_visible[0].wYear = 0;
1059     st_visible[0].wMonth = 0;
1060     st_visible[0].wDay = 0;
1061     st_daystate[1] = st_daystate[0] = st_visible[1] = st_visible[0];
1062
1063     res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st_visible);
1064     todo_wine {
1065         expect(2, res);
1066         expect(2000, st_visible[0].wYear);
1067         expect(11, st_visible[0].wMonth);
1068         expect(1, st_visible[0].wDay);
1069         expect(2000, st_visible[1].wYear);
1070         expect(12, st_visible[1].wMonth);
1071         expect(31, st_visible[1].wDay);
1072     }
1073     res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, (LPARAM)st_daystate);
1074     todo_wine {
1075         expect(4, res);
1076         expect(2000, st_daystate[0].wYear);
1077         expect(10, st_daystate[0].wMonth);
1078         expect(29, st_daystate[0].wDay);
1079         expect(2001, st_daystate[1].wYear);
1080         expect(1, st_daystate[1].wMonth);
1081         expect(6, st_daystate[1].wDay);
1082     }
1083
1084     ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_monthrange_seq, "monthcal monthrange", FALSE);
1085 }
1086
1087 static void test_monthcal_MaxSelDay(HWND hwnd)
1088 {
1089     int res;
1090
1091     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1092
1093     /* Setter and Getters for max selected days */
1094     res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 5, 0);
1095     expect(1, res);
1096     res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1097     expect(5, res);
1098
1099     res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 15, 0);
1100     expect(1, res);
1101     res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1102     expect(15, res);
1103
1104     res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, -1, 0);
1105     todo_wine {expect(0, res);}
1106     res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1107     todo_wine {expect(15, res);}
1108
1109     ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_max_sel_day_seq, "monthcal MaxSelDay", FALSE);
1110 }
1111
1112
1113 START_TEST(monthcal)
1114 {
1115     HMODULE hComctl32;
1116     BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
1117     INITCOMMONCONTROLSEX iccex;
1118     HWND hwnd, parent_wnd;
1119
1120     hComctl32 = GetModuleHandleA("comctl32.dll");
1121     pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
1122     if (!pInitCommonControlsEx)
1123     {
1124         skip("InitCommonControlsEx() is missing. Skipping the tests\n");
1125         return;
1126     }
1127     iccex.dwSize = sizeof(iccex);
1128     iccex.dwICC  = ICC_DATE_CLASSES;
1129     pInitCommonControlsEx(&iccex);
1130
1131     test_monthcal();
1132
1133     init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
1134
1135     parent_wnd = create_parent_window();
1136
1137     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1138     hwnd = create_monthcal_control(WS_CHILD | WS_BORDER | WS_VISIBLE, parent_wnd);
1139     assert(hwnd);
1140     ok_sequence(sequences, PARENT_SEQ_INDEX, create_monthcal_control_seq, "create monthcal control", TRUE);
1141
1142     SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(SYSTEM_FONT), 0);
1143
1144     test_monthcal_color(hwnd);
1145     test_monthcal_currDate(hwnd);
1146     test_monthcal_firstDay(hwnd);
1147     test_monthcal_unicode(hwnd);
1148     test_monthcal_today(hwnd);
1149     test_monthcal_scroll(hwnd);
1150     test_monthcal_monthrange(hwnd);
1151     test_monthcal_HitTest(hwnd);
1152     test_monthcal_todaylink(hwnd);
1153
1154     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1155     DestroyWindow(hwnd);
1156     ok_sequence(sequences, PARENT_SEQ_INDEX, destroy_monthcal_parent_msgs_seq, "Destroy monthcal (parent msg)", FALSE);
1157     ok_sequence(sequences, MONTHCAL_SEQ_INDEX, destroy_monthcal_child_msgs_seq, "Destroy monthcal (child msg)", FALSE);
1158
1159     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1160     hwnd = create_monthcal_control(MCS_MULTISELECT, parent_wnd);
1161     assert(hwnd);
1162     ok_sequence(sequences, PARENT_SEQ_INDEX, create_monthcal_multi_sel_style_seq, "create monthcal (multi sel style)", TRUE);
1163
1164     test_monthcal_MaxSelDay(hwnd);
1165
1166     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1167     DestroyWindow(hwnd);
1168     ok_sequence(sequences, MONTHCAL_SEQ_INDEX, destroy_monthcal_multi_sel_style_seq, "Destroy monthcal (multi sel style)", FALSE);
1169
1170     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1171     DestroyWindow(parent_wnd);
1172     ok_sequence(sequences, PARENT_SEQ_INDEX, destroy_parent_seq, "Destroy parent window", FALSE);
1173 }