4 * Copyright 2006 Jeff Latimer
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * Uniscribe allows for processing of complex scripts such as joining
22 * and filtering characters and bi-directional text with custom line breaks.
28 #include <wine/test.h>
39 const SCRIPT_PROPERTIES **ppSp;
46 SCRIPT_ITEM pItem[255];
48 WCHAR TestItem1[6] = {'T', 'e', 's', 't', '1', 0};
49 WCHAR TestItem2[6] = {'T', 'e', 's', 't', '2', 0};
54 unsigned short pwOutGlyphs[256];
55 unsigned short pwLogClust[256];
56 SCRIPT_VISATTR psva[256];
59 GOFFSET pGoffset[256];
63 /* We need a valid HDC to drive a lot of Script functions which requires the following *
64 * to set up for the tests. */
65 hwnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,
68 ShowWindow(hwnd, SW_SHOW);
71 hrgn = CreateRectRgn(0, 0, 0, 0);
74 hdc = GetDC(hwnd); /* We now have a hdc */
75 ok( hdc != NULL, "HDC failed to be created %p\n", hdc);
77 /* Start testing usp10 functions */
78 /* This test determines that the pointer returned by ScriptGetProperties is valid
79 * by checking a known value in the table */
80 hr = ScriptGetProperties(&ppSp, &iMaxProps);
81 trace("number of script properties %d\n", iMaxProps);
83 ok (iMaxProps > 0, "Number of scripts returned should not be 0\n");
85 ok( ppSp[5]->langid == 9, "Langid[5] not = to 9\n"); /* Check a known value to ensure */
89 /* This set of tests are to check that the various edits in ScriptIemize work */
90 cInChars = 5; /* Length of test without NULL */
91 cMaxItems = 1; /* Check threshold value */
92 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
93 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if cMaxItems < 2. Was %d\n",
97 hr = ScriptItemize(NULL, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
98 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if pwcInChars is NULL\n");
102 hr = ScriptItemize(TestItem1, 0, cMaxItems, NULL, NULL, pItem, &pcItems);
103 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if cInChars is 0\n");
107 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, NULL, &pcItems);
108 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if pItems is NULL\n");
110 /* This is a valid test that will cause parsing to take place */
113 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
114 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", (unsigned int) hr);
115 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
117 todo_wine ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
119 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
120 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
121 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
123 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
124 * ie. ScriptItemize has succeeded and that pItem has been set */
128 psc = NULL; /* must be null on first call */
131 hr = ScriptShape(NULL, &psc, TestItem1, cChars,
132 cMaxGlyphs, &pItem[0].a,
133 pwOutGlyphs, pwLogClust, psva, &pcGlyphs);
134 todo_wine ok (hr == E_OUTOFMEMORY, "If not enoungh output area cChars (%d) is > than CMaxGlyphs (%d) but not E_OUTOFMEMORY\n",
137 hr = ScriptShape(NULL, &psc, TestItem1, cChars,
138 cMaxGlyphs, &pItem[0].a,
139 pwOutGlyphs, pwLogClust, psva, &pcGlyphs);
140 todo_wine ok (hr == E_PENDING, "If psc is NULL (%08x) the E_PENDING should be returned\n",
142 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
143 cMaxGlyphs, &pItem[0].a,
144 pwOutGlyphs, pwLogClust, psva, &pcGlyphs);
145 todo_wine ok (hr == 0, "Should return 0 not (%08x)\n", (unsigned int) hr);
146 todo_wine ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
147 todo_wine ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
149 hr = ScriptPlace(NULL, &psc, pwOutGlyphs, pcGlyphs, psva, &pItem[0].a, piAdvance,
151 ok (hr == 0, "Should return 0 not (%08x)\n", (unsigned int) hr);
154 /* This test will check to make sure that SCRIPT_CACHE is reused and that not translation *
155 * takes place if fNoGlyphIndex is set. */
159 hr = ScriptItemize(TestItem2, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
160 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", (unsigned int) hr);
161 /* This test is for the intertrim operation of ScriptItemize where only one SCRIPT_ITEM is *
163 todo_wine ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
164 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
165 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
166 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue */
170 pItem[0].a.fNoGlyphIndex = 1; /* say no translate */
171 hr = ScriptShape(NULL, &psc, TestItem2, cChars,
172 cMaxGlyphs, &pItem[0].a,
173 pwOutGlyphs, pwLogClust, psva, &pcGlyphs);
174 ok (hr != E_PENDING, "If psc should not be NULL (%08x) and the E_PENDING should be returned\n",
176 todo_wine ok (hr == 0, "Should return 0 not (%08x)\n", (unsigned int) hr);
177 todo_wine ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
178 todo_wine ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
179 for (cnt=0; cnt < cChars && TestItem2[cnt] == pwOutGlyphs[cnt]; cnt++) {}
180 todo_wine ok (cnt == cChars, "Translation to place when told not to. WCHAR %d - %04x != %04x\n",
181 cnt, TestItem2[cnt], pwOutGlyphs[cnt]);
183 hr = ScriptPlace(NULL, &psc, pwOutGlyphs, pcGlyphs, psva, &pItem[0].a, piAdvance,
185 todo_wine ok (hr == 0, "Should return 0 not (%08x)\n", (unsigned int) hr);
188 hr = ScriptFreeCache( &psc);
189 ok (!psc, "psc is not null after ScriptFreeCache\n");
192 ReleaseDC(hwnd, hdc);