f6f0acb9b16be1f45bb75a53fb76eefb35b71db1
[reactos.git] / rostests / winetests / gdiplus / stringformat.c
1 /*
2 * Unit test suite for string format
3 *
4 * Copyright (C) 2007 Google (Evan Stade)
5 *
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.
10 *
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.
15 *
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #define WIN32_NO_STATUS
22 #define _INC_WINDOWS
23 #define COM_NO_WINDOWS_H
24
25 //#include "windows.h"
26 #include <wine/test.h>
27 #include <wingdi.h>
28 #include <objbase.h>
29 #include <gdiplus.h>
30
31 #define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
32 #define expectf(expected, got) ok(got == expected, "Expected %.2f, got %.2f\n", expected, got)
33
34 static void test_constructor(void)
35 {
36 GpStringFormat *format;
37 GpStatus stat;
38 INT n, count;
39 StringAlignment align, valign;
40 StringTrimming trimming;
41 StringDigitSubstitute digitsub;
42 LANGID digitlang;
43
44 stat = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
45 expect(Ok, stat);
46
47 GdipGetStringFormatAlign(format, &align);
48 GdipGetStringFormatLineAlign(format, &valign);
49 GdipGetStringFormatHotkeyPrefix(format, &n);
50 GdipGetStringFormatTrimming(format, &trimming);
51 GdipGetStringFormatDigitSubstitution(format, &digitlang, &digitsub);
52 GdipGetStringFormatMeasurableCharacterRangeCount(format, &count);
53
54 expect(HotkeyPrefixNone, n);
55 expect(StringAlignmentNear, align);
56 expect(StringAlignmentNear, align);
57 expect(StringTrimmingCharacter, trimming);
58 expect(StringDigitSubstituteUser, digitsub);
59 expect(LANG_NEUTRAL, digitlang);
60 expect(0, count);
61
62 stat = GdipDeleteStringFormat(format);
63 expect(Ok, stat);
64 }
65
66 static void test_characterrange(void)
67 {
68 CharacterRange ranges[3];
69 INT count;
70 GpStringFormat* format;
71 GpStatus stat;
72
73 stat = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
74 expect(Ok, stat);
75 stat = GdipSetStringFormatMeasurableCharacterRanges(NULL, 3, ranges);
76 expect(InvalidParameter, stat);
77 stat = GdipSetStringFormatMeasurableCharacterRanges(format, 0, ranges);
78 expect(Ok, stat);
79 stat = GdipSetStringFormatMeasurableCharacterRanges(format, 3, NULL);
80 expect(InvalidParameter, stat);
81
82 stat = GdipSetStringFormatMeasurableCharacterRanges(format, 3, ranges);
83 expect(Ok, stat);
84 stat = GdipGetStringFormatMeasurableCharacterRangeCount(format, &count);
85 expect(Ok, stat);
86 if (stat == Ok) expect(3, count);
87
88 stat= GdipDeleteStringFormat(format);
89 expect(Ok, stat);
90 }
91
92 static void test_digitsubstitution(void)
93 {
94 GpStringFormat *format;
95 GpStatus stat;
96 StringDigitSubstitute digitsub;
97 LANGID digitlang;
98
99 stat = GdipCreateStringFormat(0, LANG_RUSSIAN, &format);
100 expect(Ok, stat);
101
102 /* NULL arguments */
103 stat = GdipGetStringFormatDigitSubstitution(NULL, NULL, NULL);
104 expect(InvalidParameter, stat);
105 stat = GdipGetStringFormatDigitSubstitution(format, NULL, NULL);
106 expect(Ok, stat);
107 stat = GdipGetStringFormatDigitSubstitution(NULL, &digitlang, NULL);
108 expect(InvalidParameter, stat);
109 stat = GdipGetStringFormatDigitSubstitution(NULL, NULL, &digitsub);
110 expect(InvalidParameter, stat);
111 stat = GdipGetStringFormatDigitSubstitution(NULL, &digitlang, &digitsub);
112 expect(InvalidParameter, stat);
113 stat = GdipSetStringFormatDigitSubstitution(NULL, LANG_NEUTRAL, StringDigitSubstituteNone);
114 expect(InvalidParameter, stat);
115
116 /* try to get both and one by one */
117 stat = GdipGetStringFormatDigitSubstitution(format, &digitlang, &digitsub);
118 expect(Ok, stat);
119 expect(StringDigitSubstituteUser, digitsub);
120 expect(LANG_NEUTRAL, digitlang);
121
122 digitsub = StringDigitSubstituteNone;
123 stat = GdipGetStringFormatDigitSubstitution(format, NULL, &digitsub);
124 expect(Ok, stat);
125 expect(StringDigitSubstituteUser, digitsub);
126
127 digitlang = LANG_RUSSIAN;
128 stat = GdipGetStringFormatDigitSubstitution(format, &digitlang, NULL);
129 expect(Ok, stat);
130 expect(LANG_NEUTRAL, digitlang);
131
132 /* set/get */
133 stat = GdipSetStringFormatDigitSubstitution(format, MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL),
134 StringDigitSubstituteUser);
135 expect(Ok, stat);
136 digitsub = StringDigitSubstituteNone;
137 digitlang = LANG_RUSSIAN;
138 stat = GdipGetStringFormatDigitSubstitution(format, &digitlang, &digitsub);
139 expect(Ok, stat);
140 expect(StringDigitSubstituteUser, digitsub);
141 expect(MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL), digitlang);
142
143 stat = GdipDeleteStringFormat(format);
144 expect(Ok, stat);
145 }
146
147 static void test_getgenerictypographic(void)
148 {
149 GpStringFormat *format;
150 GpStatus stat;
151 INT flags;
152 INT n;
153 StringAlignment align, valign;
154 StringTrimming trimming;
155 StringDigitSubstitute digitsub;
156 LANGID digitlang;
157 INT tabcount;
158
159 /* NULL arg */
160 stat = GdipStringFormatGetGenericTypographic(NULL);
161 expect(InvalidParameter, stat);
162
163 stat = GdipStringFormatGetGenericTypographic(&format);
164 expect(Ok, stat);
165
166 GdipGetStringFormatFlags(format, &flags);
167 GdipGetStringFormatAlign(format, &align);
168 GdipGetStringFormatLineAlign(format, &valign);
169 GdipGetStringFormatHotkeyPrefix(format, &n);
170 GdipGetStringFormatTrimming(format, &trimming);
171 GdipGetStringFormatDigitSubstitution(format, &digitlang, &digitsub);
172 GdipGetStringFormatTabStopCount(format, &tabcount);
173
174 expect((StringFormatFlagsNoFitBlackBox |StringFormatFlagsLineLimit | StringFormatFlagsNoClip),
175 flags);
176 expect(HotkeyPrefixNone, n);
177 expect(StringAlignmentNear, align);
178 expect(StringAlignmentNear, align);
179 expect(StringTrimmingNone, trimming);
180 expect(StringDigitSubstituteUser, digitsub);
181 expect(LANG_NEUTRAL, digitlang);
182 expect(0, tabcount);
183
184 stat = GdipDeleteStringFormat(format);
185 expect(Ok, stat);
186 }
187
188 static REAL tabstops[] = {0.0, 10.0, 2.0};
189 static void test_tabstops(void)
190 {
191 GpStringFormat *format;
192 GpStatus stat;
193 INT count;
194 REAL tabs[3];
195 REAL firsttab;
196
197 stat = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
198 expect(Ok, stat);
199
200 /* NULL */
201 stat = GdipGetStringFormatTabStopCount(NULL, NULL);
202 expect(InvalidParameter, stat);
203 stat = GdipGetStringFormatTabStopCount(NULL, &count);
204 expect(InvalidParameter, stat);
205 stat = GdipGetStringFormatTabStopCount(format, NULL);
206 expect(InvalidParameter, stat);
207
208 stat = GdipSetStringFormatTabStops(NULL, 0.0, 0, NULL);
209 expect(InvalidParameter, stat);
210 stat = GdipSetStringFormatTabStops(format, 0.0, 0, NULL);
211 expect(InvalidParameter, stat);
212 stat = GdipSetStringFormatTabStops(NULL, 0.0, 0, tabstops);
213 expect(InvalidParameter, stat);
214
215 stat = GdipGetStringFormatTabStops(NULL, 0, NULL, NULL);
216 expect(InvalidParameter, stat);
217 stat = GdipGetStringFormatTabStops(format, 0, NULL, NULL);
218 expect(InvalidParameter, stat);
219 stat = GdipGetStringFormatTabStops(NULL, 0, &firsttab, NULL);
220 expect(InvalidParameter, stat);
221 stat = GdipGetStringFormatTabStops(NULL, 0, NULL, tabs);
222 expect(InvalidParameter, stat);
223 stat = GdipGetStringFormatTabStops(format, 0, &firsttab, NULL);
224 expect(InvalidParameter, stat);
225 stat = GdipGetStringFormatTabStops(format, 0, NULL, tabs);
226 expect(InvalidParameter, stat);
227
228 /* not NULL */
229 stat = GdipGetStringFormatTabStopCount(format, &count);
230 expect(Ok, stat);
231 expect(0, count);
232 /* negative tabcount */
233 stat = GdipSetStringFormatTabStops(format, 0.0, -1, tabstops);
234 expect(Ok, stat);
235 count = -1;
236 stat = GdipGetStringFormatTabStopCount(format, &count);
237 expect(Ok, stat);
238 expect(0, count);
239
240 stat = GdipSetStringFormatTabStops(format, -10.0, 0, tabstops);
241 expect(Ok, stat);
242 stat = GdipSetStringFormatTabStops(format, -10.0, 1, tabstops);
243 expect(NotImplemented, stat);
244
245 firsttab = -1.0;
246 tabs[0] = tabs[1] = tabs[2] = -1.0;
247 stat = GdipGetStringFormatTabStops(format, 0, &firsttab, tabs);
248 expect(Ok, stat);
249 expectf(-1.0, tabs[0]);
250 expectf(-1.0, tabs[1]);
251 expectf(-1.0, tabs[2]);
252 expectf(0.0, firsttab);
253
254 stat = GdipSetStringFormatTabStops(format, +0.0, 3, tabstops);
255 expect(Ok, stat);
256 count = 0;
257 stat = GdipGetStringFormatTabStopCount(format, &count);
258 expect(Ok, stat);
259 expect(3, count);
260
261 firsttab = -1.0;
262 tabs[0] = tabs[1] = tabs[2] = -1.0;
263 stat = GdipGetStringFormatTabStops(format, 3, &firsttab, tabs);
264 expect(Ok, stat);
265 expectf(0.0, tabs[0]);
266 expectf(10.0, tabs[1]);
267 expectf(2.0, tabs[2]);
268 expectf(0.0, firsttab);
269
270 stat = GdipSetStringFormatTabStops(format, 10.0, 3, tabstops);
271 expect(Ok, stat);
272 firsttab = -1.0;
273 tabs[0] = tabs[1] = tabs[2] = -1.0;
274 stat = GdipGetStringFormatTabStops(format, 0, &firsttab, tabs);
275 expect(Ok, stat);
276 expectf(-1.0, tabs[0]);
277 expectf(-1.0, tabs[1]);
278 expectf(-1.0, tabs[2]);
279 expectf(10.0, firsttab);
280
281 /* zero tabcount, after valid setting to 3 */
282 stat = GdipSetStringFormatTabStops(format, 0.0, 0, tabstops);
283 expect(Ok, stat);
284 count = 0;
285 stat = GdipGetStringFormatTabStopCount(format, &count);
286 expect(Ok, stat);
287 expect(3, count);
288
289 stat = GdipDeleteStringFormat(format);
290 expect(Ok, stat);
291 }
292
293 static void test_getgenericdefault(void)
294 {
295 GpStringFormat *format;
296 GpStatus stat;
297
298 INT flags;
299 INT n;
300 StringAlignment align, valign;
301 StringTrimming trimming;
302 StringDigitSubstitute digitsub;
303 LANGID digitlang;
304 INT tabcount;
305
306 /* NULL arg */
307 stat = GdipStringFormatGetGenericDefault(NULL);
308 expect(InvalidParameter, stat);
309
310 stat = GdipStringFormatGetGenericDefault(&format);
311 expect(Ok, stat);
312
313 GdipGetStringFormatFlags(format, &flags);
314 GdipGetStringFormatAlign(format, &align);
315 GdipGetStringFormatLineAlign(format, &valign);
316 GdipGetStringFormatHotkeyPrefix(format, &n);
317 GdipGetStringFormatTrimming(format, &trimming);
318 GdipGetStringFormatDigitSubstitution(format, &digitlang, &digitsub);
319 GdipGetStringFormatTabStopCount(format, &tabcount);
320
321 expect(0, flags);
322 expect(HotkeyPrefixNone, n);
323 expect(StringAlignmentNear, align);
324 expect(StringAlignmentNear, align);
325 expect(StringTrimmingCharacter, trimming);
326 expect(StringDigitSubstituteUser, digitsub);
327 expect(LANG_NEUTRAL, digitlang);
328 expect(0, tabcount);
329
330 stat = GdipDeleteStringFormat(format);
331 expect(Ok, stat);
332 }
333
334 static void test_stringformatflags(void)
335 {
336 GpStringFormat *format;
337 GpStatus stat;
338
339 INT flags;
340
341 stat = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
342 expect(Ok, stat);
343
344 /* NULL args */
345 stat = GdipSetStringFormatFlags(NULL, 0);
346 expect(InvalidParameter, stat);
347
348 stat = GdipSetStringFormatFlags(format, 0);
349 expect(Ok, stat);
350 stat = GdipGetStringFormatFlags(format, &flags);
351 expect(Ok, stat);
352 expect(0, flags);
353
354 /* Check some valid flags */
355 stat = GdipSetStringFormatFlags(format, StringFormatFlagsDirectionRightToLeft);
356 expect(Ok, stat);
357 stat = GdipGetStringFormatFlags(format, &flags);
358 expect(Ok, stat);
359 expect(StringFormatFlagsDirectionRightToLeft, flags);
360
361 stat = GdipSetStringFormatFlags(format, StringFormatFlagsNoFontFallback);
362 expect(Ok, stat);
363 stat = GdipGetStringFormatFlags(format, &flags);
364 expect(Ok, stat);
365 expect(StringFormatFlagsNoFontFallback, flags);
366
367 /* Check some flag combinations */
368 stat = GdipSetStringFormatFlags(format, StringFormatFlagsDirectionVertical
369 | StringFormatFlagsNoFitBlackBox);
370 expect(Ok, stat);
371 stat = GdipGetStringFormatFlags(format, &flags);
372 expect(Ok, stat);
373 expect((StringFormatFlagsDirectionVertical
374 | StringFormatFlagsNoFitBlackBox), flags);
375
376 stat = GdipSetStringFormatFlags(format, StringFormatFlagsDisplayFormatControl
377 | StringFormatFlagsMeasureTrailingSpaces);
378 expect(Ok, stat);
379 stat = GdipGetStringFormatFlags(format, &flags);
380 expect(Ok, stat);
381 expect((StringFormatFlagsDisplayFormatControl
382 | StringFormatFlagsMeasureTrailingSpaces), flags);
383
384 /* Check invalid flags */
385 stat = GdipSetStringFormatFlags(format, 0xdeadbeef);
386 expect(Ok, stat);
387 stat = GdipGetStringFormatFlags(format, &flags);
388 expect(Ok, stat);
389 expect(0xdeadbeef, flags);
390
391 stat = GdipDeleteStringFormat(format);
392 expect(Ok, stat);
393 }
394
395 START_TEST(stringformat)
396 {
397 struct GdiplusStartupInput gdiplusStartupInput;
398 ULONG_PTR gdiplusToken;
399
400 gdiplusStartupInput.GdiplusVersion = 1;
401 gdiplusStartupInput.DebugEventCallback = NULL;
402 gdiplusStartupInput.SuppressBackgroundThread = 0;
403 gdiplusStartupInput.SuppressExternalCodecs = 0;
404
405 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
406
407 test_constructor();
408 test_characterrange();
409 test_digitsubstitution();
410 test_getgenerictypographic();
411 test_tabstops();
412 test_getgenericdefault();
413 test_stringformatflags();
414
415 GdiplusShutdown(gdiplusToken);
416 }