usp10: Add Khmer script.
[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 typedef struct _itemTest {
35     char todo_flag[5];
36     int iCharPos;
37     int fRTL;
38     int fLayoutRTL;
39     int uBidiLevel;
40     ULONG scriptTag;
41     BOOL isBroken;
42     int broken_value[5];
43 } itemTest;
44
45 typedef struct _shapeTest_char {
46     WORD wLogClust;
47     SCRIPT_CHARPROP CharProp;
48 } shapeTest_char;
49
50 typedef struct _shapeTest_glyph {
51     int Glyph;
52     SCRIPT_GLYPHPROP GlyphProp;
53 } shapeTest_glyph;
54
55 /* Uniscribe 1.6 calls */
56 static HRESULT (WINAPI *pScriptItemizeOpenType)( const WCHAR *pwcInChars, int cInChars, int cMaxItems, const SCRIPT_CONTROL *psControl, const SCRIPT_STATE *psState, SCRIPT_ITEM *pItems, ULONG *pScriptTags, int *pcItems);
57
58 static HRESULT (WINAPI *pScriptShapeOpenType)( HDC hdc, SCRIPT_CACHE *psc, SCRIPT_ANALYSIS *psa, OPENTYPE_TAG tagScript, OPENTYPE_TAG tagLangSys, int *rcRangeChars, TEXTRANGE_PROPERTIES **rpRangeProperties, int cRanges, const WCHAR *pwcChars, int cChars, int cMaxGlyphs, WORD *pwLogClust, SCRIPT_CHARPROP *pCharProps, WORD *pwOutGlyphs, SCRIPT_GLYPHPROP *pOutGlyphProps, int *pcGlyphs);
59
60 static DWORD (WINAPI *pGetGlyphIndicesW)(HDC hdc, LPCWSTR lpstr, INT count, LPWORD pgi, DWORD flags);
61
62 static inline void _test_items_ok(LPCWSTR string, DWORD cchString,
63                          SCRIPT_CONTROL *Control, SCRIPT_STATE *State,
64                          DWORD nItems, const itemTest* items, BOOL nItemsToDo,
65                          INT nItemsBroken)
66 {
67     HRESULT hr;
68     int x, outnItems;
69     SCRIPT_ITEM outpItems[15];
70     ULONG tags[15] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
71
72     if (pScriptItemizeOpenType)
73         hr = pScriptItemizeOpenType(string, cchString, 15, Control, State, outpItems, tags, &outnItems);
74     else
75         hr = ScriptItemize(string, cchString, 15, Control, State, outpItems, &outnItems);
76
77     winetest_ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
78     if (nItemsBroken && broken(nItemsBroken == outnItems))
79     {
80         winetest_win_skip("This test broken on this platform\n");
81         return;
82     }
83     if (nItemsToDo)
84         todo_wine winetest_ok(outnItems == nItems, "Wrong number of items\n");
85     else
86         winetest_ok(outnItems == nItems, "Wrong number of items\n");
87     for (x = 0; x <= outnItems; x++)
88     {
89         if (items[x].isBroken && broken(outpItems[x].iCharPos == items[x].broken_value[0]))
90             winetest_win_skip("This test broken on this platform\n");
91         else if (items[x].todo_flag[0])
92             todo_wine winetest_ok(outpItems[x].iCharPos == items[x].iCharPos, "%i:Wrong CharPos\n",x);
93         else
94             winetest_ok(outpItems[x].iCharPos == items[x].iCharPos, "%i:Wrong CharPos (%i)\n",x,outpItems[x].iCharPos);
95
96         if (items[x].isBroken && broken(outpItems[x].a.fRTL== items[x].broken_value[1]))
97             winetest_win_skip("This test broken on this platform\n");
98         else if (items[x].todo_flag[1])
99             todo_wine winetest_ok(outpItems[x].a.fRTL == items[x].fRTL, "%i:Wrong fRTL\n",x);
100         else
101             winetest_ok(outpItems[x].a.fRTL == items[x].fRTL, "%i:Wrong fRTL(%i)\n",x,outpItems[x].a.fRTL);
102
103         if (items[x].isBroken && broken(outpItems[x].a.fLayoutRTL == items[x].broken_value[2]))
104             winetest_win_skip("This test broken on this platform\n");
105         else if (items[x].todo_flag[2])
106             todo_wine winetest_ok(outpItems[x].a.fLayoutRTL == items[x].fLayoutRTL, "%i:Wrong fLayoutRTL\n",x);
107         else
108             winetest_ok(outpItems[x].a.fLayoutRTL == items[x].fLayoutRTL, "%i:Wrong fLayoutRTL(%i)\n",x,outpItems[x].a.fLayoutRTL);
109
110         if (items[x].isBroken && broken(outpItems[x].a.s.uBidiLevel == items[x].broken_value[3]))
111             winetest_win_skip("This test broken on this platform\n");
112         else if (items[x].todo_flag[3])
113             todo_wine winetest_ok(outpItems[x].a.s.uBidiLevel == items[x].uBidiLevel, "%i:Wrong BidiLevel\n",x);
114         else
115             winetest_ok(outpItems[x].a.s.uBidiLevel == items[x].uBidiLevel, "%i:Wrong BidiLevel(%i)\n",x,outpItems[x].a.s.uBidiLevel);
116         if (x != outnItems)
117             winetest_ok(outpItems[x].a.eScript != SCRIPT_UNDEFINED, "%i: Undefined script\n",x);
118         if (pScriptItemizeOpenType)
119         {
120             if (items[x].isBroken && broken(tags[x] == items[x].broken_value[4]))
121                 winetest_win_skip("This test broken on this platform\n");
122             else if (items[x].todo_flag[4])
123                 todo_wine winetest_ok(tags[x] == items[x].scriptTag,"%i:Incorrect Script Tag %x != %x\n",x,tags[x],items[x].scriptTag);
124             else
125                 winetest_ok(tags[x] == items[x].scriptTag,"%i:Incorrect Script Tag %x != %x\n",x,tags[x],items[x].scriptTag);
126         }
127     }
128 }
129
130 #define test_items_ok(a,b,c,d,e,f,g,h) (winetest_set_location(__FILE__,__LINE__), 0) ? 0 : _test_items_ok(a,b,c,d,e,f,g,h)
131
132 #define MS_MAKE_TAG( _x1, _x2, _x3, _x4 ) \
133           ( ( (ULONG)_x4 << 24 ) |     \
134             ( (ULONG)_x3 << 16 ) |     \
135             ( (ULONG)_x2 <<  8 ) |     \
136               (ULONG)_x1         )
137
138 #define latn_tag MS_MAKE_TAG('l','a','t','n')
139 #define arab_tag MS_MAKE_TAG('a','r','a','b')
140 #define thai_tag MS_MAKE_TAG('t','h','a','i')
141 #define hebr_tag MS_MAKE_TAG('h','e','b','r')
142 #define syrc_tag MS_MAKE_TAG('s','y','r','c')
143 #define deva_tag MS_MAKE_TAG('d','e','v','a')
144 #define beng_tag MS_MAKE_TAG('b','e','n','g')
145 #define guru_tag MS_MAKE_TAG('g','u','r','u')
146 #define gujr_tag MS_MAKE_TAG('g','u','j','r')
147 #define orya_tag MS_MAKE_TAG('o','r','y','a')
148 #define taml_tag MS_MAKE_TAG('t','a','m','l')
149 #define telu_tag MS_MAKE_TAG('t','e','l','u')
150 #define knda_tag MS_MAKE_TAG('k','n','d','a')
151 #define mlym_tag MS_MAKE_TAG('m','l','y','m')
152 #define mymr_tag MS_MAKE_TAG('m','y','m','r')
153 #define tale_tag MS_MAKE_TAG('t','a','l','e')
154 #define talu_tag MS_MAKE_TAG('t','a','l','u')
155 #define khmr_tag MS_MAKE_TAG('k','h','m','r')
156
157 static void test_ScriptItemize( void )
158 {
159     static const WCHAR test1[] = {'t', 'e', 's', 't',0};
160     static const itemTest t11[2] = {{{0,0,0,0,0},0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},4,0,0,0,-1}};
161     static const itemTest t12[2] = {{{0,0,0,0,0},0,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},4,0,0,0,-1,FALSE}};
162
163     static const WCHAR test1b[] = {' ', ' ', ' ', ' ',0};
164     static const itemTest t1b1[2] = {{{0,0,0,0,0},0,0,0,0,0,FALSE},{{0,0,0,0,0},4,0,0,0,-1,FALSE}};
165     static const itemTest t1b2[2] = {{{0,0,0,0,0},0,1,1,1,0,FALSE},{{0,0,0,0,0},4,0,0,0,-1,FALSE}};
166
167     static const WCHAR test1c[] = {' ', ' ', ' ', '1', '2', ' ',0};
168     static const itemTest t1c1[2] = {{{0,0,0,0,0},0,0,0,0,0,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
169     static const itemTest t1c2[4] = {{{0,0,0,0,0},0,1,1,1,0,FALSE},{{0,0,0,0,0},3,0,1,2,0,FALSE},{{0,0,0,0,0},5,1,1,1,0,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
170
171     /* Arabic, English*/
172     static const WCHAR test2[] = {'1','2','3','-','5','2',0x064a,0x064f,0x0633,0x0627,0x0648,0x0650,0x064a,'7','1','.',0};
173     static const itemTest t21[7] = {{{0,0,0,0,0},0,0,0,0,0,FALSE},{{0,0,0,0,0},3,0,0,0,0,FALSE},{{0,0,0,0,0},4,0,0,0,0,FALSE},{{0,0,0,0,0},6,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},13,0,0,0,0,FALSE},{{0,0,0,0,0},15,0,0,0,0,FALSE},{{0,0,0,0,0},16,0,0,0,-1,FALSE}};
174     static const itemTest t22[5] = {{{0,0,0,0,0},0,0,0,2,0,FALSE},{{0,0,0,0,0},6,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},13,0,1,2,0,FALSE},{{0,0,0,0,0},15,0,0,0,0,FALSE},{{0,0,0,0,0},16,0,0,0,-1,FALSE}};
175     static const itemTest t23[5] = {{{0,0,0,0,0},0,0,1,2,0,FALSE},{{0,0,0,0,0},6,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},13,0,1,2,0,FALSE},{{0,0,0,0,0},15,1,1,1,0,FALSE},{{0,0,0,0,0},16,0,0,0,-1,FALSE}};
176
177     static const WCHAR test2b[] = {'A','B','C','-','D','E','F',' ',0x0621,0x0623,0x0624,0};
178     static const itemTest t2b1[5] = {{{0,0,0,0,0},0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},3,0,0,0,0,FALSE},{{0,0,0,0,0},4,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},8,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
179     static const itemTest t2b2[5] = {{{0,0,0,0,0},0,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},3,0,0,2,0,FALSE},{{0,0,0,0,0},4,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},7,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
180     static const itemTest t2b3[3] = {{{0,0,0,0,0},0,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},7,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
181
182     /* leading space */
183     static const WCHAR test2c[] = {' ',0x0621,0x0623,0x0624,'A','B','C','-','D','E','F',0};
184     static const itemTest t2c1[5] = {{{0,0,0,0,0},0,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},4,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},7,0,0,0,0,FALSE},{{0,0,0,0,0},8,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
185     static const itemTest t2c2[6] = {{{0,0,0,0,0},0,0,0,0,0,FALSE},{{0,0,0,0,0},1,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},4,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},7,0,0,0,0,FALSE},{{0,0,0,0,0},8,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
186     static const itemTest t2c3[5] = {{{0,0,0,0,0},0,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},4,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},7,0,0,2,0,FALSE},{{0,0,0,0,0},8,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
187     static const itemTest t2c4[3] = {{{0,0,0,0,0},0,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},4,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
188
189     /* trailing space */
190     static const WCHAR test2d[] = {'A','B','C','-','D','E','F',0x0621,0x0623,0x0624,' ',0};
191     static const itemTest t2d1[5] = {{{0,0,0,0,0},0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},3,0,0,0,0,FALSE},{{0,0,0,0,0},4,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},7,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
192     static const itemTest t2d2[6] = {{{0,0,0,0,0},0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},3,0,0,0,0,FALSE},{{0,0,0,0,0},4,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},7,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},10,0,0,0,0,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
193     static const itemTest t2d3[5] = {{{0,0,0,0,0},0,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},3,0,0,2,0,FALSE},{{0,0,0,0,0},4,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},7,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
194     static const itemTest t2d4[3] = {{{0,0,0,0,0},0,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},7,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
195
196     /* Thai */
197     static const WCHAR test3[] =
198 {0x0e04,0x0e27,0x0e32,0x0e21,0x0e1e,0x0e22,0x0e32,0x0e22,0x0e32, 0x0e21
199 ,0x0e2d,0x0e22,0x0e39,0x0e48,0x0e17,0x0e35,0x0e48,0x0e44,0x0e2b,0x0e19
200 ,0x0e04,0x0e27,0x0e32,0x0e21,0x0e2a, 0x0e33,0x0e40,0x0e23,0x0e47,0x0e08,
201  0x0e2d,0x0e22,0x0e39,0x0e48,0x0e17,0x0e35,0x0e48,0x0e19,0x0e31,0x0e48,0x0e19,0};
202
203     static const itemTest t31[2] = {{{0,0,0,0,0},0,0,0,0,thai_tag,FALSE},{{0,0,0,0,0},41,0,0,0,-1,FALSE}};
204     static const itemTest t32[2] = {{{0,0,0,0,0},0,0,0,2,thai_tag,FALSE},{{0,0,0,0,0},41,0,0,0,-1,FALSE}};
205
206     static const WCHAR test4[]  = {'1','2','3','-','5','2',' ','i','s',' ','7','1','.',0};
207
208     static const itemTest t41[6] = {{{0,0,0,0,0},0,0,0,0,0,FALSE},{{0,0,0,0,0},3,0,0,0,0,FALSE},{{0,0,0,0,0},4,0,0,0,0,FALSE},{{0,0,0,0,0},7,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},10,0,0,0,0,FALSE},{{0,0,0,0,0},12,0,0,0,-1,FALSE}};
209     static const itemTest t42[5] = {{{0,0,0,0,0},0,0,1,2,0,FALSE},{{0,0,0,0,0},6,1,1,1,0,FALSE},{{0,0,0,0,0},7,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},10,0,0,2,0,FALSE},{{0,0,0,0,0},12,0,0,0,-1,FALSE}};
210     static const itemTest t43[4] = {{{0,0,0,0,0},0,0,1,2,0,FALSE},{{0,0,0,0,0},6,1,1,1,0,FALSE},{{0,0,0,0,0},7,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},12,0,0,0,-1,FALSE}};
211
212     /* Arabic */
213     static const WCHAR test5[]  =
214 {0x0627,0x0644,0x0635,0x0651,0x0650,0x062d,0x0629,0x064f,' ',0x062a,0x064e,
215 0x0627,0x062c,0x064c,' ',0x0639,0x064e,0x0644,0x0649,' ',
216 0x0631,0x064f,0x0624,0x0648,0x0633,0x0650,' ',0x0627,0x0644
217 ,0x0623,0x0635,0x0650,0x062d,0x0651,0x064e,0x0627,0x0621,0x0650,0};
218     static const itemTest t51[2] = {{{0,0,0,0,0},0,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},38,0,0,0,-1,FALSE}};
219
220     /* Hebrew */
221     static const WCHAR test6[]  = {0x05e9, 0x05dc, 0x05d5, 0x05dd, '.',0};
222     static const itemTest t61[3] = {{{0,0,0,0,0},0,1,1,1,hebr_tag,FALSE},{{0,0,0,0,0},4,0,0,0,0,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
223     static const itemTest t62[3] = {{{0,0,0,0,0},0,1,1,1,hebr_tag,FALSE},{{0,0,0,0,0},4,1,1,1,0,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
224     static const itemTest t63[2] = {{{0,0,0,0,0},0,1,1,1,hebr_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
225     static const WCHAR test7[]  = {'p','a','r','t',' ','o','n','e',' ',0x05d7, 0x05dc, 0x05e7, ' ', 0x05e9, 0x05ea, 0x05d9, 0x05d9, 0x05dd, ' ','p','a','r','t',' ','t','h','r','e','e', 0};
226     static const itemTest t71[4] = {{{0,0,0,0,0},0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},9,1,1,1,hebr_tag,FALSE},{{0,0,0,0,0},19,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},29,0,0,0,-1,FALSE}};
227     static const itemTest t72[4] = {{{0,0,0,0,0},0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},9,1,1,1,hebr_tag,FALSE},{{0,0,0,0,0},18,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},29,0,0,0,-1,FALSE}};
228     static const itemTest t73[4] = {{{0,0,0,0,0},0,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},8,1,1,1,hebr_tag,FALSE},{{0,0,0,0,0},19,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},29,0,0,0,-1,FALSE}};
229     static const WCHAR test8[] = {0x0633, 0x0644, 0x0627, 0x0645,0};
230     static const itemTest t81[2] = {{{0,0,0,0,0},0,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},4,0,0,0,-1,FALSE}};
231
232     /* Syriac  (Like Arabic )*/
233     static const WCHAR test9[] = {0x0710, 0x0712, 0x0712, 0x0714, '.',0};
234     static const itemTest t91[3] = {{{0,0,0,0,0},0,1,1,1,syrc_tag,FALSE},{{0,0,0,0,0},4,0,0,0,0,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
235     static const itemTest t92[3] = {{{0,0,0,0,0},0,1,1,1,syrc_tag},{{0,0,0,0,0},4,1,1,1,0,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
236     static const itemTest t93[2] = {{{0,0,0,0,0},0,1,1,1,syrc_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
237
238     static const WCHAR test10[] = {0x0717, 0x0718, 0x071a, 0x071b,0};
239     static const itemTest t101[2] = {{{0,0,0,0,0},0,1,1,1,syrc_tag,FALSE},{{0,0,0,0,0},4,0,0,0,-1,FALSE}};
240
241     /* Devanagari */
242     static const WCHAR test11[] = {0x0926, 0x0947, 0x0935, 0x0928, 0x093e, 0x0917, 0x0930, 0x0940};
243     static const itemTest t111[2] = {{{0,0,0,0,0},0,0,0,0,deva_tag,FALSE},{{0,0,0,0,0},8,0,0,0,-1,FALSE}};
244     static const itemTest t112[2] = {{{0,0,0,0,0},0,0,0,2,deva_tag,FALSE},{{0,0,0,0,0},8,0,0,0,-1,FALSE}};
245
246     /* Bengali */
247     static const WCHAR test12[] = {0x09ac, 0x09be, 0x0982, 0x09b2, 0x09be};
248     static const itemTest t121[2] = {{{0,0,0,0,0},0,0,0,0,beng_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
249     static const itemTest t122[2] = {{{0,0,0,0,0},0,0,0,2,beng_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
250
251     /* Gurmukhi */
252     static const WCHAR test13[] = {0x0a17, 0x0a41, 0x0a30, 0x0a2e, 0x0a41, 0x0a16, 0x0a40};
253     static const itemTest t131[2] = {{{0,0,0,0,0},0,0,0,0,guru_tag,FALSE},{{0,0,0,0,0},7,0,0,0,-1,FALSE}};
254     static const itemTest t132[2] = {{{0,0,0,0,0},0,0,0,2,guru_tag,FALSE},{{0,0,0,0,0},7,0,0,0,-1,FALSE}};
255
256     /* Gujarati */
257     static const WCHAR test14[] = {0x0a97, 0x0ac1, 0x0a9c, 0x0ab0, 0x0abe, 0x0aa4, 0x0ac0};
258     static const itemTest t141[2] = {{{0,0,0,0,0},0,0,0,0,gujr_tag,FALSE},{{0,0,0,0,0},7,0,0,0,-1,FALSE}};
259     static const itemTest t142[2] = {{{0,0,0,0,0},0,0,0,2,gujr_tag,FALSE},{{0,0,0,0,0},7,0,0,0,-1,FALSE}};
260
261     /* Oriya */
262     static const WCHAR test15[] = {0x0b13, 0x0b21, 0x0b3c, 0x0b3f, 0x0b06};
263     static const itemTest t151[2] = {{{0,0,0,0,0},0,0,0,0,orya_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
264     static const itemTest t152[2] = {{{0,0,0,0,0},0,0,0,2,orya_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
265
266     /* Tamil */
267     static const WCHAR test16[] = {0x0ba4, 0x0bae, 0x0bbf, 0x0bb4, 0x0bcd};
268     static const itemTest t161[2] = {{{0,0,0,0,0},0,0,0,0,taml_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
269     static const itemTest t162[2] = {{{0,0,0,0,0},0,0,0,2,taml_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
270
271     /* Telugu */
272     static const WCHAR test17[] = {0x0c24, 0x0c46, 0x0c32, 0x0c41, 0x0c17, 0x0c41};
273     static const itemTest t171[2] = {{{0,0,0,0,0},0,0,0,0,telu_tag,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
274     static const itemTest t172[2] = {{{0,0,0,0,0},0,0,0,2,telu_tag,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
275
276     /* Kannada */
277     static const WCHAR test18[] = {0x0c95, 0x0ca8, 0x0ccd, 0x0ca8, 0x0ca1};
278     static const itemTest t181[2] = {{{0,0,0,0,0},0,0,0,0,knda_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
279     static const itemTest t182[2] = {{{0,0,0,0,0},0,0,0,2,knda_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
280
281     /* Malayalam */
282     static const WCHAR test19[] = {0x0d2e, 0x0d32, 0x0d2f, 0x0d3e, 0x0d33, 0x0d02};
283     static const itemTest t191[2] = {{{0,0,0,0,0},0,0,0,0,mlym_tag,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
284     static const itemTest t192[2] = {{{0,0,0,0,0},0,0,0,2,mlym_tag,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
285
286     /* Diacritical */
287     static const WCHAR test20[] = {0x0309,'a','b','c','d',0};
288     static const itemTest t201[3] = {{{0,0,0,0,0},0,0,0,0,0x0,FALSE},{{0,0,0,0,0},1,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
289     static const itemTest t202[3] = {{{0,0,0,0,0},0,0,0,2,0,TRUE,{-1,1,1,1,-1}},{{0,0,0,0,0},1,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
290
291     static const WCHAR test21[] = {0x0710, 0x0712, 0x0308, 0x0712, 0x0714,0};
292     static const itemTest t211[2] = {{{0,0,0,0,0},0,1,1,1,syrc_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
293
294     /* Latin Punctuation */
295     static const WCHAR test22[] = {'#','$',',','!','\"','*',0};
296     static const itemTest t221[3] = {{{0,0,0,0,0},0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},3,0,0,0,0,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
297     static const itemTest t222[3] = {{{0,0,0,0,0},0,1,1,1,latn_tag,FALSE},{{0,0,0,0,0},3,1,1,1,0,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
298     static const itemTest t223[2] = {{{0,0,0,0,0},0,1,1,1,latn_tag,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
299
300     /* Number 2*/
301     static const WCHAR test23[] = {'1','2','3',0x00b2,0x00b3,0x2070,0};
302     static const itemTest t231[3] = {{{0,0,0,0,0},0,0,0,0,0,FALSE},{{0,0,0,0,0},3,0,0,0,0,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
303     static const itemTest t232[3] = {{{0,0,0,0,0},0,0,1,2,0,FALSE},{{0,0,0,0,0},3,0,1,2,0,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
304
305     /* Myanmar */
306     static const WCHAR test24[] = {0x1019,0x103c,0x1014,0x103a,0x1019,0x102c,0x1021,0x1000,0x1039,0x1001,0x101b,0x102c};
307     static const itemTest t241[2] = {{{0,0,0,0,0},0,0,0,0,mymr_tag,FALSE},{{0,0,0,0,0},12,0,0,0,-1,FALSE}};
308     static const itemTest t242[2] = {{{0,0,0,0,0},0,0,0,2,mymr_tag,TRUE,{-1,1,1,1,-1}},{{0,0,0,0,0},12,0,0,0,-1,FALSE}};
309
310     /* Tai Le */
311     static const WCHAR test25[] = {0x1956,0x196d,0x1970,0x1956,0x196c,0x1973,0x1951,0x1968,0x1952,0x1970};
312     static const itemTest t251[2] = {{{0,0,0,0,0},0,0,0,0,tale_tag,TRUE,{-1,-1,-1,-1,latn_tag}},{{0,0,0,0,0},10,0,0,0,-1,FALSE}};
313     static const itemTest t252[2] = {{{0,0,0,0,0},0,0,0,2,tale_tag,TRUE,{-1,1,1,1,latn_tag}},{{0,0,0,0,0},10,0,0,0,-1,FALSE}};
314
315     /* New Tai Lue */
316     static const WCHAR test26[] = {0x1992,0x19c4};
317     static const itemTest t261[2] = {{{0,0,0,0,0},0,0,0,0,talu_tag,TRUE,{-1,-1,-1,-1,latn_tag}},{{0,0,0,0,0},2,0,0,0,-1,FALSE}};
318     static const itemTest t262[2] = {{{0,0,0,0,0},0,0,0,2,talu_tag,TRUE,{-1,1,1,1,latn_tag}},{{0,0,0,0,0},2,0,0,0,-1,FALSE}};
319
320     /* Khmer */
321     static const WCHAR test27[] = {0x1781,0x17c1,0x1798,0x179a,0x1797,0x17b6,0x179f,0x17b6};
322     static const itemTest t271[2] = {{{0,0,0,0,0},0,0,0,0,khmr_tag,FALSE},{{0,0,0,0,0},8,0,0,0,-1,FALSE}};
323     static const itemTest t272[2] = {{{0,0,0,0,0},0,0,0,2,khmr_tag,TRUE,{-1,1,1,1,-1}},{{0,0,0,0,0},8,0,0,0,-1,FALSE}};
324
325
326     SCRIPT_ITEM items[15];
327     SCRIPT_CONTROL  Control;
328     SCRIPT_STATE    State;
329     HRESULT hr;
330     HMODULE usp10;
331     int nItems;
332
333     usp10 = LoadLibraryA("usp10.dll");
334     ok (usp10 != 0,"Unable to LoadLibrary on usp10.dll\n");
335     pScriptItemizeOpenType = (void*)GetProcAddress(usp10, "ScriptItemizeOpenType");
336     pScriptShapeOpenType = (void*)GetProcAddress(usp10, "ScriptShapeOpenType");
337     pGetGlyphIndicesW = (void*)GetProcAddress(GetModuleHandleA("gdi32.dll"), "GetGlyphIndicesW");
338
339     memset(&Control, 0, sizeof(Control));
340     memset(&State, 0, sizeof(State));
341
342     hr = ScriptItemize(NULL, 4, 10, &Control, &State, items, NULL);
343     ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if pwcInChars is NULL\n");
344
345     hr = ScriptItemize(test1, 4, 10, &Control, &State, NULL, NULL);
346     ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if pItems is NULL\n");
347
348     hr = ScriptItemize(test1, 4, 1, &Control, &State, items, NULL);
349     ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if cMaxItems < 2.\n");
350
351     hr = ScriptItemize(test1, 0, 10, NULL, NULL, items, &nItems);
352     ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if cInChars is 0\n");
353
354     test_items_ok(test1,4,NULL,NULL,1,t11,FALSE,0);
355     test_items_ok(test1b,4,NULL,NULL,1,t1b1,FALSE,0);
356     test_items_ok(test1c,6,NULL,NULL,1,t1c1,FALSE,0);
357     test_items_ok(test2,16,NULL,NULL,6,t21,FALSE,0);
358     test_items_ok(test2b,11,NULL,NULL,4,t2b1,FALSE,0);
359     test_items_ok(test2c,11,NULL,NULL,4,t2c1,FALSE,0);
360     test_items_ok(test2d,11,NULL,NULL,4,t2d1,FALSE,0);
361     test_items_ok(test3,41,NULL,NULL,1,t31,FALSE,0);
362     test_items_ok(test4,12,NULL,NULL,5,t41,FALSE,0);
363     test_items_ok(test5,38,NULL,NULL,1,t51,FALSE,0);
364     test_items_ok(test6,5,NULL,NULL,2,t61,FALSE,0);
365     test_items_ok(test7,29,NULL,NULL,3,t71,FALSE,0);
366     test_items_ok(test8,4,NULL,NULL,1,t81,FALSE,0);
367     test_items_ok(test9,5,NULL,NULL,2,t91,FALSE,0);
368     test_items_ok(test10,4,NULL,NULL,1,t101,FALSE,0);
369     test_items_ok(test11,8,NULL,NULL,1,t111,FALSE,0);
370     test_items_ok(test12,5,NULL,NULL,1,t121,FALSE,0);
371     test_items_ok(test13,7,NULL,NULL,1,t131,FALSE,0);
372     test_items_ok(test14,7,NULL,NULL,1,t141,FALSE,0);
373     test_items_ok(test15,5,NULL,NULL,1,t151,FALSE,0);
374     test_items_ok(test16,5,NULL,NULL,1,t161,FALSE,0);
375     test_items_ok(test17,6,NULL,NULL,1,t171,FALSE,0);
376     test_items_ok(test18,5,NULL,NULL,1,t181,FALSE,0);
377     test_items_ok(test19,6,NULL,NULL,1,t191,FALSE,0);
378     test_items_ok(test20,5,NULL,NULL,2,t201,FALSE,0);
379     test_items_ok(test21,5,NULL,NULL,1,t211,FALSE,0);
380     test_items_ok(test22,6,NULL,NULL,2,t221,FALSE,0);
381     test_items_ok(test23,6,NULL,NULL,2,t231,FALSE,0);
382     test_items_ok(test24,12,NULL,NULL,1,t241,FALSE,0);
383     test_items_ok(test25,10,NULL,NULL,1,t251,FALSE,0);
384     test_items_ok(test26,2,NULL,NULL,1,t261,FALSE,0);
385     test_items_ok(test27,8,NULL,NULL,1,t271,FALSE,0);
386
387     State.uBidiLevel = 0;
388     test_items_ok(test1,4,&Control,&State,1,t11,FALSE,0);
389     test_items_ok(test1b,4,&Control,&State,1,t1b1,FALSE,0);
390     test_items_ok(test1c,6,&Control,&State,1,t1c1,FALSE,0);
391     test_items_ok(test2,16,&Control,&State,4,t22,FALSE,0);
392     test_items_ok(test2b,11,&Control,&State,4,t2b1,FALSE,0);
393     test_items_ok(test2c,11,&Control,&State,5,t2c2,FALSE,0);
394     test_items_ok(test2d,11,&Control,&State,5,t2d2,FALSE,0);
395     test_items_ok(test3,41,&Control,&State,1,t31,FALSE,0);
396     test_items_ok(test4,12,&Control,&State,5,t41,FALSE,0);
397     test_items_ok(test5,38,&Control,&State,1,t51,FALSE,0);
398     test_items_ok(test6,5,&Control,&State,2,t61,FALSE,0);
399     test_items_ok(test7,29,&Control,&State,3,t72,FALSE,0);
400     test_items_ok(test8,4,&Control,&State,1,t81,FALSE,0);
401     test_items_ok(test9,5,&Control,&State,2,t91,FALSE,0);
402     test_items_ok(test10,4,&Control,&State,1,t101,FALSE,0);
403     test_items_ok(test11,8,&Control,&State,1,t111,FALSE,0);
404     test_items_ok(test12,5,&Control,&State,1,t121,FALSE,0);
405     test_items_ok(test13,7,&Control,&State,1,t131,FALSE,0);
406     test_items_ok(test14,7,&Control,&State,1,t141,FALSE,0);
407     test_items_ok(test15,5,&Control,&State,1,t151,FALSE,0);
408     test_items_ok(test16,5,&Control,&State,1,t161,FALSE,0);
409     test_items_ok(test17,6,&Control,&State,1,t171,FALSE,0);
410     test_items_ok(test18,5,&Control,&State,1,t181,FALSE,0);
411     test_items_ok(test19,6,&Control,&State,1,t191,FALSE,0);
412     test_items_ok(test20,5,&Control,&State,2,t201,FALSE,0);
413     test_items_ok(test21,5,&Control,&State,1,t211,FALSE,0);
414     test_items_ok(test22,6,&Control,&State,2,t221,FALSE,0);
415     test_items_ok(test23,6,&Control,&State,2,t231,FALSE,0);
416     test_items_ok(test24,12,&Control,&State,1,t241,FALSE,0);
417     test_items_ok(test25,10,&Control,&State,1,t251,FALSE,0);
418     test_items_ok(test26,2,&Control,&State,1,t261,FALSE,0);
419     test_items_ok(test27,8,&Control,&State,1,t271,FALSE,0);
420
421     State.uBidiLevel = 1;
422     test_items_ok(test1,4,&Control,&State,1,t12,FALSE,0);
423     test_items_ok(test1b,4,&Control,&State,1,t1b2,FALSE,0);
424     test_items_ok(test1c,6,&Control,&State,3,t1c2,FALSE,0);
425     test_items_ok(test2,16,&Control,&State,4,t23,FALSE,0);
426     test_items_ok(test2b,11,&Control,&State,4,t2b2,FALSE,0);
427     test_items_ok(test2c,11,&Control,&State,4,t2c3,FALSE,0);
428     test_items_ok(test2d,11,&Control,&State,4,t2d3,FALSE,0);
429     test_items_ok(test3,41,&Control,&State,1,t32,FALSE,0);
430     test_items_ok(test4,12,&Control,&State,4,t42,FALSE,0);
431     test_items_ok(test5,38,&Control,&State,1,t51,FALSE,0);
432     test_items_ok(test6,5,&Control,&State,2,t62,FALSE,0);
433     test_items_ok(test7,29,&Control,&State,3,t73,FALSE,0);
434     test_items_ok(test8,4,&Control,&State,1,t81,FALSE,0);
435     test_items_ok(test9,5,&Control,&State,2,t92,FALSE,0);
436     test_items_ok(test10,4,&Control,&State,1,t101,FALSE,0);
437     test_items_ok(test11,8,&Control,&State,1,t112,FALSE,0);
438     test_items_ok(test12,5,&Control,&State,1,t122,FALSE,0);
439     test_items_ok(test13,7,&Control,&State,1,t132,FALSE,0);
440     test_items_ok(test14,7,&Control,&State,1,t142,FALSE,0);
441     test_items_ok(test15,5,&Control,&State,1,t152,FALSE,0);
442     test_items_ok(test16,5,&Control,&State,1,t162,FALSE,0);
443     test_items_ok(test17,6,&Control,&State,1,t172,FALSE,0);
444     test_items_ok(test18,5,&Control,&State,1,t182,FALSE,0);
445     test_items_ok(test19,6,&Control,&State,1,t192,FALSE,0);
446     test_items_ok(test20,5,&Control,&State,2,t202,FALSE,0);
447     test_items_ok(test21,5,&Control,&State,1,t211,FALSE,0);
448     test_items_ok(test22,6,&Control,&State,2,t222,FALSE,1);
449     test_items_ok(test23,6,&Control,&State,2,t232,FALSE,0);
450     test_items_ok(test24,12,&Control,&State,1,t242,FALSE,0);
451     test_items_ok(test25,10,&Control,&State,1,t252,FALSE,0);
452     test_items_ok(test26,2,&Control,&State,1,t262,FALSE,0);
453     test_items_ok(test27,8,&Control,&State,1,t272,FALSE,0);
454
455     State.uBidiLevel = 1;
456     Control.fMergeNeutralItems = TRUE;
457     test_items_ok(test1,4,&Control,&State,1,t12,FALSE,0);
458     test_items_ok(test1b,4,&Control,&State,1,t1b2,FALSE,0);
459     test_items_ok(test1c,6,&Control,&State,3,t1c2,FALSE,0);
460     test_items_ok(test2,16,&Control,&State,4,t23,FALSE,0);
461     test_items_ok(test2b,11,&Control,&State,2,t2b3,FALSE,4);
462     test_items_ok(test2c,11,&Control,&State,2,t2c4,FALSE,4);
463     test_items_ok(test2d,11,&Control,&State,2,t2d4,FALSE,4);
464     test_items_ok(test3,41,&Control,&State,1,t32,FALSE,0);
465     test_items_ok(test4,12,&Control,&State,3,t43,FALSE,4);
466     test_items_ok(test5,38,&Control,&State,1,t51,FALSE,0);
467     test_items_ok(test6,5,&Control,&State,1,t63,FALSE,2);
468     test_items_ok(test7,29,&Control,&State,3,t73,FALSE,0);
469     test_items_ok(test8,4,&Control,&State,1,t81,FALSE,0);
470     test_items_ok(test9,5,&Control,&State,1,t93,FALSE,2);
471     test_items_ok(test10,4,&Control,&State,1,t101,FALSE,0);
472     test_items_ok(test11,8,&Control,&State,1,t112,FALSE,0);
473     test_items_ok(test12,5,&Control,&State,1,t122,FALSE,0);
474     test_items_ok(test13,7,&Control,&State,1,t132,FALSE,0);
475     test_items_ok(test14,7,&Control,&State,1,t142,FALSE,0);
476     test_items_ok(test15,5,&Control,&State,1,t152,FALSE,0);
477     test_items_ok(test16,5,&Control,&State,1,t162,FALSE,0);
478     test_items_ok(test17,6,&Control,&State,1,t172,FALSE,0);
479     test_items_ok(test18,5,&Control,&State,1,t182,FALSE,0);
480     test_items_ok(test19,6,&Control,&State,1,t192,FALSE,0);
481     test_items_ok(test20,5,&Control,&State,2,t202,FALSE,0);
482     test_items_ok(test21,5,&Control,&State,1,t211,FALSE,0);
483     test_items_ok(test22,6,&Control,&State,1,t223,FALSE,2);
484     test_items_ok(test23,6,&Control,&State,2,t232,FALSE,0);
485     test_items_ok(test24,12,&Control,&State,1,t242,FALSE,0);
486     test_items_ok(test25,10,&Control,&State,1,t252,FALSE,0);
487     test_items_ok(test26,2,&Control,&State,1,t262,FALSE,0);
488     test_items_ok(test27,8,&Control,&State,1,t272,FALSE,0);
489 }
490
491 static inline void _test_shape_ok(int valid, HDC hdc, LPCWSTR string,
492                          DWORD cchString, SCRIPT_CONTROL *Control,
493                          SCRIPT_STATE *State, DWORD item, DWORD nGlyphs,
494                          const shapeTest_char* charItems,
495                          const shapeTest_glyph* glyphItems)
496 {
497     HRESULT hr;
498     int x, outnItems=0, outnGlyphs=0;
499     SCRIPT_ITEM outpItems[15];
500     SCRIPT_CACHE sc = NULL;
501     WORD *glyphs;
502     WORD *logclust;
503     int maxGlyphs = cchString * 1.5;
504     SCRIPT_GLYPHPROP *glyphProp;
505     SCRIPT_CHARPROP  *charProp;
506     ULONG tags[15];
507
508     hr = pScriptItemizeOpenType(string, cchString, 15, Control, State, outpItems, tags, &outnItems);
509     if (hr == USP_E_SCRIPT_NOT_IN_FONT)
510     {
511         if (valid > 0)
512             winetest_win_skip("Select font does not support script\n");
513         else
514             winetest_trace("Select font does not support script\n");
515         return;
516     }
517     if (valid > 0)
518         winetest_ok(!hr, "ScriptItemizeOpenType should return S_OK not %08x\n", hr);
519     else if (hr)
520         winetest_trace("ScriptItemizeOpenType should return S_OK not %08x\n", hr);
521
522
523     if (outnItems <= item)
524     {
525         if (valid > 0)
526             winetest_win_skip("Did not get enough items\n");
527         else
528             winetest_trace("Did not get enough items\n");
529         return;
530     }
531
532     logclust = HeapAlloc(GetProcessHeap(), 0, sizeof(WORD) * cchString);
533     memset(logclust,'a',sizeof(WORD) * cchString);
534     charProp = HeapAlloc(GetProcessHeap(), 0, sizeof(SCRIPT_CHARPROP) * cchString);
535     memset(charProp,'a',sizeof(SCRIPT_CHARPROP) * cchString);
536     glyphs = HeapAlloc(GetProcessHeap(), 0, sizeof(WORD) * maxGlyphs);
537     memset(glyphs,'a',sizeof(WORD) * cchString);
538     glyphProp = HeapAlloc(GetProcessHeap(), 0, sizeof(SCRIPT_GLYPHPROP) * maxGlyphs);
539     memset(glyphProp,'a',sizeof(SCRIPT_GLYPHPROP) * cchString);
540
541     hr = pScriptShapeOpenType(hdc, &sc, &outpItems[item].a, tags[item], 0x00000000, NULL, NULL, 0, string, cchString, maxGlyphs, logclust, charProp, glyphs, glyphProp, &outnGlyphs);
542     if (valid > 0)
543         winetest_ok(hr == S_OK, "ScriptShapeOpenType failed (%x)\n",hr);
544     else if (hr != S_OK)
545         winetest_trace("ScriptShapeOpenType failed (%x)\n",hr);
546     if (FAILED(hr))
547         return;
548
549     for (x = 0; x < cchString; x++)
550     {
551         if (valid > 0)
552             winetest_ok(logclust[x] == charItems[x].wLogClust, "%i: invalid LogClust(%i)\n",x,logclust[x]);
553         else if (logclust[x] != charItems[x].wLogClust)
554             winetest_trace("%i: invalid LogClust(%i)\n",x,logclust[x]);
555         if (valid > 0)
556             winetest_ok(charProp[x].fCanGlyphAlone == charItems[x].CharProp.fCanGlyphAlone, "%i: invalid fCanGlyphAlone\n",x);
557         else if (charProp[x].fCanGlyphAlone != charItems[x].CharProp.fCanGlyphAlone)
558             winetest_trace("%i: invalid fCanGlyphAlone\n",x);
559     }
560
561     if (valid > 0)
562         winetest_ok(nGlyphs == outnGlyphs, "got incorrect number of glyphs (%i)\n",outnGlyphs);
563     else if (nGlyphs != outnGlyphs)
564         winetest_trace("got incorrect number of glyphs (%i)\n",outnGlyphs);
565     for (x = 0; x < outnGlyphs; x++)
566     {
567         if (glyphItems[x].Glyph)
568         {
569             if (valid > 0)
570                 winetest_ok(glyphs[x]!=0, "%i: Glyph not present when it should be\n",x);
571             else if (glyphs[x]==0)
572                 winetest_trace("%i: Glyph not present when it should be\n",x);
573         }
574         else
575         {
576             if (valid > 0)
577                 winetest_ok(glyphs[x]==0, "%i: Glyph present when it should not be\n",x);
578             else if (glyphs[x]!=0)
579                 winetest_trace("%i: Glyph present when it should not be\n",x);
580         }
581         if (valid > 0)
582             winetest_ok(glyphProp[x].sva.uJustification == glyphItems[x].GlyphProp.sva.uJustification, "%i: uJustification incorrect (%i)\n",x,glyphProp[x].sva.uJustification);
583         else if (glyphProp[x].sva.uJustification != glyphItems[x].GlyphProp.sva.uJustification)
584             winetest_trace("%i: uJustification incorrect (%i)\n",x,glyphProp[x].sva.uJustification);
585         if (valid > 0)
586             winetest_ok(glyphProp[x].sva.fClusterStart == glyphItems[x].GlyphProp.sva.fClusterStart, "%i: fClusterStart incorrect (%i)\n",x,glyphProp[x].sva.fClusterStart);
587         else if (glyphProp[x].sva.fClusterStart != glyphItems[x].GlyphProp.sva.fClusterStart)
588             winetest_trace("%i: fClusterStart incorrect (%i)\n",x,glyphProp[x].sva.fClusterStart);
589         if (valid > 0)
590             winetest_ok(glyphProp[x].sva.fDiacritic == glyphItems[x].GlyphProp.sva.fDiacritic, "%i: fDiacritic incorrect (%i)\n",x,glyphProp[x].sva.fDiacritic);
591         else if (glyphProp[x].sva.fDiacritic != glyphItems[x].GlyphProp.sva.fDiacritic)
592             winetest_trace("%i: fDiacritic incorrect (%i)\n",x,glyphProp[x].sva.fDiacritic);
593         if (valid > 0)
594             winetest_ok(glyphProp[x].sva.fZeroWidth == glyphItems[x].GlyphProp.sva.fZeroWidth, "%i: fZeroWidth incorrect (%i)\n",x,glyphProp[x].sva.fZeroWidth);
595         else if (glyphProp[x].sva.fZeroWidth != glyphItems[x].GlyphProp.sva.fZeroWidth)
596             winetest_trace("%i: fZeroWidth incorrect (%i)\n",x,glyphProp[x].sva.fZeroWidth);
597     }
598
599     HeapFree(GetProcessHeap(),0,logclust);
600     HeapFree(GetProcessHeap(),0,charProp);
601     HeapFree(GetProcessHeap(),0,glyphs);
602     HeapFree(GetProcessHeap(),0,glyphProp);
603     ScriptFreeCache(&sc);
604 }
605
606 #define test_shape_ok(a,b,c,d,e,f,g,h,i) (winetest_set_location(__FILE__,__LINE__), 0) ? 0 : _test_shape_ok(1,a,b,c,d,e,f,g,h,i)
607
608 #define test_shape_ok_valid(v,a,b,c,d,e,f,g,h,i) (winetest_set_location(__FILE__,__LINE__), 0) ? 0 : _test_shape_ok(v,a,b,c,d,e,f,g,h,i)
609
610 typedef struct tagRangeP {
611     BYTE range;
612     LOGFONTA lf;
613 } fontEnumParam;
614
615 static int CALLBACK enumFontProc( const LOGFONT *lpelfe, const TEXTMETRIC *lpntme,
616                            DWORD FontType, LPARAM lParam)
617 {
618     NEWTEXTMETRICEX *ntme = (NEWTEXTMETRICEX*)lpntme;
619     fontEnumParam *rp = (fontEnumParam*) lParam;
620     int idx = 0;
621     DWORD i;
622     DWORD mask = 0;
623
624     if (FontType != TRUETYPE_FONTTYPE)
625         return 1;
626
627     i = rp->range;
628     while (i > sizeof(DWORD)*8)
629     {
630         idx++;
631         i -= (sizeof(DWORD)*8);
632     }
633     if (idx > 3)
634         return 0;
635
636     mask = 1 << i;
637
638     if (ntme->ntmFontSig.fsUsb[idx] & mask)
639     {
640         memcpy(&(rp->lf),lpelfe,sizeof(LOGFONT));
641         return 0;
642     }
643     return 1;
644 }
645
646 static int _find_font_for_range(HDC hdc, const CHAR *recommended, BYTE range, const WCHAR check, HFONT *hfont, HFONT *origFont)
647 {
648     int rc = 0;
649     fontEnumParam lParam;
650
651     lParam.range = range;
652     memset(&lParam.lf,0,sizeof(LOGFONT));
653     *hfont = NULL;
654
655     if (recommended)
656     {
657         lstrcpyA(lParam.lf.lfFaceName, recommended);
658         if (!EnumFontFamiliesExA(hdc, &lParam.lf, enumFontProc, (LPARAM)&lParam, 0))
659         {
660             *hfont = CreateFontIndirectA(&lParam.lf);
661             if (*hfont)
662             {
663                 winetest_trace("using font %s\n",lParam.lf.lfFaceName);
664                 rc = 1;
665             }
666         }
667     }
668
669     if (!*hfont)
670     {
671         memset(&lParam.lf,0,sizeof(LOGFONT));
672         lParam.lf.lfCharSet = DEFAULT_CHARSET;
673
674         if (!EnumFontFamiliesExA(hdc, &lParam.lf, enumFontProc, (LPARAM)&lParam, 0) && lParam.lf.lfFaceName[0])
675         {
676             *hfont = CreateFontIndirectA(&lParam.lf);
677             if (*hfont)
678                 winetest_trace("trying font %s: failures will only be warnings\n",lParam.lf.lfFaceName);
679         }
680     }
681
682     if (*hfont)
683     {
684         WORD glyph = 0;
685
686         *origFont = SelectObject(hdc,*hfont);
687         if (pGetGlyphIndicesW && (pGetGlyphIndicesW(hdc, &check, 1, &glyph, 0) == GDI_ERROR || glyph ==0))
688         {
689             winetest_trace("    Font fails to contain required glyphs\n");
690             SelectObject(hdc,*origFont);
691             DeleteObject(*hfont);
692             *hfont=NULL;
693             rc = 0;
694         }
695         else if (!rc)
696             rc = -1;
697     }
698     else
699         winetest_trace("Failed to find usable font\n");
700
701     return rc;
702 }
703
704 #define find_font_for_range(a,b,c,d,e,f) (winetest_set_location(__FILE__,__LINE__), 0) ? 0 : _find_font_for_range(a,b,c,d,e,f)
705
706 static void test_ScriptShapeOpenType(HDC hdc)
707 {
708     HRESULT hr;
709     SCRIPT_CACHE sc = NULL;
710     WORD glyphs[4], logclust[4];
711     SCRIPT_GLYPHPROP glyphProp[4];
712     SCRIPT_ITEM items[2];
713     ULONG tags[2];
714     SCRIPT_CONTROL  Control;
715     SCRIPT_STATE    State;
716     int nb, outnItems;
717     HFONT hfont, hfont_orig;
718     int test_valid;
719
720     static const WCHAR test1[] = {'w', 'i', 'n', 'e',0};
721     static const shapeTest_char t1_c[] = {{0,{0,0}},{1,{0,0}},{2,{0,0}},{3,{0,0}}};
722     static const shapeTest_glyph t1_g[] = {
723                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
724                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
725                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
726                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}} };
727
728     static const WCHAR test2[] = {0x202B, 'i', 'n', 0x202C,0};
729     static const shapeTest_char t2_c[] = {{0,{0,0}},{1,{0,0}},{2,{0,0}},{3,{0,0}}};
730     static const shapeTest_glyph t2_g[] = {
731                             {0,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
732                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
733                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
734                             {0,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}} };
735
736     /* Hebrew */
737     static const WCHAR test_hebrew[]  = {0x05e9, 0x05dc, 0x05d5, 0x05dd,0};
738     static const shapeTest_char hebrew_c[] = {{3,{0,0}},{2,{0,0}},{1,{0,0}},{0,{0,0}}};
739     static const shapeTest_glyph hebrew_g[] = {
740                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
741                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
742                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
743                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}} };
744
745     /* Arabic */
746     static const WCHAR test_arabic[] = {0x0633,0x0644,0x0627,0x0645,0};
747     static const shapeTest_char arabic_c[] = {{2,{0,0}},{1,{0,0}},{1,{0,0}},{0,{0,0}}};
748     static const shapeTest_glyph arabic_g[] = {
749                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
750                             {1,{{SCRIPT_JUSTIFY_ARABIC_NORMAL,1,0,0,0,0},0}},
751                             {1,{{SCRIPT_JUSTIFY_ARABIC_SEEN,1,0,0,0,0},0}} };
752
753     /* Thai */
754     static const WCHAR test_thai[] = {0x0e2a, 0x0e04, 0x0e23, 0x0e34, 0x0e1b, 0x0e15, 0x0e4c, 0x0e44, 0x0e17, 0x0e22,};
755     static const shapeTest_char thai_c[] = {{0,{0,0}},{1,{0,0}},{2,{0,0}},{2,{0,0}},{4,{0,0}},{5,{0,0}},{5,{0,0}},{7,{0,0}},{8,{0,0}},{9,{0,0}}};
756     static const shapeTest_glyph thai_g[] = {
757                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
758                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
759                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
760                             {1,{{SCRIPT_JUSTIFY_CHARACTER,0,1,1,0,0},0}},
761                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
762                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
763                             {1,{{SCRIPT_JUSTIFY_CHARACTER,0,1,1,0,0},0}},
764                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
765                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
766                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}}};
767
768     /* Syriac */
769     static const WCHAR test_syriac[] = {0x0710, 0x0710, 0x0710, 0x0728, 0x0718, 0x0723,0};
770     static const shapeTest_char syriac_c[] = {{5,{0,0}},{4,{0,0}},{3,{0,0}},{2,{0,0}},{1,{0,0}},{0,{0,0}}};
771     static const shapeTest_glyph syriac_g[] = {
772                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
773                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
774                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
775                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
776                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
777                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
778
779     /* Thaana */
780     static const WCHAR test_thaana[] = {0x078a, 0x07ae, 0x0792, 0x07b0, 0x0020, 0x0796, 0x07aa, 0x0789, 0x07b0, 0x0795, 0x07ac, 0x0791, 0x07b0};
781     static const shapeTest_char thaana_c[] = {{12,{0,0}},{12,{0,0}},{10,{0,0}},{10,{0,0}},{8,{1,0}},{7,{0,0}},{7,{0,0}},{5,{0,0}},{5,{0,0}},{3,{0,0}},{3,{0,0}},{1,{0,0}},{1,{0,0}}};
782     static const shapeTest_glyph thaana_g[] = {
783                             {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
784                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
785                             {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
786                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
787                             {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
788                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
789                             {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
790                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
791                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
792                             {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
793                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
794                             {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
795                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
796
797     /* Phags-pa */
798     static const WCHAR test_phagspa[] = {0xa84f, 0xa861, 0xa843, 0x0020, 0xa863, 0xa861, 0xa859, 0x0020, 0xa850, 0xa85c, 0xa85e};
799     static const shapeTest_char phagspa_c[] = {{0,{0,0}},{1,{0,0}},{2,{0,0}},{3,{1,0}},{4,{0,0}},{5,{0,0}},{6,{0,0}},{7,{1,0}},{8,{0,0}},{9,{0,0}},{10,{0,0}}};
800     static const shapeTest_glyph phagspa_g[] = {
801                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
802                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
803                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
804                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
805                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
806                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
807                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
808                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
809                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
810                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
811                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
812
813     /* Lao */
814     static const WCHAR test_lao[] = {0x0ead, 0x0eb1, 0x0e81, 0x0eaa, 0x0ead, 0x0e99, 0x0ea5, 0x0eb2, 0x0ea7, 0};
815     static const shapeTest_char lao_c[] = {{0,{0,0}},{0,{0,0}},{2,{0,0}},{3,{0,0}},{4,{0,0}},{5,{0,0}},{6,{0,0}},{7,{0,0}},{8,{0,0}}};
816     static const shapeTest_glyph lao_g[] = {
817                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
818                             {1,{{SCRIPT_JUSTIFY_CHARACTER,0,1,1,0,0},0}},
819                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
820                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
821                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
822                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
823                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
824                             {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
825                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
826
827     /* Tibetan */
828     static const WCHAR test_tibetan[] = {0x0f04, 0x0f05, 0x0f0e, 0x0020, 0x0f51, 0x0f7c, 0x0f53, 0x0f0b, 0x0f5a, 0x0f53, 0x0f0b, 0x0f51, 0x0f44, 0x0f0b, 0x0f54, 0x0f7c, 0x0f0d};
829     static const shapeTest_char tibetan_c[] = {{0,{0,0}},{1,{0,0}},{2,{0,0}},{3,{1,0}},{4,{0,0}},{4,{0,0}},{6,{0,0}},{7,{0,0}},{8,{0,0}},{9,{0,0}},{10,{0,0}},{11,{0,0}},{12,{0,0}},{13,{0,0}},{14,{0,0}},{14,{0,0}},{16,{0,0}}};
830     static const shapeTest_glyph tibetan_g[] = {
831                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
832                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
833                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
834                             {1,{{SCRIPT_JUSTIFY_BLANK,1,0,0,0,0},0}},
835                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
836                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
837                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
838                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
839                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
840                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
841                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
842                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
843                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
844                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
845                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
846                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
847                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
848
849     /* Devanagari */
850     static const WCHAR test_devanagari[] = {0x0926, 0x0947, 0x0935, 0x0928, 0x093e, 0x0917, 0x0930, 0x0940};
851     static const shapeTest_char devanagari_c[] = {{0,{0,0}},{0,{0,0}},{2,{0,0}},{3,{0,0}},{3,{0,0}},{5,{0,0}},{6,{0,0}},{6,{0,0}}};
852     static const shapeTest_glyph devanagari_g[] = {
853                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
854                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
855                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
856                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
857                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
858                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
859                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
860                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
861
862     /* Bengali */
863     static const WCHAR test_bengali[] = {0x09ac, 0x09be, 0x0982, 0x09b2, 0x09be};
864     static const shapeTest_char bengali_c[] = {{0,{0,0}},{0,{0,0}},{0,{0,0}},{3,{0,0}},{3,{0,0}}};
865     static const shapeTest_glyph bengali_g[] = {
866                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
867                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
868                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
869                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
870                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
871
872     /* Gurmukhi */
873     static const WCHAR test_gurmukhi[] = {0x0a17, 0x0a41, 0x0a30, 0x0a2e, 0x0a41, 0x0a16, 0x0a40};
874     static const shapeTest_char gurmukhi_c[] = {{0,{0,0}},{0,{0,0}},{2,{0,0}},{3,{0,0}},{3,{0,0}},{5,{0,0}},{5,{0,0}}};
875     static const shapeTest_glyph gurmukhi_g[] = {
876                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
877                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
878                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
879                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
880                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
881                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
882                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
883
884     /* Gujarati */
885     static const WCHAR test_gujarati[] = {0x0a97, 0x0ac1, 0x0a9c, 0x0ab0, 0x0abe, 0x0aa4, 0x0ac0};
886     static const shapeTest_char gujarati_c[] = {{0,{0,0}},{0,{0,0}},{2,{0,0}},{3,{0,0}},{3,{0,0}},{5,{0,0}},{5,{0,0}}};
887     static const shapeTest_glyph gujarati_g[] = {
888                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
889                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
890                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
891                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
892                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
893                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
894                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
895
896     /* Oriya */
897     static const WCHAR test_oriya[] = {0x0b13, 0x0b21, 0x0b3c, 0x0b3f, 0x0b06};
898     static const shapeTest_char oriya_c[] = {{0,{0,0}},{1,{0,0}},{1,{0,0}},{1,{0,0}},{3,{0,0}}};
899     static const shapeTest_glyph oriya_g[] = {
900                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
901                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
902                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
903                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
904
905     /* Tamil */
906     static const WCHAR test_tamil[] = {0x0ba4, 0x0bae, 0x0bbf, 0x0bb4, 0x0bcd};
907     static const shapeTest_char tamil_c[] = {{0,{0,0}},{1,{0,0}},{1,{0,0}},{3,{0,0}},{3,{0,0}}};
908     static const shapeTest_glyph tamil_g[] = {
909                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
910                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
911                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
912                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
913
914     /* Telugu */
915     static const WCHAR test_telugu[] = {0x0c24, 0x0c46, 0x0c32, 0x0c41, 0x0c17, 0x0c41};
916     static const shapeTest_char telugu_c[] = {{0,{0,0}},{0,{0,0}},{2,{0,0}},{2,{0,0}},{4,{0,0}},{4,{0,0}}};
917     static const shapeTest_glyph telugu_g[] = {
918                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
919                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
920                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
921                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
922                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
923                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
924
925     /* Malayalam */
926     static const WCHAR test_malayalam[] = {0x0d2e, 0x0d32, 0x0d2f, 0x0d3e, 0x0d33, 0x0d02};
927     static const shapeTest_char malayalam_c[] = {{0,{0,0}},{1,{0,0}},{2,{0,0}},{2,{0,0}},{4,{0,0}},{4,{0,0}}};
928     static const shapeTest_glyph malayalam_g[] = {
929                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
930                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
931                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
932                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
933                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
934                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
935
936     /* Kannada */
937     static const WCHAR test_kannada[] = {0x0c95, 0x0ca8, 0x0ccd, 0x0ca8, 0x0ca1};
938     static const shapeTest_char kannada_c[] = {{0,{0,0}},{1,{0,0}},{1,{0,0}},{1,{0,0}},{3,{0,0}}};
939     static const shapeTest_glyph kannada_g[] = {
940                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
941                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
942                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
943                             {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
944                             {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
945
946     if (!pScriptItemizeOpenType || !pScriptShapeOpenType)
947     {
948         win_skip("ScriptShapeOpenType not available on this platform\n");
949         return;
950     }
951
952     memset(&Control, 0 , sizeof(Control));
953     memset(&State, 0 , sizeof(State));
954
955     hr = pScriptItemizeOpenType(test1, 4, 2, &Control, &State, items, tags, &outnItems);
956     ok(!hr, "ScriptItemizeOpenType should return S_OK not %08x\n", hr);
957     ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
958
959     hr = pScriptShapeOpenType(hdc, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, NULL, NULL, glyphs, NULL, &nb);
960     ok(hr == E_INVALIDARG, "ScriptShapeOpenType should return E_INVALIDARG not %08x\n", hr);
961
962     hr = pScriptShapeOpenType(hdc, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, NULL, NULL, glyphs, glyphProp, NULL);
963     ok(hr == E_INVALIDARG, "ScriptShapeOpenType should return E_INVALIDARG not %08x\n", hr);
964
965     hr = pScriptShapeOpenType(NULL, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, NULL, NULL, glyphs, glyphProp, &nb);
966     ok(hr == E_INVALIDARG, "ScriptShapeOpenType should return E_PENDING not %08x\n", hr);
967
968     hr = pScriptShapeOpenType(hdc, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, NULL, NULL, glyphs, glyphProp, &nb);
969     ok( hr == E_INVALIDARG,
970        "ScriptShapeOpenType should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
971     hr = pScriptShapeOpenType(hdc, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, logclust, NULL, glyphs, glyphProp, &nb);
972     ok(hr == E_INVALIDARG, "ScriptShapeOpenType should return E_INVALIDARG not %08x\n", hr);
973
974     ScriptFreeCache(&sc);
975
976     test_shape_ok(hdc, test1, 4, &Control, &State, 0, 4, t1_c, t1_g);
977     test_shape_ok(hdc, test2, 4, &Control, &State, 1, 4, t2_c, t2_g);
978
979     test_valid = find_font_for_range(hdc, "Microsoft Sans Serif", 11, test_hebrew[0], &hfont, &hfont_orig);
980     if (hfont != NULL)
981     {
982         test_shape_ok_valid(test_valid, hdc, test_hebrew, 4, &Control, &State, 0, 4, hebrew_c, hebrew_g);
983         SelectObject(hdc, hfont_orig);
984         DeleteObject(hfont);
985     }
986
987     test_valid = find_font_for_range(hdc, "Microsoft Sans Serif", 13, test_arabic[0], &hfont, &hfont_orig);
988     if (hfont != NULL)
989     {
990         test_shape_ok_valid(test_valid, hdc, test_arabic, 4, &Control, &State, 0, 3, arabic_c, arabic_g);
991         SelectObject(hdc, hfont_orig);
992         DeleteObject(hfont);
993     }
994
995     test_valid = find_font_for_range(hdc, "Microsoft Sans Serif", 24, test_thai[0], &hfont, &hfont_orig);
996     if (hfont != NULL)
997     {
998         test_shape_ok_valid(test_valid, hdc, test_thai, 10, &Control, &State, 0, 10, thai_c, thai_g);
999         SelectObject(hdc, hfont_orig);
1000         DeleteObject(hfont);
1001     }
1002
1003     test_valid = find_font_for_range(hdc, "Estrangelo Edessa", 71, test_syriac[0], &hfont, &hfont_orig);
1004     if (hfont != NULL)
1005     {
1006         test_shape_ok_valid(test_valid, hdc, test_syriac, 6, &Control, &State, 0, 6, syriac_c, syriac_g);
1007         SelectObject(hdc, hfont_orig);
1008         DeleteObject(hfont);
1009     }
1010
1011     test_valid = find_font_for_range(hdc, "MV Boli", 72, test_thaana[0], &hfont, &hfont_orig);
1012     if (hfont != NULL)
1013     {
1014         test_shape_ok_valid(test_valid, hdc, test_thaana, 13, &Control, &State, 0, 13, thaana_c, thaana_g);
1015         SelectObject(hdc, hfont_orig);
1016         DeleteObject(hfont);
1017     }
1018
1019     test_valid = find_font_for_range(hdc, "Microsoft PhagsPa", 53, test_phagspa[0], &hfont, &hfont_orig);
1020     if (hfont != NULL)
1021     {
1022         test_shape_ok_valid(test_valid, hdc, test_phagspa, 11, &Control, &State, 0, 11, phagspa_c, phagspa_g);
1023         SelectObject(hdc, hfont_orig);
1024         DeleteObject(hfont);
1025     }
1026
1027     test_valid = find_font_for_range(hdc, "DokChampa", 25, test_lao[0], &hfont, &hfont_orig);
1028     if (hfont != NULL)
1029     {
1030         test_shape_ok_valid(test_valid, hdc, test_lao, 9, &Control, &State, 0, 9, lao_c, lao_g);
1031         SelectObject(hdc, hfont_orig);
1032         DeleteObject(hfont);
1033     }
1034
1035     test_valid = find_font_for_range(hdc, "Microsoft Himalaya", 70, test_tibetan[0], &hfont, &hfont_orig);
1036     if (hfont != NULL)
1037     {
1038         test_shape_ok_valid(test_valid, hdc, test_tibetan, 17, &Control, &State, 0, 17, tibetan_c, tibetan_g);
1039         SelectObject(hdc, hfont_orig);
1040         DeleteObject(hfont);
1041     }
1042
1043     test_valid = find_font_for_range(hdc, "Mangal", 15, test_devanagari[0], &hfont, &hfont_orig);
1044     if (hfont != NULL)
1045     {
1046         test_shape_ok_valid(test_valid, hdc, test_devanagari, 8, &Control, &State, 0, 8, devanagari_c, devanagari_g);
1047         SelectObject(hdc, hfont_orig);
1048         DeleteObject(hfont);
1049     }
1050
1051     test_valid = find_font_for_range(hdc, "Vrinda", 16, test_bengali[0], &hfont, &hfont_orig);
1052     if (hfont != NULL)
1053     {
1054         test_shape_ok_valid(test_valid, hdc, test_bengali, 5, &Control, &State, 0, 5, bengali_c, bengali_g);
1055         SelectObject(hdc, hfont_orig);
1056         DeleteObject(hfont);
1057     }
1058
1059     test_valid = find_font_for_range(hdc, "Raavi", 17, test_gurmukhi[0], &hfont, &hfont_orig);
1060     if (hfont != NULL)
1061     {
1062         test_shape_ok_valid(test_valid, hdc, test_gurmukhi, 7, &Control, &State, 0, 7, gurmukhi_c, gurmukhi_g);
1063         SelectObject(hdc, hfont_orig);
1064         DeleteObject(hfont);
1065     }
1066
1067     test_valid = find_font_for_range(hdc, "Shruti", 18, test_gujarati[0], &hfont, &hfont_orig);
1068     if (hfont != NULL)
1069     {
1070         test_shape_ok_valid(test_valid, hdc, test_gujarati, 7, &Control, &State, 0, 7, gujarati_c, gujarati_g);
1071         SelectObject(hdc, hfont_orig);
1072         DeleteObject(hfont);
1073     }
1074
1075     test_valid = find_font_for_range(hdc, "Kalinga", 19, test_oriya[0], &hfont, &hfont_orig);
1076     if (hfont != NULL)
1077     {
1078         test_shape_ok_valid(test_valid, hdc, test_oriya, 5, &Control, &State, 0, 4, oriya_c, oriya_g);
1079         SelectObject(hdc, hfont_orig);
1080         DeleteObject(hfont);
1081     }
1082
1083     test_valid = find_font_for_range(hdc, "Latha", 20, test_tamil[0], &hfont, &hfont_orig);
1084     if (hfont != NULL)
1085     {
1086         test_shape_ok_valid(test_valid, hdc, test_tamil, 5, &Control, &State, 0, 4, tamil_c, tamil_g);
1087         SelectObject(hdc, hfont_orig);
1088         DeleteObject(hfont);
1089     }
1090
1091     test_valid = find_font_for_range(hdc, "Gautami", 21, test_telugu[0], &hfont, &hfont_orig);
1092     if (hfont != NULL)
1093     {
1094         test_shape_ok_valid(test_valid, hdc, test_telugu, 6, &Control, &State, 0, 6, telugu_c, telugu_g);
1095         SelectObject(hdc, hfont_orig);
1096         DeleteObject(hfont);
1097     }
1098
1099     test_valid = find_font_for_range(hdc, "Kartika", 23, test_malayalam[0], &hfont, &hfont_orig);
1100     if (hfont != NULL)
1101     {
1102         test_shape_ok_valid(test_valid, hdc, test_malayalam, 6, &Control, &State, 0, 6, malayalam_c, malayalam_g);
1103         SelectObject(hdc, hfont_orig);
1104         DeleteObject(hfont);
1105     }
1106
1107     test_valid = find_font_for_range(hdc, "Tunga", 22, test_kannada[0], &hfont, &hfont_orig);
1108     if (hfont != NULL)
1109     {
1110         test_shape_ok_valid(test_valid, hdc, test_kannada, 5, &Control, &State, 0, 4, kannada_c, kannada_g);
1111         SelectObject(hdc, hfont_orig);
1112         DeleteObject(hfont);
1113     }
1114 }
1115
1116 static void test_ScriptShape(HDC hdc)
1117 {
1118     static const WCHAR test1[] = {'w', 'i', 'n', 'e',0};
1119     static const WCHAR test2[] = {0x202B, 'i', 'n', 0x202C,0};
1120     HRESULT hr;
1121     SCRIPT_CACHE sc = NULL;
1122     WORD glyphs[4], glyphs2[4], logclust[4];
1123     SCRIPT_VISATTR attrs[4];
1124     SCRIPT_ITEM items[2];
1125     int nb;
1126
1127     hr = ScriptItemize(test1, 4, 2, NULL, NULL, items, NULL);
1128     ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
1129     ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1130
1131     hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, NULL, &nb);
1132     ok(hr == E_INVALIDARG, "ScriptShape should return E_INVALIDARG not %08x\n", hr);
1133
1134     hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, attrs, NULL);
1135     ok(hr == E_INVALIDARG, "ScriptShape should return E_INVALIDARG not %08x\n", hr);
1136
1137     hr = ScriptShape(NULL, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, attrs, &nb);
1138     ok(hr == E_PENDING, "ScriptShape should return E_PENDING not %08x\n", hr);
1139
1140     hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, attrs, &nb);
1141     ok(broken(hr == S_OK) ||
1142        hr == E_INVALIDARG || /* Vista, W2K8 */
1143        hr == E_FAIL, /* WIN7 */
1144        "ScriptShape should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
1145     ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1146
1147     hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, logclust, attrs, &nb);
1148     ok(!hr, "ScriptShape should return S_OK not %08x\n", hr);
1149     ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1150
1151
1152     memset(glyphs,-1,sizeof(glyphs));
1153     memset(logclust,-1,sizeof(logclust));
1154     memset(attrs,-1,sizeof(attrs));
1155     hr = ScriptShape(NULL, &sc, test1, 4, 4, &items[0].a, glyphs, logclust, attrs, &nb);
1156     ok(!hr, "ScriptShape should return S_OK not %08x\n", hr);
1157     ok(nb == 4, "Wrong number of items\n");
1158     ok(logclust[0] == 0, "clusters out of order\n");
1159     ok(logclust[1] == 1, "clusters out of order\n");
1160     ok(logclust[2] == 2, "clusters out of order\n");
1161     ok(logclust[3] == 3, "clusters out of order\n");
1162     ok(attrs[0].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1163     ok(attrs[1].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1164     ok(attrs[2].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1165     ok(attrs[3].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1166     ok(attrs[0].fClusterStart == 1, "fClusterStart incorrect\n");
1167     ok(attrs[1].fClusterStart == 1, "fClusterStart incorrect\n");
1168     ok(attrs[2].fClusterStart == 1, "fClusterStart incorrect\n");
1169     ok(attrs[3].fClusterStart == 1, "fClusterStart incorrect\n");
1170     ok(attrs[0].fDiacritic == 0, "fDiacritic incorrect\n");
1171     ok(attrs[1].fDiacritic == 0, "fDiacritic incorrect\n");
1172     ok(attrs[2].fDiacritic == 0, "fDiacritic incorrect\n");
1173     ok(attrs[3].fDiacritic == 0, "fDiacritic incorrect\n");
1174     ok(attrs[0].fZeroWidth == 0, "fZeroWidth incorrect\n");
1175     ok(attrs[1].fZeroWidth == 0, "fZeroWidth incorrect\n");
1176     ok(attrs[2].fZeroWidth == 0, "fZeroWidth incorrect\n");
1177     ok(attrs[3].fZeroWidth == 0, "fZeroWidth incorrect\n");
1178
1179     ScriptFreeCache(&sc);
1180     sc = NULL;
1181
1182     memset(glyphs2,-1,sizeof(glyphs2));
1183     memset(logclust,-1,sizeof(logclust));
1184     memset(attrs,-1,sizeof(attrs));
1185     hr = ScriptShape(hdc, &sc, test2, 4, 4, &items[0].a, glyphs2, logclust, attrs, &nb);
1186     ok(hr == S_OK, "ScriptShape should return S_OK not %08x\n", hr);
1187     ok(nb == 4, "Wrong number of items\n");
1188     ok(glyphs2[0] == 0 || broken(glyphs2[0] == 0x80), "Incorrect glyph for 0x202B\n");
1189     ok(glyphs2[3] == 0 || broken(glyphs2[3] == 0x80), "Incorrect glyph for 0x202C\n");
1190     ok(logclust[0] == 0, "clusters out of order\n");
1191     ok(logclust[1] == 1, "clusters out of order\n");
1192     ok(logclust[2] == 2, "clusters out of order\n");
1193     ok(logclust[3] == 3, "clusters out of order\n");
1194     ok(attrs[0].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1195     ok(attrs[1].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1196     ok(attrs[2].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1197     ok(attrs[3].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1198     ok(attrs[0].fClusterStart == 1, "fClusterStart incorrect\n");
1199     ok(attrs[1].fClusterStart == 1, "fClusterStart incorrect\n");
1200     ok(attrs[2].fClusterStart == 1, "fClusterStart incorrect\n");
1201     ok(attrs[3].fClusterStart == 1, "fClusterStart incorrect\n");
1202     ok(attrs[0].fDiacritic == 0, "fDiacritic incorrect\n");
1203     ok(attrs[1].fDiacritic == 0, "fDiacritic incorrect\n");
1204     ok(attrs[2].fDiacritic == 0, "fDiacritic incorrect\n");
1205     ok(attrs[3].fDiacritic == 0, "fDiacritic incorrect\n");
1206     ok(attrs[0].fZeroWidth == 0, "fZeroWidth incorrect\n");
1207     ok(attrs[1].fZeroWidth == 0, "fZeroWidth incorrect\n");
1208     ok(attrs[2].fZeroWidth == 0, "fZeroWidth incorrect\n");
1209     ok(attrs[3].fZeroWidth == 0, "fZeroWidth incorrect\n");
1210
1211     /* modify LTR to RTL */
1212     items[0].a.fRTL = 1;
1213     memset(glyphs2,-1,sizeof(glyphs2));
1214     memset(logclust,-1,sizeof(logclust));
1215     memset(attrs,-1,sizeof(attrs));
1216     hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs2, logclust, attrs, &nb);
1217     ok(!hr, "ScriptShape should return S_OK not %08x\n", hr);
1218     ok(nb == 4, "Wrong number of items\n");
1219     ok(glyphs2[0] == glyphs[3], "Glyphs not reordered properly\n");
1220     ok(glyphs2[1] == glyphs[2], "Glyphs not reordered properly\n");
1221     ok(glyphs2[2] == glyphs[1], "Glyphs not reordered properly\n");
1222     ok(glyphs2[3] == glyphs[0], "Glyphs not reordered properly\n");
1223     ok(logclust[0] == 3, "clusters out of order\n");
1224     ok(logclust[1] == 2, "clusters out of order\n");
1225     ok(logclust[2] == 1, "clusters out of order\n");
1226     ok(logclust[3] == 0, "clusters out of order\n");
1227     ok(attrs[0].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1228     ok(attrs[1].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1229     ok(attrs[2].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1230     ok(attrs[3].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1231     ok(attrs[0].fClusterStart == 1, "fClusterStart incorrect\n");
1232     ok(attrs[1].fClusterStart == 1, "fClusterStart incorrect\n");
1233     ok(attrs[2].fClusterStart == 1, "fClusterStart incorrect\n");
1234     ok(attrs[3].fClusterStart == 1, "fClusterStart incorrect\n");
1235     ok(attrs[0].fDiacritic == 0, "fDiacritic incorrect\n");
1236     ok(attrs[1].fDiacritic == 0, "fDiacritic incorrect\n");
1237     ok(attrs[2].fDiacritic == 0, "fDiacritic incorrect\n");
1238     ok(attrs[3].fDiacritic == 0, "fDiacritic incorrect\n");
1239     ok(attrs[0].fZeroWidth == 0, "fZeroWidth incorrect\n");
1240     ok(attrs[1].fZeroWidth == 0, "fZeroWidth incorrect\n");
1241     ok(attrs[2].fZeroWidth == 0, "fZeroWidth incorrect\n");
1242     ok(attrs[3].fZeroWidth == 0, "fZeroWidth incorrect\n");
1243
1244     ScriptFreeCache(&sc);
1245 }
1246
1247 static void test_ScriptPlace(HDC hdc)
1248 {
1249     static const WCHAR test1[] = {'t', 'e', 's', 't',0};
1250     BOOL ret;
1251     HRESULT hr;
1252     SCRIPT_CACHE sc = NULL;
1253     WORD glyphs[4], logclust[4];
1254     SCRIPT_VISATTR attrs[4];
1255     SCRIPT_ITEM items[2];
1256     int nb, widths[4];
1257     GOFFSET offset[4];
1258     ABC abc[4];
1259
1260     hr = ScriptItemize(test1, 4, 2, NULL, NULL, items, NULL);
1261     ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
1262     ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1263
1264     hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, logclust, attrs, &nb);
1265     ok(!hr, "ScriptShape should return S_OK not %08x\n", hr);
1266     ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1267
1268     hr = ScriptPlace(hdc, &sc, glyphs, 4, NULL, &items[0].a, widths, NULL, NULL);
1269     ok(hr == E_INVALIDARG, "ScriptPlace should return E_INVALIDARG not %08x\n", hr);
1270
1271     hr = ScriptPlace(NULL, &sc, glyphs, 4, attrs, &items[0].a, widths, NULL, NULL);
1272     ok(broken(hr == E_PENDING) ||
1273        hr == E_INVALIDARG || /* Vista, W2K8 */
1274        hr == E_FAIL, /* WIN7 */
1275        "ScriptPlace should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
1276
1277     hr = ScriptPlace(NULL, &sc, glyphs, 4, attrs, &items[0].a, widths, offset, NULL);
1278     ok(hr == E_PENDING, "ScriptPlace should return E_PENDING not %08x\n", hr);
1279
1280     hr = ScriptPlace(NULL, &sc, glyphs, 4, attrs, &items[0].a, widths, NULL, abc);
1281     ok(broken(hr == E_PENDING) ||
1282        hr == E_INVALIDARG || /* Vista, W2K8 */
1283        hr == E_FAIL, /* WIN7 */
1284        "ScriptPlace should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
1285
1286     hr = ScriptPlace(hdc, &sc, glyphs, 4, attrs, &items[0].a, widths, offset, NULL);
1287     ok(!hr, "ScriptPlace should return S_OK not %08x\n", hr);
1288     ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1289
1290     ret = ExtTextOutW(hdc, 1, 1, 0, NULL, glyphs, 4, widths);
1291     ok(ret, "ExtTextOutW should return TRUE\n");
1292
1293     ScriptFreeCache(&sc);
1294 }
1295
1296 static void test_ScriptItemIzeShapePlace(HDC hdc, unsigned short pwOutGlyphs[256])
1297 {
1298     HRESULT         hr;
1299     int             iMaxProps;
1300     const SCRIPT_PROPERTIES **ppSp;
1301
1302     int             cInChars;
1303     int             cMaxItems;
1304     SCRIPT_ITEM     pItem[255];
1305     int             pcItems;
1306     WCHAR           TestItem1[] = {'T', 'e', 's', 't', 'a', 0}; 
1307     WCHAR           TestItem2[] = {'T', 'e', 's', 't', 'b', 0}; 
1308     WCHAR           TestItem3[] = {'T', 'e', 's', 't', 'c',' ','1','2','3',' ',' ','e','n','d',0};
1309     WCHAR           TestItem4[] = {'T', 'e', 's', 't', 'd',' ',0x0684,0x0694,0x06a4,' ',' ','\r','\n','e','n','d',0};
1310     WCHAR           TestItem5[] = {0x0684,'T','e','s','t','e',' ',0x0684,0x0694,0x06a4,' ',' ','e','n','d',0};
1311     WCHAR           TestItem6[] = {'T', 'e', 's', 't', 'f',' ',' ',' ','\r','\n','e','n','d',0};
1312
1313     SCRIPT_CACHE    psc;
1314     int             cChars;
1315     int             cMaxGlyphs;
1316     unsigned short  pwOutGlyphs1[256];
1317     unsigned short  pwOutGlyphs2[256];
1318     unsigned short  pwLogClust[256];
1319     SCRIPT_VISATTR  psva[256];
1320     int             pcGlyphs;
1321     int             piAdvance[256];
1322     GOFFSET         pGoffset[256];
1323     ABC             pABC[256];
1324     int             cnt;
1325
1326     /* Start testing usp10 functions                                                         */
1327     /* This test determines that the pointer returned by ScriptGetProperties is valid
1328      * by checking a known value in the table                                                */
1329     hr = ScriptGetProperties(&ppSp, &iMaxProps);
1330     ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
1331     trace("number of script properties %d\n", iMaxProps);
1332     ok (iMaxProps > 0, "Number of scripts returned should not be 0\n");
1333     if  (iMaxProps > 0)
1334          ok( ppSp[0]->langid == 0, "Langid[0] not = to 0\n"); /* Check a known value to ensure   */
1335                                                               /* ptrs work                       */
1336
1337     /* This is a valid test that will cause parsing to take place                             */
1338     cInChars = 5;
1339     cMaxItems = 255;
1340     hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1341     ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1342     /*  This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
1343      *  returned.                                                                             */
1344     ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
1345     if (pcItems > 0)
1346         ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
1347             "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
1348             pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
1349
1350     /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
1351      * ie. ScriptItemize has succeeded and that pItem has been set                            */
1352     cInChars = 5;
1353     if (hr == 0) {
1354         psc = NULL;                                   /* must be null on first call           */
1355         cChars = cInChars;
1356         cMaxGlyphs = cInChars;
1357         hr = ScriptShape(NULL, &psc, TestItem1, cChars,
1358                          cMaxGlyphs, &pItem[0].a,
1359                          pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1360         ok (hr == E_PENDING, "If psc is NULL (%08x) the E_PENDING should be returned\n", hr);
1361         cMaxGlyphs = 4;
1362         hr = ScriptShape(hdc, &psc, TestItem1, cChars,
1363                          cMaxGlyphs, &pItem[0].a,
1364                          pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1365         ok (hr == E_OUTOFMEMORY, "If not enough output area cChars (%d) is > than CMaxGlyphs "
1366                                  "(%d) but not E_OUTOFMEMORY\n",
1367                                  cChars, cMaxGlyphs);
1368         cMaxGlyphs = 256;
1369         hr = ScriptShape(hdc, &psc, TestItem1, cChars,
1370                          cMaxGlyphs, &pItem[0].a,
1371                          pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1372         ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
1373         ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1374         ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
1375         if (hr ==0) {
1376             hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
1377                              pGoffset, pABC);
1378             ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", hr);
1379             hr = ScriptPlace(NULL, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
1380                              pGoffset, pABC);
1381             ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", hr);
1382             for (cnt=0; cnt < pcGlyphs; cnt++)
1383                 pwOutGlyphs[cnt] = pwOutGlyphs1[cnt];                 /* Send to next function */
1384         }
1385
1386         /* This test will check to make sure that SCRIPT_CACHE is reused and that not translation   *
1387          * takes place if fNoGlyphIndex is set.                                                     */
1388
1389         cInChars = 5;
1390         cMaxItems = 255;
1391         hr = ScriptItemize(TestItem2, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1392         ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1393         /*  This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is   *
1394          *  returned.                                                                               */
1395         ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
1396                             "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
1397                              pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
1398         /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue                    */
1399         if (hr == 0) {
1400              cChars = cInChars;
1401              cMaxGlyphs = 256;
1402              pItem[0].a.fNoGlyphIndex = 1;                /* say no translate                     */
1403              hr = ScriptShape(NULL, &psc, TestItem2, cChars,
1404                               cMaxGlyphs, &pItem[0].a,
1405                               pwOutGlyphs2, pwLogClust, psva, &pcGlyphs);
1406              ok (hr != E_PENDING, "If psc should not be NULL (%08x) and the E_PENDING should be returned\n", hr);
1407              ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
1408              ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1409              ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
1410              for (cnt=0; cnt < cChars && TestItem2[cnt] == pwOutGlyphs2[cnt]; cnt++) {}
1411              ok (cnt == cChars, "Translation to place when told not to. WCHAR %d - %04x != %04x\n",
1412                            cnt, TestItem2[cnt], pwOutGlyphs2[cnt]);
1413              if (hr ==0) {
1414                  hr = ScriptPlace(hdc, &psc, pwOutGlyphs2, pcGlyphs, psva, &pItem[0].a, piAdvance,
1415                                   pGoffset, pABC);
1416                  ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", hr);
1417              }
1418         }
1419         ScriptFreeCache( &psc);
1420         ok (!psc, "psc is not null after ScriptFreeCache\n");
1421
1422     }
1423
1424     /* This is a valid test that will cause parsing to take place and create 3 script_items   */
1425     cInChars = (sizeof(TestItem3)/2)-1;
1426     cMaxItems = 255;
1427     hr = ScriptItemize(TestItem3, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1428     ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1429     if  (hr == 0)
1430         {
1431         ok (pcItems == 3, "The number of SCRIPT_ITEMS should be 3 not %d\n", pcItems);
1432         if (pcItems > 2)
1433         {
1434             ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == 6,
1435                 "Start pos [0] not = 0 (%d) or end pos [1] not = %d\n",
1436                 pItem[0].iCharPos, pItem[1].iCharPos);
1437             ok (pItem[1].iCharPos == 6 && pItem[2].iCharPos == 11,
1438                 "Start pos [1] not = 6 (%d) or end pos [2] not = 11 (%d)\n",
1439                 pItem[1].iCharPos, pItem[2].iCharPos);
1440             ok (pItem[2].iCharPos == 11 && pItem[3].iCharPos == cInChars,
1441                 "Start pos [2] not = 11 (%d) or end [3] pos not = 14 (%d), cInChars = %d\n",
1442                 pItem[2].iCharPos, pItem[3].iCharPos, cInChars);
1443         }
1444     }
1445
1446     /* This is a valid test that will cause parsing to take place and create 5 script_items   */
1447     cInChars = (sizeof(TestItem4)/2)-1;
1448     cMaxItems = 255;
1449     hr = ScriptItemize(TestItem4, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1450     ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1451     if  (hr == 0)
1452         {
1453         ok (pcItems == 5, "The number of SCRIPT_ITEMS should be 5 not %d\n", pcItems);
1454         if (pcItems > 4)
1455         {
1456             ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == 6,
1457                 "Start pos [0] not = 0 (%d) or end pos [1] not = %d\n",
1458                 pItem[0].iCharPos, pItem[1].iCharPos);
1459             ok (pItem[0].a.s.uBidiLevel == 0, "Should have been bidi=0 not %d\n",
1460                                                pItem[0].a.s.uBidiLevel);
1461             ok (pItem[1].iCharPos == 6 && pItem[2].iCharPos == 11,
1462                 "Start pos [1] not = 6 (%d) or end pos [2] not = 11 (%d)\n",
1463                 pItem[1].iCharPos, pItem[2].iCharPos);
1464             ok (pItem[1].a.s.uBidiLevel == 1, "Should have been bidi=1 not %d\n",
1465                                               pItem[1].a.s.uBidiLevel);
1466             ok (pItem[2].iCharPos == 11 && pItem[3].iCharPos == 12,
1467                 "Start pos [2] not = 11 (%d) or end [3] pos not = 12 (%d)\n",
1468                 pItem[2].iCharPos, pItem[3].iCharPos);
1469             ok (pItem[2].a.s.uBidiLevel == 0, "Should have been bidi=0 not %d\n",
1470                                                pItem[2].a.s.uBidiLevel);
1471             ok (pItem[3].iCharPos == 12 && pItem[4].iCharPos == 13,
1472                 "Start pos [3] not = 12 (%d) or end [4] pos not = 13 (%d)\n",
1473                 pItem[3].iCharPos, pItem[4].iCharPos);
1474             ok (pItem[3].a.s.uBidiLevel == 0, "Should have been bidi=0 not %d\n",
1475                                                pItem[3].a.s.uBidiLevel);
1476             ok (pItem[4].iCharPos == 13 && pItem[5].iCharPos == cInChars,
1477                 "Start pos [4] not = 13 (%d) or end [5] pos not = 16 (%d), cInChars = %d\n",
1478                 pItem[4].iCharPos, pItem[5].iCharPos, cInChars);
1479         }
1480     }
1481
1482     /*
1483      * This test is for when the first unicode character requires bidi support
1484      */
1485     cInChars = (sizeof(TestItem5)-1)/sizeof(WCHAR);
1486     hr = ScriptItemize(TestItem5, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1487     ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1488     ok (pcItems == 4, "There should have been 4 items, found %d\n", pcItems);
1489     ok (pItem[0].a.s.uBidiLevel == 1, "The first character should have been bidi=1 not %d\n",
1490                                        pItem[0].a.s.uBidiLevel);
1491
1492     /* This test checks to make sure that the test to see if there are sufficient buffers to store  *
1493      * the pointer to the last char works.  Note that windows often needs a greater number of       *
1494      * SCRIPT_ITEMS to process a string than is returned in pcItems.                                */
1495     cInChars = (sizeof(TestItem6)/2)-1;
1496     cMaxItems = 4;
1497     hr = ScriptItemize(TestItem6, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1498     ok (hr == E_OUTOFMEMORY, "ScriptItemize should return E_OUTOFMEMORY, returned %08x\n", hr);
1499
1500 }
1501
1502 static void test_ScriptGetCMap(HDC hdc, unsigned short pwOutGlyphs[256])
1503 {
1504     HRESULT         hr;
1505     SCRIPT_CACHE    psc = NULL;
1506     int             cInChars;
1507     int             cChars;
1508     unsigned short  pwOutGlyphs2[256];
1509     unsigned short  pwOutGlyphs3[256];
1510     DWORD           dwFlags;
1511     int             cnt;
1512
1513     static const WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
1514     static const WCHAR TestItem2[] = {0x202B, 'i', 'n', 0x202C,0};
1515     static const WCHAR TestItem3[] = {'a','b','c','d','(','<','{','[',0x2039,0};
1516     static const WCHAR TestItem3b[] = {'a','b','c','d',')','>','}',']',0x203A,0};
1517
1518     /*  Check to make sure that SCRIPT_CACHE gets allocated ok                     */
1519     dwFlags = 0;
1520     cInChars = cChars = 5;
1521     /* Some sanity checks for ScriptGetCMap */
1522
1523     hr = ScriptGetCMap(NULL, NULL, NULL, 0, 0, NULL);
1524     ok( hr == E_INVALIDARG, "(NULL,NULL,NULL,0,0,NULL), "
1525                             "expected E_INVALIDARG, got %08x\n", hr);
1526
1527     hr = ScriptGetCMap(NULL, NULL, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
1528     ok( hr == E_INVALIDARG, "(NULL,NULL,TestItem1, cInChars, dwFlags, pwOutGlyphs3), "
1529                             "expected E_INVALIDARG, got %08x\n", hr);
1530
1531     /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1532     psc = NULL;
1533     hr = ScriptGetCMap(NULL, &psc, TestItem1, cInChars, 0, pwOutGlyphs3);
1534     ok( hr == E_PENDING, "(NULL,&psc,NULL,0,0,NULL), expected E_PENDING, "
1535                          "got %08x\n", hr);
1536     ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1537
1538     /* Set psc to NULL but add hdc, to be able to check if a pointer is returned in psc */
1539     psc = NULL;
1540     hr = ScriptGetCMap(hdc, &psc, TestItem1, cInChars, 0, pwOutGlyphs3);
1541     ok( hr == S_OK, "ScriptGetCMap(NULL,&psc,NULL,0,0,NULL), expected S_OK, "
1542                     "got %08x\n", hr);
1543     ok( psc != NULL, "ScritpGetCMap expected psc to be not NULL\n");
1544     ScriptFreeCache( &psc);
1545
1546     /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1547     psc = NULL;
1548     hr = ScriptGetCMap(NULL, &psc, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
1549     ok( hr == E_PENDING, "(NULL,&psc,), expected E_PENDING, got %08x\n", hr);
1550     ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1551     /*  Check to see if the results are the same as those returned by ScriptShape  */
1552     hr = ScriptGetCMap(hdc, &psc, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
1553     ok (hr == 0, "ScriptGetCMap should return 0 not (%08x)\n", hr);
1554     ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1555     for (cnt=0; cnt < cChars && pwOutGlyphs[cnt] == pwOutGlyphs3[cnt]; cnt++) {}
1556     ok (cnt == cInChars, "Translation not correct. WCHAR %d - %04x != %04x\n",
1557                          cnt, pwOutGlyphs[cnt], pwOutGlyphs3[cnt]);
1558
1559     ScriptFreeCache( &psc);
1560     ok (!psc, "psc is not null after ScriptFreeCache\n");
1561
1562     cInChars = cChars = 4;
1563     hr = ScriptGetCMap(hdc, &psc, TestItem2, cInChars, dwFlags, pwOutGlyphs3);
1564     ok (hr == S_FALSE, "ScriptGetCMap should return S_FALSE not (%08x)\n", hr);
1565     ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1566     ok(pwOutGlyphs3[0] == 0 || broken(pwOutGlyphs3[0] == 0x80), "Glyph 0 should be default glyph\n");
1567     ok(pwOutGlyphs3[3] == 0 || broken(pwOutGlyphs3[0] == 0x80), "Glyph 0 should be default glyph\n");
1568
1569
1570     cInChars = cChars = 9;
1571     hr = ScriptGetCMap(hdc, &psc, TestItem3b, cInChars, dwFlags, pwOutGlyphs2);
1572     ok (hr == S_OK, "ScriptGetCMap should return S_OK not (%08x)\n", hr);
1573     ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1574
1575     cInChars = cChars = 9;
1576     dwFlags = SGCM_RTL;
1577     hr = ScriptGetCMap(hdc, &psc, TestItem3, cInChars, dwFlags, pwOutGlyphs3);
1578     ok (hr == S_OK, "ScriptGetCMap should return S_OK not (%08x)\n", hr);
1579     ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1580     ok(pwOutGlyphs3[0] == pwOutGlyphs2[0], "glyph incorrectly altered\n");
1581     ok(pwOutGlyphs3[1] == pwOutGlyphs2[1], "glyph incorreclty altered\n");
1582     ok(pwOutGlyphs3[2] == pwOutGlyphs2[2], "glyph incorreclty altered\n");
1583     ok(pwOutGlyphs3[3] == pwOutGlyphs2[3], "glyph incorreclty altered\n");
1584     ok(pwOutGlyphs3[4] == pwOutGlyphs2[4], "glyph not mirrored correctly\n");
1585     ok(pwOutGlyphs3[5] == pwOutGlyphs2[5], "glyph not mirrored correctly\n");
1586     ok(pwOutGlyphs3[6] == pwOutGlyphs2[6], "glyph not mirrored correctly\n");
1587     ok(pwOutGlyphs3[7] == pwOutGlyphs2[7], "glyph not mirrored correctly\n");
1588     ok(pwOutGlyphs3[8] == pwOutGlyphs2[8], "glyph not mirrored correctly\n");
1589
1590     ScriptFreeCache( &psc);
1591     ok (!psc, "psc is not null after ScriptFreeCache\n");
1592 }
1593
1594 static void test_ScriptGetFontProperties(HDC hdc)
1595 {
1596     HRESULT         hr;
1597     SCRIPT_CACHE    psc,old_psc;
1598     SCRIPT_FONTPROPERTIES sfp;
1599
1600     /* Some sanity checks for ScriptGetFontProperties */
1601
1602     hr = ScriptGetFontProperties(NULL,NULL,NULL);
1603     ok( hr == E_INVALIDARG, "(NULL,NULL,NULL), expected E_INVALIDARG, got %08x\n", hr);
1604
1605     hr = ScriptGetFontProperties(NULL,NULL,&sfp);
1606     ok( hr == E_INVALIDARG, "(NULL,NULL,&sfp), expected E_INVALIDARG, got %08x\n", hr);
1607
1608     /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1609     psc = NULL;
1610     hr = ScriptGetFontProperties(NULL,&psc,NULL);
1611     ok( hr == E_INVALIDARG, "(NULL,&psc,NULL), expected E_INVALIDARG, got %08x\n", hr);
1612     ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1613
1614     /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1615     psc = NULL;
1616     hr = ScriptGetFontProperties(NULL,&psc,&sfp);
1617     ok( hr == E_PENDING, "(NULL,&psc,&sfp), expected E_PENDING, got %08x\n", hr);
1618     ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1619
1620     hr = ScriptGetFontProperties(hdc,NULL,NULL);
1621     ok( hr == E_INVALIDARG, "(hdc,NULL,NULL), expected E_INVALIDARG, got %08x\n", hr);
1622
1623     hr = ScriptGetFontProperties(hdc,NULL,&sfp);
1624     ok( hr == E_INVALIDARG, "(hdc,NULL,&sfp), expected E_INVALIDARG, got %08x\n", hr);
1625
1626     /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1627     psc = NULL;
1628     hr = ScriptGetFontProperties(hdc,&psc,NULL);
1629     ok( hr == E_INVALIDARG, "(hdc,&psc,NULL), expected E_INVALIDARG, got %08x\n", hr);
1630     ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1631
1632     /* Pass an invalid sfp */
1633     psc = NULL;
1634     sfp.cBytes = sizeof(SCRIPT_FONTPROPERTIES) - 1;
1635     hr = ScriptGetFontProperties(hdc,&psc,&sfp);
1636     ok( hr == E_INVALIDARG, "(hdc,&psc,&sfp) invalid, expected E_INVALIDARG, got %08x\n", hr);
1637     ok( psc != NULL, "Expected a pointer in psc, got NULL\n");
1638     ScriptFreeCache(&psc);
1639     ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1640
1641     /* Give it the correct cBytes, we don't care about what's coming back */
1642     sfp.cBytes = sizeof(SCRIPT_FONTPROPERTIES);
1643     psc = NULL;
1644     hr = ScriptGetFontProperties(hdc,&psc,&sfp);
1645     ok( hr == S_OK, "(hdc,&psc,&sfp) partly initialized, expected S_OK, got %08x\n", hr);
1646     ok( psc != NULL, "Expected a pointer in psc, got NULL\n");
1647
1648     /* Save the psc pointer */
1649     old_psc = psc;
1650     /* Now a NULL hdc again */
1651     hr = ScriptGetFontProperties(NULL,&psc,&sfp);
1652     ok( hr == S_OK, "(NULL,&psc,&sfp), expected S_OK, got %08x\n", hr);
1653     ok( psc == old_psc, "Expected psc not to be changed, was %p is now %p\n", old_psc, psc);
1654     ScriptFreeCache(&psc);
1655     ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1656 }
1657
1658 static void test_ScriptTextOut(HDC hdc)
1659 {
1660     HRESULT         hr;
1661
1662     int             cInChars;
1663     int             cMaxItems;
1664     SCRIPT_ITEM     pItem[255];
1665     int             pcItems;
1666     WCHAR           TestItem1[] = {'T', 'e', 's', 't', 'a', 0}; 
1667
1668     SCRIPT_CACHE    psc;
1669     int             cChars;
1670     int             cMaxGlyphs;
1671     unsigned short  pwOutGlyphs1[256];
1672     WORD            pwLogClust[256];
1673     SCRIPT_VISATTR  psva[256];
1674     int             pcGlyphs;
1675     int             piAdvance[256];
1676     GOFFSET         pGoffset[256];
1677     ABC             pABC[256];
1678     RECT            rect;
1679     int             piX;
1680     int             iCP = 1;
1681     BOOL            fTrailing = FALSE;
1682     SCRIPT_LOGATTR  *psla;
1683     SCRIPT_LOGATTR  sla[256];
1684
1685     /* This is a valid test that will cause parsing to take place                             */
1686     cInChars = 5;
1687     cMaxItems = 255;
1688     hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1689     ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1690     /*  This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
1691      *  returned.                                                                             */
1692     ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
1693     if (pcItems > 0)
1694         ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
1695             "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
1696             pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
1697
1698     /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
1699      * ie. ScriptItemize has succeeded and that pItem has been set                            */
1700     cInChars = 5;
1701     if (hr == 0) {
1702         psc = NULL;                                   /* must be null on first call           */
1703         cChars = cInChars;
1704         cMaxGlyphs = 256;
1705         hr = ScriptShape(hdc, &psc, TestItem1, cChars,
1706                          cMaxGlyphs, &pItem[0].a,
1707                          pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1708         ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
1709         ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1710         ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
1711         if (hr ==0) {
1712             /* Note hdc is needed as glyph info is not yet in psc                  */
1713             hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
1714                              pGoffset, pABC);
1715             ok (hr == 0, "Should return 0 not (%08x)\n", hr);
1716             ScriptFreeCache(&psc);              /* Get rid of psc for next test set */
1717             ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1718
1719             hr = ScriptTextOut(NULL, NULL, 0, 0, 0, NULL, NULL, NULL, 0, NULL, 0, NULL, NULL, NULL);
1720             ok (hr == E_INVALIDARG, "Should return 0 not (%08x)\n", hr);
1721
1722             hr = ScriptTextOut(NULL, NULL, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1723                                piAdvance, NULL, pGoffset);
1724             ok( hr == E_INVALIDARG, "(NULL,NULL,TestItem1, cInChars, dwFlags, pwOutGlyphs3), "
1725                                     "expected E_INVALIDARG, got %08x\n", hr);
1726
1727             /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1728             psc = NULL;
1729             hr = ScriptTextOut(NULL, &psc, 0, 0, 0, NULL, NULL, NULL, 0, NULL, 0,
1730                                NULL, NULL, NULL);
1731             ok( hr == E_INVALIDARG, "(NULL,&psc,NULL,0,0,0,NULL,), expected E_INVALIDARG, "
1732                                     "got %08x\n", hr);
1733             ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1734
1735             /* hdc is required for this one rather than the usual optional          */
1736             psc = NULL;
1737             hr = ScriptTextOut(NULL, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1738                                piAdvance, NULL, pGoffset);
1739             ok( hr == E_INVALIDARG, "(NULL,&psc,), expected E_INVALIDARG, got %08x\n", hr);
1740             ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1741
1742             /* Set that it returns 0 status */
1743             hr = ScriptTextOut(hdc, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1744                                piAdvance, NULL, pGoffset);
1745             ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
1746
1747             /* Test Rect Rgn is acceptable */
1748             rect.top = 10;
1749             rect.bottom = 20;
1750             rect.left = 10;
1751             rect.right = 40;
1752             hr = ScriptTextOut(hdc, &psc, 0, 0, 0, &rect, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1753                                piAdvance, NULL, pGoffset);
1754             ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
1755
1756             iCP = 1;
1757             hr = ScriptCPtoX(iCP, fTrailing, cChars, pcGlyphs, (const WORD *) &pwLogClust,
1758                             (const SCRIPT_VISATTR *) &psva, (const int *)&piAdvance, &pItem[0].a, &piX);
1759             ok(hr == S_OK, "ScriptCPtoX Stub should return S_OK not %08x\n", hr);
1760
1761             psla = (SCRIPT_LOGATTR *)&sla;
1762             hr = ScriptBreak(TestItem1, cChars, &pItem[0].a, psla);
1763             ok(hr == S_OK, "ScriptBreak Stub should return S_OK not %08x\n", hr);
1764
1765             /* Clean up and go   */
1766             ScriptFreeCache(&psc);
1767             ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1768         }
1769     }
1770 }
1771
1772 static void test_ScriptTextOut2(HDC hdc)
1773 {
1774 /*  Intent is to validate that the HDC passed into ScriptTextOut is
1775  *  used instead of the (possibly) invalid cached one
1776  */
1777     HRESULT         hr;
1778
1779     HDC             hdc1, hdc2;
1780     int             cInChars;
1781     int             cMaxItems;
1782     SCRIPT_ITEM     pItem[255];
1783     int             pcItems;
1784     WCHAR           TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
1785
1786     SCRIPT_CACHE    psc;
1787     int             cChars;
1788     int             cMaxGlyphs;
1789     unsigned short  pwOutGlyphs1[256];
1790     WORD            pwLogClust[256];
1791     SCRIPT_VISATTR  psva[256];
1792     int             pcGlyphs;
1793     int             piAdvance[256];
1794     GOFFSET         pGoffset[256];
1795     ABC             pABC[256];
1796
1797     /* Create an extra DC that will be used until the ScriptTextOut */
1798     hdc1 = CreateCompatibleDC(hdc);
1799     ok (hdc1 != 0, "CreateCompatibleDC failed to create a DC\n");
1800     hdc2 = CreateCompatibleDC(hdc);
1801     ok (hdc2 != 0, "CreateCompatibleDC failed to create a DC\n");
1802
1803     /* This is a valid test that will cause parsing to take place                             */
1804     cInChars = 5;
1805     cMaxItems = 255;
1806     hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1807     ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1808     /*  This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
1809      *  returned.                                                                             */
1810     ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
1811     if (pcItems > 0)
1812         ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
1813             "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
1814             pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
1815
1816     /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
1817      * ie. ScriptItemize has succeeded and that pItem has been set                            */
1818     cInChars = 5;
1819     if (hr == 0) {
1820         psc = NULL;                                   /* must be null on first call           */
1821         cChars = cInChars;
1822         cMaxGlyphs = 256;
1823         hr = ScriptShape(hdc2, &psc, TestItem1, cChars,
1824                          cMaxGlyphs, &pItem[0].a,
1825                          pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1826         ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
1827         ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1828         ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
1829         if (hr ==0) {
1830             /* Note hdc is needed as glyph info is not yet in psc                  */
1831             hr = ScriptPlace(hdc2, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
1832                              pGoffset, pABC);
1833             ok (hr == 0, "Should return 0 not (%08x)\n", hr);
1834
1835             /*   key part!!!   cached dc is being deleted  */
1836             hr = DeleteDC(hdc2);
1837             ok(hr == 1, "DeleteDC should return 1 not %08x\n", hr);
1838
1839             /* At this point the cached hdc (hdc2) has been destroyed,
1840              * however, we are passing in a *real* hdc (the original hdc).
1841              * The text should be written to that DC
1842              */
1843             hr = ScriptTextOut(hdc1, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1844                                piAdvance, NULL, pGoffset);
1845             ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
1846             ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1847
1848             DeleteDC(hdc1);
1849
1850             /* Clean up and go   */
1851             ScriptFreeCache(&psc);
1852             ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1853         }
1854     }
1855 }
1856
1857 static void test_ScriptTextOut3(HDC hdc)
1858 {
1859     HRESULT         hr;
1860
1861     int             cInChars;
1862     int             cMaxItems;
1863     SCRIPT_ITEM     pItem[255];
1864     int             pcItems;
1865     WCHAR           TestItem1[] = {' ','\r', 0};
1866
1867     SCRIPT_CACHE    psc;
1868     int             cChars;
1869     int             cMaxGlyphs;
1870     unsigned short  pwOutGlyphs1[256];
1871     WORD            pwLogClust[256];
1872     SCRIPT_VISATTR  psva[256];
1873     int             pcGlyphs;
1874     int             piAdvance[256];
1875     GOFFSET         pGoffset[256];
1876     ABC             pABC[256];
1877     RECT            rect;
1878
1879     /* This is to ensure that nonexistent glyphs are translated into a valid glyph number */
1880     cInChars = 2;
1881     cMaxItems = 255;
1882     hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1883     ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1884     /*  This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
1885      *  returned.                                                                             */
1886     ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
1887     if (pcItems > 0)
1888         ok (pItem[0].iCharPos == 0 && pItem[2].iCharPos == cInChars,
1889             "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
1890             pItem[0].iCharPos, cInChars, pItem[2].iCharPos);
1891
1892     /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
1893      * ie. ScriptItemize has succeeded and that pItem has been set                            */
1894     cInChars = 2;
1895     if (hr == 0) {
1896         psc = NULL;                                   /* must be null on first call           */
1897         cChars = cInChars;
1898         cMaxGlyphs = 256;
1899         hr = ScriptShape(hdc, &psc, TestItem1, cChars,
1900                          cMaxGlyphs, &pItem[0].a,
1901                          pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1902         ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
1903         ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1904         ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
1905         if (hr ==0) {
1906             /* Note hdc is needed as glyph info is not yet in psc                  */
1907             hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
1908                              pGoffset, pABC);
1909             ok (hr == 0, "Should return 0 not (%08x)\n", hr);
1910
1911             /* Test Rect Rgn is acceptable */
1912             rect.top = 10;
1913             rect.bottom = 20;
1914             rect.left = 10;
1915             rect.right = 40;
1916             hr = ScriptTextOut(hdc, &psc, 0, 0, 0, &rect, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1917                                piAdvance, NULL, pGoffset);
1918             ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
1919
1920         }
1921         /* Clean up and go   */
1922         ScriptFreeCache(&psc);
1923         ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1924     }
1925 }
1926
1927 #define test_item_ScriptXtoX(a,b,c,d,e,f) (winetest_set_location(__FILE__,__LINE__), 0) ? 0 : _test_item_ScriptXtoX(a,b,c,d,e,f)
1928
1929 static void _test_item_ScriptXtoX(SCRIPT_ANALYSIS *psa, int cChars, int cGlyphs, const int* offsets, const WORD *pwLogClust, const int* piAdvance )
1930 {
1931     int iX, iCP;
1932     int icChars, icGlyphs;
1933     int piCP, piX;
1934     HRESULT hr;
1935     SCRIPT_VISATTR psva[10];
1936     int piTrailing;
1937     BOOL fTrailing;
1938     int direction;
1939
1940     memset(psva,0,sizeof(psva));
1941     direction = (psa->fRTL)?-1:+1;
1942
1943     for(iCP = 0; iCP < cChars; iCP++)
1944     {
1945         iX = offsets[iCP];
1946         icChars = cChars;
1947         icGlyphs = cGlyphs;
1948         hr = ScriptXtoCP(iX, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piCP, &piTrailing);
1949         winetest_ok(hr == S_OK, "ScriptXtoCP: should return S_OK not %08x\n", hr);
1950         winetest_ok(piCP == iCP, "ScriptXtoCP: iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
1951         winetest_ok(piTrailing == 0, "ScriptXtoCP: iX=%d should return piTrailing=0 not %d\n", iX, piTrailing);
1952     }
1953
1954     for(iCP = 0; iCP < cChars; iCP++)
1955     {
1956         iX = offsets[iCP]+direction;
1957         icChars = cChars;
1958         icGlyphs = cGlyphs;
1959         hr = ScriptXtoCP(iX, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piCP, &piTrailing);
1960         winetest_ok(hr == S_OK, "ScriptXtoCP leading: should return S_OK not %08x\n", hr);
1961         winetest_ok(piCP == iCP, "ScriptXtoCP leading: iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
1962         winetest_ok(piTrailing == 0, "ScriptXtoCP leading: iX=%d should return piTrailing=0 not %d\n", iX, piTrailing);
1963     }
1964
1965     for(iCP = 0; iCP < cChars; iCP++)
1966     {
1967         iX = offsets[iCP+1]-direction;
1968         icChars = cChars;
1969         icGlyphs = cGlyphs;
1970         hr = ScriptXtoCP(iX, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piCP, &piTrailing);
1971         winetest_ok(hr == S_OK, "ScriptXtoCP trailing: should return S_OK not %08x\n", hr);
1972         winetest_ok(piCP == iCP, "ScriptXtoCP trailing: iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
1973         winetest_ok(piTrailing == 1, "ScriptXtoCP trailing: iX=%d should return piTrailing=1 not %d\n", iX, piTrailing);
1974     }
1975
1976     for(iCP = 0; iCP <= cChars+1; iCP++)
1977     {
1978         fTrailing = FALSE;
1979         icChars = cChars;
1980         icGlyphs = cGlyphs;
1981         hr = ScriptCPtoX(iCP, fTrailing, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piX);
1982         winetest_ok(hr == S_OK, "ScriptCPtoX: should return S_OK not %08x\n", hr);
1983         winetest_ok(piX == offsets[iCP],
1984            "ScriptCPtoX: iCP=%d should return piX=%d not %d\n", iCP, offsets[iCP], piX);
1985     }
1986
1987     for(iCP = 0; iCP <= cChars+1; iCP++)
1988     {
1989         fTrailing = TRUE;
1990         icChars = cChars;
1991         icGlyphs = cGlyphs;
1992         hr = ScriptCPtoX(iCP, fTrailing, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piX);
1993         winetest_ok(hr == S_OK, "ScriptCPtoX trailing: should return S_OK not %08x\n", hr);
1994         winetest_ok(piX == offsets[iCP+1],
1995            "ScriptCPtoX trailing: iCP=%d should return piX=%d not %d\n", iCP, offsets[iCP+1], piX);
1996     }
1997 }
1998
1999 static void test_ScriptXtoX(void)
2000 /****************************************************************************************
2001  *  This routine tests the ScriptXtoCP and ScriptCPtoX functions using static variables *
2002  ****************************************************************************************/
2003 {
2004     WORD pwLogClust[10] = {0, 0, 0, 1, 1, 2, 2, 3, 3, 3};
2005     WORD pwLogClust_RTL[10] = {3, 3, 3, 2, 2, 1, 1, 0, 0, 0};
2006     WORD pwLogClust_2[7] = {4, 3, 3, 2, 1, 0 ,0};
2007     int piAdvance[10] = {201, 190, 210, 180, 170, 204, 189, 195, 212, 203};
2008     int piAdvance_2[5] = {39, 26, 19, 17, 11};
2009     static const int offsets[13] = {0, 67, 134, 201, 296, 391, 496, 601, 1052, 1503, 1954, 1954, 1954};
2010     static const int offsets_RTL[13] = {781, 721, 661, 601, 496, 391, 296, 201, 134, 67, 0, 0, 0};
2011     static const int offsets_2[10] = {112, 101, 92, 84, 65, 39, 19, 0, 0, 0};
2012     SCRIPT_VISATTR psva[10];
2013     SCRIPT_ANALYSIS sa;
2014     int iX;
2015     int piCP;
2016     int piTrailing;
2017     HRESULT hr;
2018
2019     memset(&sa, 0 , sizeof(SCRIPT_ANALYSIS));
2020     memset(psva, 0, sizeof(psva));
2021
2022     sa.fRTL = FALSE;
2023     hr = ScriptXtoCP(-1, 10, 10, pwLogClust, psva, piAdvance, &sa, &piCP, &piTrailing);
2024     ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
2025     if (piTrailing)
2026         ok(piCP == -1, "Negative iX should return piCP=-1 not %d\n", piCP);
2027     else /* win2k3 */
2028         ok(piCP == 10, "Negative iX should return piCP=10 not %d\n", piCP);
2029
2030     for (iX = 0; iX <= 7; iX++)
2031     {
2032         WORD clust = 0;
2033         INT advance = 16;
2034         hr = ScriptXtoCP(iX, 1, 1, &clust, psva, &advance, &sa, &piCP, &piTrailing);
2035         ok(piCP==0 && piTrailing==0,"%i should return 0(%i) and 0(%i)\n",iX, piCP,piTrailing);
2036     }
2037     for (iX = 8; iX < 16; iX++)
2038     {
2039         WORD clust = 0;
2040         INT advance = 16;
2041         hr = ScriptXtoCP(iX, 1, 1, &clust, psva, &advance, &sa, &piCP, &piTrailing);
2042         ok(piCP==0 && piTrailing==1,"%i should return 0(%i) and 1(%i)\n",iX, piCP,piTrailing);
2043     }
2044
2045     sa.fRTL = TRUE;
2046     hr = ScriptXtoCP(-1, 10, 10, pwLogClust_RTL, psva, piAdvance, &sa, &piCP, &piTrailing);
2047     ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
2048     if (piTrailing)
2049         ok(piCP == -1, "Negative iX should return piCP=-1 not %d\n", piCP);
2050     else /* win2k3 */
2051         ok(piCP == 10, "Negative iX should return piCP=10 not %d\n", piCP);
2052
2053     iX = 1954;
2054     hr = ScriptXtoCP(1954, 10, 10, pwLogClust_RTL, psva, piAdvance, &sa, &piCP, &piTrailing);
2055     ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
2056     ok(piCP == -1, "iX=%d should return piCP=-1 not %d\n", iX, piCP);
2057     ok(piTrailing == 1, "iX=%d should return piTrailing=1 not %d\n", iX, piTrailing);
2058
2059     for (iX = 1; iX <= 8; iX++)
2060     {
2061         WORD clust = 0;
2062         INT advance = 16;
2063         hr = ScriptXtoCP(iX, 1, 1, &clust, psva, &advance, &sa, &piCP, &piTrailing);
2064         ok(piCP==0 && piTrailing==1,"%i should return 0(%i) and 1(%i)\n",iX,piCP,piTrailing);
2065     }
2066     for (iX = 9; iX < 16; iX++)
2067     {
2068         WORD clust = 0;
2069         INT advance = 16;
2070         hr = ScriptXtoCP(iX, 1, 1, &clust, psva, &advance, &sa, &piCP, &piTrailing);
2071         ok(piCP==0 && piTrailing==0,"%i should return 0(%i) and 0(%i)\n",iX,piCP,piTrailing);
2072     }
2073
2074     sa.fRTL = FALSE;
2075     test_item_ScriptXtoX(&sa, 10, 10, offsets, pwLogClust, piAdvance);
2076     sa.fRTL = TRUE;
2077     test_item_ScriptXtoX(&sa, 10, 10, offsets_RTL, pwLogClust_RTL, piAdvance);
2078     test_item_ScriptXtoX(&sa, 7, 5, offsets_2, pwLogClust_2, piAdvance_2);
2079 }
2080
2081 static void test_ScriptString(HDC hdc)
2082 {
2083 /*******************************************************************************************
2084  *
2085  * This set of tests are for the string functions of uniscribe.  The ScriptStringAnalyse
2086  * function allocates memory pointed to by the SCRIPT_STRING_ANALYSIS ssa pointer.  This
2087  * memory is freed by ScriptStringFree.  There needs to be a valid hdc for this as
2088  * ScriptStringAnalyse calls ScriptSItemize, ScriptShape and ScriptPlace which require it.
2089  *
2090  */
2091
2092     HRESULT         hr;
2093     WCHAR           teststr[] = {'T','e','s','t','1',' ','a','2','b','3', '\0'};
2094     int             len = (sizeof(teststr) / sizeof(WCHAR)) - 1;
2095     int             Glyphs = len * 2 + 16;
2096     int             Charset;
2097     DWORD           Flags = SSA_GLYPHS;
2098     int             ReqWidth = 100;
2099     const int       Dx[5] = {10, 10, 10, 10, 10};
2100     const BYTE      InClass = 0;
2101     SCRIPT_STRING_ANALYSIS ssa = NULL;
2102
2103     int             X = 10; 
2104     int             Y = 100;
2105     UINT            Options = 0; 
2106     const RECT      rc = {0, 50, 100, 100}; 
2107     int             MinSel = 0;
2108     int             MaxSel = 0;
2109     BOOL            Disabled = FALSE;
2110     const int      *clip_len;
2111     int            i;
2112     UINT           *order;
2113
2114
2115     Charset = -1;     /* this flag indicates unicode input */
2116     /* Test without hdc to get E_PENDING */
2117     hr = ScriptStringAnalyse( NULL, teststr, len, Glyphs, Charset, Flags,
2118                               ReqWidth, NULL, NULL, Dx, NULL,
2119                               &InClass, &ssa);
2120     ok(hr == E_PENDING, "ScriptStringAnalyse Stub should return E_PENDING not %08x\n", hr);
2121
2122     /* test with hdc, this should be a valid test  */
2123     hr = ScriptStringAnalyse( hdc, teststr, len, Glyphs, Charset, Flags,
2124                               ReqWidth, NULL, NULL, Dx, NULL,
2125                               &InClass, &ssa);
2126     ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
2127     ScriptStringFree(&ssa);
2128
2129     /* test makes sure that a call with a valid pssa still works */
2130     hr = ScriptStringAnalyse( hdc, teststr, len, Glyphs, Charset, Flags,
2131                               ReqWidth, NULL, NULL, Dx, NULL,
2132                               &InClass, &ssa);
2133     ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
2134     ok(ssa != NULL, "ScriptStringAnalyse pssa should not be NULL\n");
2135
2136     if (hr == S_OK)
2137     {
2138         hr = ScriptStringOut(ssa, X, Y, Options, &rc, MinSel, MaxSel, Disabled);
2139         ok(hr == S_OK, "ScriptStringOut should return S_OK not %08x\n", hr);
2140     }
2141
2142      clip_len = ScriptString_pcOutChars(ssa);
2143      ok(*clip_len == len, "ScriptString_pcOutChars failed, got %d, expected %d\n", *clip_len, len);
2144
2145      order = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *clip_len * sizeof(UINT));
2146      hr = ScriptStringGetOrder(ssa, order);
2147      ok(hr == S_OK, "ScriptStringGetOrder failed, got %08x, expected S_OK\n", hr);
2148
2149      for (i = 0; i < *clip_len; i++) ok(order[i] == i, "%d: got %d expected %d\n", i, order[i], i);
2150      HeapFree(GetProcessHeap(), 0, order);
2151
2152      hr = ScriptStringFree(&ssa);
2153      ok(hr == S_OK, "ScriptStringFree should return S_OK not %08x\n", hr);
2154 }
2155
2156 static void test_ScriptStringXtoCP_CPtoX(HDC hdc)
2157 {
2158 /*****************************************************************************************
2159  *
2160  * This test is for the ScriptStringXtoCP and ScriptStringXtoCP functions.  Due to the
2161  * nature of the fonts between Windows and Wine, the test is implemented by generating
2162  * values using one one function then checking the output of the second.  In this way
2163  * the validity of the functions is established using Windows as a base and confirming
2164  * similar behaviour in wine.
2165  */
2166
2167     HRESULT         hr;
2168     static const WCHAR teststr1[]  = {0x05e9, 'i', 0x05dc, 'n', 0x05d5, 'e', 0x05dd, '.',0};
2169     static const BOOL rtl[] = {1, 0, 1, 0, 1, 0, 1, 0};
2170     void            *String = (WCHAR *) &teststr1;      /* ScriptStringAnalysis needs void */
2171     int             String_len = (sizeof(teststr1)/sizeof(WCHAR))-1;
2172     int             Glyphs = String_len * 2 + 16;       /* size of buffer as recommended  */
2173     int             Charset = -1;                       /* unicode                        */
2174     DWORD           Flags = SSA_GLYPHS;
2175     int             ReqWidth = 100;
2176     const BYTE      InClass = 0;
2177     SCRIPT_STRING_ANALYSIS ssa = NULL;
2178
2179     int             Ch;                                  /* Character position in string */
2180     int             iTrailing;
2181     int             Cp;                                  /* Character position in string */
2182     int             X;
2183     int             trail,lead;
2184     BOOL            fTrailing;
2185
2186     /* Test with hdc, this should be a valid test
2187      * Here we generate an SCRIPT_STRING_ANALYSIS that will be used as input to the
2188      * following character positions to X and X to character position functions.
2189      */
2190
2191     hr = ScriptStringAnalyse( hdc, String, String_len, Glyphs, Charset, Flags,
2192                               ReqWidth, NULL, NULL, NULL, NULL,
2193                               &InClass, &ssa);
2194     ok(hr == S_OK ||
2195        hr == E_INVALIDARG, /* NT */
2196        "ScriptStringAnalyse should return S_OK or E_INVALIDARG not %08x\n", hr);
2197
2198     if  (hr == S_OK)
2199     {
2200         ok(ssa != NULL, "ScriptStringAnalyse ssa should not be NULL\n");
2201
2202         /*
2203          * Loop to generate character positions to provide starting positions for the
2204          * ScriptStringCPtoX and ScriptStringXtoCP functions
2205          */
2206         for (Cp = 0; Cp < String_len; Cp++)
2207         {
2208             /* The fTrailing flag is used to indicate whether the X being returned is at
2209              * the beginning or the end of the character. What happens here is that if
2210              * fTrailing indicates the end of the character, ie. FALSE, then ScriptStringXtoCP
2211              * returns the beginning of the next character and iTrailing is FALSE.  So for this
2212              * loop iTrailing will be FALSE in both cases.
2213              */
2214             hr = ScriptStringCPtoX(ssa, Cp, TRUE, &trail);
2215             ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
2216             hr = ScriptStringCPtoX(ssa, Cp, FALSE, &lead);
2217             ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
2218             if (rtl[Cp])
2219                 ok(lead > trail, "Leading values should be after trailing for rtl characters(%i)\n",Cp);
2220             else
2221                 ok(lead < trail, "Trailing values should be after leading for ltr characters(%i)\n",Cp);
2222
2223             /* move by 1 pixel so that we are not inbetween 2 characters.  That could result in being the lead of a rtl and
2224                at the same time the trail of an ltr */
2225
2226             /* inside the leading edge */
2227             X = lead;
2228             if (rtl[Cp]) X--; else X++;
2229             hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2230             ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2231             ok(Cp == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp, Ch, trail);
2232             ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
2233                                   iTrailing, X);
2234
2235             /* inside the trailing edge */
2236             X = trail;
2237             if (rtl[Cp]) X++; else X--;
2238             hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2239             ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2240             ok(Cp == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp, Ch, trail);
2241             ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
2242                                   iTrailing, X);
2243
2244             /* outside the "trailing" edge */
2245             if (Cp < String_len-1)
2246             {
2247                 if (rtl[Cp]) X = lead; else X = trail;
2248                 X++;
2249                 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2250                 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2251                 ok(Cp + 1 == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp + 1, Ch, trail);
2252                 if (rtl[Cp+1])
2253                     ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
2254                                           iTrailing, X);
2255                 else
2256                     ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
2257                                           iTrailing, X);
2258             }
2259
2260             /* outside the "leading" edge */
2261             if (Cp != 0)
2262             {
2263                 if (rtl[Cp]) X = trail; else X = lead;
2264                 X--;
2265                 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2266                 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2267                 ok(Cp - 1 == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp - 1, Ch, trail);
2268                 if (Cp != 0  && rtl[Cp-1])
2269                     ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
2270                                           iTrailing, X);
2271                 else
2272                     ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
2273                                           iTrailing, X);
2274             }
2275         }
2276
2277         /* Check beyond the leading boundary of the whole string */
2278         if (rtl[0])
2279         {
2280             /* having a leading rtl character seems to confuse usp */
2281             /* this looks to be a windows bug we should emulate */
2282             hr = ScriptStringCPtoX(ssa, 0, TRUE, &X);
2283             ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
2284             X--;
2285             hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2286             ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2287             ok(Ch == 1, "ScriptStringXtoCP should return Ch = 1 not %d for X outside leading edge when rtl\n", Ch);
2288             ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = outside leading edge when rtl\n",
2289                                        iTrailing);
2290         }
2291         else
2292         {
2293             hr = ScriptStringCPtoX(ssa, 0, FALSE, &X);
2294             ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
2295             X--;
2296             hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2297             ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2298             ok(Ch == -1, "ScriptStringXtoCP should return Ch = -1 not %d for X outside leading edge\n", Ch);
2299             ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = outside leading edge\n",
2300                                        iTrailing);
2301         }
2302
2303         /* Check beyond the end boundary of the whole string */
2304         if (rtl[String_len-1])
2305         {
2306             hr = ScriptStringCPtoX(ssa, String_len-1, FALSE, &X);
2307             ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
2308         }
2309         else
2310         {
2311             hr = ScriptStringCPtoX(ssa, String_len-1, TRUE, &X);
2312             ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
2313         }
2314         X++;
2315         hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2316         ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2317         ok(Ch == String_len, "ScriptStringXtoCP should return Ch = %i not %d for X outside trailing edge\n", String_len, Ch);
2318         ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = outside trailing edge\n",
2319                                    iTrailing);
2320
2321         /*
2322          * Cleanup the SSA for the next round of tests
2323          */
2324         hr = ScriptStringFree(&ssa);
2325         ok(hr == S_OK, "ScriptStringFree should return S_OK not %08x\n", hr);
2326
2327         /*
2328          * Test to see that exceeding the number of chars returns E_INVALIDARG.  First
2329          * generate an SSA for the subsequent tests.
2330          */
2331         hr = ScriptStringAnalyse( hdc, String, String_len, Glyphs, Charset, Flags,
2332                                   ReqWidth, NULL, NULL, NULL, NULL,
2333                                   &InClass, &ssa);
2334         ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
2335
2336         /*
2337          * When ScriptStringCPtoX is called with a character position Cp that exceeds the
2338          * string length, return E_INVALIDARG.  This also invalidates the ssa so a
2339          * ScriptStringFree should also fail.
2340          */
2341         fTrailing = FALSE;
2342         Cp = String_len + 1;
2343         hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
2344         ok(hr == E_INVALIDARG, "ScriptStringCPtoX should return E_INVALIDARG not %08x\n", hr);
2345
2346         ScriptStringFree(&ssa);
2347     }
2348 }
2349
2350 static void test_ScriptCacheGetHeight(HDC hdc)
2351 {
2352     HRESULT hr;
2353     SCRIPT_CACHE sc = NULL;
2354     LONG height;
2355
2356     hr = ScriptCacheGetHeight(NULL, NULL, NULL);
2357     ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2358
2359     hr = ScriptCacheGetHeight(NULL, &sc, NULL);
2360     ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2361
2362     hr = ScriptCacheGetHeight(NULL, &sc, &height);
2363     ok(hr == E_PENDING, "expected E_PENDING, got 0x%08x\n", hr);
2364
2365     height = 0;
2366
2367     hr = ScriptCacheGetHeight(hdc, &sc, &height);
2368     ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
2369     ok(height > 0, "expected height > 0\n");
2370
2371     ScriptFreeCache(&sc);
2372 }
2373
2374 static void test_ScriptGetGlyphABCWidth(HDC hdc)
2375 {
2376     HRESULT hr;
2377     SCRIPT_CACHE sc = NULL;
2378     ABC abc;
2379
2380     hr = ScriptGetGlyphABCWidth(NULL, NULL, 'a', NULL);
2381     ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2382
2383     hr = ScriptGetGlyphABCWidth(NULL, &sc, 'a', NULL);
2384     ok(broken(hr == E_PENDING) ||
2385        hr == E_INVALIDARG, /* WIN7 */
2386        "expected E_INVALIDARG, got 0x%08x\n", hr);
2387
2388     hr = ScriptGetGlyphABCWidth(NULL, &sc, 'a', &abc);
2389     ok(hr == E_PENDING, "expected E_PENDING, got 0x%08x\n", hr);
2390
2391     if (0) {    /* crashes on WinXP */
2392     hr = ScriptGetGlyphABCWidth(hdc, &sc, 'a', NULL);
2393     ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2394     }
2395
2396     hr = ScriptGetGlyphABCWidth(hdc, &sc, 'a', &abc);
2397     ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
2398
2399     ScriptFreeCache(&sc);
2400 }
2401
2402 static void test_ScriptLayout(void)
2403 {
2404     HRESULT hr;
2405     static const BYTE levels[][10] =
2406     {
2407         { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
2408         { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
2409         { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
2410         { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
2411
2412         { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1},
2413         { 1, 1, 1, 2, 2, 2, 1, 1, 1, 1 },
2414         { 2, 2, 2, 1, 1, 1, 2, 2, 2, 2 },
2415         { 0, 0, 1, 1, 2, 2, 1, 1, 0, 0 },
2416         { 1, 1, 2, 2, 3, 3, 2, 2, 1, 1 },
2417
2418         { 0, 0, 1, 1, 2, 2, 1, 1, 0, 1 },
2419         { 1, 0, 1, 2, 2, 1, 2, 1, 0, 1 },
2420     };
2421     static const int expect_l2v[][10] =
2422     {
2423         { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
2424         { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
2425         { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
2426         { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
2427
2428         { 0, 1, 2, 3, 4, 9, 8 ,7 ,6, 5},
2429 /**/    { 9, 8, 7, 4, 5, 6, 3 ,2 ,1, 0},
2430 /**/    { 7, 8, 9, 6, 5, 4, 0 ,1 ,2, 3},
2431         { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
2432         { 9, 8, 2, 3, 5, 4, 6 ,7 ,1, 0},
2433
2434         { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
2435 /**/    { 0, 1, 7, 5, 6, 4, 3 ,2 ,8, 9},
2436     };
2437     static const int expect_v2l[][10] =
2438     {
2439         { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
2440         { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
2441         { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
2442         { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
2443
2444         { 0, 1, 2, 3, 4, 9, 8 ,7 ,6, 5},
2445         { 9, 8, 7, 6, 3, 4, 5 ,2 ,1, 0},
2446         { 6, 7, 8, 9, 5, 4, 3 ,0 ,1, 2},
2447         { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
2448         { 9, 8, 2, 3, 5, 4, 6 ,7 ,1, 0},
2449
2450         { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
2451         { 0, 1, 7, 6, 5, 3, 4 ,2 ,8, 9},
2452     };
2453
2454     int i, j, vistolog[sizeof(levels[0])], logtovis[sizeof(levels[0])];
2455
2456     hr = ScriptLayout(sizeof(levels[0]), NULL, vistolog, logtovis);
2457     ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2458
2459     hr = ScriptLayout(sizeof(levels[0]), levels[0], NULL, NULL);
2460     ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2461
2462     for (i = 0; i < sizeof(levels)/sizeof(levels[0]); i++)
2463     {
2464         hr = ScriptLayout(sizeof(levels[0]), levels[i], vistolog, logtovis);
2465         ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
2466
2467         for (j = 0; j < sizeof(levels[i]); j++)
2468         {
2469             ok(expect_v2l[i][j] == vistolog[j],
2470                "failure: levels[%d][%d] = %d, vistolog[%d] = %d\n",
2471                i, j, levels[i][j], j, vistolog[j] );
2472         }
2473
2474         for (j = 0; j < sizeof(levels[i]); j++)
2475         {
2476             ok(expect_l2v[i][j] == logtovis[j],
2477                "failure: levels[%d][%d] = %d, logtovis[%d] = %d\n",
2478                i, j, levels[i][j], j, logtovis[j] );
2479         }
2480     }
2481 }
2482
2483 static BOOL CALLBACK enum_proc(LGRPID group, LCID lcid, LPSTR locale, LONG_PTR lparam)
2484 {
2485     HRESULT hr;
2486     SCRIPT_DIGITSUBSTITUTE sds;
2487     SCRIPT_CONTROL sc;
2488     SCRIPT_STATE ss;
2489     LCID lcid_old;
2490
2491     if (!IsValidLocale(lcid, LCID_INSTALLED)) return TRUE;
2492
2493     memset(&sds, 0, sizeof(sds));
2494     memset(&sc, 0, sizeof(sc));
2495     memset(&ss, 0, sizeof(ss));
2496
2497     lcid_old = GetThreadLocale();
2498     if (!SetThreadLocale(lcid)) return TRUE;
2499
2500     hr = ScriptRecordDigitSubstitution(lcid, &sds);
2501     ok(hr == S_OK, "ScriptRecordDigitSubstitution failed: 0x%08x\n", hr);
2502
2503     hr = ScriptApplyDigitSubstitution(&sds, &sc, &ss);
2504     ok(hr == S_OK, "ScriptApplyDigitSubstitution failed: 0x%08x\n", hr);
2505
2506     SetThreadLocale(lcid_old);
2507     return TRUE;
2508 }
2509
2510 static void test_digit_substitution(void)
2511 {
2512     BOOL ret;
2513     unsigned int i;
2514     static const LGRPID groups[] =
2515     {
2516         LGRPID_WESTERN_EUROPE,
2517         LGRPID_CENTRAL_EUROPE,
2518         LGRPID_BALTIC,
2519         LGRPID_GREEK,
2520         LGRPID_CYRILLIC,
2521         LGRPID_TURKISH,
2522         LGRPID_JAPANESE,
2523         LGRPID_KOREAN,
2524         LGRPID_TRADITIONAL_CHINESE,
2525         LGRPID_SIMPLIFIED_CHINESE,
2526         LGRPID_THAI,
2527         LGRPID_HEBREW,
2528         LGRPID_ARABIC,
2529         LGRPID_VIETNAMESE,
2530         LGRPID_INDIC,
2531         LGRPID_GEORGIAN,
2532         LGRPID_ARMENIAN
2533     };
2534     HMODULE hKernel32;
2535     static BOOL (WINAPI * pEnumLanguageGroupLocalesA)(LANGGROUPLOCALE_ENUMPROCA,LGRPID,DWORD,LONG_PTR);
2536
2537     hKernel32 = GetModuleHandleA("kernel32.dll");
2538     pEnumLanguageGroupLocalesA = (void*)GetProcAddress(hKernel32, "EnumLanguageGroupLocalesA");
2539
2540     if (!pEnumLanguageGroupLocalesA)
2541     {
2542         win_skip("EnumLanguageGroupLocalesA not available on this platform\n");
2543         return;
2544     }
2545
2546     for (i = 0; i < sizeof(groups)/sizeof(groups[0]); i++)
2547     {
2548         ret = pEnumLanguageGroupLocalesA(enum_proc, groups[i], 0, 0);
2549         if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
2550         {
2551             win_skip("EnumLanguageGroupLocalesA not implemented on this platform\n");
2552             break;
2553         }
2554         
2555         ok(ret, "EnumLanguageGroupLocalesA failed unexpectedly: %u\n", GetLastError());
2556     }
2557 }
2558
2559 static void test_ScriptGetProperties(void)
2560 {
2561     const SCRIPT_PROPERTIES **props;
2562     HRESULT hr;
2563     int num;
2564
2565     hr = ScriptGetProperties(NULL, NULL);
2566     ok(hr == E_INVALIDARG, "ScriptGetProperties succeeded\n");
2567
2568     hr = ScriptGetProperties(NULL, &num);
2569     ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
2570
2571     hr = ScriptGetProperties(&props, NULL);
2572     ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
2573
2574     hr = ScriptGetProperties(&props, &num);
2575     ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
2576 }
2577
2578 static void test_ScriptBreak(void)
2579 {
2580     static const WCHAR test[] = {' ','\r','\n',0};
2581     SCRIPT_ITEM items[4];
2582     SCRIPT_LOGATTR la;
2583     HRESULT hr;
2584
2585     hr = ScriptItemize(test, 3, 4, NULL, NULL, items, NULL);
2586     ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
2587
2588     memset(&la, 0, sizeof(la));
2589     hr = ScriptBreak(test, 1, &items[0].a, &la);
2590     ok(!hr, "ScriptBreak should return S_OK not %08x\n", hr);
2591
2592     ok(!la.fSoftBreak, "fSoftBreak set\n");
2593     ok(la.fWhiteSpace, "fWhiteSpace not set\n");
2594     ok(la.fCharStop, "fCharStop not set\n");
2595     ok(!la.fWordStop, "fWordStop set\n");
2596     ok(!la.fInvalid, "fInvalid set\n");
2597     ok(!la.fReserved, "fReserved set\n");
2598
2599     memset(&la, 0, sizeof(la));
2600     hr = ScriptBreak(test + 1, 1, &items[1].a, &la);
2601     ok(!hr, "ScriptBreak should return S_OK not %08x\n", hr);
2602
2603     ok(!la.fSoftBreak, "fSoftBreak set\n");
2604     ok(!la.fWhiteSpace, "fWhiteSpace set\n");
2605     ok(la.fCharStop, "fCharStop not set\n");
2606     ok(!la.fWordStop, "fWordStop set\n");
2607     ok(!la.fInvalid, "fInvalid set\n");
2608     ok(!la.fReserved, "fReserved set\n");
2609
2610     memset(&la, 0, sizeof(la));
2611     hr = ScriptBreak(test + 2, 1, &items[2].a, &la);
2612     ok(!hr, "ScriptBreak should return S_OK not %08x\n", hr);
2613
2614     ok(!la.fSoftBreak, "fSoftBreak set\n");
2615     ok(!la.fWhiteSpace, "fWhiteSpace set\n");
2616     ok(la.fCharStop, "fCharStop not set\n");
2617     ok(!la.fWordStop, "fWordStop set\n");
2618     ok(!la.fInvalid, "fInvalid set\n");
2619     ok(!la.fReserved, "fReserved set\n");
2620 }
2621
2622 static void test_newlines(void)
2623 {
2624     static const WCHAR test1[] = {'t','e','x','t','\r','t','e','x','t',0};
2625     static const WCHAR test2[] = {'t','e','x','t','\n','t','e','x','t',0};
2626     static const WCHAR test3[] = {'t','e','x','t','\r','\n','t','e','x','t',0};
2627     static const WCHAR test4[] = {'t','e','x','t','\n','\r','t','e','x','t',0};
2628     static const WCHAR test5[] = {'1','2','3','4','\n','\r','1','2','3','4',0};
2629     SCRIPT_ITEM items[5];
2630     HRESULT hr;
2631     int count;
2632
2633     count = 0;
2634     hr = ScriptItemize(test1, lstrlenW(test1), 5, NULL, NULL, items, &count);
2635     ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
2636     ok(count == 3, "got %d expected 3\n", count);
2637
2638     count = 0;
2639     hr = ScriptItemize(test2, lstrlenW(test2), 5, NULL, NULL, items, &count);
2640     ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
2641     ok(count == 3, "got %d expected 3\n", count);
2642
2643     count = 0;
2644     hr = ScriptItemize(test3, lstrlenW(test3), 5, NULL, NULL, items, &count);
2645     ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
2646     ok(count == 4, "got %d expected 4\n", count);
2647
2648     count = 0;
2649     hr = ScriptItemize(test4, lstrlenW(test4), 5, NULL, NULL, items, &count);
2650     ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
2651     ok(count == 4, "got %d expected 4\n", count);
2652
2653     count = 0;
2654     hr = ScriptItemize(test5, lstrlenW(test5), 5, NULL, NULL, items, &count);
2655     ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
2656     ok(count == 4, "got %d expected 4\n", count);
2657 }
2658
2659 START_TEST(usp10)
2660 {
2661     HWND            hwnd;
2662     HDC             hdc;
2663     LOGFONTA        lf;
2664     HFONT           hfont;
2665
2666     unsigned short  pwOutGlyphs[256];
2667
2668     /* We need a valid HDC to drive a lot of Script functions which requires the following    *
2669      * to set up for the tests.                                                               */
2670     hwnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,
2671                            0, 0, 0, NULL);
2672     assert(hwnd != 0);
2673     ShowWindow(hwnd, SW_SHOW);
2674     UpdateWindow(hwnd);
2675
2676     hdc = GetDC(hwnd);                                      /* We now have a hdc             */
2677     ok( hdc != NULL, "HDC failed to be created %p\n", hdc);
2678
2679     memset(&lf, 0, sizeof(LOGFONTA));
2680     lstrcpyA(lf.lfFaceName, "Tahoma");
2681     lf.lfHeight = 10;
2682     lf.lfWeight = 3;
2683     lf.lfWidth = 10;
2684
2685     hfont = SelectObject(hdc, CreateFontIndirectA(&lf));
2686     ok(hfont != NULL, "SelectObject failed: %p\n", hfont);
2687
2688     test_ScriptItemize();
2689     test_ScriptItemIzeShapePlace(hdc,pwOutGlyphs);
2690     test_ScriptGetCMap(hdc, pwOutGlyphs);
2691     test_ScriptCacheGetHeight(hdc);
2692     test_ScriptGetGlyphABCWidth(hdc);
2693     test_ScriptShape(hdc);
2694     test_ScriptShapeOpenType(hdc);
2695     test_ScriptPlace(hdc);
2696
2697     test_ScriptGetFontProperties(hdc);
2698     test_ScriptTextOut(hdc);
2699     test_ScriptTextOut2(hdc);
2700     test_ScriptTextOut3(hdc);
2701     test_ScriptXtoX();
2702     test_ScriptString(hdc);
2703     test_ScriptStringXtoCP_CPtoX(hdc);
2704
2705     test_ScriptLayout();
2706     test_digit_substitution();
2707     test_ScriptGetProperties();
2708     test_ScriptBreak();
2709     test_newlines();
2710
2711     ReleaseDC(hwnd, hdc);
2712     DestroyWindow(hwnd);
2713 }