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