usp10: Add ScriptGetCMap functionality to translate wchars to glyphs.
[wine/hacks.git] / dlls / usp10 / tests / usp10.c
blob12907dc37afb56d39fcb44bbe43c18c43e55012f
1 /*
2 * Tests for usp10 dll
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
20 * Notes:
21 * Uniscribe allows for processing of complex scripts such as joining
22 * and filtering characters and bi-directional text with custom line breaks.
25 #include <assert.h>
26 #include <stdio.h>
28 #include <wine/test.h>
29 #include <winbase.h>
30 #include <wingdi.h>
31 #include <winuser.h>
32 #include <winerror.h>
33 #include <usp10.h>
35 START_TEST(usp10)
37 HRESULT hr;
38 int iMaxProps;
39 const SCRIPT_PROPERTIES **ppSp;
40 HWND hwnd;
41 HRGN hrgn;
42 HDC hdc;
44 int cInChars;
45 int cMaxItems;
46 SCRIPT_ITEM pItem[255];
47 int pcItems;
48 WCHAR TestItem1[6] = {'T', 'e', 's', 't', '1', 0};
49 WCHAR TestItem2[6] = {'T', 'e', 's', 't', '2', 0};
51 SCRIPT_CACHE psc;
52 int cChars;
53 int cMaxGlyphs;
54 unsigned short pwOutGlyphs[256];
55 unsigned short pwOutGlyphs2[256];
56 unsigned short pwOutGlyphs3[256];
57 unsigned short pwLogClust[256];
58 SCRIPT_VISATTR psva[256];
59 int pcGlyphs;
60 int piAdvance[256];
61 GOFFSET pGoffset[256];
62 ABC pABC[256];
63 int cnt;
64 DWORD dwFlags;
66 /* We need a valid HDC to drive a lot of Script functions which requires the following *
67 * to set up for the tests. */
68 hwnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,
69 0, 0, 0, NULL);
70 assert(hwnd != 0);
71 ShowWindow(hwnd, SW_SHOW);
72 UpdateWindow(hwnd);
74 hrgn = CreateRectRgn(0, 0, 0, 0);
75 assert(hrgn != 0);
77 hdc = GetDC(hwnd); /* We now have a hdc */
78 ok( hdc != NULL, "HDC failed to be created %p\n", hdc);
80 /* Start testing usp10 functions */
81 /* This test determines that the pointer returned by ScriptGetProperties is valid
82 * by checking a known value in the table */
83 hr = ScriptGetProperties(&ppSp, &iMaxProps);
84 trace("number of script properties %d\n", iMaxProps);
85 ok (iMaxProps > 0, "Number of scripts returned should not be 0\n");
86 if (iMaxProps > 0)
87 ok( ppSp[5]->langid == 9, "Langid[5] not = to 9\n"); /* Check a known value to ensure */
88 /* ptrs work */
91 /* This set of tests are to check that the various edits in ScriptIemize work */
92 cInChars = 5; /* Length of test without NULL */
93 cMaxItems = 1; /* Check threshold value */
94 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
95 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if cMaxItems < 2. Was %d\n",
96 cMaxItems);
97 cInChars = 5;
98 cMaxItems = 255;
99 hr = ScriptItemize(NULL, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
100 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if pwcInChars is NULL\n");
102 cInChars = 5;
103 cMaxItems = 255;
104 hr = ScriptItemize(TestItem1, 0, cMaxItems, NULL, NULL, pItem, &pcItems);
105 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if cInChars is 0\n");
107 cInChars = 5;
108 cMaxItems = 255;
109 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, NULL, &pcItems);
110 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if pItems is NULL\n");
112 /* This is a valid test that will cause parsing to take place */
113 cInChars = 5;
114 cMaxItems = 255;
115 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
116 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", (unsigned int) hr);
117 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
118 * returned. */
119 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
120 if (pcItems > 0)
121 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
122 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
123 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
125 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
126 * ie. ScriptItemize has succeeded and that pItem has been set */
127 cInChars = 5;
128 cMaxItems = 255;
129 if (hr == 0) {
130 psc = NULL; /* must be null on first call */
131 cChars = cInChars;
132 cMaxGlyphs = cInChars;
133 hr = ScriptShape(NULL, &psc, TestItem1, cChars,
134 cMaxGlyphs, &pItem[0].a,
135 pwOutGlyphs, pwLogClust, psva, &pcGlyphs);
136 ok (hr == E_PENDING, "If psc is NULL (%08x) the E_PENDING should be returned\n",
137 (unsigned int) hr);
138 cMaxGlyphs = 4;
139 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
140 cMaxGlyphs, &pItem[0].a,
141 pwOutGlyphs, pwLogClust, psva, &pcGlyphs);
142 ok (hr == E_OUTOFMEMORY, "If not enough output area cChars (%d) is > than CMaxGlyphs (%d) but not E_OUTOFMEMORY\n",
143 cChars, cMaxGlyphs);
144 cMaxGlyphs = 256;
145 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
146 cMaxGlyphs, &pItem[0].a,
147 pwOutGlyphs, pwLogClust, psva, &pcGlyphs);
148 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", (unsigned int) hr);
149 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
150 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
151 if (hr ==0) {
152 hr = ScriptPlace(NULL, &psc, pwOutGlyphs, pcGlyphs, psva, &pItem[0].a, piAdvance,
153 pGoffset, pABC);
154 ok (hr == 0, "Should return 0 not (%08x)\n", (unsigned int) hr);
157 /* This test will check to make sure that SCRIPT_CACHE is reused and that not translation *
158 * takes place if fNoGlyphIndex is set. */
160 cInChars = 5;
161 cMaxItems = 255;
162 hr = ScriptItemize(TestItem2, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
163 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", (unsigned int) hr);
164 /* This test is for the intertrim operation of ScriptItemize where only one SCRIPT_ITEM is *
165 * returned. */
166 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
167 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
168 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
169 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue */
170 if (hr == 0) {
171 cChars = cInChars;
172 cMaxGlyphs = 256;
173 pItem[0].a.fNoGlyphIndex = 1; /* say no translate */
174 hr = ScriptShape(NULL, &psc, TestItem2, cChars,
175 cMaxGlyphs, &pItem[0].a,
176 pwOutGlyphs2, pwLogClust, psva, &pcGlyphs);
177 ok (hr != E_PENDING, "If psc should not be NULL (%08x) and the E_PENDING should be returned\n",
178 (unsigned int) hr);
179 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", (unsigned int) hr);
180 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
181 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
182 for (cnt=0; cnt < cChars && TestItem2[cnt] == pwOutGlyphs2[cnt]; cnt++) {}
183 ok (cnt == cChars, "Translation to place when told not to. WCHAR %d - %04x != %04x\n",
184 cnt, TestItem2[cnt], pwOutGlyphs2[cnt]);
185 if (hr ==0) {
186 hr = ScriptPlace(NULL, &psc, pwOutGlyphs2, pcGlyphs, psva, &pItem[0].a, piAdvance,
187 pGoffset, pABC);
188 ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", (unsigned int) hr);
191 hr = ScriptFreeCache( &psc);
192 ok (!psc, "psc is not null after ScriptFreeCache\n");
194 /* Check to make sure that SCRIPT_CACHE gets allocated ok */
195 dwFlags = 0;
196 hr = ScriptGetCMap(NULL, &psc, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
197 ok (hr == E_PENDING, "If psc is NULL (%08x) the E_PENDING should be returned\n",
198 (unsigned int) hr);
199 /* Check to see if teh results are the same as those returned by ScriptShape */
200 hr = ScriptGetCMap(hdc, &psc, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
201 ok (hr == 0, "ScriptGetCMap should return 0 not (%08x)\n", (unsigned int) hr);
202 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
203 for (cnt=0; cnt < cChars && pwOutGlyphs[cnt] == pwOutGlyphs3[cnt]; cnt++) {}
204 ok (cnt == cInChars, "Translation not correct. WCHAR %d - %04x != %04x\n",
205 cnt, pwOutGlyphs[cnt], pwOutGlyphs3[cnt]);
207 hr = ScriptFreeCache( &psc);
208 ok (!psc, "psc is not null after ScriptFreeCache\n");
211 DeleteObject(hrgn);
212 ReleaseDC(hwnd, hdc);
213 DestroyWindow(hwnd);
214 return;