usp10: Add tests for ScriptStringCptoX and ScriptStringXtoCp for activation in later...
[wine/multimedia.git] / dlls / usp10 / tests / usp10.c
blobf9b1decb9fdb45cf20df3330e39b3c142ef189d4
1 /*
2 * Tests for usp10 dll
4 * Copyright 2006 Jeff Latimer
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * Notes:
21 * Uniscribe allows for processing of complex scripts such as joining
22 * and filtering characters and bi-directional text with custom line breaks.
25 #include <assert.h>
26 #include <stdio.h>
28 #include <wine/test.h>
29 #include <winbase.h>
30 #include <wingdi.h>
31 #include <winuser.h>
32 #include <winerror.h>
33 #include <winnls.h>
34 #include <usp10.h>
36 static void test_ScriptItemIzeShapePlace(HDC hdc, unsigned short pwOutGlyphs[256])
38 HRESULT hr;
39 int iMaxProps;
40 const SCRIPT_PROPERTIES **ppSp;
42 int cInChars;
43 int cMaxItems;
44 SCRIPT_ITEM pItem[255];
45 int pcItems;
46 WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
47 WCHAR TestItem2[] = {'T', 'e', 's', 't', 'b', 0};
48 WCHAR TestItem3[] = {'T', 'e', 's', 't', 'c',' ','1','2','3',' ',' ','e','n','d',0};
49 WCHAR TestItem4[] = {'T', 'e', 's', 't', 'c',' ',0x0684,0x0694,0x06a4,' ',' ','e','n','d',0};
50 WCHAR TestItem5[] = {0x0684,'T','e','s','t','c',' ',0x0684,0x0694,0x06a4,' ',' ','e','n','d',0};
52 SCRIPT_CACHE psc;
53 int cChars;
54 int cMaxGlyphs;
55 unsigned short pwOutGlyphs1[256];
56 unsigned short pwOutGlyphs2[256];
57 unsigned short pwLogClust[256];
58 SCRIPT_VISATTR psva[256];
59 int pcGlyphs;
60 int piAdvance[256];
61 GOFFSET pGoffset[256];
62 ABC pABC[256];
63 LOGFONTA lf;
64 HFONT zfont;
65 int cnt;
68 lstrcpyA(lf.lfFaceName, "Symbol");
69 lf.lfHeight = 10;
70 lf.lfItalic = 0;
71 lf.lfEscapement = 0;
72 lf.lfOrientation = 0;
73 lf.lfUnderline = 0;
74 lf.lfStrikeOut = 0;
75 lf.lfWeight = 3;
76 lf.lfWidth = 10;
78 zfont = (HFONT) SelectObject(hdc, CreateFontIndirectA(&lf));
80 /* Start testing usp10 functions */
81 /* This test determines that the pointer returned by ScriptGetProperties is valid
82 * by checking a known value in the table */
83 hr = ScriptGetProperties(&ppSp, &iMaxProps);
84 trace("number of script properties %d\n", iMaxProps);
85 ok (iMaxProps > 0, "Number of scripts returned should not be 0\n");
86 if (iMaxProps > 0)
87 ok( ppSp[5]->langid == 9, "Langid[5] not = to 9\n"); /* Check a known value to ensure */
88 /* ptrs work */
91 /* This set of tests are to check that the various edits in ScriptIemize work */
92 cInChars = 5; /* Length of test without NULL */
93 cMaxItems = 1; /* Check threshold value */
94 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
95 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if cMaxItems < 2. Was %d\n",
96 cMaxItems);
97 cInChars = 5;
98 cMaxItems = 255;
99 hr = ScriptItemize(NULL, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
100 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if pwcInChars is NULL\n");
102 cInChars = 5;
103 cMaxItems = 255;
104 hr = ScriptItemize(TestItem1, 0, cMaxItems, NULL, NULL, pItem, &pcItems);
105 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if cInChars is 0\n");
107 cInChars = 5;
108 cMaxItems = 255;
109 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, NULL, &pcItems);
110 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if pItems is NULL\n");
112 /* This is a valid test that will cause parsing to take place */
113 cInChars = 5;
114 cMaxItems = 255;
115 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
116 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
117 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
118 * returned. */
119 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
120 if (pcItems > 0)
121 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
122 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
123 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
125 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
126 * ie. ScriptItemize has succeeded and that pItem has been set */
127 cInChars = 5;
128 cMaxItems = 255;
129 if (hr == 0) {
130 psc = NULL; /* must be null on first call */
131 cChars = cInChars;
132 cMaxGlyphs = cInChars;
133 hr = ScriptShape(NULL, &psc, TestItem1, cChars,
134 cMaxGlyphs, &pItem[0].a,
135 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
136 ok (hr == E_PENDING, "If psc is NULL (%08x) the E_PENDING should be returned\n", hr);
137 cMaxGlyphs = 4;
138 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
139 cMaxGlyphs, &pItem[0].a,
140 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
141 ok (hr == E_OUTOFMEMORY, "If not enough output area cChars (%d) is > than CMaxGlyphs "
142 "(%d) but not E_OUTOFMEMORY\n",
143 cChars, cMaxGlyphs);
144 cMaxGlyphs = 256;
145 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
146 cMaxGlyphs, &pItem[0].a,
147 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
148 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
149 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
150 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
151 if (hr ==0) {
152 hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
153 pGoffset, pABC);
154 ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", hr);
155 hr = ScriptPlace(NULL, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
156 pGoffset, pABC);
157 ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", hr);
158 for (cnt=0; cnt < pcGlyphs; cnt++)
159 pwOutGlyphs[cnt] = pwOutGlyphs1[cnt]; /* Send to next function */
162 /* This test will check to make sure that SCRIPT_CACHE is reused and that not translation *
163 * takes place if fNoGlyphIndex is set. */
165 cInChars = 5;
166 cMaxItems = 255;
167 hr = ScriptItemize(TestItem2, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
168 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
169 /* This test is for the intertrim operation of ScriptItemize where only one SCRIPT_ITEM is *
170 * returned. */
171 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
172 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
173 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
174 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue */
175 if (hr == 0) {
176 cChars = cInChars;
177 cMaxGlyphs = 256;
178 pItem[0].a.fNoGlyphIndex = 1; /* say no translate */
179 hr = ScriptShape(NULL, &psc, TestItem2, cChars,
180 cMaxGlyphs, &pItem[0].a,
181 pwOutGlyphs2, pwLogClust, psva, &pcGlyphs);
182 ok (hr != E_PENDING, "If psc should not be NULL (%08x) and the E_PENDING should be returned\n", hr);
183 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
184 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
185 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
186 for (cnt=0; cnt < cChars && TestItem2[cnt] == pwOutGlyphs2[cnt]; cnt++) {}
187 ok (cnt == cChars, "Translation to place when told not to. WCHAR %d - %04x != %04x\n",
188 cnt, TestItem2[cnt], pwOutGlyphs2[cnt]);
189 if (hr ==0) {
190 hr = ScriptPlace(hdc, &psc, pwOutGlyphs2, pcGlyphs, psva, &pItem[0].a, piAdvance,
191 pGoffset, pABC);
192 ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", hr);
195 hr = ScriptFreeCache( &psc);
196 ok (!psc, "psc is not null after ScriptFreeCache\n");
200 /* This is a valid test that will cause parsing to take place and create 3 script_items */
201 cInChars = (sizeof(TestItem3)/2)-1;
202 cMaxItems = 255;
203 hr = ScriptItemize(TestItem3, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
204 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
205 if (hr == 0)
207 ok (pcItems == 3, "The number of SCRIPT_ITEMS should be 3 not %d\n", pcItems);
208 if (pcItems > 2)
210 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == 6,
211 "Start pos [0] not = 0 (%d) or end pos [1] not = %d\n",
212 pItem[0].iCharPos, pItem[1].iCharPos);
213 ok (pItem[1].iCharPos == 6 && pItem[2].iCharPos == 11,
214 "Start pos [1] not = 6 (%d) or end pos [2] not = 11 (%d)\n",
215 pItem[1].iCharPos, pItem[2].iCharPos);
216 ok (pItem[2].iCharPos == 11 && pItem[3].iCharPos == cInChars,
217 "Start pos [2] not = 11 (%d) or end [3] pos not = 14 (%d), cInChars = %d\n",
218 pItem[2].iCharPos, pItem[3].iCharPos, cInChars);
220 hr = ScriptFreeCache( &psc);
221 ok (!psc, "psc is not null after ScriptFreeCache\n");
224 /* This is a valid test that will cause parsing to take place and create 3 script_items */
225 cInChars = (sizeof(TestItem4)/2)-1;
226 cMaxItems = 255;
227 hr = ScriptItemize(TestItem4, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
228 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
229 if (hr == 0)
231 ok (pcItems == 3, "The number of SCRIPT_ITEMS should be 3 not %d\n", pcItems);
232 if (pcItems > 2)
234 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == 6,
235 "Start pos [0] not = 0 (%d) or end pos [1] not = %d\n",
236 pItem[0].iCharPos, pItem[1].iCharPos);
237 ok (pItem[1].iCharPos == 6 && pItem[2].iCharPos == 11,
238 "Start pos [1] not = 6 (%d) or end pos [2] not = 11 (%d)\n",
239 pItem[1].iCharPos, pItem[2].iCharPos);
240 ok (pItem[2].iCharPos == 11 && pItem[3].iCharPos == cInChars,
241 "Start pos [2] not = 11 (%d) or end [3] pos not = 14 (%d), cInChars = %d\n",
242 pItem[2].iCharPos, pItem[3].iCharPos, cInChars);
244 hr = ScriptFreeCache( &psc);
245 ok (!psc, "psc is not null after ScriptFreeCache\n");
249 * This test is for when the first unicode character requires bidi support
251 cInChars = (sizeof(TestItem5)-1)/sizeof(WCHAR);
252 hr = ScriptItemize(TestItem5, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
253 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
254 ok (pcItems == 4, "There should have been 4 items, found %d\n", pcItems);
255 ok (pItem[0].a.s.uBidiLevel == 1, "The first character should have been bidi=1 not %d\n",
256 pItem[0].a.s.uBidiLevel);
259 void test_ScriptGetCMap(HDC hdc, unsigned short pwOutGlyphs[256])
261 HRESULT hr;
262 SCRIPT_CACHE psc = NULL;
263 int cInChars;
264 int cChars;
265 unsigned short pwOutGlyphs3[256];
266 WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
267 DWORD dwFlags;
268 int cnt;
270 /* Check to make sure that SCRIPT_CACHE gets allocated ok */
271 dwFlags = 0;
272 cInChars = cChars = 5;
273 /* Some sanity checks for ScriptGetCMap */
275 hr = ScriptGetCMap(NULL, NULL, NULL, 0, 0, NULL);
276 ok( hr == E_INVALIDARG, "(NULL,NULL,NULL,0,0,NULL), "
277 "expected E_INVALIDARG, got %08x\n", hr);
279 hr = ScriptGetCMap(NULL, NULL, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
280 ok( hr == E_INVALIDARG, "(NULL,NULL,TestItem1, cInChars, dwFlags, pwOutGlyphs3), "
281 "expected E_INVALIDARG, got %08x\n", hr);
283 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
284 psc = NULL;
285 hr = ScriptGetCMap(NULL, &psc, NULL, 0, 0, NULL);
286 ok( hr == E_PENDING, "(NULL,&psc,NULL,0,0NULL), expected E_PENDING, "
287 "got %08x\n", hr);
288 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
290 /* Set psc to NULL but add hdc, to be able to check if a pointer is returned in psc */
291 psc = NULL;
292 hr = ScriptGetCMap(hdc, &psc, NULL, 0, 0, NULL);
293 ok( hr == S_OK, "ScriptGetCMap(NULL,&psc,NULL,0,0,NULL), expected S_OK, "
294 "got %08x\n", hr);
295 ok( psc != NULL, "ScritpGetCMap expected psc to be not NULL\n");
297 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
298 psc = NULL;
299 hr = ScriptGetCMap(NULL, &psc, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
300 ok( hr == E_PENDING, "(NULL,&psc,), expected E_PENDING, got %08x\n", hr);
301 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
302 /* Check to see if the results are the same as those returned by ScriptShape */
303 hr = ScriptGetCMap(hdc, &psc, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
304 ok (hr == 0, "ScriptGetCMap should return 0 not (%08x)\n", hr);
305 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
306 for (cnt=0; cnt < cChars && pwOutGlyphs[cnt] == pwOutGlyphs3[cnt]; cnt++) {}
307 ok (cnt == cInChars, "Translation not correct. WCHAR %d - %04x != %04x\n",
308 cnt, pwOutGlyphs[cnt], pwOutGlyphs3[cnt]);
310 hr = ScriptFreeCache( &psc);
311 ok (!psc, "psc is not null after ScriptFreeCache\n");
315 void test_ScriptGetFontProperties(void)
317 HRESULT hr;
318 HDC hdc;
319 HWND hwnd;
320 SCRIPT_CACHE psc,old_psc;
321 SCRIPT_FONTPROPERTIES sfp;
323 /* Only do the bare minumum to get a valid hdc */
324 hwnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,0, 0, 0, NULL);
325 assert(hwnd != 0);
327 hdc = GetDC(hwnd);
328 ok( hdc != NULL, "HDC failed to be created %p\n", hdc);
330 /* Some sanity checks for ScriptGetFontProperties */
332 hr = ScriptGetFontProperties(NULL,NULL,NULL);
333 ok( hr == E_INVALIDARG, "(NULL,NULL,NULL), expected E_INVALIDARG, got %08x\n", hr);
335 hr = ScriptGetFontProperties(NULL,NULL,&sfp);
336 ok( hr == E_INVALIDARG, "(NULL,NULL,&sfp), expected E_INVALIDARG, got %08x\n", hr);
338 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
339 psc = NULL;
340 hr = ScriptGetFontProperties(NULL,&psc,NULL);
341 ok( hr == E_INVALIDARG, "(NULL,&psc,NULL), expected E_INVALIDARG, got %08x\n", hr);
342 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
344 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
345 psc = NULL;
346 hr = ScriptGetFontProperties(NULL,&psc,&sfp);
347 ok( hr == E_PENDING, "(NULL,&psc,&sfp), expected E_PENDING, got %08x\n", hr);
348 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
350 hr = ScriptGetFontProperties(hdc,NULL,NULL);
351 ok( hr == E_INVALIDARG, "(hdc,NULL,NULL), expected E_INVALIDARG, got %08x\n", hr);
353 hr = ScriptGetFontProperties(hdc,NULL,&sfp);
354 ok( hr == E_INVALIDARG, "(hdc,NULL,&sfp), expected E_INVALIDARG, got %08x\n", hr);
356 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
357 psc = NULL;
358 hr = ScriptGetFontProperties(hdc,&psc,NULL);
359 ok( hr == E_INVALIDARG, "(hdc,&psc,NULL), expected E_INVALIDARG, got %08x\n", hr);
360 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
362 /* Pass an uninitialized sfp */
363 psc = NULL;
364 hr = ScriptGetFontProperties(hdc,&psc,&sfp);
365 ok( hr == E_INVALIDARG, "(hdc,&psc,&sfp) partly uninitialized, expected E_INVALIDARG, got %08x\n", hr);
366 ok( psc != NULL, "Expected a pointer in psc, got NULL\n");
367 ScriptFreeCache(&psc);
368 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
370 /* Give it the correct cBytes, we don't care about what's coming back */
371 sfp.cBytes = sizeof(SCRIPT_FONTPROPERTIES);
372 psc = NULL;
373 hr = ScriptGetFontProperties(hdc,&psc,&sfp);
374 ok( hr == S_OK, "(hdc,&psc,&sfp) partly initialized, expected S_OK, got %08x\n", hr);
375 ok( psc != NULL, "Expected a pointer in psc, got NULL\n");
377 /* Save the psc pointer */
378 old_psc = psc;
379 /* Now a NULL hdc again */
380 hr = ScriptGetFontProperties(NULL,&psc,&sfp);
381 ok( hr == S_OK, "(NULL,&psc,&sfp), expected S_OK, got %08x\n", hr);
382 ok( psc == old_psc, "Expected psc not to be changed, was %p is now %p\n", old_psc, psc);
383 ScriptFreeCache(&psc);
384 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
386 /* Cleanup */
387 ReleaseDC(hwnd, hdc);
388 DestroyWindow(hwnd);
391 void test_ScriptTextOut(void)
393 HRESULT hr;
394 HWND hwnd;
395 HDC hdc;
397 int cInChars;
398 int cMaxItems;
399 SCRIPT_ITEM pItem[255];
400 int pcItems;
401 WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
403 SCRIPT_CACHE psc;
404 int cChars;
405 int cMaxGlyphs;
406 unsigned short pwOutGlyphs1[256];
407 WORD pwLogClust[256];
408 SCRIPT_VISATTR psva[256];
409 int pcGlyphs;
410 int piAdvance[256];
411 GOFFSET pGoffset[256];
412 ABC pABC[256];
413 RECT rect;
414 int piX;
415 int iCP = 1;
416 BOOL fTrailing = FALSE;
417 SCRIPT_LOGATTR *psla;
418 SCRIPT_LOGATTR sla[256];
420 /* We need a valid HDC to drive a lot of Script functions which requires the following *
421 * to set up for the tests. */
422 hwnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,
423 0, 0, 0, NULL);
424 assert(hwnd != 0);
425 ShowWindow(hwnd, SW_SHOW);
426 UpdateWindow(hwnd);
428 hdc = GetDC(hwnd); /* We now have a hdc */
429 ok( hdc != NULL, "HDC failed to be created %p\n", hdc);
431 /* This is a valid test that will cause parsing to take place */
432 cInChars = 5;
433 cMaxItems = 255;
434 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
435 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
436 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
437 * returned. */
438 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
439 if (pcItems > 0)
440 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
441 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
442 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
444 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
445 * ie. ScriptItemize has succeeded and that pItem has been set */
446 cInChars = 5;
447 cMaxItems = 255;
448 if (hr == 0) {
449 psc = NULL; /* must be null on first call */
450 cChars = cInChars;
451 cMaxGlyphs = cInChars;
452 cMaxGlyphs = 256;
453 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
454 cMaxGlyphs, &pItem[0].a,
455 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
456 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
457 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
458 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
459 if (hr ==0) {
460 /* Note hdc is needed as glyph info is not yet in psc */
461 hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
462 pGoffset, pABC);
463 ok (hr == 0, "Should return 0 not (%08x)\n", hr);
464 ScriptFreeCache(&psc); /* Get rid of psc for next test set */
465 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
467 hr = ScriptTextOut(NULL, NULL, 0, 0, 0, NULL, NULL, NULL, 0, NULL, 0, NULL, NULL, NULL);
468 ok (hr == E_INVALIDARG, "Should return 0 not (%08x)\n", hr);
470 hr = ScriptTextOut(NULL, NULL, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
471 piAdvance, NULL, pGoffset);
472 ok( hr == E_INVALIDARG, "(NULL,NULL,TestItem1, cInChars, dwFlags, pwOutGlyphs3), "
473 "expected E_INVALIDARG, got %08x\n", hr);
475 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
476 psc = NULL;
477 hr = ScriptTextOut(NULL, &psc, 0, 0, 0, NULL, NULL, NULL, 0, NULL, 0,
478 NULL, NULL, NULL);
479 ok( hr == E_INVALIDARG, "(NULL,&psc,NULL,0,0,0,NULL,), expected E_INVALIDARG, "
480 "got %08x\n", hr);
481 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
483 /* Set psc to NULL, to be able to check if a pointer is returned in psc
484 * hdc is required for this one rather than the usual optional */
485 psc = NULL;
486 hr = ScriptTextOut(NULL, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
487 piAdvance, NULL, pGoffset);
488 ok( hr == E_INVALIDARG, "(NULL,&psc,), expected E_INVALIDARG, got %08x\n", hr);
489 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
491 /* Set that is gets a psc and that returns 0 status */
492 hr = ScriptTextOut(hdc, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
493 piAdvance, NULL, pGoffset);
494 ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
495 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
497 /* Test Rect Rgn is acceptable */
498 rect.top = 10;
499 rect.bottom = 20;
500 rect.left = 10;
501 rect.right = 40;
502 hr = ScriptTextOut(hdc, &psc, 0, 0, 0, &rect, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
503 piAdvance, NULL, pGoffset);
504 ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
505 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
507 iCP = 1;
508 hr = ScriptCPtoX(iCP, fTrailing, cChars, pcGlyphs, (const WORD *) &pwLogClust,
509 (const SCRIPT_VISATTR *) &psva, (const int *)&piAdvance, &pItem[0].a, &piX);
510 ok(hr == S_OK, "ScriptCPtoX Stub should return S_OK not %08x\n", hr);
512 psla = (SCRIPT_LOGATTR *)&sla;
513 hr = ScriptBreak(TestItem1, cChars, &pItem[0].a, psla);
514 ok(hr == S_OK, "ScriptBreak Stub should return S_OK not %08x\n", hr);
516 /* Clean up and go */
517 ScriptFreeCache(&psc);
518 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
521 ReleaseDC(hwnd, hdc);
522 DestroyWindow(hwnd);
525 static void test_ScriptXtoX(void)
526 /****************************************************************************************
527 * This routine tests the ScriptXtoCP and ScriptCPtoX functions using static variables *
528 ****************************************************************************************/
530 int iX, iCP;
531 int cChars;
532 int cGlyphs;
533 WORD pwLogClust[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
534 SCRIPT_VISATTR psva[10];
535 int piAdvance[10] = {200, 190, 210, 180, 170, 204, 189, 195, 212, 203};
536 SCRIPT_ANALYSIS psa;
537 int piCP, piX;
538 int piTrailing;
539 BOOL fTrailing;
540 HRESULT hr;
542 iX = -1;
543 cChars = 10;
544 cGlyphs = 10;
545 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &psa, &piCP, &piTrailing);
546 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
547 ok(piCP == -1, "Negative iX should return piCP=-1 not %d\n", piCP);
548 ok(piTrailing == TRUE, "Negative iX should return piTrailing=TRUE not %d\n", piTrailing);
549 iX = 1954;
550 cChars = 10;
551 cGlyphs = 10;
552 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &psa, &piCP, &piTrailing);
553 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
554 ok(piCP == 10, "Excessive iX should return piCP=10 not %d\n", piCP);
555 ok(piTrailing == FALSE, "Excessive iX should return piTrailing=FALSE not %d\n", piTrailing);
556 iX = 779;
557 cChars = 10;
558 cGlyphs = 10;
559 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &psa, &piCP, &piTrailing);
560 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
561 ok(piCP == 3, "iX=%d should return piCP=3 not %d\n", iX, piCP);
562 ok(piTrailing == 1, "iX=%d should return piTrailing=1 not %d\n", iX, piTrailing);
563 iX = 780;
564 cChars = 10;
565 cGlyphs = 10;
566 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &psa, &piCP, &piTrailing);
567 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
568 ok(piCP == 3, "iX=%d should return piCP=3 not %d\n", iX, piCP);
569 ok(piTrailing == 1, "iX=%d should return piTrailing=1 not %d\n", iX, piTrailing);
570 iX = 868;
571 cChars = 10;
572 cGlyphs = 10;
573 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &psa, &piCP, &piTrailing);
574 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
575 ok(piCP == 4, "iX=%d should return piCP=4 not %d\n", iX, piCP);
577 iCP=5;
578 fTrailing = FALSE;
579 cChars = 10;
580 cGlyphs = 10;
581 hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance, &psa, &piX);
582 ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
583 ok(piX == 976, "iCP=%d should return piX=976 not %d\n", iCP, piX);
584 iCP=5;
585 fTrailing = TRUE;
586 cChars = 10;
587 cGlyphs = 10;
588 hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance, &psa, &piX);
589 ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
590 ok(piX == 1171, "iCP=%d should return piX=1171 not %d\n", iCP, piX);
591 iCP=6;
592 fTrailing = FALSE;
593 cChars = 10;
594 cGlyphs = 10;
595 hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance, &psa, &piX);
596 ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
597 ok(piX == 1171, "iCP=%d should return piX=1171 not %d\n", iCP, piX);
598 iCP=11;
599 fTrailing = FALSE;
600 cChars = 10;
601 cGlyphs = 10;
602 hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance, &psa, &piX);
603 ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
604 ok(piX == 1953, "iCP=%d should return piX=1953 not %d\n", iCP, piX);
605 iCP=11;
606 fTrailing = TRUE;
607 cChars = 10;
608 cGlyphs = 10;
609 hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance, &psa, &piX);
610 ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
611 ok(piX == 1953, "iCP=%d should return piX=1953 not %d\n", iCP, piX);
615 static void test_ScriptString(void)
617 /*******************************************************************************************
619 * This set of tests are for the string functions of uniscribe. The ScriptStringAnalyse
620 * function allocates memory pointed to by the SCRIPT_STRING_ANALYSIS ssa pointer. This
621 * memory if freed by ScriptStringFree. There needs to be a valid hdc for this this as
622 * ScriptStrinAnalyse calls ScriptSItemize, ScriptShape and ScriptPlace which require it.
626 HRESULT hr;
627 HWND hwnd;
628 HDC hdc = 0;
629 WCHAR teststr[] = {'T','e','s','t','1',' ','a','2','b','3', '\0'};
630 int String = (sizeof(teststr)/sizeof(WCHAR))-1;
631 int Glyphs = String * 2 + 16;
632 int Charset;
633 DWORD Flags = SSA_GLYPHS;
634 int ReqWidth = 100;
635 SCRIPT_CONTROL Control;
636 SCRIPT_STATE State;
637 const int Dx[5] = {10, 10, 10, 10, 10};
638 SCRIPT_TABDEF Tabdef;
639 const BYTE InClass = 0;
640 SCRIPT_STRING_ANALYSIS ssa = NULL;
642 int X = 10;
643 int Y = 100;
644 UINT Options = 0;
645 const RECT rc = {0, 50, 100, 100};
646 int MinSel = 0;
647 int MaxSel = 0;
648 BOOL Disabled = FALSE;
650 LOGFONTA lf;
651 HFONT zfont;
653 /* We need a valid HDC to drive a lot of Script functions which requires the following *
654 * to set up for the tests. */
655 hwnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,
656 0, 0, 0, NULL);
657 assert(hwnd != 0);
659 hdc = GetDC(hwnd); /* We now have a hdc */
660 ok( hdc != NULL, "HDC failed to be created %p\n", hdc);
662 lstrcpyA(lf.lfFaceName, "Symbol");
663 lf.lfHeight = 10;
664 lf.lfItalic = 0;
665 lf.lfEscapement = 0;
666 lf.lfOrientation = 0;
667 lf.lfUnderline = 0;
668 lf.lfStrikeOut = 0;
669 lf.lfWeight = 300;
670 lf.lfWidth = 10;
672 zfont = (HFONT) SelectObject(hdc, CreateFontIndirectA(&lf));
674 Charset = -1; /* this flag indicates unicode input */
675 /* Test without hdc to get E_INVALIDARG */
676 hr = ScriptStringAnalyse( NULL, teststr, String, Glyphs, Charset, Flags,
677 ReqWidth, &Control, &State, Dx, &Tabdef,
678 &InClass, &ssa);
679 ok(hr == E_PENDING, "ScriptStringAnalyse Stub should return E_PENDING not %08x\n", hr);
681 /* test with hdc, this should be a valid test */
682 hr = ScriptStringAnalyse( hdc, teststr, String, Glyphs, Charset, Flags,
683 ReqWidth, &Control, &State, Dx, &Tabdef,
684 &InClass, &ssa);
685 todo_wine ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
687 /* test makes sure that a call with a valid pssa still works */
688 hr = ScriptStringAnalyse( hdc, teststr, String, Glyphs, Charset, Flags,
689 ReqWidth, &Control, &State, Dx, &Tabdef,
690 &InClass, &ssa);
691 todo_wine ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
692 todo_wine ok(ssa != NULL, "ScriptStringAnalyse pssa should not be NULL\n");
694 if (hr == 0)
696 hr = ScriptStringOut(ssa, X, Y, Options, &rc, MinSel, MaxSel, Disabled);
697 todo_wine ok(hr == S_OK, "ScriptStringOut should return S_OK not %08x\n", hr);
698 hr = ScriptStringFree(&ssa);
699 todo_wine ok(hr == S_OK, "ScriptStringFree should return S_OK not %08x\n", hr);
703 void test_ScriptStringXtoCP_CPtoX(HDC hdc)
705 /*****************************************************************************************
707 * This test is for the ScriptStringXtoCP and ScriptStringXtoCP functions. Due to the
708 * nature of the fonts between Windows and Wine, the test is implemented by generating
709 * values using one one function then checking the output of the second. In this way
710 * the validity of the functions is established using Windows as a base and confirming
711 * similar behaviour in wine.
714 HRESULT hr;
715 WCHAR teststr1[] = {'T', 'e', 's', 't', 'e', '1', '2', ' ', 'a', '\0'};
716 void *String = (WCHAR *) &teststr1; /* ScriptStringAnalysis needs void */
717 int String_len = (sizeof(teststr1)/sizeof(WCHAR))-1;
718 int Glyphs = String_len * 2 + 16; /* size of buffer as recommended */
719 int Charset = -1; /* unicode */
720 DWORD Flags = SSA_GLYPHS;
721 int ReqWidth = 100;
722 SCRIPT_CONTROL Control;
723 SCRIPT_STATE State;
724 SCRIPT_TABDEF Tabdef;
725 const BYTE InClass = 0;
726 SCRIPT_STRING_ANALYSIS ssa = NULL;
728 int Ch; /* Character position in string */
729 int iTrailing;
730 int Cp; /* Character position in string */
731 int X;
732 BOOL fTrailing;
734 LOGFONTA lf;
735 HFONT zfont;
737 lstrcpyA(lf.lfFaceName, "Symbol");
738 lf.lfHeight = 10;
739 lf.lfCharSet = 0;
740 lf.lfItalic = 0;
741 lf.lfEscapement = 0;
742 lf.lfOrientation = 0;
743 lf.lfUnderline = 0;
744 lf.lfStrikeOut = 0;
745 lf.lfWeight = 400;
746 lf.lfWidth = 0;
747 lf.lfPitchAndFamily = 0;
749 zfont = (HFONT) SelectObject(hdc, CreateFontIndirectA(&lf));
751 /* Test with hdc, this should be a valid test
752 * Here we generrate an SCRIPT_STRING_ANALYSIS that will be used as input to the
753 * following character positions to X and X to character position functions.
755 hr = ScriptStringAnalyse( hdc, String, String_len, Glyphs, Charset, Flags,
756 ReqWidth, &Control, &State, NULL, &Tabdef,
757 &InClass, &ssa);
758 todo_wine ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
759 todo_wine ok(ssa != NULL, "ScriptStringAnalyse ssa should not be NULL\n");
760 if (hr == 0)
763 * Loop to generate character positions to provide starting positions for the
764 * ScriptStringCPtoX and ScriptStringXtoCP functions
766 for (Cp = 0; Cp < String_len; Cp++)
768 /* The fTrailing flag is used to indicate whether the X being returned is at
769 * the beginning or the end of the character. What happens here is that if
770 * fTrailing indicates the end of the character, ie. FALSE, then ScriptStringXtoCP
771 * returns the beginning of the next character and iTrailing is FALSE. So for this
772 * loop iTrailing will be FALSE in both cases.
774 fTrailing = FALSE;
775 hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
776 todo_wine ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
777 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
778 todo_wine ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
779 todo_wine ok(Cp == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp, Ch, X);
780 todo_wine ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
781 iTrailing, X);
782 fTrailing = TRUE;
783 hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
784 todo_wine ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
785 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
786 todo_wine ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
789 * Check that character position returned by ScriptStringXtoCP in Ch matches the
790 * one input to ScriptStringCPtoX. This means that the Cp to X position and back
791 * again works
793 todo_wine ok(Cp + 1 == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp + 1, Ch, X);
794 todo_wine ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
795 iTrailing, X);
799 * This test is to check that if the X position is just inside the trailing edge of the
800 * character then iTrailing will indicate the trailing edge, ie. TRUE
802 fTrailing = TRUE;
803 Cp = 3;
804 hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
805 todo_wine ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
806 X--; /* put X just inside the trailing edge */
807 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
808 todo_wine ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
809 todo_wine ok(Cp == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp, Ch, X);
810 todo_wine ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
811 iTrailing, X);
814 * This test is to check that if the X position is just outside the trailing edge of the
815 * character then iTrailing will indicate the leading edge, ie. FALSE, and Ch will indicate
816 * the next character, ie. Cp + 1
818 fTrailing = TRUE;
819 Cp = 3;
820 hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
821 todo_wine ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
822 X++; /* put X just outside the trailing edge */
823 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
824 todo_wine ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
825 todo_wine ok(Cp + 1 == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp + 1, Ch, X);
826 todo_wine ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
827 iTrailing, X);
830 * This test is to check that if the X position is just outside the leading edge of the
831 * character then iTrailing will indicate the trailing edge, ie. TRUE, and Ch will indicate
832 * the next character down , ie. Cp - 1
834 fTrailing = FALSE;
835 Cp = 3;
836 hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
837 todo_wine ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
838 X--; /* put X just outside the leading edge */
839 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
840 todo_wine ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
841 todo_wine ok(Cp - 1 == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp - 1, Ch, X);
842 todo_wine ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
843 iTrailing, X);
846 * Cleanup the the SSA for the next round of tests
848 hr = ScriptStringFree(&ssa);
849 todo_wine ok(hr == S_OK, "ScriptStringFree should return S_OK not %08x\n", hr);
852 * Test to see that exceeding the number of chars returns E_INVALIDARG. First
853 * generate an SSA for the subsequent tests.
855 hr = ScriptStringAnalyse( hdc, String, String_len, Glyphs, Charset, Flags,
856 ReqWidth, &Control, &State, NULL, &Tabdef,
857 &InClass, &ssa);
858 todo_wine ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
861 * When ScriptStringCPtoX is called with a character position Cp that exceeds the
862 * string length, return E_INVALIDARG. This also invalidates the ssa so a
863 * ScriptStringFree should also fail.
865 fTrailing = FALSE;
866 Cp = String_len + 1;
867 hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
868 todo_wine ok(hr == E_INVALIDARG, "ScriptStringCPtoX should return E_INVALIDARG not %08x\n", hr);
870 hr = ScriptStringFree(&ssa);
872 * ScriptStringCPtoX should free ssa, hence ScriptStringFree should fail
874 todo_wine ok(hr == E_INVALIDARG, "ScriptStringFree should return E_INVALIDARG not %08x\n", hr);
878 void test_ScriptCacheGetHeight(HDC hdc)
880 HRESULT hr;
881 SCRIPT_CACHE sc = NULL;
882 long height;
884 hr = ScriptCacheGetHeight(NULL, NULL, NULL);
885 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
887 hr = ScriptCacheGetHeight(NULL, &sc, NULL);
888 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
890 hr = ScriptCacheGetHeight(NULL, &sc, &height);
891 ok(hr == E_PENDING, "expected E_PENDING, got 0x%08x\n", hr);
893 height = 0;
895 hr = ScriptCacheGetHeight(hdc, &sc, &height);
896 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
898 ok(height > 0, "expected height > 0\n");
901 void test_ScriptGetGlyphABCWidth(HDC hdc)
903 HRESULT hr;
904 LOGFONTA lf;
905 HFONT hfont;
906 SCRIPT_CACHE sc = NULL;
907 ABC abc;
909 memset(&lf, 0, sizeof(lf));
911 lstrcpyA(lf.lfFaceName, "Symbol");
912 hfont = CreateFontIndirectA(&lf);
913 hfont = SelectObject(hdc, hfont);
915 hr = ScriptGetGlyphABCWidth(NULL, NULL, 'a', NULL);
916 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
918 hr = ScriptGetGlyphABCWidth(NULL, &sc, 'a', NULL);
919 ok(hr == E_PENDING, "expected E_PENDING, got 0x%08x\n", hr);
921 if (0) { /* crashes on WinXP */
922 hr = ScriptGetGlyphABCWidth(hdc, &sc, 'a', NULL);
923 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
926 hr = ScriptGetGlyphABCWidth(hdc, &sc, 'a', &abc);
927 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
930 void test_ScriptLayout(void)
932 HRESULT hr;
933 static const BYTE levels[][5] =
935 { 0, 0, 0, 0, 0 },
936 { 1, 1, 1, 1, 1 },
937 { 2, 2, 2, 2, 2 },
938 { 3, 3, 3, 3, 3 },
940 static const int expect[][5] =
942 { 0, 1, 2, 3, 4 },
943 { 4, 3, 2, 1, 0 },
944 { 0, 1, 2, 3, 4 },
945 { 4, 3, 2, 1, 0 }
947 int i, j, vistolog[sizeof(levels[0])], logtovis[sizeof(levels[0])];
949 hr = ScriptLayout(sizeof(levels[0]), NULL, vistolog, logtovis);
950 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
952 hr = ScriptLayout(sizeof(levels[0]), levels[0], NULL, NULL);
953 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
955 for (i = 0; i < sizeof(levels)/sizeof(levels[0]); i++)
957 hr = ScriptLayout(sizeof(levels[0]), levels[i], vistolog, logtovis);
958 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
960 for (j = 0; j < sizeof(levels[i]); j++)
962 ok(expect[i][j] == vistolog[j],
963 "failure: levels[%d][%d] = %d, vistolog[%d] = %d\n",
964 i, j, levels[i][j], j, vistolog[j] );
967 for (j = 0; j < sizeof(levels[i]); j++)
969 ok(expect[i][j] == logtovis[j],
970 "failure: levels[%d][%d] = %d, logtovis[%d] = %d\n",
971 i, j, levels[i][j], j, logtovis[j] );
976 static const struct
978 LGRPID group;
979 LCID lcid;
980 SCRIPT_DIGITSUBSTITUTE sds;
981 DWORD uDefaultLanguage;
982 DWORD fContextDigits;
983 WORD fDigitSubstitute;
985 subst_data[] =
987 { 0x01, 0x00403, { 9, 3, 1, 0 }, 9, 0, 0 },
988 { 0x01, 0x00406, { 9, 6, 1, 0 }, 9, 0, 0 },
989 { 0x01, 0x00407, { 9, 7, 1, 0 }, 9, 0, 0 },
990 { 0x01, 0x00409, { 9, 9, 1, 0 }, 9, 0, 0 },
991 { 0x01, 0x0040a, { 9, 10, 1, 0 }, 9, 0, 0 },
992 { 0x01, 0x0040b, { 9, 11, 1, 0 }, 9, 0, 0 },
993 { 0x01, 0x0040c, { 9, 12, 1, 0 }, 9, 0, 0 },
994 { 0x01, 0x0040f, { 9, 15, 1, 0 }, 9, 0, 0 },
995 { 0x01, 0x00410, { 9, 16, 1, 0 }, 9, 0, 0 },
996 { 0x01, 0x00413, { 9, 19, 1, 0 }, 9, 0, 0 },
997 { 0x01, 0x00414, { 9, 20, 1, 0 }, 9, 0, 0 },
998 { 0x01, 0x00416, { 9, 22, 1, 0 }, 9, 0, 0 },
999 { 0x01, 0x0041d, { 9, 29, 1, 0 }, 9, 0, 0 },
1000 { 0x01, 0x00421, { 9, 33, 1, 0 }, 9, 0, 0 },
1001 { 0x01, 0x0042d, { 9, 45, 1, 0 }, 9, 0, 0 },
1002 { 0x01, 0x00432, { 9, 50, 1, 0 }, 9, 0, 0 },
1003 { 0x01, 0x00434, { 9, 52, 1, 0 }, 9, 0, 0 },
1004 { 0x01, 0x00435, { 9, 53, 1, 0 }, 9, 0, 0 },
1005 { 0x01, 0x00436, { 9, 54, 1, 0 }, 9, 0, 0 },
1006 { 0x01, 0x00438, { 9, 56, 1, 0 }, 9, 0, 0 },
1007 { 0x01, 0x0043a, { 9, 58, 1, 0 }, 9, 0, 0 },
1008 { 0x01, 0x0043b, { 9, 59, 1, 0 }, 9, 0, 0 },
1009 { 0x01, 0x0043e, { 9, 62, 1, 0 }, 9, 0, 0 },
1010 { 0x01, 0x00441, { 9, 65, 1, 0 }, 9, 0, 0 },
1011 { 0x01, 0x00452, { 9, 82, 1, 0 }, 9, 0, 0 },
1012 { 0x01, 0x00456, { 9, 86, 1, 0 }, 9, 0, 0 },
1013 { 0x01, 0x0046b, { 9, 107, 1, 0 }, 9, 0, 0 },
1014 { 0x01, 0x0046c, { 9, 108, 1, 0 }, 9, 0, 0 },
1015 { 0x01, 0x00481, { 9, 129, 1, 0 }, 9, 0, 0 },
1016 { 0x01, 0x00807, { 9, 7, 1, 0 }, 9, 0, 0 },
1017 { 0x01, 0x00809, { 9, 9, 1, 0 }, 9, 0, 0 },
1018 { 0x01, 0x0080a, { 9, 10, 1, 0 }, 9, 0, 0 },
1019 { 0x01, 0x0080c, { 9, 12, 1, 0 }, 9, 0, 0 },
1020 { 0x01, 0x00810, { 9, 16, 1, 0 }, 9, 0, 0 },
1021 { 0x01, 0x00813, { 9, 19, 1, 0 }, 9, 0, 0 },
1022 { 0x01, 0x00814, { 9, 20, 1, 0 }, 9, 0, 0 },
1023 { 0x01, 0x00816, { 9, 22, 1, 0 }, 9, 0, 0 },
1024 { 0x01, 0x0081d, { 9, 29, 1, 0 }, 9, 0, 0 },
1025 { 0x01, 0x0083b, { 9, 59, 1, 0 }, 9, 0, 0 },
1026 { 0x01, 0x0083e, { 9, 62, 1, 0 }, 9, 0, 0 },
1027 { 0x01, 0x0086b, { 9, 107, 1, 0 }, 9, 0, 0 },
1028 { 0x01, 0x00c07, { 9, 7, 1, 0 }, 9, 0, 0 },
1029 { 0x01, 0x00c09, { 9, 9, 1, 0 }, 9, 0, 0 },
1030 { 0x01, 0x00c0a, { 9, 10, 1, 0 }, 9, 0, 0 },
1031 { 0x01, 0x00c0c, { 9, 12, 1, 0 }, 9, 0, 0 },
1032 { 0x01, 0x00c3b, { 9, 59, 1, 0 }, 9, 0, 0 },
1033 { 0x01, 0x00c6b, { 9, 107, 1, 0 }, 9, 0, 0 },
1034 { 0x01, 0x01007, { 9, 7, 1, 0 }, 9, 0, 0 },
1035 { 0x01, 0x01009, { 9, 9, 1, 0 }, 9, 0, 0 },
1036 { 0x01, 0x0100a, { 9, 10, 1, 0 }, 9, 0, 0 },
1037 { 0x01, 0x0100c, { 9, 12, 1, 0 }, 9, 0, 0 },
1038 { 0x01, 0x0103b, { 9, 59, 1, 0 }, 9, 0, 0 },
1039 { 0x01, 0x01407, { 9, 7, 1, 0 }, 9, 0, 0 },
1040 { 0x01, 0x01409, { 9, 9, 1, 0 }, 9, 0, 0 },
1041 { 0x01, 0x0140a, { 9, 10, 1, 0 }, 9, 0, 0 },
1042 { 0x01, 0x0140c, { 9, 12, 1, 0 }, 9, 0, 0 },
1043 { 0x01, 0x0143b, { 9, 59, 1, 0 }, 9, 0, 0 },
1044 { 0x01, 0x01809, { 9, 9, 1, 0 }, 9, 0, 0 },
1045 { 0x01, 0x0180a, { 9, 10, 1, 0 }, 9, 0, 0 },
1046 { 0x01, 0x0180c, { 9, 12, 1, 0 }, 9, 0, 0 },
1047 { 0x01, 0x0183b, { 9, 59, 1, 0 }, 9, 0, 0 },
1048 { 0x01, 0x01c09, { 9, 9, 1, 0 }, 9, 0, 0 },
1049 { 0x01, 0x01c0a, { 9, 10, 1, 0 }, 9, 0, 0 },
1050 { 0x01, 0x01c3b, { 9, 59, 1, 0 }, 9, 0, 0 },
1051 { 0x01, 0x02009, { 9, 9, 1, 0 }, 9, 0, 0 },
1052 { 0x01, 0x0200a, { 9, 10, 1, 0 }, 9, 0, 0 },
1053 { 0x01, 0x0203b, { 9, 59, 1, 0 }, 9, 0, 0 },
1054 { 0x01, 0x02409, { 9, 9, 1, 0 }, 9, 0, 0 },
1055 { 0x01, 0x0240a, { 9, 10, 1, 0 }, 9, 0, 0 },
1056 { 0x01, 0x0243b, { 9, 59, 1, 0 }, 9, 0, 0 },
1057 { 0x01, 0x02809, { 9, 9, 1, 0 }, 9, 0, 0 },
1058 { 0x01, 0x0280a, { 9, 10, 1, 0 }, 9, 0, 0 },
1059 { 0x01, 0x02c09, { 9, 9, 1, 0 }, 9, 0, 0 },
1060 { 0x01, 0x02c0a, { 9, 10, 1, 0 }, 9, 0, 0 },
1061 { 0x01, 0x03009, { 9, 9, 1, 0 }, 9, 0, 0 },
1062 { 0x01, 0x0300a, { 9, 10, 1, 0 }, 9, 0, 0 },
1063 { 0x01, 0x03409, { 9, 9, 1, 0 }, 9, 0, 0 },
1064 { 0x01, 0x0340a, { 9, 10, 1, 0 }, 9, 0, 0 },
1065 { 0x01, 0x0380a, { 9, 10, 1, 0 }, 9, 0, 0 },
1066 { 0x01, 0x03c0a, { 9, 10, 1, 0 }, 9, 0, 0 },
1067 { 0x01, 0x0400a, { 9, 10, 1, 0 }, 9, 0, 0 },
1068 { 0x01, 0x0440a, { 9, 10, 1, 0 }, 9, 0, 0 },
1069 { 0x01, 0x0480a, { 9, 10, 1, 0 }, 9, 0, 0 },
1070 { 0x01, 0x04c0a, { 9, 10, 1, 0 }, 9, 0, 0 },
1071 { 0x01, 0x0500a, { 9, 10, 1, 0 }, 9, 0, 0 },
1072 { 0x01, 0x10407, { 9, 7, 1, 0 }, 9, 0, 0 },
1073 { 0x02, 0x00405, { 9, 5, 1, 0 }, 9, 0, 0 },
1074 { 0x02, 0x0040e, { 9, 14, 1, 0 }, 9, 0, 0 },
1075 { 0x02, 0x00415, { 9, 21, 1, 0 }, 9, 0, 0 },
1076 { 0x02, 0x00418, { 9, 24, 1, 0 }, 9, 0, 0 },
1077 { 0x02, 0x0041a, { 9, 26, 1, 0 }, 9, 0, 0 },
1078 { 0x02, 0x0041b, { 9, 27, 1, 0 }, 9, 0, 0 },
1079 { 0x02, 0x0041c, { 9, 28, 1, 0 }, 9, 0, 0 },
1080 { 0x02, 0x00424, { 9, 36, 1, 0 }, 9, 0, 0 },
1081 { 0x02, 0x0081a, { 9, 26, 1, 0 }, 9, 0, 0 },
1082 { 0x02, 0x0101a, { 9, 26, 1, 0 }, 9, 0, 0 },
1083 { 0x02, 0x0141a, { 9, 26, 1, 0 }, 9, 0, 0 },
1084 { 0x02, 0x0181a, { 9, 26, 1, 0 }, 9, 0, 0 },
1085 { 0x02, 0x1040e, { 9, 14, 1, 0 }, 9, 0, 0 },
1086 { 0x03, 0x00425, { 9, 37, 1, 0 }, 9, 0, 0 },
1087 { 0x03, 0x00426, { 9, 38, 1, 0 }, 9, 0, 0 },
1088 { 0x03, 0x00427, { 9, 39, 1, 0 }, 9, 0, 0 },
1089 { 0x04, 0x00408, { 9, 8, 1, 0 }, 9, 0, 0 },
1090 { 0x05, 0x00402, { 9, 2, 1, 0 }, 9, 0, 0 },
1091 { 0x05, 0x00419, { 9, 25, 1, 0 }, 9, 0, 0 },
1092 { 0x05, 0x00422, { 9, 34, 1, 0 }, 9, 0, 0 },
1093 { 0x05, 0x00423, { 9, 35, 1, 0 }, 9, 0, 0 },
1094 { 0x05, 0x0042f, { 9, 47, 1, 0 }, 9, 0, 0 },
1095 { 0x05, 0x0043f, { 9, 63, 1, 0 }, 9, 0, 0 },
1096 { 0x05, 0x00440, { 9, 64, 1, 0 }, 9, 0, 0 },
1097 { 0x05, 0x00444, { 9, 68, 1, 0 }, 9, 0, 0 },
1098 { 0x05, 0x00450, { 9, 80, 1, 0 }, 9, 0, 0 },
1099 { 0x05, 0x0082c, { 9, 44, 1, 0 }, 9, 0, 0 },
1100 { 0x05, 0x00843, { 9, 67, 1, 0 }, 9, 0, 0 },
1101 { 0x05, 0x00c1a, { 9, 26, 1, 0 }, 9, 0, 0 },
1102 { 0x05, 0x01c1a, { 9, 26, 1, 0 }, 9, 0, 0 },
1103 { 0x06, 0x0041f, { 9, 31, 1, 0 }, 9, 0, 0 },
1104 { 0x06, 0x0042c, { 9, 44, 1, 0 }, 9, 0, 0 },
1105 { 0x06, 0x00443, { 9, 67, 1, 0 }, 9, 0, 0 },
1106 { 0x07, 0x00411, { 9, 17, 1, 0 }, 9, 0, 0 },
1107 { 0x08, 0x00412, { 9, 18, 1, 0 }, 9, 0, 0 },
1108 { 0x09, 0x00404, { 9, 4, 1, 0 }, 9, 0, 0 },
1109 { 0x09, 0x00c04, { 9, 4, 1, 0 }, 9, 0, 0 },
1110 { 0x09, 0x01404, { 9, 4, 1, 0 }, 9, 0, 0 },
1111 { 0x09, 0x21404, { 9, 4, 1, 0 }, 9, 0, 0 },
1112 { 0x09, 0x30404, { 9, 4, 1, 0 }, 9, 0, 0 },
1113 { 0x0a, 0x00804, { 9, 4, 1, 0 }, 9, 0, 0 },
1114 { 0x0a, 0x01004, { 9, 4, 1, 0 }, 9, 0, 0 },
1115 { 0x0a, 0x20804, { 9, 4, 1, 0 }, 9, 0, 0 },
1116 { 0x0a, 0x21004, { 9, 4, 1, 0 }, 9, 0, 0 },
1117 { 0x0b, 0x0041e, { 9, 30, 1, 0 }, 9, 0, 0 },
1118 { 0x0c, 0x0040d, { 9, 13, 1, 0 }, 9, 0, 0 },
1119 { 0x0d, 0x00401, { 1, 1, 0, 0 }, 9, 0, 0 },
1120 { 0x0d, 0x00420, { 9, 32, 1, 0 }, 9, 0, 0 },
1121 { 0x0d, 0x00429, { 41, 41, 0, 0 }, 9, 0, 0 },
1122 { 0x0d, 0x0045a, { 9, 90, 1, 0 }, 9, 0, 0 },
1123 { 0x0d, 0x00465, { 9, 101, 1, 0 }, 9, 0, 0 },
1124 { 0x0d, 0x00801, { 1, 1, 0, 0 }, 9, 0, 0 },
1125 { 0x0d, 0x00c01, { 1, 1, 0, 0 }, 9, 0, 0 },
1126 { 0x0d, 0x01001, { 1, 1, 0, 0 }, 9, 0, 0 },
1127 { 0x0d, 0x01401, { 1, 1, 0, 0 }, 9, 0, 0 },
1128 { 0x0d, 0x01801, { 1, 1, 0, 0 }, 9, 0, 0 },
1129 { 0x0d, 0x01c01, { 1, 1, 0, 0 }, 9, 0, 0 },
1130 { 0x0d, 0x02001, { 1, 1, 0, 0 }, 9, 0, 0 },
1131 { 0x0d, 0x02401, { 1, 1, 0, 0 }, 9, 0, 0 },
1132 { 0x0d, 0x02801, { 1, 1, 0, 0 }, 9, 0, 0 },
1133 { 0x0d, 0x02c01, { 1, 1, 0, 0 }, 9, 0, 0 },
1134 { 0x0d, 0x03001, { 1, 1, 0, 0 }, 9, 0, 0 },
1135 { 0x0d, 0x03401, { 1, 1, 0, 0 }, 9, 0, 0 },
1136 { 0x0d, 0x03801, { 1, 1, 0, 0 }, 9, 0, 0 },
1137 { 0x0d, 0x03c01, { 1, 1, 0, 0 }, 9, 0, 0 },
1138 { 0x0d, 0x04001, { 1, 1, 0, 0 }, 9, 0, 0 },
1139 { 0x0e, 0x0042a, { 9, 42, 1, 0 }, 9, 0, 0 },
1140 { 0x0f, 0x00439, { 9, 57, 1, 0 }, 9, 0, 0 },
1141 { 0x0f, 0x00446, { 9, 70, 1, 0 }, 9, 0, 0 },
1142 { 0x0f, 0x00447, { 9, 71, 1, 0 }, 9, 0, 0 },
1143 { 0x0f, 0x00449, { 9, 73, 1, 0 }, 9, 0, 0 },
1144 { 0x0f, 0x0044a, { 9, 74, 1, 0 }, 9, 0, 0 },
1145 { 0x0f, 0x0044b, { 9, 75, 1, 0 }, 9, 0, 0 },
1146 { 0x0f, 0x0044e, { 9, 78, 1, 0 }, 9, 0, 0 },
1147 { 0x0f, 0x0044f, { 9, 79, 1, 0 }, 9, 0, 0 },
1148 { 0x0f, 0x00457, { 9, 87, 1, 0 }, 9, 0, 0 },
1149 { 0x10, 0x00437, { 9, 55, 1, 0 }, 9, 0, 0 },
1150 { 0x10, 0x10437, { 9, 55, 1, 0 }, 9, 0, 0 },
1151 { 0x11, 0x0042b, { 9, 43, 1, 0 }, 9, 0, 0 }
1154 static BOOL CALLBACK enum_proc(LGRPID group, LCID lcid, LPSTR locale, LONG_PTR lparam)
1156 HRESULT hr;
1157 SCRIPT_DIGITSUBSTITUTE sds;
1158 SCRIPT_CONTROL sc;
1159 SCRIPT_STATE ss;
1160 LCID lcid_old;
1161 unsigned int i;
1163 if (!IsValidLocale(lcid, LCID_INSTALLED)) return TRUE;
1165 memset(&sds, 0, sizeof(sds));
1166 memset(&sc, 0, sizeof(sc));
1167 memset(&ss, 0, sizeof(ss));
1169 lcid_old = GetThreadLocale();
1170 if (!SetThreadLocale(lcid)) return TRUE;
1172 hr = ScriptRecordDigitSubstitution(lcid, &sds);
1173 ok(hr == S_OK, "ScriptRecordDigitSubstitution failed: 0x%08x\n", hr);
1175 hr = ScriptApplyDigitSubstitution(&sds, &sc, &ss);
1176 ok(hr == S_OK, "ScriptApplyDigitSubstitution failed: 0x%08x\n", hr);
1178 for (i = 0; i < sizeof(subst_data)/sizeof(subst_data[0]); i++)
1180 if (group == subst_data[i].group && lcid == subst_data[i].lcid)
1182 ok(!memcmp(&sds, &subst_data[i].sds, sizeof(sds)),
1183 "substitution data does not match\n");
1185 ok(sc.uDefaultLanguage == subst_data[i].uDefaultLanguage,
1186 "sc.uDefaultLanguage does not match\n");
1187 ok(sc.fContextDigits == subst_data[i].fContextDigits,
1188 "sc.fContextDigits does not match\n");
1189 ok(ss.fDigitSubstitute == subst_data[i].fDigitSubstitute,
1190 "ss.fDigitSubstitute does not match\n");
1193 SetThreadLocale(lcid_old);
1194 return TRUE;
1197 static void test_digit_substitution(void)
1199 BOOL ret;
1200 unsigned int i;
1201 static const LGRPID groups[] =
1203 LGRPID_WESTERN_EUROPE,
1204 LGRPID_CENTRAL_EUROPE,
1205 LGRPID_BALTIC,
1206 LGRPID_GREEK,
1207 LGRPID_CYRILLIC,
1208 LGRPID_TURKISH,
1209 LGRPID_JAPANESE,
1210 LGRPID_KOREAN,
1211 LGRPID_TRADITIONAL_CHINESE,
1212 LGRPID_SIMPLIFIED_CHINESE,
1213 LGRPID_THAI,
1214 LGRPID_HEBREW,
1215 LGRPID_ARABIC,
1216 LGRPID_VIETNAMESE,
1217 LGRPID_INDIC,
1218 LGRPID_GEORGIAN,
1219 LGRPID_ARMENIAN
1222 for (i = 0; i < sizeof(groups)/sizeof(groups[0]); i++)
1224 ret = EnumLanguageGroupLocales(enum_proc, groups[i], 0, 0);
1225 ok(ret, "EnumLanguageGroupLocales failed unexpectedly: 0x%08x\n", GetLastError());
1229 START_TEST(usp10)
1231 HWND hwnd;
1232 HDC hdc;
1234 unsigned short pwOutGlyphs[256];
1236 /* We need a valid HDC to drive a lot of Script functions which requires the following *
1237 * to set up for the tests. */
1238 hwnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,
1239 0, 0, 0, NULL);
1240 assert(hwnd != 0);
1241 ShowWindow(hwnd, SW_SHOW);
1242 UpdateWindow(hwnd);
1244 hdc = GetDC(hwnd); /* We now have a hdc */
1245 ok( hdc != NULL, "HDC failed to be created %p\n", hdc);
1247 test_ScriptItemIzeShapePlace(hdc,pwOutGlyphs);
1248 test_ScriptGetCMap(hdc, pwOutGlyphs);
1249 test_ScriptCacheGetHeight(hdc);
1250 test_ScriptGetGlyphABCWidth(hdc);
1252 test_ScriptGetFontProperties();
1253 test_ScriptTextOut();
1254 test_ScriptXtoX();
1255 test_ScriptString();
1256 test_ScriptStringXtoCP_CPtoX(hdc);
1258 test_ScriptLayout();
1259 test_digit_substitution();
1261 ReleaseDC(hwnd, hdc);
1262 DestroyWindow(hwnd);