sync mlang winetest with wine 1.1.29
[reactos.git] / rostests / winetests / mlang / mlang.c
1 /*
2 * Unit test suite for MLANG APIs.
3 *
4 * Copyright 2004 Dmitry Timoshkov
5 * Copyright 2009 Detlef Riekenberg
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * 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 #define COBJMACROS
23
24 #include <stdarg.h>
25 #include <stdio.h>
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winerror.h"
30 #include "initguid.h"
31 #include "mlang.h"
32
33 #include "wine/test.h"
34
35 #ifndef CP_UNICODE
36 #define CP_UNICODE 1200
37 #endif
38
39 #if 0
40 #define DUMP_CP_INFO
41 #define DUMP_SCRIPT_INFO
42
43 #if defined DUMP_CP_INFO || defined DUMP_SCRIPT_INFO
44 #include "wine/debug.h"
45 #endif
46 #endif /* 0 */
47
48 static BOOL (WINAPI *pGetCPInfoExA)(UINT, DWORD, LPCPINFOEXA);
49 static HRESULT (WINAPI *pConvertINetMultiByteToUnicode)(LPDWORD, DWORD, LPCSTR,
50 LPINT, LPWSTR, LPINT);
51 static HRESULT (WINAPI *pConvertINetUnicodeToMultiByte)(LPDWORD, DWORD, LPCWSTR,
52 LPINT, LPSTR, LPINT);
53 static HRESULT (WINAPI *pRfc1766ToLcidA)(LCID *, LPCSTR);
54 static HRESULT (WINAPI *pLcidToRfc1766A)(LCID, LPSTR, INT);
55
56 typedef struct lcid_tag_table {
57 LPCSTR rfc1766;
58 LCID lcid;
59 HRESULT hr;
60 LCID broken_lcid;
61 LPCSTR broken_rfc;
62 } lcid_table_entry;
63
64 /* en, ar and zh use SUBLANG_NEUTRAL for the rfc1766 name without the country
65 all others suppress the country with SUBLANG_DEFAULT.
66 For 3 letter language codes, the rfc1766 is too small for the country */
67
68 static const lcid_table_entry lcid_table[] = {
69 {"e", -1, E_FAIL},
70 {"", -1, E_FAIL},
71 {"-", -1, E_FAIL},
72 {"e-", -1, E_FAIL},
73
74 {"ar", 1, S_OK},
75 {"zh", 4, S_OK},
76
77 {"de", 0x0407, S_OK},
78 {"de-ch", 0x0807, S_OK},
79 {"de-at", 0x0c07, S_OK},
80 {"de-lu", 0x1007, S_OK},
81 {"de-li", 0x1407, S_OK},
82
83 {"en", 9, S_OK},
84 {"en-gb", 0x809, S_OK},
85 {"en-GB", 0x809, S_OK},
86 {"EN-GB", 0x809, S_OK},
87 {"en-US", 0x409, S_OK},
88 {"en-us", 0x409, S_OK},
89
90 {"fr", 0x040c, S_OK},
91 {"fr-be", 0x080c, S_OK},
92 {"fr-ca", 0x0c0c, S_OK},
93 {"fr-ch", 0x100c, S_OK},
94 {"fr-lu", 0x140c, S_OK},
95 {"fr-mc", 0x180c, S_OK, 0x040c, "fr"},
96
97 {"it", 0x0410, S_OK},
98 {"it-ch", 0x0810, S_OK},
99
100 {"nl", 0x0413, S_OK},
101 {"nl-be", 0x0813, S_OK},
102 {"pl", 0x0415, S_OK},
103 {"ru", 0x0419, S_OK},
104
105 {"kok", 0x0457, S_OK, 0x0412, "x-kok"}
106
107 };
108
109 #define TODO_NAME 1
110
111 typedef struct info_table_tag {
112 LCID lcid;
113 LANGID lang;
114 DWORD todo;
115 LPCSTR rfc1766;
116 LPCWSTR localename;
117 LPCWSTR broken_name;
118 } info_table_entry;
119
120 static const WCHAR de_en[] = {'E','n','g','l','i','s','c','h',0};
121 static const WCHAR de_enca[] = {'E','n','g','l','i','s','c','h',' ',
122 '(','K','a','n','a','d','a',')',0};
123 static const WCHAR de_engb[] = {'E','n','g','l','i','s','c','h',' ',
124 '(','G','r','o',0xDF,'b','r','i','t','a','n','n','i','e','n',')',0};
125 static const WCHAR de_engb2[] ={'E','n','g','l','i','s','c','h',' ',
126 '(','V','e','r','e','i','n','i','g','t','e','s',' ',
127 'K',0xF6,'n','i','g','r','e','i','c',0};
128 static const WCHAR de_enus[] = {'E','n','g','l','i','s','c','h',' ',
129 '(','U','S','A',')',0};
130 static const WCHAR de_de[] = {'D','e','u','t','s','c','h',' ',
131 '(','D','e','u','t','s','c','h','l','a','n','d',')',0};
132 static const WCHAR de_deat[] = {'D','e','u','t','s','c','h',' ',
133 '(',0xD6,'s','t','e','r','r','e','i','c','h',')',0};
134 static const WCHAR de_dech[] = {'D','e','u','t','s','c','h',' ',
135 '(','S','c','h','w','e','i','z',')',0};
136
137 static const WCHAR en_en[] = {'E','n','g','l','i','s','h',0};
138 static const WCHAR en_enca[] = {'E','n','g','l','i','s','h',' ',
139 '(','C','a','n','a','d','a',')',0};
140 static const WCHAR en_engb[] = {'E','n','g','l','i','s','h',' ',
141 '(','U','n','i','t','e','d',' ','K','i','n','g','d','o','m',')',0};
142 static const WCHAR en_enus[] = {'E','n','g','l','i','s','h',' ',
143 '(','U','n','i','t','e','d',' ','S','t','a','t','e','s',')',0};
144 static const WCHAR en_de[] = {'G','e','r','m','a','n',' ',
145 '(','G','e','r','m','a','n','y',')',0};
146 static const WCHAR en_deat[] = {'G','e','r','m','a','n',' ',
147 '(','A','u','s','t','r','i','a',')',0};
148 static const WCHAR en_dech[] = {'G','e','r','m','a','n',' ',
149 '(','S','w','i','t','z','e','r','l','a','n','d',')',0};
150
151 static const WCHAR fr_en[] = {'A','n','g','l','a','i','s',0};
152 static const WCHAR fr_enca[] = {'A','n','g','l','a','i','s',' ',
153 '(','C','a','n','a','d','a',')',0};
154 static const WCHAR fr_engb[] = {'A','n','g','l','a','i','s',' ',
155 '(','R','o','y','a','u','m','e','-','U','n','i',')',0};
156 static const WCHAR fr_enus[] = {'A','n','g','l','a','i','s',' ',
157 '(',0xC9, 't','a','t','s','-','U','n','i','s',')',0};
158 static const WCHAR fr_enus2[] ={'A','n','g','l','a','i','s',' ',
159 '(','U','.','S','.',')',0};
160 static const WCHAR fr_de[] = {'A','l','l','e','m','a','n','d',' ',
161 '(','A','l','l','e','m','a','g','n','e',')',0};
162 static const WCHAR fr_de2[] = {'A','l','l','e','m','a','n','d',' ',
163 '(','S','t','a','n','d','a','r','d',')',0};
164 static const WCHAR fr_deat[] = {'A','l','l','e','m','a','n','d',' ',
165 '(','A','u','t','r','i','c','h','e',')',0};
166 static const WCHAR fr_dech[] = {'A','l','l','e','m','a','n','d',' ',
167 '(','S','u','i','s','s','e',')',0};
168
169 static const info_table_entry info_table[] = {
170 {MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL), MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL),
171 0, "en", en_en},
172 {MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL),
173 0, "en-us", en_enus},
174 {MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_UK), MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL),
175 0, "en-gb", en_engb},
176 {MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL),
177 0, "en-us", en_enus},
178 {MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_CAN), MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL),
179 0, "en-ca", en_enca},
180
181 {MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT), MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL),
182 0, "de", en_de},
183 {MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN), MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL),
184 0, "de", en_de},
185 {MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN_SWISS), MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL),
186 0, "de-ch", en_dech},
187 {MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN_AUSTRIAN), MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL),
188 0, "de-at", en_deat},
189
190 {MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL), MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT),
191 TODO_NAME, "en", de_en},
192 {MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT),
193 TODO_NAME, "en-us", de_enus},
194 {MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_UK), MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT),
195 TODO_NAME, "en-gb", de_engb, de_engb2},
196 {MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT),
197 TODO_NAME, "en-us", de_enus},
198 {MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_CAN), MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT),
199 TODO_NAME, "en-ca", de_enca},
200
201 {MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT), MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT),
202 TODO_NAME, "de", de_de},
203 {MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN), MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT),
204 TODO_NAME, "de",de_de},
205 {MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN_SWISS), MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT),
206 TODO_NAME, "de-ch", de_dech},
207 {MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN_AUSTRIAN), MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT),
208 TODO_NAME, "de-at", de_deat},
209
210 {MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL), MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT),
211 TODO_NAME, "en", fr_en},
212 {MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT),
213 TODO_NAME, "en-us", fr_enus, fr_enus2},
214 {MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_UK), MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT),
215 TODO_NAME, "en-gb", fr_engb},
216 {MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT),
217 TODO_NAME, "en-us", fr_enus, fr_enus2},
218 {MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_CAN), MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT),
219 TODO_NAME, "en-ca", fr_enca},
220
221 {MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT), MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT),
222 TODO_NAME, "de", fr_de, fr_de2},
223 {MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN), MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT),
224 TODO_NAME, "de", fr_de, fr_de2},
225 {MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN_SWISS), MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT),
226 TODO_NAME, "de-ch", fr_dech},
227 {MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN_AUSTRIAN), MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT),
228 TODO_NAME, "de-at", fr_deat}
229
230 };
231
232 static BOOL init_function_ptrs(void)
233 {
234 HMODULE hMlang;
235
236 hMlang = LoadLibraryA("mlang.dll");
237 if (!hMlang)
238 {
239 skip("mlang not available\n");
240 return FALSE;
241 }
242
243 pConvertINetMultiByteToUnicode = (void *)GetProcAddress(hMlang, "ConvertINetMultiByteToUnicode");
244 pConvertINetUnicodeToMultiByte = (void *)GetProcAddress(hMlang, "ConvertINetUnicodeToMultiByte");
245 pRfc1766ToLcidA = (void *)GetProcAddress(hMlang, "Rfc1766ToLcidA");
246 pLcidToRfc1766A = (void *)GetProcAddress(hMlang, "LcidToRfc1766A");
247
248 pGetCPInfoExA = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"), "GetCPInfoExA");
249
250 return TRUE;
251 }
252
253 #define ok_w2(format, szString1, szString2) \
254 \
255 if (lstrcmpW((szString1), (szString2)) != 0) \
256 { \
257 CHAR string1[256], string2[256]; \
258 WideCharToMultiByte(CP_ACP, 0, (szString1), -1, string1, 256, NULL, NULL); \
259 WideCharToMultiByte(CP_ACP, 0, (szString2), -1, string2, 256, NULL, NULL); \
260 ok(0, (format), string1, string2); \
261 }
262
263 /* lstrcmpW is not supported on Win9x! */
264 static int mylstrcmpW(const WCHAR* str1, const WCHAR* str2)
265 {
266 if (!str2) return 1;
267 while (*str1 && *str1==*str2) {
268 str1++;
269 str2++;
270 }
271 return *str1-*str2;
272 }
273
274 /* lstrcpyW is not supported on Win95 */
275 static void mylstrcpyW(WCHAR* str1, const WCHAR* str2)
276 {
277 while (str2 && *str2) {
278 *str1 = *str2;
279 str1++;
280 str2++;
281 }
282 *str1 = '\0';
283 }
284
285 static void test_multibyte_to_unicode_translations(IMultiLanguage2 *iML2)
286 {
287 /* these APIs are broken regarding constness of the input buffer */
288 char stringA[] = "Just a test string\0"; /* double 0 for CP_UNICODE tests */
289 WCHAR stringW[] = {'J','u','s','t',' ','a',' ','t','e','s','t',' ','s','t','r','i','n','g',0};
290 char bufA[256];
291 WCHAR bufW[256];
292 UINT lenA, lenW, expected_len;
293 HRESULT ret;
294
295 /* IMultiLanguage2_ConvertStringToUnicode tests */
296
297 memset(bufW, 'x', sizeof(bufW));
298 lenA = 0;
299 lenW = sizeof(bufW)/sizeof(bufW[0]);
300 ret = IMultiLanguage2_ConvertStringToUnicode(iML2, NULL, 1252, stringA, &lenA, bufW, &lenW);
301 ok(ret == S_OK, "IMultiLanguage2_ConvertStringToUnicode failed: %08x\n", ret);
302 ok(lenA == 0, "expected lenA 0, got %u\n", lenA);
303 ok(lenW == 0, "expected lenW 0, got %u\n", lenW);
304
305 memset(bufW, 'x', sizeof(bufW));
306 lenA = -1;
307 lenW = sizeof(bufW)/sizeof(bufW[0]);
308 ret = IMultiLanguage2_ConvertStringToUnicode(iML2, NULL, 1252, stringA, &lenA, bufW, &lenW);
309 ok(ret == S_OK, "IMultiLanguage2_ConvertStringToUnicode failed: %08x\n", ret);
310 ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
311 ok(lenW == lstrlenW(stringW), "expected lenW %u, got %u\n", lstrlenW(stringW), lenW);
312 if (lenW < sizeof(bufW)/sizeof(bufW[0])) {
313 /* can only happen if the convert call fails */
314 ok(bufW[lenW] != 0, "buf should not be 0 terminated\n");
315 bufW[lenW] = 0; /* -1 doesn't include 0 terminator */
316 }
317 ok(!lstrcmpW(bufW, stringW), "bufW/stringW mismatch\n");
318
319 memset(bufW, 'x', sizeof(bufW));
320 lenA = -1;
321 lenW = 5;
322 ret = IMultiLanguage2_ConvertStringToUnicode(iML2, NULL, 1252, stringA, &lenA, bufW, &lenW);
323 ok(ret == E_FAIL, "IMultiLanguage2_ConvertStringToUnicode should fail: %08x\n", ret);
324 ok(lenW == 0, "expected lenW 0, got %u\n", lenW);
325 /* still has to do partial conversion */
326 ok(!memcmp(bufW, stringW, 5 * sizeof(WCHAR)), "bufW/stringW mismatch\n");
327
328 memset(bufW, 'x', sizeof(bufW));
329 lenA = -1;
330 lenW = sizeof(bufW)/sizeof(bufW[0]);
331 ret = IMultiLanguage2_ConvertStringToUnicode(iML2, NULL, CP_UNICODE, stringA, &lenA, bufW, &lenW);
332 ok(ret == S_OK, "IMultiLanguage2_ConvertStringToUnicode failed: %08x\n", ret);
333 ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
334 ok(lenW == lstrlenW(stringW)/(int)sizeof(WCHAR), "wrong lenW %u\n", lenW);
335 ok(bufW[lenW] != 0, "buf should not be 0 terminated\n");
336 bufW[lenW] = 0; /* -1 doesn't include 0 terminator */
337 ok(!lstrcmpA((LPCSTR)bufW, stringA), "bufW/stringA mismatch\n");
338
339 memset(bufW, 'x', sizeof(bufW));
340 lenA = lstrlenA(stringA);
341 lenW = 0;
342 ret = IMultiLanguage2_ConvertStringToUnicode(iML2, NULL, 1252, stringA, &lenA, NULL, &lenW);
343 ok(ret == S_OK, "IMultiLanguage2_ConvertStringToUnicode failed: %08x\n", ret);
344 ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
345 expected_len = MultiByteToWideChar(1252, 0, stringA, lenA, NULL, 0);
346 ok(lenW == expected_len, "expected lenW %u, got %u\n", expected_len, lenW);
347
348 memset(bufW, 'x', sizeof(bufW));
349 lenA = lstrlenA(stringA);
350 lenW = sizeof(bufW)/sizeof(bufW[0]);
351 ret = pConvertINetMultiByteToUnicode(NULL, 1252, stringA, (INT *)&lenA, NULL, (INT *)&lenW);
352 ok(ret == S_OK, "ConvertINetMultiByteToUnicode failed: %08x\n", ret);
353 ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
354 expected_len = MultiByteToWideChar(1252, 0, stringA, lenA, NULL, 0);
355 ok(lenW == expected_len, "expected lenW %u, got %u\n", expected_len, lenW);
356
357 memset(bufW, 'x', sizeof(bufW));
358 lenA = lstrlenA(stringA);
359 lenW = 0;
360 ret = pConvertINetMultiByteToUnicode(NULL, 1252, stringA, (INT *)&lenA, NULL, (INT *)&lenW);
361 ok(ret == S_OK, "ConvertINetMultiByteToUnicode failed: %08x\n", ret);
362 ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
363 expected_len = MultiByteToWideChar(1252, 0, stringA, lenA, NULL, 0);
364 ok(lenW == expected_len, "expected lenW %u, got %u\n", expected_len, lenW);
365
366 /* IMultiLanguage2_ConvertStringFromUnicode tests */
367
368 memset(bufA, 'x', sizeof(bufA));
369 lenW = 0;
370 lenA = sizeof(bufA);
371 ret = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, stringW, &lenW, bufA, &lenA);
372 ok(ret == S_OK, "IMultiLanguage2_ConvertStringFromUnicode failed: %08x\n", ret);
373 ok(lenA == 0, "expected lenA 0, got %u\n", lenA);
374 ok(lenW == 0, "expected lenW 0, got %u\n", lenW);
375
376 memset(bufA, 'x', sizeof(bufA));
377 lenW = -1;
378 lenA = sizeof(bufA);
379 ret = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, stringW, &lenW, bufA, &lenA);
380 ok(ret == S_OK, "IMultiLanguage2_ConvertStringFromUnicode failed: %08x\n", ret);
381 ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
382 ok(lenW == lstrlenW(stringW), "expected lenW %u, got %u\n", lstrlenW(stringW), lenW);
383 ok(bufA[lenA] != 0, "buf should not be 0 terminated\n");
384 bufA[lenA] = 0; /* -1 doesn't include 0 terminator */
385 ok(!lstrcmpA(bufA, stringA), "bufA/stringA mismatch\n");
386
387 memset(bufA, 'x', sizeof(bufA));
388 lenW = -1;
389 lenA = 5;
390 ret = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, stringW, &lenW, bufA, &lenA);
391 ok(ret == E_FAIL, "IMultiLanguage2_ConvertStringFromUnicode should fail: %08x\n", ret);
392 ok(lenA == 0, "expected lenA 0, got %u\n", lenA);
393 /* still has to do partial conversion */
394 ok(!memcmp(bufA, stringA, 5), "bufW/stringW mismatch\n");
395
396 memset(bufA, 'x', sizeof(bufA));
397 lenW = -1;
398 lenA = sizeof(bufA);
399 ret = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, CP_UNICODE, stringW, &lenW, bufA, &lenA);
400 ok(ret == S_OK, "IMultiLanguage2_ConvertStringFromUnicode failed: %08x\n", ret);
401 ok(lenA == lstrlenA(stringA) * (int)sizeof(WCHAR), "wrong lenA %u\n", lenA);
402 ok(lenW == lstrlenW(stringW), "expected lenW %u, got %u\n", lstrlenW(stringW), lenW);
403 ok(bufA[lenA] != 0 && bufA[lenA+1] != 0, "buf should not be 0 terminated\n");
404 bufA[lenA] = 0; /* -1 doesn't include 0 terminator */
405 bufA[lenA+1] = 0; /* sizeof(WCHAR) */
406 ok(!lstrcmpW((LPCWSTR)bufA, stringW), "bufA/stringW mismatch\n");
407
408 memset(bufA, 'x', sizeof(bufA));
409 lenW = lstrlenW(stringW);
410 lenA = 0;
411 ret = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, stringW, &lenW, NULL, &lenA);
412 ok(ret == S_OK, "IMultiLanguage2_ConvertStringFromUnicode failed: %08x\n", ret);
413 ok(lenW == lstrlenW(stringW), "expected lenW %u, got %u\n", lstrlenW(stringW), lenW);
414 expected_len = WideCharToMultiByte(1252, 0, stringW, lenW, NULL, 0, NULL, NULL);
415 ok(lenA == expected_len, "expected lenA %u, got %u\n", expected_len, lenA);
416 }
417
418 static void cpinfo_cmp(MIMECPINFO *cpinfo1, MIMECPINFO *cpinfo2)
419 {
420 ok(cpinfo1->dwFlags == cpinfo2->dwFlags, "dwFlags mismatch: %08x != %08x\n", cpinfo1->dwFlags, cpinfo2->dwFlags);
421 ok(cpinfo1->uiCodePage == cpinfo2->uiCodePage, "uiCodePage mismatch: %u != %u\n", cpinfo1->uiCodePage, cpinfo2->uiCodePage);
422 ok(cpinfo1->uiFamilyCodePage == cpinfo2->uiFamilyCodePage, "uiFamilyCodePage mismatch: %u != %u\n", cpinfo1->uiFamilyCodePage, cpinfo2->uiFamilyCodePage);
423 ok(!lstrcmpW(cpinfo1->wszDescription, cpinfo2->wszDescription), "wszDescription mismatch\n");
424 ok(!lstrcmpW(cpinfo1->wszWebCharset, cpinfo2->wszWebCharset), "wszWebCharset mismatch\n");
425 ok(!lstrcmpW(cpinfo1->wszHeaderCharset, cpinfo2->wszHeaderCharset), "wszHeaderCharset mismatch\n");
426 ok(!lstrcmpW(cpinfo1->wszBodyCharset, cpinfo2->wszBodyCharset), "wszBodyCharset mismatch\n");
427 ok(!lstrcmpW(cpinfo1->wszFixedWidthFont, cpinfo2->wszFixedWidthFont), "wszFixedWidthFont mismatch\n");
428 ok(!lstrcmpW(cpinfo1->wszProportionalFont, cpinfo2->wszProportionalFont), "wszProportionalFont mismatch\n");
429 ok(cpinfo1->bGDICharset == cpinfo2->bGDICharset, "bGDICharset mismatch: %d != %d\n", cpinfo1->bGDICharset, cpinfo2->bGDICharset);
430 }
431
432 #ifdef DUMP_CP_INFO
433 static const char *dump_mime_flags(DWORD flags)
434 {
435 static char buf[1024];
436
437 buf[0] = 0;
438
439 if (flags & MIMECONTF_MAILNEWS) strcat(buf, " MIMECONTF_MAILNEWS");
440 if (flags & MIMECONTF_BROWSER) strcat(buf, " MIMECONTF_BROWSER");
441 if (flags & MIMECONTF_MINIMAL) strcat(buf, " MIMECONTF_MINIMAL");
442 if (flags & MIMECONTF_IMPORT) strcat(buf, " MIMECONTF_IMPORT");
443 if (flags & MIMECONTF_SAVABLE_MAILNEWS) strcat(buf, " MIMECONTF_SAVABLE_MAILNEWS");
444 if (flags & MIMECONTF_SAVABLE_BROWSER) strcat(buf, " MIMECONTF_SAVABLE_BROWSER");
445 if (flags & MIMECONTF_EXPORT) strcat(buf, " MIMECONTF_EXPORT");
446 if (flags & MIMECONTF_PRIVCONVERTER) strcat(buf, " MIMECONTF_PRIVCONVERTER");
447 if (flags & MIMECONTF_VALID) strcat(buf, " MIMECONTF_VALID");
448 if (flags & MIMECONTF_VALID_NLS) strcat(buf, " MIMECONTF_VALID_NLS");
449 if (flags & MIMECONTF_MIME_IE4) strcat(buf, " MIMECONTF_MIME_IE4");
450 if (flags & MIMECONTF_MIME_LATEST) strcat(buf, " MIMECONTF_MIME_LATEST");
451 if (flags & MIMECONTF_MIME_REGISTRY) strcat(buf, " MIMECONTF_MIME_REGISTRY");
452
453 return buf;
454 }
455 #endif
456
457 static HRESULT check_convertible(IMultiLanguage2 *iML2, UINT from, UINT to)
458 {
459 CHAR convert[MAX_PATH];
460 BYTE dest[MAX_PATH];
461 HRESULT hr;
462 UINT srcsz, destsz;
463
464 static WCHAR strW[] = {'a','b','c',0};
465
466 /* Check to see if the target codepage has these characters or not */
467 if (from != CP_UTF8)
468 {
469 BOOL fDefaultChar;
470 char ch[10];
471 int cb;
472 cb = WideCharToMultiByte( from, WC_NO_BEST_FIT_CHARS | WC_COMPOSITECHECK | WC_DEFAULTCHAR,
473 strW, 3, ch, sizeof(ch), NULL, &fDefaultChar);
474
475 if(cb == 0 || fDefaultChar)
476 {
477 trace("target codepage %i does not contain 'abc'\n",from);
478 return E_FAIL;
479 }
480 }
481
482 srcsz = lstrlenW(strW) + 1;
483 destsz = MAX_PATH;
484 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, from, strW,
485 &srcsz, convert, &destsz);
486 if (hr != S_OK)
487 return S_FALSE;
488
489 srcsz = -1;
490 destsz = MAX_PATH;
491 hr = IMultiLanguage2_ConvertString(iML2, NULL, from, to, (BYTE *)convert,
492 &srcsz, dest, &destsz);
493 if (hr != S_OK)
494 return S_FALSE;
495
496 return S_OK;
497 }
498
499 static void test_EnumCodePages(IMultiLanguage2 *iML2, DWORD flags)
500 {
501 IEnumCodePage *iEnumCP = NULL;
502 MIMECPINFO *cpinfo;
503 MIMECPINFO cpinfo2;
504 HRESULT ret;
505 ULONG i, n;
506 UINT total;
507
508 total = 0;
509 ret = IMultiLanguage2_GetNumberOfCodePageInfo(iML2, &total);
510 ok(ret == S_OK && total != 0, "IMultiLanguage2_GetNumberOfCodePageInfo: expected S_OK/!0, got %08x/%u\n", ret, total);
511
512 trace("total mlang supported codepages %u\n", total);
513
514 ret = IMultiLanguage2_EnumCodePages(iML2, flags, LANG_NEUTRAL, &iEnumCP);
515 ok(ret == S_OK && iEnumCP, "IMultiLanguage2_EnumCodePages: expected S_OK/!NULL, got %08x/%p\n", ret, iEnumCP);
516
517 ret = IEnumCodePage_Reset(iEnumCP);
518 ok(ret == S_OK, "IEnumCodePage_Reset: expected S_OK, got %08x\n", ret);
519 n = 65536;
520 ret = IEnumCodePage_Next(iEnumCP, 0, NULL, &n);
521 if (ret == S_FALSE)
522 ok(n == 0 && ret == S_FALSE, "IEnumCodePage_Next: expected 0/S_FALSE, got %u/%08x\n", n, ret);
523 else if (ret == E_FAIL)
524 ok(n == 65536 && ret == E_FAIL, "IEnumCodePage_Next: expected 65536/E_FAIL, got %u/%08x\n", n, ret);
525 ret = IEnumCodePage_Next(iEnumCP, 0, NULL, NULL);
526 if (ret == S_FALSE)
527 ok(ret == S_FALSE, "IEnumCodePage_Next: expected S_FALSE, got %08x\n", ret);
528 else if (ret == E_FAIL)
529 ok(n == 65536 && ret == E_FAIL, "IEnumCodePage_Next: expected 65536/E_FAIL, got %u/%08x\n", n, ret);
530
531 cpinfo = HeapAlloc(GetProcessHeap(), 0, sizeof(*cpinfo) * total * 2);
532
533 n = total * 2;
534 ret = IEnumCodePage_Next(iEnumCP, 0, cpinfo, &n);
535 ok(ret == S_FALSE && n == 0, "IEnumCodePage_Next: expected S_FALSE/0, got %08x/%u\n", ret, n);
536
537 n = total * 2;
538 ret = IEnumCodePage_Next(iEnumCP, n, cpinfo, &n);
539 ok(ret == S_OK && n != 0, "IEnumCodePage_Next: expected S_OK/!0, got %08x/%u\n", ret, n);
540
541 trace("flags %08x, enumerated codepages %u\n", flags, n);
542
543 if (!flags)
544 {
545 ok(n == total, "IEnumCodePage_Next: expected %u, got %u\n", total, n);
546
547 flags = MIMECONTF_MIME_LATEST;
548 }
549
550 total = n;
551
552 for (i = 0; i < n; i++)
553 {
554 CHARSETINFO csi;
555 MIMECSETINFO mcsi;
556 HRESULT convertible = S_OK;
557 static const WCHAR autoW[] = {'_','a','u','t','o',0};
558 static const WCHAR feffW[] = {'u','n','i','c','o','d','e','F','E','F','F',0};
559
560 #ifdef DUMP_CP_INFO
561 trace("MIMECPINFO #%u:\n"
562 "dwFlags %08x %s\n"
563 "uiCodePage %u\n"
564 "uiFamilyCodePage %u\n"
565 "wszDescription %s\n"
566 "wszWebCharset %s\n"
567 "wszHeaderCharset %s\n"
568 "wszBodyCharset %s\n"
569 "wszFixedWidthFont %s\n"
570 "wszProportionalFont %s\n"
571 "bGDICharset %d\n\n",
572 i,
573 cpinfo[i].dwFlags, dump_mime_flags(cpinfo[i].dwFlags),
574 cpinfo[i].uiCodePage,
575 cpinfo[i].uiFamilyCodePage,
576 wine_dbgstr_w(cpinfo[i].wszDescription),
577 wine_dbgstr_w(cpinfo[i].wszWebCharset),
578 wine_dbgstr_w(cpinfo[i].wszHeaderCharset),
579 wine_dbgstr_w(cpinfo[i].wszBodyCharset),
580 wine_dbgstr_w(cpinfo[i].wszFixedWidthFont),
581 wine_dbgstr_w(cpinfo[i].wszProportionalFont),
582 cpinfo[i].bGDICharset);
583 #endif
584 ok(cpinfo[i].dwFlags & flags, "enumerated flags %08x do not include requested %08x\n", cpinfo[i].dwFlags, flags);
585
586 if (TranslateCharsetInfo((DWORD *)(INT_PTR)cpinfo[i].uiFamilyCodePage, &csi, TCI_SRCCODEPAGE))
587 ok(cpinfo[i].bGDICharset == csi.ciCharset, "%d != %d\n", cpinfo[i].bGDICharset, csi.ciCharset);
588 else
589 if (winetest_debug > 1)
590 trace("TranslateCharsetInfo failed for cp %u\n", cpinfo[i].uiFamilyCodePage);
591
592 #ifdef DUMP_CP_INFO
593 trace("%u: codepage %u family %u\n", i, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
594 #endif
595 /* Win95 does not support UTF-7 */
596 if (cpinfo[i].uiCodePage == CP_UTF7) continue;
597
598 /* support files for some codepages might be not installed, or
599 * the codepage is just an alias.
600 */
601 if (IsValidCodePage(cpinfo[i].uiCodePage))
602 {
603 ret = IMultiLanguage2_IsConvertible(iML2, cpinfo[i].uiCodePage, CP_UNICODE);
604 ok(ret == S_OK, "IMultiLanguage2_IsConvertible(%u -> CP_UNICODE) = %08x\n", cpinfo[i].uiCodePage, ret);
605 ret = IMultiLanguage2_IsConvertible(iML2, CP_UNICODE, cpinfo[i].uiCodePage);
606 ok(ret == S_OK, "IMultiLanguage2_IsConvertible(CP_UNICODE -> %u) = %08x\n", cpinfo[i].uiCodePage, ret);
607
608 convertible = check_convertible(iML2, cpinfo[i].uiCodePage, CP_UTF8);
609 if (convertible != E_FAIL)
610 {
611 ret = IMultiLanguage2_IsConvertible(iML2, cpinfo[i].uiCodePage, CP_UTF8);
612 ok(ret == convertible, "IMultiLanguage2_IsConvertible(%u -> CP_UTF8) = %08x\n", cpinfo[i].uiCodePage, ret);
613 ret = IMultiLanguage2_IsConvertible(iML2, CP_UTF8, cpinfo[i].uiCodePage);
614 ok(ret == convertible, "IMultiLanguage2_IsConvertible(CP_UTF8 -> %u) = %08x\n", cpinfo[i].uiCodePage, ret);
615 }
616 }
617 else
618 if (winetest_debug > 1)
619 trace("IsValidCodePage failed for cp %u\n", cpinfo[i].uiCodePage);
620
621 if (memcmp(cpinfo[i].wszWebCharset,feffW,sizeof(WCHAR)*11)==0)
622 skip("Legacy windows bug returning invalid charset of unicodeFEFF\n");
623 else
624 {
625 ret = IMultiLanguage2_GetCharsetInfo(iML2, cpinfo[i].wszWebCharset, &mcsi);
626 /* _autoxxx charsets are a fake and GetCharsetInfo fails for them */
627 if (memcmp(cpinfo[i].wszWebCharset, autoW, 5 * sizeof(WCHAR)))
628 {
629 ok (ret == S_OK, "IMultiLanguage2_GetCharsetInfo failed: %08x\n", ret);
630 #ifdef DUMP_CP_INFO
631 trace("%s: %u %u %s\n", wine_dbgstr_w(cpinfo[i].wszWebCharset), mcsi.uiCodePage, mcsi.uiInternetEncoding, wine_dbgstr_w(mcsi.wszCharset));
632 #endif
633 ok(!lstrcmpiW(cpinfo[i].wszWebCharset, mcsi.wszCharset),
634 #ifdef DUMP_CP_INFO
635 "%s != %s\n",
636 wine_dbgstr_w(cpinfo[i].wszWebCharset), wine_dbgstr_w(mcsi.wszCharset));
637 #else
638 "wszWebCharset mismatch\n");
639 #endif
640
641 if (0)
642 {
643 /* native mlang returns completely messed up encodings in some cases */
644 ok(mcsi.uiInternetEncoding == cpinfo[i].uiCodePage || mcsi.uiInternetEncoding == cpinfo[i].uiFamilyCodePage,
645 "%u != %u || %u\n", mcsi.uiInternetEncoding, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
646 ok(mcsi.uiCodePage == cpinfo[i].uiCodePage || mcsi.uiCodePage == cpinfo[i].uiFamilyCodePage,
647 "%u != %u || %u\n", mcsi.uiCodePage, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
648 }
649 }
650 }
651
652 if (memcmp(cpinfo[i].wszHeaderCharset,feffW,sizeof(WCHAR)*11)==0)
653 skip("Legacy windows bug returning invalid charset of unicodeFEFF\n");
654 else
655 {
656 ret = IMultiLanguage2_GetCharsetInfo(iML2, cpinfo[i].wszHeaderCharset, &mcsi);
657 /* _autoxxx charsets are a fake and GetCharsetInfo fails for them */
658 if (memcmp(cpinfo[i].wszHeaderCharset, autoW, 5 * sizeof(WCHAR)))
659 {
660 ok (ret == S_OK, "IMultiLanguage2_GetCharsetInfo failed: %08x\n", ret);
661 #ifdef DUMP_CP_INFO
662 trace("%s: %u %u %s\n", wine_dbgstr_w(cpinfo[i].wszHeaderCharset), mcsi.uiCodePage, mcsi.uiInternetEncoding, wine_dbgstr_w(mcsi.wszCharset));
663 #endif
664 ok(!lstrcmpiW(cpinfo[i].wszHeaderCharset, mcsi.wszCharset),
665 #ifdef DUMP_CP_INFO
666 "%s != %s\n",
667 wine_dbgstr_w(cpinfo[i].wszHeaderCharset), wine_dbgstr_w(mcsi.wszCharset));
668 #else
669 "wszHeaderCharset mismatch\n");
670 #endif
671
672 if (0)
673 {
674 /* native mlang returns completely messed up encodings in some cases */
675 ok(mcsi.uiInternetEncoding == cpinfo[i].uiCodePage || mcsi.uiInternetEncoding == cpinfo[i].uiFamilyCodePage,
676 "%u != %u || %u\n", mcsi.uiInternetEncoding, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
677 ok(mcsi.uiCodePage == cpinfo[i].uiCodePage || mcsi.uiCodePage == cpinfo[i].uiFamilyCodePage,
678 "%u != %u || %u\n", mcsi.uiCodePage, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
679 }
680 }
681 }
682
683 if (memcmp(cpinfo[i].wszBodyCharset,feffW,sizeof(WCHAR)*11)==0)
684 skip("Legacy windows bug returning invalid charset of unicodeFEFF\n");
685 else
686 {
687 ret = IMultiLanguage2_GetCharsetInfo(iML2, cpinfo[i].wszBodyCharset, &mcsi);
688 /* _autoxxx charsets are a fake and GetCharsetInfo fails for them */
689 if (memcmp(cpinfo[i].wszBodyCharset, autoW, 5 * sizeof(WCHAR)))
690 {
691 ok (ret == S_OK, "IMultiLanguage2_GetCharsetInfo failed: %08x\n", ret);
692 #ifdef DUMP_CP_INFO
693 trace("%s: %u %u %s\n", wine_dbgstr_w(cpinfo[i].wszBodyCharset), mcsi.uiCodePage, mcsi.uiInternetEncoding, wine_dbgstr_w(mcsi.wszCharset));
694 #endif
695 ok(!lstrcmpiW(cpinfo[i].wszBodyCharset, mcsi.wszCharset),
696 #ifdef DUMP_CP_INFO
697 "%s != %s\n",
698 wine_dbgstr_w(cpinfo[i].wszBodyCharset), wine_dbgstr_w(mcsi.wszCharset));
699 #else
700 "wszBodyCharset mismatch\n");
701 #endif
702
703 if (0)
704 {
705 /* native mlang returns completely messed up encodings in some cases */
706 ok(mcsi.uiInternetEncoding == cpinfo[i].uiCodePage || mcsi.uiInternetEncoding == cpinfo[i].uiFamilyCodePage,
707 "%u != %u || %u\n", mcsi.uiInternetEncoding, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
708 ok(mcsi.uiCodePage == cpinfo[i].uiCodePage || mcsi.uiCodePage == cpinfo[i].uiFamilyCodePage,
709 "%u != %u || %u\n", mcsi.uiCodePage, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
710 }
711 }
712 }
713 }
714
715 /* now IEnumCodePage_Next should fail, since pointer is at the end */
716 n = 1;
717 ret = IEnumCodePage_Next(iEnumCP, 1, &cpinfo2, &n);
718 ok(ret == S_FALSE && n == 0, "IEnumCodePage_Next: expected S_FALSE/0, got %08x/%u\n", ret, n);
719
720 ret = IEnumCodePage_Reset(iEnumCP);
721 ok(ret == S_OK, "IEnumCodePage_Reset: expected S_OK, got %08x\n", ret);
722 n = 0;
723 ret = IEnumCodePage_Next(iEnumCP, 1, &cpinfo2, &n);
724 ok(n == 1 && ret == S_OK, "IEnumCodePage_Next: expected 1/S_OK, got %u/%08x\n", n, ret);
725 cpinfo_cmp(&cpinfo[0], &cpinfo2);
726
727 if (0)
728 {
729 /* Due to a bug in MS' implementation of IEnumCodePage_Skip
730 * it's not used here.
731 */
732 ret = IEnumCodePage_Skip(iEnumCP, 1);
733 ok(ret == S_OK, "IEnumCodePage_Skip: expected S_OK, got %08x\n", ret);
734 }
735 for (i = 0; i < total - 1; i++)
736 {
737 n = 0;
738 ret = IEnumCodePage_Next(iEnumCP, 1, &cpinfo2, &n);
739 ok(n == 1 && ret == S_OK, "IEnumCodePage_Next: expected 1/S_OK, got %u/%08x\n", n, ret);
740 cpinfo_cmp(&cpinfo[i + 1], &cpinfo2);
741 }
742
743 HeapFree(GetProcessHeap(), 0, cpinfo);
744 IEnumCodePage_Release(iEnumCP);
745 }
746
747 static void scriptinfo_cmp(SCRIPTINFO *sinfo1, SCRIPTINFO *sinfo2)
748 {
749 ok(sinfo1->ScriptId == sinfo2->ScriptId, "ScriptId mismatch: %d != %d\n", sinfo1->ScriptId, sinfo2->ScriptId);
750 ok(sinfo1->uiCodePage == sinfo2->uiCodePage, "uiCodePage mismatch: %u != %u\n", sinfo1->uiCodePage, sinfo2->uiCodePage);
751 ok(!lstrcmpW(sinfo1->wszDescription, sinfo2->wszDescription), "wszDescription mismatch\n");
752 ok(!lstrcmpW(sinfo1->wszFixedWidthFont, sinfo2->wszFixedWidthFont), "wszFixedWidthFont mismatch\n");
753 ok(!lstrcmpW(sinfo1->wszProportionalFont, sinfo2->wszProportionalFont), "wszProportionalFont mismatch\n");
754 }
755
756 static void test_EnumScripts(IMultiLanguage2 *iML2, DWORD flags)
757 {
758 IEnumScript *iEnumScript = NULL;
759 SCRIPTINFO *sinfo;
760 SCRIPTINFO sinfo2;
761 HRESULT ret;
762 ULONG i, n;
763 UINT total;
764
765 total = 0;
766 ret = IMultiLanguage2_GetNumberOfScripts(iML2, &total);
767 ok(ret == S_OK && total != 0, "IMultiLanguage2_GetNumberOfScripts: expected S_OK/!0, got %08x/%u\n", ret, total);
768
769 trace("total mlang supported scripts %u\n", total);
770
771 ret = IMultiLanguage2_EnumScripts(iML2, flags, LANG_NEUTRAL, &iEnumScript);
772 ok(ret == S_OK && iEnumScript, "IMultiLanguage2_EnumScripts: expected S_OK/!NULL, got %08x/%p\n", ret, iEnumScript);
773
774 ret = IEnumScript_Reset(iEnumScript);
775 ok(ret == S_OK, "IEnumScript_Reset: expected S_OK, got %08x\n", ret);
776 n = 65536;
777 ret = IEnumScript_Next(iEnumScript, 0, NULL, &n);
778 ok(n == 65536 && ret == E_FAIL, "IEnumScript_Next: expected 65536/E_FAIL, got %u/%08x\n", n, ret);
779 ret = IEnumScript_Next(iEnumScript, 0, NULL, NULL);
780 ok(ret == E_FAIL, "IEnumScript_Next: expected E_FAIL, got %08x\n", ret);
781
782 sinfo = HeapAlloc(GetProcessHeap(), 0, sizeof(*sinfo) * total * 2);
783
784 n = total * 2;
785 ret = IEnumScript_Next(iEnumScript, 0, sinfo, &n);
786 ok(ret == S_FALSE && n == 0, "IEnumScript_Next: expected S_FALSE/0, got %08x/%u\n", ret, n);
787
788 n = total * 2;
789 ret = IEnumScript_Next(iEnumScript, n, sinfo, &n);
790 ok(ret == S_OK && n != 0, "IEnumScript_Next: expected S_OK, got %08x/%u\n", ret, n);
791
792 trace("flags %08x, enumerated scripts %u\n", flags, n);
793
794 if (!flags)
795 {
796 ok(n == total, "IEnumScript_Next: expected %u, got %u\n", total, n);
797 flags = SCRIPTCONTF_SCRIPT_USER | SCRIPTCONTF_SCRIPT_HIDE | SCRIPTCONTF_SCRIPT_SYSTEM;
798 }
799
800 total = n;
801
802 for (i = 0; pGetCPInfoExA && i < n; i++)
803 {
804 #ifdef DUMP_SCRIPT_INFO
805 trace("SCRIPTINFO #%u:\n"
806 "ScriptId %08x\n"
807 "uiCodePage %u\n"
808 "wszDescription %s\n"
809 "wszFixedWidthFont %s\n"
810 "wszProportionalFont %s\n\n",
811 i,
812 sinfo[i].ScriptId,
813 sinfo[i].uiCodePage,
814 wine_dbgstr_w(sinfo[i].wszDescription),
815 wine_dbgstr_w(sinfo[i].wszFixedWidthFont),
816 wine_dbgstr_w(sinfo[i].wszProportionalFont));
817 trace("%u codepage %u\n", i, sinfo[i].uiCodePage);
818 #endif
819 }
820
821 /* now IEnumScript_Next should fail, since pointer is at the end */
822 n = 1;
823 ret = IEnumScript_Next(iEnumScript, 1, &sinfo2, &n);
824 ok(ret == S_FALSE && n == 0, "IEnumScript_Next: expected S_FALSE/0, got %08x/%u\n", ret, n);
825
826 ret = IEnumScript_Reset(iEnumScript);
827 ok(ret == S_OK, "IEnumScript_Reset: expected S_OK, got %08x\n", ret);
828 n = 0;
829 ret = IEnumScript_Next(iEnumScript, 1, &sinfo2, &n);
830 ok(n == 1 && ret == S_OK, "IEnumScript_Next: expected 1/S_OK, got %u/%08x\n", n, ret);
831 scriptinfo_cmp(&sinfo[0], &sinfo2);
832
833 if (0)
834 {
835 /* Due to a bug in MS' implementation of IEnumScript_Skip
836 * it's not used here.
837 */
838 ret = IEnumScript_Skip(iEnumScript, 1);
839 ok(ret == S_OK, "IEnumScript_Skip: expected S_OK, got %08x\n", ret);
840 }
841 for (i = 0; i < total - 1; i++)
842 {
843 n = 0;
844 ret = IEnumScript_Next(iEnumScript, 1, &sinfo2, &n);
845 ok(n == 1 && ret == S_OK, "IEnumScript_Next: expected 1/S_OK, got %u/%08x\n", n, ret);
846 scriptinfo_cmp(&sinfo[i + 1], &sinfo2);
847 }
848
849 HeapFree(GetProcessHeap(), 0, sinfo);
850 IEnumScript_Release(iEnumScript);
851 }
852
853 static void IMLangFontLink_Test(IMLangFontLink* iMLFL)
854 {
855 DWORD dwCodePages, dwManyCodePages;
856 DWORD dwCmpCodePages;
857 UINT CodePage;
858 static const WCHAR str[3] = { 'd', 0x0436, 0xff90 };
859 LONG processed;
860 HRESULT ret;
861
862 dwCodePages = ~0u;
863 ret = IMLangFontLink_CodePageToCodePages(iMLFL, -1, &dwCodePages);
864 ok(ret == E_FAIL, "IMLangFontLink_CodePageToCodePages should fail: %x\n", ret);
865 ok(dwCodePages == 0, "expected 0, got %u\n", dwCodePages);
866
867 dwCodePages = 0;
868 ret = IMLangFontLink_CodePageToCodePages(iMLFL, 932, &dwCodePages);
869 ok(ret == S_OK, "IMLangFontLink_CodePageToCodePages error %x\n", ret);
870 ok(dwCodePages == FS_JISJAPAN, "expected FS_JISJAPAN, got %08x\n", dwCodePages);
871 CodePage = 0;
872 ret = IMLangFontLink_CodePagesToCodePage(iMLFL, dwCodePages, 1035, &CodePage);
873 ok(ret == S_OK, "IMLangFontLink_CodePagesToCodePage error %x\n", ret);
874 ok(CodePage == 932, "Incorrect CodePage Returned (%i)\n",CodePage);
875
876 dwManyCodePages = 0;
877 ret = IMLangFontLink_CodePageToCodePages(iMLFL, 1252, &dwManyCodePages);
878 ok(ret == S_OK, "IMLangFontLink_CodePageToCodePages error %x\n", ret);
879 ok(dwManyCodePages == FS_LATIN1, "expected FS_LATIN1, got %08x\n", dwManyCodePages);
880 dwCodePages = 0;
881 ret = IMLangFontLink_CodePageToCodePages(iMLFL, 1256, &dwCodePages);
882 ok(ret == S_OK, "IMLangFontLink_CodePageToCodePages error %x\n", ret);
883 ok(dwCodePages == FS_ARABIC, "expected FS_ARABIC, got %08x\n", dwCodePages);
884 dwManyCodePages |= dwCodePages;
885 ret = IMLangFontLink_CodePageToCodePages(iMLFL, 874, &dwCodePages);
886 ok(ret == S_OK, "IMLangFontLink_CodePageToCodePages error %x\n", ret);
887 ok(dwCodePages == FS_THAI, "expected FS_THAI, got %08x\n", dwCodePages);
888 dwManyCodePages |= dwCodePages;
889
890 ret = IMLangFontLink_CodePagesToCodePage(iMLFL, dwManyCodePages, 1256, &CodePage);
891 ok(ret == S_OK, "IMLangFontLink_CodePagesToCodePage error %x\n", ret);
892 ok(CodePage == 1256, "Incorrect CodePage Returned (%i)\n",CodePage);
893
894 ret = IMLangFontLink_CodePagesToCodePage(iMLFL, dwManyCodePages, 936, &CodePage);
895 ok(ret == S_OK, "IMLangFontLink_CodePagesToCodePage error %x\n", ret);
896 ok(CodePage == 1252, "Incorrect CodePage Returned (%i)\n",CodePage);
897
898 /* Tests for GetCharCodePages */
899
900 /* Latin 1 */
901 dwCmpCodePages = FS_LATIN1 | FS_LATIN2 | FS_CYRILLIC | FS_GREEK | FS_TURKISH
902 | FS_HEBREW | FS_ARABIC | FS_BALTIC | FS_VIETNAMESE | FS_THAI
903 | FS_JISJAPAN | FS_CHINESESIMP | FS_WANSUNG | FS_CHINESETRAD;
904 ret = IMLangFontLink_GetCharCodePages(iMLFL, 'd', &dwCodePages);
905 ok(ret == S_OK, "IMLangFontLink_GetCharCodePages error %x\n", ret);
906 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
907
908 dwCodePages = 0;
909 processed = 0;
910 ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[0], 1, 0, &dwCodePages, &processed);
911 ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
912 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
913 ok(processed == 1, "expected 1, got %d\n", processed);
914
915 /* Cyrillic */
916 dwCmpCodePages = FS_CYRILLIC | FS_JISJAPAN | FS_CHINESESIMP | FS_WANSUNG;
917 ret = IMLangFontLink_GetCharCodePages(iMLFL, 0x0436, &dwCodePages);
918 ok(ret == S_OK, "IMLangFontLink_GetCharCodePages error %x\n", ret);
919 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
920
921 dwCodePages = 0;
922 processed = 0;
923 ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[1], 1, 0, &dwCodePages, &processed);
924 ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
925 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
926 ok(processed == 1, "expected 1, got %d\n", processed);
927
928 /* Japanese */
929 dwCmpCodePages = FS_JISJAPAN;
930 ret = IMLangFontLink_GetCharCodePages(iMLFL, 0xff90, &dwCodePages);
931 ok(ret == S_OK, "IMLangFontLink_GetCharCodePages error %x\n", ret);
932 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
933
934 dwCodePages = 0;
935 processed = 0;
936 ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[2], 1, 0, &dwCodePages, &processed);
937 ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
938 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
939 ok(processed == 1, "expected 1, got %d\n", processed);
940
941 dwCmpCodePages = FS_CYRILLIC | FS_JISJAPAN | FS_CHINESESIMP | FS_WANSUNG;
942 dwCodePages = 0;
943 processed = 0;
944 ret = IMLangFontLink_GetStrCodePages(iMLFL, str, 2, 0, &dwCodePages, &processed);
945 ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
946 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
947 ok(processed == 2, "expected 2, got %d\n", processed);
948
949 dwCmpCodePages = FS_JISJAPAN;
950 dwCodePages = 0;
951 processed = 0;
952 ret = IMLangFontLink_GetStrCodePages(iMLFL, str, 3, 0, &dwCodePages, &processed);
953 ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
954 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
955 ok(processed == 3, "expected 3, got %d\n", processed);
956
957 dwCodePages = 0xffff;
958 processed = -1;
959 ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[2], 1, 0, &dwCodePages, &processed);
960 ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
961 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
962 ok(processed == 1, "expected 0, got %d\n", processed);
963
964 ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[2], 1, 0, NULL, NULL);
965 ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
966
967 dwCodePages = 0xffff;
968 processed = -1;
969 ret = IMLangFontLink_GetStrCodePages(iMLFL, str, -1, 0, &dwCodePages, &processed);
970 ok(ret == E_INVALIDARG, "IMLangFontLink_GetStrCodePages should fail: %x\n", ret);
971 ok(dwCodePages == 0, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
972 ok(processed == 0, "expected 0, got %d\n", processed);
973
974 dwCodePages = 0xffff;
975 processed = -1;
976 ret = IMLangFontLink_GetStrCodePages(iMLFL, NULL, 1, 0, &dwCodePages, &processed);
977 ok(ret == E_INVALIDARG, "IMLangFontLink_GetStrCodePages should fail: %x\n", ret);
978 ok(dwCodePages == 0, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
979 ok(processed == 0, "expected 0, got %d\n", processed);
980
981 dwCodePages = 0xffff;
982 processed = -1;
983 ret = IMLangFontLink_GetStrCodePages(iMLFL, str, 0, 0, &dwCodePages, &processed);
984 ok(ret == E_INVALIDARG, "IMLangFontLink_GetStrCodePages should fail: %x\n", ret);
985 ok(dwCodePages == 0, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
986 ok(processed == 0, "expected 0, got %d\n", processed);
987 }
988
989 /* copied from libs/wine/string.c */
990 static WCHAR *strstrW(const WCHAR *str, const WCHAR *sub)
991 {
992 while (*str)
993 {
994 const WCHAR *p1 = str, *p2 = sub;
995 while (*p1 && *p2 && *p1 == *p2) { p1++; p2++; }
996 if (!*p2) return (WCHAR *)str;
997 str++;
998 }
999 return NULL;
1000 }
1001
1002 static void test_rfc1766(IMultiLanguage2 *iML2)
1003 {
1004 IEnumRfc1766 *pEnumRfc1766;
1005 RFC1766INFO info;
1006 ULONG n;
1007 HRESULT ret;
1008 BSTR rfcstr;
1009
1010 ret = IMultiLanguage2_EnumRfc1766(iML2, LANG_NEUTRAL, &pEnumRfc1766);
1011 ok(ret == S_OK, "IMultiLanguage2_EnumRfc1766 error %08x\n", ret);
1012
1013 while (1)
1014 {
1015 ret = IEnumRfc1766_Next(pEnumRfc1766, 1, &info, &n);
1016 if (ret != S_OK) break;
1017
1018 #ifdef DUMP_CP_INFO
1019 trace("lcid %04x rfc_name %s locale_name %s\n",
1020 info.lcid, wine_dbgstr_w(info.wszRfc1766), wine_dbgstr_w(info.wszLocaleName));
1021 #endif
1022
1023 ok(n == 1, "couldn't fetch 1 RFC1766INFO structure\n");
1024
1025 /* verify the Rfc1766 value */
1026 ret = IMultiLanguage2_GetRfc1766FromLcid(iML2, info.lcid, &rfcstr);
1027 ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
1028
1029 /* not an exact 1:1 correspondence between lcid and rfc1766 in the
1030 * mlang database, e.g., nb-no -> 1044 -> no */
1031 ok(strstrW(info.wszRfc1766, rfcstr) != NULL,
1032 "Expected matching locale names\n");
1033
1034 SysFreeString(rfcstr);
1035 }
1036 IEnumRfc1766_Release(pEnumRfc1766);
1037 }
1038
1039 static void test_GetLcidFromRfc1766(IMultiLanguage2 *iML2)
1040 {
1041 WCHAR rfc1766W[MAX_RFC1766_NAME + 1];
1042 LCID lcid;
1043 HRESULT ret;
1044 DWORD i;
1045
1046 static WCHAR en[] = { 'e','n',0 };
1047 static WCHAR en_them[] = { 'e','n','-','t','h','e','m',0 };
1048 static WCHAR english[] = { 'e','n','g','l','i','s','h',0 };
1049
1050
1051 for(i = 0; i < sizeof(lcid_table) / sizeof(lcid_table[0]); i++) {
1052 lcid = -1;
1053 MultiByteToWideChar(CP_ACP, 0, lcid_table[i].rfc1766, -1, rfc1766W, MAX_RFC1766_NAME);
1054 ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, rfc1766W);
1055
1056 /* IE <6.0 guess 0x412 (ko) from "kok" */
1057 ok((ret == lcid_table[i].hr) ||
1058 broken(lcid_table[i].broken_lcid && (ret == S_FALSE)),
1059 "#%02d: HRESULT 0x%x (expected 0x%x)\n", i, ret, lcid_table[i].hr);
1060
1061 ok((lcid == lcid_table[i].lcid) ||
1062 broken(lcid == lcid_table[i].broken_lcid), /* IE <6.0 */
1063 "#%02d: got LCID 0x%x (expected 0x%x)\n", i, lcid, lcid_table[i].lcid);
1064 }
1065
1066
1067 ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, NULL, en);
1068 ok(ret == E_INVALIDARG, "GetLcidFromRfc1766 returned: %08x\n", ret);
1069
1070 ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, NULL);
1071 ok(ret == E_INVALIDARG, "GetLcidFromRfc1766 returned: %08x\n", ret);
1072
1073 ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, en_them);
1074 ok((ret == E_FAIL || ret == S_FALSE), "GetLcidFromRfc1766 returned: %08x\n", ret);
1075 if (ret == S_FALSE)
1076 {
1077 BSTR rfcstr;
1078 static WCHAR en[] = {'e','n',0};
1079
1080 ret = IMultiLanguage2_GetRfc1766FromLcid(iML2, lcid, &rfcstr);
1081 ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
1082 ok_w2("Expected \"%s\", got \"%s\"n", en, rfcstr);
1083 }
1084
1085 ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, english);
1086 ok((ret == E_FAIL || ret == S_FALSE), "GetLcidFromRfc1766 returned: %08x\n", ret);
1087 if (ret == S_FALSE)
1088 {
1089 BSTR rfcstr;
1090 static WCHAR en[] = {'e','n',0};
1091
1092 ret = IMultiLanguage2_GetRfc1766FromLcid(iML2, lcid, &rfcstr);
1093 ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
1094 ok_w2("Expected \"%s\", got \"%s\"n", en, rfcstr);
1095 }
1096
1097 }
1098
1099 static void test_Rfc1766ToLcid(void)
1100 {
1101 LCID lcid;
1102 HRESULT ret;
1103 DWORD i;
1104
1105 for(i = 0; i < sizeof(lcid_table) / sizeof(lcid_table[0]); i++) {
1106 lcid = -1;
1107 ret = pRfc1766ToLcidA(&lcid, lcid_table[i].rfc1766);
1108
1109 /* IE <6.0 guess 0x412 (ko) from "kok" */
1110 ok( (ret == lcid_table[i].hr) ||
1111 broken(lcid_table[i].broken_lcid && (ret == S_FALSE)),
1112 "#%02d: HRESULT 0x%x (expected 0x%x)\n", i, ret, lcid_table[i].hr);
1113
1114 ok( (lcid == lcid_table[i].lcid) ||
1115 broken(lcid == lcid_table[i].broken_lcid), /* IE <6.0 */
1116 "#%02d: got LCID 0x%x (expected 0x%x)\n", i, lcid, lcid_table[i].lcid);
1117 }
1118
1119 ret = pRfc1766ToLcidA(&lcid, NULL);
1120 ok(ret == E_INVALIDARG, "got 0x%08x (expected E_INVALIDARG)\n", ret);
1121
1122 ret = pRfc1766ToLcidA(NULL, "en");
1123 ok(ret == E_INVALIDARG, "got 0x%08x (expected E_INVALIDARG)\n", ret);
1124 }
1125
1126 static void test_GetNumberOfCodePageInfo(IMultiLanguage2 *iML2)
1127 {
1128 HRESULT hr;
1129 UINT value;
1130
1131 value = 0xdeadbeef;
1132 hr = IMultiLanguage2_GetNumberOfCodePageInfo(iML2, &value);
1133 ok( (hr == S_OK) && value,
1134 "got 0x%x with %d (expected S_OK with '!= 0')\n", hr, value);
1135
1136 hr = IMultiLanguage2_GetNumberOfCodePageInfo(iML2, NULL);
1137 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
1138
1139 }
1140
1141 static void test_GetRfc1766FromLcid(IMultiLanguage2 *iML2)
1142 {
1143 CHAR expected[MAX_RFC1766_NAME];
1144 CHAR buffer[MAX_RFC1766_NAME + 1];
1145 DWORD i;
1146 HRESULT hr;
1147 BSTR rfcstr;
1148
1149 for(i = 0; i < sizeof(lcid_table) / sizeof(lcid_table[0]); i++) {
1150 buffer[0] = '\0';
1151
1152 rfcstr = NULL;
1153 hr = IMultiLanguage2_GetRfc1766FromLcid(iML2, lcid_table[i].lcid, &rfcstr);
1154 ok(hr == lcid_table[i].hr,
1155 "#%02d: HRESULT 0x%x (expected 0x%x)\n", i, hr, lcid_table[i].hr);
1156
1157 if (hr != S_OK)
1158 continue; /* no result-string created */
1159
1160 WideCharToMultiByte(CP_ACP, 0, rfcstr, -1, buffer, sizeof(buffer), NULL, NULL);
1161 LCMapStringA(LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, lcid_table[i].rfc1766,
1162 lstrlenA(lcid_table[i].rfc1766) + 1, expected, MAX_RFC1766_NAME);
1163
1164 /* IE <6.0 return "x-kok" for LCID 0x457 ("kok") */
1165 ok( (!lstrcmpA(buffer, expected)) ||
1166 broken(!lstrcmpA(buffer, lcid_table[i].broken_rfc)),
1167 "#%02d: got '%s' (expected '%s')\n", i, buffer, expected);
1168
1169 SysFreeString(rfcstr);
1170 }
1171
1172 hr = IMultiLanguage2_GetRfc1766FromLcid(iML2, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NULL);
1173 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
1174 }
1175
1176 static void test_LcidToRfc1766(void)
1177 {
1178 CHAR expected[MAX_RFC1766_NAME];
1179 CHAR buffer[MAX_RFC1766_NAME * 2];
1180 HRESULT hr;
1181 DWORD i;
1182
1183 for(i = 0; i < sizeof(lcid_table) / sizeof(lcid_table[0]); i++) {
1184
1185 memset(buffer, '#', sizeof(buffer)-1);
1186 buffer[sizeof(buffer)-1] = '\0';
1187
1188 hr = pLcidToRfc1766A(lcid_table[i].lcid, buffer, MAX_RFC1766_NAME);
1189
1190 /* IE <5.0 does not recognize 0x180c (fr-mc) and 0x457 (kok) */
1191 ok( (hr == lcid_table[i].hr) ||
1192 broken(lcid_table[i].broken_lcid && (hr == E_FAIL)),
1193 "#%02d: HRESULT 0x%x (expected 0x%x)\n", i, hr, lcid_table[i].hr);
1194
1195 if (hr != S_OK)
1196 continue;
1197
1198 LCMapStringA(LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, lcid_table[i].rfc1766,
1199 lstrlenA(lcid_table[i].rfc1766) + 1, expected, MAX_RFC1766_NAME);
1200
1201 /* IE <6.0 return "x-kok" for LCID 0x457 ("kok") */
1202 /* IE <5.0 return "fr" for LCID 0x180c ("fr-mc") */
1203 ok( (!lstrcmpA(buffer, expected)) ||
1204 broken(!lstrcmpA(buffer, lcid_table[i].broken_rfc)),
1205 "#%02d: got '%s' (expected '%s')\n", i, buffer, expected);
1206
1207 }
1208
1209 memset(buffer, '#', sizeof(buffer)-1);
1210 buffer[sizeof(buffer)-1] = '\0';
1211 hr = pLcidToRfc1766A(-1, buffer, MAX_RFC1766_NAME);
1212 ok(hr == E_FAIL, "got 0x%08x and '%s' (expected E_FAIL)\n", hr, buffer);
1213
1214 hr = pLcidToRfc1766A(LANG_ENGLISH, NULL, MAX_RFC1766_NAME);
1215 ok(hr == E_INVALIDARG, "got 0x%08x (expected E_INVALIDARG)\n", hr);
1216
1217 memset(buffer, '#', sizeof(buffer)-1);
1218 buffer[sizeof(buffer)-1] = '\0';
1219 hr = pLcidToRfc1766A(LANG_ENGLISH, buffer, -1);
1220 ok(hr == E_INVALIDARG, "got 0x%08x and '%s' (expected E_INVALIDARG)\n", hr, buffer);
1221
1222 memset(buffer, '#', sizeof(buffer)-1);
1223 buffer[sizeof(buffer)-1] = '\0';
1224 hr = pLcidToRfc1766A(LANG_ENGLISH, buffer, 0);
1225 ok(hr == E_INVALIDARG, "got 0x%08x and '%s' (expected E_INVALIDARG)\n", hr, buffer);
1226 }
1227
1228 static void test_GetRfc1766Info(IMultiLanguage2 *iML2)
1229 {
1230 WCHAR short_broken_name[MAX_LOCALE_NAME];
1231 CHAR rfc1766A[MAX_RFC1766_NAME + 1];
1232 BYTE buffer[sizeof(RFC1766INFO) + 4];
1233 PRFC1766INFO prfc = (RFC1766INFO *) buffer;
1234 HRESULT ret;
1235 DWORD i;
1236
1237 for(i = 0; i < sizeof(info_table) / sizeof(info_table[0]); i++) {
1238 memset(buffer, 'x', sizeof(RFC1766INFO) + 2);
1239 buffer[sizeof(buffer) -1] = 0;
1240 buffer[sizeof(buffer) -2] = 0;
1241
1242 ret = IMultiLanguage2_GetRfc1766Info(iML2, info_table[i].lcid, info_table[i].lang, prfc);
1243 WideCharToMultiByte(CP_ACP, 0, prfc->wszRfc1766, -1, rfc1766A, MAX_RFC1766_NAME, NULL, NULL);
1244 ok(ret == S_OK, "#%02d: got 0x%x (expected S_OK)\n", i, ret);
1245 ok(prfc->lcid == info_table[i].lcid,
1246 "#%02d: got 0x%04x (expected 0x%04x)\n", i, prfc->lcid, info_table[i].lcid);
1247
1248 ok(!lstrcmpA(rfc1766A, info_table[i].rfc1766),
1249 "#%02d: got '%s' (expected '%s')\n", i, rfc1766A, info_table[i].rfc1766);
1250
1251 /* Some IE versions truncate an oversized name one character to short */
1252 mylstrcpyW(short_broken_name, info_table[i].broken_name);
1253 short_broken_name[MAX_LOCALE_NAME - 2] = '\0';
1254
1255 if (info_table[i].todo & TODO_NAME) {
1256 todo_wine
1257 ok( (!mylstrcmpW(prfc->wszLocaleName, info_table[i].localename)) ||
1258 broken(!mylstrcmpW(prfc->wszLocaleName, info_table[i].broken_name)) || /* IE < 6.0 */
1259 broken(!mylstrcmpW(prfc->wszLocaleName, short_broken_name)),
1260 "#%02d: got %s (expected %s)\n", i,
1261 wine_dbgstr_w(prfc->wszLocaleName), wine_dbgstr_w(info_table[i].localename));
1262 }
1263 else
1264 ok( (!mylstrcmpW(prfc->wszLocaleName, info_table[i].localename)) ||
1265 broken(!mylstrcmpW(prfc->wszLocaleName, info_table[i].broken_name)) || /* IE < 6.0 */
1266 broken(!mylstrcmpW(prfc->wszLocaleName, short_broken_name)),
1267 "#%02d: got %s (expected %s)\n", i,
1268 wine_dbgstr_w(prfc->wszLocaleName), wine_dbgstr_w(info_table[i].localename));
1269
1270 }
1271
1272 /* SUBLANG_NEUTRAL only allowed for english, arabic, chinese */
1273 ret = IMultiLanguage2_GetRfc1766Info(iML2, MAKELANGID(LANG_GERMAN, SUBLANG_NEUTRAL), LANG_ENGLISH, prfc);
1274 ok(ret == E_FAIL, "got 0x%x (expected E_FAIL)\n", ret);
1275
1276 ret = IMultiLanguage2_GetRfc1766Info(iML2, MAKELANGID(LANG_ITALIAN, SUBLANG_NEUTRAL), LANG_ENGLISH, prfc);
1277 ok(ret == E_FAIL, "got 0x%x (expected E_FAIL)\n", ret);
1278
1279 /* NULL not allowed */
1280 ret = IMultiLanguage2_GetRfc1766Info(iML2, 0, LANG_ENGLISH, prfc);
1281 ok(ret == E_FAIL, "got 0x%x (expected E_FAIL)\n", ret);
1282
1283 ret = IMultiLanguage2_GetRfc1766Info(iML2, LANG_ENGLISH, LANG_ENGLISH, NULL);
1284 ok(ret == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", ret);
1285 }
1286
1287 static void test_IMultiLanguage2_ConvertStringFromUnicode(IMultiLanguage2 *iML2)
1288 {
1289 CHAR dest[MAX_PATH];
1290 CHAR invariate[MAX_PATH];
1291 UINT srcsz, destsz;
1292 HRESULT hr;
1293
1294 static WCHAR src[] = {'a','b','c',0};
1295
1296 memset(invariate, 'x', sizeof(invariate));
1297
1298 /* pSrcStr NULL */
1299 memset(dest, 'x', sizeof(dest));
1300 srcsz = lstrlenW(src) + 1;
1301 destsz = sizeof(dest);
1302 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, NULL,
1303 &srcsz, dest, &destsz);
1304 ok(hr == S_OK || hr == E_FAIL,"expected S_OK or E_FAIL, got %08x\n",hr);
1305 if (hr == S_OK)
1306 {
1307 ok(srcsz == lstrlenW(src) + 1,
1308 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1309 }
1310 else if (hr == E_FAIL)
1311 {
1312 ok(srcsz == 0,
1313 "Expected %u, got %u\n", 0, srcsz);
1314 }
1315
1316 ok(!memcmp(dest, invariate, sizeof(dest)),
1317 "Expected dest to be unchanged, got %s\n", dest);
1318 ok(destsz == 0, "Expected 0, got %u\n", destsz);
1319
1320 /* pcSrcSize NULL */
1321 memset(dest, 'x', sizeof(dest));
1322 destsz = sizeof(dest);
1323 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1324 NULL, dest, &destsz);
1325 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1326 ok(!strncmp(dest, "abc", 3),
1327 "Expected first three chars to be \"abc\"\n");
1328 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1329 "Expected rest of dest to be unchanged, got %s\n", dest);
1330 ok(destsz == lstrlenW(src),
1331 "Expected %u, got %u\n", lstrlenW(src), destsz);
1332
1333 /* both pSrcStr and pcSrcSize NULL */
1334 memset(dest, 'x', sizeof(dest));
1335 destsz = sizeof(dest);
1336 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, NULL,
1337 NULL, dest, &destsz);
1338 ok(hr == S_OK || hr == E_FAIL, "Expected S_OK or E_FAIL, got %08x\n", hr);
1339 ok(!memcmp(dest, invariate, sizeof(dest)),
1340 "Expected dest to be unchanged, got %s\n", dest);
1341 ok(destsz == 0, "Expected 0, got %u\n", destsz);
1342
1343 /* pDstStr NULL */
1344 memset(dest, 'x', sizeof(dest));
1345 srcsz = lstrlenW(src) + 1;
1346 destsz = sizeof(dest);
1347 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1348 &srcsz, NULL, &destsz);
1349 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1350 ok(srcsz == lstrlenW(src) + 1,
1351 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1352 ok(destsz == lstrlenW(src) + 1,
1353 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1354
1355 /* pcDstSize NULL */
1356 memset(dest, 'x', sizeof(dest));
1357 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1358 &srcsz, dest, NULL);
1359 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1360 ok(srcsz == lstrlenW(src) + 1,
1361 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1362 ok(!memcmp(dest, invariate, sizeof(dest)),
1363 "Expected dest to be unchanged, got %s\n", dest);
1364
1365 /* pcSrcSize is 0 */
1366 memset(dest, 'x', sizeof(dest));
1367 srcsz = 0;
1368 destsz = sizeof(dest);
1369 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1370 &srcsz, dest, &destsz);
1371 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1372 ok(srcsz == 0, "Expected 0, got %u\n", srcsz);
1373 ok(!memcmp(dest, invariate, sizeof(dest)),
1374 "Expected dest to be unchanged, got %s\n", dest);
1375 ok(destsz == 0, "Expected 0, got %u\n", destsz);
1376
1377 /* pcSrcSize does not include NULL terminator */
1378 memset(dest, 'x', sizeof(dest));
1379 srcsz = lstrlenW(src);
1380 destsz = sizeof(dest);
1381 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1382 &srcsz, dest, &destsz);
1383 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1384 ok(srcsz == lstrlenW(src),
1385 "Expected %u, got %u\n", lstrlenW(src), srcsz);
1386 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1387 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1388 "Expected rest of dest to be unchanged, got %s\n", dest);
1389 ok(destsz == lstrlenW(src),
1390 "Expected %u, got %u\n", lstrlenW(src), destsz);
1391
1392 /* pcSrcSize includes NULL terminator */
1393 memset(dest, 'x', sizeof(dest));
1394 srcsz = lstrlenW(src) + 1;
1395 destsz = sizeof(dest);
1396 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1397 &srcsz, dest, &destsz);
1398 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1399 ok(srcsz == lstrlenW(src) + 1, "Expected 3, got %u\n", srcsz);
1400 ok(!lstrcmpA(dest, "abc"), "Expected \"abc\", got \"%s\"\n", dest);
1401 ok(destsz == lstrlenW(src) + 1,
1402 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1403
1404 /* pcSrcSize is -1 */
1405 memset(dest, 'x', sizeof(dest));
1406 srcsz = -1;
1407 destsz = sizeof(dest);
1408 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1409 &srcsz, dest, &destsz);
1410 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1411 ok(srcsz == lstrlenW(src),
1412 "Expected %u, got %u\n", lstrlenW(src), srcsz);
1413 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1414 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1415 "Expected rest of dest to be unchanged, got %s\n", dest);
1416 ok(destsz == lstrlenW(src),
1417 "Expected %u, got %u\n", lstrlenW(src), destsz);
1418
1419 /* pcDstSize is 0 */
1420 memset(dest, 'x', sizeof(dest));
1421 srcsz = lstrlenW(src) + 1;
1422 destsz = 0;
1423 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1424 &srcsz, dest, &destsz);
1425 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1426 ok(srcsz == lstrlenW(src) + 1,
1427 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1428 ok(!memcmp(dest, invariate, sizeof(dest)),
1429 "Expected dest to be unchanged, got %s\n", dest);
1430 ok(destsz == lstrlenW(src) + 1,
1431 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1432
1433 /* pcDstSize is not large enough */
1434 memset(dest, 'x', sizeof(dest));
1435 srcsz = lstrlenW(src) + 1;
1436 destsz = lstrlenW(src);
1437 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1438 &srcsz, dest, &destsz);
1439 ok(hr == E_FAIL, "Expected E_FAIL, got %08x\n", hr);
1440 ok(srcsz == 0, "Expected 0, got %u\n", srcsz);
1441 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1442 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1443 "Expected rest of dest to be unchanged, got %s\n", dest);
1444 ok(destsz == 0, "Expected 0, got %u\n", srcsz);
1445
1446 /* pcDstSize (bytes) does not leave room for NULL terminator */
1447 memset(dest, 'x', sizeof(dest));
1448 srcsz = lstrlenW(src) + 1;
1449 destsz = lstrlenW(src) * sizeof(WCHAR);
1450 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1451 &srcsz, dest, &destsz);
1452 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1453 ok(srcsz == lstrlenW(src) + 1,
1454 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1455 ok(!lstrcmpA(dest, "abc"), "Expected \"abc\", got \"%s\"\n", dest);
1456 ok(destsz == lstrlenW(src) + 1,
1457 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1458 }
1459
1460 static void test_ConvertINetUnicodeToMultiByte(void)
1461 {
1462 CHAR dest[MAX_PATH];
1463 CHAR invariate[MAX_PATH];
1464 INT srcsz, destsz;
1465 HRESULT hr;
1466
1467 static WCHAR src[] = {'a','b','c',0};
1468
1469 memset(invariate, 'x', sizeof(invariate));
1470
1471 /* lpSrcStr NULL */
1472 memset(dest, 'x', sizeof(dest));
1473 srcsz = lstrlenW(src) + 1;
1474 destsz = sizeof(dest);
1475 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, NULL, &srcsz, dest, &destsz);
1476 ok(hr == S_OK || hr == E_FAIL, "Expected S_OK or E_FAIL, got %08x\n", hr);
1477 if (hr == S_OK)
1478 ok(srcsz == lstrlenW(src) + 1,
1479 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1480 else if (hr == E_FAIL)
1481 ok(srcsz == 0,
1482 "Expected %u, got %u\n", 0, srcsz);
1483 ok(!memcmp(dest, invariate, sizeof(dest)),
1484 "Expected dest to be unchanged, got %s\n", dest);
1485 ok(destsz == 0, "Expected 0, got %u\n", destsz);
1486
1487 /* lpnWideCharCount NULL */
1488 memset(dest, 'x', sizeof(dest));
1489 destsz = sizeof(dest);
1490 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, NULL, dest, &destsz);
1491 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1492 ok(!strncmp(dest, "abc", 3),
1493 "Expected first three chars to be \"abc\"\n");
1494 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1495 "Expected rest of dest to be unchanged, got %s\n", dest);
1496 ok(destsz == lstrlenW(src),
1497 "Expected %u, got %u\n", lstrlenW(src), destsz);
1498
1499 /* both lpSrcStr and lpnWideCharCount NULL */
1500 memset(dest, 'x', sizeof(dest));
1501 destsz = sizeof(dest);
1502 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, NULL, NULL, dest, &destsz);
1503 ok(hr == S_OK || hr == E_FAIL, "Expected S_OK or E_FAIL, got %08x\n", hr);
1504 ok(!memcmp(dest, invariate, sizeof(dest)),
1505 "Expected dest to be unchanged, got %s\n", dest);
1506 ok(destsz == 0, "Expected 0, got %u\n", destsz);
1507
1508 /* lpDstStr NULL */
1509 memset(dest, 'x', sizeof(dest));
1510 srcsz = lstrlenW(src) + 1;
1511 destsz = sizeof(dest);
1512 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, NULL, &destsz);
1513 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1514 ok(srcsz == lstrlenW(src) + 1,
1515 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1516 ok(destsz == lstrlenW(src) + 1,
1517 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1518
1519 /* lpnMultiCharCount NULL */
1520 memset(dest, 'x', sizeof(dest));
1521 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, NULL);
1522 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1523 ok(srcsz == lstrlenW(src) + 1,
1524 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1525 ok(!memcmp(dest, invariate, sizeof(dest)),
1526 "Expected dest to be unchanged, got %s\n", dest);
1527
1528 /* lpnWideCharCount is 0 */
1529 memset(dest, 'x', sizeof(dest));
1530 srcsz = 0;
1531 destsz = sizeof(dest);
1532 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1533 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1534 ok(srcsz == 0, "Expected 0, got %u\n", srcsz);
1535 ok(!memcmp(dest, invariate, sizeof(dest)),
1536 "Expected dest to be unchanged, got %s\n", dest);
1537 ok(destsz == 0, "Expected 0, got %u\n", destsz);
1538
1539 /* lpnWideCharCount does not include NULL terminator */
1540 memset(dest, 'x', sizeof(dest));
1541 srcsz = lstrlenW(src);
1542 destsz = sizeof(dest);
1543 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1544 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1545 ok(srcsz == lstrlenW(src),
1546 "Expected %u, got %u\n", lstrlenW(src), srcsz);
1547 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1548 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1549 "Expected rest of dest to be unchanged, got %s\n", dest);
1550 ok(destsz == lstrlenW(src),
1551 "Expected %u, got %u\n", lstrlenW(src), destsz);
1552
1553 /* lpnWideCharCount includes NULL terminator */
1554 memset(dest, 'x', sizeof(dest));
1555 srcsz = lstrlenW(src) + 1;
1556 destsz = sizeof(dest);
1557 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1558 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1559 ok(srcsz == lstrlenW(src) + 1, "Expected 3, got %u\n", srcsz);
1560 ok(!lstrcmpA(dest, "abc"), "Expected \"abc\", got \"%s\"\n", dest);
1561 ok(destsz == lstrlenW(src) + 1,
1562 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1563
1564 /* lpnWideCharCount is -1 */
1565 memset(dest, 'x', sizeof(dest));
1566 srcsz = -1;
1567 destsz = sizeof(dest);
1568 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1569 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1570 ok(srcsz == lstrlenW(src),
1571 "Expected %u, got %u\n", lstrlenW(src), srcsz);
1572 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1573 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1574 "Expected rest of dest to be unchanged, got %s\n", dest);
1575 ok(destsz == lstrlenW(src),
1576 "Expected %u, got %u\n", lstrlenW(src), destsz);
1577
1578 /* lpnMultiCharCount is 0 */
1579 memset(dest, 'x', sizeof(dest));
1580 srcsz = lstrlenW(src) + 1;
1581 destsz = 0;
1582 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1583 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1584 ok(srcsz == lstrlenW(src) + 1,
1585 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1586 ok(!memcmp(dest, invariate, sizeof(dest)),
1587 "Expected dest to be unchanged, got %s\n", dest);
1588 ok(destsz == lstrlenW(src) + 1,
1589 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1590
1591 /* lpnMultiCharCount is not large enough */
1592 memset(dest, 'x', sizeof(dest));
1593 srcsz = lstrlenW(src) + 1;
1594 destsz = lstrlenW(src);
1595 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1596 ok(hr == E_FAIL, "Expected E_FAIL, got %08x\n", hr);
1597 ok(srcsz == 0, "Expected 0, got %u\n", srcsz);
1598 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1599 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1600 "Expected rest of dest to be unchanged, got %s\n", dest);
1601 ok(destsz == 0, "Expected 0, got %u\n", srcsz);
1602
1603 /* lpnMultiCharCount (bytes) does not leave room for NULL terminator */
1604 memset(dest, 'x', sizeof(dest));
1605 srcsz = lstrlenW(src) + 1;
1606 destsz = lstrlenW(src) * sizeof(WCHAR);
1607 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1608 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1609 ok(srcsz == lstrlenW(src) + 1,
1610 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1611 ok(!lstrcmpA(dest, "abc"), "Expected \"abc\", got \"%s\"\n", dest);
1612 ok(destsz == lstrlenW(src) + 1,
1613 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1614 }
1615
1616 static void test_JapaneseConversion(void)
1617 {
1618 /* Data */
1619 static WCHAR unc_jp[9][12] = {
1620 {9,0x31,0x20,0x3042,0x3044,0x3046,0x3048,0x304a,0x000d,0x000a},
1621 {9,0x31,0x20,0x30a2,0x30a4,0x30a6,0x30a8,0x30aa,0x000d,0x000a},
1622 {9,0x31,0x20,0xff71,0xff72,0xff73,0xff74,0xff75,0x000d,0x000a},
1623 {9,0x31,0x20,0x3041,0x3043,0x3045,0x3047,0x3049,0x000d,0x000a},
1624 {9,0x31,0x20,0x30a1,0x30a3,0x30a5,0x30a7,0x30a9,0x000d,0x000a},
1625 {9,0x31,0x20,0xff67,0xff68,0xff69,0xff6a,0xff6b,0x000d,0x000a},
1626 {9,0x31,0x20,0x300c,0x65e5,0x672c,0x8a9e,0x300d,0x000d,0x000a},
1627 {7,0x31,0x20,0x25c7,0x25c7,0x3012,0x000d,0x000a},
1628 {11,0x31,0x20,0x203b,0x3010,0x0074,0x0065,0x0073,0x0074,0x3011,0x000d,0x000a}
1629 };
1630 static CHAR jis_jp[9][27] = {
1631 {20,0x31,0x20,0x1b,0x24,0x42,0x24,0x22,0x24,0x24,0x24,0x26,0x24,0x28,
1632 0x24,0x2a,0x1b,0x28,0x42,0x0d,0x0a},
1633 {20,0x31,0x20,0x1b,0x24,0x42,0x25,0x22,0x25,0x24,0x25,0x26,0x25,0x28,
1634 0x25,0x2a,0x1b,0x28,0x42,0x0d,0x0a},
1635 {20,0x31,0x20,0x1b,0x24,0x42,0x25,0x22,0x25,0x24,0x25,0x26,0x25,0x28,
1636 0x25,0x2a,0x1b,0x28,0x42,0x0d,0x0a},
1637 {20,0x31,0x20,0x1b,0x24,0x42,0x24,0x21,0x24,0x23,0x24,0x25,0x24,0x27,
1638 0x24,0x29,0x1b,0x28,0x42,0x0d,0x0a},
1639 {20,0x31,0x20,0x1b,0x24,0x42,0x25,0x21,0x25,0x23,0x25,0x25,0x25,0x27,
1640 0x25,0x29,0x1b,0x28,0x42,0x0d,0x0a},
1641 {20,0x31,0x20,0x1b,0x24,0x42,0x25,0x21,0x25,0x23,0x25,0x25,0x25,0x27,
1642 0x25,0x29,0x1b,0x28,0x42,0x0d,0x0a},
1643 {20,0x31,0x20,0x1b,0x24,0x42,0x21,0x56,0x46,0x7c,0x4b,0x5c,0x38,0x6c,
1644 0x21,0x57,0x1b,0x28,0x42,0x0d,0x0a},
1645 {16,0x31,0x20,0x1b,0x24,0x42,0x21,0x7e,0x21,0x7e,0x22,0x29,0x1b,0x28,
1646 0x42,0x0d,0x0a},
1647 {26,0x31,0x20,0x1b,0x24,0x42,0x22,0x28,0x21,0x5a,0x1b,0x28,0x42,0x74,
1648 0x65,0x73,0x74,0x1b,0x24,0x42,0x21,0x5b,0x1b,0x28,0x42,0x0d,0x0a}
1649 };
1650 static CHAR sjis_jp[9][15] = {
1651 {14,0x31,0x20,0x82,0xa0,0x82,0xa2,0x82,0xa4,0x82,0xa6,0x82,0xa8,0x0d,0x0a},
1652 {14,0x31,0x20,0x83,0x41,0x83,0x43,0x83,0x45,0x83,0x47,0x83,0x49,0x0d,0x0a},
1653 {9,0x31,0x20,0xb1,0xb2,0xb3,0xb4,0xb5,0x0d,0x0a},
1654 {14,0x31,0x20,0x82,0x9f,0x82,0xa1,0x82,0xa3,0x82,0xa5,0x82,0xa7,0x0d,0x0a},
1655 {14,0x31,0x20,0x83,0x40,0x83,0x42,0x83,0x44,0x83,0x46,0x83,0x48,0x0d,0x0a},
1656 {9,0x31,0x20,0xa7,0xa8,0xa9,0xaa,0xab,0x0d,0x0a},
1657 {14,0x31,0x20,0x81,0x75,0x93,0xfa,0x96,0x7b,0x8c,0xea,0x81,0x76,0x0d,0x0a},
1658 {10,0x31,0x20,0x81,0x9e,0x81,0x9e,0x81,0xa7,0x0d,0x0a},
1659 {14,0x31,0x20,0x81,0xa6,0x81,0x79,0x74,0x65,0x73,0x74,0x81,0x7a,0x0d,0x0a}
1660 };
1661 static CHAR euc_jp[9][15] = {
1662 {14,0x31,0x20,0xa4,0xa2,0xa4,0xa4,0xa4,0xa6,0xa4,0xa8,0xa4,0xaa,0x0d,0x0a},
1663 {14,0x31,0x20,0xa5,0xa2,0xa5,0xa4,0xa5,0xa6,0xa5,0xa8,0xa5,0xaa,0x0d,0x0a},
1664 {14,0x31,0x20,0x8e,0xb1,0x8e,0xb2,0x8e,0xb3,0x8e,0xb4,0x8e,0xb5,0x0d,0x0a},
1665 {14,0x31,0x20,0xa4,0xa1,0xa4,0xa3,0xa4,0xa5,0xa4,0xa7,0xa4,0xa9,0x0d,0x0a},
1666 {14,0x31,0x20,0xa5,0xa1,0xa5,0xa3,0xa5,0xa5,0xa5,0xa7,0xa5,0xa9,0x0d,0x0a},
1667 {14,0x31,0x20,0x8e,0xa7,0x8e,0xa8,0x8e,0xa9,0x8e,0xaa,0x8e,0xab,0x0d,0x0a},
1668 {14,0x31,0x20,0xa1,0xd6,0xc6,0xfc,0xcb,0xdc,0xb8,0xec,0xa1,0xd7,0x0d,0x0a},
1669 {10,0x31,0x20,0xa1,0xfe,0xa1,0xfe,0xa2,0xa9,0x0d,0x0a},
1670 {14,0x31,0x20,0xa2,0xa8,0xa1,0xda,0x74,0x65,0x73,0x74,0xa1,0xdb,0x0d,0x0a}
1671 };
1672
1673 INT srcsz, destsz;
1674 INT i;
1675 HRESULT hr;
1676 CHAR output[30];
1677 WCHAR outputW[30];
1678 int outlen;
1679
1680 /* test unc->jis */
1681 for (i = 0; i < 9; i++)
1682 {
1683 int j;
1684 destsz = 30;
1685 outlen = jis_jp[i][0];
1686 srcsz = unc_jp[i][0];
1687 hr = pConvertINetUnicodeToMultiByte(NULL, 50220, &unc_jp[i][1], &srcsz, output, &destsz);
1688 if (hr == S_FALSE)
1689 {
1690 skip("Code page identifier 50220 is not supported\n");
1691 break;
1692 }
1693 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n", i, hr);
1694 ok(destsz == outlen, "(%i) Expected %i, got %i\n",i,outlen,destsz);
1695 ok(srcsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],srcsz);
1696 ok(memcmp(output,&jis_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1697
1698 /* and back */
1699 srcsz = outlen;
1700 destsz = 30;
1701 hr = pConvertINetMultiByteToUnicode(NULL, 50220, output, &srcsz, outputW,&destsz);
1702
1703 /*
1704 * JIS does not have hankata so it get automatically converted to
1705 * zenkata. this means that strings 1 and 2 are identical as well as
1706 * strings 4 and 5.
1707 */
1708 j = i;
1709 if (i == 2) j = 1;
1710 if (i == 5) j = 4;
1711
1712 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i, hr);
1713 ok(destsz == unc_jp[j][0],"(%i) Expected %i, got %i\n",i,unc_jp[j][0],destsz);
1714 ok(srcsz == outlen,"(%i) Expected %i, got %i\n",i,outlen,srcsz);
1715 ok(memcmp(outputW,&unc_jp[j][1],destsz)==0,"(%i) Strings do not match\n",i);
1716 }
1717
1718 /* test unc->sjis */
1719 for (i = 0; i < 9; i++)
1720 {
1721 destsz = 30;
1722 outlen = sjis_jp[i][0];
1723 srcsz = unc_jp[i][0];
1724
1725 hr = pConvertINetUnicodeToMultiByte(NULL, 932, &unc_jp[i][1], &srcsz, output, &destsz);
1726 if (hr == S_FALSE)
1727 {
1728 skip("Code page identifier 932 is not supported\n");
1729 break;
1730 }
1731 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i,hr);
1732 ok(destsz == outlen,"(%i) Expected %i, got %i\n",i,outlen,destsz);
1733 ok(srcsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],srcsz);
1734 ok(memcmp(output,&sjis_jp[i][1],outlen)==0,"(%i) Strings do not match\n",i);
1735
1736 srcsz = outlen;
1737 destsz = 30;
1738 hr = pConvertINetMultiByteToUnicode(NULL, 932, output, &srcsz, outputW,&destsz);
1739
1740 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n", i, hr);
1741 ok(destsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1742 ok(srcsz == outlen,"(%i) Expected %i, got %i\n",i,outlen,srcsz);
1743 ok(memcmp(outputW,&unc_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1744 }
1745
1746 /* test unc->euc */
1747 for (i = 0; i < 9; i++)
1748 {
1749 destsz = 30;
1750 outlen = euc_jp[i][0];
1751 srcsz = unc_jp[i][0];
1752
1753 hr = pConvertINetUnicodeToMultiByte(NULL, 51932, &unc_jp[i][1], &srcsz, output, &destsz);
1754 if (hr == S_FALSE)
1755 {
1756 skip("Code page identifier 51932 is not supported\n");
1757 break;
1758 }
1759 ok(hr == S_OK, "(%i) Expected S_OK, got %08x\n",i,hr);
1760 ok(destsz == outlen, "(%i) Expected %i, got %i\n",i,outlen,destsz);
1761 ok(srcsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1762 ok(memcmp(output,&euc_jp[i][1],outlen)==0,"(%i) Strings do not match\n",i);
1763
1764 srcsz = outlen;
1765 destsz = 30;
1766 hr = pConvertINetMultiByteToUnicode(NULL, 51932, output, &srcsz, outputW,&destsz);
1767
1768 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i,hr);
1769 ok(destsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1770 ok(srcsz == outlen,"(%i) Expected %i, got %i\n",i,outlen,srcsz);
1771 ok(memcmp(outputW,&unc_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1772 }
1773
1774 /* Japanese autodetect */
1775 i = 0;
1776 destsz = 30;
1777 srcsz = jis_jp[i][0];
1778 hr = pConvertINetMultiByteToUnicode(NULL, 50932, &jis_jp[i][1], &srcsz, outputW, &destsz);
1779 if (hr == S_FALSE)
1780 {
1781 skip("Code page identifier 50932 is not supported\n");
1782 return;
1783 }
1784 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i,hr);
1785 ok(destsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1786 ok(srcsz == jis_jp[i][0],"(%i) Expected %i, got %i\n",i,jis_jp[i][0],srcsz);
1787 ok(memcmp(outputW,&unc_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1788
1789 i = 1;
1790 destsz = 30;
1791 srcsz = sjis_jp[i][0];
1792 hr = pConvertINetMultiByteToUnicode(NULL, 50932, &sjis_jp[i][1], &srcsz, outputW, &destsz);
1793 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i,hr);
1794 ok(destsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1795 ok(srcsz == sjis_jp[i][0],"(%i) Expected %i, got %i\n",i,sjis_jp[i][0],srcsz);
1796 ok(memcmp(outputW,&unc_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1797 }
1798
1799 static void test_GetScriptFontInfo(IMLangFontLink2 *font_link)
1800 {
1801 HRESULT hr;
1802 UINT nfonts;
1803 SCRIPTFONTINFO sfi[1];
1804
1805 nfonts = 0;
1806 hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidAsciiLatin, 0, &nfonts, NULL);
1807 ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1808 ok(nfonts, "unexpected result\n");
1809
1810 nfonts = 0;
1811 hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidAsciiLatin, SCRIPTCONTF_FIXED_FONT, &nfonts, NULL);
1812 ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1813 ok(nfonts, "unexpected result\n");
1814
1815 nfonts = 0;
1816 hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidAsciiLatin, SCRIPTCONTF_PROPORTIONAL_FONT, &nfonts, NULL);
1817 ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1818 ok(nfonts, "unexpected result\n");
1819
1820 nfonts = 1;
1821 memset(sfi, 0, sizeof(sfi));
1822 hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidAsciiLatin, SCRIPTCONTF_FIXED_FONT, &nfonts, sfi);
1823 ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1824 ok(nfonts == 1, "got %u, expected 1\n", nfonts);
1825 ok(sfi[0].scripts != 0, "unexpected result\n");
1826 ok(sfi[0].wszFont[0], "unexpected result\n");
1827
1828 nfonts = 1;
1829 memset(sfi, 0, sizeof(sfi));
1830 hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidAsciiLatin, SCRIPTCONTF_PROPORTIONAL_FONT, &nfonts, sfi);
1831 ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1832 ok(nfonts == 1, "got %u, expected 1\n", nfonts);
1833 ok(sfi[0].scripts != 0, "unexpected result\n");
1834 ok(sfi[0].wszFont[0], "unexpected result\n");
1835 }
1836
1837 static void test_CodePageToScriptID(IMLangFontLink2 *font_link)
1838 {
1839 HRESULT hr;
1840 UINT i;
1841 SCRIPT_ID sid;
1842 static const struct
1843 {
1844 UINT cp;
1845 SCRIPT_ID sid;
1846 HRESULT hr;
1847 }
1848 cp_sid[] =
1849 {
1850 {874, sidThai},
1851 {932, sidKana},
1852 {936, sidHan},
1853 {949, sidHangul},
1854 {950, sidBopomofo},
1855 {1250, sidAsciiLatin},
1856 {1251, sidCyrillic},
1857 {1252, sidAsciiLatin},
1858 {1253, sidGreek},
1859 {1254, sidAsciiLatin},
1860 {1255, sidHebrew},
1861 {1256, sidArabic},
1862 {1257, sidAsciiLatin},
1863 {1258, sidAsciiLatin},
1864 {CP_UNICODE, 0, E_FAIL}
1865 };
1866
1867 for (i = 0; i < sizeof(cp_sid)/sizeof(cp_sid[0]); i++)
1868 {
1869 hr = IMLangFontLink2_CodePageToScriptID(font_link, cp_sid[i].cp, &sid);
1870 ok(hr == cp_sid[i].hr, "%u CodePageToScriptID failed 0x%08x %u\n", i, hr, GetLastError());
1871 if (SUCCEEDED(hr))
1872 {
1873 ok(sid == cp_sid[i].sid,
1874 "%u got sid %u for codepage %u, expected %u\n", i, sid, cp_sid[i].cp, cp_sid[i].sid);
1875 }
1876 }
1877 }
1878
1879 static void test_GetFontUnicodeRanges(IMLangFontLink2 *font_link)
1880 {
1881 HRESULT hr;
1882 UINT count;
1883 HFONT hfont, old_hfont;
1884 LOGFONTA lf;
1885 HDC hdc;
1886 UNICODERANGE *ur;
1887
1888 hdc = CreateCompatibleDC(0);
1889 memset(&lf, 0, sizeof(lf));
1890 lstrcpyA(lf.lfFaceName, "Arial");
1891 hfont = CreateFontIndirectA(&lf);
1892 old_hfont = SelectObject(hdc, hfont);
1893
1894 count = 0;
1895 hr = IMLangFontLink2_GetFontUnicodeRanges(font_link, NULL, &count, NULL);
1896 ok(hr == E_FAIL, "expected E_FAIL, got 0x%08x\n", hr);
1897
1898 hr = IMLangFontLink2_GetFontUnicodeRanges(font_link, hdc, NULL, NULL);
1899 ok(hr == E_INVALIDARG, "expected E_FAIL, got 0x%08x\n", hr);
1900
1901 count = 0;
1902 hr = IMLangFontLink2_GetFontUnicodeRanges(font_link, hdc, &count, NULL);
1903 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1904 ok(count, "expected count > 0\n");
1905
1906 ur = HeapAlloc(GetProcessHeap(), 0, sizeof(*ur) * count);
1907
1908 hr = IMLangFontLink2_GetFontUnicodeRanges(font_link, hdc, &count, ur);
1909 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1910
1911 count--;
1912 hr = IMLangFontLink2_GetFontUnicodeRanges(font_link, hdc, &count, ur);
1913 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1914
1915 HeapFree(GetProcessHeap(), 0, ur);
1916
1917 SelectObject(hdc, old_hfont);
1918 DeleteObject(hfont);
1919 DeleteDC(hdc);
1920 }
1921
1922 static void test_IsCodePageInstallable(IMultiLanguage2 *ml2)
1923 {
1924 UINT i;
1925 HRESULT hr;
1926
1927 SetLastError(0xdeadbeef);
1928 lstrcmpW(NULL, NULL);
1929 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1930 {
1931 /* This corruption leads (sometimes) to test failures in oleaut32 but also
1932 * to the inability to use the Regional Settings.
1933 * This only seems to be an issue with Win98 and IE6 (mlang version 6.0.2800.1106).
1934 *
1935 * A reboot restores the codepages again.
1936 */
1937 win_skip("IsCodePageInstallable could mess up the codepages on Win98\n");
1938 return;
1939 }
1940
1941 for (i = 0; i < 0xffff; i++)
1942 {
1943 hr = IMultiLanguage2_IsCodePageInstallable(ml2, i);
1944
1945 /* it would be better to use IMultiLanguage2_ValidateCodePageEx here but that brings
1946 * up an installation dialog on some platforms, even when specifying CPIOD_PEEK.
1947 */
1948 if (IsValidCodePage(i))
1949 ok(hr == S_OK, "code page %u is valid but not installable 0x%08x\n", i, hr);
1950 }
1951 }
1952
1953 START_TEST(mlang)
1954 {
1955 IMultiLanguage *iML = NULL;
1956 IMultiLanguage2 *iML2 = NULL;
1957 IMLangFontLink *iMLFL = NULL;
1958 IMLangFontLink2 *iMLFL2 = NULL;
1959 HRESULT ret;
1960
1961 if (!init_function_ptrs())
1962 return;
1963
1964 CoInitialize(NULL);
1965 test_Rfc1766ToLcid();
1966 test_LcidToRfc1766();
1967
1968 test_ConvertINetUnicodeToMultiByte();
1969 test_JapaneseConversion();
1970
1971
1972 trace("IMultiLanguage\n");
1973 ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
1974 &IID_IMultiLanguage, (void **)&iML);
1975 if (ret != S_OK || !iML) return;
1976
1977 test_GetNumberOfCodePageInfo((IMultiLanguage2 *)iML);
1978 IMultiLanguage_Release(iML);
1979
1980
1981 /* IMultiLanguage2 (IE5.0 and above) */
1982 trace("IMultiLanguage2\n");
1983 ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
1984 &IID_IMultiLanguage2, (void **)&iML2);
1985 if (ret != S_OK || !iML2) return;
1986
1987 test_rfc1766(iML2);
1988 test_GetLcidFromRfc1766(iML2);
1989 test_GetRfc1766FromLcid(iML2);
1990 test_GetRfc1766Info(iML2);
1991 test_GetNumberOfCodePageInfo(iML2);
1992
1993 test_EnumCodePages(iML2, 0);
1994 test_EnumCodePages(iML2, MIMECONTF_MIME_LATEST);
1995 test_EnumCodePages(iML2, MIMECONTF_BROWSER);
1996 test_EnumCodePages(iML2, MIMECONTF_MINIMAL);
1997 test_EnumCodePages(iML2, MIMECONTF_VALID);
1998 /* FIXME: why MIMECONTF_MIME_REGISTRY returns 0 of supported codepages? */
1999 /*test_EnumCodePages(iML2, MIMECONTF_MIME_REGISTRY);*/
2000
2001 test_EnumScripts(iML2, 0);
2002 test_EnumScripts(iML2, SCRIPTCONTF_SCRIPT_USER);
2003 test_EnumScripts(iML2, SCRIPTCONTF_SCRIPT_USER | SCRIPTCONTF_SCRIPT_HIDE | SCRIPTCONTF_SCRIPT_SYSTEM);
2004
2005 ret = IMultiLanguage2_IsConvertible(iML2, CP_UTF8, CP_UNICODE);
2006 ok(ret == S_OK, "IMultiLanguage2_IsConvertible(CP_UTF8 -> CP_UNICODE) = %08x\n", ret);
2007 ret = IMultiLanguage2_IsConvertible(iML2, CP_UNICODE, CP_UTF8);
2008 ok(ret == S_OK, "IMultiLanguage2_IsConvertible(CP_UNICODE -> CP_UTF8) = %08x\n", ret);
2009
2010 test_multibyte_to_unicode_translations(iML2);
2011 test_IMultiLanguage2_ConvertStringFromUnicode(iML2);
2012
2013 test_IsCodePageInstallable(iML2);
2014
2015 IMultiLanguage2_Release(iML2);
2016
2017
2018 /* IMLangFontLink */
2019 ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
2020 &IID_IMLangFontLink, (void **)&iMLFL);
2021 if (ret != S_OK || !iMLFL) return;
2022
2023 IMLangFontLink_Test(iMLFL);
2024 IMLangFontLink_Release(iMLFL);
2025
2026 /* IMLangFontLink2 */
2027 ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
2028 &IID_IMLangFontLink2, (void **)&iMLFL2);
2029 if (ret != S_OK || !iMLFL2) return;
2030
2031 test_GetScriptFontInfo(iMLFL2);
2032 test_GetFontUnicodeRanges(iMLFL2);
2033 test_CodePageToScriptID(iMLFL2);
2034 IMLangFontLink2_Release(iMLFL2);
2035
2036 CoUninitialize();
2037 }