1 /* Unit test suite for datetime control.
3 * Copyright 2007 Kanit Therdsteerasukdi
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/test.h"
25 #define expect(EXPECTED, GOT) ok((GOT)==(EXPECTED), "Expected %d, got %ld\n", (EXPECTED), (GOT))
27 #define expect_unsuccess(EXPECTED, GOT) ok((GOT)==(EXPECTED), "Expected %d(unsuccessful), got %ld(successful)\n", (EXPECTED), (GOT))
29 static HWND create_datetime_control(DWORD style, DWORD exstyle)
31 HWND hWndDateTime = NULL;
33 hWndDateTime = CreateWindowEx(0,
46 static void test_dtm_set_format(HWND hWndDateTime)
51 r = SendMessage(hWndDateTime, DTM_SETFORMAT, 0, (LPARAM)NULL);
54 r = SendMessage(hWndDateTime, DTM_SETFORMAT, 0,
55 (LPARAM)"'Today is: 'hh':'m':'s dddd MMM dd', 'yyyy");
60 void test_mccolor_types(HWND hWndDateTime, int mccolor_type, const char* mccolor_name)
63 COLORREF theColor, prevColor;
66 r = SendMessage(hWndDateTime, DTM_SETMCCOLOR, mccolor_type, theColor);
67 ok(r != -1, "%s: Set RGB(0,0,0): Expected COLORREF of previous value, got %ld\n", mccolor_name, r);
69 theColor=RGB(255,255,255);
70 r = SendMessage(hWndDateTime, DTM_SETMCCOLOR, mccolor_type, theColor);
71 ok(r==prevColor, "%s: Set RGB(255,255,255): Expected COLORREF of previous value, got %ld\n", mccolor_name, r);
73 theColor=RGB(100,180,220);
74 r = SendMessage(hWndDateTime, DTM_SETMCCOLOR, mccolor_type, theColor);
75 ok(r==prevColor, "%s: Set RGB(100,180,220): Expected COLORREF of previous value, got %ld\n", mccolor_name, r);
76 r = SendMessage(hWndDateTime, DTM_GETMCCOLOR, mccolor_type, 0);
77 ok(r==theColor, "%s: GETMCCOLOR: Expected %d, got %ld\n", mccolor_name, theColor, r);
80 static void test_dtm_set_and_get_mccolor(HWND hWndDateTime)
82 test_mccolor_types(hWndDateTime, MCSC_BACKGROUND, "MCSC_BACKGROUND");
83 test_mccolor_types(hWndDateTime, MCSC_MONTHBK, "MCSC_MONTHBK");
84 test_mccolor_types(hWndDateTime, MCSC_TEXT, "MCSC_TEXT");
85 test_mccolor_types(hWndDateTime, MCSC_TITLEBK, "MCSC_TITLEBK");
86 test_mccolor_types(hWndDateTime, MCSC_TITLETEXT, "MCSC_TITLETEXT");
87 test_mccolor_types(hWndDateTime, MCSC_TRAILINGTEXT, "MCSC_TRAILINGTEXT");
90 static void test_dtm_set_and_get_mcfont(HWND hWndDateTime)
92 HFONT hFontOrig, hFontNew;
94 hFontOrig = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
95 SendMessage(hWndDateTime, DTM_SETMCFONT, (WPARAM)hFontOrig, TRUE);
96 hFontNew = (HFONT)SendMessage(hWndDateTime, DTM_GETMCFONT, 0, 0);
97 ok(hFontOrig == hFontNew, "Expected hFontOrig==hFontNew, hFontOrig=%p, hFontNew=%p\n", hFontOrig, hFontNew);
100 static void test_dtm_get_monthcal(HWND hWndDateTime)
105 r = SendMessage(hWndDateTime, DTM_GETMONTHCAL, 0, 0);
106 ok(r == (LPARAM)NULL, "Expected NULL(no child month calendar control), got %ld\n", r);
110 void fill_systime_struct(SYSTEMTIME *st, int year, int month, int dayofweek, int day, int hour, int minute, int second, int milliseconds)
114 st->wDayOfWeek = dayofweek;
117 st->wMinute = minute;
118 st->wSecond = second;
119 st->wMilliseconds = milliseconds;
122 LPARAM compare_systime_date(SYSTEMTIME *st1, SYSTEMTIME *st2)
124 return (st1->wYear == st2->wYear)
125 && (st1->wMonth == st2->wMonth)
126 && (st1->wDayOfWeek == st2->wDayOfWeek)
127 && (st1->wDay == st2->wDay);
130 LPARAM compare_systime_time(SYSTEMTIME *st1, SYSTEMTIME *st2)
132 return (st1->wHour == st2->wHour)
133 && (st1->wMinute == st2->wMinute)
134 && (st1->wSecond == st2->wSecond)
135 && (st1->wMilliseconds == st2->wMilliseconds);
138 LPARAM compare_systime(SYSTEMTIME *st1, SYSTEMTIME *st2)
140 if(!compare_systime_date(st1, st2))
143 return compare_systime_time(st1, st2);
146 #define expect_systime(ST1, ST2) ok(compare_systime((ST1), (ST2))==1, "ST1 != ST2\n")
147 #define expect_systime_date(ST1, ST2) ok(compare_systime_date((ST1), (ST2))==1, "ST1.date != ST2.date\n")
148 #define expect_systime_time(ST1, ST2) ok(compare_systime_time((ST1), (ST2))==1, "ST1.time != ST2.time\n")
150 static void test_dtm_set_and_get_range(HWND hWndDateTime)
156 /* initialize st[0] to lowest possible value */
157 fill_systime_struct(&st[0], 1601, 1, 0, 1, 0, 0, 0, 0);
158 /* intialize st[1] to all invalid numbers */
159 fill_systime_struct(&st[1], 0, 0, 7, 0, 24, 60, 60, 1000);
161 r = SendMessage(hWndDateTime, DTM_SETRANGE, GDTR_MIN, (LPARAM)st);
163 r = SendMessage(hWndDateTime, DTM_GETRANGE, 0, (LPARAM)getSt);
164 ok(r == GDTR_MIN, "Expected %x, not %x(GDTR_MAX) or %x(GDTR_MIN | GDTR_MAX), got %lx\n", GDTR_MIN, GDTR_MAX, GDTR_MIN | GDTR_MAX, r);
165 expect_systime(&st[0], &getSt[0]);
167 r = SendMessage(hWndDateTime, DTM_SETRANGE, GDTR_MAX, (LPARAM)st);
168 expect_unsuccess(0, r);
170 /* set st[0] to all invalid numbers */
171 fill_systime_struct(&st[0], 0, 0, 7, 0, 24, 60, 60, 1000);
172 /* set st[1] to highest possible value */
173 fill_systime_struct(&st[1], 30827, 12, 6, 31, 23, 59, 59, 999);
175 r = SendMessage(hWndDateTime, DTM_SETRANGE, GDTR_MAX, (LPARAM)st);
177 r = SendMessage(hWndDateTime, DTM_GETRANGE, 0, (LPARAM)getSt);
179 ok(r == GDTR_MAX, "Expected %x, not %x(GDTR_MIN) or %x(GDTR_MIN | GDTR_MAX), got %lx\n", GDTR_MAX, GDTR_MIN, GDTR_MIN | GDTR_MAX, r);
181 expect_systime(&st[1], &getSt[1]);
183 r = SendMessage(hWndDateTime, DTM_SETRANGE, GDTR_MIN, (LPARAM)st);
184 expect_unsuccess(0, r);
185 r = SendMessage(hWndDateTime, DTM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st);
186 expect_unsuccess(0, r);
188 /* set st[0] to highest possible value */
189 fill_systime_struct(&st[0], 30827, 12, 6, 31, 23, 59, 59, 999);
191 r = SendMessage(hWndDateTime, DTM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st);
193 r = SendMessage(hWndDateTime, DTM_GETRANGE, 0, (LPARAM)getSt);
194 ok(r == (GDTR_MIN | GDTR_MAX), "Expected %x, not %x(GDTR_MIN) or %x(GDTR_MAX), got %lx\n", (GDTR_MIN | GDTR_MAX), GDTR_MIN, GDTR_MAX, r);
195 expect_systime(&st[0], &getSt[0]);
196 expect_systime(&st[1], &getSt[1]);
198 /* initialize st[0] to lowest possible value */
199 fill_systime_struct(&st[0], 1601, 1, 0, 1, 0, 0, 0, 0);
200 /* set st[1] to highest possible value */
201 fill_systime_struct(&st[1], 30827, 12, 6, 31, 23, 59, 59, 999);
203 r = SendMessage(hWndDateTime, DTM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st);
205 r = SendMessage(hWndDateTime, DTM_GETRANGE, 0, (LPARAM)getSt);
206 ok(r == (GDTR_MIN | GDTR_MAX), "Expected %x, not %x(GDTR_MIN) or %x(GDTR_MAX), got %lx\n", (GDTR_MIN | GDTR_MAX), GDTR_MIN, GDTR_MAX, r);
207 expect_systime(&st[0], &getSt[0]);
208 expect_systime(&st[1], &getSt[1]);
210 /* set st[0] to value higher than minimum */
211 fill_systime_struct(&st[0], 1980, 1, 3, 23, 14, 34, 37, 465);
212 /* set st[1] to value lower than maximum */
213 fill_systime_struct(&st[1], 2007, 3, 2, 31, 23, 59, 59, 999);
215 r = SendMessage(hWndDateTime, DTM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st);
217 r = SendMessage(hWndDateTime, DTM_GETRANGE, 0, (LPARAM)getSt);
218 ok(r == (GDTR_MIN | GDTR_MAX), "Expected %x, not %x(GDTR_MIN) or %x(GDTR_MAX), got %lx\n", (GDTR_MIN | GDTR_MAX), GDTR_MIN, GDTR_MAX, r);
219 expect_systime(&st[0], &getSt[0]);
220 expect_systime(&st[1], &getSt[1]);
223 /* when max<min for DTM_SETRANGE, Windows seems to swap the min and max values,
224 although that's undocumented. However, it doesn't seem to be implemented
225 correctly, causing some strange side effects */
226 static void test_dtm_set_range_swap_min_max(HWND hWndDateTime)
233 fill_systime_struct(&st[0], 2007, 2, 4, 15, 2, 2, 2, 2);
235 r = SendMessage(hWndDateTime, DTM_SETSYSTEMTIME, GDT_VALID, (LPARAM)&st[0]);
237 r = SendMessage(hWndDateTime, DTM_GETSYSTEMTIME, 0, (LPARAM)&origSt);
238 ok(r == GDT_VALID, "Expected %d, not %d(GDT_NONE) or %d(GDT_ERROR), got %ld\n", GDT_VALID, GDT_NONE, GDT_ERROR, r);
239 expect_systime(&st[0], &origSt);
241 /* set st[0] to value higher than st[1] */
242 fill_systime_struct(&st[0], 2007, 3, 2, 31, 23, 59, 59, 999);
243 fill_systime_struct(&st[1], 1980, 1, 3, 23, 14, 34, 37, 465);
245 /* since min>max, min and max values should be swapped by DTM_SETRANGE
247 r = SendMessage(hWndDateTime, DTM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st);
249 r = SendMessage(hWndDateTime, DTM_GETRANGE, 0, (LPARAM)getSt);
250 ok(r == (GDTR_MIN | GDTR_MAX), "Expected %x, not %x(GDTR_MIN) or %x(GDTR_MAX), got %lx\n", (GDTR_MIN | GDTR_MAX), GDTR_MIN, GDTR_MAX, r);
252 expect_systime(&st[0], &getSt[0]);
255 expect_systime(&st[1], &getSt[1]);
258 fill_systime_struct(&st[0], 1980, 1, 3, 23, 14, 34, 37, 465);
260 r = SendMessage(hWndDateTime, DTM_SETSYSTEMTIME, GDT_VALID, (LPARAM)&st[0]);
262 r = SendMessage(hWndDateTime, DTM_GETSYSTEMTIME, 0, (LPARAM)&getSt[0]);
263 ok(r == GDT_VALID, "Expected %d, not %d(GDT_NONE) or %d(GDT_ERROR), got %ld\n", GDT_VALID, GDT_NONE, GDT_ERROR, r);
264 /* the time part seems to not change after swapping the min and max values
265 and doing DTM_SETSYSTEMTIME */
266 expect_systime_date(&st[0], &getSt[0]);
268 expect_systime_time(&origSt, &getSt[0]);
271 /* set st[0] to value higher than minimum */
272 fill_systime_struct(&st[0], 1980, 1, 3, 23, 14, 34, 37, 465);
273 /* set st[1] to value lower than maximum */
274 fill_systime_struct(&st[1], 2007, 3, 2, 31, 23, 59, 59, 999);
276 r = SendMessage(hWndDateTime, DTM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st);
278 /* for some reason after we swapped the min and max values before,
279 whenever we do a DTM_SETRANGE, the DTM_GETRANGE will return the values
281 r = SendMessage(hWndDateTime, DTM_GETRANGE, 0, (LPARAM)getSt);
282 ok(r == (GDTR_MIN | GDTR_MAX), "Expected %x, not %x(GDTR_MIN) or %x(GDTR_MAX), got %lx\n", (GDTR_MIN | GDTR_MAX), GDTR_MIN, GDTR_MAX, r);
284 expect_systime(&st[0], &getSt[1]);
287 expect_systime(&st[1], &getSt[0]);
290 /* set st[0] to value higher than st[1] */
291 fill_systime_struct(&st[0], 2007, 3, 2, 31, 23, 59, 59, 999);
292 fill_systime_struct(&st[1], 1980, 1, 3, 23, 14, 34, 37, 465);
294 /* set min>max again, so that the return values of DTM_GETRANGE are no
295 longer swapped the next time we do a DTM SETRANGE and DTM_GETRANGE*/
296 r = SendMessage(hWndDateTime, DTM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st);
298 r = SendMessage(hWndDateTime, DTM_GETRANGE, 0, (LPARAM)getSt);
299 ok(r == (GDTR_MIN | GDTR_MAX), "Expected %x, not %x(GDTR_MIN) or %x(GDTR_MAX), got %lx\n", (GDTR_MIN | GDTR_MAX), GDTR_MIN, GDTR_MAX, r);
300 expect_systime(&st[0], &getSt[1]);
301 expect_systime(&st[1], &getSt[0]);
303 /* initialize st[0] to lowest possible value */
304 fill_systime_struct(&st[0], 1601, 1, 0, 1, 0, 0, 0, 0);
305 /* set st[1] to highest possible value */
306 fill_systime_struct(&st[1], 30827, 12, 6, 31, 23, 59, 59, 999);
308 r = SendMessage(hWndDateTime, DTM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st);
310 r = SendMessage(hWndDateTime, DTM_GETRANGE, 0, (LPARAM)getSt);
311 ok(r == (GDTR_MIN | GDTR_MAX), "Expected %x, not %x(GDTR_MIN) or %x(GDTR_MAX), got %lx\n", (GDTR_MIN | GDTR_MAX), GDTR_MIN, GDTR_MAX, r);
312 expect_systime(&st[0], &getSt[0]);
313 expect_systime(&st[1], &getSt[1]);
316 static void test_dtm_set_and_get_system_time(HWND hWndDateTime)
322 r = SendMessage(hWndDateTime, DTM_SETSYSTEMTIME, GDT_NONE, (LPARAM)&st);
324 r = SendMessage(hWndDateTime, DTM_GETSYSTEMTIME, 0, (LPARAM)&getSt);
325 ok(r == GDT_NONE, "Expected %d, not %d(GDT_VALID) or %d(GDT_ERROR), got %ld\n", GDT_NONE, GDT_VALID, GDT_ERROR, r);
327 /* set st to lowest possible value */
328 fill_systime_struct(&st, 1601, 1, 0, 1, 0, 0, 0, 0);
330 r = SendMessage(hWndDateTime, DTM_SETSYSTEMTIME, GDT_VALID, (LPARAM)&st);
333 /* set st to highest possible value */
334 fill_systime_struct(&st, 30827, 12, 6, 31, 23, 59, 59, 999);
336 r = SendMessage(hWndDateTime, DTM_SETSYSTEMTIME, GDT_VALID, (LPARAM)&st);
339 /* set st to value between min and max */
340 fill_systime_struct(&st, 1980, 1, 3, 23, 14, 34, 37, 465);
342 r = SendMessage(hWndDateTime, DTM_SETSYSTEMTIME, GDT_VALID, (LPARAM)&st);
344 r = SendMessage(hWndDateTime, DTM_GETSYSTEMTIME, 0, (LPARAM)&getSt);
345 ok(r == GDT_VALID, "Expected %d, not %d(GDT_NONE) or %d(GDT_ERROR), got %ld\n", GDT_VALID, GDT_NONE, GDT_ERROR, r);
346 expect_systime(&st, &getSt);
348 /* set st to invalid value */
349 fill_systime_struct(&st, 0, 0, 7, 0, 24, 60, 60, 1000);
352 r = SendMessage(hWndDateTime, DTM_SETSYSTEMTIME, GDT_VALID, (LPARAM)&st);
353 expect_unsuccess(0, r);
357 static void test_datetime_control(void)
361 hWndDateTime = create_datetime_control(DTS_SHOWNONE, 0);
363 ok(hWndDateTime != NULL, "Expected non NULL, got %p\n", hWndDateTime);
364 if(hWndDateTime!=NULL) {
365 test_dtm_set_format(hWndDateTime);
366 test_dtm_set_and_get_mccolor(hWndDateTime);
367 test_dtm_set_and_get_mcfont(hWndDateTime);
368 test_dtm_get_monthcal(hWndDateTime);
369 test_dtm_set_and_get_range(hWndDateTime);
370 test_dtm_set_range_swap_min_max(hWndDateTime);
371 test_dtm_set_and_get_system_time(hWndDateTime);
374 skip("hWndDateTime is NULL\n");
377 DestroyWindow(hWndDateTime);
382 INITCOMMONCONTROLSEX icex;
384 icex.dwSize = sizeof(icex);
385 icex.dwICC = ICC_DATE_CLASSES;
386 InitCommonControlsEx(&icex);
388 test_datetime_control();