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
;
44 SCRIPT_VISATTR attrs
[4];
48 hr
= ScriptItemize(NULL
, 4, 2, NULL
, NULL
, items
, NULL
);
49 ok(hr
== E_INVALIDARG
, "ScriptItemize should return E_INVALIDARG not %08x\n", hr
);
51 hr
= ScriptItemize(test1
, 4, 2, NULL
, NULL
, NULL
, NULL
);
52 ok(hr
== E_INVALIDARG
, "ScriptItemize should return E_INVALIDARG not %08x\n", hr
);
54 hr
= ScriptItemize(test1
, 4, 2, NULL
, NULL
, items
, NULL
);
55 ok(!hr
, "ScriptItemize should return S_OK not %08x\n", hr
);
56 ok(items
[0].a
.fNoGlyphIndex
== FALSE
, "fNoGlyphIndex TRUE\n");
58 hr
= ScriptShape(hdc
, &sc
, test1
, 4, 4, &items
[0].a
, glyphs
, NULL
, NULL
, &nb
);
59 ok(hr
== E_INVALIDARG
, "ScriptShape should return E_INVALIDARG not %08x\n", hr
);
61 hr
= ScriptShape(hdc
, &sc
, test1
, 4, 4, &items
[0].a
, glyphs
, NULL
, attrs
, NULL
);
62 ok(hr
== E_INVALIDARG
, "ScriptShape should return E_INVALIDARG not %08x\n", hr
);
64 hr
= ScriptShape(NULL
, &sc
, test1
, 4, 4, &items
[0].a
, glyphs
, NULL
, attrs
, &nb
);
65 ok(hr
== E_PENDING
, "ScriptShape should return E_PENDING not %08x\n", hr
);
67 hr
= ScriptShape(hdc
, &sc
, test1
, 4, 4, &items
[0].a
, glyphs
, NULL
, attrs
, &nb
);
68 ok(!hr
, "ScriptShape should return S_OK not %08x\n", hr
);
69 ok(items
[0].a
.fNoGlyphIndex
== FALSE
, "fNoGlyphIndex TRUE\n");
71 hr
= ScriptShape(NULL
, &sc
, test1
, 4, 4, &items
[0].a
, glyphs
, NULL
, attrs
, &nb
);
72 ok(!hr
, "ScriptShape should return S_OK not %08x\n", hr
);
74 hr
= ScriptPlace(hdc
, &sc
, glyphs
, 4, NULL
, &items
[0].a
, widths
, NULL
, NULL
);
75 ok(hr
== E_INVALIDARG
, "ScriptPlace should return E_INVALIDARG not %08x\n", hr
);
77 hr
= ScriptPlace(NULL
, &sc
, glyphs
, 4, attrs
, &items
[0].a
, widths
, NULL
, NULL
);
78 ok(hr
== E_PENDING
, "ScriptPlace should return E_PENDING not %08x\n", hr
);
80 hr
= ScriptPlace(hdc
, &sc
, glyphs
, 4, attrs
, &items
[0].a
, widths
, NULL
, NULL
);
81 ok(!hr
, "ScriptPlace should return S_OK not %08x\n", hr
);
82 ok(items
[0].a
.fNoGlyphIndex
== FALSE
, "fNoGlyphIndex TRUE\n");
84 ret
= ExtTextOutW(hdc
, 1, 1, 0, NULL
, glyphs
, 4, widths
);
85 ok(ret
, "ExtTextOutW should return TRUE\n");
90 static void test_ScriptItemIzeShapePlace(HDC hdc
, unsigned short pwOutGlyphs
[256])
94 const SCRIPT_PROPERTIES
**ppSp
;
98 SCRIPT_ITEM pItem
[255];
100 WCHAR TestItem1
[] = {'T', 'e', 's', 't', 'a', 0};
101 WCHAR TestItem2
[] = {'T', 'e', 's', 't', 'b', 0};
102 WCHAR TestItem3
[] = {'T', 'e', 's', 't', 'c',' ','1','2','3',' ',' ','e','n','d',0};
103 WCHAR TestItem4
[] = {'T', 'e', 's', 't', 'c',' ',0x0684,0x0694,0x06a4,' ',' ','e','n','d',0};
104 WCHAR TestItem5
[] = {0x0684,'T','e','s','t','c',' ',0x0684,0x0694,0x06a4,' ',' ','e','n','d',0};
109 unsigned short pwOutGlyphs1
[256];
110 unsigned short pwOutGlyphs2
[256];
111 unsigned short pwLogClust
[256];
112 SCRIPT_VISATTR psva
[256];
115 GOFFSET pGoffset
[256];
119 /* Start testing usp10 functions */
120 /* This test determines that the pointer returned by ScriptGetProperties is valid
121 * by checking a known value in the table */
122 hr
= ScriptGetProperties(&ppSp
, &iMaxProps
);
123 trace("number of script properties %d\n", iMaxProps
);
124 ok (iMaxProps
> 0, "Number of scripts returned should not be 0\n");
126 ok( ppSp
[5]->langid
== 9, "Langid[5] not = to 9\n"); /* Check a known value to ensure */
130 /* This set of tests are to check that the various edits in ScriptIemize work */
131 cInChars
= 5; /* Length of test without NULL */
132 cMaxItems
= 1; /* Check threshold value */
133 hr
= ScriptItemize(TestItem1
, cInChars
, cMaxItems
, NULL
, NULL
, pItem
, &pcItems
);
134 ok (hr
== E_INVALIDARG
, "ScriptItemize should return E_INVALIDARG if cMaxItems < 2. Was %d\n",
138 hr
= ScriptItemize(NULL
, cInChars
, cMaxItems
, NULL
, NULL
, pItem
, &pcItems
);
139 ok (hr
== E_INVALIDARG
, "ScriptItemize should return E_INVALIDARG if pwcInChars is NULL\n");
143 hr
= ScriptItemize(TestItem1
, 0, cMaxItems
, NULL
, NULL
, pItem
, &pcItems
);
144 ok (hr
== E_INVALIDARG
, "ScriptItemize should return E_INVALIDARG if cInChars is 0\n");
148 hr
= ScriptItemize(TestItem1
, cInChars
, cMaxItems
, NULL
, NULL
, NULL
, &pcItems
);
149 ok (hr
== E_INVALIDARG
, "ScriptItemize should return E_INVALIDARG if pItems is NULL\n");
151 /* This is a valid test that will cause parsing to take place */
154 hr
= ScriptItemize(TestItem1
, cInChars
, cMaxItems
, NULL
, NULL
, pItem
, &pcItems
);
155 ok (hr
== 0, "ScriptItemize should return 0, returned %08x\n", hr
);
156 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
158 ok (pcItems
> 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
160 ok (pItem
[0].iCharPos
== 0 && pItem
[1].iCharPos
== cInChars
,
161 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
162 pItem
[0].iCharPos
, cInChars
, pItem
[1].iCharPos
);
164 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
165 * ie. ScriptItemize has succeeded and that pItem has been set */
169 psc
= NULL
; /* must be null on first call */
171 cMaxGlyphs
= cInChars
;
172 hr
= ScriptShape(NULL
, &psc
, TestItem1
, cChars
,
173 cMaxGlyphs
, &pItem
[0].a
,
174 pwOutGlyphs1
, pwLogClust
, psva
, &pcGlyphs
);
175 ok (hr
== E_PENDING
, "If psc is NULL (%08x) the E_PENDING should be returned\n", hr
);
177 hr
= ScriptShape(hdc
, &psc
, TestItem1
, cChars
,
178 cMaxGlyphs
, &pItem
[0].a
,
179 pwOutGlyphs1
, pwLogClust
, psva
, &pcGlyphs
);
180 ok (hr
== E_OUTOFMEMORY
, "If not enough output area cChars (%d) is > than CMaxGlyphs "
181 "(%d) but not E_OUTOFMEMORY\n",
184 hr
= ScriptShape(hdc
, &psc
, TestItem1
, cChars
,
185 cMaxGlyphs
, &pItem
[0].a
,
186 pwOutGlyphs1
, pwLogClust
, psva
, &pcGlyphs
);
187 ok (hr
== 0, "ScriptShape should return 0 not (%08x)\n", hr
);
188 ok (psc
!= NULL
, "psc should not be null and have SCRIPT_CACHE buffer address\n");
189 ok (pcGlyphs
== cChars
, "Chars in (%d) should equal Glyphs out (%d)\n", cChars
, pcGlyphs
);
191 hr
= ScriptPlace(hdc
, &psc
, pwOutGlyphs1
, pcGlyphs
, psva
, &pItem
[0].a
, piAdvance
,
193 ok (hr
== 0, "ScriptPlace should return 0 not (%08x)\n", hr
);
194 hr
= ScriptPlace(NULL
, &psc
, pwOutGlyphs1
, pcGlyphs
, psva
, &pItem
[0].a
, piAdvance
,
196 ok (hr
== 0, "ScriptPlace should return 0 not (%08x)\n", hr
);
197 for (cnt
=0; cnt
< pcGlyphs
; cnt
++)
198 pwOutGlyphs
[cnt
] = pwOutGlyphs1
[cnt
]; /* Send to next function */
201 /* This test will check to make sure that SCRIPT_CACHE is reused and that not translation *
202 * takes place if fNoGlyphIndex is set. */
206 hr
= ScriptItemize(TestItem2
, cInChars
, cMaxItems
, NULL
, NULL
, pItem
, &pcItems
);
207 ok (hr
== 0, "ScriptItemize should return 0, returned %08x\n", hr
);
208 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
210 ok (pItem
[0].iCharPos
== 0 && pItem
[1].iCharPos
== cInChars
,
211 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
212 pItem
[0].iCharPos
, cInChars
, pItem
[1].iCharPos
);
213 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue */
217 pItem
[0].a
.fNoGlyphIndex
= 1; /* say no translate */
218 hr
= ScriptShape(NULL
, &psc
, TestItem2
, cChars
,
219 cMaxGlyphs
, &pItem
[0].a
,
220 pwOutGlyphs2
, pwLogClust
, psva
, &pcGlyphs
);
221 ok (hr
!= E_PENDING
, "If psc should not be NULL (%08x) and the E_PENDING should be returned\n", hr
);
222 ok (hr
== 0, "ScriptShape should return 0 not (%08x)\n", hr
);
223 ok (psc
!= NULL
, "psc should not be null and have SCRIPT_CACHE buffer address\n");
224 ok (pcGlyphs
== cChars
, "Chars in (%d) should equal Glyphs out (%d)\n", cChars
, pcGlyphs
);
225 for (cnt
=0; cnt
< cChars
&& TestItem2
[cnt
] == pwOutGlyphs2
[cnt
]; cnt
++) {}
226 ok (cnt
== cChars
, "Translation to place when told not to. WCHAR %d - %04x != %04x\n",
227 cnt
, TestItem2
[cnt
], pwOutGlyphs2
[cnt
]);
229 hr
= ScriptPlace(hdc
, &psc
, pwOutGlyphs2
, pcGlyphs
, psva
, &pItem
[0].a
, piAdvance
,
231 ok (hr
== 0, "ScriptPlace should return 0 not (%08x)\n", hr
);
234 hr
= ScriptFreeCache( &psc
);
235 ok (!psc
, "psc is not null after ScriptFreeCache\n");
239 /* This is a valid test that will cause parsing to take place and create 3 script_items */
240 cInChars
= (sizeof(TestItem3
)/2)-1;
242 hr
= ScriptItemize(TestItem3
, cInChars
, cMaxItems
, NULL
, NULL
, pItem
, &pcItems
);
243 ok (hr
== 0, "ScriptItemize should return 0, returned %08x\n", hr
);
246 ok (pcItems
== 3, "The number of SCRIPT_ITEMS should be 3 not %d\n", pcItems
);
249 ok (pItem
[0].iCharPos
== 0 && pItem
[1].iCharPos
== 6,
250 "Start pos [0] not = 0 (%d) or end pos [1] not = %d\n",
251 pItem
[0].iCharPos
, pItem
[1].iCharPos
);
252 ok (pItem
[1].iCharPos
== 6 && pItem
[2].iCharPos
== 11,
253 "Start pos [1] not = 6 (%d) or end pos [2] not = 11 (%d)\n",
254 pItem
[1].iCharPos
, pItem
[2].iCharPos
);
255 ok (pItem
[2].iCharPos
== 11 && pItem
[3].iCharPos
== cInChars
,
256 "Start pos [2] not = 11 (%d) or end [3] pos not = 14 (%d), cInChars = %d\n",
257 pItem
[2].iCharPos
, pItem
[3].iCharPos
, cInChars
);
259 hr
= ScriptFreeCache( &psc
);
260 ok (!psc
, "psc is not null after ScriptFreeCache\n");
263 /* This is a valid test that will cause parsing to take place and create 3 script_items */
264 cInChars
= (sizeof(TestItem4
)/2)-1;
266 hr
= ScriptItemize(TestItem4
, cInChars
, cMaxItems
, NULL
, NULL
, pItem
, &pcItems
);
267 ok (hr
== 0, "ScriptItemize should return 0, returned %08x\n", hr
);
270 ok (pcItems
== 3, "The number of SCRIPT_ITEMS should be 3 not %d\n", pcItems
);
273 ok (pItem
[0].iCharPos
== 0 && pItem
[1].iCharPos
== 6,
274 "Start pos [0] not = 0 (%d) or end pos [1] not = %d\n",
275 pItem
[0].iCharPos
, pItem
[1].iCharPos
);
276 ok (pItem
[1].iCharPos
== 6 && pItem
[2].iCharPos
== 11,
277 "Start pos [1] not = 6 (%d) or end pos [2] not = 11 (%d)\n",
278 pItem
[1].iCharPos
, pItem
[2].iCharPos
);
279 ok (pItem
[2].iCharPos
== 11 && pItem
[3].iCharPos
== cInChars
,
280 "Start pos [2] not = 11 (%d) or end [3] pos not = 14 (%d), cInChars = %d\n",
281 pItem
[2].iCharPos
, pItem
[3].iCharPos
, cInChars
);
283 hr
= ScriptFreeCache( &psc
);
284 ok (!psc
, "psc is not null after ScriptFreeCache\n");
288 * This test is for when the first unicode character requires bidi support
290 cInChars
= (sizeof(TestItem5
)-1)/sizeof(WCHAR
);
291 hr
= ScriptItemize(TestItem5
, cInChars
, cMaxItems
, NULL
, NULL
, pItem
, &pcItems
);
292 ok (hr
== 0, "ScriptItemize should return 0, returned %08x\n", hr
);
293 ok (pcItems
== 4, "There should have been 4 items, found %d\n", pcItems
);
294 ok (pItem
[0].a
.s
.uBidiLevel
== 1, "The first character should have been bidi=1 not %d\n",
295 pItem
[0].a
.s
.uBidiLevel
);
298 static void test_ScriptGetCMap(HDC hdc
, unsigned short pwOutGlyphs
[256])
301 SCRIPT_CACHE psc
= NULL
;
304 unsigned short pwOutGlyphs3
[256];
305 WCHAR TestItem1
[] = {'T', 'e', 's', 't', 'a', 0};
309 /* Check to make sure that SCRIPT_CACHE gets allocated ok */
311 cInChars
= cChars
= 5;
312 /* Some sanity checks for ScriptGetCMap */
314 hr
= ScriptGetCMap(NULL
, NULL
, NULL
, 0, 0, NULL
);
315 ok( hr
== E_INVALIDARG
, "(NULL,NULL,NULL,0,0,NULL), "
316 "expected E_INVALIDARG, got %08x\n", hr
);
318 hr
= ScriptGetCMap(NULL
, NULL
, TestItem1
, cInChars
, dwFlags
, pwOutGlyphs3
);
319 ok( hr
== E_INVALIDARG
, "(NULL,NULL,TestItem1, cInChars, dwFlags, pwOutGlyphs3), "
320 "expected E_INVALIDARG, got %08x\n", hr
);
322 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
324 hr
= ScriptGetCMap(NULL
, &psc
, NULL
, 0, 0, NULL
);
325 ok( hr
== E_PENDING
, "(NULL,&psc,NULL,0,0NULL), expected E_PENDING, "
327 ok( psc
== NULL
, "Expected psc to be NULL, got %p\n", psc
);
329 /* Set psc to NULL but add hdc, to be able to check if a pointer is returned in psc */
331 hr
= ScriptGetCMap(hdc
, &psc
, NULL
, 0, 0, NULL
);
332 ok( hr
== S_OK
, "ScriptGetCMap(NULL,&psc,NULL,0,0,NULL), expected S_OK, "
334 ok( psc
!= NULL
, "ScritpGetCMap expected psc to be not NULL\n");
335 ScriptFreeCache( &psc
);
337 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
339 hr
= ScriptGetCMap(NULL
, &psc
, TestItem1
, cInChars
, dwFlags
, pwOutGlyphs3
);
340 ok( hr
== E_PENDING
, "(NULL,&psc,), expected E_PENDING, got %08x\n", hr
);
341 ok( psc
== NULL
, "Expected psc to be NULL, got %p\n", psc
);
342 /* Check to see if the results are the same as those returned by ScriptShape */
343 hr
= ScriptGetCMap(hdc
, &psc
, TestItem1
, cInChars
, dwFlags
, pwOutGlyphs3
);
344 ok (hr
== 0, "ScriptGetCMap should return 0 not (%08x)\n", hr
);
345 ok (psc
!= NULL
, "psc should not be null and have SCRIPT_CACHE buffer address\n");
346 for (cnt
=0; cnt
< cChars
&& pwOutGlyphs
[cnt
] == pwOutGlyphs3
[cnt
]; cnt
++) {}
347 ok (cnt
== cInChars
, "Translation not correct. WCHAR %d - %04x != %04x\n",
348 cnt
, pwOutGlyphs
[cnt
], pwOutGlyphs3
[cnt
]);
350 hr
= ScriptFreeCache( &psc
);
351 ok (!psc
, "psc is not null after ScriptFreeCache\n");
355 static void test_ScriptGetFontProperties(HDC hdc
)
358 SCRIPT_CACHE psc
,old_psc
;
359 SCRIPT_FONTPROPERTIES sfp
;
361 /* Some sanity checks for ScriptGetFontProperties */
363 hr
= ScriptGetFontProperties(NULL
,NULL
,NULL
);
364 ok( hr
== E_INVALIDARG
, "(NULL,NULL,NULL), expected E_INVALIDARG, got %08x\n", hr
);
366 hr
= ScriptGetFontProperties(NULL
,NULL
,&sfp
);
367 ok( hr
== E_INVALIDARG
, "(NULL,NULL,&sfp), expected E_INVALIDARG, got %08x\n", hr
);
369 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
371 hr
= ScriptGetFontProperties(NULL
,&psc
,NULL
);
372 ok( hr
== E_INVALIDARG
, "(NULL,&psc,NULL), expected E_INVALIDARG, got %08x\n", hr
);
373 ok( psc
== NULL
, "Expected psc to be NULL, got %p\n", psc
);
375 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
377 hr
= ScriptGetFontProperties(NULL
,&psc
,&sfp
);
378 ok( hr
== E_PENDING
, "(NULL,&psc,&sfp), expected E_PENDING, got %08x\n", hr
);
379 ok( psc
== NULL
, "Expected psc to be NULL, got %p\n", psc
);
381 hr
= ScriptGetFontProperties(hdc
,NULL
,NULL
);
382 ok( hr
== E_INVALIDARG
, "(hdc,NULL,NULL), expected E_INVALIDARG, got %08x\n", hr
);
384 hr
= ScriptGetFontProperties(hdc
,NULL
,&sfp
);
385 ok( hr
== E_INVALIDARG
, "(hdc,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(hdc
,&psc
,NULL
);
390 ok( hr
== E_INVALIDARG
, "(hdc,&psc,NULL), expected E_INVALIDARG, got %08x\n", hr
);
391 ok( psc
== NULL
, "Expected psc to be NULL, got %p\n", psc
);
393 /* Pass an invalid sfp */
395 sfp
.cBytes
= sizeof(SCRIPT_FONTPROPERTIES
) - 1;
396 hr
= ScriptGetFontProperties(hdc
,&psc
,&sfp
);
397 ok( hr
== E_INVALIDARG
, "(hdc,&psc,&sfp) invalid, expected E_INVALIDARG, got %08x\n", hr
);
398 ok( psc
!= NULL
, "Expected a pointer in psc, got NULL\n");
399 ScriptFreeCache(&psc
);
400 ok( psc
== NULL
, "Expected psc to be NULL, got %p\n", psc
);
402 /* Give it the correct cBytes, we don't care about what's coming back */
403 sfp
.cBytes
= sizeof(SCRIPT_FONTPROPERTIES
);
405 hr
= ScriptGetFontProperties(hdc
,&psc
,&sfp
);
406 ok( hr
== S_OK
, "(hdc,&psc,&sfp) partly initialized, expected S_OK, got %08x\n", hr
);
407 ok( psc
!= NULL
, "Expected a pointer in psc, got NULL\n");
409 /* Save the psc pointer */
411 /* Now a NULL hdc again */
412 hr
= ScriptGetFontProperties(NULL
,&psc
,&sfp
);
413 ok( hr
== S_OK
, "(NULL,&psc,&sfp), expected S_OK, got %08x\n", hr
);
414 ok( psc
== old_psc
, "Expected psc not to be changed, was %p is now %p\n", old_psc
, psc
);
415 ScriptFreeCache(&psc
);
416 ok( psc
== NULL
, "Expected psc to be NULL, got %p\n", psc
);
419 static void test_ScriptTextOut(HDC hdc
)
425 SCRIPT_ITEM pItem
[255];
427 WCHAR TestItem1
[] = {'T', 'e', 's', 't', 'a', 0};
432 unsigned short pwOutGlyphs1
[256];
433 WORD pwLogClust
[256];
434 SCRIPT_VISATTR psva
[256];
437 GOFFSET pGoffset
[256];
442 BOOL fTrailing
= FALSE
;
443 SCRIPT_LOGATTR
*psla
;
444 SCRIPT_LOGATTR sla
[256];
446 /* This is a valid test that will cause parsing to take place */
449 hr
= ScriptItemize(TestItem1
, cInChars
, cMaxItems
, NULL
, NULL
, pItem
, &pcItems
);
450 ok (hr
== 0, "ScriptItemize should return 0, returned %08x\n", hr
);
451 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
453 ok (pcItems
> 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
455 ok (pItem
[0].iCharPos
== 0 && pItem
[1].iCharPos
== cInChars
,
456 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
457 pItem
[0].iCharPos
, cInChars
, pItem
[1].iCharPos
);
459 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
460 * ie. ScriptItemize has succeeded and that pItem has been set */
464 psc
= NULL
; /* must be null on first call */
466 cMaxGlyphs
= cInChars
;
468 hr
= ScriptShape(hdc
, &psc
, TestItem1
, cChars
,
469 cMaxGlyphs
, &pItem
[0].a
,
470 pwOutGlyphs1
, pwLogClust
, psva
, &pcGlyphs
);
471 ok (hr
== 0, "ScriptShape should return 0 not (%08x)\n", hr
);
472 ok (psc
!= NULL
, "psc should not be null and have SCRIPT_CACHE buffer address\n");
473 ok (pcGlyphs
== cChars
, "Chars in (%d) should equal Glyphs out (%d)\n", cChars
, pcGlyphs
);
475 /* Note hdc is needed as glyph info is not yet in psc */
476 hr
= ScriptPlace(hdc
, &psc
, pwOutGlyphs1
, pcGlyphs
, psva
, &pItem
[0].a
, piAdvance
,
478 ok (hr
== 0, "Should return 0 not (%08x)\n", hr
);
479 ScriptFreeCache(&psc
); /* Get rid of psc for next test set */
480 ok( psc
== NULL
, "Expected psc to be NULL, got %p\n", psc
);
482 hr
= ScriptTextOut(NULL
, NULL
, 0, 0, 0, NULL
, NULL
, NULL
, 0, NULL
, 0, NULL
, NULL
, NULL
);
483 ok (hr
== E_INVALIDARG
, "Should return 0 not (%08x)\n", hr
);
485 hr
= ScriptTextOut(NULL
, NULL
, 0, 0, 0, NULL
, &pItem
[0].a
, NULL
, 0, pwOutGlyphs1
, pcGlyphs
,
486 piAdvance
, NULL
, pGoffset
);
487 ok( hr
== E_INVALIDARG
, "(NULL,NULL,TestItem1, cInChars, dwFlags, pwOutGlyphs3), "
488 "expected E_INVALIDARG, got %08x\n", hr
);
490 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
492 hr
= ScriptTextOut(NULL
, &psc
, 0, 0, 0, NULL
, NULL
, NULL
, 0, NULL
, 0,
494 ok( hr
== E_INVALIDARG
, "(NULL,&psc,NULL,0,0,0,NULL,), expected E_INVALIDARG, "
496 ok( psc
== NULL
, "Expected psc to be NULL, got %p\n", psc
);
498 /* hdc is required for this one rather than the usual optional */
500 hr
= ScriptTextOut(NULL
, &psc
, 0, 0, 0, NULL
, &pItem
[0].a
, NULL
, 0, pwOutGlyphs1
, pcGlyphs
,
501 piAdvance
, NULL
, pGoffset
);
502 ok( hr
== E_INVALIDARG
, "(NULL,&psc,), expected E_INVALIDARG, got %08x\n", hr
);
503 ok( psc
== NULL
, "Expected psc to be NULL, got %p\n", psc
);
505 /* Set that it returns 0 status */
506 hr
= ScriptTextOut(hdc
, &psc
, 0, 0, 0, NULL
, &pItem
[0].a
, NULL
, 0, pwOutGlyphs1
, pcGlyphs
,
507 piAdvance
, NULL
, pGoffset
);
508 ok (hr
== 0, "ScriptTextOut should return 0 not (%08x)\n", hr
);
510 /* Test Rect Rgn is acceptable */
515 hr
= ScriptTextOut(hdc
, &psc
, 0, 0, 0, &rect
, &pItem
[0].a
, NULL
, 0, pwOutGlyphs1
, pcGlyphs
,
516 piAdvance
, NULL
, pGoffset
);
517 ok (hr
== 0, "ScriptTextOut should return 0 not (%08x)\n", hr
);
520 hr
= ScriptCPtoX(iCP
, fTrailing
, cChars
, pcGlyphs
, (const WORD
*) &pwLogClust
,
521 (const SCRIPT_VISATTR
*) &psva
, (const int *)&piAdvance
, &pItem
[0].a
, &piX
);
522 ok(hr
== S_OK
, "ScriptCPtoX Stub should return S_OK not %08x\n", hr
);
524 psla
= (SCRIPT_LOGATTR
*)&sla
;
525 hr
= ScriptBreak(TestItem1
, cChars
, &pItem
[0].a
, psla
);
526 ok(hr
== S_OK
, "ScriptBreak Stub should return S_OK not %08x\n", hr
);
528 /* Clean up and go */
529 ScriptFreeCache(&psc
);
530 ok( psc
== NULL
, "Expected psc to be NULL, got %p\n", psc
);
535 static void test_ScriptTextOut2(HDC hdc
)
537 /* Intent is to validate that the HDC passed into ScriptTextOut is
538 * used instead of the (possibly) invalid cached one
545 SCRIPT_ITEM pItem
[255];
547 WCHAR TestItem1
[] = {'T', 'e', 's', 't', 'a', 0};
552 unsigned short pwOutGlyphs1
[256];
553 WORD pwLogClust
[256];
554 SCRIPT_VISATTR psva
[256];
557 GOFFSET pGoffset
[256];
560 /* Create an extra DC that will be used until the ScriptTextOut */
561 hdc1
= CreateCompatibleDC(hdc
);
562 ok (hdc1
!= 0, "CreateCompatibleDC failed to create a DC\n");
563 hdc2
= CreateCompatibleDC(hdc
);
564 ok (hdc2
!= 0, "CreateCompatibleDC failed to create a DC\n");
566 /* This is a valid test that will cause parsing to take place */
569 hr
= ScriptItemize(TestItem1
, cInChars
, cMaxItems
, NULL
, NULL
, pItem
, &pcItems
);
570 ok (hr
== 0, "ScriptItemize should return 0, returned %08x\n", hr
);
571 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
573 ok (pcItems
> 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
575 ok (pItem
[0].iCharPos
== 0 && pItem
[1].iCharPos
== cInChars
,
576 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
577 pItem
[0].iCharPos
, cInChars
, pItem
[1].iCharPos
);
579 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
580 * ie. ScriptItemize has succeeded and that pItem has been set */
584 psc
= NULL
; /* must be null on first call */
586 cMaxGlyphs
= cInChars
;
588 hr
= ScriptShape(hdc2
, &psc
, TestItem1
, cChars
,
589 cMaxGlyphs
, &pItem
[0].a
,
590 pwOutGlyphs1
, pwLogClust
, psva
, &pcGlyphs
);
591 ok (hr
== 0, "ScriptShape should return 0 not (%08x)\n", hr
);
592 ok (psc
!= NULL
, "psc should not be null and have SCRIPT_CACHE buffer address\n");
593 ok (pcGlyphs
== cChars
, "Chars in (%d) should equal Glyphs out (%d)\n", cChars
, pcGlyphs
);
595 /* Note hdc is needed as glyph info is not yet in psc */
596 hr
= ScriptPlace(hdc2
, &psc
, pwOutGlyphs1
, pcGlyphs
, psva
, &pItem
[0].a
, piAdvance
,
598 ok (hr
== 0, "Should return 0 not (%08x)\n", hr
);
600 /* key part!!! cached dc is being deleted */
602 ok(hr
== 1, "DeleteDC should return 1 not %08x\n", hr
);
604 /* At this point the cached hdc (hdc2) has been destroyed,
605 * however, we are passing in a *real* hdc (the original hdc).
606 * The text should be written to that DC
608 hr
= ScriptTextOut(hdc1
, &psc
, 0, 0, 0, NULL
, &pItem
[0].a
, NULL
, 0, pwOutGlyphs1
, pcGlyphs
,
609 piAdvance
, NULL
, pGoffset
);
610 ok (hr
== 0, "ScriptTextOut should return 0 not (%08x)\n", hr
);
611 ok (psc
!= NULL
, "psc should not be null and have SCRIPT_CACHE buffer address\n");
615 /* Clean up and go */
616 ScriptFreeCache(&psc
);
617 ok( psc
== NULL
, "Expected psc to be NULL, got %p\n", psc
);
622 static void test_ScriptXtoX(void)
623 /****************************************************************************************
624 * This routine tests the ScriptXtoCP and ScriptCPtoX functions using static variables *
625 ****************************************************************************************/
627 static const WCHAR test
[] = {'t', 'e', 's', 't',0};
628 SCRIPT_ITEM items
[2];
632 WORD pwLogClust
[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
633 SCRIPT_VISATTR psva
[10];
634 int piAdvance
[10] = {200, 190, 210, 180, 170, 204, 189, 195, 212, 203};
640 hr
= ScriptItemize(test
, lstrlenW(test
), sizeof(items
)/sizeof(items
[0]), NULL
, NULL
, items
, NULL
);
641 ok(!hr
, "ScriptItemize should return S_OK not %08x\n", hr
);
646 hr
= ScriptXtoCP(iX
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
, &items
[0].a
, &piCP
, &piTrailing
);
647 ok(hr
== S_OK
, "ScriptXtoCP should return S_OK not %08x\n", hr
);
649 ok(piCP
== -1, "Negative iX should return piCP=-1 not %d\n", piCP
);
651 ok(piCP
== 10, "Negative iX should return piCP=10 not %d\n", piCP
);
656 hr
= ScriptXtoCP(iX
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
, &items
[0].a
, &piCP
, &piTrailing
);
657 ok(hr
== S_OK
, "ScriptXtoCP should return S_OK not %08x\n", hr
);
658 if (piTrailing
) /* win2k3 */
659 ok(piCP
== -1, "Negative iX should return piCP=-1 not %d\n", piCP
);
661 ok(piCP
== 10, "Negative iX should return piCP=10 not %d\n", piCP
);
666 hr
= ScriptXtoCP(iX
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
, &items
[0].a
, &piCP
, &piTrailing
);
667 ok(hr
== S_OK
, "ScriptXtoCP should return S_OK not %08x\n", hr
);
669 piCP
== -1, /* win2k3 */
670 "iX=%d should return piCP=3 or piCP=-1 not %d\n", iX
, piCP
);
671 ok(piTrailing
== 1, "iX=%d should return piTrailing=1 not %d\n", iX
, piTrailing
);
676 hr
= ScriptXtoCP(iX
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
, &items
[0].a
, &piCP
, &piTrailing
);
677 ok(hr
== S_OK
, "ScriptXtoCP should return S_OK not %08x\n", hr
);
679 piCP
== -1, /* win2k3 */
680 "iX=%d should return piCP=3 or piCP=-1 not %d\n", iX
, piCP
);
681 ok(piTrailing
== 1, "iX=%d should return piTrailing=1 not %d\n", iX
, piTrailing
);
686 hr
= ScriptXtoCP(iX
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
, &items
[0].a
, &piCP
, &piTrailing
);
687 ok(hr
== S_OK
, "ScriptXtoCP should return S_OK not %08x\n", hr
);
689 piCP
== -1, /* win2k3 */
690 "iX=%d should return piCP=4 or piCP=-1 not %d\n", iX
, piCP
);
695 hr
= ScriptXtoCP(iX
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
, &items
[0].a
, &piCP
, &piTrailing
);
696 ok(hr
== S_OK
, "ScriptXtoCP should return S_OK not %08x\n", hr
);
698 piCP
== 10, /* win2k3 */
699 "iX=%d should return piCP=0 piCP=10 not %d\n", iX
, piCP
);
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
);
706 ok(piCP
== 0, "iX=%d should return piCP=0 not %d\n", iX
, piCP
);
711 hr
= ScriptXtoCP(iX
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
, &items
[0].a
, &piCP
, &piTrailing
);
712 ok(hr
== S_OK
, "ScriptXtoCP should return S_OK not %08x\n", hr
);
714 piCP
== 0, /* win2k3 */
715 "iX=%d should return piCP=1 or piCP=0 not %d\n", iX
, piCP
);
721 hr
= ScriptCPtoX(iCP
, fTrailing
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
, &items
[0].a
, &piX
);
722 ok(hr
== S_OK
, "ScriptCPtoX should return S_OK not %08x\n", hr
);
724 piX
== 100, /* win2k3 */
725 "iCP=%d should return piX=976 or piX=100 not %d\n", iCP
, piX
);
731 hr
= ScriptCPtoX(iCP
, fTrailing
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
, &items
[0].a
, &piX
);
732 ok(hr
== S_OK
, "ScriptCPtoX should return S_OK not %08x\n", hr
);
734 piX
== 80, /* win2k3 */
735 "iCP=%d should return piX=1171 or piX=80 not %d\n", iCP
, piX
);
741 hr
= ScriptCPtoX(iCP
, fTrailing
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
, &items
[0].a
, &piX
);
742 ok(hr
== S_OK
, "ScriptCPtoX should return S_OK not %08x\n", hr
);
744 piX
== 80, /* win2k3 */
745 "iCP=%d should return piX=1171 or piX=80 not %d\n", iCP
, piX
);
751 hr
= ScriptCPtoX(iCP
, fTrailing
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
, &items
[0].a
, &piX
);
752 ok(hr
== S_OK
, "ScriptCPtoX should return S_OK not %08x\n", hr
);
754 piX
== 0, /* win2k3 */
755 "iCP=%d should return piX=1953 or piX=0 not %d\n", iCP
, piX
);
761 hr
= ScriptCPtoX(iCP
, fTrailing
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
, &items
[0].a
, &piX
);
762 ok(hr
== S_OK
, "ScriptCPtoX should return S_OK not %08x\n", hr
);
764 piX
== 0, /* win2k3 */
765 "iCP=%d should return piX=1953 or piX=0 not %d\n", iCP
, piX
);
768 static void test_ScriptString(HDC hdc
)
770 /*******************************************************************************************
772 * This set of tests are for the string functions of uniscribe. The ScriptStringAnalyse
773 * function allocates memory pointed to by the SCRIPT_STRING_ANALYSIS ssa pointer. This
774 * memory if freed by ScriptStringFree. There needs to be a valid hdc for this as
775 * ScriptStringAnalyse calls ScriptSItemize, ScriptShape and ScriptPlace which require it.
780 WCHAR teststr
[] = {'T','e','s','t','1',' ','a','2','b','3', '\0'};
781 int len
= (sizeof(teststr
) / sizeof(WCHAR
)) - 1;
782 int Glyphs
= len
* 2 + 16;
784 DWORD Flags
= SSA_GLYPHS
;
786 SCRIPT_CONTROL Control
;
788 const int Dx
[5] = {10, 10, 10, 10, 10};
789 SCRIPT_TABDEF Tabdef
;
790 const BYTE InClass
= 0;
791 SCRIPT_STRING_ANALYSIS ssa
= NULL
;
796 const RECT rc
= {0, 50, 100, 100};
799 BOOL Disabled
= FALSE
;
805 Charset
= -1; /* this flag indicates unicode input */
806 /* Test without hdc to get E_PENDING */
807 hr
= ScriptStringAnalyse( NULL
, teststr
, len
, Glyphs
, Charset
, Flags
,
808 ReqWidth
, &Control
, &State
, Dx
, &Tabdef
,
810 ok(hr
== E_PENDING
, "ScriptStringAnalyse Stub should return E_PENDING not %08x\n", hr
);
812 /* test with hdc, this should be a valid test */
813 hr
= ScriptStringAnalyse( hdc
, teststr
, len
, Glyphs
, Charset
, Flags
,
814 ReqWidth
, &Control
, &State
, Dx
, &Tabdef
,
816 ok(hr
== S_OK
, "ScriptStringAnalyse should return S_OK not %08x\n", hr
);
817 ScriptStringFree(&ssa
);
819 /* test makes sure that a call with a valid pssa still works */
820 hr
= ScriptStringAnalyse( hdc
, teststr
, len
, Glyphs
, Charset
, Flags
,
821 ReqWidth
, &Control
, &State
, Dx
, &Tabdef
,
823 ok(hr
== S_OK
, "ScriptStringAnalyse should return S_OK not %08x\n", hr
);
824 ok(ssa
!= NULL
, "ScriptStringAnalyse pssa should not be NULL\n");
828 hr
= ScriptStringOut(ssa
, X
, Y
, Options
, &rc
, MinSel
, MaxSel
, Disabled
);
829 ok(hr
== S_OK
, "ScriptStringOut should return S_OK not %08x\n", hr
);
832 clip_len
= ScriptString_pcOutChars(ssa
);
833 ok(*clip_len
== len
, "ScriptString_pcOutChars failed, got %d, expected %d\n", *clip_len
, len
);
835 order
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, *clip_len
* sizeof(UINT
));
836 hr
= ScriptStringGetOrder(ssa
, order
);
837 ok(hr
== S_OK
, "ScriptStringGetOrder failed, got %08x, expected S_OK\n", hr
);
839 for (i
= 0; i
< *clip_len
; i
++) ok(order
[i
] == i
, "%d: got %d expected %d\n", i
, order
[i
], i
);
840 HeapFree(GetProcessHeap(), 0, order
);
842 hr
= ScriptStringFree(&ssa
);
843 ok(hr
== S_OK
, "ScriptStringFree should return S_OK not %08x\n", hr
);
846 static void test_ScriptStringXtoCP_CPtoX(HDC hdc
)
848 /*****************************************************************************************
850 * This test is for the ScriptStringXtoCP and ScriptStringXtoCP functions. Due to the
851 * nature of the fonts between Windows and Wine, the test is implemented by generating
852 * values using one one function then checking the output of the second. In this way
853 * the validity of the functions is established using Windows as a base and confirming
854 * similar behaviour in wine.
858 WCHAR teststr1
[] = {'T', 'e', 's', 't', 'e', '1', '2', ' ', 'a', '\0'};
859 void *String
= (WCHAR
*) &teststr1
; /* ScriptStringAnalysis needs void */
860 int String_len
= (sizeof(teststr1
)/sizeof(WCHAR
))-1;
861 int Glyphs
= String_len
* 2 + 16; /* size of buffer as recommended */
862 int Charset
= -1; /* unicode */
863 DWORD Flags
= SSA_GLYPHS
;
865 SCRIPT_CONTROL Control
;
867 SCRIPT_TABDEF Tabdef
;
868 const BYTE InClass
= 0;
869 SCRIPT_STRING_ANALYSIS ssa
= NULL
;
871 int Ch
; /* Character position in string */
873 int Cp
; /* Character position in string */
877 /* Test with hdc, this should be a valid test
878 * Here we generate an SCRIPT_STRING_ANALYSIS that will be used as input to the
879 * following character positions to X and X to character position functions.
881 hr
= ScriptStringAnalyse( hdc
, String
, String_len
, Glyphs
, Charset
, Flags
,
882 ReqWidth
, &Control
, &State
, NULL
, &Tabdef
,
885 hr
== E_INVALIDARG
, /* NT */
886 "ScriptStringAnalyse should return S_OK or E_INVALIDARG not %08x\n", hr
);
890 ok(ssa
!= NULL
, "ScriptStringAnalyse ssa should not be NULL\n");
893 * Loop to generate character positions to provide starting positions for the
894 * ScriptStringCPtoX and ScriptStringXtoCP functions
896 for (Cp
= 0; Cp
< String_len
; Cp
++)
898 /* The fTrailing flag is used to indicate whether the X being returned is at
899 * the beginning or the end of the character. What happens here is that if
900 * fTrailing indicates the end of the character, ie. FALSE, then ScriptStringXtoCP
901 * returns the beginning of the next character and iTrailing is FALSE. So for this
902 * loop iTrailing will be FALSE in both cases.
905 hr
= ScriptStringCPtoX(ssa
, Cp
, fTrailing
, &X
);
906 ok(hr
== S_OK
, "ScriptStringCPtoX should return S_OK not %08x\n", hr
);
907 hr
= ScriptStringXtoCP(ssa
, X
, &Ch
, &iTrailing
);
908 ok(hr
== S_OK
, "ScriptStringXtoCP should return S_OK not %08x\n", hr
);
909 ok(Cp
== Ch
, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp
, Ch
, X
);
910 ok(iTrailing
== FALSE
, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
913 hr
= ScriptStringCPtoX(ssa
, Cp
, fTrailing
, &X
);
914 ok(hr
== S_OK
, "ScriptStringCPtoX should return S_OK not %08x\n", hr
);
915 hr
= ScriptStringXtoCP(ssa
, X
, &Ch
, &iTrailing
);
916 ok(hr
== S_OK
, "ScriptStringXtoCP should return S_OK not %08x\n", hr
);
919 * Check that character position returned by ScriptStringXtoCP in Ch matches the
920 * one input to ScriptStringCPtoX. This means that the Cp to X position and back
923 ok(Cp
+ 1 == Ch
, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp
+ 1, Ch
, X
);
924 ok(iTrailing
== FALSE
, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
928 * This test is to check that if the X position is just inside the trailing edge of the
929 * character then iTrailing will indicate the trailing edge, ie. TRUE
933 hr
= ScriptStringCPtoX(ssa
, Cp
, fTrailing
, &X
);
934 ok(hr
== S_OK
, "ScriptStringCPtoX should return S_OK not %08x\n", hr
);
935 X
--; /* put X just inside the trailing edge */
936 hr
= ScriptStringXtoCP(ssa
, X
, &Ch
, &iTrailing
);
937 ok(hr
== S_OK
, "ScriptStringXtoCP should return S_OK not %08x\n", hr
);
938 ok(Cp
== Ch
, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp
, Ch
, X
);
939 ok(iTrailing
== TRUE
, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
943 * This test is to check that if the X position is just outside the trailing edge of the
944 * character then iTrailing will indicate the leading edge, ie. FALSE, and Ch will indicate
945 * the next character, ie. Cp + 1
949 hr
= ScriptStringCPtoX(ssa
, Cp
, fTrailing
, &X
);
950 ok(hr
== S_OK
, "ScriptStringCPtoX should return S_OK not %08x\n", hr
);
951 X
++; /* put X just outside the trailing edge */
952 hr
= ScriptStringXtoCP(ssa
, X
, &Ch
, &iTrailing
);
953 ok(hr
== S_OK
, "ScriptStringXtoCP should return S_OK not %08x\n", hr
);
954 ok(Cp
+ 1 == Ch
, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp
+ 1, Ch
, X
);
955 ok(iTrailing
== FALSE
, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
959 * This test is to check that if the X position is just outside the leading edge of the
960 * character then iTrailing will indicate the trailing edge, ie. TRUE, and Ch will indicate
961 * the next character down , ie. Cp - 1
965 hr
= ScriptStringCPtoX(ssa
, Cp
, fTrailing
, &X
);
966 ok(hr
== S_OK
, "ScriptStringCPtoX should return S_OK not %08x\n", hr
);
967 X
--; /* put X just outside the leading edge */
968 hr
= ScriptStringXtoCP(ssa
, X
, &Ch
, &iTrailing
);
969 ok(hr
== S_OK
, "ScriptStringXtoCP should return S_OK not %08x\n", hr
);
970 ok(Cp
- 1 == Ch
, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp
- 1, Ch
, X
);
971 ok(iTrailing
== TRUE
, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
975 * Cleanup the SSA for the next round of tests
977 hr
= ScriptStringFree(&ssa
);
978 ok(hr
== S_OK
, "ScriptStringFree should return S_OK not %08x\n", hr
);
981 * Test to see that exceeding the number of chars returns E_INVALIDARG. First
982 * generate an SSA for the subsequent tests.
984 hr
= ScriptStringAnalyse( hdc
, String
, String_len
, Glyphs
, Charset
, Flags
,
985 ReqWidth
, &Control
, &State
, NULL
, &Tabdef
,
987 ok(hr
== S_OK
, "ScriptStringAnalyse should return S_OK not %08x\n", hr
);
990 * When ScriptStringCPtoX is called with a character position Cp that exceeds the
991 * string length, return E_INVALIDARG. This also invalidates the ssa so a
992 * ScriptStringFree should also fail.
996 hr
= ScriptStringCPtoX(ssa
, Cp
, fTrailing
, &X
);
997 ok(hr
== E_INVALIDARG
, "ScriptStringCPtoX should return E_INVALIDARG not %08x\n", hr
);
999 hr
= ScriptStringFree(&ssa
);
1001 * ScriptStringCPtoX should free ssa, hence ScriptStringFree should fail
1003 ok(hr
== E_INVALIDARG
||
1004 hr
== E_FAIL
, /* win2k3 */
1005 "ScriptStringFree should return E_INVALIDARG or E_FAIL not %08x\n", hr
);
1009 static void test_ScriptCacheGetHeight(HDC hdc
)
1012 SCRIPT_CACHE sc
= NULL
;
1015 hr
= ScriptCacheGetHeight(NULL
, NULL
, NULL
);
1016 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got 0x%08x\n", hr
);
1018 hr
= ScriptCacheGetHeight(NULL
, &sc
, NULL
);
1019 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got 0x%08x\n", hr
);
1021 hr
= ScriptCacheGetHeight(NULL
, &sc
, &height
);
1022 ok(hr
== E_PENDING
, "expected E_PENDING, got 0x%08x\n", hr
);
1026 hr
= ScriptCacheGetHeight(hdc
, &sc
, &height
);
1027 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
1028 ok(height
> 0, "expected height > 0\n");
1030 ScriptFreeCache(&sc
);
1033 static void test_ScriptGetGlyphABCWidth(HDC hdc
)
1036 SCRIPT_CACHE sc
= NULL
;
1039 hr
= ScriptGetGlyphABCWidth(NULL
, NULL
, 'a', NULL
);
1040 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got 0x%08x\n", hr
);
1042 hr
= ScriptGetGlyphABCWidth(NULL
, &sc
, 'a', NULL
);
1043 ok(hr
== E_PENDING
, "expected E_PENDING, got 0x%08x\n", hr
);
1045 if (0) { /* crashes on WinXP */
1046 hr
= ScriptGetGlyphABCWidth(hdc
, &sc
, 'a', NULL
);
1047 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got 0x%08x\n", hr
);
1050 hr
= ScriptGetGlyphABCWidth(hdc
, &sc
, 'a', &abc
);
1051 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
1053 ScriptFreeCache(&sc
);
1056 static void test_ScriptLayout(void)
1059 static const BYTE levels
[][5] =
1066 static const int expect
[][5] =
1073 int i
, j
, vistolog
[sizeof(levels
[0])], logtovis
[sizeof(levels
[0])];
1075 hr
= ScriptLayout(sizeof(levels
[0]), NULL
, vistolog
, logtovis
);
1076 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got 0x%08x\n", hr
);
1078 hr
= ScriptLayout(sizeof(levels
[0]), levels
[0], NULL
, NULL
);
1079 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got 0x%08x\n", hr
);
1081 for (i
= 0; i
< sizeof(levels
)/sizeof(levels
[0]); i
++)
1083 hr
= ScriptLayout(sizeof(levels
[0]), levels
[i
], vistolog
, logtovis
);
1084 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
1086 for (j
= 0; j
< sizeof(levels
[i
]); j
++)
1088 ok(expect
[i
][j
] == vistolog
[j
],
1089 "failure: levels[%d][%d] = %d, vistolog[%d] = %d\n",
1090 i
, j
, levels
[i
][j
], j
, vistolog
[j
] );
1093 for (j
= 0; j
< sizeof(levels
[i
]); j
++)
1095 ok(expect
[i
][j
] == logtovis
[j
],
1096 "failure: levels[%d][%d] = %d, logtovis[%d] = %d\n",
1097 i
, j
, levels
[i
][j
], j
, logtovis
[j
] );
1102 static BOOL CALLBACK
enum_proc(LGRPID group
, LCID lcid
, LPSTR locale
, LONG_PTR lparam
)
1105 SCRIPT_DIGITSUBSTITUTE sds
;
1110 if (!IsValidLocale(lcid
, LCID_INSTALLED
)) return TRUE
;
1112 memset(&sds
, 0, sizeof(sds
));
1113 memset(&sc
, 0, sizeof(sc
));
1114 memset(&ss
, 0, sizeof(ss
));
1116 lcid_old
= GetThreadLocale();
1117 if (!SetThreadLocale(lcid
)) return TRUE
;
1119 hr
= ScriptRecordDigitSubstitution(lcid
, &sds
);
1120 ok(hr
== S_OK
, "ScriptRecordDigitSubstitution failed: 0x%08x\n", hr
);
1122 hr
= ScriptApplyDigitSubstitution(&sds
, &sc
, &ss
);
1123 ok(hr
== S_OK
, "ScriptApplyDigitSubstitution failed: 0x%08x\n", hr
);
1125 SetThreadLocale(lcid_old
);
1129 static void test_digit_substitution(void)
1133 static const LGRPID groups
[] =
1135 LGRPID_WESTERN_EUROPE
,
1136 LGRPID_CENTRAL_EUROPE
,
1143 LGRPID_TRADITIONAL_CHINESE
,
1144 LGRPID_SIMPLIFIED_CHINESE
,
1154 static BOOL (WINAPI
* pEnumLanguageGroupLocalesA
)(LANGGROUPLOCALE_ENUMPROC
,LGRPID
,DWORD
,LONG_PTR
);
1156 hKernel32
= GetModuleHandleA("kernel32.dll");
1157 pEnumLanguageGroupLocalesA
= (void*)GetProcAddress(hKernel32
, "EnumLanguageGroupLocalesA");
1159 if (!pEnumLanguageGroupLocalesA
)
1161 win_skip("EnumLanguageGroupLocalesA not available on this platform\n");
1165 for (i
= 0; i
< sizeof(groups
)/sizeof(groups
[0]); i
++)
1167 ret
= pEnumLanguageGroupLocalesA(enum_proc
, groups
[i
], 0, 0);
1168 ok(ret
, "EnumLanguageGroupLocalesA failed unexpectedly: %u\n", GetLastError());
1172 static void test_ScriptGetProperties(void)
1174 const SCRIPT_PROPERTIES
**props
;
1178 hr
= ScriptGetProperties(NULL
, NULL
);
1179 ok(hr
== E_INVALIDARG
, "ScriptGetProperties succeeded\n");
1181 hr
= ScriptGetProperties(NULL
, &num
);
1182 ok(hr
== S_OK
, "ScriptGetProperties failed: 0x%08x\n", hr
);
1184 hr
= ScriptGetProperties(&props
, NULL
);
1185 ok(hr
== S_OK
, "ScriptGetProperties failed: 0x%08x\n", hr
);
1187 hr
= ScriptGetProperties(&props
, &num
);
1188 ok(hr
== S_OK
, "ScriptGetProperties failed: 0x%08x\n", hr
);
1191 static void test_ScriptBreak(void)
1193 static const WCHAR test
[] = {' ','\r','\n',0};
1194 SCRIPT_ITEM items
[4];
1198 hr
= ScriptItemize(test
, 3, 4, NULL
, NULL
, items
, NULL
);
1199 ok(!hr
, "ScriptItemize should return S_OK not %08x\n", hr
);
1201 memset(&la
, 0, sizeof(la
));
1202 hr
= ScriptBreak(test
, 1, &items
[0].a
, &la
);
1203 ok(!hr
, "ScriptBreak should return S_OK not %08x\n", hr
);
1205 ok(!la
.fSoftBreak
, "fSoftBreak set\n");
1206 ok(la
.fWhiteSpace
, "fWhiteSpace not set\n");
1207 ok(la
.fCharStop
, "fCharStop not set\n");
1208 ok(!la
.fWordStop
, "fWordStop set\n");
1209 ok(!la
.fInvalid
, "fInvalid set\n");
1210 ok(!la
.fReserved
, "fReserved set\n");
1212 memset(&la
, 0, sizeof(la
));
1213 hr
= ScriptBreak(test
+ 1, 1, &items
[1].a
, &la
);
1214 ok(!hr
, "ScriptBreak should return S_OK not %08x\n", hr
);
1216 ok(!la
.fSoftBreak
, "fSoftBreak set\n");
1217 ok(!la
.fWhiteSpace
, "fWhiteSpace set\n");
1218 ok(la
.fCharStop
, "fCharStop not set\n");
1219 ok(!la
.fWordStop
, "fWordStop set\n");
1220 ok(!la
.fInvalid
, "fInvalid set\n");
1221 ok(!la
.fReserved
, "fReserved set\n");
1223 memset(&la
, 0, sizeof(la
));
1224 hr
= ScriptBreak(test
+ 2, 1, &items
[2].a
, &la
);
1225 ok(!hr
, "ScriptBreak should return S_OK not %08x\n", hr
);
1227 ok(!la
.fSoftBreak
, "fSoftBreak set\n");
1228 ok(!la
.fWhiteSpace
, "fWhiteSpace set\n");
1229 ok(la
.fCharStop
, "fCharStop not set\n");
1230 ok(!la
.fWordStop
, "fWordStop set\n");
1231 ok(!la
.fInvalid
, "fInvalid set\n");
1232 ok(!la
.fReserved
, "fReserved set\n");
1235 static void test_newlines(void)
1237 static const WCHAR test1
[] = {'t','e','x','t','\r','t','e','x','t',0};
1238 static const WCHAR test2
[] = {'t','e','x','t','\n','t','e','x','t',0};
1239 static const WCHAR test3
[] = {'t','e','x','t','\r','\n','t','e','x','t',0};
1240 static const WCHAR test4
[] = {'t','e','x','t','\n','\r','t','e','x','t',0};
1241 static const WCHAR test5
[] = {'1','2','3','4','\n','\r','1','2','3','4',0};
1242 SCRIPT_ITEM items
[5];
1247 hr
= ScriptItemize(test1
, lstrlenW(test1
), 5, NULL
, NULL
, items
, &count
);
1248 ok(hr
== S_OK
, "ScriptItemize failed: 0x%08x\n", hr
);
1249 ok(count
== 3, "got %d expected 3\n", count
);
1252 hr
= ScriptItemize(test2
, lstrlenW(test2
), 5, NULL
, NULL
, items
, &count
);
1253 ok(hr
== S_OK
, "ScriptItemize failed: 0x%08x\n", hr
);
1254 ok(count
== 3, "got %d expected 3\n", count
);
1257 hr
= ScriptItemize(test3
, lstrlenW(test3
), 5, NULL
, NULL
, items
, &count
);
1258 ok(hr
== S_OK
, "ScriptItemize failed: 0x%08x\n", hr
);
1259 ok(count
== 4, "got %d expected 4\n", count
);
1262 hr
= ScriptItemize(test4
, lstrlenW(test4
), 5, NULL
, NULL
, items
, &count
);
1263 ok(hr
== S_OK
, "ScriptItemize failed: 0x%08x\n", hr
);
1264 ok(count
== 4, "got %d expected 4\n", count
);
1267 hr
= ScriptItemize(test5
, lstrlenW(test5
), 5, NULL
, NULL
, items
, &count
);
1268 ok(hr
== S_OK
, "ScriptItemize failed: 0x%08x\n", hr
);
1269 ok(count
== 4, "got %d expected 4\n", count
);
1279 unsigned short pwOutGlyphs
[256];
1281 /* We need a valid HDC to drive a lot of Script functions which requires the following *
1282 * to set up for the tests. */
1283 hwnd
= CreateWindowExA(0, "static", "", WS_POPUP
, 0,0,100,100,
1286 ShowWindow(hwnd
, SW_SHOW
);
1289 hdc
= GetDC(hwnd
); /* We now have a hdc */
1290 ok( hdc
!= NULL
, "HDC failed to be created %p\n", hdc
);
1292 memset(&lf
, 0, sizeof(LOGFONTA
));
1293 lstrcpyA(lf
.lfFaceName
, "Tahoma");
1298 hfont
= SelectObject(hdc
, CreateFontIndirectA(&lf
));
1300 test_ScriptItemIzeShapePlace(hdc
,pwOutGlyphs
);
1301 test_ScriptGetCMap(hdc
, pwOutGlyphs
);
1302 test_ScriptCacheGetHeight(hdc
);
1303 test_ScriptGetGlyphABCWidth(hdc
);
1304 test_ScriptShape(hdc
);
1306 test_ScriptGetFontProperties(hdc
);
1307 test_ScriptTextOut(hdc
);
1308 test_ScriptTextOut2(hdc
);
1310 test_ScriptString(hdc
);
1311 test_ScriptStringXtoCP_CPtoX(hdc
);
1313 test_ScriptLayout();
1314 test_digit_substitution();
1315 test_ScriptGetProperties();
1319 ReleaseDC(hwnd
, hdc
);
1320 DestroyWindow(hwnd
);