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