[KERNEL32_APITEST] JapaneseCalendar must work even if not codepage 932"
[reactos.git] / modules / rostests / apitests / kernel32 / JapaneseCalendar.c
1 /*
2 * Japanese Calendar Testcase
3 *
4 * Copyright 2019 Katayama Hirofumi MZ
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include "precomp.h"
22
23 #ifndef CAL_SABBREVERASTRING
24 #define CAL_SABBREVERASTRING 0x00000039
25 #endif
26
27 START_TEST(JapaneseCalendar)
28 {
29 CHAR szTextA[64];
30 WCHAR szTextW[64];
31 SYSTEMTIME st;
32 DWORD langid = MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT);
33 LCID lcid = MAKELCID(langid, SORT_DEFAULT);
34 DWORD dwValue;
35 CALTYPE type;
36 int ret;
37 static const WCHAR s_szSeireki19[] = {0x897F, 0x66A6, '1', '9', 0}; // L"\u897F\u66A6" L"19"
38 static const WCHAR s_szHeisei[] = {0x5E73, 0x6210, 0}; // L"\u5E73\u6210"
39 static const WCHAR s_szHeisei31[] = {0x5E73, 0x6210, '3', '1', 0}; // L"\u5E73\u6210" L"31"
40 static const WCHAR s_szOneCharHeisei[] = {0x5E73, 0}; // L"\u5E73"
41 static const WCHAR s_szWareki[] = {0x548C, 0x66A6, 0}; // L"\u548C\u66A6"
42 static const WCHAR s_szNen[] = {0x5E74, 0}; // L"\u5E74"
43
44 trace("lcid: 0x%08lX\n", lcid);
45 trace("langid: 0x%04lX\n", langid);
46
47 ZeroMemory(&st, sizeof(st));
48 st.wYear = 2019;
49 st.wMonth = 4;
50 st.wDayOfWeek = 4;
51 st.wDay = 4;
52
53 /* Standard Date Formatting */
54 {
55 DWORD dwFlags = 0;
56
57 szTextA[0] = 0x7F;
58 szTextA[1] = 0;
59 ret = GetDateFormatA(lcid, dwFlags, &st, "gyy", szTextA, ARRAYSIZE(szTextA));
60 ok(ret != 0, "ret: %d\n", ret);
61 ok(/* WinXP */ lstrcmpiA(szTextA, "19") == 0 ||
62 /* Win10 */ lstrcmpiA(szTextA, "\x90\xBC\x97\xEF" "19") == 0, "szTextA: %s\n", szTextA);
63
64 szTextA[0] = 0x7F;
65 szTextA[1] = 0;
66 ret = GetDateFormatA(lcid, dwFlags, &st, "ggyy", szTextA, ARRAYSIZE(szTextA));
67 ok(ret != 0, "ret: %d\n", ret);
68 ok(/* WinXP */ lstrcmpiA(szTextA, "19") == 0 ||
69 /* Win10 */ lstrcmpiA(szTextA, "\x90\xBC\x97\xEF" "19") == 0, "szTextA: %s\n", szTextA);
70
71 szTextW[0] = 0x7F;
72 szTextW[1] = 0;
73 ret = GetDateFormatW(lcid, dwFlags, &st, L"gyy", szTextW, ARRAYSIZE(szTextW));
74 ok(ret != 0, "ret: %d\n", ret);
75 ok(/* WinXP */ lstrcmpiW(szTextW, L"19") == 0 ||
76 /* Win10 */ lstrcmpiW(szTextW, s_szSeireki19) == 0,
77 "szTextW: %04X %04X %04X\n", szTextW[0], szTextW[1], szTextW[2]);
78
79 szTextW[0] = 0x7F;
80 szTextW[1] = 0;
81 ret = GetDateFormatW(lcid, dwFlags, &st, L"ggyy", szTextW, ARRAYSIZE(szTextW));
82 ok(ret != 0, "ret: %d\n", ret);
83 ok(/* WinXP */ lstrcmpiW(szTextW, L"19") == 0 ||
84 /* Win10 */ lstrcmpiW(szTextW, s_szSeireki19) == 0,
85 "szTextW: %04X %04X %04X\n", szTextW[0], szTextW[1], szTextW[2]);
86 }
87
88 /* Alternative Date Formatting (Wareki) */
89 {
90 DWORD dwFlags = DATE_USE_ALT_CALENDAR;
91
92 szTextA[0] = 0x7F;
93 szTextA[1] = 0;
94 ret = GetDateFormatA(lcid, dwFlags, &st, "gyy", szTextA, ARRAYSIZE(szTextA));
95 ok(ret != 0, "ret: %d\n", ret);
96 ok(lstrcmpiA(szTextA, "\x95\xBD\x90\xAC" "31") == 0, "szTextA: %s\n", szTextA);
97
98 szTextA[0] = 0x7F;
99 szTextA[1] = 0;
100 ret = GetDateFormatA(lcid, dwFlags, &st, "ggyy", szTextA, ARRAYSIZE(szTextA));
101 ok(ret != 0, "ret: %d\n", ret);
102 ok(lstrcmpiA(szTextA, "\x95\xBD\x90\xAC" "31") == 0, "szTextA: %s\n", szTextA);
103
104 szTextW[0] = 0x7F;
105 szTextW[1] = 0;
106 ret = GetDateFormatW(lcid, dwFlags, &st, L"gyy", szTextW, ARRAYSIZE(szTextW));
107 ok(ret != 0, "ret: %d\n", ret);
108 ok(lstrcmpiW(szTextW, s_szHeisei31) == 0,
109 "szTextW: %04X %04X %04X\n", szTextW[0], szTextW[1], szTextW[2]);
110
111 szTextW[0] = 0x7F;
112 szTextW[1] = 0;
113 ret = GetDateFormatW(lcid, dwFlags, &st, L"ggyy", szTextW, ARRAYSIZE(szTextW));
114 ok(ret != 0, "ret: %d\n", ret);
115 ok(lstrcmpiW(szTextW, s_szHeisei31) == 0,
116 "szTextW: %04X %04X %04X\n", szTextW[0], szTextW[1], szTextW[2]);
117 }
118
119 /* Japanese calendar-related locale info (MBCS) */
120 {
121 type = CAL_ICALINTVALUE | CAL_RETURN_NUMBER;
122 ret = GetCalendarInfoA(lcid, CAL_JAPAN, type, NULL, 0, &dwValue);
123 ok(ret != 0, "ret: %d\n", ret);
124 ok_long(dwValue, 3);
125
126 type = CAL_ITWODIGITYEARMAX | CAL_RETURN_NUMBER;
127 ret = GetCalendarInfoA(lcid, CAL_JAPAN, type, NULL, 0, &dwValue);
128 ok(ret != 0, "ret: %d\n", ret);
129 ok_long(dwValue, 99);
130
131 type = CAL_IYEAROFFSETRANGE | CAL_RETURN_NUMBER;
132 ret = GetCalendarInfoA(lcid, CAL_JAPAN, type, NULL, 0, &dwValue);
133 ok(ret != 0, "ret: %d\n", ret);
134 ok(dwValue == 1989 || dwValue == 2019, "dwValue was %ld\n", dwValue);
135
136 szTextA[0] = 0x7F;
137 szTextA[1] = 0;
138 type = CAL_SABBREVERASTRING;
139 ret = GetCalendarInfoA(lcid, CAL_JAPAN, type, szTextA, ARRAYSIZE(szTextA), NULL);
140 ok_int(ret, FALSE);
141 ok(lstrcmpiA(szTextA, "\x7F") == 0, "szTextA: %s\n", szTextA);
142
143 szTextA[0] = 0x7F;
144 szTextA[1] = 0;
145 type = CAL_SCALNAME;
146 ret = GetCalendarInfoA(lcid, CAL_JAPAN, type, szTextA, ARRAYSIZE(szTextA), NULL);
147 ok(ret != 0, "ret: %d\n", ret);
148 ok(lstrcmpiA(szTextA, "\x98\x61\x97\xEF") == 0, "szTextA: %s\n", szTextA);
149
150 szTextA[0] = 0x7F;
151 szTextA[1] = 0;
152 type = CAL_SERASTRING;
153 ret = GetCalendarInfoA(lcid, CAL_JAPAN, type, szTextA, ARRAYSIZE(szTextA), NULL);
154 ok(ret != 0, "ret: %d\n", ret);
155 ok(lstrcmpiA(szTextA, "\x95\xBD\x90\xAC") == 0, "szTextA: %s\n", szTextA);
156
157 szTextA[0] = 0x7F;
158 szTextA[1] = 0;
159 type = CAL_SLONGDATE;
160 ret = GetCalendarInfoA(lcid, CAL_JAPAN, type, szTextA, ARRAYSIZE(szTextA), NULL);
161 ok(ret != 0, "ret: %d\n", ret);
162 ok(strstr(szTextA, "\x94\x4E") != NULL, "szTextA: %s\n", szTextA);
163
164 szTextA[0] = 0x7F;
165 szTextA[1] = 0;
166 type = CAL_SSHORTDATE;
167 ret = GetCalendarInfoA(lcid, CAL_JAPAN, type, szTextA, ARRAYSIZE(szTextA), NULL);
168 ok(ret != 0, "ret: %d\n", ret);
169 ok(strstr(szTextA, "/") != NULL, "szTextA: %s\n", szTextA);
170 }
171
172 /* Japanese calendar-related locale info (Unicode) */
173 {
174 type = CAL_ICALINTVALUE | CAL_RETURN_NUMBER;
175 ret = GetCalendarInfoW(lcid, CAL_JAPAN, type, NULL, 0, &dwValue);
176 ok(ret != 0, "ret: %d\n", ret);
177 ok_long(dwValue, 3);
178
179 type = CAL_ITWODIGITYEARMAX | CAL_RETURN_NUMBER;
180 ret = GetCalendarInfoW(lcid, CAL_JAPAN, type, NULL, 0, &dwValue);
181 ok(ret != 0, "ret: %d\n", ret);
182 ok_long(dwValue, 99);
183
184 type = CAL_IYEAROFFSETRANGE | CAL_RETURN_NUMBER;
185 ret = GetCalendarInfoW(lcid, CAL_JAPAN, type, NULL, 0, &dwValue);
186 ok(ret != 0, "ret: %d\n", ret);
187 ok(dwValue == 1989 || dwValue == 2019, "dwValue was %ld\n", dwValue);
188
189 szTextW[0] = 0x7F;
190 szTextW[1] = 0;
191 type = CAL_SABBREVERASTRING;
192 ret = GetCalendarInfoW(lcid, CAL_JAPAN, type, szTextW, ARRAYSIZE(szTextW), NULL);
193 ok(/* WinXP */ ret == 0 || /* Win10 */ ret != 0, "ret: %d\n", ret);
194 ok(/* WinXP */ (szTextW[0] == 0x7F && szTextW[1] == 0) ||
195 /* Win10 */ lstrcmpiW(szTextW, s_szOneCharHeisei) == 0,
196 "szTextW: %04X %04X %04X\n", szTextW[0], szTextW[1], szTextW[2]);
197
198 szTextW[0] = 0x7F;
199 szTextW[1] = 0;
200 type = CAL_SCALNAME;
201 ret = GetCalendarInfoW(lcid, CAL_JAPAN, type, szTextW, ARRAYSIZE(szTextW), NULL);
202 ok(ret != 0, "ret: %d\n", ret);
203 ok(lstrcmpiW(szTextW, s_szWareki) == 0, "szTextW: %04X %04X %04X\n", szTextW[0], szTextW[1], szTextW[2]);
204
205 szTextW[0] = 0x7F;
206 szTextW[1] = 0;
207 type = CAL_SERASTRING;
208 ret = GetCalendarInfoW(lcid, CAL_JAPAN, type, szTextW, ARRAYSIZE(szTextW), NULL);
209 ok(ret != 0, "ret: %d\n", ret);
210 ok(wcsstr(szTextW, s_szHeisei) != NULL, "szTextW: %04X %04X %04X\n", szTextW[0], szTextW[1], szTextW[2]);
211
212 szTextW[0] = 0x7F;
213 szTextW[1] = 0;
214 type = CAL_SLONGDATE;
215 ret = GetCalendarInfoW(lcid, CAL_JAPAN, type, szTextW, ARRAYSIZE(szTextW), NULL);
216 ok(ret != 0, "ret: %d\n", ret);
217 ok(wcsstr(szTextW, s_szNen) != NULL, "\n");
218
219 szTextW[0] = 0x7F;
220 szTextW[1] = 0;
221 type = CAL_SSHORTDATE;
222 ret = GetCalendarInfoW(lcid, CAL_JAPAN, type, szTextW, ARRAYSIZE(szTextW), NULL);
223 ok(ret != 0, "ret: %d\n", ret);
224 ok(wcsstr(szTextW, L"/") != NULL, "\n");
225 }
226 }