msi: Fix a typo.
[wine] / dlls / usp10 / tests / usp10.c
1 /*
2  * Tests for usp10 dll
3  *
4  * Copyright 2006 Jeff Latimer
5  * Copyright 2006 Hans Leidekker
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  *
21  * Notes:
22  * Uniscribe allows for processing of complex scripts such as joining
23  * and filtering characters and bi-directional text with custom line breaks.
24  */
25
26 #include <assert.h>
27 #include <stdio.h>
28
29 #include <wine/test.h>
30 #include <winbase.h>
31 #include <wingdi.h>
32 #include <winuser.h>
33 #include <winerror.h>
34 #include <winnls.h>
35 #include <usp10.h>
36
37 static void test_ScriptShape(HDC hdc)
38 {
39     static const WCHAR test1[] = {'t', 'e', 's', 't',0};
40     BOOL ret;
41     HRESULT hr;
42     SCRIPT_CACHE sc = NULL;
43     WORD glyphs[4];
44     SCRIPT_VISATTR attrs[4];
45     SCRIPT_ITEM items[2];
46     int nb, widths[4];
47
48     hr = ScriptItemize(NULL, 4, 2, NULL, NULL, items, NULL);
49     ok(hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG not %08x\n", hr);
50
51     hr = ScriptItemize(test1, 4, 2, NULL, NULL, NULL, NULL);
52     ok(hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG not %08x\n", hr);
53
54     hr = ScriptItemize(test1, 4, 2, NULL, NULL, items, NULL);
55     ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
56     ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
57
58     hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, NULL, &nb);
59     ok(hr == E_INVALIDARG, "ScriptShape should return E_INVALIDARG not %08x\n", hr);
60
61     hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, attrs, NULL);
62     ok(hr == E_INVALIDARG, "ScriptShape should return E_INVALIDARG not %08x\n", hr);
63
64     hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, attrs, &nb);
65     ok(!hr, "ScriptShape should return S_OK not %08x\n", hr);
66     ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
67
68     hr = ScriptPlace(hdc, &sc, glyphs, 4, NULL, &items[0].a, widths, NULL, NULL);
69     ok(hr == E_INVALIDARG, "ScriptPlace should return E_INVALIDARG not %08x\n", hr);
70
71     hr = ScriptPlace(hdc, &sc, glyphs, 4, attrs, &items[0].a, widths, NULL, NULL);
72     ok(!hr, "ScriptPlace should return S_OK not %08x\n", hr);
73     ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
74
75     ret = ExtTextOutW(hdc, 1, 1, 0, NULL, glyphs, 4, widths);
76     ok(ret, "ExtTextOutW should return TRUE\n");
77
78     ScriptFreeCache(&sc);
79 }
80
81 static void test_ScriptItemIzeShapePlace(HDC hdc, unsigned short pwOutGlyphs[256])
82 {
83     HRESULT         hr;
84     int             iMaxProps;
85     const SCRIPT_PROPERTIES **ppSp;
86
87     int             cInChars;
88     int             cMaxItems;
89     SCRIPT_ITEM     pItem[255];
90     int             pcItems;
91     WCHAR           TestItem1[] = {'T', 'e', 's', 't', 'a', 0}; 
92     WCHAR           TestItem2[] = {'T', 'e', 's', 't', 'b', 0}; 
93     WCHAR           TestItem3[] = {'T', 'e', 's', 't', 'c',' ','1','2','3',' ',' ','e','n','d',0}; 
94     WCHAR           TestItem4[] = {'T', 'e', 's', 't', 'c',' ',0x0684,0x0694,0x06a4,' ',' ','e','n','d',0};
95     WCHAR           TestItem5[] = {0x0684,'T','e','s','t','c',' ',0x0684,0x0694,0x06a4,' ',' ','e','n','d',0}; 
96
97     SCRIPT_CACHE    psc;
98     int             cChars;
99     int             cMaxGlyphs;
100     unsigned short  pwOutGlyphs1[256];
101     unsigned short  pwOutGlyphs2[256];
102     unsigned short  pwLogClust[256];
103     SCRIPT_VISATTR  psva[256];
104     int             pcGlyphs;
105     int             piAdvance[256];
106     GOFFSET         pGoffset[256];
107     ABC             pABC[256];
108     int             cnt;
109
110     /* Start testing usp10 functions                                                         */
111     /* This test determines that the pointer returned by ScriptGetProperties is valid
112      * by checking a known value in the table                                                */
113     hr = ScriptGetProperties(&ppSp, &iMaxProps);
114     trace("number of script properties %d\n", iMaxProps);
115     ok (iMaxProps > 0, "Number of scripts returned should not be 0\n"); 
116     if  (iMaxProps > 0)
117          ok( ppSp[5]->langid == 9, "Langid[5] not = to 9\n"); /* Check a known value to ensure   */
118                                                               /* ptrs work                       */
119
120
121     /* This set of tests are to check that the various edits in ScriptIemize work           */
122     cInChars = 5;                                        /* Length of test without NULL     */
123     cMaxItems = 1;                                       /* Check threshold value           */
124     hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
125     ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if cMaxItems < 2.  Was %d\n",
126         cMaxItems);
127     cInChars = 5;
128     cMaxItems = 255;
129     hr = ScriptItemize(NULL, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
130     ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if pwcInChars is NULL\n");
131
132     cInChars = 5;
133     cMaxItems = 255;
134     hr = ScriptItemize(TestItem1, 0, cMaxItems, NULL, NULL, pItem, &pcItems);
135     ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if cInChars is 0\n");
136
137     cInChars = 5;
138     cMaxItems = 255;
139     hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, NULL, &pcItems);
140     ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if pItems is NULL\n");
141
142     /* This is a valid test that will cause parsing to take place                             */
143     cInChars = 5;
144     cMaxItems = 255;
145     hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
146     ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
147     /*  This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
148      *  returned.                                                                             */
149     ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
150     if (pcItems > 0)
151         ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
152             "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
153             pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
154
155     /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
156      * ie. ScriptItemize has succeeded and that pItem has been set                            */
157     cInChars = 5;
158     cMaxItems = 255;
159     if (hr == 0) {
160         psc = NULL;                                   /* must be null on first call           */
161         cChars = cInChars;
162         cMaxGlyphs = cInChars;
163         hr = ScriptShape(NULL, &psc, TestItem1, cChars,
164                          cMaxGlyphs, &pItem[0].a,
165                          pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
166         ok (hr == E_PENDING, "If psc is NULL (%08x) the E_PENDING should be returned\n", hr);
167         cMaxGlyphs = 4;
168         hr = ScriptShape(hdc, &psc, TestItem1, cChars,
169                          cMaxGlyphs, &pItem[0].a,
170                          pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
171         ok (hr == E_OUTOFMEMORY, "If not enough output area cChars (%d) is > than CMaxGlyphs "
172                                  "(%d) but not E_OUTOFMEMORY\n",
173                                  cChars, cMaxGlyphs);
174         cMaxGlyphs = 256;
175         hr = ScriptShape(hdc, &psc, TestItem1, cChars,
176                          cMaxGlyphs, &pItem[0].a,
177                          pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
178         ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
179         ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
180         ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
181         if (hr ==0) {
182             hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
183                              pGoffset, pABC);
184             ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", hr);
185             hr = ScriptPlace(NULL, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
186                              pGoffset, pABC);
187             ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", hr);
188             for (cnt=0; cnt < pcGlyphs; cnt++)
189                 pwOutGlyphs[cnt] = pwOutGlyphs1[cnt];                 /* Send to next function */
190         }
191
192         /* This test will check to make sure that SCRIPT_CACHE is reused and that not translation   *
193          * takes place if fNoGlyphIndex is set.                                                     */
194
195         cInChars = 5;
196         cMaxItems = 255;
197         hr = ScriptItemize(TestItem2, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
198         ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
199         /*  This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
200          *  returned.                                                                               */
201         ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
202                             "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
203                              pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
204         /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue                    */
205         if (hr == 0) {
206              cChars = cInChars;
207              cMaxGlyphs = 256;
208              pItem[0].a.fNoGlyphIndex = 1;                /* say no translate                     */
209              hr = ScriptShape(NULL, &psc, TestItem2, cChars,
210                               cMaxGlyphs, &pItem[0].a,
211                               pwOutGlyphs2, pwLogClust, psva, &pcGlyphs);
212              ok (hr != E_PENDING, "If psc should not be NULL (%08x) and the E_PENDING should be returned\n", hr);
213              ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
214              ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
215              ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
216              for (cnt=0; cnt < cChars && TestItem2[cnt] == pwOutGlyphs2[cnt]; cnt++) {}
217              ok (cnt == cChars, "Translation to place when told not to. WCHAR %d - %04x != %04x\n",
218                            cnt, TestItem2[cnt], pwOutGlyphs2[cnt]);
219              if (hr ==0) {
220                  hr = ScriptPlace(hdc, &psc, pwOutGlyphs2, pcGlyphs, psva, &pItem[0].a, piAdvance,
221                                   pGoffset, pABC);
222                  ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", hr);
223              }
224         }
225         hr = ScriptFreeCache( &psc);
226         ok (!psc, "psc is not null after ScriptFreeCache\n");
227
228     }
229
230     /* This is a valid test that will cause parsing to take place and create 3 script_items   */
231     cInChars = (sizeof(TestItem3)/2)-1;
232     cMaxItems = 255;
233     hr = ScriptItemize(TestItem3, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
234     ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
235     if  (hr == 0)
236         {
237         ok (pcItems == 3, "The number of SCRIPT_ITEMS should be 3 not %d\n", pcItems);
238         if (pcItems > 2)
239         {
240             ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == 6,
241                 "Start pos [0] not = 0 (%d) or end pos [1] not = %d\n",
242                 pItem[0].iCharPos, pItem[1].iCharPos);
243             ok (pItem[1].iCharPos == 6 && pItem[2].iCharPos == 11,
244                 "Start pos [1] not = 6 (%d) or end pos [2] not = 11 (%d)\n",
245                 pItem[1].iCharPos, pItem[2].iCharPos);
246             ok (pItem[2].iCharPos == 11 && pItem[3].iCharPos == cInChars,
247                 "Start pos [2] not = 11 (%d) or end [3] pos not = 14 (%d), cInChars = %d\n",
248                 pItem[2].iCharPos, pItem[3].iCharPos, cInChars);
249         }
250         hr = ScriptFreeCache( &psc);
251         ok (!psc, "psc is not null after ScriptFreeCache\n");
252     }
253
254     /* This is a valid test that will cause parsing to take place and create 3 script_items   */
255     cInChars = (sizeof(TestItem4)/2)-1;
256     cMaxItems = 255;
257     hr = ScriptItemize(TestItem4, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
258     ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
259     if  (hr == 0)
260         {
261         ok (pcItems == 3, "The number of SCRIPT_ITEMS should be 3 not %d\n", pcItems);
262         if (pcItems > 2)
263         {
264             ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == 6,
265                 "Start pos [0] not = 0 (%d) or end pos [1] not = %d\n",
266                 pItem[0].iCharPos, pItem[1].iCharPos);
267             ok (pItem[1].iCharPos == 6 && pItem[2].iCharPos == 11,
268                 "Start pos [1] not = 6 (%d) or end pos [2] not = 11 (%d)\n",
269                 pItem[1].iCharPos, pItem[2].iCharPos);
270             ok (pItem[2].iCharPos == 11 && pItem[3].iCharPos == cInChars,
271                 "Start pos [2] not = 11 (%d) or end [3] pos not = 14 (%d), cInChars = %d\n",
272                 pItem[2].iCharPos, pItem[3].iCharPos, cInChars);
273         }
274         hr = ScriptFreeCache( &psc);
275         ok (!psc, "psc is not null after ScriptFreeCache\n");
276     }
277
278     /*
279      * This test is for when the first unicode character requires bidi support
280      */ 
281     cInChars = (sizeof(TestItem5)-1)/sizeof(WCHAR);
282     hr = ScriptItemize(TestItem5, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
283     ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
284     ok (pcItems == 4, "There should have been 4 items, found %d\n", pcItems);
285     ok (pItem[0].a.s.uBidiLevel == 1, "The first character should have been bidi=1 not %d\n", 
286                                        pItem[0].a.s.uBidiLevel);
287 }
288
289 static void test_ScriptGetCMap(HDC hdc, unsigned short pwOutGlyphs[256])
290 {
291     HRESULT         hr;
292     SCRIPT_CACHE    psc = NULL;
293     int             cInChars;
294     int             cChars;
295     unsigned short  pwOutGlyphs3[256];
296     WCHAR           TestItem1[] = {'T', 'e', 's', 't', 'a', 0}; 
297     DWORD           dwFlags;
298     int             cnt;
299
300     /*  Check to make sure that SCRIPT_CACHE gets allocated ok                     */
301     dwFlags = 0;
302     cInChars = cChars = 5;
303     /* Some sanity checks for ScriptGetCMap */
304
305     hr = ScriptGetCMap(NULL, NULL, NULL, 0, 0, NULL);
306     ok( hr == E_INVALIDARG, "(NULL,NULL,NULL,0,0,NULL), "
307                             "expected E_INVALIDARG, got %08x\n", hr);
308
309     hr = ScriptGetCMap(NULL, NULL, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
310     ok( hr == E_INVALIDARG, "(NULL,NULL,TestItem1, cInChars, dwFlags, pwOutGlyphs3), "
311                             "expected E_INVALIDARG, got %08x\n", hr);
312
313     /* Set psc to NULL, to be able to check if a pointer is returned in psc */
314     psc = NULL;
315     hr = ScriptGetCMap(NULL, &psc, NULL, 0, 0, NULL);
316     ok( hr == E_PENDING, "(NULL,&psc,NULL,0,0NULL), expected E_PENDING, "
317                          "got %08x\n", hr);
318     ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
319
320     /* Set psc to NULL but add hdc, to be able to check if a pointer is returned in psc */
321     psc = NULL;
322     hr = ScriptGetCMap(hdc, &psc, NULL, 0, 0, NULL);
323     ok( hr == S_OK, "ScriptGetCMap(NULL,&psc,NULL,0,0,NULL), expected S_OK, "
324                     "got %08x\n", hr);
325     ok( psc != NULL, "ScritpGetCMap expected psc to be not NULL\n");
326     ScriptFreeCache( &psc);
327
328     /* Set psc to NULL, to be able to check if a pointer is returned in psc */
329     psc = NULL;
330     hr = ScriptGetCMap(NULL, &psc, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
331     ok( hr == E_PENDING, "(NULL,&psc,), expected E_PENDING, got %08x\n", hr);
332     ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
333     /*  Check to see if the results are the same as those returned by ScriptShape  */
334     hr = ScriptGetCMap(hdc, &psc, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
335     ok (hr == 0, "ScriptGetCMap should return 0 not (%08x)\n", hr);
336     ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
337     for (cnt=0; cnt < cChars && pwOutGlyphs[cnt] == pwOutGlyphs3[cnt]; cnt++) {}
338     ok (cnt == cInChars, "Translation not correct. WCHAR %d - %04x != %04x\n",
339                          cnt, pwOutGlyphs[cnt], pwOutGlyphs3[cnt]);
340         
341     hr = ScriptFreeCache( &psc);
342     ok (!psc, "psc is not null after ScriptFreeCache\n");
343
344 }
345
346 static void test_ScriptGetFontProperties(HDC hdc)
347 {
348     HRESULT         hr;
349     SCRIPT_CACHE    psc,old_psc;
350     SCRIPT_FONTPROPERTIES sfp;
351
352     /* Some sanity checks for ScriptGetFontProperties */
353
354     hr = ScriptGetFontProperties(NULL,NULL,NULL);
355     ok( hr == E_INVALIDARG, "(NULL,NULL,NULL), expected E_INVALIDARG, got %08x\n", hr);
356
357     hr = ScriptGetFontProperties(NULL,NULL,&sfp);
358     ok( hr == E_INVALIDARG, "(NULL,NULL,&sfp), expected E_INVALIDARG, got %08x\n", hr);
359
360     /* Set psc to NULL, to be able to check if a pointer is returned in psc */
361     psc = NULL;
362     hr = ScriptGetFontProperties(NULL,&psc,NULL);
363     ok( hr == E_INVALIDARG, "(NULL,&psc,NULL), expected E_INVALIDARG, got %08x\n", hr);
364     ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
365
366     /* Set psc to NULL, to be able to check if a pointer is returned in psc */
367     psc = NULL;
368     hr = ScriptGetFontProperties(NULL,&psc,&sfp);
369     ok( hr == E_PENDING, "(NULL,&psc,&sfp), expected E_PENDING, got %08x\n", hr);
370     ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
371
372     hr = ScriptGetFontProperties(hdc,NULL,NULL);
373     ok( hr == E_INVALIDARG, "(hdc,NULL,NULL), expected E_INVALIDARG, got %08x\n", hr);
374
375     hr = ScriptGetFontProperties(hdc,NULL,&sfp);
376     ok( hr == E_INVALIDARG, "(hdc,NULL,&sfp), expected E_INVALIDARG, got %08x\n", hr);
377
378     /* Set psc to NULL, to be able to check if a pointer is returned in psc */
379     psc = NULL;
380     hr = ScriptGetFontProperties(hdc,&psc,NULL);
381     ok( hr == E_INVALIDARG, "(hdc,&psc,NULL), expected E_INVALIDARG, got %08x\n", hr);
382     ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
383
384     /* Pass an invalid sfp */
385     psc = NULL;
386     sfp.cBytes = sizeof(SCRIPT_FONTPROPERTIES) - 1;
387     hr = ScriptGetFontProperties(hdc,&psc,&sfp);
388     ok( hr == E_INVALIDARG, "(hdc,&psc,&sfp) invalid, expected E_INVALIDARG, got %08x\n", hr);
389     ok( psc != NULL, "Expected a pointer in psc, got NULL\n");
390     ScriptFreeCache(&psc);
391     ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
392
393     /* Give it the correct cBytes, we don't care about what's coming back */
394     sfp.cBytes = sizeof(SCRIPT_FONTPROPERTIES);
395     psc = NULL;
396     hr = ScriptGetFontProperties(hdc,&psc,&sfp);
397     ok( hr == S_OK, "(hdc,&psc,&sfp) partly initialized, expected S_OK, got %08x\n", hr);
398     ok( psc != NULL, "Expected a pointer in psc, got NULL\n");
399
400     /* Save the psc pointer */
401     old_psc = psc;
402     /* Now a NULL hdc again */
403     hr = ScriptGetFontProperties(NULL,&psc,&sfp);
404     ok( hr == S_OK, "(NULL,&psc,&sfp), expected S_OK, got %08x\n", hr);
405     ok( psc == old_psc, "Expected psc not to be changed, was %p is now %p\n", old_psc, psc);
406     ScriptFreeCache(&psc);
407     ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
408 }
409
410 static void test_ScriptTextOut(HDC hdc)
411 {
412     HRESULT         hr;
413
414     int             cInChars;
415     int             cMaxItems;
416     SCRIPT_ITEM     pItem[255];
417     int             pcItems;
418     WCHAR           TestItem1[] = {'T', 'e', 's', 't', 'a', 0}; 
419
420     SCRIPT_CACHE    psc;
421     int             cChars;
422     int             cMaxGlyphs;
423     unsigned short  pwOutGlyphs1[256];
424     WORD            pwLogClust[256];
425     SCRIPT_VISATTR  psva[256];
426     int             pcGlyphs;
427     int             piAdvance[256];
428     GOFFSET         pGoffset[256];
429     ABC             pABC[256];
430     RECT            rect;
431     int             piX;
432     int             iCP = 1;
433     BOOL            fTrailing = FALSE;
434     SCRIPT_LOGATTR  *psla;
435     SCRIPT_LOGATTR  sla[256];
436
437     /* This is a valid test that will cause parsing to take place                             */
438     cInChars = 5;
439     cMaxItems = 255;
440     hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
441     ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
442     /*  This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
443      *  returned.                                                                             */
444     ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
445     if (pcItems > 0)
446         ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
447             "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
448             pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
449
450     /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
451      * ie. ScriptItemize has succeeded and that pItem has been set                            */
452     cInChars = 5;
453     cMaxItems = 255;
454     if (hr == 0) {
455         psc = NULL;                                   /* must be null on first call           */
456         cChars = cInChars;
457         cMaxGlyphs = cInChars;
458         cMaxGlyphs = 256;
459         hr = ScriptShape(hdc, &psc, TestItem1, cChars,
460                          cMaxGlyphs, &pItem[0].a,
461                          pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
462         ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
463         ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
464         ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
465         if (hr ==0) {
466             /* Note hdc is needed as glyph info is not yet in psc                  */
467             hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
468                              pGoffset, pABC);
469             ok (hr == 0, "Should return 0 not (%08x)\n", hr);
470             ScriptFreeCache(&psc);              /* Get rid of psc for next test set */
471             ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
472
473             hr = ScriptTextOut(NULL, NULL, 0, 0, 0, NULL, NULL, NULL, 0, NULL, 0, NULL, NULL, NULL);
474             ok (hr == E_INVALIDARG, "Should return 0 not (%08x)\n", hr);
475
476             hr = ScriptTextOut(NULL, NULL, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
477                                piAdvance, NULL, pGoffset);
478             ok( hr == E_INVALIDARG, "(NULL,NULL,TestItem1, cInChars, dwFlags, pwOutGlyphs3), "
479                                     "expected E_INVALIDARG, got %08x\n", hr);
480
481             /* Set psc to NULL, to be able to check if a pointer is returned in psc */
482             psc = NULL;
483             hr = ScriptTextOut(NULL, &psc, 0, 0, 0, NULL, NULL, NULL, 0, NULL, 0,
484                                NULL, NULL, NULL);
485             ok( hr == E_INVALIDARG, "(NULL,&psc,NULL,0,0,0,NULL,), expected E_INVALIDARG, "
486                                     "got %08x\n", hr);
487             ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
488
489             /* Set psc to NULL, to be able to check if a pointer is returned in psc
490              * hdc is required for this one rather than the usual optional          */
491             psc = NULL;
492             hr = ScriptTextOut(NULL, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
493                                piAdvance, NULL, pGoffset);
494             ok( hr == E_INVALIDARG, "(NULL,&psc,), expected E_INVALIDARG, got %08x\n", hr);
495             ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
496
497             /* Set that is gets a psc and that returns 0 status */
498             hr = ScriptTextOut(hdc, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
499                                piAdvance, NULL, pGoffset);
500             ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
501             ok (psc == NULL, "psc should be null\n");
502
503             /* Test Rect Rgn is acceptable */
504             rect.top = 10;
505             rect.bottom = 20;
506             rect.left = 10;
507             rect.right = 40;
508             hr = ScriptTextOut(hdc, &psc, 0, 0, 0, &rect, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
509                                piAdvance, NULL, pGoffset);
510             ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
511             ok (psc == NULL, "psc should be null\n");
512
513             iCP = 1;
514             hr = ScriptCPtoX(iCP, fTrailing, cChars, pcGlyphs, (const WORD *) &pwLogClust,
515                             (const SCRIPT_VISATTR *) &psva, (const int *)&piAdvance, &pItem[0].a, &piX);
516             ok(hr == S_OK, "ScriptCPtoX Stub should return S_OK not %08x\n", hr);
517
518             psla = (SCRIPT_LOGATTR *)&sla;
519             hr = ScriptBreak(TestItem1, cChars, &pItem[0].a, psla);
520             ok(hr == S_OK, "ScriptBreak Stub should return S_OK not %08x\n", hr);
521
522             /* Clean up and go   */
523             ScriptFreeCache(&psc);
524             ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
525         }
526     }
527 }
528
529 static void test_ScriptTextOut2(HDC hdc)
530 {
531 /*  Intent is to validate that the HDC passed into ScriptTextOut is
532  *  used instead of the (possibly) invalid cached one
533  */
534     HRESULT         hr;
535
536     HDC             hdc1, hdc2;
537     int             cInChars;
538     int             cMaxItems;
539     SCRIPT_ITEM     pItem[255];
540     int             pcItems;
541     WCHAR           TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
542
543     SCRIPT_CACHE    psc;
544     int             cChars;
545     int             cMaxGlyphs;
546     unsigned short  pwOutGlyphs1[256];
547     WORD            pwLogClust[256];
548     SCRIPT_VISATTR  psva[256];
549     int             pcGlyphs;
550     int             piAdvance[256];
551     GOFFSET         pGoffset[256];
552     ABC             pABC[256];
553
554     /* Create an extra DC that will be used until the ScriptTextOut */
555     hdc1 = CreateCompatibleDC(hdc);
556     ok (hdc1 != 0, "CreateCompatibleDC failed to create a DC\n");
557     hdc2 = CreateCompatibleDC(hdc);
558     ok (hdc2 != 0, "CreateCompatibleDC failed to create a DC\n");
559
560     /* This is a valid test that will cause parsing to take place                             */
561     cInChars = 5;
562     cMaxItems = 255;
563     hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
564     ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
565     /*  This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
566      *  returned.                                                                             */
567     ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
568     if (pcItems > 0)
569         ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
570             "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
571             pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
572
573     /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
574      * ie. ScriptItemize has succeeded and that pItem has been set                            */
575     cInChars = 5;
576     cMaxItems = 255;
577     if (hr == 0) {
578         psc = NULL;                                   /* must be null on first call           */
579         cChars = cInChars;
580         cMaxGlyphs = cInChars;
581         cMaxGlyphs = 256;
582         hr = ScriptShape(hdc2, &psc, TestItem1, cChars,
583                          cMaxGlyphs, &pItem[0].a,
584                          pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
585         ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
586         ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
587         ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
588         if (hr ==0) {
589             /* Note hdc is needed as glyph info is not yet in psc                  */
590             hr = ScriptPlace(hdc2, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
591                              pGoffset, pABC);
592             ok (hr == 0, "Should return 0 not (%08x)\n", hr);
593
594             /*   key part!!!   cached dc is being deleted  */
595             hr = DeleteDC(hdc2);
596             ok(hr == 1, "DeleteDC should return 1 not %08x\n", hr);
597
598             /* At this point the cached hdc (hdc2) has been destroyed,
599              * however, we are passing in a *real* hdc (the original hdc).
600              * The text should be written to that DC
601              */
602             hr = ScriptTextOut(hdc1, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
603                                piAdvance, NULL, pGoffset);
604             ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
605             ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
606
607             DeleteDC(hdc1);
608
609             /* Clean up and go   */
610             ScriptFreeCache(&psc);
611             ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
612         }
613     }
614 }
615
616 static void test_ScriptXtoX(void)
617 /****************************************************************************************
618  *  This routine tests the ScriptXtoCP and ScriptCPtoX functions using static variables *
619  ****************************************************************************************/
620 {
621     int iX, iCP;
622     int cChars;
623     int cGlyphs;
624     WORD pwLogClust[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
625     SCRIPT_VISATTR psva[10];
626     int piAdvance[10] = {200, 190, 210, 180, 170, 204, 189, 195, 212, 203};
627     SCRIPT_ANALYSIS psa;
628     int piCP, piX;
629     int piTrailing;
630     BOOL fTrailing;
631     HRESULT hr;
632
633     iX = -1;
634     cChars = 10;
635     cGlyphs = 10;
636     hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &psa, &piCP, &piTrailing);
637     ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
638     ok(piCP == -1, "Negative iX should return piCP=-1 not %d\n", piCP);
639     ok(piTrailing == TRUE, "Negative iX should return piTrailing=TRUE not %d\n", piTrailing);
640     iX = 1954;
641     cChars = 10;
642     cGlyphs = 10;
643     hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &psa, &piCP, &piTrailing);
644     ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
645     ok(piCP == 10, "Excessive iX should return piCP=10 not %d\n", piCP);
646     ok(piTrailing == FALSE, "Excessive iX should return piTrailing=FALSE not %d\n", piTrailing);
647     iX = 779;
648     cChars = 10;
649     cGlyphs = 10;
650     hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &psa, &piCP, &piTrailing);
651     ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
652     ok(piCP == 3, "iX=%d should return piCP=3 not %d\n", iX, piCP);
653     ok(piTrailing == 1, "iX=%d should return piTrailing=1 not %d\n", iX, piTrailing);
654     iX = 780;
655     cChars = 10;
656     cGlyphs = 10;
657     hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &psa, &piCP, &piTrailing);
658     ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
659     ok(piCP == 3, "iX=%d should return piCP=3 not %d\n", iX, piCP);
660     ok(piTrailing == 1, "iX=%d should return piTrailing=1 not %d\n", iX, piTrailing);
661     iX = 868;
662     cChars = 10;
663     cGlyphs = 10;
664     hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &psa, &piCP, &piTrailing);
665     ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
666     ok(piCP == 4, "iX=%d should return piCP=4 not %d\n", iX, piCP);
667
668     iX = 0;
669     cChars = 10;
670     cGlyphs = 10;
671     hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &psa, &piCP, &piTrailing);
672     ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
673     ok(piCP == 0, "iX=%d should return piCP=0 not %d\n", iX, piCP);
674     iX = 195;
675     cChars = 10;
676     cGlyphs = 10;
677     hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &psa, &piCP, &piTrailing);
678     ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
679     ok(piCP == 0, "iX=%d should return piCP=0 not %d\n", iX, piCP);
680     iX = 196;
681     cChars = 10;
682     cGlyphs = 10;
683     hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &psa, &piCP, &piTrailing);
684     ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
685     ok(piCP == 1, "iX=%d should return piCP=1 not %d\n", iX, piCP);
686
687     iCP=5;
688     fTrailing = FALSE;
689     cChars = 10;
690     cGlyphs = 10;
691     hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance, &psa, &piX);
692     ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
693     ok(piX == 976, "iCP=%d should return piX=976 not %d\n", iCP, piX);
694     iCP=5;
695     fTrailing = TRUE;
696     cChars = 10;
697     cGlyphs = 10;
698     hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance, &psa, &piX);
699     ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
700     ok(piX == 1171, "iCP=%d should return piX=1171 not %d\n", iCP, piX);   
701     iCP=6;
702     fTrailing = FALSE;
703     cChars = 10;
704     cGlyphs = 10;
705     hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance, &psa, &piX);
706     ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
707     ok(piX == 1171, "iCP=%d should return piX=1171 not %d\n", iCP, piX);
708     iCP=11;
709     fTrailing = FALSE;
710     cChars = 10;
711     cGlyphs = 10;
712     hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance, &psa, &piX);
713     ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
714     ok(piX == 1953, "iCP=%d should return piX=1953 not %d\n", iCP, piX);
715     iCP=11;
716     fTrailing = TRUE;
717     cChars = 10;
718     cGlyphs = 10;
719     hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance, &psa, &piX);
720     ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
721     ok(piX == 1953, "iCP=%d should return piX=1953 not %d\n", iCP, piX); 
722
723 }
724
725 static void test_ScriptString(HDC hdc)
726 {
727 /*******************************************************************************************
728  *
729  * This set of tests are for the string functions of uniscribe.  The ScriptStringAnalyse
730  * function allocates memory pointed to by the SCRIPT_STRING_ANALYSIS ssa pointer.  This
731  * memory if freed by ScriptStringFree.  There needs to be a valid hdc for this as
732  * ScriptStringAnalyse calls ScriptSItemize, ScriptShape and ScriptPlace which require it.
733  *
734  */
735
736     HRESULT         hr;
737     WCHAR           teststr[] = {'T','e','s','t','1',' ','a','2','b','3', '\0'};
738     int             len = (sizeof(teststr) / sizeof(WCHAR)) - 1;
739     int             Glyphs = len * 2 + 16;
740     int             Charset;
741     DWORD           Flags = SSA_GLYPHS;
742     int             ReqWidth = 100;
743     SCRIPT_CONTROL  Control;
744     SCRIPT_STATE    State;
745     const int       Dx[5] = {10, 10, 10, 10, 10};
746     SCRIPT_TABDEF   Tabdef;
747     const BYTE      InClass = 0;
748     SCRIPT_STRING_ANALYSIS ssa = NULL;
749
750     int             X = 10; 
751     int             Y = 100;
752     UINT            Options = 0; 
753     const RECT      rc = {0, 50, 100, 100}; 
754     int             MinSel = 0;
755     int             MaxSel = 0;
756     BOOL            Disabled = FALSE;
757     const int      *clip_len;
758     int            i;
759     UINT           *order;
760
761
762     Charset = -1;     /* this flag indicates unicode input */
763     /* Test without hdc to get E_PENDING */
764     hr = ScriptStringAnalyse( NULL, teststr, len, Glyphs, Charset, Flags,
765                              ReqWidth, &Control, &State, Dx, &Tabdef,
766                              &InClass, &ssa);
767     ok(hr == E_PENDING, "ScriptStringAnalyse Stub should return E_PENDING not %08x\n", hr);
768
769     /* test with hdc, this should be a valid test  */
770     hr = ScriptStringAnalyse( hdc, teststr, len, Glyphs, Charset, Flags,
771                               ReqWidth, &Control, &State, Dx, &Tabdef,
772                               &InClass, &ssa);
773     ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
774     ScriptStringFree(&ssa);
775
776     /* test makes sure that a call with a valid pssa still works */
777     hr = ScriptStringAnalyse( hdc, teststr, len, Glyphs, Charset, Flags,
778                               ReqWidth, &Control, &State, Dx, &Tabdef,
779                               &InClass, &ssa);
780     ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
781     ok(ssa != NULL, "ScriptStringAnalyse pssa should not be NULL\n");
782
783     if (hr == S_OK)
784     {
785         hr = ScriptStringOut(ssa, X, Y, Options, &rc, MinSel, MaxSel, Disabled);
786         ok(hr == S_OK, "ScriptStringOut should return S_OK not %08x\n", hr);
787     }
788
789      clip_len = ScriptString_pcOutChars(ssa);
790      ok(*clip_len == len, "ScriptString_pcOutChars failed, got %d, expected %d\n", *clip_len, len);
791
792      order = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *clip_len * sizeof(UINT));
793      hr = ScriptStringGetOrder(ssa, order);
794      ok(hr == S_OK, "ScriptStringGetOrder failed, got %08x, expected S_OK\n", hr);
795
796      for (i = 0; i < *clip_len; i++) ok(order[i] == i, "%d: got %d expected %d\n", i, order[i], i);
797      HeapFree(GetProcessHeap(), 0, order);
798
799      hr = ScriptStringFree(&ssa);
800      ok(hr == S_OK, "ScriptStringFree should return S_OK not %08x\n", hr);
801 }
802
803 static void test_ScriptStringXtoCP_CPtoX(HDC hdc)
804 {
805 /*****************************************************************************************
806  *
807  * This test is for the ScriptStringXtoCP and ScriptStringXtoCP functions.  Due to the
808  * nature of the fonts between Windows and Wine, the test is implemented by generating
809  * values using one one function then checking the output of the second.  In this way
810  * the validity of the functions is established using Windows as a base and confirming
811  * similar behaviour in wine.
812  */
813
814     HRESULT         hr;
815     WCHAR           teststr1[] = {'T', 'e', 's', 't', 'e', '1', '2', ' ', 'a', '\0'};
816     void            *String = (WCHAR *) &teststr1;      /* ScriptStringAnalysis needs void */
817     int             String_len = (sizeof(teststr1)/sizeof(WCHAR))-1;
818     int             Glyphs = String_len * 2 + 16;       /* size of buffer as recommended  */
819     int             Charset = -1;                       /* unicode                        */
820     DWORD           Flags = SSA_GLYPHS;
821     int             ReqWidth = 100;
822     SCRIPT_CONTROL  Control;
823     SCRIPT_STATE    State;
824     SCRIPT_TABDEF   Tabdef;
825     const BYTE      InClass = 0;
826     SCRIPT_STRING_ANALYSIS ssa = NULL;
827
828     int             Ch;                                  /* Character position in string */
829     int             iTrailing;
830     int             Cp;                                  /* Character position in string */
831     int             X;
832     BOOL            fTrailing;
833
834     /* Test with hdc, this should be a valid test
835      * Here we generate an SCRIPT_STRING_ANALYSIS that will be used as input to the
836      * following character positions to X and X to character position functions.
837      */
838     hr = ScriptStringAnalyse( hdc, String, String_len, Glyphs, Charset, Flags,
839                               ReqWidth, &Control, &State, NULL, &Tabdef,
840                               &InClass, &ssa);
841     ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
842     ok(ssa != NULL, "ScriptStringAnalyse ssa should not be NULL\n");
843     if  (hr == 0)
844     {
845         /*
846          * Loop to generate character positions to provide starting positions for the
847          * ScriptStringCPtoX and ScriptStringXtoCP functions
848          */
849         for (Cp = 0; Cp < String_len; Cp++)
850         {
851             /* The fTrailing flag is used to indicate whether the X being returned is at
852              * the beginning or the end of the character. What happens here is that if
853              * fTrailing indicates the end of the character, ie. FALSE, then ScriptStringXtoCP
854              * returns the beginning of the next character and iTrailing is FALSE.  So for this
855              * loop iTrailing will be FALSE in both cases.
856              */
857             fTrailing = FALSE;
858             hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
859             ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
860             hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
861             ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
862             ok(Cp == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp, Ch, X);
863             ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n", 
864                                   iTrailing, X);
865             fTrailing = TRUE;
866             hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
867             ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
868             hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
869             ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
870
871             /*
872              * Check that character position returned by ScriptStringXtoCP in Ch matches the
873              * one input to ScriptStringCPtoX.  This means that the Cp to X position and back
874              * again works
875              */
876             ok(Cp + 1 == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp + 1, Ch, X);
877             ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n", 
878                                    iTrailing, X);
879         }
880         /*
881          * This test is to check that if the X position is just inside the trailing edge of the
882          * character then iTrailing will indicate the trailing edge, ie. TRUE
883          */
884         fTrailing = TRUE;
885         Cp = 3;
886         hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
887         ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
888         X--;                                /* put X just inside the trailing edge */
889         hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
890         ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
891         ok(Cp == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp, Ch, X);
892         ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n", 
893                                   iTrailing, X);
894
895         /*
896          * This test is to check that if the X position is just outside the trailing edge of the
897          * character then iTrailing will indicate the leading edge, ie. FALSE, and Ch will indicate
898          * the next character, ie. Cp + 1 
899          */
900         fTrailing = TRUE;
901         Cp = 3;
902         hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
903         ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
904         X++;                                /* put X just outside the trailing edge */
905         hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
906         ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
907         ok(Cp + 1 == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp + 1, Ch, X);
908         ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n", 
909                                   iTrailing, X);
910
911         /*
912          * This test is to check that if the X position is just outside the leading edge of the
913          * character then iTrailing will indicate the trailing edge, ie. TRUE, and Ch will indicate
914          * the next character down , ie. Cp - 1 
915          */
916         fTrailing = FALSE;
917         Cp = 3;
918         hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
919         ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
920         X--;                                /* put X just outside the leading edge */
921         hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
922         ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
923         ok(Cp - 1 == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp - 1, Ch, X);
924         ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n", 
925                                   iTrailing, X);
926
927         /*
928          * Cleanup the SSA for the next round of tests
929          */
930         hr = ScriptStringFree(&ssa);
931         ok(hr == S_OK, "ScriptStringFree should return S_OK not %08x\n", hr);
932
933         /*
934          * Test to see that exceeding the number of chars returns E_INVALIDARG.  First
935          * generate an SSA for the subsequent tests.
936          */
937         hr = ScriptStringAnalyse( hdc, String, String_len, Glyphs, Charset, Flags,
938                                   ReqWidth, &Control, &State, NULL, &Tabdef,
939                                   &InClass, &ssa);
940         ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
941
942         /*
943          * When ScriptStringCPtoX is called with a character position Cp that exceeds the
944          * string length, return E_INVALIDARG.  This also invalidates the ssa so a 
945          * ScriptStringFree should also fail.
946          */
947         fTrailing = FALSE;
948         Cp = String_len + 1; 
949         hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
950         ok(hr == E_INVALIDARG, "ScriptStringCPtoX should return E_INVALIDARG not %08x\n", hr);
951
952         hr = ScriptStringFree(&ssa);
953         /*
954          * ScriptStringCPtoX should free ssa, hence ScriptStringFree should fail
955          */
956         ok(hr == E_INVALIDARG ||
957            hr == E_FAIL, /* win2k3 */
958            "ScriptStringFree should return E_INVALIDARG or E_FAIL not %08x\n", hr);
959     }
960 }
961
962 static void test_ScriptCacheGetHeight(HDC hdc)
963 {
964     HRESULT hr;
965     SCRIPT_CACHE sc = NULL;
966     LONG height;
967
968     hr = ScriptCacheGetHeight(NULL, NULL, NULL);
969     ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
970
971     hr = ScriptCacheGetHeight(NULL, &sc, NULL);
972     ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
973
974     hr = ScriptCacheGetHeight(NULL, &sc, &height);
975     ok(hr == E_PENDING, "expected E_PENDING, got 0x%08x\n", hr);
976
977     height = 0;
978
979     hr = ScriptCacheGetHeight(hdc, &sc, &height);
980     ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
981     ok(height > 0, "expected height > 0\n");
982
983     ScriptFreeCache(&sc);
984 }
985
986 static void test_ScriptGetGlyphABCWidth(HDC hdc)
987 {
988     HRESULT hr;
989     SCRIPT_CACHE sc = NULL;
990     ABC abc;
991
992     hr = ScriptGetGlyphABCWidth(NULL, NULL, 'a', NULL);
993     ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
994
995     hr = ScriptGetGlyphABCWidth(NULL, &sc, 'a', NULL);
996     ok(hr == E_PENDING, "expected E_PENDING, got 0x%08x\n", hr);
997
998     if (0) {    /* crashes on WinXP */
999     hr = ScriptGetGlyphABCWidth(hdc, &sc, 'a', NULL);
1000     ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
1001     }
1002
1003     hr = ScriptGetGlyphABCWidth(hdc, &sc, 'a', &abc);
1004     ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1005
1006     ScriptFreeCache(&sc);
1007 }
1008
1009 static void test_ScriptLayout(void)
1010 {
1011     HRESULT hr;
1012     static const BYTE levels[][5] =
1013     {
1014         { 0, 0, 0, 0, 0 },
1015         { 1, 1, 1, 1, 1 },
1016         { 2, 2, 2, 2, 2 },
1017         { 3, 3, 3, 3, 3 },
1018     };
1019     static const int expect[][5] =
1020     {
1021         { 0, 1, 2, 3, 4 },
1022         { 4, 3, 2, 1, 0 },
1023         { 0, 1, 2, 3, 4 },
1024         { 4, 3, 2, 1, 0 }
1025     };
1026     int i, j, vistolog[sizeof(levels[0])], logtovis[sizeof(levels[0])];
1027
1028     hr = ScriptLayout(sizeof(levels[0]), NULL, vistolog, logtovis);
1029     ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
1030
1031     hr = ScriptLayout(sizeof(levels[0]), levels[0], NULL, NULL);
1032     ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
1033
1034     for (i = 0; i < sizeof(levels)/sizeof(levels[0]); i++)
1035     {
1036         hr = ScriptLayout(sizeof(levels[0]), levels[i], vistolog, logtovis);
1037         ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1038
1039         for (j = 0; j < sizeof(levels[i]); j++)
1040         {
1041             ok(expect[i][j] == vistolog[j],
1042                "failure: levels[%d][%d] = %d, vistolog[%d] = %d\n",
1043                i, j, levels[i][j], j, vistolog[j] );
1044         }
1045
1046         for (j = 0; j < sizeof(levels[i]); j++)
1047         {
1048             ok(expect[i][j] == logtovis[j],
1049                "failure: levels[%d][%d] = %d, logtovis[%d] = %d\n",
1050                i, j, levels[i][j], j, logtovis[j] );
1051         }
1052     }
1053 }
1054
1055 static const struct
1056 {
1057     LGRPID group;
1058     LCID lcid;
1059     SCRIPT_DIGITSUBSTITUTE sds;
1060     DWORD uDefaultLanguage;
1061     DWORD fContextDigits;
1062     WORD fDigitSubstitute;
1063 }
1064 subst_data[] =
1065 {
1066     { 0x01, 0x00403, { 9, 3, 1, 0 }, 9, 0, 0 },
1067     { 0x01, 0x00406, { 9, 6, 1, 0 }, 9, 0, 0 },
1068     { 0x01, 0x00407, { 9, 7, 1, 0 }, 9, 0, 0 },
1069     { 0x01, 0x00409, { 9, 9, 1, 0 }, 9, 0, 0 },
1070     { 0x01, 0x0040a, { 9, 10, 1, 0 }, 9, 0, 0 },
1071     { 0x01, 0x0040b, { 9, 11, 1, 0 }, 9, 0, 0 },
1072     { 0x01, 0x0040c, { 9, 12, 1, 0 }, 9, 0, 0 },
1073     { 0x01, 0x0040f, { 9, 15, 1, 0 }, 9, 0, 0 },
1074     { 0x01, 0x00410, { 9, 16, 1, 0 }, 9, 0, 0 },
1075     { 0x01, 0x00413, { 9, 19, 1, 0 }, 9, 0, 0 },
1076     { 0x01, 0x00414, { 9, 20, 1, 0 }, 9, 0, 0 },
1077     { 0x01, 0x00416, { 9, 22, 1, 0 }, 9, 0, 0 },
1078     { 0x01, 0x0041d, { 9, 29, 1, 0 }, 9, 0, 0 },
1079     { 0x01, 0x00421, { 9, 33, 1, 0 }, 9, 0, 0 },
1080     { 0x01, 0x0042d, { 9, 45, 1, 0 }, 9, 0, 0 },
1081     { 0x01, 0x00432, { 9, 50, 1, 0 }, 9, 0, 0 },
1082     { 0x01, 0x00434, { 9, 52, 1, 0 }, 9, 0, 0 },
1083     { 0x01, 0x00435, { 9, 53, 1, 0 }, 9, 0, 0 },
1084     { 0x01, 0x00436, { 9, 54, 1, 0 }, 9, 0, 0 },
1085     { 0x01, 0x00438, { 9, 56, 1, 0 }, 9, 0, 0 },
1086     { 0x01, 0x0043a, { 9, 58, 1, 0 }, 9, 0, 0 },
1087     { 0x01, 0x0043b, { 9, 59, 1, 0 }, 9, 0, 0 },
1088     { 0x01, 0x0043e, { 9, 62, 1, 0 }, 9, 0, 0 },
1089     { 0x01, 0x00441, { 9, 65, 1, 0 }, 9, 0, 0 },
1090     { 0x01, 0x00452, { 9, 82, 1, 0 }, 9, 0, 0 },
1091     { 0x01, 0x00456, { 9, 86, 1, 0 }, 9, 0, 0 },
1092     { 0x01, 0x0046b, { 9, 107, 1, 0 }, 9, 0, 0 },
1093     { 0x01, 0x0046c, { 9, 108, 1, 0 }, 9, 0, 0 },
1094     { 0x01, 0x00481, { 9, 129, 1, 0 }, 9, 0, 0 },
1095     { 0x01, 0x00807, { 9, 7, 1, 0 }, 9, 0, 0 },
1096     { 0x01, 0x00809, { 9, 9, 1, 0 }, 9, 0, 0 },
1097     { 0x01, 0x0080a, { 9, 10, 1, 0 }, 9, 0, 0 },
1098     { 0x01, 0x0080c, { 9, 12, 1, 0 }, 9, 0, 0 },
1099     { 0x01, 0x00810, { 9, 16, 1, 0 }, 9, 0, 0 },
1100     { 0x01, 0x00813, { 9, 19, 1, 0 }, 9, 0, 0 },
1101     { 0x01, 0x00814, { 9, 20, 1, 0 }, 9, 0, 0 },
1102     { 0x01, 0x00816, { 9, 22, 1, 0 }, 9, 0, 0 },
1103     { 0x01, 0x0081d, { 9, 29, 1, 0 }, 9, 0, 0 },
1104     { 0x01, 0x0083b, { 9, 59, 1, 0 }, 9, 0, 0 },
1105     { 0x01, 0x0083e, { 9, 62, 1, 0 }, 9, 0, 0 },
1106     { 0x01, 0x0086b, { 9, 107, 1, 0 }, 9, 0, 0 },
1107     { 0x01, 0x00c07, { 9, 7, 1, 0 }, 9, 0, 0 },
1108     { 0x01, 0x00c09, { 9, 9, 1, 0 }, 9, 0, 0 },
1109     { 0x01, 0x00c0a, { 9, 10, 1, 0 }, 9, 0, 0 },
1110     { 0x01, 0x00c0c, { 9, 12, 1, 0 }, 9, 0, 0 },
1111     { 0x01, 0x00c3b, { 9, 59, 1, 0 }, 9, 0, 0 },
1112     { 0x01, 0x00c6b, { 9, 107, 1, 0 }, 9, 0, 0 },
1113     { 0x01, 0x01007, { 9, 7, 1, 0 }, 9, 0, 0 },
1114     { 0x01, 0x01009, { 9, 9, 1, 0 }, 9, 0, 0 },
1115     { 0x01, 0x0100a, { 9, 10, 1, 0 }, 9, 0, 0 },
1116     { 0x01, 0x0100c, { 9, 12, 1, 0 }, 9, 0, 0 },
1117     { 0x01, 0x0103b, { 9, 59, 1, 0 }, 9, 0, 0 },
1118     { 0x01, 0x01407, { 9, 7, 1, 0 }, 9, 0, 0 },
1119     { 0x01, 0x01409, { 9, 9, 1, 0 }, 9, 0, 0 },
1120     { 0x01, 0x0140a, { 9, 10, 1, 0 }, 9, 0, 0 },
1121     { 0x01, 0x0140c, { 9, 12, 1, 0 }, 9, 0, 0 },
1122     { 0x01, 0x0143b, { 9, 59, 1, 0 }, 9, 0, 0 },
1123     { 0x01, 0x01809, { 9, 9, 1, 0 }, 9, 0, 0 },
1124     { 0x01, 0x0180a, { 9, 10, 1, 0 }, 9, 0, 0 },
1125     { 0x01, 0x0180c, { 9, 12, 1, 0 }, 9, 0, 0 },
1126     { 0x01, 0x0183b, { 9, 59, 1, 0 }, 9, 0, 0 },
1127     { 0x01, 0x01c09, { 9, 9, 1, 0 }, 9, 0, 0 },
1128     { 0x01, 0x01c0a, { 9, 10, 1, 0 }, 9, 0, 0 },
1129     { 0x01, 0x01c3b, { 9, 59, 1, 0 }, 9, 0, 0 },
1130     { 0x01, 0x02009, { 9, 9, 1, 0 }, 9, 0, 0 },
1131     { 0x01, 0x0200a, { 9, 10, 1, 0 }, 9, 0, 0 },
1132     { 0x01, 0x0203b, { 9, 59, 1, 0 }, 9, 0, 0 },
1133     { 0x01, 0x02409, { 9, 9, 1, 0 }, 9, 0, 0 },
1134     { 0x01, 0x0240a, { 9, 10, 1, 0 }, 9, 0, 0 },
1135     { 0x01, 0x0243b, { 9, 59, 1, 0 }, 9, 0, 0 },
1136     { 0x01, 0x02809, { 9, 9, 1, 0 }, 9, 0, 0 },
1137     { 0x01, 0x0280a, { 9, 10, 1, 0 }, 9, 0, 0 },
1138     { 0x01, 0x02c09, { 9, 9, 1, 0 }, 9, 0, 0 },
1139     { 0x01, 0x02c0a, { 9, 10, 1, 0 }, 9, 0, 0 },
1140     { 0x01, 0x03009, { 9, 9, 1, 0 }, 9, 0, 0 },
1141     { 0x01, 0x0300a, { 9, 10, 1, 0 }, 9, 0, 0 },
1142     { 0x01, 0x03409, { 9, 9, 1, 0 }, 9, 0, 0 },
1143     { 0x01, 0x0340a, { 9, 10, 1, 0 }, 9, 0, 0 },
1144     { 0x01, 0x0380a, { 9, 10, 1, 0 }, 9, 0, 0 },
1145     { 0x01, 0x03c0a, { 9, 10, 1, 0 }, 9, 0, 0 },
1146     { 0x01, 0x0400a, { 9, 10, 1, 0 }, 9, 0, 0 },
1147     { 0x01, 0x0440a, { 9, 10, 1, 0 }, 9, 0, 0 },
1148     { 0x01, 0x0480a, { 9, 10, 1, 0 }, 9, 0, 0 },
1149     { 0x01, 0x04c0a, { 9, 10, 1, 0 }, 9, 0, 0 },
1150     { 0x01, 0x0500a, { 9, 10, 1, 0 }, 9, 0, 0 },
1151     { 0x01, 0x10407, { 9, 7, 1, 0 }, 9, 0, 0 },
1152     { 0x02, 0x00405, { 9, 5, 1, 0 }, 9, 0, 0 },
1153     { 0x02, 0x0040e, { 9, 14, 1, 0 }, 9, 0, 0 },
1154     { 0x02, 0x00415, { 9, 21, 1, 0 }, 9, 0, 0 },
1155     { 0x02, 0x00418, { 9, 24, 1, 0 }, 9, 0, 0 },
1156     { 0x02, 0x0041a, { 9, 26, 1, 0 }, 9, 0, 0 },
1157     { 0x02, 0x0041b, { 9, 27, 1, 0 }, 9, 0, 0 },
1158     { 0x02, 0x0041c, { 9, 28, 1, 0 }, 9, 0, 0 },
1159     { 0x02, 0x00424, { 9, 36, 1, 0 }, 9, 0, 0 },
1160     { 0x02, 0x0081a, { 9, 26, 1, 0 }, 9, 0, 0 },
1161     { 0x02, 0x0101a, { 9, 26, 1, 0 }, 9, 0, 0 },
1162     { 0x02, 0x0141a, { 9, 26, 1, 0 }, 9, 0, 0 },
1163     { 0x02, 0x0181a, { 9, 26, 1, 0 }, 9, 0, 0 },
1164     { 0x02, 0x1040e, { 9, 14, 1, 0 }, 9, 0, 0 },
1165     { 0x03, 0x00425, { 9, 37, 1, 0 }, 9, 0, 0 },
1166     { 0x03, 0x00426, { 9, 38, 1, 0 }, 9, 0, 0 },
1167     { 0x03, 0x00427, { 9, 39, 1, 0 }, 9, 0, 0 },
1168     { 0x04, 0x00408, { 9, 8, 1, 0 }, 9, 0, 0 },
1169     { 0x05, 0x00402, { 9, 2, 1, 0 }, 9, 0, 0 },
1170     { 0x05, 0x00419, { 9, 25, 1, 0 }, 9, 0, 0 },
1171     { 0x05, 0x00422, { 9, 34, 1, 0 }, 9, 0, 0 },
1172     { 0x05, 0x00423, { 9, 35, 1, 0 }, 9, 0, 0 },
1173     { 0x05, 0x0042f, { 9, 47, 1, 0 }, 9, 0, 0 },
1174     { 0x05, 0x0043f, { 9, 63, 1, 0 }, 9, 0, 0 },
1175     { 0x05, 0x00440, { 9, 64, 1, 0 }, 9, 0, 0 },
1176     { 0x05, 0x00444, { 9, 68, 1, 0 }, 9, 0, 0 },
1177     { 0x05, 0x00450, { 9, 80, 1, 0 }, 9, 0, 0 },
1178     { 0x05, 0x0082c, { 9, 44, 1, 0 }, 9, 0, 0 },
1179     { 0x05, 0x00843, { 9, 67, 1, 0 }, 9, 0, 0 },
1180     { 0x05, 0x00c1a, { 9, 26, 1, 0 }, 9, 0, 0 },
1181     { 0x05, 0x01c1a, { 9, 26, 1, 0 }, 9, 0, 0 },
1182     { 0x06, 0x0041f, { 9, 31, 1, 0 }, 9, 0, 0 },
1183     { 0x06, 0x0042c, { 9, 44, 1, 0 }, 9, 0, 0 },
1184     { 0x06, 0x00443, { 9, 67, 1, 0 }, 9, 0, 0 },
1185     { 0x07, 0x00411, { 9, 17, 1, 0 }, 9, 0, 0 },
1186     { 0x08, 0x00412, { 9, 18, 1, 0 }, 9, 0, 0 },
1187     { 0x09, 0x00404, { 9, 4, 1, 0 }, 9, 0, 0 },
1188     { 0x09, 0x00c04, { 9, 4, 1, 0 }, 9, 0, 0 },
1189     { 0x09, 0x01404, { 9, 4, 1, 0 }, 9, 0, 0 },
1190     { 0x09, 0x21404, { 9, 4, 1, 0 }, 9, 0, 0 },
1191     { 0x09, 0x30404, { 9, 4, 1, 0 }, 9, 0, 0 },
1192     { 0x0a, 0x00804, { 9, 4, 1, 0 }, 9, 0, 0 },
1193     { 0x0a, 0x01004, { 9, 4, 1, 0 }, 9, 0, 0 },
1194     { 0x0a, 0x20804, { 9, 4, 1, 0 }, 9, 0, 0 },
1195     { 0x0a, 0x21004, { 9, 4, 1, 0 }, 9, 0, 0 },
1196     { 0x0b, 0x0041e, { 9, 30, 1, 0 }, 9, 0, 0 },
1197     { 0x0c, 0x0040d, { 9, 13, 1, 0 }, 9, 0, 0 },
1198     { 0x0d, 0x00401, { 1, 1, 0, 0 }, 9, 0, 0 },
1199     { 0x0d, 0x00420, { 9, 32, 1, 0 }, 9, 0, 0 },
1200     { 0x0d, 0x00429, { 41, 41, 0, 0 }, 9, 0, 0 },
1201     { 0x0d, 0x0045a, { 9, 90, 1, 0 }, 9, 0, 0 },
1202     { 0x0d, 0x00465, { 9, 101, 1, 0 }, 9, 0, 0 },
1203     { 0x0d, 0x00801, { 1, 1, 0, 0 }, 9, 0, 0 },
1204     { 0x0d, 0x00c01, { 1, 1, 0, 0 }, 9, 0, 0 },
1205     { 0x0d, 0x01001, { 1, 1, 0, 0 }, 9, 0, 0 },
1206     { 0x0d, 0x01401, { 1, 1, 0, 0 }, 9, 0, 0 },
1207     { 0x0d, 0x01801, { 1, 1, 0, 0 }, 9, 0, 0 },
1208     { 0x0d, 0x01c01, { 1, 1, 0, 0 }, 9, 0, 0 },
1209     { 0x0d, 0x02001, { 1, 1, 0, 0 }, 9, 0, 0 },
1210     { 0x0d, 0x02401, { 1, 1, 0, 0 }, 9, 0, 0 },
1211     { 0x0d, 0x02801, { 1, 1, 0, 0 }, 9, 0, 0 },
1212     { 0x0d, 0x02c01, { 1, 1, 0, 0 }, 9, 0, 0 },
1213     { 0x0d, 0x03001, { 1, 1, 0, 0 }, 9, 0, 0 },
1214     { 0x0d, 0x03401, { 1, 1, 0, 0 }, 9, 0, 0 },
1215     { 0x0d, 0x03801, { 1, 1, 0, 0 }, 9, 0, 0 },
1216     { 0x0d, 0x03c01, { 1, 1, 0, 0 }, 9, 0, 0 },
1217     { 0x0d, 0x04001, { 1, 1, 0, 0 }, 9, 0, 0 },
1218     { 0x0e, 0x0042a, { 9, 42, 1, 0 }, 9, 0, 0 },
1219     { 0x0f, 0x00439, { 9, 57, 1, 0 }, 9, 0, 0 },
1220     { 0x0f, 0x00446, { 9, 70, 1, 0 }, 9, 0, 0 },
1221     { 0x0f, 0x00447, { 9, 71, 1, 0 }, 9, 0, 0 },
1222     { 0x0f, 0x00449, { 9, 73, 1, 0 }, 9, 0, 0 },
1223     { 0x0f, 0x0044a, { 9, 74, 1, 0 }, 9, 0, 0 },
1224     { 0x0f, 0x0044b, { 9, 75, 1, 0 }, 9, 0, 0 },
1225     { 0x0f, 0x0044e, { 9, 78, 1, 0 }, 9, 0, 0 },
1226     { 0x0f, 0x0044f, { 9, 79, 1, 0 }, 9, 0, 0 },
1227     { 0x0f, 0x00457, { 9, 87, 1, 0 }, 9, 0, 0 },
1228     { 0x10, 0x00437, { 9, 55, 1, 0 }, 9, 0, 0 },
1229     { 0x10, 0x10437, { 9, 55, 1, 0 }, 9, 0, 0 },
1230     { 0x11, 0x0042b, { 9, 43, 1, 0 }, 9, 0, 0 }
1231 };
1232
1233 static BOOL CALLBACK enum_proc(LGRPID group, LCID lcid, LPSTR locale, LONG_PTR lparam)
1234 {
1235     HRESULT hr;
1236     SCRIPT_DIGITSUBSTITUTE sds;
1237     SCRIPT_CONTROL sc;
1238     SCRIPT_STATE ss;
1239     LCID lcid_old;
1240     unsigned int i;
1241
1242     if (!IsValidLocale(lcid, LCID_INSTALLED)) return TRUE;
1243
1244     memset(&sds, 0, sizeof(sds));
1245     memset(&sc, 0, sizeof(sc));
1246     memset(&ss, 0, sizeof(ss));
1247
1248     lcid_old = GetThreadLocale();
1249     if (!SetThreadLocale(lcid)) return TRUE;
1250
1251     hr = ScriptRecordDigitSubstitution(lcid, &sds);
1252     ok(hr == S_OK, "ScriptRecordDigitSubstitution failed: 0x%08x\n", hr);
1253
1254     hr = ScriptApplyDigitSubstitution(&sds, &sc, &ss);
1255     ok(hr == S_OK, "ScriptApplyDigitSubstitution failed: 0x%08x\n", hr);
1256
1257     for (i = 0; i < sizeof(subst_data)/sizeof(subst_data[0]); i++)
1258     {
1259         if (group == subst_data[i].group && lcid == subst_data[i].lcid)
1260         {
1261             ok(!memcmp(&sds, &subst_data[i].sds, sizeof(sds)),
1262                "substitution data does not match\n");
1263
1264             ok(sc.uDefaultLanguage == subst_data[i].uDefaultLanguage,
1265                "sc.uDefaultLanguage does not match\n");
1266             ok(sc.fContextDigits == subst_data[i].fContextDigits,
1267                "sc.fContextDigits does not match\n");
1268             ok(ss.fDigitSubstitute == subst_data[i].fDigitSubstitute,
1269                "ss.fDigitSubstitute does not match\n");
1270         }
1271     }
1272     SetThreadLocale(lcid_old);
1273     return TRUE;
1274 }
1275
1276 static void test_digit_substitution(void)
1277 {
1278     BOOL ret;
1279     unsigned int i;
1280     static const LGRPID groups[] =
1281     {
1282         LGRPID_WESTERN_EUROPE,
1283         LGRPID_CENTRAL_EUROPE,
1284         LGRPID_BALTIC,
1285         LGRPID_GREEK,
1286         LGRPID_CYRILLIC,
1287         LGRPID_TURKISH,
1288         LGRPID_JAPANESE,
1289         LGRPID_KOREAN,
1290         LGRPID_TRADITIONAL_CHINESE,
1291         LGRPID_SIMPLIFIED_CHINESE,
1292         LGRPID_THAI,
1293         LGRPID_HEBREW,
1294         LGRPID_ARABIC,
1295         LGRPID_VIETNAMESE,
1296         LGRPID_INDIC,
1297         LGRPID_GEORGIAN,
1298         LGRPID_ARMENIAN
1299     };
1300     HMODULE hKernel32;
1301     static BOOL (WINAPI * pEnumLanguageGroupLocalesA)(LANGGROUPLOCALE_ENUMPROC,LGRPID,DWORD,LONG_PTR);
1302
1303     hKernel32 = GetModuleHandleA("kernel32.dll");
1304     pEnumLanguageGroupLocalesA = (void*)GetProcAddress(hKernel32, "EnumLanguageGroupLocalesA");
1305
1306     if (!pEnumLanguageGroupLocalesA)
1307     {
1308         trace("EnumLanguageGroupLocalesA not available on this platform\n");
1309         return;
1310     }
1311
1312     for (i = 0; i < sizeof(groups)/sizeof(groups[0]); i++)
1313     {
1314         ret = pEnumLanguageGroupLocalesA(enum_proc, groups[i], 0, 0);
1315         ok(ret, "EnumLanguageGroupLocalesA failed unexpectedly: %u\n", GetLastError());
1316     }
1317 }
1318
1319 static void test_ScriptGetProperties(void)
1320 {
1321     const SCRIPT_PROPERTIES **props;
1322     HRESULT hr;
1323     int num;
1324
1325     hr = ScriptGetProperties(NULL, NULL);
1326     ok(hr == E_INVALIDARG, "ScriptGetProperties succeeded\n");
1327
1328     hr = ScriptGetProperties(NULL, &num);
1329     ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
1330
1331     hr = ScriptGetProperties(&props, NULL);
1332     ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
1333
1334     hr = ScriptGetProperties(&props, &num);
1335     ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
1336 }
1337
1338 START_TEST(usp10)
1339 {
1340     HWND            hwnd;
1341     HDC             hdc;
1342     LOGFONTA        lf;
1343     HFONT           hfont;
1344
1345     unsigned short  pwOutGlyphs[256];
1346
1347     /* We need a valid HDC to drive a lot of Script functions which requires the following    *
1348      * to set up for the tests.                                                               */
1349     hwnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,
1350                            0, 0, 0, NULL);
1351     assert(hwnd != 0);
1352     ShowWindow(hwnd, SW_SHOW);
1353     UpdateWindow(hwnd);
1354
1355     hdc = GetDC(hwnd);                                      /* We now have a hdc             */
1356     ok( hdc != NULL, "HDC failed to be created %p\n", hdc);
1357
1358     memset(&lf, 0, sizeof(LOGFONTA));
1359     lstrcpyA(lf.lfFaceName, "Symbol");
1360     lf.lfHeight = 10;
1361     lf.lfWeight = 3;
1362     lf.lfWidth = 10;
1363
1364     hfont = SelectObject(hdc, CreateFontIndirectA(&lf));
1365
1366     test_ScriptItemIzeShapePlace(hdc,pwOutGlyphs);
1367     test_ScriptGetCMap(hdc, pwOutGlyphs);
1368     test_ScriptCacheGetHeight(hdc);
1369     test_ScriptGetGlyphABCWidth(hdc);
1370     test_ScriptShape(hdc);
1371
1372     test_ScriptGetFontProperties(hdc);
1373     test_ScriptTextOut(hdc);
1374     test_ScriptTextOut2(hdc);
1375     test_ScriptXtoX();
1376     test_ScriptString(hdc);
1377     test_ScriptStringXtoCP_CPtoX(hdc);
1378
1379     test_ScriptLayout();
1380     test_digit_substitution();
1381     test_ScriptGetProperties();
1382
1383     ReleaseDC(hwnd, hdc);
1384     DestroyWindow(hwnd);
1385 }