monthcal.c 39.6 KB
Newer Older
1 2 3 4
/*
 * comctl32 month calendar unit tests
 *
 * Copyright (C) 2006 Vitaliy Margolen
5
 * Copyright (C) 2007 Farshad Agah
6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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 23 24 25 26 27 28 29 30
 */

#include <stdarg.h>

#include "windef.h"
#include "winbase.h"
#include "winuser.h"

#include "commctrl.h"

#include "wine/test.h"
31 32
#include <assert.h>
#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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
#define NUM_MSG_SEQUENCES   2
#define PARENT_SEQ_INDEX    0
#define MONTHCAL_SEQ_INDEX  1

struct subclass_info
{
    WNDPROC oldproc;
};

static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];

static const struct message create_parent_window_seq[] = {
    { WM_GETMINMAXINFO, sent },
    { WM_NCCREATE, sent },
    { WM_NCCALCSIZE, sent|wparam, 0 },
    { WM_CREATE, sent },
    { WM_SHOWWINDOW, sent|wparam, 1 },
    { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
55
    { WM_QUERYNEWPALETTE, sent|optional },
56 57
    { WM_WINDOWPOSCHANGING, sent|wparam|optional, 0 },
    { WM_WINDOWPOSCHANGED, sent|optional },
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
    { WM_ACTIVATEAPP, sent|wparam, 1 },
    { WM_NCACTIVATE, sent|wparam, 1 },
    { WM_ACTIVATE, sent|wparam, 1 },
    { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
    { WM_IME_NOTIFY, sent|defwinproc|optional },
    { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
    /* Win9x adds SWP_NOZORDER below */
    { WM_WINDOWPOSCHANGED, sent, /*|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ },
    { WM_NCCALCSIZE, sent|wparam|optional, 1 },
    { WM_SIZE, sent },
    { WM_MOVE, sent },
    { 0 }
};

static const struct message create_monthcal_control_seq[] = {
    { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
74
    { WM_QUERYUISTATE, sent|optional },
75 76 77 78 79 80 81
    { WM_GETFONT, sent },
    { WM_PARENTNOTIFY, sent|wparam, WM_CREATE},
    { 0 }
};

static const struct message create_monthcal_multi_sel_style_seq[] = {
    { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
82
    { WM_QUERYUISTATE, sent|optional },
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
    { WM_GETFONT, sent },
    { 0 }
};

static const struct message monthcal_color_seq[] = {
    { MCM_GETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, 0},
    { MCM_SETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, RGB(0,0,0)},
    { MCM_GETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, 0},
    { MCM_SETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, RGB(255,255,255)},
    { MCM_GETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, 0},

    { MCM_GETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, 0},
    { MCM_SETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, RGB(0,0,0)},
    { MCM_GETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, 0},
    { MCM_SETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, RGB(255,255,255)},
    { MCM_GETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, 0},

    { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TEXT, 0},
    { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TEXT, RGB(0,0,0)},
    { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TEXT, 0},
    { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TEXT, RGB(255,255,255)},
    { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TEXT, 0},

    { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, 0},
    { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, RGB(0,0,0)},
    { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, 0},
    { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, RGB(255,255,255)},
    { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, 0},

    { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, 0},
    { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, RGB(0,0,0)},
    { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, 0},
    { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, RGB(255,255,255)},
    { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, 0},

    { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, 0},
    { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, RGB(0,0,0)},
    { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, 0},
    { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, RGB(255,255,255)},
    { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, 0},
    { 0 }
};

static const struct message monthcal_curr_date_seq[] = {
    { MCM_SETCURSEL, sent|wparam, 0},
    { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
    { WM_ERASEBKGND, sent|lparam|defwinproc, 0},
    { MCM_SETCURSEL, sent|wparam, 0},
    { MCM_SETCURSEL, sent|wparam, 0},
    { MCM_GETCURSEL, sent|wparam, 0},
    { MCM_GETCURSEL, sent|wparam|lparam, 0, 0},
    { 0 }
};

static const struct message monthcal_first_day_seq[] = {
    { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},

140
    { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -5},
141 142
    { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},

143
    { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -4},
144 145
    { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},

146
    { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -3},
147 148
    { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},

149
    { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -2},
150 151
    { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},

152 153 154 155 156 157 158 159 160 161
    { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -1},
    { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},

    { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
    { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},

    { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 1},
    { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},

    { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 2},
162 163
    { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},

164
    { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 3},
165
    { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
166 167 168 169 170 171 172

    { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 4},
    { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},

    { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 5},
    { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},

173
    { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 6},
174 175 176 177 178 179 180 181 182 183
    { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},

    { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 7},
    { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},

    { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 8},
    { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},

    { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 9},
    { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
184

185 186 187 188
    { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 10},
    { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},

    { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 11},
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
    { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
    { 0 }
};

static const struct message monthcal_unicode_seq[] = {
    { MCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
    { MCM_SETUNICODEFORMAT, sent|wparam|lparam, 1, 0},
    { MCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
    { MCM_SETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
    { MCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
    { MCM_SETUNICODEFORMAT, sent|wparam|lparam, 1, 0},
    { 0 }
};

static const struct message monthcal_hit_test_seq[] = {
204 205
    { MCM_SETCURSEL, sent|wparam, 0},
    { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
206 207 208 209 210 211 212 213 214 215 216 217 218
    { MCM_HITTEST, sent|wparam, 0},
    { MCM_HITTEST, sent|wparam, 0},
    { MCM_HITTEST, sent|wparam, 0},
    { MCM_HITTEST, sent|wparam, 0},
    { MCM_HITTEST, sent|wparam, 0},
    { MCM_HITTEST, sent|wparam, 0},
    { MCM_HITTEST, sent|wparam, 0},
    { MCM_HITTEST, sent|wparam, 0},
    { MCM_HITTEST, sent|wparam, 0},
    { MCM_HITTEST, sent|wparam, 0},
    { MCM_HITTEST, sent|wparam, 0},
    { MCM_HITTEST, sent|wparam, 0},
    { MCM_HITTEST, sent|wparam, 0},
219 220 221
    { 0 }
};

222 223 224 225 226 227 228 229 230 231 232 233
static const struct message monthcal_todaylink_seq[] = {
    { MCM_HITTEST, sent|wparam, 0},
    { MCM_SETTODAY, sent|wparam, 0},
    { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
    { MCM_GETTODAY, sent|wparam, 0},
    { WM_LBUTTONDOWN, sent|wparam|lparam, MK_LBUTTON, MAKELONG(70, 370)},
    { WM_CAPTURECHANGED, sent|wparam|lparam|defwinproc, 0, 0},
    { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
    { MCM_GETCURSEL, sent|wparam, 0},
    { 0 }
};

234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
static const struct message monthcal_today_seq[] = {
    { MCM_SETTODAY, sent|wparam, 0},
    { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
    { MCM_GETTODAY, sent|wparam, 0},
    { MCM_SETTODAY, sent|wparam, 0},
    { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
    { MCM_GETTODAY, sent|wparam, 0},
    { 0 }
};

static const struct message monthcal_scroll_seq[] = {
    { MCM_SETMONTHDELTA, sent|wparam|lparam, 2, 0},
    { MCM_SETMONTHDELTA, sent|wparam|lparam, 3, 0},
    { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
    { MCM_SETMONTHDELTA, sent|wparam|lparam, 12, 0},
    { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
    { MCM_SETMONTHDELTA, sent|wparam|lparam, 15, 0},
    { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
    { MCM_SETMONTHDELTA, sent|wparam|lparam, -5, 0},
    { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
    { 0 }
};

257 258 259 260 261 262
static const struct message monthcal_monthrange_seq[] = {
    { MCM_GETMONTHRANGE, sent|wparam, GMR_VISIBLE},
    { MCM_GETMONTHRANGE, sent|wparam, GMR_DAYSTATE},
    { 0 }
};

263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
static const struct message monthcal_max_sel_day_seq[] = {
    { MCM_SETMAXSELCOUNT, sent|wparam|lparam, 5, 0},
    { MCM_GETMAXSELCOUNT, sent|wparam|lparam, 0, 0},
    { MCM_SETMAXSELCOUNT, sent|wparam|lparam, 15, 0},
    { MCM_GETMAXSELCOUNT, sent|wparam|lparam, 0, 0},
    { MCM_SETMAXSELCOUNT, sent|wparam|lparam, -1, 0},
    { MCM_GETMAXSELCOUNT, sent|wparam|lparam, 0, 0},
    { 0 }
};

/* expected message sequence for parent*/
static const struct message destroy_monthcal_parent_msgs_seq[] = {
    { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY},
    { 0 }
};

/* expected message sequence for child*/
static const struct message destroy_monthcal_child_msgs_seq[] = {
281
    { 0x0090, sent|optional }, /* Vista */
282 283 284 285 286 287 288 289 290
    { WM_SHOWWINDOW, sent|wparam|lparam, 0, 0},
    { WM_WINDOWPOSCHANGING, sent|wparam, 0},
    { WM_WINDOWPOSCHANGED, sent|wparam, 0},
    { WM_DESTROY, sent|wparam|lparam, 0, 0},
    { WM_NCDESTROY, sent|wparam|lparam, 0, 0},
    { 0 }
};

static const struct message destroy_monthcal_multi_sel_style_seq[] = {
291
    { 0x0090, sent|optional }, /* Vista */
292 293 294 295 296 297 298
    { WM_DESTROY, sent|wparam|lparam, 0, 0},
    { WM_NCDESTROY, sent|wparam|lparam, 0, 0},
    { 0 }
};

/* expected message sequence for parent window*/
static const struct message destroy_parent_seq[] = {
299
    { 0x0090, sent|optional }, /* Vista */
300 301
    { WM_WINDOWPOSCHANGING, sent|wparam, 0},
    { WM_WINDOWPOSCHANGED, sent|wparam, 0},
302 303 304 305
    { WM_NCACTIVATE, sent|wparam, 0},
    { WM_ACTIVATE, sent|wparam, 0},
    { WM_NCACTIVATE, sent|wparam|lparam|optional, 0, 0},
    { WM_ACTIVATE, sent|wparam|lparam|optional, 0, 0},
306 307 308 309 310 311 312 313 314
    { WM_ACTIVATEAPP, sent|wparam, 0},
    { WM_KILLFOCUS, sent|wparam|lparam, 0, 0},
    { WM_IME_SETCONTEXT, sent|wparam|optional, 0},
    { WM_IME_NOTIFY, sent|wparam|lparam|defwinproc|optional, 1, 0},
    { WM_DESTROY, sent|wparam|lparam, 0, 0},
    { WM_NCDESTROY, sent|wparam|lparam, 0, 0},
    { 0 }
};

315
static void test_monthcal(void)
316 317
{
    HWND hwnd;
318
    SYSTEMTIME st[2], st1[2];
319
    int res, month_range;
320 321 322 323

    hwnd = CreateWindowA(MONTHCAL_CLASSA, "MonthCal", WS_POPUP | WS_VISIBLE, CW_USEDEFAULT,
                         0, 300, 300, 0, 0, NULL, NULL);
    ok(hwnd != NULL, "Failed to create MonthCal\n");
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
    GetSystemTime(&st[0]);
    st[1] = st[0];

    /* Invalid date/time */
    st[0].wYear  = 2000;
    /* Time should not matter */
    st[1].wHour = st[1].wMinute = st[1].wSecond = 70;
    ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set MAX limit\n");
    ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
    ok(st1[0].wYear != 2000, "Lover limit changed\n");

    st[1].wMonth = 0;
    ok(!SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Should have failed to set limits\n");
    ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
    ok(st1[0].wYear != 2000, "Lover limit changed\n");
    ok(!SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Should have failed to set MAX limit\n");
    ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
    ok(st1[0].wYear != 2000, "Lover limit changed\n");

343
    GetSystemTime(&st[0]);
344
    st[0].wDay = 20;
345 346 347
    st[0].wMonth = 5;
    st[1] = st[0];

348
    month_range = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
349 350
    st[1].wMonth--;
    ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
351 352
    res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
    ok(res == month_range, "Invalid month range (%d)\n", res);
353
    ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == (GDTR_MIN|GDTR_MAX), "Limits should be set\n");
354

355 356
    st[1].wMonth += 2;
    ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
357 358 359
    res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
    ok(res == month_range, "Invalid month range (%d)\n", res);

360 361 362 363 364 365 366
    st[1].wYear --;
    ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
    st[1].wYear += 1;
    ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");

    st[1].wMonth -= 3;
    ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
367
    ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "Only MAX limit should be set\n");
368 369 370 371 372 373
    st[1].wMonth += 4;
    ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
    st[1].wYear -= 3;
    ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
    st[1].wYear += 4;
    ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
374
    ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "Only MAX limit should be set\n");
375 376 377 378

    DestroyWindow(hwnd);
}

379 380
static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
381
    static LONG defwndproc_counter = 0;
382 383 384
    LRESULT ret;
    struct message msg;

385 386 387
    /* log system messages, except for painting */
    if (message < WM_USER &&
        message != WM_PAINT &&
388 389 390 391 392 393 394
        message != WM_ERASEBKGND &&
        message != WM_NCPAINT &&
        message != WM_NCHITTEST &&
        message != WM_GETTEXT &&
        message != WM_GETICON &&
        message != WM_DEVICECHANGE)
    {
395
        trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411

        msg.message = message;
        msg.flags = sent|wparam|lparam;
        if (defwndproc_counter) msg.flags |= defwinproc;
        msg.wParam = wParam;
        msg.lParam = lParam;
        add_message(sequences, PARENT_SEQ_INDEX, &msg);
    }

    defwndproc_counter++;
    ret = DefWindowProcA(hwnd, message, wParam, lParam);
    defwndproc_counter--;

    return ret;
}

412
static BOOL register_parent_wnd_class(void)
413 414 415 416 417 418 419 420 421
{
    WNDCLASSA cls;

    cls.style = 0;
    cls.lpfnWndProc = parent_wnd_proc;
    cls.cbClsExtra = 0;
    cls.cbWndExtra = 0;
    cls.hInstance = GetModuleHandleA(NULL);
    cls.hIcon = 0;
422
    cls.hCursor = LoadCursorA(0, IDC_ARROW);
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450
    cls.hbrBackground = GetStockObject(WHITE_BRUSH);
    cls.lpszMenuName = NULL;
    cls.lpszClassName = "Month-Cal test parent class";
    return RegisterClassA(&cls);
}

static HWND create_parent_window(void)
{
    HWND hwnd;

    InitCommonControls();

    /* flush message sequences, so we can check the new sequence by the end of function */
    flush_sequences(sequences, NUM_MSG_SEQUENCES);

    if (!register_parent_wnd_class())
        return NULL;

    hwnd = CreateWindowEx(0, "Month-Cal test parent class",
                          "Month-Cal test parent window",
                          WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
                          WS_MAXIMIZEBOX | WS_VISIBLE,
                          0, 0, 500, 500,
                          GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);

    assert(hwnd);

    /* check for message sequences */
451
    ok_sequence(sequences, PARENT_SEQ_INDEX, create_parent_window_seq, "create parent window", FALSE);
452 453 454 455 456 457

    return hwnd;
}

static LRESULT WINAPI monthcal_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
458
    struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
459
    static LONG defwndproc_counter = 0;
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
    LRESULT ret;
    struct message msg;

    msg.message = message;
    msg.flags = sent|wparam|lparam;
    if (defwndproc_counter) msg.flags |= defwinproc;
    msg.wParam = wParam;
    msg.lParam = lParam;
    add_message(sequences, MONTHCAL_SEQ_INDEX, &msg);

    defwndproc_counter++;
    ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
    defwndproc_counter--;

    return ret;
}

static HWND create_monthcal_control(DWORD style, HWND parent_window)
478
{
479
    struct subclass_info *info;
480 481
    HWND hwnd;

482 483 484 485
    info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
    if (!info)
        return NULL;

486 487 488 489
    hwnd = CreateWindowEx(0,
                    MONTHCAL_CLASS,
                    "",
                    style,
490
                    0, 0, 300, 400,
491 492 493 494 495 496 497 498
                    parent_window, NULL, GetModuleHandleA(NULL), NULL);

    if (!hwnd)
    {
        HeapFree(GetProcessHeap(), 0, info);
        return NULL;
    }

499 500 501
    info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
                                            (LONG_PTR)monthcal_subclass_proc);
    SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
502 503 504 505

    return hwnd;
}

506 507 508

/* Setter and Getters Tests */

509 510 511 512
static void test_monthcal_color(HWND hwnd)
{
    int res, temp;

513 514
    flush_sequences(sequences, NUM_MSG_SEQUENCES);

515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574
    /* Setter and Getters for color*/
    temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
    res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(0,0,0));
    expect(temp, res);
    temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
    expect(RGB(0,0,0), temp);
    res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(255,255,255));
    expect(temp, res);
    temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
    expect(RGB(255,255,255), temp);

    temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
    res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(0,0,0));
    expect(temp, res);
    temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
    expect(RGB(0,0,0), temp);
    res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(255,255,255));
    expect(temp, res);
    temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
    expect(RGB(255,255,255), temp);

    temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
    res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(0,0,0));
    expect(temp, res);
    temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
    expect(RGB(0,0,0), temp);
    res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(255,255,255));
    expect(temp, res);
    temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
    expect(RGB(255,255,255), temp);

    temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
    res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(0,0,0));
    expect(temp, res);
    temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
    expect(RGB(0,0,0), temp);
    res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(255,255,255));
    expect(temp, res);
    temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
    expect(RGB(255,255,255), temp);

    temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
    res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(0,0,0));
    expect(temp, res);
    temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
    expect(RGB(0,0,0), temp);
    res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(255,255,255));
    expect(temp, res);
    temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
    expect(RGB(255,255,255), temp);

    temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
    res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(0,0,0));
    expect(temp, res);
    temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
    expect(RGB(0,0,0), temp);
    res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(255,255,255));
    expect(temp, res);
    temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
    expect(RGB(255,255,255), temp);
575 576

    ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_color_seq, "monthcal color", FALSE);
577 578 579 580 581 582 583
}

static void test_monthcal_currDate(HWND hwnd)
{
    SYSTEMTIME st_original, st_new, st_test;
    int res;

584 585
    flush_sequences(sequences, NUM_MSG_SEQUENCES);

586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604
    /* Setter and Getters for current date selected */
    st_original.wYear = 2000;
    st_original.wMonth = 11;
    st_original.wDay = 28;
    st_original.wHour = 11;
    st_original.wMinute = 59;
    st_original.wSecond = 30;
    st_original.wMilliseconds = 0;
    st_original.wDayOfWeek = 0;

    st_new = st_test = st_original;

    /* Should not validate the time */
    res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
    expect(1,res);

    /* Overflow matters, check for wDay */
    st_test.wDay += 4;
    res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
605
    expect(0,res);
606 607 608 609 610 611 612 613

    /* correct wDay before checking for wMonth */
    st_test.wDay -= 4;
    expect(st_original.wDay, st_test.wDay);

    /* Overflow matters, check for wMonth */
    st_test.wMonth += 4;
    res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
614
    expect(0,res);
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629

    /* checking if gets the information right, modify st_new */
    st_new.wYear += 4;
    st_new.wMonth += 4;
    st_new.wDay += 4;
    st_new.wHour += 4;
    st_new.wMinute += 4;
    st_new.wSecond += 4;

    res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_new);
    expect(1, res);

    /* st_new change to st_origin, above settings with overflow */
    /* should not change the current settings */
    expect(st_original.wYear, st_new.wYear);
630
    expect(st_original.wMonth, st_new.wMonth);
631 632 633 634 635
    expect(st_original.wDay, st_new.wDay);
    expect(st_original.wHour, st_new.wHour);
    expect(st_original.wMinute, st_new.wMinute);
    expect(st_original.wSecond, st_new.wSecond);

636
    /* lparam cannot be NULL */
637
    res = SendMessage(hwnd, MCM_GETCURSEL, 0, 0);
638
    expect(0, res);
639 640

    ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_curr_date_seq, "monthcal currDate", TRUE);
641 642 643 644
}

static void test_monthcal_firstDay(HWND hwnd)
{
645
    int res, fday, i, prev;
646 647 648
    TCHAR b[128];
    LCID lcid = LOCALE_USER_DEFAULT;

649 650
    flush_sequences(sequences, NUM_MSG_SEQUENCES);

651
    /* Setter and Getters for first day of week */
652 653 654
    /* check for locale first day */
    if(GetLocaleInfo(lcid, LOCALE_IFIRSTDAYOFWEEK, b, 128)){
        fday = atoi(b);
655
        trace("fday: %d\n", fday);
656 657 658
        res = SendMessage(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
        expect(fday, res);
        prev = fday;
659

660 661 662
        /* checking for the values that actually will be stored as */
        /* current first day when we set a new value */
        for (i = -5; i < 12; i++){
663
            res = SendMessage(hwnd, MCM_SETFIRSTDAYOFWEEK, 0, (LPARAM) i);
664 665 666 667 668 669 670
            expect(prev, res);
            res = SendMessage(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
            prev = res;

            if (i == -1){
                expect(MAKELONG(fday, FALSE), res);
            }else if (i >= 7){
671 672
                /* out of range sets max first day of week, locale is ignored */
                expect(MAKELONG(6, TRUE), res);
673 674 675
            }else{
                expect(MAKELONG(i, TRUE), res);
            }
676 677
        }

678 679 680 681
        ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_first_day_seq, "monthcal firstDay", FALSE);

    }else{
        skip("Cannot retrieve first day of the week\n");
682
    }
683

684 685 686 687 688 689
}

static void test_monthcal_unicode(HWND hwnd)
{
    int res, temp;

690 691
    flush_sequences(sequences, NUM_MSG_SEQUENCES);

692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
    /* Setter and Getters for Unicode format */

    /* getting the current settings */
    temp = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);

    /* setting to 1, should return previous settings */
    res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 1, 0);
    expect(temp, res);

    /* current setting is 1, so, should return 1 */
    res = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
    todo_wine {expect(1, res);}

    /* setting to 0, should return previous settings */
    res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 0, 0);
    todo_wine {expect(1, res);}

    /* current setting is 0, so, it should return 0 */
    res = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
    expect(0, res);

    /* should return previous settings */
    res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 1, 0);
    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
    UINT res;
724
    SYSTEMTIME st;
725 726 727 728 729 730
    LONG x;
    UINT title_index;
    static const UINT title_hits[] =
        { MCHT_NOWHERE, MCHT_TITLEBK, MCHT_TITLEBTNPREV, MCHT_TITLEBK,
          MCHT_TITLEMONTH, MCHT_TITLEBK, MCHT_TITLEYEAR, MCHT_TITLEBK,
          MCHT_TITLEBTNNEXT, MCHT_TITLEBK, MCHT_NOWHERE };
731 732 733

    memset(&mchit, 0, sizeof(MCHITTESTINFO));

734 735
    flush_sequences(sequences, NUM_MSG_SEQUENCES);

736 737 738 739 740 741 742 743 744 745 746 747
    st.wYear = 2007;
    st.wMonth = 4;
    st.wDay = 11;
    st.wHour = 1;
    st.wMinute = 0;
    st.wSecond = 0;
    st.wMilliseconds = 0;
    st.wDayOfWeek = 0;

    res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st);
    expect(1,res);

748 749 750 751 752 753 754 755 756 757
    /* (0, 0) is the top left of the control and should not be active */
    mchit.cbSize = sizeof(MCHITTESTINFO);
    mchit.pt.x = 0;
    mchit.pt.y = 0;
    res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
    expect(0, mchit.pt.x);
    expect(0, mchit.pt.y);
    expect(mchit.uHit, res);
    todo_wine {expect(MCHT_NOWHERE, res);}

758
    /* (300, 400) is the bottom right of the control and should not be active */
759
    mchit.pt.x = 300;
760
    mchit.pt.y = 400;
761 762
    res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
    expect(300, mchit.pt.x);
763
    expect(400, mchit.pt.y);
764 765 766 767 768 769 770 771 772 773 774 775
    expect(mchit.uHit, res);
    todo_wine {expect(MCHT_NOWHERE, res);}

    /* (500, 500) is completely out of the control and should not be active */
    mchit.pt.x = 500;
    mchit.pt.y = 500;
    res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
    expect(500, mchit.pt.x);
    expect(500, mchit.pt.y);
    expect(mchit.uHit, res);
    todo_wine {expect(MCHT_NOWHERE, res);}

776 777 778
    /* (120, 180) is in active area - calendar background */
    mchit.pt.x = 120;
    mchit.pt.y = 180;
779
    res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
780 781
    expect(120, mchit.pt.x);
    expect(180, mchit.pt.y);
782
    expect(mchit.uHit, res);
783 784
    expect(MCHT_CALENDARBK, res);

785
    /* (70, 70) is in active area - day of the week */
786
    mchit.pt.x = 70;
787
    mchit.pt.y = 70;
788 789
    res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
    expect(70, mchit.pt.x);
790
    expect(70, mchit.pt.y);
791 792 793
    expect(mchit.uHit, res);
    todo_wine {expect(MCHT_CALENDARDAY, res);}

794
    /* (70, 90) is in active area - date from prev month */
795
    mchit.pt.x = 70;
796
    mchit.pt.y = 90;
797 798
    res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
    expect(70, mchit.pt.x);
799
    expect(90, mchit.pt.y);
800 801 802
    expect(mchit.uHit, res);
    todo_wine {expect(MCHT_CALENDARDATEPREV, res);}

803
#if 0
804 805 806 807 808 809 810
    /* (125, 115) is in active area - date from this month */
    mchit.pt.x = 125;
    mchit.pt.y = 115;
    res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
    expect(125, mchit.pt.x);
    expect(115, mchit.pt.y);
    expect(mchit.uHit, res);
811 812
    expect(MCHT_CALENDARDATE, res);
#endif
813

814
    /* (80, 220) is in active area - background section of the title */
815
    mchit.pt.x = 80;
816
    mchit.pt.y = 220;
817 818
    res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
    expect(80, mchit.pt.x);
819
    expect(220, mchit.pt.y);
820 821 822
    expect(mchit.uHit, res);
    todo_wine {expect(MCHT_TITLEBK, res);}

823 824 825
    /* (140, 215) is in active area - month section of the title */
    mchit.pt.x = 140;
    mchit.pt.y = 215;
826
    res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
827 828
    expect(140, mchit.pt.x);
    expect(215, mchit.pt.y);
829 830 831
    expect(mchit.uHit, res);
    todo_wine {expect(MCHT_TITLEMONTH, res);}

832
    /* (170, 215) is in active area - year section of the title */
833
    mchit.pt.x = 170;
834
    mchit.pt.y = 215;
835 836
    res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
    expect(170, mchit.pt.x);
837
    expect(215, mchit.pt.y);
838 839 840
    expect(mchit.uHit, res);
    todo_wine {expect(MCHT_TITLEYEAR, res);}

841
    /* (150, 260) is in active area - date from this month */
842
    mchit.pt.x = 150;
843
    mchit.pt.y = 260;
844 845
    res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
    expect(150, mchit.pt.x);
846
    expect(260, mchit.pt.y);
847 848 849
    expect(mchit.uHit, res);
    todo_wine {expect(MCHT_CALENDARDATE, res);}

850
    /* (150, 350) is in active area - date from next month */
851
    mchit.pt.x = 150;
852
    mchit.pt.y = 350;
853 854
    res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
    expect(150, mchit.pt.x);
855
    expect(350, mchit.pt.y);
856 857 858
    expect(mchit.uHit, res);
    todo_wine {expect(MCHT_CALENDARDATENEXT, res);}

859
    /* (150, 370) is in active area - today link */
860
    mchit.pt.x = 150;
861
    mchit.pt.y = 370;
862 863
    res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
    expect(150, mchit.pt.x);
864
    expect(370, mchit.pt.y);
865 866 867
    expect(mchit.uHit, res);
    todo_wine {expect(MCHT_TODAYLINK, res);}

868
    /* (70, 370) is in active area - today link */
869
    mchit.pt.x = 70;
870
    mchit.pt.y = 370;
871 872
    res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
    expect(70, mchit.pt.x);
873
    expect(370, mchit.pt.y);
874 875
    expect(mchit.uHit, res);
    todo_wine {expect(MCHT_TODAYLINK, res);}
876

877
    ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_hit_test_seq, "monthcal hit test", TRUE);
878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898

    /* The horizontal position of title bar elements depends on locale (y pos
       is constant), so we sample across a horizontal line and make sure we
       find all elements. */
    mchit.pt.y = 40;
    title_index = 0;
    for (x = 0; x < 300; x++){
        mchit.pt.x = x;
        res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
        expect(x, mchit.pt.x);
        expect(40, mchit.pt.y);
        expect(mchit.uHit, res);
        if (res != title_hits[title_index]){
            title_index++;
            if (sizeof(title_hits) / sizeof(title_hits[0]) <= title_index)
                break;
            todo_wine {expect(title_hits[title_index], res);}
        }
    }
    todo_wine {ok(300 <= x && title_index + 1 == sizeof(title_hits) / sizeof(title_hits[0]),
        "Wrong title layout\n");}
899 900
}

901 902 903 904 905
static void test_monthcal_todaylink(HWND hwnd)
{
    MCHITTESTINFO mchit;
    SYSTEMTIME st_test, st_new;
    BOOL error = FALSE;
906
    UINT res;
907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958

    memset(&mchit, 0, sizeof(MCHITTESTINFO));

    flush_sequences(sequences, NUM_MSG_SEQUENCES);

    /* (70, 370) is in active area - today link */
    mchit.cbSize = sizeof(MCHITTESTINFO);
    mchit.pt.x = 70;
    mchit.pt.y = 370;
    res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
    expect(70, mchit.pt.x);
    expect(370, mchit.pt.y);
    expect(mchit.uHit, res);
    todo_wine {expect(MCHT_TODAYLINK, res);}
    if (70 != mchit.pt.x || 370 != mchit.pt.y || mchit.uHit != res
        || MCHT_TODAYLINK != res)
        error = TRUE;

    st_test.wDay = 1;
    st_test.wMonth = 1;
    st_test.wYear = 2005;
    memset(&st_new, 0, sizeof(SYSTEMTIME));

    SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);

    res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
    expect(1, res);
    expect(1, st_new.wDay);
    expect(1, st_new.wMonth);
    expect(2005, st_new.wYear);
    if (1 != res || 1 != st_new.wDay || 1 != st_new.wMonth
        || 2005 != st_new.wYear)
        error = TRUE;

    if (error) {
        skip("cannot perform today link test\n");
        return;
    }

    res = SendMessage(hwnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELONG(70, 370));
    expect(0, res);

    memset(&st_new, 0, sizeof(SYSTEMTIME));
    res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_new);
    expect(1, res);
    expect(1, st_new.wDay);
    expect(1, st_new.wMonth);
    expect(2005, st_new.wYear);

    ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_todaylink_seq, "monthcal hit test", TRUE);
}

959 960 961 962 963
static void test_monthcal_today(HWND hwnd)
{
    SYSTEMTIME st_test, st_new;
    int res;

964 965
    flush_sequences(sequences, NUM_MSG_SEQUENCES);

966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003
    /* Setter and Getters for "today" information */

    /* check for overflow, should be ok */
    st_test.wDay = 38;
    st_test.wMonth = 38;

    st_new.wDay = 27;
    st_new.wMonth = 27;

    SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);

    res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
    expect(1, res);

    /* st_test should not change */
    expect(38, st_test.wDay);
    expect(38, st_test.wMonth);

    /* st_new should change, overflow does not matter */
    expect(38, st_new.wDay);
    expect(38, st_new.wMonth);

    /* check for zero, should be ok*/
    st_test.wDay = 0;
    st_test.wMonth = 0;

    SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);

    res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
    expect(1, res);

    /* st_test should not change */
    expect(0, st_test.wDay);
    expect(0, st_test.wMonth);

    /* st_new should change to zero*/
    expect(0, st_new.wDay);
    expect(0, st_new.wMonth);
1004 1005

    ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_today_seq, "monthcal today", TRUE);
1006 1007 1008 1009 1010 1011
}

static void test_monthcal_scroll(HWND hwnd)
{
    int res;

1012 1013
    flush_sequences(sequences, NUM_MSG_SEQUENCES);

1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036
    /* Setter and Getters for scroll rate */
    res = SendMessage(hwnd, MCM_SETMONTHDELTA, 2, 0);
    expect(0, res);

    res = SendMessage(hwnd, MCM_SETMONTHDELTA, 3, 0);
    expect(2, res);
    res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
    expect(3, res);

    res = SendMessage(hwnd, MCM_SETMONTHDELTA, 12, 0);
    expect(3, res);
    res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
    expect(12, res);

    res = SendMessage(hwnd, MCM_SETMONTHDELTA, 15, 0);
    expect(12, res);
    res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
    expect(15, res);

    res = SendMessage(hwnd, MCM_SETMONTHDELTA, -5, 0);
    expect(15, res);
    res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
    expect(-5, res);
1037 1038

    ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_scroll_seq, "monthcal scroll", FALSE);
1039 1040
}

1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075
static void test_monthcal_monthrange(HWND hwnd)
{
    int res;
    SYSTEMTIME st_visible[2], st_daystate[2];

    flush_sequences(sequences, NUM_MSG_SEQUENCES);
    st_visible[0].wYear = 0;
    st_visible[0].wMonth = 0;
    st_visible[0].wDay = 0;
    st_daystate[1] = st_daystate[0] = st_visible[1] = st_visible[0];

    res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st_visible);
    todo_wine {
        expect(2, res);
        expect(2000, st_visible[0].wYear);
        expect(11, st_visible[0].wMonth);
        expect(1, st_visible[0].wDay);
        expect(2000, st_visible[1].wYear);
        expect(12, st_visible[1].wMonth);
        expect(31, st_visible[1].wDay);
    }
    res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, (LPARAM)st_daystate);
    todo_wine {
        expect(4, res);
        expect(2000, st_daystate[0].wYear);
        expect(10, st_daystate[0].wMonth);
        expect(29, st_daystate[0].wDay);
        expect(2001, st_daystate[1].wYear);
        expect(1, st_daystate[1].wMonth);
        expect(6, st_daystate[1].wDay);
    }

    ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_monthrange_seq, "monthcal monthrange", FALSE);
}

1076 1077 1078 1079
static void test_monthcal_MaxSelDay(HWND hwnd)
{
    int res;

1080 1081
    flush_sequences(sequences, NUM_MSG_SEQUENCES);

1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096
    /* Setter and Getters for max selected days */
    res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 5, 0);
    expect(1, res);
    res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
    expect(5, res);

    res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 15, 0);
    expect(1, res);
    res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
    expect(15, res);

    res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, -1, 0);
    todo_wine {expect(0, res);}
    res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
    todo_wine {expect(15, res);}
1097 1098

    ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_max_sel_day_seq, "monthcal MaxSelDay", FALSE);
1099 1100
}

1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128
static void test_monthcal_size(HWND hwnd)
{
    int res;
    RECT r1, r2;
    HFONT hFont1, hFont2;
    LOGFONTA logfont;

    lstrcpyA(logfont.lfFaceName, "Arial");
    memset(&logfont, 0, sizeof(logfont));
    logfont.lfHeight = 12;
    hFont1 = CreateFontIndirectA(&logfont);

    logfont.lfHeight = 24;
    hFont2 = CreateFontIndirectA(&logfont);

    /* initialize to a font we can compare against */
    SendMessage(hwnd, WM_SETFONT, (WPARAM)hFont1, 0);
    res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r1);

    /* check that setting a larger font results in an larger rect */
    SendMessage(hwnd, WM_SETFONT, (WPARAM)hFont2, 0);
    res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r2);

    OffsetRect(&r1, -r1.left, -r1.top);
    OffsetRect(&r2, -r2.left, -r2.top);

    ok(r1.bottom < r2.bottom, "Failed to get larger rect with larger font\n");
}
1129

1130 1131
START_TEST(monthcal)
{
1132 1133 1134
    HMODULE hComctl32;
    BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
    INITCOMMONCONTROLSEX iccex;
1135
    HWND hwnd, parent_wnd;
1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147

    hComctl32 = GetModuleHandleA("comctl32.dll");
    pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
    if (!pInitCommonControlsEx)
    {
        skip("InitCommonControlsEx() is missing. Skipping the tests\n");
        return;
    }
    iccex.dwSize = sizeof(iccex);
    iccex.dwICC  = ICC_DATE_CLASSES;
    pInitCommonControlsEx(&iccex);

1148
    test_monthcal();
1149

1150 1151 1152 1153 1154 1155 1156 1157 1158
    init_msg_sequences(sequences, NUM_MSG_SEQUENCES);

    parent_wnd = create_parent_window();

    flush_sequences(sequences, NUM_MSG_SEQUENCES);
    hwnd = create_monthcal_control(WS_CHILD | WS_BORDER | WS_VISIBLE, parent_wnd);
    assert(hwnd);
    ok_sequence(sequences, PARENT_SEQ_INDEX, create_monthcal_control_seq, "create monthcal control", TRUE);

1159 1160
    SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(SYSTEM_FONT), 0);

1161 1162 1163 1164 1165 1166
    test_monthcal_color(hwnd);
    test_monthcal_currDate(hwnd);
    test_monthcal_firstDay(hwnd);
    test_monthcal_unicode(hwnd);
    test_monthcal_today(hwnd);
    test_monthcal_scroll(hwnd);
1167
    test_monthcal_monthrange(hwnd);
1168
    test_monthcal_HitTest(hwnd);
1169
    test_monthcal_todaylink(hwnd);
1170
    test_monthcal_size(hwnd);
1171

1172
    flush_sequences(sequences, NUM_MSG_SEQUENCES);
1173
    DestroyWindow(hwnd);
1174 1175 1176 1177 1178 1179 1180
    ok_sequence(sequences, PARENT_SEQ_INDEX, destroy_monthcal_parent_msgs_seq, "Destroy monthcal (parent msg)", FALSE);
    ok_sequence(sequences, MONTHCAL_SEQ_INDEX, destroy_monthcal_child_msgs_seq, "Destroy monthcal (child msg)", FALSE);

    flush_sequences(sequences, NUM_MSG_SEQUENCES);
    hwnd = create_monthcal_control(MCS_MULTISELECT, parent_wnd);
    assert(hwnd);
    ok_sequence(sequences, PARENT_SEQ_INDEX, create_monthcal_multi_sel_style_seq, "create monthcal (multi sel style)", TRUE);
1181 1182 1183

    test_monthcal_MaxSelDay(hwnd);

1184
    flush_sequences(sequences, NUM_MSG_SEQUENCES);
1185
    DestroyWindow(hwnd);
1186 1187 1188 1189 1190
    ok_sequence(sequences, MONTHCAL_SEQ_INDEX, destroy_monthcal_multi_sel_style_seq, "Destroy monthcal (multi sel style)", FALSE);

    flush_sequences(sequences, NUM_MSG_SEQUENCES);
    DestroyWindow(parent_wnd);
    ok_sequence(sequences, PARENT_SEQ_INDEX, destroy_parent_seq, "Destroy parent window", FALSE);
1191
}