mshtml: Added IHTMLStyleSheet::get_rules 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_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 },
65     { WM_SIZE, sent },
66     { WM_MOVE, sent },
67     { 0 }
68 };
69
70 static const struct message create_monthcal_control_seq[] = {
71     { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
72     { WM_QUERYUISTATE, sent },
73     { WM_GETFONT, sent },
74     { WM_PARENTNOTIFY, sent|wparam, WM_CREATE},
75     { 0 }
76 };
77
78 static const struct message create_monthcal_multi_sel_style_seq[] = {
79     { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
80     { WM_QUERYUISTATE, sent },
81     { WM_GETFONT, sent },
82     { 0 }
83 };
84
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},
91
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},
97
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},
103
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},
109
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},
115
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},
121     { 0 }
122 };
123
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_ERASEBKGND, sent|lparam|defwinproc, 0},
128     { MCM_SETCURSEL, sent|wparam, 0},
129     { MCM_SETCURSEL, sent|wparam, 0},
130     { MCM_GETCURSEL, sent|wparam, 0},
131     { MCM_GETCURSEL, sent|wparam|lparam, 0, 0},
132     { 0 }
133 };
134
135 static const struct message monthcal_first_day_seq[] = {
136     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
137
138     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -5},
139     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
140
141     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -4},
142     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
143
144     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -3},
145     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
146
147     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -2},
148     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
149
150     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -1},
151     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
152
153     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
154     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
155
156     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 1},
157     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
158
159     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 2},
160     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
161
162     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 3},
163     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
164
165     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 4},
166     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
167
168     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 5},
169     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
170
171     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 6},
172     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
173
174     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 7},
175     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
176
177     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 8},
178     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
179
180     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 9},
181     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
182
183     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 10},
184     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
185
186     { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 11},
187     { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
188     { 0 }
189 };
190
191 static const struct message monthcal_unicode_seq[] = {
192     { MCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
193     { MCM_SETUNICODEFORMAT, sent|wparam|lparam, 1, 0},
194     { MCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
195     { MCM_SETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
196     { MCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
197     { MCM_SETUNICODEFORMAT, sent|wparam|lparam, 1, 0},
198     { 0 }
199 };
200
201 static const struct message monthcal_hit_test_seq[] = {
202     { MCM_SETCURSEL, sent|wparam, 0},
203     { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
204     { MCM_HITTEST, sent|wparam, 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     { 0 }
222 };
223
224 static const struct message monthcal_todaylink_seq[] = {
225     { MCM_HITTEST, sent|wparam, 0},
226     { MCM_SETTODAY, sent|wparam, 0},
227     { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
228     { MCM_GETTODAY, sent|wparam, 0},
229     { WM_LBUTTONDOWN, sent|wparam|lparam, MK_LBUTTON, MAKELONG(70, 370)},
230     { WM_CAPTURECHANGED, sent|wparam|lparam|defwinproc, 0, 0},
231     { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
232     { MCM_GETCURSEL, sent|wparam, 0},
233     { 0 }
234 };
235
236 static const struct message monthcal_today_seq[] = {
237     { MCM_SETTODAY, sent|wparam, 0},
238     { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
239     { MCM_GETTODAY, sent|wparam, 0},
240     { MCM_SETTODAY, sent|wparam, 0},
241     { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
242     { MCM_GETTODAY, sent|wparam, 0},
243     { 0 }
244 };
245
246 static const struct message monthcal_scroll_seq[] = {
247     { MCM_SETMONTHDELTA, sent|wparam|lparam, 2, 0},
248     { MCM_SETMONTHDELTA, sent|wparam|lparam, 3, 0},
249     { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
250     { MCM_SETMONTHDELTA, sent|wparam|lparam, 12, 0},
251     { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
252     { MCM_SETMONTHDELTA, sent|wparam|lparam, 15, 0},
253     { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
254     { MCM_SETMONTHDELTA, sent|wparam|lparam, -5, 0},
255     { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
256     { 0 }
257 };
258
259 static const struct message monthcal_monthrange_seq[] = {
260     { MCM_GETMONTHRANGE, sent|wparam, GMR_VISIBLE},
261     { MCM_GETMONTHRANGE, sent|wparam, GMR_DAYSTATE},
262     { 0 }
263 };
264
265 static const struct message monthcal_max_sel_day_seq[] = {
266     { MCM_SETMAXSELCOUNT, sent|wparam|lparam, 5, 0},
267     { MCM_GETMAXSELCOUNT, sent|wparam|lparam, 0, 0},
268     { MCM_SETMAXSELCOUNT, sent|wparam|lparam, 15, 0},
269     { MCM_GETMAXSELCOUNT, sent|wparam|lparam, 0, 0},
270     { MCM_SETMAXSELCOUNT, sent|wparam|lparam, -1, 0},
271     { MCM_GETMAXSELCOUNT, sent|wparam|lparam, 0, 0},
272     { 0 }
273 };
274
275 /* expected message sequence for parent*/
276 static const struct message destroy_monthcal_parent_msgs_seq[] = {
277     { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY},
278     { 0 }
279 };
280
281 /* expected message sequence for child*/
282 static const struct message destroy_monthcal_child_msgs_seq[] = {
283     { WM_SHOWWINDOW, sent|wparam|lparam, 0, 0},
284     { WM_WINDOWPOSCHANGING, sent|wparam, 0},
285     { WM_WINDOWPOSCHANGED, sent|wparam, 0},
286     { WM_DESTROY, sent|wparam|lparam, 0, 0},
287     { WM_NCDESTROY, sent|wparam|lparam, 0, 0},
288     { 0 }
289 };
290
291 static const struct message destroy_monthcal_multi_sel_style_seq[] = {
292     { WM_DESTROY, sent|wparam|lparam, 0, 0},
293     { WM_NCDESTROY, sent|wparam|lparam, 0, 0},
294     { 0 }
295 };
296
297 /* expected message sequence for parent window*/
298 static const struct message destroy_parent_seq[] = {
299     { WM_WINDOWPOSCHANGING, sent|wparam, 0},
300     { WM_WINDOWPOSCHANGED, sent|wparam, 0},
301     { WM_NCACTIVATE, sent|wparam|lparam, 0, 0},
302     { WM_ACTIVATE, sent|wparam|lparam, 0, 0},
303     { WM_ACTIVATEAPP, sent|wparam, 0},
304     { WM_KILLFOCUS, sent|wparam|lparam, 0, 0},
305     { WM_IME_SETCONTEXT, sent|wparam|optional, 0},
306     { WM_IME_NOTIFY, sent|wparam|lparam|defwinproc|optional, 1, 0},
307     { WM_DESTROY, sent|wparam|lparam, 0, 0},
308     { WM_NCDESTROY, sent|wparam|lparam, 0, 0},
309     { 0 }
310 };
311
312 static void test_monthcal(void)
313 {
314     HWND hwnd;
315     SYSTEMTIME st[2], st1[2];
316     INITCOMMONCONTROLSEX ic = {sizeof(INITCOMMONCONTROLSEX), ICC_DATE_CLASSES};
317     int res, month_range;
318
319     InitCommonControlsEx(&ic);
320     hwnd = CreateWindowA(MONTHCAL_CLASSA, "MonthCal", WS_POPUP | WS_VISIBLE, CW_USEDEFAULT,
321                          0, 300, 300, 0, 0, NULL, NULL);
322     ok(hwnd != NULL, "Failed to create MonthCal\n");
323     GetSystemTime(&st[0]);
324     st[1] = st[0];
325
326     /* Invalid date/time */
327     st[0].wYear  = 2000;
328     /* Time should not matter */
329     st[1].wHour = st[1].wMinute = st[1].wSecond = 70;
330     ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set MAX limit\n");
331     ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
332     ok(st1[0].wYear != 2000, "Lover limit changed\n");
333
334     st[1].wMonth = 0;
335     ok(!SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Should have failed to set limits\n");
336     ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
337     ok(st1[0].wYear != 2000, "Lover limit changed\n");
338     ok(!SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Should have failed to set MAX limit\n");
339     ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
340     ok(st1[0].wYear != 2000, "Lover limit changed\n");
341
342     GetSystemTime(&st[0]);
343     st[0].wDay = 20;
344     st[0].wMonth = 5;
345     st[1] = st[0];
346
347     month_range = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
348     st[1].wMonth--;
349     ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
350     res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
351     ok(res == month_range, "Invalid month range (%d)\n", res);
352     ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == (GDTR_MIN|GDTR_MAX), "Limits should be set\n");
353
354     st[1].wMonth += 2;
355     ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
356     res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
357     ok(res == month_range, "Invalid month range (%d)\n", res);
358
359     st[1].wYear --;
360     ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
361     st[1].wYear += 1;
362     ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
363
364     st[1].wMonth -= 3;
365     ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
366     ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "Only MAX limit should be set\n");
367     st[1].wMonth += 4;
368     ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
369     st[1].wYear -= 3;
370     ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
371     st[1].wYear += 4;
372     ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
373     ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "Only MAX limit should be set\n");
374
375     DestroyWindow(hwnd);
376 }
377
378 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
379 {
380     static long defwndproc_counter = 0;
381     LRESULT ret;
382     struct message msg;
383
384     /* do not log painting messages */
385     if (message != WM_PAINT &&
386         message != WM_ERASEBKGND &&
387         message != WM_NCPAINT &&
388         message != WM_NCHITTEST &&
389         message != WM_GETTEXT &&
390         message != WM_GETICON &&
391         message != WM_DEVICECHANGE)
392     {
393         trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
394
395         msg.message = message;
396         msg.flags = sent|wparam|lparam;
397         if (defwndproc_counter) msg.flags |= defwinproc;
398         msg.wParam = wParam;
399         msg.lParam = lParam;
400         add_message(sequences, PARENT_SEQ_INDEX, &msg);
401     }
402
403     defwndproc_counter++;
404     ret = DefWindowProcA(hwnd, message, wParam, lParam);
405     defwndproc_counter--;
406
407     return ret;
408 }
409
410 static BOOL register_parent_wnd_class(void)
411 {
412     WNDCLASSA cls;
413
414     cls.style = 0;
415     cls.lpfnWndProc = parent_wnd_proc;
416     cls.cbClsExtra = 0;
417     cls.cbWndExtra = 0;
418     cls.hInstance = GetModuleHandleA(NULL);
419     cls.hIcon = 0;
420     cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
421     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
422     cls.lpszMenuName = NULL;
423     cls.lpszClassName = "Month-Cal test parent class";
424     return RegisterClassA(&cls);
425 }
426
427 static HWND create_parent_window(void)
428 {
429     HWND hwnd;
430
431     InitCommonControls();
432
433     /* flush message sequences, so we can check the new sequence by the end of function */
434     flush_sequences(sequences, NUM_MSG_SEQUENCES);
435
436     if (!register_parent_wnd_class())
437         return NULL;
438
439     hwnd = CreateWindowEx(0, "Month-Cal test parent class",
440                           "Month-Cal test parent window",
441                           WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
442                           WS_MAXIMIZEBOX | WS_VISIBLE,
443                           0, 0, 500, 500,
444                           GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
445
446     assert(hwnd);
447
448     /* check for message sequences */
449     ok_sequence(sequences, PARENT_SEQ_INDEX, create_parent_window_seq, "create parent window", TRUE);
450
451     return hwnd;
452 }
453
454 static LRESULT WINAPI monthcal_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
455 {
456     struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
457     static long defwndproc_counter = 0;
458     LRESULT ret;
459     struct message msg;
460
461     trace("monthcal: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
462
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);
469
470     defwndproc_counter++;
471     ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
472     defwndproc_counter--;
473
474     return ret;
475 }
476
477 static HWND create_monthcal_control(DWORD style, HWND parent_window)
478 {
479     struct subclass_info *info;
480     HWND hwnd;
481     static const INITCOMMONCONTROLSEX ic = {sizeof(INITCOMMONCONTROLSEX), ICC_DATE_CLASSES};
482
483     InitCommonControlsEx(&ic);
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         res = SendMessage(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
659         expect(fday, res);
660         prev = fday;
661
662         /* checking for the values that actually will be stored as */
663         /* current first day when we set a new value */
664         for (i = -5; i < 12; i++){
665             res = SendMessage(hwnd, MCM_SETFIRSTDAYOFWEEK, 0, (LPARAM) i);
666             expect(prev, res);
667             res = SendMessage(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
668             prev = res;
669
670             if (i == -1){
671                 expect(MAKELONG(fday, FALSE), res);
672             }else if (i >= 7){
673                 expect(MAKELONG(fday, TRUE), res);
674             }else{
675                 expect(MAKELONG(i, TRUE), res);
676             }
677         }
678
679         ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_first_day_seq, "monthcal firstDay", FALSE);
680
681     }else{
682         skip("Cannot retrieve first day of the week\n");
683     }
684
685 }
686
687 static void test_monthcal_unicode(HWND hwnd)
688 {
689     int res, temp;
690
691     flush_sequences(sequences, NUM_MSG_SEQUENCES);
692
693     /* Setter and Getters for Unicode format */
694
695     /* getting the current settings */
696     temp = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
697
698     /* setting to 1, should return previous settings */
699     res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 1, 0);
700     expect(temp, res);
701
702     /* current setting is 1, so, should return 1 */
703     res = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
704     todo_wine {expect(1, res);}
705
706     /* setting to 0, should return previous settings */
707     res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 0, 0);
708     todo_wine {expect(1, res);}
709
710     /* current setting is 0, so, it should return 0 */
711     res = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
712     expect(0, res);
713
714     /* should return previous settings */
715     res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 1, 0);
716     expect(0, res);
717
718     ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_unicode_seq, "monthcal unicode", FALSE);
719 }
720
721 static void test_monthcal_HitTest(HWND hwnd)
722 {
723     MCHITTESTINFO mchit;
724     int res;
725     SYSTEMTIME st;
726
727     memset(&mchit, 0, sizeof(MCHITTESTINFO));
728
729     flush_sequences(sequences, NUM_MSG_SEQUENCES);
730
731     st.wYear = 2007;
732     st.wMonth = 4;
733     st.wDay = 11;
734     st.wHour = 1;
735     st.wMinute = 0;
736     st.wSecond = 0;
737     st.wMilliseconds = 0;
738     st.wDayOfWeek = 0;
739
740     res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st);
741     expect(1,res);
742
743     /* (0, 0) is the top left of the control and should not be active */
744     mchit.cbSize = sizeof(MCHITTESTINFO);
745     mchit.pt.x = 0;
746     mchit.pt.y = 0;
747     res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
748     expect(0, mchit.pt.x);
749     expect(0, mchit.pt.y);
750     expect(mchit.uHit, res);
751     todo_wine {expect(MCHT_NOWHERE, res);}
752
753     /* (300, 400) is the bottom right of the control and should not be active */
754     mchit.pt.x = 300;
755     mchit.pt.y = 400;
756     res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
757     expect(300, mchit.pt.x);
758     expect(400, mchit.pt.y);
759     expect(mchit.uHit, res);
760     todo_wine {expect(MCHT_NOWHERE, res);}
761
762     /* (500, 500) is completely out of the control and should not be active */
763     mchit.pt.x = 500;
764     mchit.pt.y = 500;
765     res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
766     expect(500, mchit.pt.x);
767     expect(500, mchit.pt.y);
768     expect(mchit.uHit, res);
769     todo_wine {expect(MCHT_NOWHERE, res);}
770
771     /* (120, 180) is in active area - calendar background */
772     mchit.pt.x = 120;
773     mchit.pt.y = 180;
774     res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
775     expect(120, mchit.pt.x);
776     expect(180, mchit.pt.y);
777     expect(mchit.uHit, res);
778     expect(MCHT_CALENDARBK, res);
779
780     /* (50, 40) is in active area - previous month button */
781     mchit.pt.x = 50;
782     mchit.pt.y = 40;
783     res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
784     expect(50, mchit.pt.x);
785     expect(40, mchit.pt.y);
786     expect(mchit.uHit, res);
787     todo_wine {expect(MCHT_TITLEBTNPREV, res);}
788
789     /* (90, 40) is in active area - background section of the title */
790     mchit.pt.x = 90;
791     mchit.pt.y = 40;
792     res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
793     expect(90, mchit.pt.x);
794     expect(40, mchit.pt.y);
795     expect(mchit.uHit, res);
796     todo_wine {expect(MCHT_TITLE, res);}
797
798     /* (140, 40) is in active area - month section of the title */
799     mchit.pt.x = 140;
800     mchit.pt.y = 40;
801     res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
802     expect(140, mchit.pt.x);
803     expect(40, mchit.pt.y);
804     expect(mchit.uHit, res);
805     todo_wine {expect(MCHT_TITLEMONTH, res);}
806
807     /* (250, 40) is in active area - next month button */
808     mchit.pt.x = 250;
809     mchit.pt.y = 40;
810     res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
811     expect(250, mchit.pt.x);
812     expect(40, mchit.pt.y);
813     expect(mchit.uHit, res);
814     todo_wine {expect(MCHT_TITLEBTNNEXT, res);}
815
816     /* (70, 70) is in active area - day of the week */
817     mchit.pt.x = 70;
818     mchit.pt.y = 70;
819     res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
820     expect(70, mchit.pt.x);
821     expect(70, mchit.pt.y);
822     expect(mchit.uHit, res);
823     todo_wine {expect(MCHT_CALENDARDAY, res);}
824
825     /* (70, 90) is in active area - date from prev month */
826     mchit.pt.x = 70;
827     mchit.pt.y = 90;
828     res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
829     expect(70, mchit.pt.x);
830     expect(90, mchit.pt.y);
831     expect(mchit.uHit, res);
832     todo_wine {expect(MCHT_CALENDARDATEPREV, res);}
833
834 #if 0
835     /* (125, 115) is in active area - date from this month */
836     mchit.pt.x = 125;
837     mchit.pt.y = 115;
838     res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
839     expect(125, mchit.pt.x);
840     expect(115, mchit.pt.y);
841     expect(mchit.uHit, res);
842     expect(MCHT_CALENDARDATE, res);
843 #endif
844
845     /* (80, 220) is in active area - background section of the title */
846     mchit.pt.x = 80;
847     mchit.pt.y = 220;
848     res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
849     expect(80, mchit.pt.x);
850     expect(220, mchit.pt.y);
851     expect(mchit.uHit, res);
852     todo_wine {expect(MCHT_TITLEBK, res);}
853
854     /* (140, 215) is in active area - month section of the title */
855     mchit.pt.x = 140;
856     mchit.pt.y = 215;
857     res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
858     expect(140, mchit.pt.x);
859     expect(215, mchit.pt.y);
860     expect(mchit.uHit, res);
861     todo_wine {expect(MCHT_TITLEMONTH, res);}
862
863     /* (170, 215) is in active area - year section of the title */
864     mchit.pt.x = 170;
865     mchit.pt.y = 215;
866     res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
867     expect(170, mchit.pt.x);
868     expect(215, mchit.pt.y);
869     expect(mchit.uHit, res);
870     todo_wine {expect(MCHT_TITLEYEAR, res);}
871
872     /* (150, 260) is in active area - date from this month */
873     mchit.pt.x = 150;
874     mchit.pt.y = 260;
875     res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
876     expect(150, mchit.pt.x);
877     expect(260, mchit.pt.y);
878     expect(mchit.uHit, res);
879     todo_wine {expect(MCHT_CALENDARDATE, res);}
880
881     /* (150, 350) is in active area - date from next month */
882     mchit.pt.x = 150;
883     mchit.pt.y = 350;
884     res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
885     expect(150, mchit.pt.x);
886     expect(350, mchit.pt.y);
887     expect(mchit.uHit, res);
888     todo_wine {expect(MCHT_CALENDARDATENEXT, res);}
889
890     /* (150, 370) is in active area - today link */
891     mchit.pt.x = 150;
892     mchit.pt.y = 370;
893     res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
894     expect(150, mchit.pt.x);
895     expect(370, mchit.pt.y);
896     expect(mchit.uHit, res);
897     todo_wine {expect(MCHT_TODAYLINK, res);}
898
899     /* (70, 370) is in active area - today link */
900     mchit.pt.x = 70;
901     mchit.pt.y = 370;
902     res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
903     expect(70, mchit.pt.x);
904     expect(370, mchit.pt.y);
905     expect(mchit.uHit, res);
906     todo_wine {expect(MCHT_TODAYLINK, res);}
907
908     ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_hit_test_seq, "monthcal hit test", TRUE);
909 }
910
911 static void test_monthcal_todaylink(HWND hwnd)
912 {
913     MCHITTESTINFO mchit;
914     SYSTEMTIME st_test, st_new;
915     BOOL error = FALSE;
916     int res;
917
918     memset(&mchit, 0, sizeof(MCHITTESTINFO));
919
920     flush_sequences(sequences, NUM_MSG_SEQUENCES);
921
922     /* (70, 370) is in active area - today link */
923     mchit.cbSize = sizeof(MCHITTESTINFO);
924     mchit.pt.x = 70;
925     mchit.pt.y = 370;
926     res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
927     expect(70, mchit.pt.x);
928     expect(370, mchit.pt.y);
929     expect(mchit.uHit, res);
930     todo_wine {expect(MCHT_TODAYLINK, res);}
931     if (70 != mchit.pt.x || 370 != mchit.pt.y || mchit.uHit != res
932         || MCHT_TODAYLINK != res)
933         error = TRUE;
934
935     st_test.wDay = 1;
936     st_test.wMonth = 1;
937     st_test.wYear = 2005;
938     memset(&st_new, 0, sizeof(SYSTEMTIME));
939
940     SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
941
942     res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
943     expect(1, res);
944     expect(1, st_new.wDay);
945     expect(1, st_new.wMonth);
946     expect(2005, st_new.wYear);
947     if (1 != res || 1 != st_new.wDay || 1 != st_new.wMonth
948         || 2005 != st_new.wYear)
949         error = TRUE;
950
951     if (error) {
952         skip("cannot perform today link test\n");
953         return;
954     }
955
956     res = SendMessage(hwnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELONG(70, 370));
957     expect(0, res);
958
959     memset(&st_new, 0, sizeof(SYSTEMTIME));
960     res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_new);
961     expect(1, res);
962     expect(1, st_new.wDay);
963     expect(1, st_new.wMonth);
964     expect(2005, st_new.wYear);
965
966     ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_todaylink_seq, "monthcal hit test", TRUE);
967 }
968
969 static void test_monthcal_today(HWND hwnd)
970 {
971     SYSTEMTIME st_test, st_new;
972     int res;
973
974     flush_sequences(sequences, NUM_MSG_SEQUENCES);
975
976     /* Setter and Getters for "today" information */
977
978     /* check for overflow, should be ok */
979     st_test.wDay = 38;
980     st_test.wMonth = 38;
981
982     st_new.wDay = 27;
983     st_new.wMonth = 27;
984
985     SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
986
987     res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
988     expect(1, res);
989
990     /* st_test should not change */
991     expect(38, st_test.wDay);
992     expect(38, st_test.wMonth);
993
994     /* st_new should change, overflow does not matter */
995     expect(38, st_new.wDay);
996     expect(38, st_new.wMonth);
997
998     /* check for zero, should be ok*/
999     st_test.wDay = 0;
1000     st_test.wMonth = 0;
1001
1002     SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
1003
1004     res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
1005     expect(1, res);
1006
1007     /* st_test should not change */
1008     expect(0, st_test.wDay);
1009     expect(0, st_test.wMonth);
1010
1011     /* st_new should change to zero*/
1012     expect(0, st_new.wDay);
1013     expect(0, st_new.wMonth);
1014
1015     ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_today_seq, "monthcal today", TRUE);
1016 }
1017
1018 static void test_monthcal_scroll(HWND hwnd)
1019 {
1020     int res;
1021
1022     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1023
1024     /* Setter and Getters for scroll rate */
1025     res = SendMessage(hwnd, MCM_SETMONTHDELTA, 2, 0);
1026     expect(0, res);
1027
1028     res = SendMessage(hwnd, MCM_SETMONTHDELTA, 3, 0);
1029     expect(2, res);
1030     res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1031     expect(3, res);
1032
1033     res = SendMessage(hwnd, MCM_SETMONTHDELTA, 12, 0);
1034     expect(3, res);
1035     res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1036     expect(12, res);
1037
1038     res = SendMessage(hwnd, MCM_SETMONTHDELTA, 15, 0);
1039     expect(12, res);
1040     res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1041     expect(15, res);
1042
1043     res = SendMessage(hwnd, MCM_SETMONTHDELTA, -5, 0);
1044     expect(15, res);
1045     res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1046     expect(-5, res);
1047
1048     ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_scroll_seq, "monthcal scroll", FALSE);
1049 }
1050
1051 static void test_monthcal_monthrange(HWND hwnd)
1052 {
1053     int res;
1054     SYSTEMTIME st_visible[2], st_daystate[2];
1055
1056     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1057     st_visible[0].wYear = 0;
1058     st_visible[0].wMonth = 0;
1059     st_visible[0].wDay = 0;
1060     st_daystate[1] = st_daystate[0] = st_visible[1] = st_visible[0];
1061
1062     res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st_visible);
1063     todo_wine {
1064         expect(2, res);
1065         expect(2000, st_visible[0].wYear);
1066         expect(11, st_visible[0].wMonth);
1067         expect(1, st_visible[0].wDay);
1068         expect(2000, st_visible[1].wYear);
1069         expect(12, st_visible[1].wMonth);
1070         expect(31, st_visible[1].wDay);
1071     }
1072     res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, (LPARAM)st_daystate);
1073     todo_wine {
1074         expect(4, res);
1075         expect(2000, st_daystate[0].wYear);
1076         expect(10, st_daystate[0].wMonth);
1077         expect(29, st_daystate[0].wDay);
1078         expect(2001, st_daystate[1].wYear);
1079         expect(1, st_daystate[1].wMonth);
1080         expect(6, st_daystate[1].wDay);
1081     }
1082
1083     ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_monthrange_seq, "monthcal monthrange", FALSE);
1084 }
1085
1086 static void test_monthcal_MaxSelDay(HWND hwnd)
1087 {
1088     int res;
1089
1090     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1091
1092     /* Setter and Getters for max selected days */
1093     res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 5, 0);
1094     expect(1, res);
1095     res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1096     expect(5, res);
1097
1098     res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 15, 0);
1099     expect(1, res);
1100     res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1101     expect(15, res);
1102
1103     res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, -1, 0);
1104     todo_wine {expect(0, res);}
1105     res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1106     todo_wine {expect(15, res);}
1107
1108     ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_max_sel_day_seq, "monthcal MaxSelDay", FALSE);
1109 }
1110
1111
1112 START_TEST(monthcal)
1113 {
1114     HWND hwnd, parent_wnd;
1115     test_monthcal();
1116
1117     init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
1118
1119     parent_wnd = create_parent_window();
1120
1121     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1122     hwnd = create_monthcal_control(WS_CHILD | WS_BORDER | WS_VISIBLE, parent_wnd);
1123     assert(hwnd);
1124     ok_sequence(sequences, PARENT_SEQ_INDEX, create_monthcal_control_seq, "create monthcal control", TRUE);
1125
1126     SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(SYSTEM_FONT), 0);
1127
1128     test_monthcal_color(hwnd);
1129     test_monthcal_currDate(hwnd);
1130     test_monthcal_firstDay(hwnd);
1131     test_monthcal_unicode(hwnd);
1132     test_monthcal_today(hwnd);
1133     test_monthcal_scroll(hwnd);
1134     test_monthcal_monthrange(hwnd);
1135     test_monthcal_HitTest(hwnd);
1136     test_monthcal_todaylink(hwnd);
1137
1138     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1139     DestroyWindow(hwnd);
1140     ok_sequence(sequences, PARENT_SEQ_INDEX, destroy_monthcal_parent_msgs_seq, "Destroy monthcal (parent msg)", FALSE);
1141     ok_sequence(sequences, MONTHCAL_SEQ_INDEX, destroy_monthcal_child_msgs_seq, "Destroy monthcal (child msg)", FALSE);
1142
1143     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1144     hwnd = create_monthcal_control(MCS_MULTISELECT, parent_wnd);
1145     assert(hwnd);
1146     ok_sequence(sequences, PARENT_SEQ_INDEX, create_monthcal_multi_sel_style_seq, "create monthcal (multi sel style)", TRUE);
1147
1148     test_monthcal_MaxSelDay(hwnd);
1149
1150     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1151     DestroyWindow(hwnd);
1152     ok_sequence(sequences, MONTHCAL_SEQ_INDEX, destroy_monthcal_multi_sel_style_seq, "Destroy monthcal (multi sel style)", FALSE);
1153
1154     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1155     DestroyWindow(parent_wnd);
1156     ok_sequence(sequences, PARENT_SEQ_INDEX, destroy_parent_seq, "Destroy parent window", FALSE);
1157 }