4 * Copyright 2006 Jeff Latimer
5 * Copyright 2006 Hans Leidekker
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.
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.
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
22 * Uniscribe allows for processing of complex scripts such as joining
23 * and filtering characters and bi-directional text with custom line breaks.
29 #include <wine/test.h>
37 static void test_ScriptShape(HDC hdc)
39 static const WCHAR test1[] = {'t', 'e', 's', 't',0};
42 SCRIPT_CACHE sc = NULL;
43 WORD glyphs[4], logclust[4];
44 SCRIPT_VISATTR attrs[4];
50 hr = ScriptItemize(NULL, 4, 2, NULL, NULL, items, NULL);
51 ok(hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG not %08x\n", hr);
53 hr = ScriptItemize(test1, 4, 2, NULL, NULL, NULL, NULL);
54 ok(hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG not %08x\n", hr);
56 hr = ScriptItemize(test1, 4, 2, NULL, NULL, items, NULL);
57 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
58 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
60 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, NULL, &nb);
61 ok(hr == E_INVALIDARG, "ScriptShape should return E_INVALIDARG not %08x\n", hr);
63 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, attrs, NULL);
64 ok(hr == E_INVALIDARG, "ScriptShape should return E_INVALIDARG not %08x\n", hr);
66 hr = ScriptShape(NULL, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, attrs, &nb);
67 ok(hr == E_PENDING, "ScriptShape should return E_PENDING not %08x\n", hr);
69 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, attrs, &nb);
71 hr == E_INVALIDARG, /* Vista, W2K8 */
72 "ScriptShape should return S_OK or E_INVALIDARG, not %08x\n", hr);
73 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
75 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, logclust, attrs, &nb);
76 ok(!hr, "ScriptShape should return S_OK not %08x\n", hr);
77 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
79 hr = ScriptShape(NULL, &sc, test1, 4, 4, &items[0].a, glyphs, logclust, attrs, &nb);
80 ok(!hr, "ScriptShape should return S_OK not %08x\n", hr);
82 hr = ScriptPlace(hdc, &sc, glyphs, 4, NULL, &items[0].a, widths, NULL, NULL);
83 ok(hr == E_INVALIDARG, "ScriptPlace should return E_INVALIDARG not %08x\n", hr);
85 hr = ScriptPlace(NULL, &sc, glyphs, 4, attrs, &items[0].a, widths, NULL, NULL);
87 hr == E_INVALIDARG, /* Vista, W2K8 */
88 "ScriptPlace should return E_PENDING or E_INVALIDARG, not %08x\n", hr);
90 hr = ScriptPlace(NULL, &sc, glyphs, 4, attrs, &items[0].a, widths, offset, NULL);
91 ok(hr == E_PENDING, "ScriptPlace should return E_PENDING not %08x\n", hr);
93 hr = ScriptPlace(NULL, &sc, glyphs, 4, attrs, &items[0].a, widths, NULL, abc);
95 hr == E_INVALIDARG, /* Vista, W2K8 */
96 "ScriptPlace should return E_PENDING or E_INVALIDARG, not %08x\n", hr);
98 hr = ScriptPlace(hdc, &sc, glyphs, 4, attrs, &items[0].a, widths, offset, NULL);
99 ok(!hr, "ScriptPlace should return S_OK not %08x\n", hr);
100 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
102 ret = ExtTextOutW(hdc, 1, 1, 0, NULL, glyphs, 4, widths);
103 ok(ret, "ExtTextOutW should return TRUE\n");
105 ScriptFreeCache(&sc);
108 static void test_ScriptItemIzeShapePlace(HDC hdc, unsigned short pwOutGlyphs[256])
112 const SCRIPT_PROPERTIES **ppSp;
116 SCRIPT_ITEM pItem[255];
118 WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
119 WCHAR TestItem2[] = {'T', 'e', 's', 't', 'b', 0};
120 WCHAR TestItem3[] = {'T', 'e', 's', 't', 'c',' ','1','2','3',' ',' ','e','n','d',0};
121 WCHAR TestItem4[] = {'T', 'e', 's', 't', 'c',' ',0x0684,0x0694,0x06a4,' ',' ','e','n','d',0};
122 WCHAR TestItem5[] = {0x0684,'T','e','s','t','c',' ',0x0684,0x0694,0x06a4,' ',' ','e','n','d',0};
127 unsigned short pwOutGlyphs1[256];
128 unsigned short pwOutGlyphs2[256];
129 unsigned short pwLogClust[256];
130 SCRIPT_VISATTR psva[256];
133 GOFFSET pGoffset[256];
137 /* Start testing usp10 functions */
138 /* This test determines that the pointer returned by ScriptGetProperties is valid
139 * by checking a known value in the table */
140 hr = ScriptGetProperties(&ppSp, &iMaxProps);
141 trace("number of script properties %d\n", iMaxProps);
142 ok (iMaxProps > 0, "Number of scripts returned should not be 0\n");
144 ok( ppSp[5]->langid == 9, "Langid[5] not = to 9\n"); /* Check a known value to ensure */
148 /* This set of tests are to check that the various edits in ScriptIemize work */
149 cInChars = 5; /* Length of test without NULL */
150 cMaxItems = 1; /* Check threshold value */
151 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
152 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if cMaxItems < 2. Was %d\n",
156 hr = ScriptItemize(NULL, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
157 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if pwcInChars is NULL\n");
161 hr = ScriptItemize(TestItem1, 0, cMaxItems, NULL, NULL, pItem, &pcItems);
162 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if cInChars is 0\n");
166 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, NULL, &pcItems);
167 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if pItems is NULL\n");
169 /* This is a valid test that will cause parsing to take place */
172 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
173 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
174 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
176 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
178 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
179 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
180 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
182 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
183 * ie. ScriptItemize has succeeded and that pItem has been set */
187 psc = NULL; /* must be null on first call */
189 cMaxGlyphs = cInChars;
190 hr = ScriptShape(NULL, &psc, TestItem1, cChars,
191 cMaxGlyphs, &pItem[0].a,
192 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
193 ok (hr == E_PENDING, "If psc is NULL (%08x) the E_PENDING should be returned\n", hr);
195 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
196 cMaxGlyphs, &pItem[0].a,
197 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
198 ok (hr == E_OUTOFMEMORY, "If not enough output area cChars (%d) is > than CMaxGlyphs "
199 "(%d) but not E_OUTOFMEMORY\n",
202 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
203 cMaxGlyphs, &pItem[0].a,
204 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
205 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
206 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
207 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
209 hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
211 ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", hr);
212 hr = ScriptPlace(NULL, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
214 ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", hr);
215 for (cnt=0; cnt < pcGlyphs; cnt++)
216 pwOutGlyphs[cnt] = pwOutGlyphs1[cnt]; /* Send to next function */
219 /* This test will check to make sure that SCRIPT_CACHE is reused and that not translation *
220 * takes place if fNoGlyphIndex is set. */
224 hr = ScriptItemize(TestItem2, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
225 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
226 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
228 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
229 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
230 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
231 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue */
235 pItem[0].a.fNoGlyphIndex = 1; /* say no translate */
236 hr = ScriptShape(NULL, &psc, TestItem2, cChars,
237 cMaxGlyphs, &pItem[0].a,
238 pwOutGlyphs2, pwLogClust, psva, &pcGlyphs);
239 ok (hr != E_PENDING, "If psc should not be NULL (%08x) and the E_PENDING should be returned\n", hr);
240 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
241 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
242 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
243 for (cnt=0; cnt < cChars && TestItem2[cnt] == pwOutGlyphs2[cnt]; cnt++) {}
244 ok (cnt == cChars, "Translation to place when told not to. WCHAR %d - %04x != %04x\n",
245 cnt, TestItem2[cnt], pwOutGlyphs2[cnt]);
247 hr = ScriptPlace(hdc, &psc, pwOutGlyphs2, pcGlyphs, psva, &pItem[0].a, piAdvance,
249 ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", hr);
252 hr = ScriptFreeCache( &psc);
253 ok (!psc, "psc is not null after ScriptFreeCache\n");
257 /* This is a valid test that will cause parsing to take place and create 3 script_items */
258 cInChars = (sizeof(TestItem3)/2)-1;
260 hr = ScriptItemize(TestItem3, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
261 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
264 ok (pcItems == 3, "The number of SCRIPT_ITEMS should be 3 not %d\n", pcItems);
267 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == 6,
268 "Start pos [0] not = 0 (%d) or end pos [1] not = %d\n",
269 pItem[0].iCharPos, pItem[1].iCharPos);
270 ok (pItem[1].iCharPos == 6 && pItem[2].iCharPos == 11,
271 "Start pos [1] not = 6 (%d) or end pos [2] not = 11 (%d)\n",
272 pItem[1].iCharPos, pItem[2].iCharPos);
273 ok (pItem[2].iCharPos == 11 && pItem[3].iCharPos == cInChars,
274 "Start pos [2] not = 11 (%d) or end [3] pos not = 14 (%d), cInChars = %d\n",
275 pItem[2].iCharPos, pItem[3].iCharPos, cInChars);
277 hr = ScriptFreeCache( &psc);
278 ok (!psc, "psc is not null after ScriptFreeCache\n");
281 /* This is a valid test that will cause parsing to take place and create 3 script_items */
282 cInChars = (sizeof(TestItem4)/2)-1;
284 hr = ScriptItemize(TestItem4, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
285 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
288 ok (pcItems == 3, "The number of SCRIPT_ITEMS should be 3 not %d\n", pcItems);
291 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == 6,
292 "Start pos [0] not = 0 (%d) or end pos [1] not = %d\n",
293 pItem[0].iCharPos, pItem[1].iCharPos);
294 ok (pItem[1].iCharPos == 6 && pItem[2].iCharPos == 11,
295 "Start pos [1] not = 6 (%d) or end pos [2] not = 11 (%d)\n",
296 pItem[1].iCharPos, pItem[2].iCharPos);
297 ok (pItem[2].iCharPos == 11 && pItem[3].iCharPos == cInChars,
298 "Start pos [2] not = 11 (%d) or end [3] pos not = 14 (%d), cInChars = %d\n",
299 pItem[2].iCharPos, pItem[3].iCharPos, cInChars);
301 hr = ScriptFreeCache( &psc);
302 ok (!psc, "psc is not null after ScriptFreeCache\n");
306 * This test is for when the first unicode character requires bidi support
308 cInChars = (sizeof(TestItem5)-1)/sizeof(WCHAR);
309 hr = ScriptItemize(TestItem5, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
310 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
311 ok (pcItems == 4, "There should have been 4 items, found %d\n", pcItems);
312 ok (pItem[0].a.s.uBidiLevel == 1, "The first character should have been bidi=1 not %d\n",
313 pItem[0].a.s.uBidiLevel);
316 static void test_ScriptGetCMap(HDC hdc, unsigned short pwOutGlyphs[256])
319 SCRIPT_CACHE psc = NULL;
322 unsigned short pwOutGlyphs3[256];
323 WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
327 /* Check to make sure that SCRIPT_CACHE gets allocated ok */
329 cInChars = cChars = 5;
330 /* Some sanity checks for ScriptGetCMap */
332 hr = ScriptGetCMap(NULL, NULL, NULL, 0, 0, NULL);
333 ok( hr == E_INVALIDARG, "(NULL,NULL,NULL,0,0,NULL), "
334 "expected E_INVALIDARG, got %08x\n", hr);
336 hr = ScriptGetCMap(NULL, NULL, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
337 ok( hr == E_INVALIDARG, "(NULL,NULL,TestItem1, cInChars, dwFlags, pwOutGlyphs3), "
338 "expected E_INVALIDARG, got %08x\n", hr);
340 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
342 hr = ScriptGetCMap(NULL, &psc, NULL, 0, 0, NULL);
343 ok( hr == E_PENDING, "(NULL,&psc,NULL,0,0NULL), expected E_PENDING, "
345 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
347 /* Set psc to NULL but add hdc, to be able to check if a pointer is returned in psc */
349 hr = ScriptGetCMap(hdc, &psc, NULL, 0, 0, NULL);
350 ok( hr == S_OK, "ScriptGetCMap(NULL,&psc,NULL,0,0,NULL), expected S_OK, "
352 ok( psc != NULL, "ScritpGetCMap expected psc to be not NULL\n");
353 ScriptFreeCache( &psc);
355 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
357 hr = ScriptGetCMap(NULL, &psc, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
358 ok( hr == E_PENDING, "(NULL,&psc,), expected E_PENDING, got %08x\n", hr);
359 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
360 /* Check to see if the results are the same as those returned by ScriptShape */
361 hr = ScriptGetCMap(hdc, &psc, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
362 ok (hr == 0, "ScriptGetCMap should return 0 not (%08x)\n", hr);
363 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
364 for (cnt=0; cnt < cChars && pwOutGlyphs[cnt] == pwOutGlyphs3[cnt]; cnt++) {}
365 ok (cnt == cInChars, "Translation not correct. WCHAR %d - %04x != %04x\n",
366 cnt, pwOutGlyphs[cnt], pwOutGlyphs3[cnt]);
368 hr = ScriptFreeCache( &psc);
369 ok (!psc, "psc is not null after ScriptFreeCache\n");
373 static void test_ScriptGetFontProperties(HDC hdc)
376 SCRIPT_CACHE psc,old_psc;
377 SCRIPT_FONTPROPERTIES sfp;
379 /* Some sanity checks for ScriptGetFontProperties */
381 hr = ScriptGetFontProperties(NULL,NULL,NULL);
382 ok( hr == E_INVALIDARG, "(NULL,NULL,NULL), expected E_INVALIDARG, got %08x\n", hr);
384 hr = ScriptGetFontProperties(NULL,NULL,&sfp);
385 ok( hr == E_INVALIDARG, "(NULL,NULL,&sfp), expected E_INVALIDARG, got %08x\n", hr);
387 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
389 hr = ScriptGetFontProperties(NULL,&psc,NULL);
390 ok( hr == E_INVALIDARG, "(NULL,&psc,NULL), expected E_INVALIDARG, got %08x\n", hr);
391 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
393 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
395 hr = ScriptGetFontProperties(NULL,&psc,&sfp);
396 ok( hr == E_PENDING, "(NULL,&psc,&sfp), expected E_PENDING, got %08x\n", hr);
397 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
399 hr = ScriptGetFontProperties(hdc,NULL,NULL);
400 ok( hr == E_INVALIDARG, "(hdc,NULL,NULL), expected E_INVALIDARG, got %08x\n", hr);
402 hr = ScriptGetFontProperties(hdc,NULL,&sfp);
403 ok( hr == E_INVALIDARG, "(hdc,NULL,&sfp), expected E_INVALIDARG, got %08x\n", hr);
405 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
407 hr = ScriptGetFontProperties(hdc,&psc,NULL);
408 ok( hr == E_INVALIDARG, "(hdc,&psc,NULL), expected E_INVALIDARG, got %08x\n", hr);
409 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
411 /* Pass an invalid sfp */
413 sfp.cBytes = sizeof(SCRIPT_FONTPROPERTIES) - 1;
414 hr = ScriptGetFontProperties(hdc,&psc,&sfp);
415 ok( hr == E_INVALIDARG, "(hdc,&psc,&sfp) invalid, expected E_INVALIDARG, got %08x\n", hr);
416 ok( psc != NULL, "Expected a pointer in psc, got NULL\n");
417 ScriptFreeCache(&psc);
418 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
420 /* Give it the correct cBytes, we don't care about what's coming back */
421 sfp.cBytes = sizeof(SCRIPT_FONTPROPERTIES);
423 hr = ScriptGetFontProperties(hdc,&psc,&sfp);
424 ok( hr == S_OK, "(hdc,&psc,&sfp) partly initialized, expected S_OK, got %08x\n", hr);
425 ok( psc != NULL, "Expected a pointer in psc, got NULL\n");
427 /* Save the psc pointer */
429 /* Now a NULL hdc again */
430 hr = ScriptGetFontProperties(NULL,&psc,&sfp);
431 ok( hr == S_OK, "(NULL,&psc,&sfp), expected S_OK, got %08x\n", hr);
432 ok( psc == old_psc, "Expected psc not to be changed, was %p is now %p\n", old_psc, psc);
433 ScriptFreeCache(&psc);
434 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
437 static void test_ScriptTextOut(HDC hdc)
443 SCRIPT_ITEM pItem[255];
445 WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
450 unsigned short pwOutGlyphs1[256];
451 WORD pwLogClust[256];
452 SCRIPT_VISATTR psva[256];
455 GOFFSET pGoffset[256];
460 BOOL fTrailing = FALSE;
461 SCRIPT_LOGATTR *psla;
462 SCRIPT_LOGATTR sla[256];
464 /* This is a valid test that will cause parsing to take place */
467 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
468 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
469 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
471 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
473 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
474 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
475 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
477 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
478 * ie. ScriptItemize has succeeded and that pItem has been set */
482 psc = NULL; /* must be null on first call */
484 cMaxGlyphs = cInChars;
486 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
487 cMaxGlyphs, &pItem[0].a,
488 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
489 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
490 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
491 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
493 /* Note hdc is needed as glyph info is not yet in psc */
494 hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
496 ok (hr == 0, "Should return 0 not (%08x)\n", hr);
497 ScriptFreeCache(&psc); /* Get rid of psc for next test set */
498 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
500 hr = ScriptTextOut(NULL, NULL, 0, 0, 0, NULL, NULL, NULL, 0, NULL, 0, NULL, NULL, NULL);
501 ok (hr == E_INVALIDARG, "Should return 0 not (%08x)\n", hr);
503 hr = ScriptTextOut(NULL, NULL, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
504 piAdvance, NULL, pGoffset);
505 ok( hr == E_INVALIDARG, "(NULL,NULL,TestItem1, cInChars, dwFlags, pwOutGlyphs3), "
506 "expected E_INVALIDARG, got %08x\n", hr);
508 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
510 hr = ScriptTextOut(NULL, &psc, 0, 0, 0, NULL, NULL, NULL, 0, NULL, 0,
512 ok( hr == E_INVALIDARG, "(NULL,&psc,NULL,0,0,0,NULL,), expected E_INVALIDARG, "
514 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
516 /* hdc is required for this one rather than the usual optional */
518 hr = ScriptTextOut(NULL, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
519 piAdvance, NULL, pGoffset);
520 ok( hr == E_INVALIDARG, "(NULL,&psc,), expected E_INVALIDARG, got %08x\n", hr);
521 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
523 /* Set that it returns 0 status */
524 hr = ScriptTextOut(hdc, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
525 piAdvance, NULL, pGoffset);
526 ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
528 /* Test Rect Rgn is acceptable */
533 hr = ScriptTextOut(hdc, &psc, 0, 0, 0, &rect, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
534 piAdvance, NULL, pGoffset);
535 ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
538 hr = ScriptCPtoX(iCP, fTrailing, cChars, pcGlyphs, (const WORD *) &pwLogClust,
539 (const SCRIPT_VISATTR *) &psva, (const int *)&piAdvance, &pItem[0].a, &piX);
540 ok(hr == S_OK, "ScriptCPtoX Stub should return S_OK not %08x\n", hr);
542 psla = (SCRIPT_LOGATTR *)&sla;
543 hr = ScriptBreak(TestItem1, cChars, &pItem[0].a, psla);
544 ok(hr == S_OK, "ScriptBreak Stub should return S_OK not %08x\n", hr);
546 /* Clean up and go */
547 ScriptFreeCache(&psc);
548 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
553 static void test_ScriptTextOut2(HDC hdc)
555 /* Intent is to validate that the HDC passed into ScriptTextOut is
556 * used instead of the (possibly) invalid cached one
563 SCRIPT_ITEM pItem[255];
565 WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
570 unsigned short pwOutGlyphs1[256];
571 WORD pwLogClust[256];
572 SCRIPT_VISATTR psva[256];
575 GOFFSET pGoffset[256];
578 /* Create an extra DC that will be used until the ScriptTextOut */
579 hdc1 = CreateCompatibleDC(hdc);
580 ok (hdc1 != 0, "CreateCompatibleDC failed to create a DC\n");
581 hdc2 = CreateCompatibleDC(hdc);
582 ok (hdc2 != 0, "CreateCompatibleDC failed to create a DC\n");
584 /* This is a valid test that will cause parsing to take place */
587 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
588 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
589 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
591 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
593 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
594 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
595 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
597 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
598 * ie. ScriptItemize has succeeded and that pItem has been set */
602 psc = NULL; /* must be null on first call */
604 cMaxGlyphs = cInChars;
606 hr = ScriptShape(hdc2, &psc, TestItem1, cChars,
607 cMaxGlyphs, &pItem[0].a,
608 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
609 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
610 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
611 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
613 /* Note hdc is needed as glyph info is not yet in psc */
614 hr = ScriptPlace(hdc2, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
616 ok (hr == 0, "Should return 0 not (%08x)\n", hr);
618 /* key part!!! cached dc is being deleted */
620 ok(hr == 1, "DeleteDC should return 1 not %08x\n", hr);
622 /* At this point the cached hdc (hdc2) has been destroyed,
623 * however, we are passing in a *real* hdc (the original hdc).
624 * The text should be written to that DC
626 hr = ScriptTextOut(hdc1, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
627 piAdvance, NULL, pGoffset);
628 ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
629 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
633 /* Clean up and go */
634 ScriptFreeCache(&psc);
635 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
640 static void test_ScriptXtoX(void)
641 /****************************************************************************************
642 * This routine tests the ScriptXtoCP and ScriptCPtoX functions using static variables *
643 ****************************************************************************************/
645 static const WCHAR test[] = {'t', 'e', 's', 't',0};
646 SCRIPT_ITEM items[2];
650 WORD pwLogClust[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
651 SCRIPT_VISATTR psva[10];
652 int piAdvance[10] = {200, 190, 210, 180, 170, 204, 189, 195, 212, 203};
658 hr = ScriptItemize(test, lstrlenW(test), sizeof(items)/sizeof(items[0]), NULL, NULL, items, NULL);
659 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
664 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
665 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
667 ok(piCP == -1, "Negative iX should return piCP=-1 not %d\n", piCP);
669 ok(piCP == 10, "Negative iX should return piCP=10 not %d\n", piCP);
674 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
675 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
676 if (piTrailing) /* win2k3 */
677 ok(piCP == -1, "Negative iX should return piCP=-1 not %d\n", piCP);
679 ok(piCP == 10, "Negative iX should return piCP=10 not %d\n", piCP);
684 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
685 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
687 piCP == -1, /* win2k3 */
688 "iX=%d should return piCP=3 or piCP=-1 not %d\n", iX, piCP);
689 ok(piTrailing == 1, "iX=%d should return piTrailing=1 not %d\n", iX, piTrailing);
694 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
695 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
697 piCP == -1, /* win2k3 */
698 "iX=%d should return piCP=3 or piCP=-1 not %d\n", iX, piCP);
699 ok(piTrailing == 1, "iX=%d should return piTrailing=1 not %d\n", iX, piTrailing);
704 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
705 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
707 piCP == -1, /* win2k3 */
708 "iX=%d should return piCP=4 or piCP=-1 not %d\n", iX, piCP);
713 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
714 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
716 piCP == 10, /* win2k3 */
717 "iX=%d should return piCP=0 piCP=10 not %d\n", iX, piCP);
722 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
723 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
724 ok(piCP == 0, "iX=%d should return piCP=0 not %d\n", iX, piCP);
729 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
730 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
732 piCP == 0, /* win2k3 */
733 "iX=%d should return piCP=1 or piCP=0 not %d\n", iX, piCP);
739 hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piX);
740 ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
742 piX == 100, /* win2k3 */
743 "iCP=%d should return piX=976 or piX=100 not %d\n", iCP, piX);
749 hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piX);
750 ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
752 piX == 80, /* win2k3 */
753 "iCP=%d should return piX=1171 or piX=80 not %d\n", iCP, piX);
759 hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piX);
760 ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
762 piX == 80, /* win2k3 */
763 "iCP=%d should return piX=1171 or piX=80 not %d\n", iCP, piX);
769 hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piX);
770 ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
772 piX == 0, /* win2k3 */
773 "iCP=%d should return piX=1953 or piX=0 not %d\n", iCP, piX);
779 hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piX);
780 ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
782 piX == 0, /* win2k3 */
783 "iCP=%d should return piX=1953 or piX=0 not %d\n", iCP, piX);
786 static void test_ScriptString(HDC hdc)
788 /*******************************************************************************************
790 * This set of tests are for the string functions of uniscribe. The ScriptStringAnalyse
791 * function allocates memory pointed to by the SCRIPT_STRING_ANALYSIS ssa pointer. This
792 * memory if freed by ScriptStringFree. There needs to be a valid hdc for this as
793 * ScriptStringAnalyse calls ScriptSItemize, ScriptShape and ScriptPlace which require it.
798 WCHAR teststr[] = {'T','e','s','t','1',' ','a','2','b','3', '\0'};
799 int len = (sizeof(teststr) / sizeof(WCHAR)) - 1;
800 int Glyphs = len * 2 + 16;
802 DWORD Flags = SSA_GLYPHS;
804 SCRIPT_CONTROL Control;
806 const int Dx[5] = {10, 10, 10, 10, 10};
807 SCRIPT_TABDEF Tabdef;
808 const BYTE InClass = 0;
809 SCRIPT_STRING_ANALYSIS ssa = NULL;
814 const RECT rc = {0, 50, 100, 100};
817 BOOL Disabled = FALSE;
823 Charset = -1; /* this flag indicates unicode input */
824 /* Test without hdc to get E_PENDING */
825 hr = ScriptStringAnalyse( NULL, teststr, len, Glyphs, Charset, Flags,
826 ReqWidth, &Control, &State, Dx, &Tabdef,
828 ok(hr == E_PENDING, "ScriptStringAnalyse Stub should return E_PENDING not %08x\n", hr);
830 /* test with hdc, this should be a valid test */
831 hr = ScriptStringAnalyse( hdc, teststr, len, Glyphs, Charset, Flags,
832 ReqWidth, &Control, &State, Dx, &Tabdef,
834 ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
835 ScriptStringFree(&ssa);
837 /* test makes sure that a call with a valid pssa still works */
838 hr = ScriptStringAnalyse( hdc, teststr, len, Glyphs, Charset, Flags,
839 ReqWidth, &Control, &State, Dx, &Tabdef,
841 ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
842 ok(ssa != NULL, "ScriptStringAnalyse pssa should not be NULL\n");
846 hr = ScriptStringOut(ssa, X, Y, Options, &rc, MinSel, MaxSel, Disabled);
847 ok(hr == S_OK, "ScriptStringOut should return S_OK not %08x\n", hr);
850 clip_len = ScriptString_pcOutChars(ssa);
851 ok(*clip_len == len, "ScriptString_pcOutChars failed, got %d, expected %d\n", *clip_len, len);
853 order = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *clip_len * sizeof(UINT));
854 hr = ScriptStringGetOrder(ssa, order);
855 ok(hr == S_OK, "ScriptStringGetOrder failed, got %08x, expected S_OK\n", hr);
857 for (i = 0; i < *clip_len; i++) ok(order[i] == i, "%d: got %d expected %d\n", i, order[i], i);
858 HeapFree(GetProcessHeap(), 0, order);
860 hr = ScriptStringFree(&ssa);
861 ok(hr == S_OK, "ScriptStringFree should return S_OK not %08x\n", hr);
864 static void test_ScriptStringXtoCP_CPtoX(HDC hdc)
866 /*****************************************************************************************
868 * This test is for the ScriptStringXtoCP and ScriptStringXtoCP functions. Due to the
869 * nature of the fonts between Windows and Wine, the test is implemented by generating
870 * values using one one function then checking the output of the second. In this way
871 * the validity of the functions is established using Windows as a base and confirming
872 * similar behaviour in wine.
876 WCHAR teststr1[] = {'T', 'e', 's', 't', 'e', '1', '2', ' ', 'a', '\0'};
877 void *String = (WCHAR *) &teststr1; /* ScriptStringAnalysis needs void */
878 int String_len = (sizeof(teststr1)/sizeof(WCHAR))-1;
879 int Glyphs = String_len * 2 + 16; /* size of buffer as recommended */
880 int Charset = -1; /* unicode */
881 DWORD Flags = SSA_GLYPHS;
883 SCRIPT_CONTROL Control;
885 SCRIPT_TABDEF Tabdef;
886 const BYTE InClass = 0;
887 SCRIPT_STRING_ANALYSIS ssa = NULL;
889 int Ch; /* Character position in string */
891 int Cp; /* Character position in string */
895 /* Test with hdc, this should be a valid test
896 * Here we generate an SCRIPT_STRING_ANALYSIS that will be used as input to the
897 * following character positions to X and X to character position functions.
899 hr = ScriptStringAnalyse( hdc, String, String_len, Glyphs, Charset, Flags,
900 ReqWidth, &Control, &State, NULL, &Tabdef,
903 hr == E_INVALIDARG, /* NT */
904 "ScriptStringAnalyse should return S_OK or E_INVALIDARG not %08x\n", hr);
908 ok(ssa != NULL, "ScriptStringAnalyse ssa should not be NULL\n");
911 * Loop to generate character positions to provide starting positions for the
912 * ScriptStringCPtoX and ScriptStringXtoCP functions
914 for (Cp = 0; Cp < String_len; Cp++)
916 /* The fTrailing flag is used to indicate whether the X being returned is at
917 * the beginning or the end of the character. What happens here is that if
918 * fTrailing indicates the end of the character, ie. FALSE, then ScriptStringXtoCP
919 * returns the beginning of the next character and iTrailing is FALSE. So for this
920 * loop iTrailing will be FALSE in both cases.
923 hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
924 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
925 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
926 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
927 ok(Cp == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp, Ch, X);
928 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
931 hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
932 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
933 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
934 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
937 * Check that character position returned by ScriptStringXtoCP in Ch matches the
938 * one input to ScriptStringCPtoX. This means that the Cp to X position and back
941 ok(Cp + 1 == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp + 1, Ch, X);
942 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
946 * This test is to check that if the X position is just inside the trailing edge of the
947 * character then iTrailing will indicate the trailing edge, ie. TRUE
951 hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
952 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
953 X--; /* put X just inside the trailing edge */
954 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
955 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
956 ok(Cp == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp, Ch, X);
957 ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
961 * This test is to check that if the X position is just outside the trailing edge of the
962 * character then iTrailing will indicate the leading edge, ie. FALSE, and Ch will indicate
963 * the next character, ie. Cp + 1
967 hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
968 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
969 X++; /* put X just outside the trailing edge */
970 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
971 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
972 ok(Cp + 1 == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp + 1, Ch, X);
973 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
977 * This test is to check that if the X position is just outside the leading edge of the
978 * character then iTrailing will indicate the trailing edge, ie. TRUE, and Ch will indicate
979 * the next character down , ie. Cp - 1
983 hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
984 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
985 X--; /* put X just outside the leading edge */
986 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
987 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
988 ok(Cp - 1 == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp - 1, Ch, X);
989 ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
993 * Cleanup the SSA for the next round of tests
995 hr = ScriptStringFree(&ssa);
996 ok(hr == S_OK, "ScriptStringFree should return S_OK not %08x\n", hr);
999 * Test to see that exceeding the number of chars returns E_INVALIDARG. First
1000 * generate an SSA for the subsequent tests.
1002 hr = ScriptStringAnalyse( hdc, String, String_len, Glyphs, Charset, Flags,
1003 ReqWidth, &Control, &State, NULL, &Tabdef,
1005 ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
1008 * When ScriptStringCPtoX is called with a character position Cp that exceeds the
1009 * string length, return E_INVALIDARG. This also invalidates the ssa so a
1010 * ScriptStringFree should also fail.
1013 Cp = String_len + 1;
1014 hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
1015 ok(hr == E_INVALIDARG, "ScriptStringCPtoX should return E_INVALIDARG not %08x\n", hr);
1017 hr = ScriptStringFree(&ssa);
1019 * ScriptStringCPtoX should free ssa, hence ScriptStringFree should fail
1021 ok(hr == E_INVALIDARG ||
1022 hr == E_FAIL, /* win2k3 */
1023 "ScriptStringFree should return E_INVALIDARG or E_FAIL not %08x\n", hr);
1027 static void test_ScriptCacheGetHeight(HDC hdc)
1030 SCRIPT_CACHE sc = NULL;
1033 hr = ScriptCacheGetHeight(NULL, NULL, NULL);
1034 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
1036 hr = ScriptCacheGetHeight(NULL, &sc, NULL);
1037 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
1039 hr = ScriptCacheGetHeight(NULL, &sc, &height);
1040 ok(hr == E_PENDING, "expected E_PENDING, got 0x%08x\n", hr);
1044 hr = ScriptCacheGetHeight(hdc, &sc, &height);
1045 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1046 ok(height > 0, "expected height > 0\n");
1048 ScriptFreeCache(&sc);
1051 static void test_ScriptGetGlyphABCWidth(HDC hdc)
1054 SCRIPT_CACHE sc = NULL;
1057 hr = ScriptGetGlyphABCWidth(NULL, NULL, 'a', NULL);
1058 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
1060 hr = ScriptGetGlyphABCWidth(NULL, &sc, 'a', NULL);
1061 ok(hr == E_PENDING, "expected E_PENDING, got 0x%08x\n", hr);
1063 if (0) { /* crashes on WinXP */
1064 hr = ScriptGetGlyphABCWidth(hdc, &sc, 'a', NULL);
1065 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
1068 hr = ScriptGetGlyphABCWidth(hdc, &sc, 'a', &abc);
1069 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1071 ScriptFreeCache(&sc);
1074 static void test_ScriptLayout(void)
1077 static const BYTE levels[][5] =
1084 static const int expect[][5] =
1091 int i, j, vistolog[sizeof(levels[0])], logtovis[sizeof(levels[0])];
1093 hr = ScriptLayout(sizeof(levels[0]), NULL, vistolog, logtovis);
1094 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
1096 hr = ScriptLayout(sizeof(levels[0]), levels[0], NULL, NULL);
1097 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
1099 for (i = 0; i < sizeof(levels)/sizeof(levels[0]); i++)
1101 hr = ScriptLayout(sizeof(levels[0]), levels[i], vistolog, logtovis);
1102 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1104 for (j = 0; j < sizeof(levels[i]); j++)
1106 ok(expect[i][j] == vistolog[j],
1107 "failure: levels[%d][%d] = %d, vistolog[%d] = %d\n",
1108 i, j, levels[i][j], j, vistolog[j] );
1111 for (j = 0; j < sizeof(levels[i]); j++)
1113 ok(expect[i][j] == logtovis[j],
1114 "failure: levels[%d][%d] = %d, logtovis[%d] = %d\n",
1115 i, j, levels[i][j], j, logtovis[j] );
1120 static BOOL CALLBACK enum_proc(LGRPID group, LCID lcid, LPSTR locale, LONG_PTR lparam)
1123 SCRIPT_DIGITSUBSTITUTE sds;
1128 if (!IsValidLocale(lcid, LCID_INSTALLED)) return TRUE;
1130 memset(&sds, 0, sizeof(sds));
1131 memset(&sc, 0, sizeof(sc));
1132 memset(&ss, 0, sizeof(ss));
1134 lcid_old = GetThreadLocale();
1135 if (!SetThreadLocale(lcid)) return TRUE;
1137 hr = ScriptRecordDigitSubstitution(lcid, &sds);
1138 ok(hr == S_OK, "ScriptRecordDigitSubstitution failed: 0x%08x\n", hr);
1140 hr = ScriptApplyDigitSubstitution(&sds, &sc, &ss);
1141 ok(hr == S_OK, "ScriptApplyDigitSubstitution failed: 0x%08x\n", hr);
1143 SetThreadLocale(lcid_old);
1147 static void test_digit_substitution(void)
1151 static const LGRPID groups[] =
1153 LGRPID_WESTERN_EUROPE,
1154 LGRPID_CENTRAL_EUROPE,
1161 LGRPID_TRADITIONAL_CHINESE,
1162 LGRPID_SIMPLIFIED_CHINESE,
1172 static BOOL (WINAPI * pEnumLanguageGroupLocalesA)(LANGGROUPLOCALE_ENUMPROC,LGRPID,DWORD,LONG_PTR);
1174 hKernel32 = GetModuleHandleA("kernel32.dll");
1175 pEnumLanguageGroupLocalesA = (void*)GetProcAddress(hKernel32, "EnumLanguageGroupLocalesA");
1177 if (!pEnumLanguageGroupLocalesA)
1179 win_skip("EnumLanguageGroupLocalesA not available on this platform\n");
1183 for (i = 0; i < sizeof(groups)/sizeof(groups[0]); i++)
1185 ret = pEnumLanguageGroupLocalesA(enum_proc, groups[i], 0, 0);
1186 if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1188 win_skip("EnumLanguageGroupLocalesA not implemented on this platform\n");
1192 ok(ret, "EnumLanguageGroupLocalesA failed unexpectedly: %u\n", GetLastError());
1196 static void test_ScriptGetProperties(void)
1198 const SCRIPT_PROPERTIES **props;
1202 hr = ScriptGetProperties(NULL, NULL);
1203 ok(hr == E_INVALIDARG, "ScriptGetProperties succeeded\n");
1205 hr = ScriptGetProperties(NULL, &num);
1206 ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
1208 hr = ScriptGetProperties(&props, NULL);
1209 ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
1211 hr = ScriptGetProperties(&props, &num);
1212 ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
1215 static void test_ScriptBreak(void)
1217 static const WCHAR test[] = {' ','\r','\n',0};
1218 SCRIPT_ITEM items[4];
1222 hr = ScriptItemize(test, 3, 4, NULL, NULL, items, NULL);
1223 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
1225 memset(&la, 0, sizeof(la));
1226 hr = ScriptBreak(test, 1, &items[0].a, &la);
1227 ok(!hr, "ScriptBreak should return S_OK not %08x\n", hr);
1229 ok(!la.fSoftBreak, "fSoftBreak set\n");
1230 ok(la.fWhiteSpace, "fWhiteSpace not set\n");
1231 ok(la.fCharStop, "fCharStop not set\n");
1232 ok(!la.fWordStop, "fWordStop set\n");
1233 ok(!la.fInvalid, "fInvalid set\n");
1234 ok(!la.fReserved, "fReserved set\n");
1236 memset(&la, 0, sizeof(la));
1237 hr = ScriptBreak(test + 1, 1, &items[1].a, &la);
1238 ok(!hr, "ScriptBreak should return S_OK not %08x\n", hr);
1240 ok(!la.fSoftBreak, "fSoftBreak set\n");
1241 ok(!la.fWhiteSpace, "fWhiteSpace set\n");
1242 ok(la.fCharStop, "fCharStop not set\n");
1243 ok(!la.fWordStop, "fWordStop set\n");
1244 ok(!la.fInvalid, "fInvalid set\n");
1245 ok(!la.fReserved, "fReserved set\n");
1247 memset(&la, 0, sizeof(la));
1248 hr = ScriptBreak(test + 2, 1, &items[2].a, &la);
1249 ok(!hr, "ScriptBreak should return S_OK not %08x\n", hr);
1251 ok(!la.fSoftBreak, "fSoftBreak set\n");
1252 ok(!la.fWhiteSpace, "fWhiteSpace set\n");
1253 ok(la.fCharStop, "fCharStop not set\n");
1254 ok(!la.fWordStop, "fWordStop set\n");
1255 ok(!la.fInvalid, "fInvalid set\n");
1256 ok(!la.fReserved, "fReserved set\n");
1259 static void test_newlines(void)
1261 static const WCHAR test1[] = {'t','e','x','t','\r','t','e','x','t',0};
1262 static const WCHAR test2[] = {'t','e','x','t','\n','t','e','x','t',0};
1263 static const WCHAR test3[] = {'t','e','x','t','\r','\n','t','e','x','t',0};
1264 static const WCHAR test4[] = {'t','e','x','t','\n','\r','t','e','x','t',0};
1265 static const WCHAR test5[] = {'1','2','3','4','\n','\r','1','2','3','4',0};
1266 SCRIPT_ITEM items[5];
1271 hr = ScriptItemize(test1, lstrlenW(test1), 5, NULL, NULL, items, &count);
1272 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
1273 ok(count == 3, "got %d expected 3\n", count);
1276 hr = ScriptItemize(test2, lstrlenW(test2), 5, NULL, NULL, items, &count);
1277 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
1278 ok(count == 3, "got %d expected 3\n", count);
1281 hr = ScriptItemize(test3, lstrlenW(test3), 5, NULL, NULL, items, &count);
1282 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
1283 ok(count == 4, "got %d expected 4\n", count);
1286 hr = ScriptItemize(test4, lstrlenW(test4), 5, NULL, NULL, items, &count);
1287 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
1288 ok(count == 4, "got %d expected 4\n", count);
1291 hr = ScriptItemize(test5, lstrlenW(test5), 5, NULL, NULL, items, &count);
1292 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
1293 ok(count == 4, "got %d expected 4\n", count);
1303 unsigned short pwOutGlyphs[256];
1305 /* We need a valid HDC to drive a lot of Script functions which requires the following *
1306 * to set up for the tests. */
1307 hwnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,
1310 ShowWindow(hwnd, SW_SHOW);
1313 hdc = GetDC(hwnd); /* We now have a hdc */
1314 ok( hdc != NULL, "HDC failed to be created %p\n", hdc);
1316 memset(&lf, 0, sizeof(LOGFONTA));
1317 lstrcpyA(lf.lfFaceName, "Tahoma");
1322 hfont = SelectObject(hdc, CreateFontIndirectA(&lf));
1324 test_ScriptItemIzeShapePlace(hdc,pwOutGlyphs);
1325 test_ScriptGetCMap(hdc, pwOutGlyphs);
1326 test_ScriptCacheGetHeight(hdc);
1327 test_ScriptGetGlyphABCWidth(hdc);
1328 test_ScriptShape(hdc);
1330 test_ScriptGetFontProperties(hdc);
1331 test_ScriptTextOut(hdc);
1332 test_ScriptTextOut2(hdc);
1334 test_ScriptString(hdc);
1335 test_ScriptStringXtoCP_CPtoX(hdc);
1337 test_ScriptLayout();
1338 test_digit_substitution();
1339 test_ScriptGetProperties();
1343 ReleaseDC(hwnd, hdc);
1344 DestroyWindow(hwnd);