f6898344cedb311975738de165566bfeced47efc
[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 todo_wine_if (info_table[i].todo & TODO_NAME) {
1220 ok( (!lstrcmpW(prfc->wszLocaleName, info_table[i].localename)) ||
1221 (info_table[i].broken_name && (
1222 broken(!lstrcmpW(prfc->wszLocaleName, info_table[i].broken_name)) || /* IE < 6.0 */
1223 broken(!lstrcmpW(prfc->wszLocaleName, short_broken_name)))),
1224 "#%02d: got %s (expected %s)\n", i,
1225 wine_dbgstr_w(prfc->wszLocaleName), wine_dbgstr_w(info_table[i].localename));
1226 }
1227 }
1228
1229 /* SUBLANG_NEUTRAL only allowed for English, Arabic, Chinese */
1230 ret = IMultiLanguage2_GetRfc1766Info(iML2, MAKELANGID(LANG_GERMAN, SUBLANG_NEUTRAL), LANG_ENGLISH, prfc);
1231 ok(ret == E_FAIL, "got 0x%x (expected E_FAIL)\n", ret);
1232
1233 ret = IMultiLanguage2_GetRfc1766Info(iML2, MAKELANGID(LANG_ITALIAN, SUBLANG_NEUTRAL), LANG_ENGLISH, prfc);
1234 ok(ret == E_FAIL, "got 0x%x (expected E_FAIL)\n", ret);
1235
1236 /* NULL not allowed */
1237 ret = IMultiLanguage2_GetRfc1766Info(iML2, 0, LANG_ENGLISH, prfc);
1238 ok(ret == E_FAIL, "got 0x%x (expected E_FAIL)\n", ret);
1239
1240 ret = IMultiLanguage2_GetRfc1766Info(iML2, LANG_ENGLISH, LANG_ENGLISH, NULL);
1241 ok(ret == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", ret);
1242 }
1243
1244 static void test_IMultiLanguage2_ConvertStringFromUnicode(IMultiLanguage2 *iML2)
1245 {
1246 CHAR dest[MAX_PATH];
1247 CHAR invariate[MAX_PATH];
1248 UINT srcsz, destsz;
1249 HRESULT hr;
1250
1251 static WCHAR src[] = {'a','b','c',0};
1252
1253 memset(invariate, 'x', sizeof(invariate));
1254
1255 /* pSrcStr NULL */
1256 memset(dest, 'x', sizeof(dest));
1257 srcsz = lstrlenW(src) + 1;
1258 destsz = sizeof(dest);
1259 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, NULL,
1260 &srcsz, dest, &destsz);
1261 ok(hr == S_OK || hr == E_FAIL,"expected S_OK or E_FAIL, got %08x\n",hr);
1262 if (hr == S_OK)
1263 {
1264 ok(srcsz == lstrlenW(src) + 1,
1265 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1266 }
1267 else if (hr == E_FAIL)
1268 {
1269 ok(srcsz == 0,
1270 "Expected %u, got %u\n", 0, srcsz);
1271 }
1272
1273 ok(!memcmp(dest, invariate, sizeof(dest)),
1274 "Expected dest to be unchanged, got %s\n", dest);
1275 ok(destsz == 0, "Expected 0, got %u\n", destsz);
1276
1277 /* pcSrcSize NULL */
1278 memset(dest, 'x', sizeof(dest));
1279 destsz = sizeof(dest);
1280 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1281 NULL, dest, &destsz);
1282 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1283 ok(!strncmp(dest, "abc", 3),
1284 "Expected first three chars to be \"abc\"\n");
1285 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1286 "Expected rest of dest to be unchanged, got %s\n", dest);
1287 ok(destsz == lstrlenW(src),
1288 "Expected %u, got %u\n", lstrlenW(src), destsz);
1289
1290 /* both pSrcStr and pcSrcSize NULL */
1291 memset(dest, 'x', sizeof(dest));
1292 destsz = sizeof(dest);
1293 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, NULL,
1294 NULL, dest, &destsz);
1295 ok(hr == S_OK || hr == E_FAIL, "Expected S_OK or E_FAIL, got %08x\n", hr);
1296 ok(!memcmp(dest, invariate, sizeof(dest)),
1297 "Expected dest to be unchanged, got %s\n", dest);
1298 ok(destsz == 0, "Expected 0, got %u\n", destsz);
1299
1300 /* pDstStr NULL */
1301 memset(dest, 'x', sizeof(dest));
1302 srcsz = lstrlenW(src) + 1;
1303 destsz = sizeof(dest);
1304 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1305 &srcsz, NULL, &destsz);
1306 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1307 ok(srcsz == lstrlenW(src) + 1,
1308 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1309 ok(destsz == lstrlenW(src) + 1,
1310 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1311
1312 /* pcDstSize NULL */
1313 memset(dest, 'x', sizeof(dest));
1314 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1315 &srcsz, dest, NULL);
1316 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1317 ok(srcsz == lstrlenW(src) + 1,
1318 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1319 ok(!memcmp(dest, invariate, sizeof(dest)),
1320 "Expected dest to be unchanged, got %s\n", dest);
1321
1322 /* pcSrcSize is 0 */
1323 memset(dest, 'x', sizeof(dest));
1324 srcsz = 0;
1325 destsz = sizeof(dest);
1326 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1327 &srcsz, dest, &destsz);
1328 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1329 ok(srcsz == 0, "Expected 0, got %u\n", srcsz);
1330 ok(!memcmp(dest, invariate, sizeof(dest)),
1331 "Expected dest to be unchanged, got %s\n", dest);
1332 ok(destsz == 0, "Expected 0, got %u\n", destsz);
1333
1334 /* pcSrcSize does not include NULL terminator */
1335 memset(dest, 'x', sizeof(dest));
1336 srcsz = lstrlenW(src);
1337 destsz = sizeof(dest);
1338 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1339 &srcsz, dest, &destsz);
1340 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1341 ok(srcsz == lstrlenW(src),
1342 "Expected %u, got %u\n", lstrlenW(src), srcsz);
1343 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1344 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1345 "Expected rest of dest to be unchanged, got %s\n", dest);
1346 ok(destsz == lstrlenW(src),
1347 "Expected %u, got %u\n", lstrlenW(src), destsz);
1348
1349 /* pcSrcSize includes NULL terminator */
1350 memset(dest, 'x', sizeof(dest));
1351 srcsz = lstrlenW(src) + 1;
1352 destsz = sizeof(dest);
1353 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1354 &srcsz, dest, &destsz);
1355 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1356 ok(srcsz == lstrlenW(src) + 1, "Expected 3, got %u\n", srcsz);
1357 ok(!lstrcmpA(dest, "abc"), "Expected \"abc\", got \"%s\"\n", dest);
1358 ok(destsz == lstrlenW(src) + 1,
1359 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1360
1361 /* pcSrcSize is -1 */
1362 memset(dest, 'x', sizeof(dest));
1363 srcsz = -1;
1364 destsz = sizeof(dest);
1365 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1366 &srcsz, dest, &destsz);
1367 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1368 ok(srcsz == lstrlenW(src),
1369 "Expected %u, got %u\n", lstrlenW(src), srcsz);
1370 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1371 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1372 "Expected rest of dest to be unchanged, got %s\n", dest);
1373 ok(destsz == lstrlenW(src),
1374 "Expected %u, got %u\n", lstrlenW(src), destsz);
1375
1376 /* pcDstSize is 0 */
1377 memset(dest, 'x', sizeof(dest));
1378 srcsz = lstrlenW(src) + 1;
1379 destsz = 0;
1380 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1381 &srcsz, dest, &destsz);
1382 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1383 ok(srcsz == lstrlenW(src) + 1,
1384 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1385 ok(!memcmp(dest, invariate, sizeof(dest)),
1386 "Expected dest to be unchanged, got %s\n", dest);
1387 ok(destsz == lstrlenW(src) + 1,
1388 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1389
1390 /* pcDstSize is not large enough */
1391 memset(dest, 'x', sizeof(dest));
1392 srcsz = lstrlenW(src) + 1;
1393 destsz = lstrlenW(src);
1394 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1395 &srcsz, dest, &destsz);
1396 ok(hr == E_FAIL, "Expected E_FAIL, got %08x\n", hr);
1397 ok(srcsz == 0, "Expected 0, got %u\n", srcsz);
1398 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1399 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1400 "Expected rest of dest to be unchanged, got %s\n", dest);
1401 ok(destsz == 0, "Expected 0, got %u\n", srcsz);
1402
1403 /* pcDstSize (bytes) does not leave room for NULL terminator */
1404 memset(dest, 'x', sizeof(dest));
1405 srcsz = lstrlenW(src) + 1;
1406 destsz = lstrlenW(src) * sizeof(WCHAR);
1407 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1408 &srcsz, dest, &destsz);
1409 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1410 ok(srcsz == lstrlenW(src) + 1,
1411 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1412 ok(!lstrcmpA(dest, "abc"), "Expected \"abc\", got \"%s\"\n", dest);
1413 ok(destsz == lstrlenW(src) + 1,
1414 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1415 }
1416
1417 static void test_ConvertINetUnicodeToMultiByte(void)
1418 {
1419 CHAR dest[MAX_PATH];
1420 CHAR invariate[MAX_PATH];
1421 INT srcsz, destsz;
1422 HRESULT hr;
1423
1424 static WCHAR src[] = {'a','b','c',0};
1425
1426 memset(invariate, 'x', sizeof(invariate));
1427
1428 /* lpSrcStr NULL */
1429 memset(dest, 'x', sizeof(dest));
1430 srcsz = lstrlenW(src) + 1;
1431 destsz = sizeof(dest);
1432 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, NULL, &srcsz, dest, &destsz);
1433 ok(hr == S_OK || hr == E_FAIL, "Expected S_OK or E_FAIL, got %08x\n", hr);
1434 if (hr == S_OK)
1435 ok(srcsz == lstrlenW(src) + 1,
1436 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1437 else if (hr == E_FAIL)
1438 ok(srcsz == 0,
1439 "Expected %u, got %u\n", 0, srcsz);
1440 ok(!memcmp(dest, invariate, sizeof(dest)),
1441 "Expected dest to be unchanged, got %s\n", dest);
1442 ok(destsz == 0, "Expected 0, got %u\n", destsz);
1443
1444 /* lpnWideCharCount NULL */
1445 memset(dest, 'x', sizeof(dest));
1446 destsz = sizeof(dest);
1447 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, NULL, dest, &destsz);
1448 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1449 ok(!strncmp(dest, "abc", 3),
1450 "Expected first three chars to be \"abc\"\n");
1451 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1452 "Expected rest of dest to be unchanged, got %s\n", dest);
1453 ok(destsz == lstrlenW(src),
1454 "Expected %u, got %u\n", lstrlenW(src), destsz);
1455
1456 /* both lpSrcStr and lpnWideCharCount NULL */
1457 memset(dest, 'x', sizeof(dest));
1458 destsz = sizeof(dest);
1459 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, NULL, NULL, dest, &destsz);
1460 ok(hr == S_OK || hr == E_FAIL, "Expected S_OK or E_FAIL, got %08x\n", hr);
1461 ok(!memcmp(dest, invariate, sizeof(dest)),
1462 "Expected dest to be unchanged, got %s\n", dest);
1463 ok(destsz == 0, "Expected 0, got %u\n", destsz);
1464
1465 /* lpDstStr NULL */
1466 memset(dest, 'x', sizeof(dest));
1467 srcsz = lstrlenW(src) + 1;
1468 destsz = sizeof(dest);
1469 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, NULL, &destsz);
1470 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1471 ok(srcsz == lstrlenW(src) + 1,
1472 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1473 ok(destsz == lstrlenW(src) + 1,
1474 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1475
1476 /* lpnMultiCharCount NULL */
1477 memset(dest, 'x', sizeof(dest));
1478 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, NULL);
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(!memcmp(dest, invariate, sizeof(dest)),
1483 "Expected dest to be unchanged, got %s\n", dest);
1484
1485 /* lpnWideCharCount is 0 */
1486 memset(dest, 'x', sizeof(dest));
1487 srcsz = 0;
1488 destsz = sizeof(dest);
1489 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1490 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1491 ok(srcsz == 0, "Expected 0, got %u\n", srcsz);
1492 ok(!memcmp(dest, invariate, sizeof(dest)),
1493 "Expected dest to be unchanged, got %s\n", dest);
1494 ok(destsz == 0, "Expected 0, got %u\n", destsz);
1495
1496 /* lpnWideCharCount does not include NULL terminator */
1497 memset(dest, 'x', sizeof(dest));
1498 srcsz = lstrlenW(src);
1499 destsz = sizeof(dest);
1500 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1501 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1502 ok(srcsz == lstrlenW(src),
1503 "Expected %u, got %u\n", lstrlenW(src), srcsz);
1504 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1505 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1506 "Expected rest of dest to be unchanged, got %s\n", dest);
1507 ok(destsz == lstrlenW(src),
1508 "Expected %u, got %u\n", lstrlenW(src), destsz);
1509
1510 /* lpnWideCharCount includes NULL terminator */
1511 memset(dest, 'x', sizeof(dest));
1512 srcsz = lstrlenW(src) + 1;
1513 destsz = sizeof(dest);
1514 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1515 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1516 ok(srcsz == lstrlenW(src) + 1, "Expected 3, got %u\n", srcsz);
1517 ok(!lstrcmpA(dest, "abc"), "Expected \"abc\", got \"%s\"\n", dest);
1518 ok(destsz == lstrlenW(src) + 1,
1519 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1520
1521 /* lpnWideCharCount is -1 */
1522 memset(dest, 'x', sizeof(dest));
1523 srcsz = -1;
1524 destsz = sizeof(dest);
1525 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1526 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1527 ok(srcsz == lstrlenW(src),
1528 "Expected %u, got %u\n", lstrlenW(src), srcsz);
1529 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1530 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1531 "Expected rest of dest to be unchanged, got %s\n", dest);
1532 ok(destsz == lstrlenW(src),
1533 "Expected %u, got %u\n", lstrlenW(src), destsz);
1534
1535 /* lpnMultiCharCount is 0 */
1536 memset(dest, 'x', sizeof(dest));
1537 srcsz = lstrlenW(src) + 1;
1538 destsz = 0;
1539 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1540 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1541 ok(srcsz == lstrlenW(src) + 1,
1542 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1543 ok(!memcmp(dest, invariate, sizeof(dest)),
1544 "Expected dest to be unchanged, got %s\n", dest);
1545 ok(destsz == lstrlenW(src) + 1,
1546 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1547
1548 /* lpnMultiCharCount is not large enough */
1549 memset(dest, 'x', sizeof(dest));
1550 srcsz = lstrlenW(src) + 1;
1551 destsz = lstrlenW(src);
1552 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1553 ok(hr == E_FAIL, "Expected E_FAIL, got %08x\n", hr);
1554 ok(srcsz == 0, "Expected 0, got %u\n", srcsz);
1555 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1556 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1557 "Expected rest of dest to be unchanged, got %s\n", dest);
1558 ok(destsz == 0, "Expected 0, got %u\n", srcsz);
1559
1560 /* lpnMultiCharCount (bytes) does not leave room for NULL terminator */
1561 memset(dest, 'x', sizeof(dest));
1562 srcsz = lstrlenW(src) + 1;
1563 destsz = lstrlenW(src) * sizeof(WCHAR);
1564 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1565 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1566 ok(srcsz == lstrlenW(src) + 1,
1567 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1568 ok(!lstrcmpA(dest, "abc"), "Expected \"abc\", got \"%s\"\n", dest);
1569 ok(destsz == lstrlenW(src) + 1,
1570 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1571 }
1572
1573 static void test_JapaneseConversion(void)
1574 {
1575 /* Data */
1576 static WCHAR unc_jp[9][12] = {
1577 {9,0x31,0x20,0x3042,0x3044,0x3046,0x3048,0x304a,0x000d,0x000a},
1578 {9,0x31,0x20,0x30a2,0x30a4,0x30a6,0x30a8,0x30aa,0x000d,0x000a},
1579 {9,0x31,0x20,0xff71,0xff72,0xff73,0xff74,0xff75,0x000d,0x000a},
1580 {9,0x31,0x20,0x3041,0x3043,0x3045,0x3047,0x3049,0x000d,0x000a},
1581 {9,0x31,0x20,0x30a1,0x30a3,0x30a5,0x30a7,0x30a9,0x000d,0x000a},
1582 {9,0x31,0x20,0xff67,0xff68,0xff69,0xff6a,0xff6b,0x000d,0x000a},
1583 {9,0x31,0x20,0x300c,0x65e5,0x672c,0x8a9e,0x300d,0x000d,0x000a},
1584 {7,0x31,0x20,0x25c7,0x25c7,0x3012,0x000d,0x000a},
1585 {11,0x31,0x20,0x203b,0x3010,0x0074,0x0065,0x0073,0x0074,0x3011,0x000d,0x000a}
1586 };
1587 static CHAR jis_jp[9][27] = {
1588 {20,0x31,0x20,0x1b,0x24,0x42,0x24,0x22,0x24,0x24,0x24,0x26,0x24,0x28,
1589 0x24,0x2a,0x1b,0x28,0x42,0x0d,0x0a},
1590 {20,0x31,0x20,0x1b,0x24,0x42,0x25,0x22,0x25,0x24,0x25,0x26,0x25,0x28,
1591 0x25,0x2a,0x1b,0x28,0x42,0x0d,0x0a},
1592 {20,0x31,0x20,0x1b,0x24,0x42,0x25,0x22,0x25,0x24,0x25,0x26,0x25,0x28,
1593 0x25,0x2a,0x1b,0x28,0x42,0x0d,0x0a},
1594 {20,0x31,0x20,0x1b,0x24,0x42,0x24,0x21,0x24,0x23,0x24,0x25,0x24,0x27,
1595 0x24,0x29,0x1b,0x28,0x42,0x0d,0x0a},
1596 {20,0x31,0x20,0x1b,0x24,0x42,0x25,0x21,0x25,0x23,0x25,0x25,0x25,0x27,
1597 0x25,0x29,0x1b,0x28,0x42,0x0d,0x0a},
1598 {20,0x31,0x20,0x1b,0x24,0x42,0x25,0x21,0x25,0x23,0x25,0x25,0x25,0x27,
1599 0x25,0x29,0x1b,0x28,0x42,0x0d,0x0a},
1600 {20,0x31,0x20,0x1b,0x24,0x42,0x21,0x56,0x46,0x7c,0x4b,0x5c,0x38,0x6c,
1601 0x21,0x57,0x1b,0x28,0x42,0x0d,0x0a},
1602 {16,0x31,0x20,0x1b,0x24,0x42,0x21,0x7e,0x21,0x7e,0x22,0x29,0x1b,0x28,
1603 0x42,0x0d,0x0a},
1604 {26,0x31,0x20,0x1b,0x24,0x42,0x22,0x28,0x21,0x5a,0x1b,0x28,0x42,0x74,
1605 0x65,0x73,0x74,0x1b,0x24,0x42,0x21,0x5b,0x1b,0x28,0x42,0x0d,0x0a}
1606 };
1607 static CHAR sjis_jp[9][15] = {
1608 {14,0x31,0x20,0x82,0xa0,0x82,0xa2,0x82,0xa4,0x82,0xa6,0x82,0xa8,0x0d,0x0a},
1609 {14,0x31,0x20,0x83,0x41,0x83,0x43,0x83,0x45,0x83,0x47,0x83,0x49,0x0d,0x0a},
1610 {9,0x31,0x20,0xb1,0xb2,0xb3,0xb4,0xb5,0x0d,0x0a},
1611 {14,0x31,0x20,0x82,0x9f,0x82,0xa1,0x82,0xa3,0x82,0xa5,0x82,0xa7,0x0d,0x0a},
1612 {14,0x31,0x20,0x83,0x40,0x83,0x42,0x83,0x44,0x83,0x46,0x83,0x48,0x0d,0x0a},
1613 {9,0x31,0x20,0xa7,0xa8,0xa9,0xaa,0xab,0x0d,0x0a},
1614 {14,0x31,0x20,0x81,0x75,0x93,0xfa,0x96,0x7b,0x8c,0xea,0x81,0x76,0x0d,0x0a},
1615 {10,0x31,0x20,0x81,0x9e,0x81,0x9e,0x81,0xa7,0x0d,0x0a},
1616 {14,0x31,0x20,0x81,0xa6,0x81,0x79,0x74,0x65,0x73,0x74,0x81,0x7a,0x0d,0x0a}
1617 };
1618 static CHAR euc_jp[9][15] = {
1619 {14,0x31,0x20,0xa4,0xa2,0xa4,0xa4,0xa4,0xa6,0xa4,0xa8,0xa4,0xaa,0x0d,0x0a},
1620 {14,0x31,0x20,0xa5,0xa2,0xa5,0xa4,0xa5,0xa6,0xa5,0xa8,0xa5,0xaa,0x0d,0x0a},
1621 {14,0x31,0x20,0x8e,0xb1,0x8e,0xb2,0x8e,0xb3,0x8e,0xb4,0x8e,0xb5,0x0d,0x0a},
1622 {14,0x31,0x20,0xa4,0xa1,0xa4,0xa3,0xa4,0xa5,0xa4,0xa7,0xa4,0xa9,0x0d,0x0a},
1623 {14,0x31,0x20,0xa5,0xa1,0xa5,0xa3,0xa5,0xa5,0xa5,0xa7,0xa5,0xa9,0x0d,0x0a},
1624 {14,0x31,0x20,0x8e,0xa7,0x8e,0xa8,0x8e,0xa9,0x8e,0xaa,0x8e,0xab,0x0d,0x0a},
1625 {14,0x31,0x20,0xa1,0xd6,0xc6,0xfc,0xcb,0xdc,0xb8,0xec,0xa1,0xd7,0x0d,0x0a},
1626 {10,0x31,0x20,0xa1,0xfe,0xa1,0xfe,0xa2,0xa9,0x0d,0x0a},
1627 {14,0x31,0x20,0xa2,0xa8,0xa1,0xda,0x74,0x65,0x73,0x74,0xa1,0xdb,0x0d,0x0a}
1628 };
1629
1630 INT srcsz, destsz;
1631 INT i;
1632 HRESULT hr;
1633 CHAR output[30];
1634 WCHAR outputW[30];
1635 int outlen;
1636
1637 /* test unc->jis */
1638 for (i = 0; i < 9; i++)
1639 {
1640 int j;
1641 destsz = 30;
1642 outlen = jis_jp[i][0];
1643 srcsz = unc_jp[i][0];
1644 hr = pConvertINetUnicodeToMultiByte(NULL, 50220, &unc_jp[i][1], &srcsz, output, &destsz);
1645 if (hr == S_FALSE)
1646 {
1647 skip("Code page identifier 50220 is not supported\n");
1648 break;
1649 }
1650 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n", i, hr);
1651 ok(destsz == outlen, "(%i) Expected %i, got %i\n",i,outlen,destsz);
1652 ok(srcsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],srcsz);
1653 ok(memcmp(output,&jis_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1654
1655 /* and back */
1656 srcsz = outlen;
1657 destsz = 30;
1658 hr = pConvertINetMultiByteToUnicode(NULL, 50220, output, &srcsz, outputW,&destsz);
1659
1660 /*
1661 * JIS does not have hankata so it get automatically converted to
1662 * zenkata. this means that strings 1 and 2 are identical as well as
1663 * strings 4 and 5.
1664 */
1665 j = i;
1666 if (i == 2) j = 1;
1667 if (i == 5) j = 4;
1668
1669 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i, hr);
1670 ok(destsz == unc_jp[j][0],"(%i) Expected %i, got %i\n",i,unc_jp[j][0],destsz);
1671 ok(srcsz == outlen,"(%i) Expected %i, got %i\n",i,outlen,srcsz);
1672 ok(memcmp(outputW,&unc_jp[j][1],destsz)==0,"(%i) Strings do not match\n",i);
1673 }
1674
1675 /* test unc->sjis */
1676 for (i = 0; i < 9; i++)
1677 {
1678 destsz = 30;
1679 outlen = sjis_jp[i][0];
1680 srcsz = unc_jp[i][0];
1681
1682 hr = pConvertINetUnicodeToMultiByte(NULL, 932, &unc_jp[i][1], &srcsz, output, &destsz);
1683 if (hr == S_FALSE)
1684 {
1685 skip("Code page identifier 932 is not supported\n");
1686 break;
1687 }
1688 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i,hr);
1689 ok(destsz == outlen,"(%i) Expected %i, got %i\n",i,outlen,destsz);
1690 ok(srcsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],srcsz);
1691 ok(memcmp(output,&sjis_jp[i][1],outlen)==0,"(%i) Strings do not match\n",i);
1692
1693 srcsz = outlen;
1694 destsz = 30;
1695 hr = pConvertINetMultiByteToUnicode(NULL, 932, output, &srcsz, outputW,&destsz);
1696
1697 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n", i, hr);
1698 ok(destsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1699 ok(srcsz == outlen,"(%i) Expected %i, got %i\n",i,outlen,srcsz);
1700 ok(memcmp(outputW,&unc_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1701 }
1702
1703 /* test unc->euc */
1704 for (i = 0; i < 9; i++)
1705 {
1706 destsz = 30;
1707 outlen = euc_jp[i][0];
1708 srcsz = unc_jp[i][0];
1709
1710 hr = pConvertINetUnicodeToMultiByte(NULL, 51932, &unc_jp[i][1], &srcsz, output, &destsz);
1711 if (hr == S_FALSE)
1712 {
1713 skip("Code page identifier 51932 is not supported\n");
1714 break;
1715 }
1716 ok(hr == S_OK, "(%i) Expected S_OK, got %08x\n",i,hr);
1717 ok(destsz == outlen, "(%i) Expected %i, got %i\n",i,outlen,destsz);
1718 ok(srcsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1719 ok(memcmp(output,&euc_jp[i][1],outlen)==0,"(%i) Strings do not match\n",i);
1720
1721 srcsz = outlen;
1722 destsz = 30;
1723 hr = pConvertINetMultiByteToUnicode(NULL, 51932, output, &srcsz, outputW,&destsz);
1724
1725 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i,hr);
1726 ok(destsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1727 ok(srcsz == outlen,"(%i) Expected %i, got %i\n",i,outlen,srcsz);
1728 ok(memcmp(outputW,&unc_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1729 }
1730
1731 /* Japanese autodetect */
1732 i = 0;
1733 destsz = 30;
1734 srcsz = jis_jp[i][0];
1735 hr = pConvertINetMultiByteToUnicode(NULL, 50932, &jis_jp[i][1], &srcsz, outputW, &destsz);
1736 if (hr == S_FALSE)
1737 {
1738 skip("Code page identifier 50932 is not supported\n");
1739 return;
1740 }
1741 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i,hr);
1742 ok(destsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1743 ok(srcsz == jis_jp[i][0],"(%i) Expected %i, got %i\n",i,jis_jp[i][0],srcsz);
1744 ok(memcmp(outputW,&unc_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1745
1746 i = 1;
1747 destsz = 30;
1748 srcsz = sjis_jp[i][0];
1749 hr = pConvertINetMultiByteToUnicode(NULL, 50932, &sjis_jp[i][1], &srcsz, outputW, &destsz);
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 == sjis_jp[i][0],"(%i) Expected %i, got %i\n",i,sjis_jp[i][0],srcsz);
1753 ok(memcmp(outputW,&unc_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1754 }
1755
1756 static void test_GetScriptFontInfo(IMLangFontLink2 *font_link)
1757 {
1758 HRESULT hr;
1759 UINT nfonts;
1760 SCRIPTFONTINFO sfi[1];
1761
1762 nfonts = 0;
1763 hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidAsciiLatin, 0, &nfonts, NULL);
1764 ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1765 ok(nfonts, "unexpected result\n");
1766
1767 nfonts = 0;
1768 hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidAsciiLatin, SCRIPTCONTF_FIXED_FONT, &nfonts, NULL);
1769 ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1770 ok(nfonts, "unexpected result\n");
1771
1772 nfonts = 0;
1773 hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidAsciiLatin, SCRIPTCONTF_PROPORTIONAL_FONT, &nfonts, NULL);
1774 ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1775 ok(nfonts, "unexpected result\n");
1776
1777 nfonts = 1;
1778 memset(sfi, 0, sizeof(sfi));
1779 hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidAsciiLatin, SCRIPTCONTF_FIXED_FONT, &nfonts, sfi);
1780 ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1781 ok(nfonts == 1, "got %u, expected 1\n", nfonts);
1782 ok(sfi[0].scripts != 0, "unexpected result\n");
1783 ok(sfi[0].wszFont[0], "unexpected result\n");
1784
1785 nfonts = 1;
1786 memset(sfi, 0, sizeof(sfi));
1787 hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidAsciiLatin, SCRIPTCONTF_PROPORTIONAL_FONT, &nfonts, sfi);
1788 ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1789 ok(nfonts == 1, "got %u, expected 1\n", nfonts);
1790 ok(sfi[0].scripts != 0, "unexpected result\n");
1791 ok(sfi[0].wszFont[0], "unexpected result\n");
1792 }
1793
1794 static void test_CodePageToScriptID(IMLangFontLink2 *font_link)
1795 {
1796 HRESULT hr;
1797 UINT i;
1798 SCRIPT_ID sid;
1799 static const struct
1800 {
1801 UINT cp;
1802 SCRIPT_ID sid;
1803 HRESULT hr;
1804 }
1805 cp_sid[] =
1806 {
1807 {874, sidThai},
1808 {932, sidKana},
1809 {936, sidHan},
1810 {949, sidHangul},
1811 {950, sidBopomofo},
1812 {1250, sidAsciiLatin},
1813 {1251, sidCyrillic},
1814 {1252, sidAsciiLatin},
1815 {1253, sidGreek},
1816 {1254, sidAsciiLatin},
1817 {1255, sidHebrew},
1818 {1256, sidArabic},
1819 {1257, sidAsciiLatin},
1820 {1258, sidAsciiLatin},
1821 {CP_UNICODE, 0, E_FAIL}
1822 };
1823
1824 for (i = 0; i < sizeof(cp_sid)/sizeof(cp_sid[0]); i++)
1825 {
1826 hr = IMLangFontLink2_CodePageToScriptID(font_link, cp_sid[i].cp, &sid);
1827 ok(hr == cp_sid[i].hr, "%u CodePageToScriptID failed 0x%08x %u\n", i, hr, GetLastError());
1828 if (SUCCEEDED(hr))
1829 {
1830 ok(sid == cp_sid[i].sid,
1831 "%u got sid %u for codepage %u, expected %u\n", i, sid, cp_sid[i].cp, cp_sid[i].sid);
1832 }
1833 }
1834 }
1835
1836 static void test_GetFontUnicodeRanges(IMLangFontLink2 *font_link)
1837 {
1838 HRESULT hr;
1839 UINT count;
1840 HFONT hfont, old_hfont;
1841 LOGFONTA lf;
1842 HDC hdc;
1843 UNICODERANGE *ur;
1844
1845 hdc = CreateCompatibleDC(0);
1846 memset(&lf, 0, sizeof(lf));
1847 lstrcpyA(lf.lfFaceName, "Arial");
1848 hfont = CreateFontIndirectA(&lf);
1849 old_hfont = SelectObject(hdc, hfont);
1850
1851 count = 0;
1852 hr = IMLangFontLink2_GetFontUnicodeRanges(font_link, NULL, &count, NULL);
1853 ok(hr == E_FAIL, "expected E_FAIL, got 0x%08x\n", hr);
1854
1855 hr = IMLangFontLink2_GetFontUnicodeRanges(font_link, hdc, NULL, NULL);
1856 ok(hr == E_INVALIDARG, "expected E_FAIL, got 0x%08x\n", hr);
1857
1858 count = 0;
1859 hr = IMLangFontLink2_GetFontUnicodeRanges(font_link, hdc, &count, NULL);
1860 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1861 ok(count, "expected count > 0\n");
1862
1863 ur = HeapAlloc(GetProcessHeap(), 0, sizeof(*ur) * count);
1864
1865 hr = IMLangFontLink2_GetFontUnicodeRanges(font_link, hdc, &count, ur);
1866 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1867
1868 count--;
1869 hr = IMLangFontLink2_GetFontUnicodeRanges(font_link, hdc, &count, ur);
1870 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1871
1872 HeapFree(GetProcessHeap(), 0, ur);
1873
1874 SelectObject(hdc, old_hfont);
1875 DeleteObject(hfont);
1876 DeleteDC(hdc);
1877 }
1878
1879 static void test_IsCodePageInstallable(IMultiLanguage2 *ml2)
1880 {
1881 UINT i;
1882 HRESULT hr;
1883
1884 for (i = 0; i < 0xffff; i++)
1885 {
1886 hr = IMultiLanguage2_IsCodePageInstallable(ml2, i);
1887
1888 /* it would be better to use IMultiLanguage2_ValidateCodePageEx here but that brings
1889 * up an installation dialog on some platforms, even when specifying CPIOD_PEEK.
1890 */
1891 if (IsValidCodePage(i))
1892 ok(hr == S_OK ||
1893 broken(hr == S_FALSE) || /* win2k */
1894 broken(hr == E_INVALIDARG), /* win2k */
1895 "code page %u is valid but not installable 0x%08x\n", i, hr);
1896 }
1897 }
1898
1899 static void test_GetGlobalFontLinkObject(void)
1900 {
1901 HRESULT ret;
1902 void *unknown;
1903
1904 ret = GetGlobalFontLinkObject(NULL);
1905 ok(ret == E_INVALIDARG, "expected E_INVALIDARG got %#x\n", ret);
1906
1907 unknown = (void *)0xdeadbeef;
1908 ret = GetGlobalFontLinkObject(&unknown);
1909 todo_wine {
1910 ok(ret == S_OK, "expected S_OK got %#x\n", ret);
1911 ok(unknown != NULL && unknown != (void *)0xdeadbeef,
1912 "GetGlobalFontLinkObject() returned %p\n", unknown);
1913 }
1914 }
1915
1916 static void test_IMLangConvertCharset(IMultiLanguage *ml)
1917 {
1918 IMLangConvertCharset *convert;
1919 WCHAR strW[] = {'a','b','c','d',0};
1920 UINT cp, src_size, dst_size;
1921 char strA[] = "abcd";
1922 WCHAR buffW[20];
1923 HRESULT hr;
1924
1925 hr = IMultiLanguage_CreateConvertCharset(ml, CP_ACP, CP_UTF8, 0, &convert);
1926 todo_wine
1927 ok(hr == S_FALSE, "expected S_FALSE got 0x%08x\n", hr);
1928
1929 hr = IMLangConvertCharset_GetSourceCodePage(convert, NULL);
1930 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
1931
1932 cp = CP_UTF8;
1933 hr = IMLangConvertCharset_GetSourceCodePage(convert, &cp);
1934 ok(hr == S_OK, "expected S_OK got 0x%08x\n", hr);
1935 ok(cp == CP_ACP, "got %d\n", cp);
1936
1937 hr = IMLangConvertCharset_GetDestinationCodePage(convert, NULL);
1938 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
1939
1940 cp = CP_ACP;
1941 hr = IMLangConvertCharset_GetDestinationCodePage(convert, &cp);
1942 ok(hr == S_OK, "expected S_OK got 0x%08x\n", hr);
1943 ok(cp == CP_UTF8, "got %d\n", cp);
1944
1945 /* DoConversionToUnicode */
1946 hr = IMLangConvertCharset_Initialize(convert, CP_UTF8, CP_UNICODE, 0);
1947 ok(hr == S_OK, "expected S_OK got 0x%08x\n", hr);
1948
1949 hr = IMLangConvertCharset_DoConversionToUnicode(convert, NULL, NULL, NULL, NULL);
1950 ok(hr == E_FAIL || broken(hr == S_OK) /* win2k */, "got 0x%08x\n", hr);
1951
1952 src_size = -1;
1953 dst_size = 20;
1954 buffW[0] = 0;
1955 buffW[4] = 4;
1956 hr = IMLangConvertCharset_DoConversionToUnicode(convert, strA, &src_size, buffW, &dst_size);
1957 ok(hr == S_OK, "got 0x%08x\n", hr);
1958 ok(!memcmp(buffW, strW, 4*sizeof(WCHAR)), "got converted string %s\n", wine_dbgstr_wn(buffW, dst_size));
1959 ok(dst_size == 4, "got %d\n", dst_size);
1960 ok(buffW[4] == 4, "got %d\n", buffW[4]);
1961 ok(src_size == 4, "got %d\n", src_size);
1962
1963 src_size = -1;
1964 dst_size = 0;
1965 buffW[0] = 1;
1966 hr = IMLangConvertCharset_DoConversionToUnicode(convert, strA, &src_size, buffW, &dst_size);
1967 ok(hr == S_OK, "got 0x%08x\n", hr);
1968 ok(buffW[0] == 1, "got %d\n", buffW[0]);
1969 ok(dst_size == 4, "got %d\n", dst_size);
1970 ok(src_size == 4, "got %d\n", src_size);
1971
1972 hr = IMLangConvertCharset_Initialize(convert, CP_UNICODE, CP_UNICODE, 0);
1973 ok(hr == S_OK, "expected S_OK got 0x%08x\n", hr);
1974
1975 IMLangConvertCharset_Release(convert);
1976 }
1977
1978 static const char stream_data[] = "VCARD2.1test;test";
1979 static ULONG stream_pos;
1980
1981 static HRESULT WINAPI stream_QueryInterface(IStream *iface, REFIID riid, void **obj)
1982 {
1983 ok(FALSE, "unexpected call\n");
1984 return E_NOINTERFACE;
1985 }
1986
1987 static ULONG WINAPI stream_AddRef(IStream *iface)
1988 {
1989 ok(FALSE, "unexpected call\n");
1990 return 2;
1991 }
1992
1993 static ULONG WINAPI stream_Release(IStream *iface)
1994 {
1995 ok(FALSE, "unexpected call\n");
1996 return 1;
1997 }
1998
1999 static HRESULT WINAPI stream_Read(IStream *iface, void *buf, ULONG len, ULONG *read)
2000 {
2001 ULONG size;
2002
2003 if (stream_pos == sizeof(stream_data) - 1)
2004 {
2005 *read = 0;
2006 return S_FALSE;
2007 }
2008 size = min(sizeof(stream_data) - 1 - stream_pos, len);
2009 memcpy(buf, stream_data + stream_pos, size);
2010 stream_pos += size;
2011 *read = size;
2012 return S_OK;
2013 }
2014
2015 static HRESULT WINAPI stream_Write(IStream *iface, const void *buf, ULONG len, ULONG *written)
2016 {
2017 ok(FALSE, "unexpected call\n");
2018 return E_NOTIMPL;
2019 }
2020
2021 static HRESULT WINAPI stream_Seek(IStream *iface, LARGE_INTEGER move, DWORD origin,
2022 ULARGE_INTEGER *newpos)
2023 {
2024 if (origin == STREAM_SEEK_SET)
2025 stream_pos = move.QuadPart;
2026 else if (origin == STREAM_SEEK_CUR)
2027 stream_pos += move.QuadPart;
2028 else if (origin == STREAM_SEEK_END)
2029 stream_pos = sizeof(stream_data) - 1 - move.QuadPart;
2030
2031 if (newpos) newpos->QuadPart = stream_pos;
2032 return S_OK;
2033 }
2034
2035 static HRESULT WINAPI stream_SetSize(IStream *iface, ULARGE_INTEGER newsize)
2036 {
2037 ok(FALSE, "unexpected call\n");
2038 return E_NOTIMPL;
2039 }
2040
2041 static HRESULT WINAPI stream_CopyTo(IStream *iface, IStream *stream, ULARGE_INTEGER len,
2042 ULARGE_INTEGER *read, ULARGE_INTEGER *written)
2043 {
2044 ok(FALSE, "unexpected call\n");
2045 return E_NOTIMPL;
2046 }
2047
2048 static HRESULT WINAPI stream_Commit(IStream *iface, DWORD flags)
2049 {
2050 ok(FALSE, "unexpected call\n");
2051 return E_NOTIMPL;
2052 }
2053
2054 static HRESULT WINAPI stream_Revert(IStream *iface)
2055 {
2056 ok(FALSE, "unexpected call\n");
2057 return E_NOTIMPL;
2058 }
2059
2060 static HRESULT WINAPI stream_LockRegion(IStream *iface, ULARGE_INTEGER offset,
2061 ULARGE_INTEGER len, DWORD locktype)
2062 {
2063 ok(FALSE, "unexpected call\n");
2064 return E_NOTIMPL;
2065 }
2066
2067 static HRESULT WINAPI stream_UnlockRegion(IStream *iface, ULARGE_INTEGER offset,
2068 ULARGE_INTEGER len, DWORD locktype)
2069 {
2070 ok(FALSE, "unexpected call\n");
2071 return E_NOTIMPL;
2072 }
2073
2074 static HRESULT WINAPI stream_Stat(IStream *iface, STATSTG *stg, DWORD flag)
2075 {
2076 ok(FALSE, "unexpected call\n");
2077 return E_NOTIMPL;
2078 }
2079
2080 static HRESULT WINAPI stream_Clone(IStream *iface, IStream **stream)
2081 {
2082 ok(FALSE, "unexpected call\n");
2083 return E_NOTIMPL;
2084 }
2085
2086 static /* const */ IStreamVtbl stream_vtbl =
2087 {
2088 stream_QueryInterface,
2089 stream_AddRef,
2090 stream_Release,
2091 stream_Read,
2092 stream_Write,
2093 stream_Seek,
2094 stream_SetSize,
2095 stream_CopyTo,
2096 stream_Commit,
2097 stream_Revert,
2098 stream_LockRegion,
2099 stream_UnlockRegion,
2100 stream_Stat,
2101 stream_Clone
2102 };
2103
2104 static IStream test_stream = { &stream_vtbl };
2105
2106 static void test_DetectOutboundCodePageInIStream(IMultiLanguage3 *ml)
2107 {
2108 HRESULT hr;
2109 UINT nb_detected, detected[4];
2110 UINT preferred[] = {1250,1251,1252,65001};
2111 UINT preferred2[] = {1250,1251,1252};
2112
2113 nb_detected = 0;
2114 memset(detected, 0, sizeof(detected));
2115 hr = IMultiLanguage3_DetectOutboundCodePageInIStream(ml,
2116 MLDETECTF_PRESERVE_ORDER, &test_stream, preferred,
2117 sizeof(preferred)/sizeof(preferred[0]), detected, &nb_detected, NULL);
2118 ok(hr == E_INVALIDARG, "got %08x\n", hr);
2119
2120 nb_detected = 1;
2121 memset(detected, 0, sizeof(detected));
2122 hr = IMultiLanguage3_DetectOutboundCodePageInIStream(ml,
2123 MLDETECTF_PRESERVE_ORDER, &test_stream, preferred,
2124 sizeof(preferred)/sizeof(preferred[0]), NULL, &nb_detected, NULL);
2125 ok(hr == E_INVALIDARG, "got %08x\n", hr);
2126
2127 nb_detected = 1;
2128 memset(detected, 0, sizeof(detected));
2129 hr = IMultiLanguage3_DetectOutboundCodePageInIStream(ml,
2130 MLDETECTF_PRESERVE_ORDER, &test_stream, preferred,
2131 sizeof(preferred)/sizeof(preferred[0]), detected, &nb_detected, NULL);
2132 ok(hr == S_OK, "got %08x\n", hr);
2133 ok(nb_detected == 1, "got %u\n", nb_detected);
2134 ok(detected[0] == 65001, "got %u\n", detected[0]);
2135
2136 nb_detected = 2;
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 todo_wine ok(nb_detected == 2, "got %u\n", nb_detected);
2143 ok(detected[0] == 65001, "got %u\n", detected[0]);
2144 todo_wine ok(detected[1] == 65000, "got %u\n", detected[1]);
2145
2146 nb_detected = 3;
2147 memset(detected, 0, sizeof(detected));
2148 hr = IMultiLanguage3_DetectOutboundCodePageInIStream(ml,
2149 MLDETECTF_PRESERVE_ORDER, &test_stream, preferred,
2150 sizeof(preferred)/sizeof(preferred[0]), detected, &nb_detected, NULL);
2151 ok(hr == S_OK, "got %08x\n", hr);
2152 todo_wine ok(nb_detected == 3, "got %u\n", nb_detected);
2153 ok(detected[0] == 65001, "got %u\n", detected[0]);
2154 todo_wine ok(detected[1] == 65000, "got %u\n", detected[1]);
2155 todo_wine ok(detected[2] == 1200, "got %u\n", detected[2]);
2156
2157 nb_detected = 4;
2158 memset(detected, 0, sizeof(detected));
2159 hr = IMultiLanguage3_DetectOutboundCodePageInIStream(ml,
2160 MLDETECTF_PRESERVE_ORDER, &test_stream, preferred,
2161 sizeof(preferred)/sizeof(preferred[0]), detected, &nb_detected, NULL);
2162 ok(hr == S_OK, "got %08x\n", hr);
2163 todo_wine ok(nb_detected == 3, "got %u\n", nb_detected);
2164 ok(detected[0] == 65001, "got %u\n", detected[0]);
2165 todo_wine ok(detected[1] == 65000, "got %u\n", detected[1]);
2166 todo_wine ok(detected[2] == 1200, "got %u\n", detected[2]);
2167 ok(detected[3] == 0, "got %u\n", detected[3]);
2168
2169 nb_detected = 3;
2170 memset(detected, 0, sizeof(detected));
2171 hr = IMultiLanguage3_DetectOutboundCodePageInIStream(ml,
2172 MLDETECTF_PRESERVE_ORDER, &test_stream, preferred2,
2173 sizeof(preferred2)/sizeof(preferred2[0]), detected, &nb_detected, NULL);
2174 ok(hr == S_OK, "got %08x\n", hr);
2175 todo_wine ok(nb_detected == 3, "got %u\n", nb_detected);
2176 ok(detected[0] == 65001, "got %u\n", detected[0]);
2177 todo_wine ok(detected[1] == 65000, "got %u\n", detected[1]);
2178 todo_wine ok(detected[2] == 1200, "got %u\n", detected[2]);
2179 }
2180
2181 START_TEST(mlang)
2182 {
2183 IMultiLanguage *iML = NULL;
2184 IMultiLanguage2 *iML2 = NULL;
2185 IMultiLanguage3 *iML3 = NULL;
2186 IMLangFontLink *iMLFL = NULL;
2187 IMLangFontLink2 *iMLFL2 = NULL;
2188 HRESULT ret;
2189
2190 if (!init_function_ptrs())
2191 return;
2192
2193 CoInitialize(NULL);
2194 test_Rfc1766ToLcid();
2195 test_LcidToRfc1766();
2196
2197 test_ConvertINetUnicodeToMultiByte();
2198 test_JapaneseConversion();
2199
2200 test_GetGlobalFontLinkObject();
2201
2202 trace("IMultiLanguage\n");
2203 ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
2204 &IID_IMultiLanguage, (void **)&iML);
2205 if (ret != S_OK || !iML) return;
2206
2207 test_GetNumberOfCodePageInfo((IMultiLanguage2 *)iML);
2208 test_IMLangConvertCharset(iML);
2209 test_GetCharsetInfo_alias(iML);
2210 IMultiLanguage_Release(iML);
2211
2212
2213 /* IMultiLanguage2 (IE5.0 and above) */
2214 trace("IMultiLanguage2\n");
2215 ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
2216 &IID_IMultiLanguage2, (void **)&iML2);
2217 if (ret != S_OK || !iML2) return;
2218
2219 test_rfc1766(iML2);
2220 test_GetLcidFromRfc1766(iML2);
2221 test_GetRfc1766FromLcid(iML2);
2222 test_GetRfc1766Info(iML2);
2223 test_GetNumberOfCodePageInfo(iML2);
2224
2225 test_EnumCodePages(iML2, 0);
2226 test_EnumCodePages(iML2, MIMECONTF_MIME_LATEST);
2227 test_EnumCodePages(iML2, MIMECONTF_BROWSER);
2228 test_EnumCodePages(iML2, MIMECONTF_MINIMAL);
2229 test_EnumCodePages(iML2, MIMECONTF_VALID);
2230 /* FIXME: why MIMECONTF_MIME_REGISTRY returns 0 of supported codepages? */
2231 /*test_EnumCodePages(iML2, MIMECONTF_MIME_REGISTRY);*/
2232
2233 test_EnumScripts(iML2, 0);
2234 test_EnumScripts(iML2, SCRIPTCONTF_SCRIPT_USER);
2235 test_EnumScripts(iML2, SCRIPTCONTF_SCRIPT_USER | SCRIPTCONTF_SCRIPT_HIDE | SCRIPTCONTF_SCRIPT_SYSTEM);
2236
2237 ret = IMultiLanguage2_IsConvertible(iML2, CP_UTF8, CP_UNICODE);
2238 ok(ret == S_OK, "IMultiLanguage2_IsConvertible(CP_UTF8 -> CP_UNICODE) = %08x\n", ret);
2239 ret = IMultiLanguage2_IsConvertible(iML2, CP_UNICODE, CP_UTF8);
2240 ok(ret == S_OK, "IMultiLanguage2_IsConvertible(CP_UNICODE -> CP_UTF8) = %08x\n", ret);
2241
2242 test_multibyte_to_unicode_translations(iML2);
2243 test_IMultiLanguage2_ConvertStringFromUnicode(iML2);
2244
2245 test_IsCodePageInstallable(iML2);
2246
2247 IMultiLanguage2_Release(iML2);
2248
2249
2250 /* IMLangFontLink */
2251 ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
2252 &IID_IMLangFontLink, (void **)&iMLFL);
2253 if (ret != S_OK || !iMLFL) return;
2254
2255 IMLangFontLink_Test(iMLFL);
2256 IMLangFontLink_Release(iMLFL);
2257
2258 /* IMLangFontLink2 */
2259 ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
2260 &IID_IMLangFontLink2, (void **)&iMLFL2);
2261 if (ret != S_OK || !iMLFL2) return;
2262
2263 test_GetScriptFontInfo(iMLFL2);
2264 test_GetFontUnicodeRanges(iMLFL2);
2265 test_CodePageToScriptID(iMLFL2);
2266 IMLangFontLink2_Release(iMLFL2);
2267
2268 trace("IMultiLanguage3\n");
2269 ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
2270 &IID_IMultiLanguage3, (void **)&iML3);
2271 if (ret == S_OK)
2272 {
2273 test_DetectOutboundCodePageInIStream(iML3);
2274 IMultiLanguage3_Release(iML3);
2275 }
2276
2277 CoUninitialize();
2278 }