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