2 * Unit test suite for string format
4 * Copyright (C) 2007 Google (Evan Stade)
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/test.h"
25 #define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
26 #define expectf(expected, got) ok(got == expected, "Expected %.2f, got %.2f\n", expected, got)
28 static void test_constructor(void)
30 GpStringFormat
*format
;
33 StringAlignment align
, line_align
;
34 StringTrimming trimming
;
35 StringDigitSubstitute digitsub
;
38 stat
= GdipCreateStringFormat(0, LANG_NEUTRAL
, &format
);
41 GdipGetStringFormatAlign(format
, &align
);
42 GdipGetStringFormatLineAlign(format
, &line_align
);
43 GdipGetStringFormatHotkeyPrefix(format
, &n
);
44 GdipGetStringFormatTrimming(format
, &trimming
);
45 GdipGetStringFormatDigitSubstitution(format
, &digitlang
, &digitsub
);
46 GdipGetStringFormatMeasurableCharacterRangeCount(format
, &count
);
48 expect(HotkeyPrefixNone
, n
);
49 expect(StringAlignmentNear
, align
);
50 expect(StringAlignmentNear
, line_align
);
51 expect(StringTrimmingCharacter
, trimming
);
52 expect(StringDigitSubstituteUser
, digitsub
);
53 expect(LANG_NEUTRAL
, digitlang
);
56 stat
= GdipDeleteStringFormat(format
);
60 static void test_characterrange(void)
62 CharacterRange ranges
[3];
64 GpStringFormat
* format
;
67 stat
= GdipCreateStringFormat(0, LANG_NEUTRAL
, &format
);
69 stat
= GdipSetStringFormatMeasurableCharacterRanges(NULL
, 3, ranges
);
70 expect(InvalidParameter
, stat
);
71 stat
= GdipSetStringFormatMeasurableCharacterRanges(format
, 0, ranges
);
73 stat
= GdipSetStringFormatMeasurableCharacterRanges(format
, 3, NULL
);
74 expect(InvalidParameter
, stat
);
76 stat
= GdipSetStringFormatMeasurableCharacterRanges(format
, 3, ranges
);
78 stat
= GdipGetStringFormatMeasurableCharacterRangeCount(format
, &count
);
80 if (stat
== Ok
) expect(3, count
);
82 stat
= GdipDeleteStringFormat(format
);
86 static void test_digitsubstitution(void)
88 GpStringFormat
*format
;
90 StringDigitSubstitute digitsub
;
93 stat
= GdipCreateStringFormat(0, LANG_RUSSIAN
, &format
);
97 stat
= GdipGetStringFormatDigitSubstitution(NULL
, NULL
, NULL
);
98 expect(InvalidParameter
, stat
);
99 stat
= GdipGetStringFormatDigitSubstitution(format
, NULL
, NULL
);
101 stat
= GdipGetStringFormatDigitSubstitution(NULL
, &digitlang
, NULL
);
102 expect(InvalidParameter
, stat
);
103 stat
= GdipGetStringFormatDigitSubstitution(NULL
, NULL
, &digitsub
);
104 expect(InvalidParameter
, stat
);
105 stat
= GdipGetStringFormatDigitSubstitution(NULL
, &digitlang
, &digitsub
);
106 expect(InvalidParameter
, stat
);
107 stat
= GdipSetStringFormatDigitSubstitution(NULL
, LANG_NEUTRAL
, StringDigitSubstituteNone
);
108 expect(InvalidParameter
, stat
);
110 /* try to get both and one by one */
111 stat
= GdipGetStringFormatDigitSubstitution(format
, &digitlang
, &digitsub
);
113 expect(StringDigitSubstituteUser
, digitsub
);
114 expect(LANG_NEUTRAL
, digitlang
);
116 digitsub
= StringDigitSubstituteNone
;
117 stat
= GdipGetStringFormatDigitSubstitution(format
, NULL
, &digitsub
);
119 expect(StringDigitSubstituteUser
, digitsub
);
121 digitlang
= LANG_RUSSIAN
;
122 stat
= GdipGetStringFormatDigitSubstitution(format
, &digitlang
, NULL
);
124 expect(LANG_NEUTRAL
, digitlang
);
127 stat
= GdipSetStringFormatDigitSubstitution(format
, MAKELANGID(LANG_CHINESE
, SUBLANG_CHINESE_TRADITIONAL
),
128 StringDigitSubstituteUser
);
130 digitsub
= StringDigitSubstituteNone
;
131 digitlang
= LANG_RUSSIAN
;
132 stat
= GdipGetStringFormatDigitSubstitution(format
, &digitlang
, &digitsub
);
134 expect(StringDigitSubstituteUser
, digitsub
);
135 expect(MAKELANGID(LANG_CHINESE
, SUBLANG_CHINESE_TRADITIONAL
), digitlang
);
137 stat
= GdipDeleteStringFormat(format
);
141 static void test_getgenerictypographic(void)
143 GpStringFormat
*format
, *format2
;
147 StringAlignment align
, line_align
;
148 StringTrimming trimming
;
149 StringDigitSubstitute digitsub
;
154 stat
= GdipStringFormatGetGenericTypographic(NULL
);
155 expect(InvalidParameter
, stat
);
157 stat
= GdipStringFormatGetGenericTypographic(&format
);
160 stat
= GdipStringFormatGetGenericTypographic(&format2
);
162 ok(format
== format2
, "expected same format object\n");
163 stat
= GdipDeleteStringFormat(format2
);
166 GdipGetStringFormatFlags(format
, &flags
);
167 GdipGetStringFormatAlign(format
, &align
);
168 GdipGetStringFormatLineAlign(format
, &line_align
);
169 GdipGetStringFormatHotkeyPrefix(format
, &n
);
170 GdipGetStringFormatTrimming(format
, &trimming
);
171 GdipGetStringFormatDigitSubstitution(format
, &digitlang
, &digitsub
);
172 GdipGetStringFormatTabStopCount(format
, &tabcount
);
174 expect((StringFormatFlagsNoFitBlackBox
|StringFormatFlagsLineLimit
| StringFormatFlagsNoClip
),
176 expect(HotkeyPrefixNone
, n
);
177 expect(StringAlignmentNear
, align
);
178 expect(StringAlignmentNear
, line_align
);
179 expect(StringTrimmingNone
, trimming
);
180 expect(StringDigitSubstituteUser
, digitsub
);
181 expect(LANG_NEUTRAL
, digitlang
);
184 /* Change format parameters, release, get format object again. */
185 stat
= GdipSetStringFormatFlags(format
, StringFormatFlagsNoWrap
);
188 stat
= GdipGetStringFormatFlags(format
, &flags
);
190 expect(StringFormatFlagsNoWrap
, flags
);
192 stat
= GdipDeleteStringFormat(format
);
195 stat
= GdipStringFormatGetGenericTypographic(&format
);
198 stat
= GdipGetStringFormatFlags(format
, &flags
);
200 expect(StringFormatFlagsNoWrap
, flags
);
202 stat
= GdipDeleteStringFormat(format
);
206 static REAL tabstops
[] = {0.0, 10.0, 2.0};
207 static void test_tabstops(void)
209 GpStringFormat
*format
;
215 stat
= GdipCreateStringFormat(0, LANG_NEUTRAL
, &format
);
219 stat
= GdipGetStringFormatTabStopCount(NULL
, NULL
);
220 expect(InvalidParameter
, stat
);
221 stat
= GdipGetStringFormatTabStopCount(NULL
, &count
);
222 expect(InvalidParameter
, stat
);
223 stat
= GdipGetStringFormatTabStopCount(format
, NULL
);
224 expect(InvalidParameter
, stat
);
226 stat
= GdipSetStringFormatTabStops(NULL
, 0.0, 0, NULL
);
227 expect(InvalidParameter
, stat
);
228 stat
= GdipSetStringFormatTabStops(format
, 0.0, 0, NULL
);
229 expect(InvalidParameter
, stat
);
230 stat
= GdipSetStringFormatTabStops(NULL
, 0.0, 0, tabstops
);
231 expect(InvalidParameter
, stat
);
233 stat
= GdipGetStringFormatTabStops(NULL
, 0, NULL
, NULL
);
234 expect(InvalidParameter
, stat
);
235 stat
= GdipGetStringFormatTabStops(format
, 0, NULL
, NULL
);
236 expect(InvalidParameter
, stat
);
237 stat
= GdipGetStringFormatTabStops(NULL
, 0, &firsttab
, NULL
);
238 expect(InvalidParameter
, stat
);
239 stat
= GdipGetStringFormatTabStops(NULL
, 0, NULL
, tabs
);
240 expect(InvalidParameter
, stat
);
241 stat
= GdipGetStringFormatTabStops(format
, 0, &firsttab
, NULL
);
242 expect(InvalidParameter
, stat
);
243 stat
= GdipGetStringFormatTabStops(format
, 0, NULL
, tabs
);
244 expect(InvalidParameter
, stat
);
247 stat
= GdipGetStringFormatTabStopCount(format
, &count
);
250 /* negative tabcount */
251 stat
= GdipSetStringFormatTabStops(format
, 0.0, -1, tabstops
);
254 stat
= GdipGetStringFormatTabStopCount(format
, &count
);
258 stat
= GdipSetStringFormatTabStops(format
, -10.0, 0, tabstops
);
260 stat
= GdipSetStringFormatTabStops(format
, -10.0, 1, tabstops
);
261 expect(NotImplemented
, stat
);
264 tabs
[0] = tabs
[1] = tabs
[2] = -1.0;
265 stat
= GdipGetStringFormatTabStops(format
, 0, &firsttab
, tabs
);
267 expectf(-1.0, tabs
[0]);
268 expectf(-1.0, tabs
[1]);
269 expectf(-1.0, tabs
[2]);
270 expectf(0.0, firsttab
);
272 stat
= GdipSetStringFormatTabStops(format
, +0.0, 3, tabstops
);
275 stat
= GdipGetStringFormatTabStopCount(format
, &count
);
280 tabs
[0] = tabs
[1] = tabs
[2] = -1.0;
281 stat
= GdipGetStringFormatTabStops(format
, 3, &firsttab
, tabs
);
283 expectf(0.0, tabs
[0]);
284 expectf(10.0, tabs
[1]);
285 expectf(2.0, tabs
[2]);
286 expectf(0.0, firsttab
);
288 stat
= GdipSetStringFormatTabStops(format
, 10.0, 3, tabstops
);
291 tabs
[0] = tabs
[1] = tabs
[2] = -1.0;
292 stat
= GdipGetStringFormatTabStops(format
, 0, &firsttab
, tabs
);
294 expectf(-1.0, tabs
[0]);
295 expectf(-1.0, tabs
[1]);
296 expectf(-1.0, tabs
[2]);
297 expectf(10.0, firsttab
);
299 /* zero tabcount, after valid setting to 3 */
300 stat
= GdipSetStringFormatTabStops(format
, 0.0, 0, tabstops
);
303 stat
= GdipGetStringFormatTabStopCount(format
, &count
);
307 stat
= GdipDeleteStringFormat(format
);
311 static void test_getgenericdefault(void)
313 GpStringFormat
*format
, *format2
;
318 StringAlignment align
, line_align
;
319 StringTrimming trimming
;
320 StringDigitSubstitute digitsub
;
325 stat
= GdipStringFormatGetGenericDefault(NULL
);
326 expect(InvalidParameter
, stat
);
328 stat
= GdipStringFormatGetGenericDefault(&format
);
331 stat
= GdipStringFormatGetGenericDefault(&format2
);
333 ok(format
== format2
, "expected same format object\n");
334 stat
= GdipDeleteStringFormat(format2
);
337 GdipGetStringFormatFlags(format
, &flags
);
338 GdipGetStringFormatAlign(format
, &align
);
339 GdipGetStringFormatLineAlign(format
, &line_align
);
340 GdipGetStringFormatHotkeyPrefix(format
, &n
);
341 GdipGetStringFormatTrimming(format
, &trimming
);
342 GdipGetStringFormatDigitSubstitution(format
, &digitlang
, &digitsub
);
343 GdipGetStringFormatTabStopCount(format
, &tabcount
);
346 expect(HotkeyPrefixNone
, n
);
347 expect(StringAlignmentNear
, align
);
348 expect(StringAlignmentNear
, line_align
);
349 expect(StringTrimmingCharacter
, trimming
);
350 expect(StringDigitSubstituteUser
, digitsub
);
351 expect(LANG_NEUTRAL
, digitlang
);
354 /* Change default format parameters, release, get format object again. */
355 stat
= GdipSetStringFormatFlags(format
, StringFormatFlagsNoWrap
);
358 stat
= GdipGetStringFormatFlags(format
, &flags
);
360 expect(StringFormatFlagsNoWrap
, flags
);
362 stat
= GdipDeleteStringFormat(format
);
365 stat
= GdipStringFormatGetGenericDefault(&format
);
368 stat
= GdipGetStringFormatFlags(format
, &flags
);
370 expect(StringFormatFlagsNoWrap
, flags
);
372 stat
= GdipDeleteStringFormat(format
);
376 static void test_stringformatflags(void)
378 GpStringFormat
*format
;
383 stat
= GdipCreateStringFormat(0, LANG_NEUTRAL
, &format
);
387 stat
= GdipSetStringFormatFlags(NULL
, 0);
388 expect(InvalidParameter
, stat
);
390 stat
= GdipSetStringFormatFlags(format
, 0);
392 stat
= GdipGetStringFormatFlags(format
, &flags
);
396 /* Check some valid flags */
397 stat
= GdipSetStringFormatFlags(format
, StringFormatFlagsDirectionRightToLeft
);
399 stat
= GdipGetStringFormatFlags(format
, &flags
);
401 expect(StringFormatFlagsDirectionRightToLeft
, flags
);
403 stat
= GdipSetStringFormatFlags(format
, StringFormatFlagsNoFontFallback
);
405 stat
= GdipGetStringFormatFlags(format
, &flags
);
407 expect(StringFormatFlagsNoFontFallback
, flags
);
409 /* Check some flag combinations */
410 stat
= GdipSetStringFormatFlags(format
, StringFormatFlagsDirectionVertical
411 | StringFormatFlagsNoFitBlackBox
);
413 stat
= GdipGetStringFormatFlags(format
, &flags
);
415 expect((StringFormatFlagsDirectionVertical
416 | StringFormatFlagsNoFitBlackBox
), flags
);
418 stat
= GdipSetStringFormatFlags(format
, StringFormatFlagsDisplayFormatControl
419 | StringFormatFlagsMeasureTrailingSpaces
);
421 stat
= GdipGetStringFormatFlags(format
, &flags
);
423 expect((StringFormatFlagsDisplayFormatControl
424 | StringFormatFlagsMeasureTrailingSpaces
), flags
);
426 /* Check invalid flags */
427 stat
= GdipSetStringFormatFlags(format
, 0xdeadbeef);
429 stat
= GdipGetStringFormatFlags(format
, &flags
);
431 expect(0xdeadbeef, flags
);
433 stat
= GdipDeleteStringFormat(format
);
437 START_TEST(stringformat
)
439 struct GdiplusStartupInput gdiplusStartupInput
;
440 ULONG_PTR gdiplusToken
;
442 int (CDECL
* _controlfp_s
)(unsigned int *cur
, unsigned int newval
, unsigned int mask
);
444 /* Enable all FP exceptions except _EM_INEXACT, which gdi32 can trigger */
445 hmsvcrt
= LoadLibraryA("msvcrt");
446 _controlfp_s
= (void*)GetProcAddress(hmsvcrt
, "_controlfp_s");
447 if (_controlfp_s
) _controlfp_s(0, 0, 0x0008001e);
449 gdiplusStartupInput
.GdiplusVersion
= 1;
450 gdiplusStartupInput
.DebugEventCallback
= NULL
;
451 gdiplusStartupInput
.SuppressBackgroundThread
= 0;
452 gdiplusStartupInput
.SuppressExternalCodecs
= 0;
454 GdiplusStartup(&gdiplusToken
, &gdiplusStartupInput
, NULL
);
457 test_characterrange();
458 test_digitsubstitution();
459 test_getgenerictypographic();
461 test_getgenericdefault();
462 test_stringformatflags();
464 GdiplusShutdown(gdiplusToken
);