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 pwOutGlyphs2
[256];
56 unsigned short pwOutGlyphs3
[256];
57 unsigned short pwLogClust
[256];
58 SCRIPT_VISATTR psva
[256];
61 GOFFSET pGoffset
[256];
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,
71 ShowWindow(hwnd
, SW_SHOW
);
74 hrgn
= CreateRectRgn(0, 0, 0, 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");
87 ok( ppSp
[5]->langid
== 9, "Langid[5] not = to 9\n"); /* Check a known value to ensure */
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",
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");
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");
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 */
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 *
119 ok (pcItems
> 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
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 */
130 psc
= NULL
; /* must be null on first call */
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",
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",
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
);
152 hr
= ScriptPlace(NULL
, &psc
, pwOutGlyphs
, pcGlyphs
, psva
, &pItem
[0].a
, piAdvance
,
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. */
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 *
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 */
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",
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
]);
186 hr
= ScriptPlace(NULL
, &psc
, pwOutGlyphs2
, pcGlyphs
, psva
, &pItem
[0].a
, piAdvance
,
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 */
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",
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");
212 ReleaseDC(hwnd
, hdc
);