4 * Copyright 2006 Jeff Latimer
5 * Copyright 2006 Hans Leidekker
6 * Copyright 2010 CodeWeavers, Aric Stewart
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 * Uniscribe allows for processing of complex scripts such as joining
24 * and filtering characters and bi-directional text with custom line breaks.
30 #include <wine/test.h>
34 static void test_ScriptItemize( void )
36 static const WCHAR test1[] = {'t', 'e', 's', 't',0};
37 static const WCHAR test2[] = {'1','2','3','-','5','2',0x064a,0x064f,0x0633,0x0627,0x0648,0x0650,0x064a,'7','1','.',0};
38 static const WCHAR test3[] =
39 {0x0e04,0x0e27,0x0e32,0x0e21,0x0e1e,0x0e22,0x0e32,0x0e22,0x0e32, 0x0e21
40 ,0x0e2d,0x0e22,0x0e39,0x0e48,0x0e17,0x0e35,0x0e48,0x0e44,0x0e2b,0x0e19
41 ,0x0e04,0x0e27,0x0e32,0x0e21,0x0e2a, 0x0e33,0x0e40,0x0e23,0x0e47,0x0e08,
42 0x0e2d,0x0e22,0x0e39,0x0e48,0x0e17,0x0e35,0x0e48,0x0e19,0x0e31,0x0e48,0x0e19,0};
43 static const WCHAR test4[] = {'1','2','3','-','5','2',' ','i','s',' ','7','1','.',0};
44 static const WCHAR test5[] =
45 {0x0627,0x0644,0x0635,0x0651,0x0650,0x062d,0x0629,0x064f,' ',0x062a,0x064e,
46 0x0627,0x062c,0x064c,' ',0x0639,0x064e,0x0644,0x0649,' ',
47 0x0631,0x064f,0x0624,0x0648,0x0633,0x0650,' ',0x0627,0x0644
48 ,0x0623,0x0635,0x0650,0x062d,0x0651,0x064e,0x0627,0x0621,0x0650,0};
49 SCRIPT_ITEM items[10];
50 SCRIPT_CONTROL Control;
55 memset(&Control, 0, sizeof(Control));
56 memset(&State, 0, sizeof(State));
58 hr = ScriptItemize(NULL, 4, 10, &Control, &State, items, NULL);
59 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if pwcInChars is NULL\n");
61 hr = ScriptItemize(test1, 4, 10, &Control, &State, NULL, NULL);
62 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if pItems is NULL\n");
64 hr = ScriptItemize(test1, 4, 1, &Control, &State, items, NULL);
65 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if cMaxItems < 2.");
67 hr = ScriptItemize(test1, 0, 10, NULL, NULL, items, &nItems);
68 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if cInChars is 0\n");
70 hr = ScriptItemize(test1, 4, 10, NULL, NULL, items, &nItems);
71 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
72 ok(nItems == 1, "Wrong number of items\n");
73 ok(items[0].iCharPos == 0, "Wrong CharPos \n");
74 ok(items[0].a.fRTL == 0, "Wrong fRTL\n");
75 ok(items[0].a.fLayoutRTL == 0, "Wrong fLayoutRTL\n");
76 ok(items[0].a.s.uBidiLevel == 0, "Wrong BidiLevel\n");
79 hr = ScriptItemize(test1, 4, 10, &Control, &State, items, &nItems);
80 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
81 ok(nItems == 1, "Wrong number of items\n");
82 ok(items[0].iCharPos == 0, "Wrong CharPos \n");
83 ok(items[0].a.fRTL == 0, "Wrong fRTL\n");
84 ok(items[0].a.fLayoutRTL == 0, "Wrong fLayoutRTL\n");
85 ok(items[0].a.s.uBidiLevel == 0, "Wrong BidiLevel\n");
88 hr = ScriptItemize(test1, 4, 10, &Control, &State, items, &nItems);
89 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
90 ok(nItems == 1, "Wrong number of items\n");
91 ok(items[0].iCharPos == 0, "Wrong CharPos \n");
92 ok(items[0].a.fRTL == 0, "Wrong fRTL\n");
93 ok(items[0].a.fLayoutRTL == 0, "Wrong fLayoutRTL\n");
94 todo_wine ok(items[0].a.s.uBidiLevel == 2, "Wrong BidiLevel\n");
96 hr = ScriptItemize(test2, 16, 10, NULL, NULL, items, &nItems);
97 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
98 ok(nItems == 6, "Wrong number of items\n");
99 ok(items[0].iCharPos == 0, "Wrong CharPos \n");
100 ok(items[0].a.fRTL == 0, "Wrong fRTL\n");
101 ok(items[0].a.fLayoutRTL == 0, "Wrong fLayoutRTL\n");
102 ok(items[0].a.s.uBidiLevel == 0, "Wrong BidiLevel\n");
103 ok(items[1].iCharPos == 3, "Wrong CharPos \n");
104 ok(items[1].a.fRTL == 0, "Wrong fRTL\n");
105 ok(items[1].a.fLayoutRTL == 0, "Wrong fLayoutRTL\n");
106 ok(items[1].a.s.uBidiLevel == 0, "Wrong BidiLevel\n");
107 ok(items[2].iCharPos == 4, "Wrong CharPos \n");
108 ok(items[2].a.fRTL == 0, "Wrong fRTL\n");
109 ok(items[2].a.fLayoutRTL == 0, "Wrong fLayoutRTL\n");
110 ok(items[2].a.s.uBidiLevel == 0, "Wrong BidiLevel\n");
111 ok(items[3].iCharPos == 6, "Wrong CharPos \n");
112 ok(items[3].a.fRTL == 1, "Wrong fRTL\n");
113 ok(items[3].a.fLayoutRTL == 1, "Wrong fLayoutRTL\n");
114 ok(items[3].a.s.uBidiLevel == 1, "Wrong BidiLevel\n");
115 ok(items[4].iCharPos == 13, "Wrong CharPos \n");
116 ok(items[4].a.fRTL == 0, "Wrong fRTL\n");
117 ok(items[4].a.fLayoutRTL == 0, "Wrong fLayoutRTL\n");
118 ok(items[4].a.s.uBidiLevel == 0, "Wrong BidiLevel\n");
119 ok(items[5].iCharPos == 15, "Wrong CharPos \n");
120 ok(items[5].a.fRTL == 0, "Wrong fRTL\n");
121 ok(items[5].a.fLayoutRTL == 0, "Wrong fLayoutRTL\n");
122 ok(items[5].a.s.uBidiLevel == 0, "Wrong BidiLevel\n");
124 State.uBidiLevel = 0;
125 hr = ScriptItemize(test2, 16, 10, &Control, &State, items, &nItems);
126 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
127 ok(nItems == 4, "Wrong number of items\n");
128 ok(items[0].iCharPos == 0, "Wrong CharPos \n");
129 ok(items[0].a.fRTL == 0, "Wrong fRTL\n");
130 ok(items[0].a.fLayoutRTL == 0, "Wrong fLayoutRTL\n");
131 todo_wine ok(items[0].a.s.uBidiLevel == 2, "Wrong BidiLevel\n");
132 ok(items[1].iCharPos == 6, "Wrong CharPos \n");
133 ok(items[1].a.fRTL == 1, "Wrong fRTL\n");
134 ok(items[1].a.fLayoutRTL == 1, "Wrong fLayoutRTL\n");
135 ok(items[1].a.s.uBidiLevel == 1, "Wrong BidiLevel\n");
136 ok(items[2].iCharPos == 13, "Wrong CharPos \n");
137 ok(items[2].a.fRTL == 0, "Wrong fRTL\n");
138 todo_wine ok(items[2].a.fLayoutRTL == 1, "Wrong fLayoutRTL\n");
139 ok(items[2].a.s.uBidiLevel == 2, "Wrong BidiLevel\n");
140 ok(items[3].iCharPos == 15, "Wrong CharPos \n");
141 ok(items[3].a.fRTL == 0, "Wrong fRTL\n");
142 ok(items[3].a.fLayoutRTL == 0, "Wrong fLayoutRTL\n");
143 ok(items[3].a.s.uBidiLevel == 0, "Wrong BidiLevel\n");
145 State.uBidiLevel = 1;
146 hr = ScriptItemize(test2, 16, 10, &Control, &State, items, &nItems);
147 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
148 ok(nItems == 4, "Wrong number of items\n");
149 ok(items[0].iCharPos == 0, "Wrong CharPos \n");
150 ok(items[0].a.fRTL == 0, "Wrong fRTL\n");
151 todo_wine ok(items[0].a.fLayoutRTL == 1, "Wrong fLayoutRTL\n");
152 ok(items[0].a.s.uBidiLevel == 2, "Wrong BidiLevel\n");
153 ok(items[1].iCharPos == 6, "Wrong CharPos \n");
154 ok(items[1].a.fRTL == 1, "Wrong fRTL\n");
155 ok(items[1].a.fLayoutRTL == 1, "Wrong fLayoutRTL\n");
156 ok(items[1].a.s.uBidiLevel == 1, "Wrong BidiLevel\n");
157 ok(items[2].iCharPos == 13, "Wrong CharPos \n");
158 ok(items[2].a.fRTL == 0, "Wrong fRTL\n");
159 todo_wine ok(items[2].a.fLayoutRTL == 1, "Wrong fLayoutRTL\n");
160 ok(items[2].a.s.uBidiLevel == 2, "Wrong BidiLevel\n");
161 ok(items[3].iCharPos == 15, "Wrong CharPos \n");
162 ok(items[3].a.fRTL == 1, "Wrong fRTL\n");
163 ok(items[3].a.fLayoutRTL == 1, "Wrong fLayoutRTL\n");
164 ok(items[3].a.s.uBidiLevel == 1, "Wrong BidiLevel\n");
166 hr = ScriptItemize(test3, 41, 10, NULL, NULL, items, &nItems);
167 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
168 ok(nItems == 1, "Wrong number of items\n");
169 ok(items[0].iCharPos == 0, "Wrong CharPos \n");
170 ok(items[0].a.fRTL == 0, "Wrong fRTL\n");
171 ok(items[0].a.fLayoutRTL == 0, "Wrong fLayoutRTL\n");
172 ok(items[0].a.s.uBidiLevel == 0, "Wrong BidiLevel\n");
174 State.uBidiLevel = 0;
175 hr = ScriptItemize(test3, 41, 10, &Control, &State, items, &nItems);
176 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
177 ok(nItems == 1, "Wrong number of items\n");
178 ok(items[0].iCharPos == 0, "Wrong CharPos \n");
179 ok(items[0].a.fRTL == 0, "Wrong fRTL\n");
180 ok(items[0].a.fLayoutRTL == 0, "Wrong fLayoutRTL\n");
181 ok(items[0].a.s.uBidiLevel == 0, "Wrong BidiLevel\n");
183 State.uBidiLevel = 1;
184 hr = ScriptItemize(test3, 41, 10, &Control, &State, items, &nItems);
185 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
186 ok(nItems == 1, "Wrong number of items\n");
187 ok(items[0].iCharPos == 0, "Wrong CharPos \n");
188 ok(items[0].a.fRTL == 0, "Wrong fRTL\n");
189 ok(items[0].a.fLayoutRTL == 0, "Wrong fLayoutRTL\n");
190 todo_wine ok(items[0].a.s.uBidiLevel == 2, "Wrong BidiLevel\n");
192 hr = ScriptItemize(test4, 12, 10, NULL, NULL, items, &nItems);
193 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
194 ok(nItems == 5, "Wrong number of items\n");
195 ok(items[0].iCharPos == 0, "Wrong CharPos \n");
196 ok(items[0].a.fRTL == 0, "Wrong fRTL\n");
197 ok(items[0].a.fLayoutRTL == 0, "Wrong fLayoutRTL\n");
198 ok(items[0].a.s.uBidiLevel == 0, "Wrong BidiLevel\n");
199 ok(items[1].iCharPos == 3, "Wrong CharPos \n");
200 ok(items[1].a.fRTL == 0, "Wrong fRTL\n");
201 ok(items[1].a.fLayoutRTL == 0, "Wrong fLayoutRTL\n");
202 ok(items[1].a.s.uBidiLevel == 0, "Wrong BidiLevel\n");
203 ok(items[2].iCharPos == 4, "Wrong CharPos \n");
204 ok(items[2].a.fRTL == 0, "Wrong fRTL\n");
205 ok(items[2].a.fLayoutRTL == 0, "Wrong fLayoutRTL\n");
206 ok(items[2].a.s.uBidiLevel == 0, "Wrong BidiLevel\n");
207 ok(items[3].iCharPos == 7, "Wrong CharPos \n");
208 ok(items[3].a.fRTL == 0, "Wrong fRTL\n");
209 ok(items[3].a.fLayoutRTL == 0, "Wrong fLayoutRTL\n");
210 ok(items[3].a.s.uBidiLevel == 0, "Wrong BidiLevel\n");
211 ok(items[4].iCharPos == 10, "Wrong CharPos \n");
212 ok(items[4].a.fRTL == 0, "Wrong fRTL\n");
213 ok(items[4].a.fLayoutRTL == 0, "Wrong fLayoutRTL\n");
214 ok(items[4].a.s.uBidiLevel == 0, "Wrong BidiLevel\n");
216 State.uBidiLevel = 0;
217 hr = ScriptItemize(test4, 12, 10, &Control, &State, items, &nItems);
218 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
219 ok(nItems == 5, "Wrong number of items\n");
220 ok(items[0].iCharPos == 0, "Wrong CharPos \n");
221 ok(items[0].a.fRTL == 0, "Wrong fRTL\n");
222 ok(items[0].a.fLayoutRTL == 0, "Wrong fLayoutRTL\n");
223 ok(items[0].a.s.uBidiLevel == 0, "Wrong BidiLevel\n");
224 ok(items[1].iCharPos == 3, "Wrong CharPos \n");
225 ok(items[1].a.fRTL == 0, "Wrong fRTL\n");
226 ok(items[1].a.fLayoutRTL == 0, "Wrong fLayoutRTL\n");
227 ok(items[1].a.s.uBidiLevel == 0, "Wrong BidiLevel\n");
228 ok(items[2].iCharPos == 4, "Wrong CharPos \n");
229 ok(items[2].a.fRTL == 0, "Wrong fRTL\n");
230 ok(items[2].a.fLayoutRTL == 0, "Wrong fLayoutRTL\n");
231 ok(items[2].a.s.uBidiLevel == 0, "Wrong BidiLevel\n");
232 ok(items[3].iCharPos == 7, "Wrong CharPos \n");
233 ok(items[3].a.fRTL == 0, "Wrong fRTL\n");
234 ok(items[3].a.fLayoutRTL == 0, "Wrong fLayoutRTL\n");
235 ok(items[3].a.s.uBidiLevel == 0, "Wrong BidiLevel\n");
236 ok(items[4].iCharPos == 10, "Wrong CharPos \n");
237 ok(items[4].a.fRTL == 0, "Wrong fRTL\n");
238 ok(items[4].a.fLayoutRTL == 0, "Wrong fLayoutRTL\n");
239 ok(items[4].a.s.uBidiLevel == 0, "Wrong BidiLevel\n");
241 State.uBidiLevel = 1;
242 hr = ScriptItemize(test4, 12, 10, &Control, &State, items, &nItems);
243 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
244 todo_wine ok(nItems == 4, "Wrong number of items\n");
245 ok(items[0].iCharPos == 0, "Wrong CharPos \n");
246 ok(items[0].a.fRTL == 0, "Wrong fRTL\n");
247 todo_wine ok(items[0].a.fLayoutRTL == 1, "Wrong fLayoutRTL\n");
248 ok(items[0].a.s.uBidiLevel == 2, "Wrong BidiLevel\n");
249 ok(items[1].iCharPos == 6, "Wrong CharPos \n");
250 ok(items[1].a.fRTL == 1, "Wrong fRTL\n");
251 ok(items[1].a.fLayoutRTL == 1, "Wrong fLayoutRTL\n");
252 ok(items[1].a.s.uBidiLevel == 1, "Wrong BidiLevel\n");
253 ok(items[2].iCharPos == 7, "Wrong CharPos \n");
254 ok(items[2].a.fRTL == 0, "Wrong fRTL\n");
255 ok(items[2].a.fLayoutRTL == 0, "Wrong fLayoutRTL\n");
256 ok(items[2].a.s.uBidiLevel == 2, "Wrong BidiLevel\n");
257 todo_wine ok(items[3].iCharPos == 10, "Wrong CharPos \n");
258 ok(items[3].a.fRTL == 0, "Wrong fRTL\n");
259 ok(items[3].a.fLayoutRTL == 0, "Wrong fLayoutRTL\n");
260 todo_wine ok(items[3].a.s.uBidiLevel == 2, "Wrong BidiLevel\n");
262 hr = ScriptItemize(test5, 38, 10, NULL, NULL, items, &nItems);
263 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
264 ok(nItems == 1, "Wrong number of items\n");
265 ok(items[0].iCharPos == 0, "Wrong CharPos \n");
266 ok(items[0].a.fRTL == 1, "Wrong fRTL\n");
267 ok(items[0].a.fLayoutRTL == 1, "Wrong fLayoutRTL\n");
268 ok(items[0].a.s.uBidiLevel == 1, "Wrong BidiLevel\n");
270 State.uBidiLevel = 0;
271 hr = ScriptItemize(test5, 38, 10, &Control, &State, items, &nItems);
272 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
273 ok(nItems == 1, "Wrong number of items\n");
274 ok(items[0].iCharPos == 0, "Wrong CharPos \n");
275 ok(items[0].a.fRTL == 1, "Wrong fRTL\n");
276 ok(items[0].a.fLayoutRTL == 1, "Wrong fLayoutRTL\n");
277 ok(items[0].a.s.uBidiLevel == 1, "Wrong BidiLevel\n");
279 State.uBidiLevel = 1;
280 hr = ScriptItemize(test5, 38, 10, &Control, &State, items, &nItems);
281 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
282 ok(nItems == 1, "Wrong number of items\n");
283 ok(items[0].iCharPos == 0, "Wrong CharPos \n");
284 ok(items[0].a.fRTL == 1, "Wrong fRTL\n");
285 ok(items[0].a.fLayoutRTL == 1, "Wrong fLayoutRTL\n");
286 ok(items[0].a.s.uBidiLevel == 1, "Wrong BidiLevel\n");
290 static void test_ScriptShape(HDC hdc)
292 static const WCHAR test1[] = {'w', 'i', 'n', 'e',0};
293 static const WCHAR test2[] = {0x202B, 'i', 'n', 0x202C,0};
295 SCRIPT_CACHE sc = NULL;
296 WORD glyphs[4], glyphs2[4], logclust[4];
297 SCRIPT_VISATTR attrs[4];
298 SCRIPT_ITEM items[2];
301 hr = ScriptItemize(test1, 4, 2, NULL, NULL, items, NULL);
302 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
303 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
305 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, NULL, &nb);
306 ok(hr == E_INVALIDARG, "ScriptShape should return E_INVALIDARG not %08x\n", hr);
308 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, attrs, NULL);
309 ok(hr == E_INVALIDARG, "ScriptShape should return E_INVALIDARG not %08x\n", hr);
311 hr = ScriptShape(NULL, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, attrs, &nb);
312 ok(hr == E_PENDING, "ScriptShape should return E_PENDING not %08x\n", hr);
314 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, attrs, &nb);
315 ok(broken(hr == S_OK) ||
316 hr == E_INVALIDARG || /* Vista, W2K8 */
317 hr == E_FAIL, /* WIN7 */
318 "ScriptShape should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
319 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
321 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, logclust, attrs, &nb);
322 ok(!hr, "ScriptShape should return S_OK not %08x\n", hr);
323 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
326 memset(glyphs,-1,sizeof(glyphs));
327 memset(logclust,-1,sizeof(logclust));
328 memset(attrs,-1,sizeof(attrs));
329 hr = ScriptShape(NULL, &sc, test1, 4, 4, &items[0].a, glyphs, logclust, attrs, &nb);
330 ok(!hr, "ScriptShape should return S_OK not %08x\n", hr);
331 ok(nb == 4, "Wrong number of items\n");
332 ok(logclust[0] == 0, "clusters out of order\n");
333 ok(logclust[1] == 1, "clusters out of order\n");
334 ok(logclust[2] == 2, "clusters out of order\n");
335 ok(logclust[3] == 3, "clusters out of order\n");
336 ok(attrs[0].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
337 ok(attrs[1].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
338 ok(attrs[2].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
339 ok(attrs[3].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
340 ok(attrs[0].fClusterStart == 1, "fClusterStart incorrect\n");
341 ok(attrs[1].fClusterStart == 1, "fClusterStart incorrect\n");
342 ok(attrs[2].fClusterStart == 1, "fClusterStart incorrect\n");
343 ok(attrs[3].fClusterStart == 1, "fClusterStart incorrect\n");
344 ok(attrs[0].fDiacritic == 0, "fDiacritic incorrect\n");
345 ok(attrs[1].fDiacritic == 0, "fDiacritic incorrect\n");
346 ok(attrs[2].fDiacritic == 0, "fDiacritic incorrect\n");
347 ok(attrs[3].fDiacritic == 0, "fDiacritic incorrect\n");
348 ok(attrs[0].fZeroWidth == 0, "fZeroWidth incorrect\n");
349 ok(attrs[1].fZeroWidth == 0, "fZeroWidth incorrect\n");
350 ok(attrs[2].fZeroWidth == 0, "fZeroWidth incorrect\n");
351 ok(attrs[3].fZeroWidth == 0, "fZeroWidth incorrect\n");
353 ScriptFreeCache(&sc);
356 memset(glyphs2,-1,sizeof(glyphs2));
357 memset(logclust,-1,sizeof(logclust));
358 memset(attrs,-1,sizeof(attrs));
359 hr = ScriptShape(hdc, &sc, test2, 4, 4, &items[0].a, glyphs2, logclust, attrs, &nb);
360 ok(hr == S_OK, "ScriptShape should return S_OK not %08x\n", hr);
361 ok(nb == 4, "Wrong number of items\n");
362 ok(glyphs2[0] == 0, "Incorrect glyph for 0x202B\n");
363 ok(glyphs2[3] == 0, "Incorrect glyph for 0x202C\n");
364 ok(logclust[0] == 0, "clusters out of order\n");
365 ok(logclust[1] == 1, "clusters out of order\n");
366 ok(logclust[2] == 2, "clusters out of order\n");
367 ok(logclust[3] == 3, "clusters out of order\n");
368 ok(attrs[0].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
369 ok(attrs[1].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
370 ok(attrs[2].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
371 ok(attrs[3].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
372 ok(attrs[0].fClusterStart == 1, "fClusterStart incorrect\n");
373 ok(attrs[1].fClusterStart == 1, "fClusterStart incorrect\n");
374 ok(attrs[2].fClusterStart == 1, "fClusterStart incorrect\n");
375 ok(attrs[3].fClusterStart == 1, "fClusterStart incorrect\n");
376 ok(attrs[0].fDiacritic == 0, "fDiacritic incorrect\n");
377 ok(attrs[1].fDiacritic == 0, "fDiacritic incorrect\n");
378 ok(attrs[2].fDiacritic == 0, "fDiacritic incorrect\n");
379 ok(attrs[3].fDiacritic == 0, "fDiacritic incorrect\n");
380 ok(attrs[0].fZeroWidth == 0, "fZeroWidth incorrect\n");
381 ok(attrs[1].fZeroWidth == 0, "fZeroWidth incorrect\n");
382 ok(attrs[2].fZeroWidth == 0, "fZeroWidth incorrect\n");
383 ok(attrs[3].fZeroWidth == 0, "fZeroWidth incorrect\n");
385 /* modify LTR to RTL */
387 memset(glyphs2,-1,sizeof(glyphs2));
388 memset(logclust,-1,sizeof(logclust));
389 memset(attrs,-1,sizeof(attrs));
390 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs2, logclust, attrs, &nb);
391 ok(!hr, "ScriptShape should return S_OK not %08x\n", hr);
392 ok(nb == 4, "Wrong number of items\n");
393 ok(glyphs2[0] == glyphs[3], "Glyphs not reordered properly\n");
394 ok(glyphs2[1] == glyphs[2], "Glyphs not reordered properly\n");
395 ok(glyphs2[2] == glyphs[1], "Glyphs not reordered properly\n");
396 ok(glyphs2[3] == glyphs[0], "Glyphs not reordered properly\n");
397 ok(logclust[0] == 3, "clusters out of order\n");
398 ok(logclust[1] == 2, "clusters out of order\n");
399 ok(logclust[2] == 1, "clusters out of order\n");
400 ok(logclust[3] == 0, "clusters out of order\n");
401 ok(attrs[0].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
402 ok(attrs[1].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
403 ok(attrs[2].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
404 ok(attrs[3].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
405 ok(attrs[0].fClusterStart == 1, "fClusterStart incorrect\n");
406 ok(attrs[1].fClusterStart == 1, "fClusterStart incorrect\n");
407 ok(attrs[2].fClusterStart == 1, "fClusterStart incorrect\n");
408 ok(attrs[3].fClusterStart == 1, "fClusterStart incorrect\n");
409 ok(attrs[0].fDiacritic == 0, "fDiacritic incorrect\n");
410 ok(attrs[1].fDiacritic == 0, "fDiacritic incorrect\n");
411 ok(attrs[2].fDiacritic == 0, "fDiacritic incorrect\n");
412 ok(attrs[3].fDiacritic == 0, "fDiacritic incorrect\n");
413 ok(attrs[0].fZeroWidth == 0, "fZeroWidth incorrect\n");
414 ok(attrs[1].fZeroWidth == 0, "fZeroWidth incorrect\n");
415 ok(attrs[2].fZeroWidth == 0, "fZeroWidth incorrect\n");
416 ok(attrs[3].fZeroWidth == 0, "fZeroWidth incorrect\n");
418 ScriptFreeCache(&sc);
421 static void test_ScriptPlace(HDC hdc)
423 static const WCHAR test1[] = {'t', 'e', 's', 't',0};
426 SCRIPT_CACHE sc = NULL;
427 WORD glyphs[4], logclust[4];
428 SCRIPT_VISATTR attrs[4];
429 SCRIPT_ITEM items[2];
434 hr = ScriptItemize(test1, 4, 2, NULL, NULL, items, NULL);
435 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
436 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
438 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, logclust, attrs, &nb);
439 ok(!hr, "ScriptShape should return S_OK not %08x\n", hr);
440 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
442 hr = ScriptPlace(hdc, &sc, glyphs, 4, NULL, &items[0].a, widths, NULL, NULL);
443 ok(hr == E_INVALIDARG, "ScriptPlace should return E_INVALIDARG not %08x\n", hr);
445 hr = ScriptPlace(NULL, &sc, glyphs, 4, attrs, &items[0].a, widths, NULL, NULL);
446 ok(broken(hr == E_PENDING) ||
447 hr == E_INVALIDARG || /* Vista, W2K8 */
448 hr == E_FAIL, /* WIN7 */
449 "ScriptPlace should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
451 hr = ScriptPlace(NULL, &sc, glyphs, 4, attrs, &items[0].a, widths, offset, NULL);
452 ok(hr == E_PENDING, "ScriptPlace should return E_PENDING not %08x\n", hr);
454 hr = ScriptPlace(NULL, &sc, glyphs, 4, attrs, &items[0].a, widths, NULL, abc);
455 ok(broken(hr == E_PENDING) ||
456 hr == E_INVALIDARG || /* Vista, W2K8 */
457 hr == E_FAIL, /* WIN7 */
458 "ScriptPlace should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
460 hr = ScriptPlace(hdc, &sc, glyphs, 4, attrs, &items[0].a, widths, offset, NULL);
461 ok(!hr, "ScriptPlace should return S_OK not %08x\n", hr);
462 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
464 ret = ExtTextOutW(hdc, 1, 1, 0, NULL, glyphs, 4, widths);
465 ok(ret, "ExtTextOutW should return TRUE\n");
467 ScriptFreeCache(&sc);
470 static void test_ScriptItemIzeShapePlace(HDC hdc, unsigned short pwOutGlyphs[256])
474 const SCRIPT_PROPERTIES **ppSp;
478 SCRIPT_ITEM pItem[255];
480 WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
481 WCHAR TestItem2[] = {'T', 'e', 's', 't', 'b', 0};
482 WCHAR TestItem3[] = {'T', 'e', 's', 't', 'c',' ','1','2','3',' ',' ','e','n','d',0};
483 WCHAR TestItem4[] = {'T', 'e', 's', 't', 'c',' ',0x0684,0x0694,0x06a4,' ',' ','e','n','d',0};
484 WCHAR TestItem5[] = {0x0684,'T','e','s','t','c',' ',0x0684,0x0694,0x06a4,' ',' ','e','n','d',0};
489 unsigned short pwOutGlyphs1[256];
490 unsigned short pwOutGlyphs2[256];
491 unsigned short pwLogClust[256];
492 SCRIPT_VISATTR psva[256];
495 GOFFSET pGoffset[256];
499 /* Start testing usp10 functions */
500 /* This test determines that the pointer returned by ScriptGetProperties is valid
501 * by checking a known value in the table */
502 hr = ScriptGetProperties(&ppSp, &iMaxProps);
503 trace("number of script properties %d\n", iMaxProps);
504 ok (iMaxProps > 0, "Number of scripts returned should not be 0\n");
506 ok( ppSp[5]->langid == 9, "Langid[5] not = to 9\n"); /* Check a known value to ensure */
509 /* This is a valid test that will cause parsing to take place */
512 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
513 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
514 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
516 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
518 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
519 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
520 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
522 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
523 * ie. ScriptItemize has succeeded and that pItem has been set */
527 psc = NULL; /* must be null on first call */
529 cMaxGlyphs = cInChars;
530 hr = ScriptShape(NULL, &psc, TestItem1, cChars,
531 cMaxGlyphs, &pItem[0].a,
532 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
533 ok (hr == E_PENDING, "If psc is NULL (%08x) the E_PENDING should be returned\n", hr);
535 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
536 cMaxGlyphs, &pItem[0].a,
537 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
538 ok (hr == E_OUTOFMEMORY, "If not enough output area cChars (%d) is > than CMaxGlyphs "
539 "(%d) but not E_OUTOFMEMORY\n",
542 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
543 cMaxGlyphs, &pItem[0].a,
544 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
545 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
546 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
547 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
549 hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
551 ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", hr);
552 hr = ScriptPlace(NULL, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
554 ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", hr);
555 for (cnt=0; cnt < pcGlyphs; cnt++)
556 pwOutGlyphs[cnt] = pwOutGlyphs1[cnt]; /* Send to next function */
559 /* This test will check to make sure that SCRIPT_CACHE is reused and that not translation *
560 * takes place if fNoGlyphIndex is set. */
564 hr = ScriptItemize(TestItem2, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
565 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
566 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
568 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
569 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
570 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
571 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue */
575 pItem[0].a.fNoGlyphIndex = 1; /* say no translate */
576 hr = ScriptShape(NULL, &psc, TestItem2, cChars,
577 cMaxGlyphs, &pItem[0].a,
578 pwOutGlyphs2, pwLogClust, psva, &pcGlyphs);
579 ok (hr != E_PENDING, "If psc should not be NULL (%08x) and the E_PENDING should be returned\n", hr);
580 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
581 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
582 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
583 for (cnt=0; cnt < cChars && TestItem2[cnt] == pwOutGlyphs2[cnt]; cnt++) {}
584 ok (cnt == cChars, "Translation to place when told not to. WCHAR %d - %04x != %04x\n",
585 cnt, TestItem2[cnt], pwOutGlyphs2[cnt]);
587 hr = ScriptPlace(hdc, &psc, pwOutGlyphs2, pcGlyphs, psva, &pItem[0].a, piAdvance,
589 ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", hr);
592 hr = ScriptFreeCache( &psc);
593 ok (!psc, "psc is not null after ScriptFreeCache\n");
597 /* This is a valid test that will cause parsing to take place and create 3 script_items */
598 cInChars = (sizeof(TestItem3)/2)-1;
600 hr = ScriptItemize(TestItem3, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
601 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
604 ok (pcItems == 3, "The number of SCRIPT_ITEMS should be 3 not %d\n", pcItems);
607 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == 6,
608 "Start pos [0] not = 0 (%d) or end pos [1] not = %d\n",
609 pItem[0].iCharPos, pItem[1].iCharPos);
610 ok (pItem[1].iCharPos == 6 && pItem[2].iCharPos == 11,
611 "Start pos [1] not = 6 (%d) or end pos [2] not = 11 (%d)\n",
612 pItem[1].iCharPos, pItem[2].iCharPos);
613 ok (pItem[2].iCharPos == 11 && pItem[3].iCharPos == cInChars,
614 "Start pos [2] not = 11 (%d) or end [3] pos not = 14 (%d), cInChars = %d\n",
615 pItem[2].iCharPos, pItem[3].iCharPos, cInChars);
617 hr = ScriptFreeCache( &psc);
618 ok (!psc, "psc is not null after ScriptFreeCache\n");
621 /* This is a valid test that will cause parsing to take place and create 3 script_items */
622 cInChars = (sizeof(TestItem4)/2)-1;
624 hr = ScriptItemize(TestItem4, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
625 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
628 ok (pcItems == 3, "The number of SCRIPT_ITEMS should be 3 not %d\n", pcItems);
631 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == 6,
632 "Start pos [0] not = 0 (%d) or end pos [1] not = %d\n",
633 pItem[0].iCharPos, pItem[1].iCharPos);
634 ok (pItem[1].iCharPos == 6 && pItem[2].iCharPos == 11,
635 "Start pos [1] not = 6 (%d) or end pos [2] not = 11 (%d)\n",
636 pItem[1].iCharPos, pItem[2].iCharPos);
637 ok (pItem[2].iCharPos == 11 && pItem[3].iCharPos == cInChars,
638 "Start pos [2] not = 11 (%d) or end [3] pos not = 14 (%d), cInChars = %d\n",
639 pItem[2].iCharPos, pItem[3].iCharPos, cInChars);
641 hr = ScriptFreeCache( &psc);
642 ok (!psc, "psc is not null after ScriptFreeCache\n");
646 * This test is for when the first unicode character requires bidi support
648 cInChars = (sizeof(TestItem5)-1)/sizeof(WCHAR);
649 hr = ScriptItemize(TestItem5, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
650 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
651 ok (pcItems == 4, "There should have been 4 items, found %d\n", pcItems);
652 ok (pItem[0].a.s.uBidiLevel == 1, "The first character should have been bidi=1 not %d\n",
653 pItem[0].a.s.uBidiLevel);
656 static void test_ScriptGetCMap(HDC hdc, unsigned short pwOutGlyphs[256])
659 SCRIPT_CACHE psc = NULL;
662 unsigned short pwOutGlyphs3[256];
663 WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
667 /* Check to make sure that SCRIPT_CACHE gets allocated ok */
669 cInChars = cChars = 5;
670 /* Some sanity checks for ScriptGetCMap */
672 hr = ScriptGetCMap(NULL, NULL, NULL, 0, 0, NULL);
673 ok( hr == E_INVALIDARG, "(NULL,NULL,NULL,0,0,NULL), "
674 "expected E_INVALIDARG, got %08x\n", hr);
676 hr = ScriptGetCMap(NULL, NULL, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
677 ok( hr == E_INVALIDARG, "(NULL,NULL,TestItem1, cInChars, dwFlags, pwOutGlyphs3), "
678 "expected E_INVALIDARG, got %08x\n", hr);
680 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
682 hr = ScriptGetCMap(NULL, &psc, TestItem1, cInChars, 0, pwOutGlyphs3);
683 ok( hr == E_PENDING, "(NULL,&psc,NULL,0,0,NULL), expected E_PENDING, "
685 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
687 /* Set psc to NULL but add hdc, to be able to check if a pointer is returned in psc */
689 hr = ScriptGetCMap(hdc, &psc, TestItem1, cInChars, 0, pwOutGlyphs3);
690 ok( hr == S_OK, "ScriptGetCMap(NULL,&psc,NULL,0,0,NULL), expected S_OK, "
692 ok( psc != NULL, "ScritpGetCMap expected psc to be not NULL\n");
693 ScriptFreeCache( &psc);
695 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
697 hr = ScriptGetCMap(NULL, &psc, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
698 ok( hr == E_PENDING, "(NULL,&psc,), expected E_PENDING, got %08x\n", hr);
699 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
700 /* Check to see if the results are the same as those returned by ScriptShape */
701 hr = ScriptGetCMap(hdc, &psc, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
702 ok (hr == 0, "ScriptGetCMap should return 0 not (%08x)\n", hr);
703 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
704 for (cnt=0; cnt < cChars && pwOutGlyphs[cnt] == pwOutGlyphs3[cnt]; cnt++) {}
705 ok (cnt == cInChars, "Translation not correct. WCHAR %d - %04x != %04x\n",
706 cnt, pwOutGlyphs[cnt], pwOutGlyphs3[cnt]);
708 hr = ScriptFreeCache( &psc);
709 ok (!psc, "psc is not null after ScriptFreeCache\n");
713 static void test_ScriptGetFontProperties(HDC hdc)
716 SCRIPT_CACHE psc,old_psc;
717 SCRIPT_FONTPROPERTIES sfp;
719 /* Some sanity checks for ScriptGetFontProperties */
721 hr = ScriptGetFontProperties(NULL,NULL,NULL);
722 ok( hr == E_INVALIDARG, "(NULL,NULL,NULL), expected E_INVALIDARG, got %08x\n", hr);
724 hr = ScriptGetFontProperties(NULL,NULL,&sfp);
725 ok( hr == E_INVALIDARG, "(NULL,NULL,&sfp), expected E_INVALIDARG, got %08x\n", hr);
727 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
729 hr = ScriptGetFontProperties(NULL,&psc,NULL);
730 ok( hr == E_INVALIDARG, "(NULL,&psc,NULL), expected E_INVALIDARG, got %08x\n", hr);
731 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
733 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
735 hr = ScriptGetFontProperties(NULL,&psc,&sfp);
736 ok( hr == E_PENDING, "(NULL,&psc,&sfp), expected E_PENDING, got %08x\n", hr);
737 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
739 hr = ScriptGetFontProperties(hdc,NULL,NULL);
740 ok( hr == E_INVALIDARG, "(hdc,NULL,NULL), expected E_INVALIDARG, got %08x\n", hr);
742 hr = ScriptGetFontProperties(hdc,NULL,&sfp);
743 ok( hr == E_INVALIDARG, "(hdc,NULL,&sfp), expected E_INVALIDARG, got %08x\n", hr);
745 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
747 hr = ScriptGetFontProperties(hdc,&psc,NULL);
748 ok( hr == E_INVALIDARG, "(hdc,&psc,NULL), expected E_INVALIDARG, got %08x\n", hr);
749 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
751 /* Pass an invalid sfp */
753 sfp.cBytes = sizeof(SCRIPT_FONTPROPERTIES) - 1;
754 hr = ScriptGetFontProperties(hdc,&psc,&sfp);
755 ok( hr == E_INVALIDARG, "(hdc,&psc,&sfp) invalid, expected E_INVALIDARG, got %08x\n", hr);
756 ok( psc != NULL, "Expected a pointer in psc, got NULL\n");
757 ScriptFreeCache(&psc);
758 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
760 /* Give it the correct cBytes, we don't care about what's coming back */
761 sfp.cBytes = sizeof(SCRIPT_FONTPROPERTIES);
763 hr = ScriptGetFontProperties(hdc,&psc,&sfp);
764 ok( hr == S_OK, "(hdc,&psc,&sfp) partly initialized, expected S_OK, got %08x\n", hr);
765 ok( psc != NULL, "Expected a pointer in psc, got NULL\n");
767 /* Save the psc pointer */
769 /* Now a NULL hdc again */
770 hr = ScriptGetFontProperties(NULL,&psc,&sfp);
771 ok( hr == S_OK, "(NULL,&psc,&sfp), expected S_OK, got %08x\n", hr);
772 ok( psc == old_psc, "Expected psc not to be changed, was %p is now %p\n", old_psc, psc);
773 ScriptFreeCache(&psc);
774 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
777 static void test_ScriptTextOut(HDC hdc)
783 SCRIPT_ITEM pItem[255];
785 WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
790 unsigned short pwOutGlyphs1[256];
791 WORD pwLogClust[256];
792 SCRIPT_VISATTR psva[256];
795 GOFFSET pGoffset[256];
800 BOOL fTrailing = FALSE;
801 SCRIPT_LOGATTR *psla;
802 SCRIPT_LOGATTR sla[256];
804 /* This is a valid test that will cause parsing to take place */
807 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
808 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
809 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
811 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
813 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
814 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
815 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
817 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
818 * ie. ScriptItemize has succeeded and that pItem has been set */
822 psc = NULL; /* must be null on first call */
824 cMaxGlyphs = cInChars;
826 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
827 cMaxGlyphs, &pItem[0].a,
828 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
829 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
830 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
831 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
833 /* Note hdc is needed as glyph info is not yet in psc */
834 hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
836 ok (hr == 0, "Should return 0 not (%08x)\n", hr);
837 ScriptFreeCache(&psc); /* Get rid of psc for next test set */
838 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
840 hr = ScriptTextOut(NULL, NULL, 0, 0, 0, NULL, NULL, NULL, 0, NULL, 0, NULL, NULL, NULL);
841 ok (hr == E_INVALIDARG, "Should return 0 not (%08x)\n", hr);
843 hr = ScriptTextOut(NULL, NULL, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
844 piAdvance, NULL, pGoffset);
845 ok( hr == E_INVALIDARG, "(NULL,NULL,TestItem1, cInChars, dwFlags, pwOutGlyphs3), "
846 "expected E_INVALIDARG, got %08x\n", hr);
848 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
850 hr = ScriptTextOut(NULL, &psc, 0, 0, 0, NULL, NULL, NULL, 0, NULL, 0,
852 ok( hr == E_INVALIDARG, "(NULL,&psc,NULL,0,0,0,NULL,), expected E_INVALIDARG, "
854 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
856 /* hdc is required for this one rather than the usual optional */
858 hr = ScriptTextOut(NULL, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
859 piAdvance, NULL, pGoffset);
860 ok( hr == E_INVALIDARG, "(NULL,&psc,), expected E_INVALIDARG, got %08x\n", hr);
861 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
863 /* Set that it returns 0 status */
864 hr = ScriptTextOut(hdc, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
865 piAdvance, NULL, pGoffset);
866 ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
868 /* Test Rect Rgn is acceptable */
873 hr = ScriptTextOut(hdc, &psc, 0, 0, 0, &rect, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
874 piAdvance, NULL, pGoffset);
875 ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
878 hr = ScriptCPtoX(iCP, fTrailing, cChars, pcGlyphs, (const WORD *) &pwLogClust,
879 (const SCRIPT_VISATTR *) &psva, (const int *)&piAdvance, &pItem[0].a, &piX);
880 ok(hr == S_OK, "ScriptCPtoX Stub should return S_OK not %08x\n", hr);
882 psla = (SCRIPT_LOGATTR *)&sla;
883 hr = ScriptBreak(TestItem1, cChars, &pItem[0].a, psla);
884 ok(hr == S_OK, "ScriptBreak Stub should return S_OK not %08x\n", hr);
886 /* Clean up and go */
887 ScriptFreeCache(&psc);
888 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
893 static void test_ScriptTextOut2(HDC hdc)
895 /* Intent is to validate that the HDC passed into ScriptTextOut is
896 * used instead of the (possibly) invalid cached one
903 SCRIPT_ITEM pItem[255];
905 WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
910 unsigned short pwOutGlyphs1[256];
911 WORD pwLogClust[256];
912 SCRIPT_VISATTR psva[256];
915 GOFFSET pGoffset[256];
918 /* Create an extra DC that will be used until the ScriptTextOut */
919 hdc1 = CreateCompatibleDC(hdc);
920 ok (hdc1 != 0, "CreateCompatibleDC failed to create a DC\n");
921 hdc2 = CreateCompatibleDC(hdc);
922 ok (hdc2 != 0, "CreateCompatibleDC failed to create a DC\n");
924 /* This is a valid test that will cause parsing to take place */
927 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
928 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
929 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
931 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
933 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
934 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
935 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
937 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
938 * ie. ScriptItemize has succeeded and that pItem has been set */
942 psc = NULL; /* must be null on first call */
944 cMaxGlyphs = cInChars;
946 hr = ScriptShape(hdc2, &psc, TestItem1, cChars,
947 cMaxGlyphs, &pItem[0].a,
948 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
949 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
950 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
951 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
953 /* Note hdc is needed as glyph info is not yet in psc */
954 hr = ScriptPlace(hdc2, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
956 ok (hr == 0, "Should return 0 not (%08x)\n", hr);
958 /* key part!!! cached dc is being deleted */
960 ok(hr == 1, "DeleteDC should return 1 not %08x\n", hr);
962 /* At this point the cached hdc (hdc2) has been destroyed,
963 * however, we are passing in a *real* hdc (the original hdc).
964 * The text should be written to that DC
966 hr = ScriptTextOut(hdc1, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
967 piAdvance, NULL, pGoffset);
968 ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
969 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
973 /* Clean up and go */
974 ScriptFreeCache(&psc);
975 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
980 static void test_ScriptTextOut3(HDC hdc)
986 SCRIPT_ITEM pItem[255];
988 WCHAR TestItem1[] = {' ','\r', 0};
993 unsigned short pwOutGlyphs1[256];
994 WORD pwLogClust[256];
995 SCRIPT_VISATTR psva[256];
998 GOFFSET pGoffset[256];
1002 /* This is to ensure that non exisiting glyphs are translated into a valid glyph number */
1005 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1006 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1007 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
1009 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
1011 ok (pItem[0].iCharPos == 0 && pItem[2].iCharPos == cInChars,
1012 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
1013 pItem[0].iCharPos, cInChars, pItem[2].iCharPos);
1015 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
1016 * ie. ScriptItemize has succeeded and that pItem has been set */
1020 psc = NULL; /* must be null on first call */
1022 cMaxGlyphs = cInChars;
1024 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
1025 cMaxGlyphs, &pItem[0].a,
1026 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1027 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
1028 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1029 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
1031 /* Note hdc is needed as glyph info is not yet in psc */
1032 hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
1034 ok (hr == 0, "Should return 0 not (%08x)\n", hr);
1036 /* Test Rect Rgn is acceptable */
1041 hr = ScriptTextOut(hdc, &psc, 0, 0, 0, &rect, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1042 piAdvance, NULL, pGoffset);
1043 ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
1046 /* Clean up and go */
1047 ScriptFreeCache(&psc);
1048 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1052 static void test_ScriptXtoX(void)
1053 /****************************************************************************************
1054 * This routine tests the ScriptXtoCP and ScriptCPtoX functions using static variables *
1055 ****************************************************************************************/
1057 static const WCHAR test[] = {'t', 'e', 's', 't',0};
1058 SCRIPT_ITEM items[2];
1062 WORD pwLogClust[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
1063 SCRIPT_VISATTR psva[10];
1064 int piAdvance[10] = {200, 190, 210, 180, 170, 204, 189, 195, 212, 203};
1070 hr = ScriptItemize(test, lstrlenW(test), sizeof(items)/sizeof(items[0]), NULL, NULL, items, NULL);
1071 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
1076 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
1077 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
1079 ok(piCP == -1, "Negative iX should return piCP=-1 not %d\n", piCP);
1081 ok(piCP == 10, "Negative iX should return piCP=10 not %d\n", piCP);
1086 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
1087 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
1088 if (piTrailing) /* win2k3 */
1089 ok(piCP == -1, "Negative iX should return piCP=-1 not %d\n", piCP);
1091 ok(piCP == 10, "Negative iX should return piCP=10 not %d\n", piCP);
1096 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
1097 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
1099 piCP == -1, /* win2k3 */
1100 "iX=%d should return piCP=3 or piCP=-1 not %d\n", iX, piCP);
1101 ok(piTrailing == 1, "iX=%d should return piTrailing=1 not %d\n", iX, piTrailing);
1106 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
1107 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
1109 piCP == -1, /* win2k3 */
1110 "iX=%d should return piCP=3 or piCP=-1 not %d\n", iX, piCP);
1111 ok(piTrailing == 1, "iX=%d should return piTrailing=1 not %d\n", iX, piTrailing);
1116 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
1117 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
1119 piCP == -1, /* win2k3 */
1120 "iX=%d should return piCP=4 or piCP=-1 not %d\n", iX, piCP);
1125 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
1126 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
1128 piCP == 10, /* win2k3 */
1129 "iX=%d should return piCP=0 piCP=10 not %d\n", iX, piCP);
1134 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
1135 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
1136 ok(piCP == 0, "iX=%d should return piCP=0 not %d\n", iX, piCP);
1141 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
1142 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
1144 piCP == 0, /* win2k3 */
1145 "iX=%d should return piCP=1 or piCP=0 not %d\n", iX, piCP);
1151 hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piX);
1152 ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
1154 piX == 100, /* win2k3 */
1155 "iCP=%d should return piX=976 or piX=100 not %d\n", iCP, piX);
1161 hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piX);
1162 ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
1164 piX == 80, /* win2k3 */
1165 "iCP=%d should return piX=1171 or piX=80 not %d\n", iCP, piX);
1171 hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piX);
1172 ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
1174 piX == 80, /* win2k3 */
1175 "iCP=%d should return piX=1171 or piX=80 not %d\n", iCP, piX);
1181 hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piX);
1182 ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
1184 piX == 0, /* win2k3 */
1185 "iCP=%d should return piX=1953 or piX=0 not %d\n", iCP, piX);
1191 hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piX);
1192 ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
1194 piX == 0, /* win2k3 */
1195 "iCP=%d should return piX=1953 or piX=0 not %d\n", iCP, piX);
1198 static void test_ScriptString(HDC hdc)
1200 /*******************************************************************************************
1202 * This set of tests are for the string functions of uniscribe. The ScriptStringAnalyse
1203 * function allocates memory pointed to by the SCRIPT_STRING_ANALYSIS ssa pointer. This
1204 * memory if freed by ScriptStringFree. There needs to be a valid hdc for this as
1205 * ScriptStringAnalyse calls ScriptSItemize, ScriptShape and ScriptPlace which require it.
1210 WCHAR teststr[] = {'T','e','s','t','1',' ','a','2','b','3', '\0'};
1211 int len = (sizeof(teststr) / sizeof(WCHAR)) - 1;
1212 int Glyphs = len * 2 + 16;
1214 DWORD Flags = SSA_GLYPHS;
1216 SCRIPT_CONTROL Control;
1218 const int Dx[5] = {10, 10, 10, 10, 10};
1219 SCRIPT_TABDEF Tabdef;
1220 const BYTE InClass = 0;
1221 SCRIPT_STRING_ANALYSIS ssa = NULL;
1226 const RECT rc = {0, 50, 100, 100};
1229 BOOL Disabled = FALSE;
1230 const int *clip_len;
1235 Charset = -1; /* this flag indicates unicode input */
1236 /* Test without hdc to get E_PENDING */
1237 hr = ScriptStringAnalyse( NULL, teststr, len, Glyphs, Charset, Flags,
1238 ReqWidth, &Control, &State, Dx, &Tabdef,
1240 ok(hr == E_PENDING, "ScriptStringAnalyse Stub should return E_PENDING not %08x\n", hr);
1242 /* test with hdc, this should be a valid test */
1243 hr = ScriptStringAnalyse( hdc, teststr, len, Glyphs, Charset, Flags,
1244 ReqWidth, &Control, &State, Dx, &Tabdef,
1246 ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
1247 ScriptStringFree(&ssa);
1249 /* test makes sure that a call with a valid pssa still works */
1250 hr = ScriptStringAnalyse( hdc, teststr, len, Glyphs, Charset, Flags,
1251 ReqWidth, &Control, &State, Dx, &Tabdef,
1253 ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
1254 ok(ssa != NULL, "ScriptStringAnalyse pssa should not be NULL\n");
1258 hr = ScriptStringOut(ssa, X, Y, Options, &rc, MinSel, MaxSel, Disabled);
1259 ok(hr == S_OK, "ScriptStringOut should return S_OK not %08x\n", hr);
1262 clip_len = ScriptString_pcOutChars(ssa);
1263 ok(*clip_len == len, "ScriptString_pcOutChars failed, got %d, expected %d\n", *clip_len, len);
1265 order = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *clip_len * sizeof(UINT));
1266 hr = ScriptStringGetOrder(ssa, order);
1267 ok(hr == S_OK, "ScriptStringGetOrder failed, got %08x, expected S_OK\n", hr);
1269 for (i = 0; i < *clip_len; i++) ok(order[i] == i, "%d: got %d expected %d\n", i, order[i], i);
1270 HeapFree(GetProcessHeap(), 0, order);
1272 hr = ScriptStringFree(&ssa);
1273 ok(hr == S_OK, "ScriptStringFree should return S_OK not %08x\n", hr);
1276 static void test_ScriptStringXtoCP_CPtoX(HDC hdc)
1278 /*****************************************************************************************
1280 * This test is for the ScriptStringXtoCP and ScriptStringXtoCP functions. Due to the
1281 * nature of the fonts between Windows and Wine, the test is implemented by generating
1282 * values using one one function then checking the output of the second. In this way
1283 * the validity of the functions is established using Windows as a base and confirming
1284 * similar behaviour in wine.
1288 WCHAR teststr1[] = {'T', 'e', 's', 't', 'e', '1', '2', ' ', 'a', '\0'};
1289 void *String = (WCHAR *) &teststr1; /* ScriptStringAnalysis needs void */
1290 int String_len = (sizeof(teststr1)/sizeof(WCHAR))-1;
1291 int Glyphs = String_len * 2 + 16; /* size of buffer as recommended */
1292 int Charset = -1; /* unicode */
1293 DWORD Flags = SSA_GLYPHS;
1295 SCRIPT_CONTROL Control;
1297 SCRIPT_TABDEF Tabdef;
1298 const BYTE InClass = 0;
1299 SCRIPT_STRING_ANALYSIS ssa = NULL;
1301 int Ch; /* Character position in string */
1303 int Cp; /* Character position in string */
1307 /* Test with hdc, this should be a valid test
1308 * Here we generate an SCRIPT_STRING_ANALYSIS that will be used as input to the
1309 * following character positions to X and X to character position functions.
1311 hr = ScriptStringAnalyse( hdc, String, String_len, Glyphs, Charset, Flags,
1312 ReqWidth, &Control, &State, NULL, &Tabdef,
1315 hr == E_INVALIDARG, /* NT */
1316 "ScriptStringAnalyse should return S_OK or E_INVALIDARG not %08x\n", hr);
1320 ok(ssa != NULL, "ScriptStringAnalyse ssa should not be NULL\n");
1323 * Loop to generate character positions to provide starting positions for the
1324 * ScriptStringCPtoX and ScriptStringXtoCP functions
1326 for (Cp = 0; Cp < String_len; Cp++)
1328 /* The fTrailing flag is used to indicate whether the X being returned is at
1329 * the beginning or the end of the character. What happens here is that if
1330 * fTrailing indicates the end of the character, ie. FALSE, then ScriptStringXtoCP
1331 * returns the beginning of the next character and iTrailing is FALSE. So for this
1332 * loop iTrailing will be FALSE in both cases.
1335 hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
1336 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
1337 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
1338 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
1339 ok(Cp == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp, Ch, X);
1340 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
1343 hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
1344 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
1345 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
1346 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
1349 * Check that character position returned by ScriptStringXtoCP in Ch matches the
1350 * one input to ScriptStringCPtoX. This means that the Cp to X position and back
1353 ok(Cp + 1 == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp + 1, Ch, X);
1354 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
1358 * This test is to check that if the X position is just inside the trailing edge of the
1359 * character then iTrailing will indicate the trailing edge, ie. TRUE
1363 hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
1364 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
1365 X--; /* put X just inside the trailing edge */
1366 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
1367 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
1368 ok(Cp == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp, Ch, X);
1369 ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
1373 * This test is to check that if the X position is just outside the trailing edge of the
1374 * character then iTrailing will indicate the leading edge, ie. FALSE, and Ch will indicate
1375 * the next character, ie. Cp + 1
1379 hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
1380 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
1381 X++; /* put X just outside the trailing edge */
1382 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
1383 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
1384 ok(Cp + 1 == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp + 1, Ch, X);
1385 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
1389 * This test is to check that if the X position is just outside the leading edge of the
1390 * character then iTrailing will indicate the trailing edge, ie. TRUE, and Ch will indicate
1391 * the next character down , ie. Cp - 1
1395 hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
1396 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
1397 X--; /* put X just outside the leading edge */
1398 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
1399 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
1400 ok(Cp - 1 == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp - 1, Ch, X);
1401 ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
1405 * Cleanup the SSA for the next round of tests
1407 hr = ScriptStringFree(&ssa);
1408 ok(hr == S_OK, "ScriptStringFree should return S_OK not %08x\n", hr);
1411 * Test to see that exceeding the number of chars returns E_INVALIDARG. First
1412 * generate an SSA for the subsequent tests.
1414 hr = ScriptStringAnalyse( hdc, String, String_len, Glyphs, Charset, Flags,
1415 ReqWidth, &Control, &State, NULL, &Tabdef,
1417 ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
1420 * When ScriptStringCPtoX is called with a character position Cp that exceeds the
1421 * string length, return E_INVALIDARG. This also invalidates the ssa so a
1422 * ScriptStringFree should also fail.
1425 Cp = String_len + 1;
1426 hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
1427 ok(hr == E_INVALIDARG, "ScriptStringCPtoX should return E_INVALIDARG not %08x\n", hr);
1429 hr = ScriptStringFree(&ssa);
1431 * ScriptStringCPtoX should free ssa, hence ScriptStringFree should fail
1433 ok(hr == E_INVALIDARG ||
1434 hr == E_FAIL, /* win2k3 */
1435 "ScriptStringFree should return E_INVALIDARG or E_FAIL not %08x\n", hr);
1439 static void test_ScriptCacheGetHeight(HDC hdc)
1442 SCRIPT_CACHE sc = NULL;
1445 hr = ScriptCacheGetHeight(NULL, NULL, NULL);
1446 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
1448 hr = ScriptCacheGetHeight(NULL, &sc, NULL);
1449 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
1451 hr = ScriptCacheGetHeight(NULL, &sc, &height);
1452 ok(hr == E_PENDING, "expected E_PENDING, got 0x%08x\n", hr);
1456 hr = ScriptCacheGetHeight(hdc, &sc, &height);
1457 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1458 ok(height > 0, "expected height > 0\n");
1460 ScriptFreeCache(&sc);
1463 static void test_ScriptGetGlyphABCWidth(HDC hdc)
1466 SCRIPT_CACHE sc = NULL;
1469 hr = ScriptGetGlyphABCWidth(NULL, NULL, 'a', NULL);
1470 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
1472 hr = ScriptGetGlyphABCWidth(NULL, &sc, 'a', NULL);
1473 ok(broken(hr == E_PENDING) ||
1474 hr == E_INVALIDARG, /* WIN7 */
1475 "expected E_INVALIDARG, got 0x%08x\n", hr);
1477 hr = ScriptGetGlyphABCWidth(NULL, &sc, 'a', &abc);
1478 ok(hr == E_PENDING, "expected E_PENDING, got 0x%08x\n", hr);
1480 if (0) { /* crashes on WinXP */
1481 hr = ScriptGetGlyphABCWidth(hdc, &sc, 'a', NULL);
1482 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
1485 hr = ScriptGetGlyphABCWidth(hdc, &sc, 'a', &abc);
1486 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1488 ScriptFreeCache(&sc);
1491 static void test_ScriptLayout(void)
1494 static const BYTE levels[][10] =
1496 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
1497 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
1498 { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
1499 { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
1501 { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1},
1502 { 1, 1, 1, 2, 2, 2, 1, 1, 1, 1 },
1503 { 2, 2, 2, 1, 1, 1, 2, 2, 2, 2 },
1504 { 0, 0, 1, 1, 2, 2, 1, 1, 0, 0 },
1505 { 1, 1, 2, 2, 3, 3, 2, 2, 1, 1 },
1507 { 0, 0, 1, 1, 2, 2, 1, 1, 0, 1 },
1508 { 1, 0, 1, 2, 2, 1, 2, 1, 0, 1 },
1510 static const int expect_l2v[][10] =
1512 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
1513 { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
1514 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
1515 { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
1517 { 0, 1, 2, 3, 4, 9, 8 ,7 ,6, 5},
1518 /**/ { 9, 8, 7, 4, 5, 6, 3 ,2 ,1, 0},
1519 /**/ { 7, 8, 9, 6, 5, 4, 0 ,1 ,2, 3},
1520 { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
1521 { 9, 8, 2, 3, 5, 4, 6 ,7 ,1, 0},
1523 { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
1524 /**/ { 0, 1, 7, 5, 6, 4, 3 ,2 ,8, 9},
1526 static const int expect_v2l[][10] =
1528 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
1529 { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
1530 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
1531 { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
1533 { 0, 1, 2, 3, 4, 9, 8 ,7 ,6, 5},
1534 { 9, 8, 7, 6, 3, 4, 5 ,2 ,1, 0},
1535 { 6, 7, 8, 9, 5, 4, 3 ,0 ,1, 2},
1536 { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
1537 { 9, 8, 2, 3, 5, 4, 6 ,7 ,1, 0},
1539 { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
1540 { 0, 1, 7, 6, 5, 3, 4 ,2 ,8, 9},
1543 int i, j, vistolog[sizeof(levels[0])], logtovis[sizeof(levels[0])];
1545 hr = ScriptLayout(sizeof(levels[0]), NULL, vistolog, logtovis);
1546 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
1548 hr = ScriptLayout(sizeof(levels[0]), levels[0], NULL, NULL);
1549 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
1551 for (i = 0; i < sizeof(levels)/sizeof(levels[0]); i++)
1553 hr = ScriptLayout(sizeof(levels[0]), levels[i], vistolog, logtovis);
1554 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1556 for (j = 0; j < sizeof(levels[i]); j++)
1558 ok(expect_v2l[i][j] == vistolog[j],
1559 "failure: levels[%d][%d] = %d, vistolog[%d] = %d\n",
1560 i, j, levels[i][j], j, vistolog[j] );
1563 for (j = 0; j < sizeof(levels[i]); j++)
1565 ok(expect_l2v[i][j] == logtovis[j],
1566 "failure: levels[%d][%d] = %d, logtovis[%d] = %d\n",
1567 i, j, levels[i][j], j, logtovis[j] );
1572 static BOOL CALLBACK enum_proc(LGRPID group, LCID lcid, LPSTR locale, LONG_PTR lparam)
1575 SCRIPT_DIGITSUBSTITUTE sds;
1580 if (!IsValidLocale(lcid, LCID_INSTALLED)) return TRUE;
1582 memset(&sds, 0, sizeof(sds));
1583 memset(&sc, 0, sizeof(sc));
1584 memset(&ss, 0, sizeof(ss));
1586 lcid_old = GetThreadLocale();
1587 if (!SetThreadLocale(lcid)) return TRUE;
1589 hr = ScriptRecordDigitSubstitution(lcid, &sds);
1590 ok(hr == S_OK, "ScriptRecordDigitSubstitution failed: 0x%08x\n", hr);
1592 hr = ScriptApplyDigitSubstitution(&sds, &sc, &ss);
1593 ok(hr == S_OK, "ScriptApplyDigitSubstitution failed: 0x%08x\n", hr);
1595 SetThreadLocale(lcid_old);
1599 static void test_digit_substitution(void)
1603 static const LGRPID groups[] =
1605 LGRPID_WESTERN_EUROPE,
1606 LGRPID_CENTRAL_EUROPE,
1613 LGRPID_TRADITIONAL_CHINESE,
1614 LGRPID_SIMPLIFIED_CHINESE,
1624 static BOOL (WINAPI * pEnumLanguageGroupLocalesA)(LANGGROUPLOCALE_ENUMPROCA,LGRPID,DWORD,LONG_PTR);
1626 hKernel32 = GetModuleHandleA("kernel32.dll");
1627 pEnumLanguageGroupLocalesA = (void*)GetProcAddress(hKernel32, "EnumLanguageGroupLocalesA");
1629 if (!pEnumLanguageGroupLocalesA)
1631 win_skip("EnumLanguageGroupLocalesA not available on this platform\n");
1635 for (i = 0; i < sizeof(groups)/sizeof(groups[0]); i++)
1637 ret = pEnumLanguageGroupLocalesA(enum_proc, groups[i], 0, 0);
1638 if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1640 win_skip("EnumLanguageGroupLocalesA not implemented on this platform\n");
1644 ok(ret, "EnumLanguageGroupLocalesA failed unexpectedly: %u\n", GetLastError());
1648 static void test_ScriptGetProperties(void)
1650 const SCRIPT_PROPERTIES **props;
1654 hr = ScriptGetProperties(NULL, NULL);
1655 ok(hr == E_INVALIDARG, "ScriptGetProperties succeeded\n");
1657 hr = ScriptGetProperties(NULL, &num);
1658 ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
1660 hr = ScriptGetProperties(&props, NULL);
1661 ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
1663 hr = ScriptGetProperties(&props, &num);
1664 ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
1667 static void test_ScriptBreak(void)
1669 static const WCHAR test[] = {' ','\r','\n',0};
1670 SCRIPT_ITEM items[4];
1674 hr = ScriptItemize(test, 3, 4, NULL, NULL, items, NULL);
1675 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
1677 memset(&la, 0, sizeof(la));
1678 hr = ScriptBreak(test, 1, &items[0].a, &la);
1679 ok(!hr, "ScriptBreak should return S_OK not %08x\n", hr);
1681 ok(!la.fSoftBreak, "fSoftBreak set\n");
1682 ok(la.fWhiteSpace, "fWhiteSpace not set\n");
1683 ok(la.fCharStop, "fCharStop not set\n");
1684 ok(!la.fWordStop, "fWordStop set\n");
1685 ok(!la.fInvalid, "fInvalid set\n");
1686 ok(!la.fReserved, "fReserved set\n");
1688 memset(&la, 0, sizeof(la));
1689 hr = ScriptBreak(test + 1, 1, &items[1].a, &la);
1690 ok(!hr, "ScriptBreak should return S_OK not %08x\n", hr);
1692 ok(!la.fSoftBreak, "fSoftBreak set\n");
1693 ok(!la.fWhiteSpace, "fWhiteSpace set\n");
1694 ok(la.fCharStop, "fCharStop not set\n");
1695 ok(!la.fWordStop, "fWordStop set\n");
1696 ok(!la.fInvalid, "fInvalid set\n");
1697 ok(!la.fReserved, "fReserved set\n");
1699 memset(&la, 0, sizeof(la));
1700 hr = ScriptBreak(test + 2, 1, &items[2].a, &la);
1701 ok(!hr, "ScriptBreak should return S_OK not %08x\n", hr);
1703 ok(!la.fSoftBreak, "fSoftBreak set\n");
1704 ok(!la.fWhiteSpace, "fWhiteSpace set\n");
1705 ok(la.fCharStop, "fCharStop not set\n");
1706 ok(!la.fWordStop, "fWordStop set\n");
1707 ok(!la.fInvalid, "fInvalid set\n");
1708 ok(!la.fReserved, "fReserved set\n");
1711 static void test_newlines(void)
1713 static const WCHAR test1[] = {'t','e','x','t','\r','t','e','x','t',0};
1714 static const WCHAR test2[] = {'t','e','x','t','\n','t','e','x','t',0};
1715 static const WCHAR test3[] = {'t','e','x','t','\r','\n','t','e','x','t',0};
1716 static const WCHAR test4[] = {'t','e','x','t','\n','\r','t','e','x','t',0};
1717 static const WCHAR test5[] = {'1','2','3','4','\n','\r','1','2','3','4',0};
1718 SCRIPT_ITEM items[5];
1723 hr = ScriptItemize(test1, lstrlenW(test1), 5, NULL, NULL, items, &count);
1724 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
1725 ok(count == 3, "got %d expected 3\n", count);
1728 hr = ScriptItemize(test2, lstrlenW(test2), 5, NULL, NULL, items, &count);
1729 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
1730 ok(count == 3, "got %d expected 3\n", count);
1733 hr = ScriptItemize(test3, lstrlenW(test3), 5, NULL, NULL, items, &count);
1734 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
1735 ok(count == 4, "got %d expected 4\n", count);
1738 hr = ScriptItemize(test4, lstrlenW(test4), 5, NULL, NULL, items, &count);
1739 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
1740 ok(count == 4, "got %d expected 4\n", count);
1743 hr = ScriptItemize(test5, lstrlenW(test5), 5, NULL, NULL, items, &count);
1744 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
1745 ok(count == 4, "got %d expected 4\n", count);
1755 unsigned short pwOutGlyphs[256];
1757 /* We need a valid HDC to drive a lot of Script functions which requires the following *
1758 * to set up for the tests. */
1759 hwnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,
1762 ShowWindow(hwnd, SW_SHOW);
1765 hdc = GetDC(hwnd); /* We now have a hdc */
1766 ok( hdc != NULL, "HDC failed to be created %p\n", hdc);
1768 memset(&lf, 0, sizeof(LOGFONTA));
1769 lstrcpyA(lf.lfFaceName, "Tahoma");
1774 hfont = SelectObject(hdc, CreateFontIndirectA(&lf));
1776 test_ScriptItemize();
1777 test_ScriptItemIzeShapePlace(hdc,pwOutGlyphs);
1778 test_ScriptGetCMap(hdc, pwOutGlyphs);
1779 test_ScriptCacheGetHeight(hdc);
1780 test_ScriptGetGlyphABCWidth(hdc);
1781 test_ScriptShape(hdc);
1782 test_ScriptPlace(hdc);
1784 test_ScriptGetFontProperties(hdc);
1785 test_ScriptTextOut(hdc);
1786 test_ScriptTextOut2(hdc);
1787 test_ScriptTextOut3(hdc);
1789 test_ScriptString(hdc);
1790 test_ScriptStringXtoCP_CPtoX(hdc);
1792 test_ScriptLayout();
1793 test_digit_substitution();
1794 test_ScriptGetProperties();
1798 ReleaseDC(hwnd, hdc);
1799 DestroyWindow(hwnd);