b4fbe1180b87b496ce647d52b849f087b05baf96
[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_szOneCharHeisei1[] = {0x337B, 0}; // L"\u337B"
41 static const WCHAR s_szOneCharHeisei2[] = {0x5E73, 0}; // L"\u5E73"
42 static const WCHAR s_szOneCharReiwa1[] = {0x32FF, 0}; // L"\u32FF"
43 static const WCHAR s_szOneCharReiwa2[] = {0x4EE4, 0}; // L"\u4EE4"
44 static const WCHAR s_szOneCharReiwa3[] = {0xF9A8, 0}; // L"\uF9A8"
45 static const WCHAR s_szWareki[] = {0x548C, 0x66A6, 0}; // L"\u548C\u66A6"
46 static const WCHAR s_szNen[] = {0x5E74, 0}; // L"\u5E74"
47
48 trace("lcid: 0x%08lX\n", lcid);
49 trace("langid: 0x%04lX\n", langid);
50
51 ZeroMemory(&st, sizeof(st));
52 st.wYear = 2019;
53 st.wMonth = 4;
54 st.wDayOfWeek = 4;
55 st.wDay = 4;
56
57 /* Standard Date Formatting */
58 {
59 DWORD dwFlags = 0;
60
61 szTextA[0] = 0x7F;
62 szTextA[1] = 0;
63 ret = GetDateFormatA(lcid, dwFlags, &st, "gyy", szTextA, ARRAYSIZE(szTextA));
64 ok(ret != 0, "ret: %d\n", ret);
65 ok(/* WinXP */ lstrcmpiA(szTextA, "19") == 0 ||
66 /* Win10 */ lstrcmpiA(szTextA, "\x90\xBC\x97\xEF" "19") == 0, "szTextA: %s\n", szTextA);
67
68 szTextA[0] = 0x7F;
69 szTextA[1] = 0;
70 ret = GetDateFormatA(lcid, dwFlags, &st, "ggyy", szTextA, ARRAYSIZE(szTextA));
71 ok(ret != 0, "ret: %d\n", ret);
72 ok(/* WinXP */ lstrcmpiA(szTextA, "19") == 0 ||
73 /* Win10 */ lstrcmpiA(szTextA, "\x90\xBC\x97\xEF" "19") == 0, "szTextA: %s\n", szTextA);
74
75 szTextW[0] = 0x7F;
76 szTextW[1] = 0;
77 ret = GetDateFormatW(lcid, dwFlags, &st, L"gyy", szTextW, ARRAYSIZE(szTextW));
78 ok(ret != 0, "ret: %d\n", ret);
79 ok(/* WinXP */ lstrcmpiW(szTextW, L"19") == 0 ||
80 /* Win10 */ lstrcmpiW(szTextW, s_szSeireki19) == 0,
81 "szTextW: %04X %04X %04X\n", szTextW[0], szTextW[1], szTextW[2]);
82
83 szTextW[0] = 0x7F;
84 szTextW[1] = 0;
85 ret = GetDateFormatW(lcid, dwFlags, &st, L"ggyy", szTextW, ARRAYSIZE(szTextW));
86 ok(ret != 0, "ret: %d\n", ret);
87 ok(/* WinXP */ lstrcmpiW(szTextW, L"19") == 0 ||
88 /* Win10 */ lstrcmpiW(szTextW, s_szSeireki19) == 0,
89 "szTextW: %04X %04X %04X\n", szTextW[0], szTextW[1], szTextW[2]);
90 }
91
92 /* Alternative Date Formatting (Wareki) */
93 {
94 DWORD dwFlags = DATE_USE_ALT_CALENDAR;
95
96 szTextA[0] = 0x7F;
97 szTextA[1] = 0;
98 ret = GetDateFormatA(lcid, dwFlags, &st, "gyy", szTextA, ARRAYSIZE(szTextA));
99 ok(ret != 0, "ret: %d\n", ret);
100 ok(lstrcmpiA(szTextA, "\x95\xBD\x90\xAC" "31") == 0, "szTextA: %s\n", szTextA);
101
102 szTextA[0] = 0x7F;
103 szTextA[1] = 0;
104 ret = GetDateFormatA(lcid, dwFlags, &st, "ggyy", szTextA, ARRAYSIZE(szTextA));
105 ok(ret != 0, "ret: %d\n", ret);
106 ok(lstrcmpiA(szTextA, "\x95\xBD\x90\xAC" "31") == 0, "szTextA: %s\n", szTextA);
107
108 szTextW[0] = 0x7F;
109 szTextW[1] = 0;
110 ret = GetDateFormatW(lcid, dwFlags, &st, L"gyy", szTextW, ARRAYSIZE(szTextW));
111 ok(ret != 0, "ret: %d\n", ret);
112 ok(lstrcmpiW(szTextW, s_szHeisei31) == 0,
113 "szTextW: %04X %04X %04X\n", szTextW[0], szTextW[1], szTextW[2]);
114
115 szTextW[0] = 0x7F;
116 szTextW[1] = 0;
117 ret = GetDateFormatW(lcid, dwFlags, &st, L"ggyy", szTextW, ARRAYSIZE(szTextW));
118 ok(ret != 0, "ret: %d\n", ret);
119 ok(lstrcmpiW(szTextW, s_szHeisei31) == 0,
120 "szTextW: %04X %04X %04X\n", szTextW[0], szTextW[1], szTextW[2]);
121 }
122
123 /* Japanese calendar-related locale info (MBCS) */
124 {
125 type = CAL_ICALINTVALUE | CAL_RETURN_NUMBER;
126 ret = GetCalendarInfoA(lcid, CAL_JAPAN, type, NULL, 0, &dwValue);
127 ok(ret != 0, "ret: %d\n", ret);
128 ok_long(dwValue, 3);
129
130 type = CAL_ITWODIGITYEARMAX | CAL_RETURN_NUMBER;
131 ret = GetCalendarInfoA(lcid, CAL_JAPAN, type, NULL, 0, &dwValue);
132 ok(ret != 0, "ret: %d\n", ret);
133 ok_long(dwValue, 99);
134
135 type = CAL_IYEAROFFSETRANGE | CAL_RETURN_NUMBER;
136 ret = GetCalendarInfoA(lcid, CAL_JAPAN, type, NULL, 0, &dwValue);
137 ok(ret != 0, "ret: %d\n", ret);
138 ok(dwValue == 1989 || dwValue == 2019, "dwValue was %ld\n", dwValue);
139
140 szTextA[0] = 0x7F;
141 szTextA[1] = 0;
142 type = CAL_SABBREVERASTRING;
143 ret = GetCalendarInfoA(lcid, CAL_JAPAN, type, szTextA, ARRAYSIZE(szTextA), NULL);
144 ok_int(ret, FALSE);
145 ok(lstrcmpiA(szTextA, "\x7F") == 0, "szTextA: %s\n", szTextA);
146
147 szTextA[0] = 0x7F;
148 szTextA[1] = 0;
149 type = CAL_SCALNAME;
150 ret = GetCalendarInfoA(lcid, CAL_JAPAN, type, szTextA, ARRAYSIZE(szTextA), NULL);
151 ok(ret != 0, "ret: %d\n", ret);
152 ok(lstrcmpiA(szTextA, "\x98\x61\x97\xEF") == 0, "szTextA: %s\n", szTextA);
153
154 szTextA[0] = 0x7F;
155 szTextA[1] = 0;
156 type = CAL_SERASTRING;
157 ret = GetCalendarInfoA(lcid, CAL_JAPAN, type, szTextA, ARRAYSIZE(szTextA), NULL);
158 ok(ret != 0, "ret: %d\n", ret);
159 ok(lstrcmpiA(szTextA, "\x95\xBD\x90\xAC") == 0, "szTextA: %s\n", szTextA);
160
161 szTextA[0] = 0x7F;
162 szTextA[1] = 0;
163 type = CAL_SLONGDATE;
164 ret = GetCalendarInfoA(lcid, CAL_JAPAN, type, szTextA, ARRAYSIZE(szTextA), NULL);
165 ok(ret != 0, "ret: %d\n", ret);
166 ok(strstr(szTextA, "\x94\x4E") != NULL, "szTextA: %s\n", szTextA);
167
168 szTextA[0] = 0x7F;
169 szTextA[1] = 0;
170 type = CAL_SSHORTDATE;
171 ret = GetCalendarInfoA(lcid, CAL_JAPAN, type, szTextA, ARRAYSIZE(szTextA), NULL);
172 ok(ret != 0, "ret: %d\n", ret);
173 ok(strstr(szTextA, "/") != NULL, "szTextA: %s\n", szTextA);
174 }
175
176 /* Japanese calendar-related locale info (Unicode) */
177 {
178 type = CAL_ICALINTVALUE | CAL_RETURN_NUMBER;
179 ret = GetCalendarInfoW(lcid, CAL_JAPAN, type, NULL, 0, &dwValue);
180 ok(ret != 0, "ret: %d\n", ret);
181 ok_long(dwValue, 3);
182
183 type = CAL_ITWODIGITYEARMAX | CAL_RETURN_NUMBER;
184 ret = GetCalendarInfoW(lcid, CAL_JAPAN, type, NULL, 0, &dwValue);
185 ok(ret != 0, "ret: %d\n", ret);
186 ok_long(dwValue, 99);
187
188 type = CAL_IYEAROFFSETRANGE | CAL_RETURN_NUMBER;
189 ret = GetCalendarInfoW(lcid, CAL_JAPAN, type, NULL, 0, &dwValue);
190 ok(ret != 0, "ret: %d\n", ret);
191 ok(dwValue == 1989 || dwValue == 2019, "dwValue was %ld\n", dwValue);
192
193 szTextW[0] = 0x7F;
194 szTextW[1] = 0;
195 type = CAL_SABBREVERASTRING;
196 ret = GetCalendarInfoW(lcid, CAL_JAPAN, type, szTextW, ARRAYSIZE(szTextW), NULL);
197 ok(/* WinXP */ ret == 0 || /* Win10 */ ret != 0, "ret: %d\n", ret);
198 ok(/* WinXP */ (szTextW[0] == 0x7F && szTextW[1] == 0) ||
199 /* Win10? */ lstrcmpiW(szTextW, s_szOneCharHeisei1) == 0 ||
200 /* Win10? */ lstrcmpiW(szTextW, s_szOneCharHeisei2) == 0 ||
201 /* Win10? */ lstrcmpiW(szTextW, s_szOneCharReiwa1) == 0 ||
202 /* Win10? */ lstrcmpiW(szTextW, s_szOneCharReiwa2) == 0 ||
203 /* Win10? */ lstrcmpiW(szTextW, s_szOneCharReiwa3) == 0,
204 "szTextW: %04X %04X %04X\n", szTextW[0], szTextW[1], szTextW[2]);
205
206 szTextW[0] = 0x7F;
207 szTextW[1] = 0;
208 type = CAL_SCALNAME;
209 ret = GetCalendarInfoW(lcid, CAL_JAPAN, type, szTextW, ARRAYSIZE(szTextW), NULL);
210 ok(ret != 0, "ret: %d\n", ret);
211 ok(lstrcmpiW(szTextW, s_szWareki) == 0, "szTextW: %04X %04X %04X\n", szTextW[0], szTextW[1], szTextW[2]);
212
213 szTextW[0] = 0x7F;
214 szTextW[1] = 0;
215 type = CAL_SERASTRING;
216 ret = GetCalendarInfoW(lcid, CAL_JAPAN, type, szTextW, ARRAYSIZE(szTextW), NULL);
217 ok(ret != 0, "ret: %d\n", ret);
218 ok(wcsstr(szTextW, s_szHeisei) != NULL, "szTextW: %04X %04X %04X\n", szTextW[0], szTextW[1], szTextW[2]);
219
220 szTextW[0] = 0x7F;
221 szTextW[1] = 0;
222 type = CAL_SLONGDATE;
223 ret = GetCalendarInfoW(lcid, CAL_JAPAN, type, szTextW, ARRAYSIZE(szTextW), NULL);
224 ok(ret != 0, "ret: %d\n", ret);
225 ok(wcsstr(szTextW, s_szNen) != NULL, "\n");
226
227 szTextW[0] = 0x7F;
228 szTextW[1] = 0;
229 type = CAL_SSHORTDATE;
230 ret = GetCalendarInfoW(lcid, CAL_JAPAN, type, szTextW, ARRAYSIZE(szTextW), NULL);
231 ok(ret != 0, "ret: %d\n", ret);
232 ok(wcsstr(szTextW, L"/") != NULL, "\n");
233 }
234 }