Autosyncing with Wine HEAD
[reactos.git] / rostests / winetests / comctl32 / 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 "wingdi.h"
27 #include "winuser.h"
28
29 #include "commctrl.h"
30
31 #include "wine/test.h"
32 #include <assert.h>
33 #include <windows.h>
34 #include "msg.h"
35
36 #define expect(expected, got) ok(expected == got, "Expected %d, got %d\n", expected, got);
37
38 #define NUM_MSG_SEQUENCES 2
39 #define PARENT_SEQ_INDEX 0
40 #define MONTHCAL_SEQ_INDEX 1
41
42 struct subclass_info
43 {
44 WNDPROC oldproc;
45 };
46
47 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
48
49 static const struct message create_parent_window_seq[] = {
50 { WM_GETMINMAXINFO, sent },
51 { WM_NCCREATE, sent },
52 { WM_NCCALCSIZE, sent|wparam, 0 },
53 { WM_CREATE, sent },
54 { WM_SHOWWINDOW, sent|wparam, 1 },
55 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
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 },
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 },
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 { WM_SHOWWINDOW, sent|wparam|lparam, 0, 0},
285 { WM_WINDOWPOSCHANGING, sent|wparam, 0},
286 { WM_WINDOWPOSCHANGED, sent|wparam, 0},
287 { WM_DESTROY, sent|wparam|lparam, 0, 0},
288 { WM_NCDESTROY, sent|wparam|lparam, 0, 0},
289 { 0 }
290 };
291
292 static const struct message destroy_monthcal_multi_sel_style_seq[] = {
293 { WM_DESTROY, sent|wparam|lparam, 0, 0},
294 { WM_NCDESTROY, sent|wparam|lparam, 0, 0},
295 { 0 }
296 };
297
298 /* expected message sequence for parent window*/
299 static const struct message destroy_parent_seq[] = {
300 { WM_WINDOWPOSCHANGING, sent|wparam, 0},
301 { WM_WINDOWPOSCHANGED, sent|wparam, 0},
302 { WM_NCACTIVATE, sent|wparam|lparam, 0, 0},
303 { WM_ACTIVATE, sent|wparam|lparam, 0, 0},
304 { WM_ACTIVATEAPP, sent|wparam, 0},
305 { WM_KILLFOCUS, sent|wparam|lparam, 0, 0},
306 { WM_IME_SETCONTEXT, sent|wparam|optional, 0},
307 { WM_IME_NOTIFY, sent|wparam|lparam|defwinproc|optional, 1, 0},
308 { WM_DESTROY, sent|wparam|lparam, 0, 0},
309 { WM_NCDESTROY, sent|wparam|lparam, 0, 0},
310 { 0 }
311 };
312
313 static void test_monthcal(void)
314 {
315 HWND hwnd;
316 SYSTEMTIME st[2], st1[2];
317 int res, month_range;
318
319 InitCommonControls();
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
482 InitCommonControls();
483
484 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
485 if (!info)
486 return NULL;
487
488 hwnd = CreateWindowEx(0,
489 MONTHCAL_CLASS,
490 "",
491 style,
492 0, 0, 300, 400,
493 parent_window, NULL, GetModuleHandleA(NULL), NULL);
494
495 if (!hwnd)
496 {
497 HeapFree(GetProcessHeap(), 0, info);
498 return NULL;
499 }
500
501 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
502 (LONG_PTR)monthcal_subclass_proc);
503 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
504
505 return hwnd;
506 }
507
508
509 /* Setter and Getters Tests */
510
511 static void test_monthcal_color(HWND hwnd)
512 {
513 int res, temp;
514
515 flush_sequences(sequences, NUM_MSG_SEQUENCES);
516
517 /* Setter and Getters for color*/
518 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
519 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(0,0,0));
520 expect(temp, res);
521 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
522 expect(RGB(0,0,0), temp);
523 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(255,255,255));
524 expect(temp, res);
525 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
526 expect(RGB(255,255,255), temp);
527
528 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
529 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(0,0,0));
530 expect(temp, res);
531 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
532 expect(RGB(0,0,0), temp);
533 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(255,255,255));
534 expect(temp, res);
535 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
536 expect(RGB(255,255,255), temp);
537
538 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
539 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(0,0,0));
540 expect(temp, res);
541 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
542 expect(RGB(0,0,0), temp);
543 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(255,255,255));
544 expect(temp, res);
545 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
546 expect(RGB(255,255,255), temp);
547
548 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
549 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(0,0,0));
550 expect(temp, res);
551 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
552 expect(RGB(0,0,0), temp);
553 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(255,255,255));
554 expect(temp, res);
555 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
556 expect(RGB(255,255,255), temp);
557
558 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
559 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(0,0,0));
560 expect(temp, res);
561 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
562 expect(RGB(0,0,0), temp);
563 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(255,255,255));
564 expect(temp, res);
565 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
566 expect(RGB(255,255,255), temp);
567
568 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
569 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(0,0,0));
570 expect(temp, res);
571 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
572 expect(RGB(0,0,0), temp);
573 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(255,255,255));
574 expect(temp, res);
575 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
576 expect(RGB(255,255,255), temp);
577
578 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_color_seq, "monthcal color", FALSE);
579 }
580
581 static void test_monthcal_currDate(HWND hwnd)
582 {
583 SYSTEMTIME st_original, st_new, st_test;
584 int res;
585
586 flush_sequences(sequences, NUM_MSG_SEQUENCES);
587
588 /* Setter and Getters for current date selected */
589 st_original.wYear = 2000;
590 st_original.wMonth = 11;
591 st_original.wDay = 28;
592 st_original.wHour = 11;
593 st_original.wMinute = 59;
594 st_original.wSecond = 30;
595 st_original.wMilliseconds = 0;
596 st_original.wDayOfWeek = 0;
597
598 st_new = st_test = st_original;
599
600 /* Should not validate the time */
601 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
602 expect(1,res);
603
604 /* Overflow matters, check for wDay */
605 st_test.wDay += 4;
606 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
607 expect(0,res);
608
609 /* correct wDay before checking for wMonth */
610 st_test.wDay -= 4;
611 expect(st_original.wDay, st_test.wDay);
612
613 /* Overflow matters, check for wMonth */
614 st_test.wMonth += 4;
615 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
616 expect(0,res);
617
618 /* checking if gets the information right, modify st_new */
619 st_new.wYear += 4;
620 st_new.wMonth += 4;
621 st_new.wDay += 4;
622 st_new.wHour += 4;
623 st_new.wMinute += 4;
624 st_new.wSecond += 4;
625
626 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_new);
627 expect(1, res);
628
629 /* st_new change to st_origin, above settings with overflow */
630 /* should not change the current settings */
631 expect(st_original.wYear, st_new.wYear);
632 expect(st_original.wMonth, st_new.wMonth);
633 expect(st_original.wDay, st_new.wDay);
634 expect(st_original.wHour, st_new.wHour);
635 expect(st_original.wMinute, st_new.wMinute);
636 expect(st_original.wSecond, st_new.wSecond);
637
638 /* lparam cannot be NULL */
639 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM) NULL);
640 expect(0, res);
641
642 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_curr_date_seq, "monthcal currDate", TRUE);
643 }
644
645 static void test_monthcal_firstDay(HWND hwnd)
646 {
647 int res, fday, i, prev;
648 TCHAR b[128];
649 LCID lcid = LOCALE_USER_DEFAULT;
650
651 flush_sequences(sequences, NUM_MSG_SEQUENCES);
652
653 /* Setter and Getters for first day of week */
654 /* check for locale first day */
655 if(GetLocaleInfo(lcid, LOCALE_IFIRSTDAYOFWEEK, b, 128)){
656 fday = atoi(b);
657 res = SendMessage(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
658 expect(fday, res);
659 prev = fday;
660
661 /* checking for the values that actually will be stored as */
662 /* current first day when we set a new value */
663 for (i = -5; i < 12; i++){
664 res = SendMessage(hwnd, MCM_SETFIRSTDAYOFWEEK, 0, (LPARAM) i);
665 expect(prev, res);
666 res = SendMessage(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
667 prev = res;
668
669 if (i == -1){
670 expect(MAKELONG(fday, FALSE), res);
671 }else if (i >= 7){
672 expect(MAKELONG(fday, TRUE), res);
673 }else{
674 expect(MAKELONG(i, TRUE), res);
675 }
676 }
677
678 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_first_day_seq, "monthcal firstDay", FALSE);
679
680 }else{
681 skip("Cannot retrieve first day of the week\n");
682 }
683
684 }
685
686 static void test_monthcal_unicode(HWND hwnd)
687 {
688 int res, temp;
689
690 flush_sequences(sequences, NUM_MSG_SEQUENCES);
691
692 /* Setter and Getters for Unicode format */
693
694 /* getting the current settings */
695 temp = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
696
697 /* setting to 1, should return previous settings */
698 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 1, 0);
699 expect(temp, res);
700
701 /* current setting is 1, so, should return 1 */
702 res = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
703 todo_wine {expect(1, res);}
704
705 /* setting to 0, should return previous settings */
706 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 0, 0);
707 todo_wine {expect(1, res);}
708
709 /* current setting is 0, so, it should return 0 */
710 res = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
711 expect(0, res);
712
713 /* should return previous settings */
714 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 1, 0);
715 expect(0, res);
716
717 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_unicode_seq, "monthcal unicode", FALSE);
718 }
719
720 static void test_monthcal_HitTest(HWND hwnd)
721 {
722 MCHITTESTINFO mchit;
723 int res;
724 SYSTEMTIME st;
725
726 memset(&mchit, 0, sizeof(MCHITTESTINFO));
727
728 flush_sequences(sequences, NUM_MSG_SEQUENCES);
729
730 st.wYear = 2007;
731 st.wMonth = 4;
732 st.wDay = 11;
733 st.wHour = 1;
734 st.wMinute = 0;
735 st.wSecond = 0;
736 st.wMilliseconds = 0;
737 st.wDayOfWeek = 0;
738
739 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st);
740 expect(1,res);
741
742 /* (0, 0) is the top left of the control and should not be active */
743 mchit.cbSize = sizeof(MCHITTESTINFO);
744 mchit.pt.x = 0;
745 mchit.pt.y = 0;
746 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
747 expect(0, mchit.pt.x);
748 expect(0, mchit.pt.y);
749 expect(mchit.uHit, res);
750 todo_wine {expect(MCHT_NOWHERE, res);}
751
752 /* (300, 400) is the bottom right of the control and should not be active */
753 mchit.pt.x = 300;
754 mchit.pt.y = 400;
755 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
756 expect(300, mchit.pt.x);
757 expect(400, mchit.pt.y);
758 expect(mchit.uHit, res);
759 todo_wine {expect(MCHT_NOWHERE, res);}
760
761 /* (500, 500) is completely out of the control and should not be active */
762 mchit.pt.x = 500;
763 mchit.pt.y = 500;
764 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
765 expect(500, mchit.pt.x);
766 expect(500, mchit.pt.y);
767 expect(mchit.uHit, res);
768 todo_wine {expect(MCHT_NOWHERE, res);}
769
770 /* (120, 180) is in active area - calendar background */
771 mchit.pt.x = 120;
772 mchit.pt.y = 180;
773 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
774 expect(120, mchit.pt.x);
775 expect(180, mchit.pt.y);
776 expect(mchit.uHit, res);
777 expect(MCHT_CALENDARBK, res);
778
779 /* (50, 40) is in active area - previous month button */
780 mchit.pt.x = 50;
781 mchit.pt.y = 40;
782 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
783 expect(50, mchit.pt.x);
784 expect(40, mchit.pt.y);
785 expect(mchit.uHit, res);
786 todo_wine {expect(MCHT_TITLEBTNPREV, res);}
787
788 /* (90, 40) is in active area - background section of the title */
789 mchit.pt.x = 90;
790 mchit.pt.y = 40;
791 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
792 expect(90, mchit.pt.x);
793 expect(40, mchit.pt.y);
794 expect(mchit.uHit, res);
795 todo_wine {expect(MCHT_TITLE, res);}
796
797 /* (140, 40) is in active area - month section of the title */
798 mchit.pt.x = 140;
799 mchit.pt.y = 40;
800 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
801 expect(140, mchit.pt.x);
802 expect(40, mchit.pt.y);
803 expect(mchit.uHit, res);
804 todo_wine {expect(MCHT_TITLEMONTH, res);}
805
806 /* (250, 40) is in active area - next month button */
807 mchit.pt.x = 250;
808 mchit.pt.y = 40;
809 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
810 expect(250, mchit.pt.x);
811 expect(40, mchit.pt.y);
812 expect(mchit.uHit, res);
813 todo_wine {expect(MCHT_TITLEBTNNEXT, res);}
814
815 /* (70, 70) is in active area - day of the week */
816 mchit.pt.x = 70;
817 mchit.pt.y = 70;
818 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
819 expect(70, mchit.pt.x);
820 expect(70, mchit.pt.y);
821 expect(mchit.uHit, res);
822 todo_wine {expect(MCHT_CALENDARDAY, res);}
823
824 /* (70, 90) is in active area - date from prev month */
825 mchit.pt.x = 70;
826 mchit.pt.y = 90;
827 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
828 expect(70, mchit.pt.x);
829 expect(90, mchit.pt.y);
830 expect(mchit.uHit, res);
831 todo_wine {expect(MCHT_CALENDARDATEPREV, res);}
832
833 #if 0
834 /* (125, 115) is in active area - date from this month */
835 mchit.pt.x = 125;
836 mchit.pt.y = 115;
837 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
838 expect(125, mchit.pt.x);
839 expect(115, mchit.pt.y);
840 expect(mchit.uHit, res);
841 expect(MCHT_CALENDARDATE, res);
842 #endif
843
844 /* (80, 220) is in active area - background section of the title */
845 mchit.pt.x = 80;
846 mchit.pt.y = 220;
847 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
848 expect(80, mchit.pt.x);
849 expect(220, mchit.pt.y);
850 expect(mchit.uHit, res);
851 todo_wine {expect(MCHT_TITLEBK, res);}
852
853 /* (140, 215) is in active area - month section of the title */
854 mchit.pt.x = 140;
855 mchit.pt.y = 215;
856 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
857 expect(140, mchit.pt.x);
858 expect(215, mchit.pt.y);
859 expect(mchit.uHit, res);
860 todo_wine {expect(MCHT_TITLEMONTH, res);}
861
862 /* (170, 215) is in active area - year section of the title */
863 mchit.pt.x = 170;
864 mchit.pt.y = 215;
865 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
866 expect(170, mchit.pt.x);
867 expect(215, mchit.pt.y);
868 expect(mchit.uHit, res);
869 todo_wine {expect(MCHT_TITLEYEAR, res);}
870
871 /* (150, 260) is in active area - date from this month */
872 mchit.pt.x = 150;
873 mchit.pt.y = 260;
874 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
875 expect(150, mchit.pt.x);
876 expect(260, mchit.pt.y);
877 expect(mchit.uHit, res);
878 todo_wine {expect(MCHT_CALENDARDATE, res);}
879
880 /* (150, 350) is in active area - date from next month */
881 mchit.pt.x = 150;
882 mchit.pt.y = 350;
883 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
884 expect(150, mchit.pt.x);
885 expect(350, mchit.pt.y);
886 expect(mchit.uHit, res);
887 todo_wine {expect(MCHT_CALENDARDATENEXT, res);}
888
889 /* (150, 370) is in active area - today link */
890 mchit.pt.x = 150;
891 mchit.pt.y = 370;
892 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
893 expect(150, mchit.pt.x);
894 expect(370, mchit.pt.y);
895 expect(mchit.uHit, res);
896 todo_wine {expect(MCHT_TODAYLINK, res);}
897
898 /* (70, 370) is in active area - today link */
899 mchit.pt.x = 70;
900 mchit.pt.y = 370;
901 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
902 expect(70, mchit.pt.x);
903 expect(370, mchit.pt.y);
904 expect(mchit.uHit, res);
905 todo_wine {expect(MCHT_TODAYLINK, res);}
906
907 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_hit_test_seq, "monthcal hit test", TRUE);
908 }
909
910 static void test_monthcal_todaylink(HWND hwnd)
911 {
912 MCHITTESTINFO mchit;
913 SYSTEMTIME st_test, st_new;
914 BOOL error = FALSE;
915 int res;
916
917 memset(&mchit, 0, sizeof(MCHITTESTINFO));
918
919 flush_sequences(sequences, NUM_MSG_SEQUENCES);
920
921 /* (70, 370) is in active area - today link */
922 mchit.cbSize = sizeof(MCHITTESTINFO);
923 mchit.pt.x = 70;
924 mchit.pt.y = 370;
925 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
926 expect(70, mchit.pt.x);
927 expect(370, mchit.pt.y);
928 expect(mchit.uHit, res);
929 todo_wine {expect(MCHT_TODAYLINK, res);}
930 if (70 != mchit.pt.x || 370 != mchit.pt.y || mchit.uHit != res
931 || MCHT_TODAYLINK != res)
932 error = TRUE;
933
934 st_test.wDay = 1;
935 st_test.wMonth = 1;
936 st_test.wYear = 2005;
937 memset(&st_new, 0, sizeof(SYSTEMTIME));
938
939 SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
940
941 res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
942 expect(1, res);
943 expect(1, st_new.wDay);
944 expect(1, st_new.wMonth);
945 expect(2005, st_new.wYear);
946 if (1 != res || 1 != st_new.wDay || 1 != st_new.wMonth
947 || 2005 != st_new.wYear)
948 error = TRUE;
949
950 if (error) {
951 skip("cannot perform today link test\n");
952 return;
953 }
954
955 res = SendMessage(hwnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELONG(70, 370));
956 expect(0, res);
957
958 memset(&st_new, 0, sizeof(SYSTEMTIME));
959 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_new);
960 expect(1, res);
961 expect(1, st_new.wDay);
962 expect(1, st_new.wMonth);
963 expect(2005, st_new.wYear);
964
965 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_todaylink_seq, "monthcal hit test", TRUE);
966 }
967
968 static void test_monthcal_today(HWND hwnd)
969 {
970 SYSTEMTIME st_test, st_new;
971 int res;
972
973 flush_sequences(sequences, NUM_MSG_SEQUENCES);
974
975 /* Setter and Getters for "today" information */
976
977 /* check for overflow, should be ok */
978 st_test.wDay = 38;
979 st_test.wMonth = 38;
980
981 st_new.wDay = 27;
982 st_new.wMonth = 27;
983
984 SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
985
986 res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
987 expect(1, res);
988
989 /* st_test should not change */
990 expect(38, st_test.wDay);
991 expect(38, st_test.wMonth);
992
993 /* st_new should change, overflow does not matter */
994 expect(38, st_new.wDay);
995 expect(38, st_new.wMonth);
996
997 /* check for zero, should be ok*/
998 st_test.wDay = 0;
999 st_test.wMonth = 0;
1000
1001 SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
1002
1003 res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
1004 expect(1, res);
1005
1006 /* st_test should not change */
1007 expect(0, st_test.wDay);
1008 expect(0, st_test.wMonth);
1009
1010 /* st_new should change to zero*/
1011 expect(0, st_new.wDay);
1012 expect(0, st_new.wMonth);
1013
1014 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_today_seq, "monthcal today", TRUE);
1015 }
1016
1017 static void test_monthcal_scroll(HWND hwnd)
1018 {
1019 int res;
1020
1021 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1022
1023 /* Setter and Getters for scroll rate */
1024 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 2, 0);
1025 expect(0, res);
1026
1027 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 3, 0);
1028 expect(2, res);
1029 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1030 expect(3, res);
1031
1032 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 12, 0);
1033 expect(3, res);
1034 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1035 expect(12, res);
1036
1037 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 15, 0);
1038 expect(12, res);
1039 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1040 expect(15, res);
1041
1042 res = SendMessage(hwnd, MCM_SETMONTHDELTA, -5, 0);
1043 expect(15, res);
1044 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1045 expect(-5, res);
1046
1047 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_scroll_seq, "monthcal scroll", FALSE);
1048 }
1049
1050 static void test_monthcal_monthrange(HWND hwnd)
1051 {
1052 int res;
1053 SYSTEMTIME st_visible[2], st_daystate[2];
1054
1055 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1056 st_visible[0].wYear = 0;
1057 st_visible[0].wMonth = 0;
1058 st_visible[0].wDay = 0;
1059 st_daystate[1] = st_daystate[0] = st_visible[1] = st_visible[0];
1060
1061 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st_visible);
1062 todo_wine {
1063 expect(2, res);
1064 expect(2000, st_visible[0].wYear);
1065 expect(11, st_visible[0].wMonth);
1066 expect(1, st_visible[0].wDay);
1067 expect(2000, st_visible[1].wYear);
1068 expect(12, st_visible[1].wMonth);
1069 expect(31, st_visible[1].wDay);
1070 }
1071 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, (LPARAM)st_daystate);
1072 todo_wine {
1073 expect(4, res);
1074 expect(2000, st_daystate[0].wYear);
1075 expect(10, st_daystate[0].wMonth);
1076 expect(29, st_daystate[0].wDay);
1077 expect(2001, st_daystate[1].wYear);
1078 expect(1, st_daystate[1].wMonth);
1079 expect(6, st_daystate[1].wDay);
1080 }
1081
1082 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_monthrange_seq, "monthcal monthrange", FALSE);
1083 }
1084
1085 static void test_monthcal_MaxSelDay(HWND hwnd)
1086 {
1087 int res;
1088
1089 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1090
1091 /* Setter and Getters for max selected days */
1092 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 5, 0);
1093 expect(1, res);
1094 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1095 expect(5, res);
1096
1097 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 15, 0);
1098 expect(1, res);
1099 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1100 expect(15, res);
1101
1102 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, -1, 0);
1103 todo_wine {expect(0, res);}
1104 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1105 todo_wine {expect(15, res);}
1106
1107 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_max_sel_day_seq, "monthcal MaxSelDay", FALSE);
1108 }
1109
1110
1111 START_TEST(monthcal)
1112 {
1113 HWND hwnd, parent_wnd;
1114 test_monthcal();
1115
1116 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
1117
1118 parent_wnd = create_parent_window();
1119
1120 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1121 hwnd = create_monthcal_control(WS_CHILD | WS_BORDER | WS_VISIBLE, parent_wnd);
1122 assert(hwnd);
1123 ok_sequence(sequences, PARENT_SEQ_INDEX, create_monthcal_control_seq, "create monthcal control", TRUE);
1124
1125 SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(SYSTEM_FONT), 0);
1126
1127 test_monthcal_color(hwnd);
1128 test_monthcal_currDate(hwnd);
1129 test_monthcal_firstDay(hwnd);
1130 test_monthcal_unicode(hwnd);
1131 test_monthcal_today(hwnd);
1132 test_monthcal_scroll(hwnd);
1133 test_monthcal_monthrange(hwnd);
1134 test_monthcal_HitTest(hwnd);
1135 test_monthcal_todaylink(hwnd);
1136
1137 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1138 DestroyWindow(hwnd);
1139 ok_sequence(sequences, PARENT_SEQ_INDEX, destroy_monthcal_parent_msgs_seq, "Destroy monthcal (parent msg)", FALSE);
1140 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, destroy_monthcal_child_msgs_seq, "Destroy monthcal (child msg)", FALSE);
1141
1142 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1143 hwnd = create_monthcal_control(MCS_MULTISELECT, parent_wnd);
1144 assert(hwnd);
1145 ok_sequence(sequences, PARENT_SEQ_INDEX, create_monthcal_multi_sel_style_seq, "create monthcal (multi sel style)", TRUE);
1146
1147 test_monthcal_MaxSelDay(hwnd);
1148
1149 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1150 DestroyWindow(hwnd);
1151 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, destroy_monthcal_multi_sel_style_seq, "Destroy monthcal (multi sel style)", FALSE);
1152
1153 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1154 DestroyWindow(parent_wnd);
1155 ok_sequence(sequences, PARENT_SEQ_INDEX, destroy_parent_seq, "Destroy parent window", FALSE);
1156 }