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
);
70 ok(broken(hr
== S_OK
) ||
71 hr
== E_INVALIDARG
|| /* Vista, W2K8 */
72 hr
== E_FAIL
, /* WIN7 */
73 "ScriptShape should return E_FAIL or E_INVALIDARG, not %08x\n", hr
);
74 ok(items
[0].a
.fNoGlyphIndex
== FALSE
, "fNoGlyphIndex TRUE\n");
76 hr
= ScriptShape(hdc
, &sc
, test1
, 4, 4, &items
[0].a
, glyphs
, logclust
, attrs
, &nb
);
77 ok(!hr
, "ScriptShape should return S_OK not %08x\n", hr
);
78 ok(items
[0].a
.fNoGlyphIndex
== FALSE
, "fNoGlyphIndex TRUE\n");
80 hr
= ScriptShape(NULL
, &sc
, test1
, 4, 4, &items
[0].a
, glyphs
, logclust
, attrs
, &nb
);
81 ok(!hr
, "ScriptShape should return S_OK not %08x\n", hr
);
83 hr
= ScriptPlace(hdc
, &sc
, glyphs
, 4, NULL
, &items
[0].a
, widths
, NULL
, NULL
);
84 ok(hr
== E_INVALIDARG
, "ScriptPlace should return E_INVALIDARG not %08x\n", hr
);
86 hr
= ScriptPlace(NULL
, &sc
, glyphs
, 4, attrs
, &items
[0].a
, widths
, NULL
, NULL
);
87 ok(broken(hr
== E_PENDING
) ||
88 hr
== E_INVALIDARG
|| /* Vista, W2K8 */
89 hr
== E_FAIL
, /* WIN7 */
90 "ScriptPlace should return E_FAIL or E_INVALIDARG, not %08x\n", hr
);
92 hr
= ScriptPlace(NULL
, &sc
, glyphs
, 4, attrs
, &items
[0].a
, widths
, offset
, NULL
);
93 ok(hr
== E_PENDING
, "ScriptPlace should return E_PENDING not %08x\n", hr
);
95 hr
= ScriptPlace(NULL
, &sc
, glyphs
, 4, attrs
, &items
[0].a
, widths
, NULL
, abc
);
96 ok(broken(hr
== E_PENDING
) ||
97 hr
== E_INVALIDARG
|| /* Vista, W2K8 */
98 hr
== E_FAIL
, /* WIN7 */
99 "ScriptPlace should return E_FAIL or E_INVALIDARG, not %08x\n", hr
);
101 hr
= ScriptPlace(hdc
, &sc
, glyphs
, 4, attrs
, &items
[0].a
, widths
, offset
, NULL
);
102 ok(!hr
, "ScriptPlace should return S_OK not %08x\n", hr
);
103 ok(items
[0].a
.fNoGlyphIndex
== FALSE
, "fNoGlyphIndex TRUE\n");
105 ret
= ExtTextOutW(hdc
, 1, 1, 0, NULL
, glyphs
, 4, widths
);
106 ok(ret
, "ExtTextOutW should return TRUE\n");
108 ScriptFreeCache(&sc
);
111 static void test_ScriptItemIzeShapePlace(HDC hdc
, unsigned short pwOutGlyphs
[256])
115 const SCRIPT_PROPERTIES
**ppSp
;
119 SCRIPT_ITEM pItem
[255];
121 WCHAR TestItem1
[] = {'T', 'e', 's', 't', 'a', 0};
122 WCHAR TestItem2
[] = {'T', 'e', 's', 't', 'b', 0};
123 WCHAR TestItem3
[] = {'T', 'e', 's', 't', 'c',' ','1','2','3',' ',' ','e','n','d',0};
124 WCHAR TestItem4
[] = {'T', 'e', 's', 't', 'c',' ',0x0684,0x0694,0x06a4,' ',' ','e','n','d',0};
125 WCHAR TestItem5
[] = {0x0684,'T','e','s','t','c',' ',0x0684,0x0694,0x06a4,' ',' ','e','n','d',0};
130 unsigned short pwOutGlyphs1
[256];
131 unsigned short pwOutGlyphs2
[256];
132 unsigned short pwLogClust
[256];
133 SCRIPT_VISATTR psva
[256];
136 GOFFSET pGoffset
[256];
140 /* Start testing usp10 functions */
141 /* This test determines that the pointer returned by ScriptGetProperties is valid
142 * by checking a known value in the table */
143 hr
= ScriptGetProperties(&ppSp
, &iMaxProps
);
144 trace("number of script properties %d\n", iMaxProps
);
145 ok (iMaxProps
> 0, "Number of scripts returned should not be 0\n");
147 ok( ppSp
[5]->langid
== 9, "Langid[5] not = to 9\n"); /* Check a known value to ensure */
151 /* This set of tests are to check that the various edits in ScriptIemize work */
152 cInChars
= 5; /* Length of test without NULL */
153 cMaxItems
= 1; /* Check threshold value */
154 hr
= ScriptItemize(TestItem1
, cInChars
, cMaxItems
, NULL
, NULL
, pItem
, &pcItems
);
155 ok (hr
== E_INVALIDARG
, "ScriptItemize should return E_INVALIDARG if cMaxItems < 2. Was %d\n",
159 hr
= ScriptItemize(NULL
, cInChars
, cMaxItems
, NULL
, NULL
, pItem
, &pcItems
);
160 ok (hr
== E_INVALIDARG
, "ScriptItemize should return E_INVALIDARG if pwcInChars is NULL\n");
164 hr
= ScriptItemize(TestItem1
, 0, cMaxItems
, NULL
, NULL
, pItem
, &pcItems
);
165 ok (hr
== E_INVALIDARG
, "ScriptItemize should return E_INVALIDARG if cInChars is 0\n");
169 hr
= ScriptItemize(TestItem1
, cInChars
, cMaxItems
, NULL
, NULL
, NULL
, &pcItems
);
170 ok (hr
== E_INVALIDARG
, "ScriptItemize should return E_INVALIDARG if pItems is NULL\n");
172 /* This is a valid test that will cause parsing to take place */
175 hr
= ScriptItemize(TestItem1
, cInChars
, cMaxItems
, NULL
, NULL
, pItem
, &pcItems
);
176 ok (hr
== 0, "ScriptItemize should return 0, returned %08x\n", hr
);
177 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
179 ok (pcItems
> 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
181 ok (pItem
[0].iCharPos
== 0 && pItem
[1].iCharPos
== cInChars
,
182 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
183 pItem
[0].iCharPos
, cInChars
, pItem
[1].iCharPos
);
185 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
186 * ie. ScriptItemize has succeeded and that pItem has been set */
190 psc
= NULL
; /* must be null on first call */
192 cMaxGlyphs
= cInChars
;
193 hr
= ScriptShape(NULL
, &psc
, TestItem1
, cChars
,
194 cMaxGlyphs
, &pItem
[0].a
,
195 pwOutGlyphs1
, pwLogClust
, psva
, &pcGlyphs
);
196 ok (hr
== E_PENDING
, "If psc is NULL (%08x) the E_PENDING should be returned\n", hr
);
198 hr
= ScriptShape(hdc
, &psc
, TestItem1
, cChars
,
199 cMaxGlyphs
, &pItem
[0].a
,
200 pwOutGlyphs1
, pwLogClust
, psva
, &pcGlyphs
);
201 ok (hr
== E_OUTOFMEMORY
, "If not enough output area cChars (%d) is > than CMaxGlyphs "
202 "(%d) but not E_OUTOFMEMORY\n",
205 hr
= ScriptShape(hdc
, &psc
, TestItem1
, cChars
,
206 cMaxGlyphs
, &pItem
[0].a
,
207 pwOutGlyphs1
, pwLogClust
, psva
, &pcGlyphs
);
208 ok (hr
== 0, "ScriptShape should return 0 not (%08x)\n", hr
);
209 ok (psc
!= NULL
, "psc should not be null and have SCRIPT_CACHE buffer address\n");
210 ok (pcGlyphs
== cChars
, "Chars in (%d) should equal Glyphs out (%d)\n", cChars
, pcGlyphs
);
212 hr
= ScriptPlace(hdc
, &psc
, pwOutGlyphs1
, pcGlyphs
, psva
, &pItem
[0].a
, piAdvance
,
214 ok (hr
== 0, "ScriptPlace should return 0 not (%08x)\n", hr
);
215 hr
= ScriptPlace(NULL
, &psc
, pwOutGlyphs1
, pcGlyphs
, psva
, &pItem
[0].a
, piAdvance
,
217 ok (hr
== 0, "ScriptPlace should return 0 not (%08x)\n", hr
);
218 for (cnt
=0; cnt
< pcGlyphs
; cnt
++)
219 pwOutGlyphs
[cnt
] = pwOutGlyphs1
[cnt
]; /* Send to next function */
222 /* This test will check to make sure that SCRIPT_CACHE is reused and that not translation *
223 * takes place if fNoGlyphIndex is set. */
227 hr
= ScriptItemize(TestItem2
, cInChars
, cMaxItems
, NULL
, NULL
, pItem
, &pcItems
);
228 ok (hr
== 0, "ScriptItemize should return 0, returned %08x\n", hr
);
229 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
231 ok (pItem
[0].iCharPos
== 0 && pItem
[1].iCharPos
== cInChars
,
232 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
233 pItem
[0].iCharPos
, cInChars
, pItem
[1].iCharPos
);
234 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue */
238 pItem
[0].a
.fNoGlyphIndex
= 1; /* say no translate */
239 hr
= ScriptShape(NULL
, &psc
, TestItem2
, cChars
,
240 cMaxGlyphs
, &pItem
[0].a
,
241 pwOutGlyphs2
, pwLogClust
, psva
, &pcGlyphs
);
242 ok (hr
!= E_PENDING
, "If psc should not be NULL (%08x) and the E_PENDING should be returned\n", hr
);
243 ok (hr
== 0, "ScriptShape should return 0 not (%08x)\n", hr
);
244 ok (psc
!= NULL
, "psc should not be null and have SCRIPT_CACHE buffer address\n");
245 ok (pcGlyphs
== cChars
, "Chars in (%d) should equal Glyphs out (%d)\n", cChars
, pcGlyphs
);
246 for (cnt
=0; cnt
< cChars
&& TestItem2
[cnt
] == pwOutGlyphs2
[cnt
]; cnt
++) {}
247 ok (cnt
== cChars
, "Translation to place when told not to. WCHAR %d - %04x != %04x\n",
248 cnt
, TestItem2
[cnt
], pwOutGlyphs2
[cnt
]);
250 hr
= ScriptPlace(hdc
, &psc
, pwOutGlyphs2
, pcGlyphs
, psva
, &pItem
[0].a
, piAdvance
,
252 ok (hr
== 0, "ScriptPlace should return 0 not (%08x)\n", hr
);
255 hr
= ScriptFreeCache( &psc
);
256 ok (!psc
, "psc is not null after ScriptFreeCache\n");
260 /* This is a valid test that will cause parsing to take place and create 3 script_items */
261 cInChars
= (sizeof(TestItem3
)/2)-1;
263 hr
= ScriptItemize(TestItem3
, cInChars
, cMaxItems
, NULL
, NULL
, pItem
, &pcItems
);
264 ok (hr
== 0, "ScriptItemize should return 0, returned %08x\n", hr
);
267 ok (pcItems
== 3, "The number of SCRIPT_ITEMS should be 3 not %d\n", pcItems
);
270 ok (pItem
[0].iCharPos
== 0 && pItem
[1].iCharPos
== 6,
271 "Start pos [0] not = 0 (%d) or end pos [1] not = %d\n",
272 pItem
[0].iCharPos
, pItem
[1].iCharPos
);
273 ok (pItem
[1].iCharPos
== 6 && pItem
[2].iCharPos
== 11,
274 "Start pos [1] not = 6 (%d) or end pos [2] not = 11 (%d)\n",
275 pItem
[1].iCharPos
, pItem
[2].iCharPos
);
276 ok (pItem
[2].iCharPos
== 11 && pItem
[3].iCharPos
== cInChars
,
277 "Start pos [2] not = 11 (%d) or end [3] pos not = 14 (%d), cInChars = %d\n",
278 pItem
[2].iCharPos
, pItem
[3].iCharPos
, cInChars
);
280 hr
= ScriptFreeCache( &psc
);
281 ok (!psc
, "psc is not null after ScriptFreeCache\n");
284 /* This is a valid test that will cause parsing to take place and create 3 script_items */
285 cInChars
= (sizeof(TestItem4
)/2)-1;
287 hr
= ScriptItemize(TestItem4
, cInChars
, cMaxItems
, NULL
, NULL
, pItem
, &pcItems
);
288 ok (hr
== 0, "ScriptItemize should return 0, returned %08x\n", hr
);
291 ok (pcItems
== 3, "The number of SCRIPT_ITEMS should be 3 not %d\n", pcItems
);
294 ok (pItem
[0].iCharPos
== 0 && pItem
[1].iCharPos
== 6,
295 "Start pos [0] not = 0 (%d) or end pos [1] not = %d\n",
296 pItem
[0].iCharPos
, pItem
[1].iCharPos
);
297 ok (pItem
[1].iCharPos
== 6 && pItem
[2].iCharPos
== 11,
298 "Start pos [1] not = 6 (%d) or end pos [2] not = 11 (%d)\n",
299 pItem
[1].iCharPos
, pItem
[2].iCharPos
);
300 ok (pItem
[2].iCharPos
== 11 && pItem
[3].iCharPos
== cInChars
,
301 "Start pos [2] not = 11 (%d) or end [3] pos not = 14 (%d), cInChars = %d\n",
302 pItem
[2].iCharPos
, pItem
[3].iCharPos
, cInChars
);
304 hr
= ScriptFreeCache( &psc
);
305 ok (!psc
, "psc is not null after ScriptFreeCache\n");
309 * This test is for when the first unicode character requires bidi support
311 cInChars
= (sizeof(TestItem5
)-1)/sizeof(WCHAR
);
312 hr
= ScriptItemize(TestItem5
, cInChars
, cMaxItems
, NULL
, NULL
, pItem
, &pcItems
);
313 ok (hr
== 0, "ScriptItemize should return 0, returned %08x\n", hr
);
314 ok (pcItems
== 4, "There should have been 4 items, found %d\n", pcItems
);
315 ok (pItem
[0].a
.s
.uBidiLevel
== 1, "The first character should have been bidi=1 not %d\n",
316 pItem
[0].a
.s
.uBidiLevel
);
319 static void test_ScriptGetCMap(HDC hdc
, unsigned short pwOutGlyphs
[256])
322 SCRIPT_CACHE psc
= NULL
;
325 unsigned short pwOutGlyphs3
[256];
326 WCHAR TestItem1
[] = {'T', 'e', 's', 't', 'a', 0};
330 /* Check to make sure that SCRIPT_CACHE gets allocated ok */
332 cInChars
= cChars
= 5;
333 /* Some sanity checks for ScriptGetCMap */
335 hr
= ScriptGetCMap(NULL
, NULL
, NULL
, 0, 0, NULL
);
336 ok( hr
== E_INVALIDARG
, "(NULL,NULL,NULL,0,0,NULL), "
337 "expected E_INVALIDARG, got %08x\n", hr
);
339 hr
= ScriptGetCMap(NULL
, NULL
, TestItem1
, cInChars
, dwFlags
, pwOutGlyphs3
);
340 ok( hr
== E_INVALIDARG
, "(NULL,NULL,TestItem1, cInChars, dwFlags, pwOutGlyphs3), "
341 "expected E_INVALIDARG, got %08x\n", hr
);
343 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
345 hr
= ScriptGetCMap(NULL
, &psc
, TestItem1
, cInChars
, 0, pwOutGlyphs3
);
346 ok( hr
== E_PENDING
, "(NULL,&psc,NULL,0,0,NULL), expected E_PENDING, "
348 ok( psc
== NULL
, "Expected psc to be NULL, got %p\n", psc
);
350 /* Set psc to NULL but add hdc, to be able to check if a pointer is returned in psc */
352 hr
= ScriptGetCMap(hdc
, &psc
, TestItem1
, cInChars
, 0, pwOutGlyphs3
);
353 ok( hr
== S_OK
, "ScriptGetCMap(NULL,&psc,NULL,0,0,NULL), expected S_OK, "
355 ok( psc
!= NULL
, "ScritpGetCMap expected psc to be not NULL\n");
356 ScriptFreeCache( &psc
);
358 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
360 hr
= ScriptGetCMap(NULL
, &psc
, TestItem1
, cInChars
, dwFlags
, pwOutGlyphs3
);
361 ok( hr
== E_PENDING
, "(NULL,&psc,), expected E_PENDING, got %08x\n", hr
);
362 ok( psc
== NULL
, "Expected psc to be NULL, got %p\n", psc
);
363 /* Check to see if the results are the same as those returned by ScriptShape */
364 hr
= ScriptGetCMap(hdc
, &psc
, TestItem1
, cInChars
, dwFlags
, pwOutGlyphs3
);
365 ok (hr
== 0, "ScriptGetCMap should return 0 not (%08x)\n", hr
);
366 ok (psc
!= NULL
, "psc should not be null and have SCRIPT_CACHE buffer address\n");
367 for (cnt
=0; cnt
< cChars
&& pwOutGlyphs
[cnt
] == pwOutGlyphs3
[cnt
]; cnt
++) {}
368 ok (cnt
== cInChars
, "Translation not correct. WCHAR %d - %04x != %04x\n",
369 cnt
, pwOutGlyphs
[cnt
], pwOutGlyphs3
[cnt
]);
371 hr
= ScriptFreeCache( &psc
);
372 ok (!psc
, "psc is not null after ScriptFreeCache\n");
376 static void test_ScriptGetFontProperties(HDC hdc
)
379 SCRIPT_CACHE psc
,old_psc
;
380 SCRIPT_FONTPROPERTIES sfp
;
382 /* Some sanity checks for ScriptGetFontProperties */
384 hr
= ScriptGetFontProperties(NULL
,NULL
,NULL
);
385 ok( hr
== E_INVALIDARG
, "(NULL,NULL,NULL), expected E_INVALIDARG, got %08x\n", hr
);
387 hr
= ScriptGetFontProperties(NULL
,NULL
,&sfp
);
388 ok( hr
== E_INVALIDARG
, "(NULL,NULL,&sfp), expected E_INVALIDARG, got %08x\n", hr
);
390 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
392 hr
= ScriptGetFontProperties(NULL
,&psc
,NULL
);
393 ok( hr
== E_INVALIDARG
, "(NULL,&psc,NULL), expected E_INVALIDARG, got %08x\n", hr
);
394 ok( psc
== NULL
, "Expected psc to be NULL, got %p\n", psc
);
396 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
398 hr
= ScriptGetFontProperties(NULL
,&psc
,&sfp
);
399 ok( hr
== E_PENDING
, "(NULL,&psc,&sfp), expected E_PENDING, got %08x\n", hr
);
400 ok( psc
== NULL
, "Expected psc to be NULL, got %p\n", psc
);
402 hr
= ScriptGetFontProperties(hdc
,NULL
,NULL
);
403 ok( hr
== E_INVALIDARG
, "(hdc,NULL,NULL), expected E_INVALIDARG, got %08x\n", hr
);
405 hr
= ScriptGetFontProperties(hdc
,NULL
,&sfp
);
406 ok( hr
== E_INVALIDARG
, "(hdc,NULL,&sfp), expected E_INVALIDARG, got %08x\n", hr
);
408 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
410 hr
= ScriptGetFontProperties(hdc
,&psc
,NULL
);
411 ok( hr
== E_INVALIDARG
, "(hdc,&psc,NULL), expected E_INVALIDARG, got %08x\n", hr
);
412 ok( psc
== NULL
, "Expected psc to be NULL, got %p\n", psc
);
414 /* Pass an invalid sfp */
416 sfp
.cBytes
= sizeof(SCRIPT_FONTPROPERTIES
) - 1;
417 hr
= ScriptGetFontProperties(hdc
,&psc
,&sfp
);
418 ok( hr
== E_INVALIDARG
, "(hdc,&psc,&sfp) invalid, expected E_INVALIDARG, got %08x\n", hr
);
419 ok( psc
!= NULL
, "Expected a pointer in psc, got NULL\n");
420 ScriptFreeCache(&psc
);
421 ok( psc
== NULL
, "Expected psc to be NULL, got %p\n", psc
);
423 /* Give it the correct cBytes, we don't care about what's coming back */
424 sfp
.cBytes
= sizeof(SCRIPT_FONTPROPERTIES
);
426 hr
= ScriptGetFontProperties(hdc
,&psc
,&sfp
);
427 ok( hr
== S_OK
, "(hdc,&psc,&sfp) partly initialized, expected S_OK, got %08x\n", hr
);
428 ok( psc
!= NULL
, "Expected a pointer in psc, got NULL\n");
430 /* Save the psc pointer */
432 /* Now a NULL hdc again */
433 hr
= ScriptGetFontProperties(NULL
,&psc
,&sfp
);
434 ok( hr
== S_OK
, "(NULL,&psc,&sfp), expected S_OK, got %08x\n", hr
);
435 ok( psc
== old_psc
, "Expected psc not to be changed, was %p is now %p\n", old_psc
, psc
);
436 ScriptFreeCache(&psc
);
437 ok( psc
== NULL
, "Expected psc to be NULL, got %p\n", psc
);
440 static void test_ScriptTextOut(HDC hdc
)
446 SCRIPT_ITEM pItem
[255];
448 WCHAR TestItem1
[] = {'T', 'e', 's', 't', 'a', 0};
453 unsigned short pwOutGlyphs1
[256];
454 WORD pwLogClust
[256];
455 SCRIPT_VISATTR psva
[256];
458 GOFFSET pGoffset
[256];
463 BOOL fTrailing
= FALSE
;
464 SCRIPT_LOGATTR
*psla
;
465 SCRIPT_LOGATTR sla
[256];
467 /* This is a valid test that will cause parsing to take place */
470 hr
= ScriptItemize(TestItem1
, cInChars
, cMaxItems
, NULL
, NULL
, pItem
, &pcItems
);
471 ok (hr
== 0, "ScriptItemize should return 0, returned %08x\n", hr
);
472 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
474 ok (pcItems
> 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
476 ok (pItem
[0].iCharPos
== 0 && pItem
[1].iCharPos
== cInChars
,
477 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
478 pItem
[0].iCharPos
, cInChars
, pItem
[1].iCharPos
);
480 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
481 * ie. ScriptItemize has succeeded and that pItem has been set */
485 psc
= NULL
; /* must be null on first call */
487 cMaxGlyphs
= cInChars
;
489 hr
= ScriptShape(hdc
, &psc
, TestItem1
, cChars
,
490 cMaxGlyphs
, &pItem
[0].a
,
491 pwOutGlyphs1
, pwLogClust
, psva
, &pcGlyphs
);
492 ok (hr
== 0, "ScriptShape should return 0 not (%08x)\n", hr
);
493 ok (psc
!= NULL
, "psc should not be null and have SCRIPT_CACHE buffer address\n");
494 ok (pcGlyphs
== cChars
, "Chars in (%d) should equal Glyphs out (%d)\n", cChars
, pcGlyphs
);
496 /* Note hdc is needed as glyph info is not yet in psc */
497 hr
= ScriptPlace(hdc
, &psc
, pwOutGlyphs1
, pcGlyphs
, psva
, &pItem
[0].a
, piAdvance
,
499 ok (hr
== 0, "Should return 0 not (%08x)\n", hr
);
500 ScriptFreeCache(&psc
); /* Get rid of psc for next test set */
501 ok( psc
== NULL
, "Expected psc to be NULL, got %p\n", psc
);
503 hr
= ScriptTextOut(NULL
, NULL
, 0, 0, 0, NULL
, NULL
, NULL
, 0, NULL
, 0, NULL
, NULL
, NULL
);
504 ok (hr
== E_INVALIDARG
, "Should return 0 not (%08x)\n", hr
);
506 hr
= ScriptTextOut(NULL
, NULL
, 0, 0, 0, NULL
, &pItem
[0].a
, NULL
, 0, pwOutGlyphs1
, pcGlyphs
,
507 piAdvance
, NULL
, pGoffset
);
508 ok( hr
== E_INVALIDARG
, "(NULL,NULL,TestItem1, cInChars, dwFlags, pwOutGlyphs3), "
509 "expected E_INVALIDARG, got %08x\n", hr
);
511 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
513 hr
= ScriptTextOut(NULL
, &psc
, 0, 0, 0, NULL
, NULL
, NULL
, 0, NULL
, 0,
515 ok( hr
== E_INVALIDARG
, "(NULL,&psc,NULL,0,0,0,NULL,), expected E_INVALIDARG, "
517 ok( psc
== NULL
, "Expected psc to be NULL, got %p\n", psc
);
519 /* hdc is required for this one rather than the usual optional */
521 hr
= ScriptTextOut(NULL
, &psc
, 0, 0, 0, NULL
, &pItem
[0].a
, NULL
, 0, pwOutGlyphs1
, pcGlyphs
,
522 piAdvance
, NULL
, pGoffset
);
523 ok( hr
== E_INVALIDARG
, "(NULL,&psc,), expected E_INVALIDARG, got %08x\n", hr
);
524 ok( psc
== NULL
, "Expected psc to be NULL, got %p\n", psc
);
526 /* Set that it returns 0 status */
527 hr
= ScriptTextOut(hdc
, &psc
, 0, 0, 0, NULL
, &pItem
[0].a
, NULL
, 0, pwOutGlyphs1
, pcGlyphs
,
528 piAdvance
, NULL
, pGoffset
);
529 ok (hr
== 0, "ScriptTextOut should return 0 not (%08x)\n", hr
);
531 /* Test Rect Rgn is acceptable */
536 hr
= ScriptTextOut(hdc
, &psc
, 0, 0, 0, &rect
, &pItem
[0].a
, NULL
, 0, pwOutGlyphs1
, pcGlyphs
,
537 piAdvance
, NULL
, pGoffset
);
538 ok (hr
== 0, "ScriptTextOut should return 0 not (%08x)\n", hr
);
541 hr
= ScriptCPtoX(iCP
, fTrailing
, cChars
, pcGlyphs
, (const WORD
*) &pwLogClust
,
542 (const SCRIPT_VISATTR
*) &psva
, (const int *)&piAdvance
, &pItem
[0].a
, &piX
);
543 ok(hr
== S_OK
, "ScriptCPtoX Stub should return S_OK not %08x\n", hr
);
545 psla
= (SCRIPT_LOGATTR
*)&sla
;
546 hr
= ScriptBreak(TestItem1
, cChars
, &pItem
[0].a
, psla
);
547 ok(hr
== S_OK
, "ScriptBreak Stub should return S_OK not %08x\n", hr
);
549 /* Clean up and go */
550 ScriptFreeCache(&psc
);
551 ok( psc
== NULL
, "Expected psc to be NULL, got %p\n", psc
);
556 static void test_ScriptTextOut2(HDC hdc
)
558 /* Intent is to validate that the HDC passed into ScriptTextOut is
559 * used instead of the (possibly) invalid cached one
566 SCRIPT_ITEM pItem
[255];
568 WCHAR TestItem1
[] = {'T', 'e', 's', 't', 'a', 0};
573 unsigned short pwOutGlyphs1
[256];
574 WORD pwLogClust
[256];
575 SCRIPT_VISATTR psva
[256];
578 GOFFSET pGoffset
[256];
581 /* Create an extra DC that will be used until the ScriptTextOut */
582 hdc1
= CreateCompatibleDC(hdc
);
583 ok (hdc1
!= 0, "CreateCompatibleDC failed to create a DC\n");
584 hdc2
= CreateCompatibleDC(hdc
);
585 ok (hdc2
!= 0, "CreateCompatibleDC failed to create a DC\n");
587 /* This is a valid test that will cause parsing to take place */
590 hr
= ScriptItemize(TestItem1
, cInChars
, cMaxItems
, NULL
, NULL
, pItem
, &pcItems
);
591 ok (hr
== 0, "ScriptItemize should return 0, returned %08x\n", hr
);
592 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
594 ok (pcItems
> 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
596 ok (pItem
[0].iCharPos
== 0 && pItem
[1].iCharPos
== cInChars
,
597 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
598 pItem
[0].iCharPos
, cInChars
, pItem
[1].iCharPos
);
600 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
601 * ie. ScriptItemize has succeeded and that pItem has been set */
605 psc
= NULL
; /* must be null on first call */
607 cMaxGlyphs
= cInChars
;
609 hr
= ScriptShape(hdc2
, &psc
, TestItem1
, cChars
,
610 cMaxGlyphs
, &pItem
[0].a
,
611 pwOutGlyphs1
, pwLogClust
, psva
, &pcGlyphs
);
612 ok (hr
== 0, "ScriptShape should return 0 not (%08x)\n", hr
);
613 ok (psc
!= NULL
, "psc should not be null and have SCRIPT_CACHE buffer address\n");
614 ok (pcGlyphs
== cChars
, "Chars in (%d) should equal Glyphs out (%d)\n", cChars
, pcGlyphs
);
616 /* Note hdc is needed as glyph info is not yet in psc */
617 hr
= ScriptPlace(hdc2
, &psc
, pwOutGlyphs1
, pcGlyphs
, psva
, &pItem
[0].a
, piAdvance
,
619 ok (hr
== 0, "Should return 0 not (%08x)\n", hr
);
621 /* key part!!! cached dc is being deleted */
623 ok(hr
== 1, "DeleteDC should return 1 not %08x\n", hr
);
625 /* At this point the cached hdc (hdc2) has been destroyed,
626 * however, we are passing in a *real* hdc (the original hdc).
627 * The text should be written to that DC
629 hr
= ScriptTextOut(hdc1
, &psc
, 0, 0, 0, NULL
, &pItem
[0].a
, NULL
, 0, pwOutGlyphs1
, pcGlyphs
,
630 piAdvance
, NULL
, pGoffset
);
631 ok (hr
== 0, "ScriptTextOut should return 0 not (%08x)\n", hr
);
632 ok (psc
!= NULL
, "psc should not be null and have SCRIPT_CACHE buffer address\n");
636 /* Clean up and go */
637 ScriptFreeCache(&psc
);
638 ok( psc
== NULL
, "Expected psc to be NULL, got %p\n", psc
);
643 static void test_ScriptXtoX(void)
644 /****************************************************************************************
645 * This routine tests the ScriptXtoCP and ScriptCPtoX functions using static variables *
646 ****************************************************************************************/
648 static const WCHAR test
[] = {'t', 'e', 's', 't',0};
649 SCRIPT_ITEM items
[2];
653 WORD pwLogClust
[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
654 SCRIPT_VISATTR psva
[10];
655 int piAdvance
[10] = {200, 190, 210, 180, 170, 204, 189, 195, 212, 203};
661 hr
= ScriptItemize(test
, lstrlenW(test
), sizeof(items
)/sizeof(items
[0]), NULL
, NULL
, items
, NULL
);
662 ok(!hr
, "ScriptItemize should return S_OK not %08x\n", hr
);
667 hr
= ScriptXtoCP(iX
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
, &items
[0].a
, &piCP
, &piTrailing
);
668 ok(hr
== S_OK
, "ScriptXtoCP should return S_OK not %08x\n", hr
);
670 ok(piCP
== -1, "Negative iX should return piCP=-1 not %d\n", piCP
);
672 ok(piCP
== 10, "Negative iX should return piCP=10 not %d\n", piCP
);
677 hr
= ScriptXtoCP(iX
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
, &items
[0].a
, &piCP
, &piTrailing
);
678 ok(hr
== S_OK
, "ScriptXtoCP should return S_OK not %08x\n", hr
);
679 if (piTrailing
) /* win2k3 */
680 ok(piCP
== -1, "Negative iX should return piCP=-1 not %d\n", piCP
);
682 ok(piCP
== 10, "Negative iX should return piCP=10 not %d\n", piCP
);
687 hr
= ScriptXtoCP(iX
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
, &items
[0].a
, &piCP
, &piTrailing
);
688 ok(hr
== S_OK
, "ScriptXtoCP should return S_OK not %08x\n", hr
);
690 piCP
== -1, /* win2k3 */
691 "iX=%d should return piCP=3 or piCP=-1 not %d\n", iX
, piCP
);
692 ok(piTrailing
== 1, "iX=%d should return piTrailing=1 not %d\n", iX
, piTrailing
);
697 hr
= ScriptXtoCP(iX
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
, &items
[0].a
, &piCP
, &piTrailing
);
698 ok(hr
== S_OK
, "ScriptXtoCP should return S_OK not %08x\n", hr
);
700 piCP
== -1, /* win2k3 */
701 "iX=%d should return piCP=3 or piCP=-1 not %d\n", iX
, piCP
);
702 ok(piTrailing
== 1, "iX=%d should return piTrailing=1 not %d\n", iX
, piTrailing
);
707 hr
= ScriptXtoCP(iX
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
, &items
[0].a
, &piCP
, &piTrailing
);
708 ok(hr
== S_OK
, "ScriptXtoCP should return S_OK not %08x\n", hr
);
710 piCP
== -1, /* win2k3 */
711 "iX=%d should return piCP=4 or piCP=-1 not %d\n", iX
, piCP
);
716 hr
= ScriptXtoCP(iX
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
, &items
[0].a
, &piCP
, &piTrailing
);
717 ok(hr
== S_OK
, "ScriptXtoCP should return S_OK not %08x\n", hr
);
719 piCP
== 10, /* win2k3 */
720 "iX=%d should return piCP=0 piCP=10 not %d\n", iX
, piCP
);
725 hr
= ScriptXtoCP(iX
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
, &items
[0].a
, &piCP
, &piTrailing
);
726 ok(hr
== S_OK
, "ScriptXtoCP should return S_OK not %08x\n", hr
);
727 ok(piCP
== 0, "iX=%d should return piCP=0 not %d\n", iX
, piCP
);
732 hr
= ScriptXtoCP(iX
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
, &items
[0].a
, &piCP
, &piTrailing
);
733 ok(hr
== S_OK
, "ScriptXtoCP should return S_OK not %08x\n", hr
);
735 piCP
== 0, /* win2k3 */
736 "iX=%d should return piCP=1 or piCP=0 not %d\n", iX
, piCP
);
742 hr
= ScriptCPtoX(iCP
, fTrailing
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
, &items
[0].a
, &piX
);
743 ok(hr
== S_OK
, "ScriptCPtoX should return S_OK not %08x\n", hr
);
745 piX
== 100, /* win2k3 */
746 "iCP=%d should return piX=976 or piX=100 not %d\n", iCP
, piX
);
752 hr
= ScriptCPtoX(iCP
, fTrailing
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
, &items
[0].a
, &piX
);
753 ok(hr
== S_OK
, "ScriptCPtoX should return S_OK not %08x\n", hr
);
755 piX
== 80, /* win2k3 */
756 "iCP=%d should return piX=1171 or piX=80 not %d\n", iCP
, piX
);
762 hr
= ScriptCPtoX(iCP
, fTrailing
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
, &items
[0].a
, &piX
);
763 ok(hr
== S_OK
, "ScriptCPtoX should return S_OK not %08x\n", hr
);
765 piX
== 80, /* win2k3 */
766 "iCP=%d should return piX=1171 or piX=80 not %d\n", iCP
, piX
);
772 hr
= ScriptCPtoX(iCP
, fTrailing
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
, &items
[0].a
, &piX
);
773 ok(hr
== S_OK
, "ScriptCPtoX should return S_OK not %08x\n", hr
);
775 piX
== 0, /* win2k3 */
776 "iCP=%d should return piX=1953 or piX=0 not %d\n", iCP
, piX
);
782 hr
= ScriptCPtoX(iCP
, fTrailing
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
, &items
[0].a
, &piX
);
783 ok(hr
== S_OK
, "ScriptCPtoX should return S_OK not %08x\n", hr
);
785 piX
== 0, /* win2k3 */
786 "iCP=%d should return piX=1953 or piX=0 not %d\n", iCP
, piX
);
789 static void test_ScriptString(HDC hdc
)
791 /*******************************************************************************************
793 * This set of tests are for the string functions of uniscribe. The ScriptStringAnalyse
794 * function allocates memory pointed to by the SCRIPT_STRING_ANALYSIS ssa pointer. This
795 * memory if freed by ScriptStringFree. There needs to be a valid hdc for this as
796 * ScriptStringAnalyse calls ScriptSItemize, ScriptShape and ScriptPlace which require it.
801 WCHAR teststr
[] = {'T','e','s','t','1',' ','a','2','b','3', '\0'};
802 int len
= (sizeof(teststr
) / sizeof(WCHAR
)) - 1;
803 int Glyphs
= len
* 2 + 16;
805 DWORD Flags
= SSA_GLYPHS
;
807 SCRIPT_CONTROL Control
;
809 const int Dx
[5] = {10, 10, 10, 10, 10};
810 SCRIPT_TABDEF Tabdef
;
811 const BYTE InClass
= 0;
812 SCRIPT_STRING_ANALYSIS ssa
= NULL
;
817 const RECT rc
= {0, 50, 100, 100};
820 BOOL Disabled
= FALSE
;
826 Charset
= -1; /* this flag indicates unicode input */
827 /* Test without hdc to get E_PENDING */
828 hr
= ScriptStringAnalyse( NULL
, teststr
, len
, Glyphs
, Charset
, Flags
,
829 ReqWidth
, &Control
, &State
, Dx
, &Tabdef
,
831 ok(hr
== E_PENDING
, "ScriptStringAnalyse Stub should return E_PENDING not %08x\n", hr
);
833 /* test with hdc, this should be a valid test */
834 hr
= ScriptStringAnalyse( hdc
, teststr
, len
, Glyphs
, Charset
, Flags
,
835 ReqWidth
, &Control
, &State
, Dx
, &Tabdef
,
837 ok(hr
== S_OK
, "ScriptStringAnalyse should return S_OK not %08x\n", hr
);
838 ScriptStringFree(&ssa
);
840 /* test makes sure that a call with a valid pssa still works */
841 hr
= ScriptStringAnalyse( hdc
, teststr
, len
, Glyphs
, Charset
, Flags
,
842 ReqWidth
, &Control
, &State
, Dx
, &Tabdef
,
844 ok(hr
== S_OK
, "ScriptStringAnalyse should return S_OK not %08x\n", hr
);
845 ok(ssa
!= NULL
, "ScriptStringAnalyse pssa should not be NULL\n");
849 hr
= ScriptStringOut(ssa
, X
, Y
, Options
, &rc
, MinSel
, MaxSel
, Disabled
);
850 ok(hr
== S_OK
, "ScriptStringOut should return S_OK not %08x\n", hr
);
853 clip_len
= ScriptString_pcOutChars(ssa
);
854 ok(*clip_len
== len
, "ScriptString_pcOutChars failed, got %d, expected %d\n", *clip_len
, len
);
856 order
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, *clip_len
* sizeof(UINT
));
857 hr
= ScriptStringGetOrder(ssa
, order
);
858 ok(hr
== S_OK
, "ScriptStringGetOrder failed, got %08x, expected S_OK\n", hr
);
860 for (i
= 0; i
< *clip_len
; i
++) ok(order
[i
] == i
, "%d: got %d expected %d\n", i
, order
[i
], i
);
861 HeapFree(GetProcessHeap(), 0, order
);
863 hr
= ScriptStringFree(&ssa
);
864 ok(hr
== S_OK
, "ScriptStringFree should return S_OK not %08x\n", hr
);
867 static void test_ScriptStringXtoCP_CPtoX(HDC hdc
)
869 /*****************************************************************************************
871 * This test is for the ScriptStringXtoCP and ScriptStringXtoCP functions. Due to the
872 * nature of the fonts between Windows and Wine, the test is implemented by generating
873 * values using one one function then checking the output of the second. In this way
874 * the validity of the functions is established using Windows as a base and confirming
875 * similar behaviour in wine.
879 WCHAR teststr1
[] = {'T', 'e', 's', 't', 'e', '1', '2', ' ', 'a', '\0'};
880 void *String
= (WCHAR
*) &teststr1
; /* ScriptStringAnalysis needs void */
881 int String_len
= (sizeof(teststr1
)/sizeof(WCHAR
))-1;
882 int Glyphs
= String_len
* 2 + 16; /* size of buffer as recommended */
883 int Charset
= -1; /* unicode */
884 DWORD Flags
= SSA_GLYPHS
;
886 SCRIPT_CONTROL Control
;
888 SCRIPT_TABDEF Tabdef
;
889 const BYTE InClass
= 0;
890 SCRIPT_STRING_ANALYSIS ssa
= NULL
;
892 int Ch
; /* Character position in string */
894 int Cp
; /* Character position in string */
898 /* Test with hdc, this should be a valid test
899 * Here we generate an SCRIPT_STRING_ANALYSIS that will be used as input to the
900 * following character positions to X and X to character position functions.
902 hr
= ScriptStringAnalyse( hdc
, String
, String_len
, Glyphs
, Charset
, Flags
,
903 ReqWidth
, &Control
, &State
, NULL
, &Tabdef
,
906 hr
== E_INVALIDARG
, /* NT */
907 "ScriptStringAnalyse should return S_OK or E_INVALIDARG not %08x\n", hr
);
911 ok(ssa
!= NULL
, "ScriptStringAnalyse ssa should not be NULL\n");
914 * Loop to generate character positions to provide starting positions for the
915 * ScriptStringCPtoX and ScriptStringXtoCP functions
917 for (Cp
= 0; Cp
< String_len
; Cp
++)
919 /* The fTrailing flag is used to indicate whether the X being returned is at
920 * the beginning or the end of the character. What happens here is that if
921 * fTrailing indicates the end of the character, ie. FALSE, then ScriptStringXtoCP
922 * returns the beginning of the next character and iTrailing is FALSE. So for this
923 * loop iTrailing will be FALSE in both cases.
926 hr
= ScriptStringCPtoX(ssa
, Cp
, fTrailing
, &X
);
927 ok(hr
== S_OK
, "ScriptStringCPtoX should return S_OK not %08x\n", hr
);
928 hr
= ScriptStringXtoCP(ssa
, X
, &Ch
, &iTrailing
);
929 ok(hr
== S_OK
, "ScriptStringXtoCP should return S_OK not %08x\n", hr
);
930 ok(Cp
== Ch
, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp
, Ch
, X
);
931 ok(iTrailing
== FALSE
, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
934 hr
= ScriptStringCPtoX(ssa
, Cp
, fTrailing
, &X
);
935 ok(hr
== S_OK
, "ScriptStringCPtoX should return S_OK not %08x\n", hr
);
936 hr
= ScriptStringXtoCP(ssa
, X
, &Ch
, &iTrailing
);
937 ok(hr
== S_OK
, "ScriptStringXtoCP should return S_OK not %08x\n", hr
);
940 * Check that character position returned by ScriptStringXtoCP in Ch matches the
941 * one input to ScriptStringCPtoX. This means that the Cp to X position and back
944 ok(Cp
+ 1 == Ch
, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp
+ 1, Ch
, X
);
945 ok(iTrailing
== FALSE
, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
949 * This test is to check that if the X position is just inside the trailing edge of the
950 * character then iTrailing will indicate the trailing edge, ie. TRUE
954 hr
= ScriptStringCPtoX(ssa
, Cp
, fTrailing
, &X
);
955 ok(hr
== S_OK
, "ScriptStringCPtoX should return S_OK not %08x\n", hr
);
956 X
--; /* put X just inside the trailing edge */
957 hr
= ScriptStringXtoCP(ssa
, X
, &Ch
, &iTrailing
);
958 ok(hr
== S_OK
, "ScriptStringXtoCP should return S_OK not %08x\n", hr
);
959 ok(Cp
== Ch
, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp
, Ch
, X
);
960 ok(iTrailing
== TRUE
, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
964 * This test is to check that if the X position is just outside the trailing edge of the
965 * character then iTrailing will indicate the leading edge, ie. FALSE, and Ch will indicate
966 * the next character, ie. Cp + 1
970 hr
= ScriptStringCPtoX(ssa
, Cp
, fTrailing
, &X
);
971 ok(hr
== S_OK
, "ScriptStringCPtoX should return S_OK not %08x\n", hr
);
972 X
++; /* put X just outside the trailing edge */
973 hr
= ScriptStringXtoCP(ssa
, X
, &Ch
, &iTrailing
);
974 ok(hr
== S_OK
, "ScriptStringXtoCP should return S_OK not %08x\n", hr
);
975 ok(Cp
+ 1 == Ch
, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp
+ 1, Ch
, X
);
976 ok(iTrailing
== FALSE
, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
980 * This test is to check that if the X position is just outside the leading edge of the
981 * character then iTrailing will indicate the trailing edge, ie. TRUE, and Ch will indicate
982 * the next character down , ie. Cp - 1
986 hr
= ScriptStringCPtoX(ssa
, Cp
, fTrailing
, &X
);
987 ok(hr
== S_OK
, "ScriptStringCPtoX should return S_OK not %08x\n", hr
);
988 X
--; /* put X just outside the leading edge */
989 hr
= ScriptStringXtoCP(ssa
, X
, &Ch
, &iTrailing
);
990 ok(hr
== S_OK
, "ScriptStringXtoCP should return S_OK not %08x\n", hr
);
991 ok(Cp
- 1 == Ch
, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp
- 1, Ch
, X
);
992 ok(iTrailing
== TRUE
, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
996 * Cleanup the SSA for the next round of tests
998 hr
= ScriptStringFree(&ssa
);
999 ok(hr
== S_OK
, "ScriptStringFree should return S_OK not %08x\n", hr
);
1002 * Test to see that exceeding the number of chars returns E_INVALIDARG. First
1003 * generate an SSA for the subsequent tests.
1005 hr
= ScriptStringAnalyse( hdc
, String
, String_len
, Glyphs
, Charset
, Flags
,
1006 ReqWidth
, &Control
, &State
, NULL
, &Tabdef
,
1008 ok(hr
== S_OK
, "ScriptStringAnalyse should return S_OK not %08x\n", hr
);
1011 * When ScriptStringCPtoX is called with a character position Cp that exceeds the
1012 * string length, return E_INVALIDARG. This also invalidates the ssa so a
1013 * ScriptStringFree should also fail.
1016 Cp
= String_len
+ 1;
1017 hr
= ScriptStringCPtoX(ssa
, Cp
, fTrailing
, &X
);
1018 ok(hr
== E_INVALIDARG
, "ScriptStringCPtoX should return E_INVALIDARG not %08x\n", hr
);
1020 hr
= ScriptStringFree(&ssa
);
1022 * ScriptStringCPtoX should free ssa, hence ScriptStringFree should fail
1024 ok(hr
== E_INVALIDARG
||
1025 hr
== E_FAIL
, /* win2k3 */
1026 "ScriptStringFree should return E_INVALIDARG or E_FAIL not %08x\n", hr
);
1030 static void test_ScriptCacheGetHeight(HDC hdc
)
1033 SCRIPT_CACHE sc
= NULL
;
1036 hr
= ScriptCacheGetHeight(NULL
, NULL
, NULL
);
1037 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got 0x%08x\n", hr
);
1039 hr
= ScriptCacheGetHeight(NULL
, &sc
, NULL
);
1040 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got 0x%08x\n", hr
);
1042 hr
= ScriptCacheGetHeight(NULL
, &sc
, &height
);
1043 ok(hr
== E_PENDING
, "expected E_PENDING, got 0x%08x\n", hr
);
1047 hr
= ScriptCacheGetHeight(hdc
, &sc
, &height
);
1048 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
1049 ok(height
> 0, "expected height > 0\n");
1051 ScriptFreeCache(&sc
);
1054 static void test_ScriptGetGlyphABCWidth(HDC hdc
)
1057 SCRIPT_CACHE sc
= NULL
;
1060 hr
= ScriptGetGlyphABCWidth(NULL
, NULL
, 'a', NULL
);
1061 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got 0x%08x\n", hr
);
1063 hr
= ScriptGetGlyphABCWidth(NULL
, &sc
, 'a', NULL
);
1064 ok(broken(hr
== E_PENDING
) ||
1065 hr
== E_INVALIDARG
, /* WIN7 */
1066 "expected E_INVALIDARG, got 0x%08x\n", hr
);
1068 hr
= ScriptGetGlyphABCWidth(NULL
, &sc
, 'a', &abc
);
1069 ok(hr
== E_PENDING
, "expected E_PENDING, got 0x%08x\n", hr
);
1071 if (0) { /* crashes on WinXP */
1072 hr
= ScriptGetGlyphABCWidth(hdc
, &sc
, 'a', NULL
);
1073 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got 0x%08x\n", hr
);
1076 hr
= ScriptGetGlyphABCWidth(hdc
, &sc
, 'a', &abc
);
1077 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
1079 ScriptFreeCache(&sc
);
1082 static void test_ScriptLayout(void)
1085 static const BYTE levels
[][5] =
1092 static const int expect
[][5] =
1099 int i
, j
, vistolog
[sizeof(levels
[0])], logtovis
[sizeof(levels
[0])];
1101 hr
= ScriptLayout(sizeof(levels
[0]), NULL
, vistolog
, logtovis
);
1102 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got 0x%08x\n", hr
);
1104 hr
= ScriptLayout(sizeof(levels
[0]), levels
[0], NULL
, NULL
);
1105 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got 0x%08x\n", hr
);
1107 for (i
= 0; i
< sizeof(levels
)/sizeof(levels
[0]); i
++)
1109 hr
= ScriptLayout(sizeof(levels
[0]), levels
[i
], vistolog
, logtovis
);
1110 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
1112 for (j
= 0; j
< sizeof(levels
[i
]); j
++)
1114 ok(expect
[i
][j
] == vistolog
[j
],
1115 "failure: levels[%d][%d] = %d, vistolog[%d] = %d\n",
1116 i
, j
, levels
[i
][j
], j
, vistolog
[j
] );
1119 for (j
= 0; j
< sizeof(levels
[i
]); j
++)
1121 ok(expect
[i
][j
] == logtovis
[j
],
1122 "failure: levels[%d][%d] = %d, logtovis[%d] = %d\n",
1123 i
, j
, levels
[i
][j
], j
, logtovis
[j
] );
1128 static BOOL CALLBACK
enum_proc(LGRPID group
, LCID lcid
, LPSTR locale
, LONG_PTR lparam
)
1131 SCRIPT_DIGITSUBSTITUTE sds
;
1136 if (!IsValidLocale(lcid
, LCID_INSTALLED
)) return TRUE
;
1138 memset(&sds
, 0, sizeof(sds
));
1139 memset(&sc
, 0, sizeof(sc
));
1140 memset(&ss
, 0, sizeof(ss
));
1142 lcid_old
= GetThreadLocale();
1143 if (!SetThreadLocale(lcid
)) return TRUE
;
1145 hr
= ScriptRecordDigitSubstitution(lcid
, &sds
);
1146 ok(hr
== S_OK
, "ScriptRecordDigitSubstitution failed: 0x%08x\n", hr
);
1148 hr
= ScriptApplyDigitSubstitution(&sds
, &sc
, &ss
);
1149 ok(hr
== S_OK
, "ScriptApplyDigitSubstitution failed: 0x%08x\n", hr
);
1151 SetThreadLocale(lcid_old
);
1155 static void test_digit_substitution(void)
1159 static const LGRPID groups
[] =
1161 LGRPID_WESTERN_EUROPE
,
1162 LGRPID_CENTRAL_EUROPE
,
1169 LGRPID_TRADITIONAL_CHINESE
,
1170 LGRPID_SIMPLIFIED_CHINESE
,
1180 static BOOL (WINAPI
* pEnumLanguageGroupLocalesA
)(LANGGROUPLOCALE_ENUMPROC
,LGRPID
,DWORD
,LONG_PTR
);
1182 hKernel32
= GetModuleHandleA("kernel32.dll");
1183 pEnumLanguageGroupLocalesA
= (void*)GetProcAddress(hKernel32
, "EnumLanguageGroupLocalesA");
1185 if (!pEnumLanguageGroupLocalesA
)
1187 win_skip("EnumLanguageGroupLocalesA not available on this platform\n");
1191 for (i
= 0; i
< sizeof(groups
)/sizeof(groups
[0]); i
++)
1193 ret
= pEnumLanguageGroupLocalesA(enum_proc
, groups
[i
], 0, 0);
1194 if (!ret
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1196 win_skip("EnumLanguageGroupLocalesA not implemented on this platform\n");
1200 ok(ret
, "EnumLanguageGroupLocalesA failed unexpectedly: %u\n", GetLastError());
1204 static void test_ScriptGetProperties(void)
1206 const SCRIPT_PROPERTIES
**props
;
1210 hr
= ScriptGetProperties(NULL
, NULL
);
1211 ok(hr
== E_INVALIDARG
, "ScriptGetProperties succeeded\n");
1213 hr
= ScriptGetProperties(NULL
, &num
);
1214 ok(hr
== S_OK
, "ScriptGetProperties failed: 0x%08x\n", hr
);
1216 hr
= ScriptGetProperties(&props
, NULL
);
1217 ok(hr
== S_OK
, "ScriptGetProperties failed: 0x%08x\n", hr
);
1219 hr
= ScriptGetProperties(&props
, &num
);
1220 ok(hr
== S_OK
, "ScriptGetProperties failed: 0x%08x\n", hr
);
1223 static void test_ScriptBreak(void)
1225 static const WCHAR test
[] = {' ','\r','\n',0};
1226 SCRIPT_ITEM items
[4];
1230 hr
= ScriptItemize(test
, 3, 4, NULL
, NULL
, items
, NULL
);
1231 ok(!hr
, "ScriptItemize should return S_OK not %08x\n", hr
);
1233 memset(&la
, 0, sizeof(la
));
1234 hr
= ScriptBreak(test
, 1, &items
[0].a
, &la
);
1235 ok(!hr
, "ScriptBreak should return S_OK not %08x\n", hr
);
1237 ok(!la
.fSoftBreak
, "fSoftBreak set\n");
1238 ok(la
.fWhiteSpace
, "fWhiteSpace not set\n");
1239 ok(la
.fCharStop
, "fCharStop not set\n");
1240 ok(!la
.fWordStop
, "fWordStop set\n");
1241 ok(!la
.fInvalid
, "fInvalid set\n");
1242 ok(!la
.fReserved
, "fReserved set\n");
1244 memset(&la
, 0, sizeof(la
));
1245 hr
= ScriptBreak(test
+ 1, 1, &items
[1].a
, &la
);
1246 ok(!hr
, "ScriptBreak should return S_OK not %08x\n", hr
);
1248 ok(!la
.fSoftBreak
, "fSoftBreak set\n");
1249 ok(!la
.fWhiteSpace
, "fWhiteSpace set\n");
1250 ok(la
.fCharStop
, "fCharStop not set\n");
1251 ok(!la
.fWordStop
, "fWordStop set\n");
1252 ok(!la
.fInvalid
, "fInvalid set\n");
1253 ok(!la
.fReserved
, "fReserved set\n");
1255 memset(&la
, 0, sizeof(la
));
1256 hr
= ScriptBreak(test
+ 2, 1, &items
[2].a
, &la
);
1257 ok(!hr
, "ScriptBreak should return S_OK not %08x\n", hr
);
1259 ok(!la
.fSoftBreak
, "fSoftBreak set\n");
1260 ok(!la
.fWhiteSpace
, "fWhiteSpace set\n");
1261 ok(la
.fCharStop
, "fCharStop not set\n");
1262 ok(!la
.fWordStop
, "fWordStop set\n");
1263 ok(!la
.fInvalid
, "fInvalid set\n");
1264 ok(!la
.fReserved
, "fReserved set\n");
1267 static void test_newlines(void)
1269 static const WCHAR test1
[] = {'t','e','x','t','\r','t','e','x','t',0};
1270 static const WCHAR test2
[] = {'t','e','x','t','\n','t','e','x','t',0};
1271 static const WCHAR test3
[] = {'t','e','x','t','\r','\n','t','e','x','t',0};
1272 static const WCHAR test4
[] = {'t','e','x','t','\n','\r','t','e','x','t',0};
1273 static const WCHAR test5
[] = {'1','2','3','4','\n','\r','1','2','3','4',0};
1274 SCRIPT_ITEM items
[5];
1279 hr
= ScriptItemize(test1
, lstrlenW(test1
), 5, NULL
, NULL
, items
, &count
);
1280 ok(hr
== S_OK
, "ScriptItemize failed: 0x%08x\n", hr
);
1281 ok(count
== 3, "got %d expected 3\n", count
);
1284 hr
= ScriptItemize(test2
, lstrlenW(test2
), 5, NULL
, NULL
, items
, &count
);
1285 ok(hr
== S_OK
, "ScriptItemize failed: 0x%08x\n", hr
);
1286 ok(count
== 3, "got %d expected 3\n", count
);
1289 hr
= ScriptItemize(test3
, lstrlenW(test3
), 5, NULL
, NULL
, items
, &count
);
1290 ok(hr
== S_OK
, "ScriptItemize failed: 0x%08x\n", hr
);
1291 ok(count
== 4, "got %d expected 4\n", count
);
1294 hr
= ScriptItemize(test4
, lstrlenW(test4
), 5, NULL
, NULL
, items
, &count
);
1295 ok(hr
== S_OK
, "ScriptItemize failed: 0x%08x\n", hr
);
1296 ok(count
== 4, "got %d expected 4\n", count
);
1299 hr
= ScriptItemize(test5
, lstrlenW(test5
), 5, NULL
, NULL
, items
, &count
);
1300 ok(hr
== S_OK
, "ScriptItemize failed: 0x%08x\n", hr
);
1301 ok(count
== 4, "got %d expected 4\n", count
);
1311 unsigned short pwOutGlyphs
[256];
1313 /* We need a valid HDC to drive a lot of Script functions which requires the following *
1314 * to set up for the tests. */
1315 hwnd
= CreateWindowExA(0, "static", "", WS_POPUP
, 0,0,100,100,
1318 ShowWindow(hwnd
, SW_SHOW
);
1321 hdc
= GetDC(hwnd
); /* We now have a hdc */
1322 ok( hdc
!= NULL
, "HDC failed to be created %p\n", hdc
);
1324 memset(&lf
, 0, sizeof(LOGFONTA
));
1325 lstrcpyA(lf
.lfFaceName
, "Tahoma");
1330 hfont
= SelectObject(hdc
, CreateFontIndirectA(&lf
));
1332 test_ScriptItemIzeShapePlace(hdc
,pwOutGlyphs
);
1333 test_ScriptGetCMap(hdc
, pwOutGlyphs
);
1334 test_ScriptCacheGetHeight(hdc
);
1335 test_ScriptGetGlyphABCWidth(hdc
);
1336 test_ScriptShape(hdc
);
1338 test_ScriptGetFontProperties(hdc
);
1339 test_ScriptTextOut(hdc
);
1340 test_ScriptTextOut2(hdc
);
1342 test_ScriptString(hdc
);
1343 test_ScriptStringXtoCP_CPtoX(hdc
);
1345 test_ScriptLayout();
1346 test_digit_substitution();
1347 test_ScriptGetProperties();
1351 ReleaseDC(hwnd
, hdc
);
1352 DestroyWindow(hwnd
);