kernel32: Remove superfluous heap reallocation calls in FormatMessageA/W.
[wine] / dlls / usp10 / tests / usp10.c
1 /*
2  * Tests for usp10 dll
3  *
4  * Copyright 2006 Jeff Latimer
5  * Copyright 2006 Hans Leidekker
6  * Copyright 2010 CodeWeavers, Aric Stewart
7  *
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.
12  *
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.
17  *
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
21  *
22  * Notes:
23  * Uniscribe allows for processing of complex scripts such as joining
24  * and filtering characters and bi-directional text with custom line breaks.
25  */
26
27 #include <assert.h>
28 #include <stdio.h>
29
30 #include <wine/test.h>
31 #include <windows.h>
32 #include <usp10.h>
33
34 static void test_ScriptItemize( void )
35 {
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;
51     SCRIPT_STATE    State;
52     HRESULT hr;
53     int nItems;
54
55     memset(&Control, 0, sizeof(Control));
56     memset(&State, 0, sizeof(State));
57
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");
60
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");
63
64     hr = ScriptItemize(test1, 4, 1, &Control, &State, items, NULL);
65     ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if cMaxItems < 2.");
66
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");
69
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");
77
78     State.uBidiLevel = 0;
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");
86
87     State.uBidiLevel = 1;
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");
95
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");
123
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");
144
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");
165
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");
173
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");
182
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");
191
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");
215
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");
240
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");
261
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");
269
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");
278
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");
287 }
288
289
290 static void test_ScriptShape(HDC hdc)
291 {
292     static const WCHAR test1[] = {'w', 'i', 'n', 'e',0};
293     static const WCHAR test2[] = {0x202B, 'i', 'n', 0x202C,0};
294     HRESULT hr;
295     SCRIPT_CACHE sc = NULL;
296     WORD glyphs[4], glyphs2[4], logclust[4];
297     SCRIPT_VISATTR attrs[4];
298     SCRIPT_ITEM items[2];
299     int nb;
300
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");
304
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);
307
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);
310
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);
313
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");
320
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");
324
325
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");
352
353     ScriptFreeCache(&sc);
354     sc = NULL;
355
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");
384
385     /* modify LTR to RTL */
386     items[0].a.fRTL = 1;
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");
417
418     ScriptFreeCache(&sc);
419 }
420
421 static void test_ScriptPlace(HDC hdc)
422 {
423     static const WCHAR test1[] = {'t', 'e', 's', 't',0};
424     BOOL ret;
425     HRESULT hr;
426     SCRIPT_CACHE sc = NULL;
427     WORD glyphs[4], logclust[4];
428     SCRIPT_VISATTR attrs[4];
429     SCRIPT_ITEM items[2];
430     int nb, widths[4];
431     GOFFSET offset[4];
432     ABC abc[4];
433
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");
437
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");
441
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);
444
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);
450
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);
453
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);
459
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");
463
464     ret = ExtTextOutW(hdc, 1, 1, 0, NULL, glyphs, 4, widths);
465     ok(ret, "ExtTextOutW should return TRUE\n");
466
467     ScriptFreeCache(&sc);
468 }
469
470 static void test_ScriptItemIzeShapePlace(HDC hdc, unsigned short pwOutGlyphs[256])
471 {
472     HRESULT         hr;
473     int             iMaxProps;
474     const SCRIPT_PROPERTIES **ppSp;
475
476     int             cInChars;
477     int             cMaxItems;
478     SCRIPT_ITEM     pItem[255];
479     int             pcItems;
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}; 
485
486     SCRIPT_CACHE    psc;
487     int             cChars;
488     int             cMaxGlyphs;
489     unsigned short  pwOutGlyphs1[256];
490     unsigned short  pwOutGlyphs2[256];
491     unsigned short  pwLogClust[256];
492     SCRIPT_VISATTR  psva[256];
493     int             pcGlyphs;
494     int             piAdvance[256];
495     GOFFSET         pGoffset[256];
496     ABC             pABC[256];
497     int             cnt;
498
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"); 
505     if  (iMaxProps > 0)
506          ok( ppSp[5]->langid == 9, "Langid[5] not = to 9\n"); /* Check a known value to ensure   */
507                                                               /* ptrs work                       */
508
509     /* This is a valid test that will cause parsing to take place                             */
510     cInChars = 5;
511     cMaxItems = 255;
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 *
515      *  returned.                                                                             */
516     ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
517     if (pcItems > 0)
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);
521
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                            */
524     cInChars = 5;
525     cMaxItems = 255;
526     if (hr == 0) {
527         psc = NULL;                                   /* must be null on first call           */
528         cChars = cInChars;
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);
534         cMaxGlyphs = 4;
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",
540                                  cChars, cMaxGlyphs);
541         cMaxGlyphs = 256;
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);
548         if (hr ==0) {
549             hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
550                              pGoffset, pABC);
551             ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", hr);
552             hr = ScriptPlace(NULL, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
553                              pGoffset, pABC);
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 */
557         }
558
559         /* This test will check to make sure that SCRIPT_CACHE is reused and that not translation   *
560          * takes place if fNoGlyphIndex is set.                                                     */
561
562         cInChars = 5;
563         cMaxItems = 255;
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 *
567          *  returned.                                                                               */
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                    */
572         if (hr == 0) {
573              cChars = cInChars;
574              cMaxGlyphs = 256;
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]);
586              if (hr ==0) {
587                  hr = ScriptPlace(hdc, &psc, pwOutGlyphs2, pcGlyphs, psva, &pItem[0].a, piAdvance,
588                                   pGoffset, pABC);
589                  ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", hr);
590              }
591         }
592         hr = ScriptFreeCache( &psc);
593         ok (!psc, "psc is not null after ScriptFreeCache\n");
594
595     }
596
597     /* This is a valid test that will cause parsing to take place and create 3 script_items   */
598     cInChars = (sizeof(TestItem3)/2)-1;
599     cMaxItems = 255;
600     hr = ScriptItemize(TestItem3, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
601     ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
602     if  (hr == 0)
603         {
604         ok (pcItems == 3, "The number of SCRIPT_ITEMS should be 3 not %d\n", pcItems);
605         if (pcItems > 2)
606         {
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);
616         }
617         hr = ScriptFreeCache( &psc);
618         ok (!psc, "psc is not null after ScriptFreeCache\n");
619     }
620
621     /* This is a valid test that will cause parsing to take place and create 3 script_items   */
622     cInChars = (sizeof(TestItem4)/2)-1;
623     cMaxItems = 255;
624     hr = ScriptItemize(TestItem4, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
625     ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
626     if  (hr == 0)
627         {
628         ok (pcItems == 3, "The number of SCRIPT_ITEMS should be 3 not %d\n", pcItems);
629         if (pcItems > 2)
630         {
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);
640         }
641         hr = ScriptFreeCache( &psc);
642         ok (!psc, "psc is not null after ScriptFreeCache\n");
643     }
644
645     /*
646      * This test is for when the first unicode character requires bidi support
647      */ 
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);
654 }
655
656 static void test_ScriptGetCMap(HDC hdc, unsigned short pwOutGlyphs[256])
657 {
658     HRESULT         hr;
659     SCRIPT_CACHE    psc = NULL;
660     int             cInChars;
661     int             cChars;
662     unsigned short  pwOutGlyphs3[256];
663     WCHAR           TestItem1[] = {'T', 'e', 's', 't', 'a', 0}; 
664     DWORD           dwFlags;
665     int             cnt;
666
667     /*  Check to make sure that SCRIPT_CACHE gets allocated ok                     */
668     dwFlags = 0;
669     cInChars = cChars = 5;
670     /* Some sanity checks for ScriptGetCMap */
671
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);
675
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);
679
680     /* Set psc to NULL, to be able to check if a pointer is returned in psc */
681     psc = NULL;
682     hr = ScriptGetCMap(NULL, &psc, TestItem1, cInChars, 0, pwOutGlyphs3);
683     ok( hr == E_PENDING, "(NULL,&psc,NULL,0,0,NULL), expected E_PENDING, "
684                          "got %08x\n", hr);
685     ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
686
687     /* Set psc to NULL but add hdc, to be able to check if a pointer is returned in psc */
688     psc = NULL;
689     hr = ScriptGetCMap(hdc, &psc, TestItem1, cInChars, 0, pwOutGlyphs3);
690     ok( hr == S_OK, "ScriptGetCMap(NULL,&psc,NULL,0,0,NULL), expected S_OK, "
691                     "got %08x\n", hr);
692     ok( psc != NULL, "ScritpGetCMap expected psc to be not NULL\n");
693     ScriptFreeCache( &psc);
694
695     /* Set psc to NULL, to be able to check if a pointer is returned in psc */
696     psc = NULL;
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]);
707         
708     hr = ScriptFreeCache( &psc);
709     ok (!psc, "psc is not null after ScriptFreeCache\n");
710
711 }
712
713 static void test_ScriptGetFontProperties(HDC hdc)
714 {
715     HRESULT         hr;
716     SCRIPT_CACHE    psc,old_psc;
717     SCRIPT_FONTPROPERTIES sfp;
718
719     /* Some sanity checks for ScriptGetFontProperties */
720
721     hr = ScriptGetFontProperties(NULL,NULL,NULL);
722     ok( hr == E_INVALIDARG, "(NULL,NULL,NULL), expected E_INVALIDARG, got %08x\n", hr);
723
724     hr = ScriptGetFontProperties(NULL,NULL,&sfp);
725     ok( hr == E_INVALIDARG, "(NULL,NULL,&sfp), expected E_INVALIDARG, got %08x\n", hr);
726
727     /* Set psc to NULL, to be able to check if a pointer is returned in psc */
728     psc = NULL;
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);
732
733     /* Set psc to NULL, to be able to check if a pointer is returned in psc */
734     psc = NULL;
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);
738
739     hr = ScriptGetFontProperties(hdc,NULL,NULL);
740     ok( hr == E_INVALIDARG, "(hdc,NULL,NULL), expected E_INVALIDARG, got %08x\n", hr);
741
742     hr = ScriptGetFontProperties(hdc,NULL,&sfp);
743     ok( hr == E_INVALIDARG, "(hdc,NULL,&sfp), expected E_INVALIDARG, got %08x\n", hr);
744
745     /* Set psc to NULL, to be able to check if a pointer is returned in psc */
746     psc = NULL;
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);
750
751     /* Pass an invalid sfp */
752     psc = NULL;
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);
759
760     /* Give it the correct cBytes, we don't care about what's coming back */
761     sfp.cBytes = sizeof(SCRIPT_FONTPROPERTIES);
762     psc = NULL;
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");
766
767     /* Save the psc pointer */
768     old_psc = psc;
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);
775 }
776
777 static void test_ScriptTextOut(HDC hdc)
778 {
779     HRESULT         hr;
780
781     int             cInChars;
782     int             cMaxItems;
783     SCRIPT_ITEM     pItem[255];
784     int             pcItems;
785     WCHAR           TestItem1[] = {'T', 'e', 's', 't', 'a', 0}; 
786
787     SCRIPT_CACHE    psc;
788     int             cChars;
789     int             cMaxGlyphs;
790     unsigned short  pwOutGlyphs1[256];
791     WORD            pwLogClust[256];
792     SCRIPT_VISATTR  psva[256];
793     int             pcGlyphs;
794     int             piAdvance[256];
795     GOFFSET         pGoffset[256];
796     ABC             pABC[256];
797     RECT            rect;
798     int             piX;
799     int             iCP = 1;
800     BOOL            fTrailing = FALSE;
801     SCRIPT_LOGATTR  *psla;
802     SCRIPT_LOGATTR  sla[256];
803
804     /* This is a valid test that will cause parsing to take place                             */
805     cInChars = 5;
806     cMaxItems = 255;
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 *
810      *  returned.                                                                             */
811     ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
812     if (pcItems > 0)
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);
816
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                            */
819     cInChars = 5;
820     cMaxItems = 255;
821     if (hr == 0) {
822         psc = NULL;                                   /* must be null on first call           */
823         cChars = cInChars;
824         cMaxGlyphs = cInChars;
825         cMaxGlyphs = 256;
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);
832         if (hr ==0) {
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,
835                              pGoffset, pABC);
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);
839
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);
842
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);
847
848             /* Set psc to NULL, to be able to check if a pointer is returned in psc */
849             psc = NULL;
850             hr = ScriptTextOut(NULL, &psc, 0, 0, 0, NULL, NULL, NULL, 0, NULL, 0,
851                                NULL, NULL, NULL);
852             ok( hr == E_INVALIDARG, "(NULL,&psc,NULL,0,0,0,NULL,), expected E_INVALIDARG, "
853                                     "got %08x\n", hr);
854             ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
855
856             /* hdc is required for this one rather than the usual optional          */
857             psc = NULL;
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);
862
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);
867
868             /* Test Rect Rgn is acceptable */
869             rect.top = 10;
870             rect.bottom = 20;
871             rect.left = 10;
872             rect.right = 40;
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);
876
877             iCP = 1;
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);
881
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);
885
886             /* Clean up and go   */
887             ScriptFreeCache(&psc);
888             ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
889         }
890     }
891 }
892
893 static void test_ScriptTextOut2(HDC hdc)
894 {
895 /*  Intent is to validate that the HDC passed into ScriptTextOut is
896  *  used instead of the (possibly) invalid cached one
897  */
898     HRESULT         hr;
899
900     HDC             hdc1, hdc2;
901     int             cInChars;
902     int             cMaxItems;
903     SCRIPT_ITEM     pItem[255];
904     int             pcItems;
905     WCHAR           TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
906
907     SCRIPT_CACHE    psc;
908     int             cChars;
909     int             cMaxGlyphs;
910     unsigned short  pwOutGlyphs1[256];
911     WORD            pwLogClust[256];
912     SCRIPT_VISATTR  psva[256];
913     int             pcGlyphs;
914     int             piAdvance[256];
915     GOFFSET         pGoffset[256];
916     ABC             pABC[256];
917
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");
923
924     /* This is a valid test that will cause parsing to take place                             */
925     cInChars = 5;
926     cMaxItems = 255;
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 *
930      *  returned.                                                                             */
931     ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
932     if (pcItems > 0)
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);
936
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                            */
939     cInChars = 5;
940     cMaxItems = 255;
941     if (hr == 0) {
942         psc = NULL;                                   /* must be null on first call           */
943         cChars = cInChars;
944         cMaxGlyphs = cInChars;
945         cMaxGlyphs = 256;
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);
952         if (hr ==0) {
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,
955                              pGoffset, pABC);
956             ok (hr == 0, "Should return 0 not (%08x)\n", hr);
957
958             /*   key part!!!   cached dc is being deleted  */
959             hr = DeleteDC(hdc2);
960             ok(hr == 1, "DeleteDC should return 1 not %08x\n", hr);
961
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
965              */
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");
970
971             DeleteDC(hdc1);
972
973             /* Clean up and go   */
974             ScriptFreeCache(&psc);
975             ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
976         }
977     }
978 }
979
980 static void test_ScriptTextOut3(HDC hdc)
981 {
982     HRESULT         hr;
983
984     int             cInChars;
985     int             cMaxItems;
986     SCRIPT_ITEM     pItem[255];
987     int             pcItems;
988     WCHAR           TestItem1[] = {' ','\r', 0};
989
990     SCRIPT_CACHE    psc;
991     int             cChars;
992     int             cMaxGlyphs;
993     unsigned short  pwOutGlyphs1[256];
994     WORD            pwLogClust[256];
995     SCRIPT_VISATTR  psva[256];
996     int             pcGlyphs;
997     int             piAdvance[256];
998     GOFFSET         pGoffset[256];
999     ABC             pABC[256];
1000     RECT            rect;
1001
1002     /* This is to ensure that non exisiting glyphs are translated into a valid glyph number */
1003     cInChars = 2;
1004     cMaxItems = 255;
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 *
1008      *  returned.                                                                             */
1009     ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
1010     if (pcItems > 0)
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);
1014
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                            */
1017     cInChars = 2;
1018     cMaxItems = 255;
1019     if (hr == 0) {
1020         psc = NULL;                                   /* must be null on first call           */
1021         cChars = cInChars;
1022         cMaxGlyphs = cInChars;
1023         cMaxGlyphs = 256;
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);
1030         if (hr ==0) {
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,
1033                              pGoffset, pABC);
1034             ok (hr == 0, "Should return 0 not (%08x)\n", hr);
1035
1036             /* Test Rect Rgn is acceptable */
1037             rect.top = 10;
1038             rect.bottom = 20;
1039             rect.left = 10;
1040             rect.right = 40;
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);
1044
1045         }
1046         /* Clean up and go   */
1047         ScriptFreeCache(&psc);
1048         ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1049     }
1050 }
1051
1052 static void test_ScriptXtoX(void)
1053 /****************************************************************************************
1054  *  This routine tests the ScriptXtoCP and ScriptCPtoX functions using static variables *
1055  ****************************************************************************************/
1056 {
1057     static const WCHAR test[] = {'t', 'e', 's', 't',0};
1058     SCRIPT_ITEM items[2];
1059     int iX, iCP;
1060     int cChars;
1061     int cGlyphs;
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};
1065     int piCP, piX;
1066     int piTrailing;
1067     BOOL fTrailing;
1068     HRESULT hr;
1069
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);
1072
1073     iX = -1;
1074     cChars = 10;
1075     cGlyphs = 10;
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);
1078     if (piTrailing)
1079         ok(piCP == -1, "Negative iX should return piCP=-1 not %d\n", piCP);
1080     else /* win2k3 */
1081         ok(piCP == 10, "Negative iX should return piCP=10 not %d\n", piCP);
1082
1083     iX = 1954;
1084     cChars = 10;
1085     cGlyphs = 10;
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);
1090     else
1091         ok(piCP == 10, "Negative iX should return piCP=10 not %d\n", piCP);
1092
1093     iX = 779;
1094     cChars = 10;
1095     cGlyphs = 10;
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);
1098     ok(piCP == 3 ||
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);
1102
1103     iX = 780;
1104     cChars = 10;
1105     cGlyphs = 10;
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);
1108     ok(piCP == 3 ||
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);
1112
1113     iX = 868;
1114     cChars = 10;
1115     cGlyphs = 10;
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);
1118     ok(piCP == 4 ||
1119        piCP == -1, /* win2k3 */
1120        "iX=%d should return piCP=4 or piCP=-1 not %d\n", iX, piCP);
1121
1122     iX = 0;
1123     cChars = 10;
1124     cGlyphs = 10;
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);
1127     ok(piCP == 0 ||
1128        piCP == 10, /* win2k3 */
1129        "iX=%d should return piCP=0 piCP=10 not %d\n", iX, piCP);
1130
1131     iX = 195;
1132     cChars = 10;
1133     cGlyphs = 10;
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);
1137
1138     iX = 196;
1139     cChars = 10;
1140     cGlyphs = 10;
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);
1143     ok(piCP == 1 ||
1144        piCP == 0, /* win2k3 */
1145        "iX=%d should return piCP=1 or piCP=0 not %d\n", iX, piCP);
1146
1147     iCP=5;
1148     fTrailing = FALSE;
1149     cChars = 10;
1150     cGlyphs = 10;
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);
1153     ok(piX == 976 ||
1154        piX == 100, /* win2k3 */
1155        "iCP=%d should return piX=976 or piX=100 not %d\n", iCP, piX);
1156
1157     iCP=5;
1158     fTrailing = TRUE;
1159     cChars = 10;
1160     cGlyphs = 10;
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);
1163     ok(piX == 1171 ||
1164        piX == 80, /* win2k3 */
1165        "iCP=%d should return piX=1171 or piX=80 not %d\n", iCP, piX);
1166
1167     iCP=6;
1168     fTrailing = FALSE;
1169     cChars = 10;
1170     cGlyphs = 10;
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);
1173     ok(piX == 1171 ||
1174        piX == 80, /* win2k3 */
1175        "iCP=%d should return piX=1171 or piX=80 not %d\n", iCP, piX);
1176
1177     iCP=11;
1178     fTrailing = FALSE;
1179     cChars = 10;
1180     cGlyphs = 10;
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);
1183     ok(piX == 1953 ||
1184        piX == 0, /* win2k3 */
1185        "iCP=%d should return piX=1953 or piX=0 not %d\n", iCP, piX);
1186
1187     iCP=11;
1188     fTrailing = TRUE;
1189     cChars = 10;
1190     cGlyphs = 10;
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);
1193     ok(piX == 1953 ||
1194        piX == 0, /* win2k3 */
1195        "iCP=%d should return piX=1953 or piX=0 not %d\n", iCP, piX);
1196 }
1197
1198 static void test_ScriptString(HDC hdc)
1199 {
1200 /*******************************************************************************************
1201  *
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.
1206  *
1207  */
1208
1209     HRESULT         hr;
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;
1213     int             Charset;
1214     DWORD           Flags = SSA_GLYPHS;
1215     int             ReqWidth = 100;
1216     SCRIPT_CONTROL  Control;
1217     SCRIPT_STATE    State;
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;
1222
1223     int             X = 10; 
1224     int             Y = 100;
1225     UINT            Options = 0; 
1226     const RECT      rc = {0, 50, 100, 100}; 
1227     int             MinSel = 0;
1228     int             MaxSel = 0;
1229     BOOL            Disabled = FALSE;
1230     const int      *clip_len;
1231     int            i;
1232     UINT           *order;
1233
1234
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,
1239                              &InClass, &ssa);
1240     ok(hr == E_PENDING, "ScriptStringAnalyse Stub should return E_PENDING not %08x\n", hr);
1241
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,
1245                               &InClass, &ssa);
1246     ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
1247     ScriptStringFree(&ssa);
1248
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,
1252                               &InClass, &ssa);
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");
1255
1256     if (hr == S_OK)
1257     {
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);
1260     }
1261
1262      clip_len = ScriptString_pcOutChars(ssa);
1263      ok(*clip_len == len, "ScriptString_pcOutChars failed, got %d, expected %d\n", *clip_len, len);
1264
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);
1268
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);
1271
1272      hr = ScriptStringFree(&ssa);
1273      ok(hr == S_OK, "ScriptStringFree should return S_OK not %08x\n", hr);
1274 }
1275
1276 static void test_ScriptStringXtoCP_CPtoX(HDC hdc)
1277 {
1278 /*****************************************************************************************
1279  *
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.
1285  */
1286
1287     HRESULT         hr;
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;
1294     int             ReqWidth = 100;
1295     SCRIPT_CONTROL  Control;
1296     SCRIPT_STATE    State;
1297     SCRIPT_TABDEF   Tabdef;
1298     const BYTE      InClass = 0;
1299     SCRIPT_STRING_ANALYSIS ssa = NULL;
1300
1301     int             Ch;                                  /* Character position in string */
1302     int             iTrailing;
1303     int             Cp;                                  /* Character position in string */
1304     int             X;
1305     BOOL            fTrailing;
1306
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.
1310      */
1311     hr = ScriptStringAnalyse( hdc, String, String_len, Glyphs, Charset, Flags,
1312                               ReqWidth, &Control, &State, NULL, &Tabdef,
1313                               &InClass, &ssa);
1314     ok(hr == S_OK ||
1315        hr == E_INVALIDARG, /* NT */
1316        "ScriptStringAnalyse should return S_OK or E_INVALIDARG not %08x\n", hr);
1317
1318     if  (hr == S_OK)
1319     {
1320         ok(ssa != NULL, "ScriptStringAnalyse ssa should not be NULL\n");
1321
1322         /*
1323          * Loop to generate character positions to provide starting positions for the
1324          * ScriptStringCPtoX and ScriptStringXtoCP functions
1325          */
1326         for (Cp = 0; Cp < String_len; Cp++)
1327         {
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.
1333              */
1334             fTrailing = FALSE;
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", 
1341                                   iTrailing, X);
1342             fTrailing = TRUE;
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);
1347
1348             /*
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
1351              * again works
1352              */
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", 
1355                                    iTrailing, X);
1356         }
1357         /*
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
1360          */
1361         fTrailing = TRUE;
1362         Cp = 3;
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", 
1370                                   iTrailing, X);
1371
1372         /*
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 
1376          */
1377         fTrailing = TRUE;
1378         Cp = 3;
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", 
1386                                   iTrailing, X);
1387
1388         /*
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 
1392          */
1393         fTrailing = FALSE;
1394         Cp = 3;
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", 
1402                                   iTrailing, X);
1403
1404         /*
1405          * Cleanup the SSA for the next round of tests
1406          */
1407         hr = ScriptStringFree(&ssa);
1408         ok(hr == S_OK, "ScriptStringFree should return S_OK not %08x\n", hr);
1409
1410         /*
1411          * Test to see that exceeding the number of chars returns E_INVALIDARG.  First
1412          * generate an SSA for the subsequent tests.
1413          */
1414         hr = ScriptStringAnalyse( hdc, String, String_len, Glyphs, Charset, Flags,
1415                                   ReqWidth, &Control, &State, NULL, &Tabdef,
1416                                   &InClass, &ssa);
1417         ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
1418
1419         /*
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.
1423          */
1424         fTrailing = FALSE;
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);
1428
1429         hr = ScriptStringFree(&ssa);
1430         /*
1431          * ScriptStringCPtoX should free ssa, hence ScriptStringFree should fail
1432          */
1433         ok(hr == E_INVALIDARG ||
1434            hr == E_FAIL, /* win2k3 */
1435            "ScriptStringFree should return E_INVALIDARG or E_FAIL not %08x\n", hr);
1436     }
1437 }
1438
1439 static void test_ScriptCacheGetHeight(HDC hdc)
1440 {
1441     HRESULT hr;
1442     SCRIPT_CACHE sc = NULL;
1443     LONG height;
1444
1445     hr = ScriptCacheGetHeight(NULL, NULL, NULL);
1446     ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
1447
1448     hr = ScriptCacheGetHeight(NULL, &sc, NULL);
1449     ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
1450
1451     hr = ScriptCacheGetHeight(NULL, &sc, &height);
1452     ok(hr == E_PENDING, "expected E_PENDING, got 0x%08x\n", hr);
1453
1454     height = 0;
1455
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");
1459
1460     ScriptFreeCache(&sc);
1461 }
1462
1463 static void test_ScriptGetGlyphABCWidth(HDC hdc)
1464 {
1465     HRESULT hr;
1466     SCRIPT_CACHE sc = NULL;
1467     ABC abc;
1468
1469     hr = ScriptGetGlyphABCWidth(NULL, NULL, 'a', NULL);
1470     ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
1471
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);
1476
1477     hr = ScriptGetGlyphABCWidth(NULL, &sc, 'a', &abc);
1478     ok(hr == E_PENDING, "expected E_PENDING, got 0x%08x\n", hr);
1479
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);
1483     }
1484
1485     hr = ScriptGetGlyphABCWidth(hdc, &sc, 'a', &abc);
1486     ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1487
1488     ScriptFreeCache(&sc);
1489 }
1490
1491 static void test_ScriptLayout(void)
1492 {
1493     HRESULT hr;
1494     static const BYTE levels[][10] =
1495     {
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 },
1500
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 },
1506
1507         { 0, 0, 1, 1, 2, 2, 1, 1, 0, 1 },
1508         { 1, 0, 1, 2, 2, 1, 2, 1, 0, 1 },
1509     };
1510     static const int expect_l2v[][10] =
1511     {
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 },
1516
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},
1522
1523         { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
1524 /**/    { 0, 1, 7, 5, 6, 4, 3 ,2 ,8, 9},
1525     };
1526     static const int expect_v2l[][10] =
1527     {
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 },
1532
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},
1538
1539         { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
1540         { 0, 1, 7, 6, 5, 3, 4 ,2 ,8, 9},
1541     };
1542
1543     int i, j, vistolog[sizeof(levels[0])], logtovis[sizeof(levels[0])];
1544
1545     hr = ScriptLayout(sizeof(levels[0]), NULL, vistolog, logtovis);
1546     ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
1547
1548     hr = ScriptLayout(sizeof(levels[0]), levels[0], NULL, NULL);
1549     ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
1550
1551     for (i = 0; i < sizeof(levels)/sizeof(levels[0]); i++)
1552     {
1553         hr = ScriptLayout(sizeof(levels[0]), levels[i], vistolog, logtovis);
1554         ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1555
1556         for (j = 0; j < sizeof(levels[i]); j++)
1557         {
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] );
1561         }
1562
1563         for (j = 0; j < sizeof(levels[i]); j++)
1564         {
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] );
1568         }
1569     }
1570 }
1571
1572 static BOOL CALLBACK enum_proc(LGRPID group, LCID lcid, LPSTR locale, LONG_PTR lparam)
1573 {
1574     HRESULT hr;
1575     SCRIPT_DIGITSUBSTITUTE sds;
1576     SCRIPT_CONTROL sc;
1577     SCRIPT_STATE ss;
1578     LCID lcid_old;
1579
1580     if (!IsValidLocale(lcid, LCID_INSTALLED)) return TRUE;
1581
1582     memset(&sds, 0, sizeof(sds));
1583     memset(&sc, 0, sizeof(sc));
1584     memset(&ss, 0, sizeof(ss));
1585
1586     lcid_old = GetThreadLocale();
1587     if (!SetThreadLocale(lcid)) return TRUE;
1588
1589     hr = ScriptRecordDigitSubstitution(lcid, &sds);
1590     ok(hr == S_OK, "ScriptRecordDigitSubstitution failed: 0x%08x\n", hr);
1591
1592     hr = ScriptApplyDigitSubstitution(&sds, &sc, &ss);
1593     ok(hr == S_OK, "ScriptApplyDigitSubstitution failed: 0x%08x\n", hr);
1594
1595     SetThreadLocale(lcid_old);
1596     return TRUE;
1597 }
1598
1599 static void test_digit_substitution(void)
1600 {
1601     BOOL ret;
1602     unsigned int i;
1603     static const LGRPID groups[] =
1604     {
1605         LGRPID_WESTERN_EUROPE,
1606         LGRPID_CENTRAL_EUROPE,
1607         LGRPID_BALTIC,
1608         LGRPID_GREEK,
1609         LGRPID_CYRILLIC,
1610         LGRPID_TURKISH,
1611         LGRPID_JAPANESE,
1612         LGRPID_KOREAN,
1613         LGRPID_TRADITIONAL_CHINESE,
1614         LGRPID_SIMPLIFIED_CHINESE,
1615         LGRPID_THAI,
1616         LGRPID_HEBREW,
1617         LGRPID_ARABIC,
1618         LGRPID_VIETNAMESE,
1619         LGRPID_INDIC,
1620         LGRPID_GEORGIAN,
1621         LGRPID_ARMENIAN
1622     };
1623     HMODULE hKernel32;
1624     static BOOL (WINAPI * pEnumLanguageGroupLocalesA)(LANGGROUPLOCALE_ENUMPROCA,LGRPID,DWORD,LONG_PTR);
1625
1626     hKernel32 = GetModuleHandleA("kernel32.dll");
1627     pEnumLanguageGroupLocalesA = (void*)GetProcAddress(hKernel32, "EnumLanguageGroupLocalesA");
1628
1629     if (!pEnumLanguageGroupLocalesA)
1630     {
1631         win_skip("EnumLanguageGroupLocalesA not available on this platform\n");
1632         return;
1633     }
1634
1635     for (i = 0; i < sizeof(groups)/sizeof(groups[0]); i++)
1636     {
1637         ret = pEnumLanguageGroupLocalesA(enum_proc, groups[i], 0, 0);
1638         if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1639         {
1640             win_skip("EnumLanguageGroupLocalesA not implemented on this platform\n");
1641             break;
1642         }
1643         
1644         ok(ret, "EnumLanguageGroupLocalesA failed unexpectedly: %u\n", GetLastError());
1645     }
1646 }
1647
1648 static void test_ScriptGetProperties(void)
1649 {
1650     const SCRIPT_PROPERTIES **props;
1651     HRESULT hr;
1652     int num;
1653
1654     hr = ScriptGetProperties(NULL, NULL);
1655     ok(hr == E_INVALIDARG, "ScriptGetProperties succeeded\n");
1656
1657     hr = ScriptGetProperties(NULL, &num);
1658     ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
1659
1660     hr = ScriptGetProperties(&props, NULL);
1661     ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
1662
1663     hr = ScriptGetProperties(&props, &num);
1664     ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
1665 }
1666
1667 static void test_ScriptBreak(void)
1668 {
1669     static const WCHAR test[] = {' ','\r','\n',0};
1670     SCRIPT_ITEM items[4];
1671     SCRIPT_LOGATTR la;
1672     HRESULT hr;
1673
1674     hr = ScriptItemize(test, 3, 4, NULL, NULL, items, NULL);
1675     ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
1676
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);
1680
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");
1687
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);
1691
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");
1698
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);
1702
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");
1709 }
1710
1711 static void test_newlines(void)
1712 {
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];
1719     HRESULT hr;
1720     int count;
1721
1722     count = 0;
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);
1726
1727     count = 0;
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);
1731
1732     count = 0;
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);
1736
1737     count = 0;
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);
1741
1742     count = 0;
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);
1746 }
1747
1748 START_TEST(usp10)
1749 {
1750     HWND            hwnd;
1751     HDC             hdc;
1752     LOGFONTA        lf;
1753     HFONT           hfont;
1754
1755     unsigned short  pwOutGlyphs[256];
1756
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,
1760                            0, 0, 0, NULL);
1761     assert(hwnd != 0);
1762     ShowWindow(hwnd, SW_SHOW);
1763     UpdateWindow(hwnd);
1764
1765     hdc = GetDC(hwnd);                                      /* We now have a hdc             */
1766     ok( hdc != NULL, "HDC failed to be created %p\n", hdc);
1767
1768     memset(&lf, 0, sizeof(LOGFONTA));
1769     lstrcpyA(lf.lfFaceName, "Tahoma");
1770     lf.lfHeight = 10;
1771     lf.lfWeight = 3;
1772     lf.lfWidth = 10;
1773
1774     hfont = SelectObject(hdc, CreateFontIndirectA(&lf));
1775
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);
1783
1784     test_ScriptGetFontProperties(hdc);
1785     test_ScriptTextOut(hdc);
1786     test_ScriptTextOut2(hdc);
1787     test_ScriptTextOut3(hdc);
1788     test_ScriptXtoX();
1789     test_ScriptString(hdc);
1790     test_ScriptStringXtoCP_CPtoX(hdc);
1791
1792     test_ScriptLayout();
1793     test_digit_substitution();
1794     test_ScriptGetProperties();
1795     test_ScriptBreak();
1796     test_newlines();
1797
1798     ReleaseDC(hwnd, hdc);
1799     DestroyWindow(hwnd);
1800 }