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
, valign
;
34 StringTrimming trimming
;
35 StringDigitSubstitute digitsub
;
38 stat
= GdipCreateStringFormat(0, LANG_NEUTRAL
, &format
);
41 GdipGetStringFormatAlign(format
, &align
);
42 GdipGetStringFormatLineAlign(format
, &valign
);
43 GdipGetStringFormatHotkeyPrefix(format
, &n
);
44 GdipGetStringFormatTrimming(format
, &trimming
);
45 GdipGetStringFormatDigitSubstitution(format
, &digitlang
, &digitsub
);
47 expect(HotkeyPrefixNone
, n
);
48 expect(StringAlignmentNear
, align
);
49 expect(StringAlignmentNear
, align
);
50 expect(StringTrimmingCharacter
, trimming
);
51 expect(StringDigitSubstituteUser
, digitsub
);
52 expect(LANG_NEUTRAL
, digitlang
);
54 stat
= GdipDeleteStringFormat(format
);
58 static void test_characterrange(void)
60 CharacterRange ranges
[3];
62 GpStringFormat
* format
;
65 stat
= GdipCreateStringFormat(0, LANG_NEUTRAL
, &format
);
69 stat
= GdipSetStringFormatMeasurableCharacterRanges(format
, 3, ranges
);
71 stat
= GdipGetStringFormatMeasurableCharacterRangeCount(format
, &count
);
73 if (stat
== Ok
) expect(3, count
);
75 stat
= GdipDeleteStringFormat(format
);
79 static void test_digitsubstitution(void)
81 GpStringFormat
*format
;
83 StringDigitSubstitute digitsub
;
86 stat
= GdipCreateStringFormat(0, LANG_RUSSIAN
, &format
);
90 stat
= GdipGetStringFormatDigitSubstitution(NULL
, NULL
, NULL
);
91 expect(InvalidParameter
, stat
);
92 stat
= GdipGetStringFormatDigitSubstitution(format
, NULL
, NULL
);
94 stat
= GdipGetStringFormatDigitSubstitution(NULL
, &digitlang
, NULL
);
95 expect(InvalidParameter
, stat
);
96 stat
= GdipGetStringFormatDigitSubstitution(NULL
, NULL
, &digitsub
);
97 expect(InvalidParameter
, stat
);
98 stat
= GdipGetStringFormatDigitSubstitution(NULL
, &digitlang
, &digitsub
);
99 expect(InvalidParameter
, stat
);
100 stat
= GdipSetStringFormatDigitSubstitution(NULL
, LANG_NEUTRAL
, StringDigitSubstituteNone
);
101 expect(InvalidParameter
, stat
);
103 /* try to get both and one by one */
104 stat
= GdipGetStringFormatDigitSubstitution(format
, &digitlang
, &digitsub
);
106 expect(StringDigitSubstituteUser
, digitsub
);
107 expect(LANG_NEUTRAL
, digitlang
);
109 digitsub
= StringDigitSubstituteNone
;
110 stat
= GdipGetStringFormatDigitSubstitution(format
, NULL
, &digitsub
);
112 expect(StringDigitSubstituteUser
, digitsub
);
114 digitlang
= LANG_RUSSIAN
;
115 stat
= GdipGetStringFormatDigitSubstitution(format
, &digitlang
, NULL
);
117 expect(LANG_NEUTRAL
, digitlang
);
120 stat
= GdipSetStringFormatDigitSubstitution(format
, MAKELANGID(LANG_CHINESE
, SUBLANG_CHINESE_TRADITIONAL
),
121 StringDigitSubstituteUser
);
123 digitsub
= StringDigitSubstituteNone
;
124 digitlang
= LANG_RUSSIAN
;
125 stat
= GdipGetStringFormatDigitSubstitution(format
, &digitlang
, &digitsub
);
127 expect(StringDigitSubstituteUser
, digitsub
);
128 expect(MAKELANGID(LANG_CHINESE
, SUBLANG_CHINESE_TRADITIONAL
), digitlang
);
130 stat
= GdipDeleteStringFormat(format
);
134 static void test_getgenerictypographic(void)
136 GpStringFormat
*format
;
140 StringAlignment align
, valign
;
141 StringTrimming trimming
;
142 StringDigitSubstitute digitsub
;
147 stat
= GdipStringFormatGetGenericTypographic(NULL
);
148 expect(InvalidParameter
, stat
);
150 stat
= GdipStringFormatGetGenericTypographic(&format
);
153 GdipGetStringFormatFlags(format
, &flags
);
154 GdipGetStringFormatAlign(format
, &align
);
155 GdipGetStringFormatLineAlign(format
, &valign
);
156 GdipGetStringFormatHotkeyPrefix(format
, &n
);
157 GdipGetStringFormatTrimming(format
, &trimming
);
158 GdipGetStringFormatDigitSubstitution(format
, &digitlang
, &digitsub
);
159 GdipGetStringFormatTabStopCount(format
, &tabcount
);
161 expect((StringFormatFlagsNoFitBlackBox
|StringFormatFlagsLineLimit
| StringFormatFlagsNoClip
),
163 expect(HotkeyPrefixNone
, n
);
164 expect(StringAlignmentNear
, align
);
165 expect(StringAlignmentNear
, align
);
166 expect(StringTrimmingNone
, trimming
);
167 expect(StringDigitSubstituteUser
, digitsub
);
168 expect(LANG_NEUTRAL
, digitlang
);
171 stat
= GdipDeleteStringFormat(format
);
175 static REAL tabstops
[] = {0.0, 10.0, 2.0};
176 static void test_tabstops(void)
178 GpStringFormat
*format
;
184 stat
= GdipCreateStringFormat(0, LANG_NEUTRAL
, &format
);
188 stat
= GdipGetStringFormatTabStopCount(NULL
, NULL
);
189 expect(InvalidParameter
, stat
);
190 stat
= GdipGetStringFormatTabStopCount(NULL
, &count
);
191 expect(InvalidParameter
, stat
);
192 stat
= GdipGetStringFormatTabStopCount(format
, NULL
);
193 expect(InvalidParameter
, stat
);
195 stat
= GdipSetStringFormatTabStops(NULL
, 0.0, 0, NULL
);
196 expect(InvalidParameter
, stat
);
197 stat
= GdipSetStringFormatTabStops(format
, 0.0, 0, NULL
);
198 expect(InvalidParameter
, stat
);
199 stat
= GdipSetStringFormatTabStops(NULL
, 0.0, 0, tabstops
);
200 expect(InvalidParameter
, stat
);
202 stat
= GdipGetStringFormatTabStops(NULL
, 0, NULL
, NULL
);
203 expect(InvalidParameter
, stat
);
204 stat
= GdipGetStringFormatTabStops(format
, 0, NULL
, NULL
);
205 expect(InvalidParameter
, stat
);
206 stat
= GdipGetStringFormatTabStops(NULL
, 0, &firsttab
, NULL
);
207 expect(InvalidParameter
, stat
);
208 stat
= GdipGetStringFormatTabStops(NULL
, 0, NULL
, tabs
);
209 expect(InvalidParameter
, stat
);
210 stat
= GdipGetStringFormatTabStops(format
, 0, &firsttab
, NULL
);
211 expect(InvalidParameter
, stat
);
212 stat
= GdipGetStringFormatTabStops(format
, 0, NULL
, tabs
);
213 expect(InvalidParameter
, stat
);
216 stat
= GdipGetStringFormatTabStopCount(format
, &count
);
219 /* negative tabcount */
220 stat
= GdipSetStringFormatTabStops(format
, 0.0, -1, tabstops
);
223 stat
= GdipGetStringFormatTabStopCount(format
, &count
);
227 stat
= GdipSetStringFormatTabStops(format
, -10.0, 0, tabstops
);
229 stat
= GdipSetStringFormatTabStops(format
, -10.0, 1, tabstops
);
230 expect(NotImplemented
, stat
);
233 tabs
[0] = tabs
[1] = tabs
[2] = -1.0;
234 stat
= GdipGetStringFormatTabStops(format
, 0, &firsttab
, tabs
);
236 expectf(-1.0, tabs
[0]);
237 expectf(-1.0, tabs
[1]);
238 expectf(-1.0, tabs
[2]);
239 expectf(0.0, firsttab
);
241 stat
= GdipSetStringFormatTabStops(format
, +0.0, 3, tabstops
);
244 stat
= GdipGetStringFormatTabStopCount(format
, &count
);
249 tabs
[0] = tabs
[1] = tabs
[2] = -1.0;
250 stat
= GdipGetStringFormatTabStops(format
, 3, &firsttab
, tabs
);
252 expectf(0.0, tabs
[0]);
253 expectf(10.0, tabs
[1]);
254 expectf(2.0, tabs
[2]);
255 expectf(0.0, firsttab
);
257 stat
= GdipSetStringFormatTabStops(format
, 10.0, 3, tabstops
);
260 tabs
[0] = tabs
[1] = tabs
[2] = -1.0;
261 stat
= GdipGetStringFormatTabStops(format
, 0, &firsttab
, tabs
);
263 expectf(-1.0, tabs
[0]);
264 expectf(-1.0, tabs
[1]);
265 expectf(-1.0, tabs
[2]);
266 expectf(10.0, firsttab
);
268 /* zero tabcount, after valid setting to 3 */
269 stat
= GdipSetStringFormatTabStops(format
, 0.0, 0, tabstops
);
272 stat
= GdipGetStringFormatTabStopCount(format
, &count
);
276 stat
= GdipDeleteStringFormat(format
);
280 static void test_getgenericdefault(void)
282 GpStringFormat
*format
;
287 StringAlignment align
, valign
;
288 StringTrimming trimming
;
289 StringDigitSubstitute digitsub
;
294 stat
= GdipStringFormatGetGenericDefault(NULL
);
295 expect(InvalidParameter
, stat
);
297 stat
= GdipStringFormatGetGenericDefault(&format
);
300 GdipGetStringFormatFlags(format
, &flags
);
301 GdipGetStringFormatAlign(format
, &align
);
302 GdipGetStringFormatLineAlign(format
, &valign
);
303 GdipGetStringFormatHotkeyPrefix(format
, &n
);
304 GdipGetStringFormatTrimming(format
, &trimming
);
305 GdipGetStringFormatDigitSubstitution(format
, &digitlang
, &digitsub
);
306 GdipGetStringFormatTabStopCount(format
, &tabcount
);
309 expect(HotkeyPrefixNone
, n
);
310 expect(StringAlignmentNear
, align
);
311 expect(StringAlignmentNear
, align
);
312 expect(StringTrimmingCharacter
, trimming
);
313 expect(StringDigitSubstituteUser
, digitsub
);
314 expect(LANG_NEUTRAL
, digitlang
);
317 stat
= GdipDeleteStringFormat(format
);
321 START_TEST(stringformat
)
323 struct GdiplusStartupInput gdiplusStartupInput
;
324 ULONG_PTR gdiplusToken
;
326 gdiplusStartupInput
.GdiplusVersion
= 1;
327 gdiplusStartupInput
.DebugEventCallback
= NULL
;
328 gdiplusStartupInput
.SuppressBackgroundThread
= 0;
329 gdiplusStartupInput
.SuppressExternalCodecs
= 0;
331 GdiplusStartup(&gdiplusToken
, &gdiplusStartupInput
, NULL
);
334 test_characterrange();
335 test_digitsubstitution();
336 test_getgenerictypographic();
338 test_getgenericdefault();
340 GdiplusShutdown(gdiplusToken
);