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);
46 GdipGetStringFormatMeasurableCharacterRangeCount(format, &count);
48 expect(HotkeyPrefixNone, n);
49 expect(StringAlignmentNear, align);
50 expect(StringAlignmentNear, 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;
147 StringAlignment align, valign;
148 StringTrimming trimming;
149 StringDigitSubstitute digitsub;
154 stat = GdipStringFormatGetGenericTypographic(NULL);
155 expect(InvalidParameter, stat);
157 stat = GdipStringFormatGetGenericTypographic(&format);
160 GdipGetStringFormatFlags(format, &flags);
161 GdipGetStringFormatAlign(format, &align);
162 GdipGetStringFormatLineAlign(format, &valign);
163 GdipGetStringFormatHotkeyPrefix(format, &n);
164 GdipGetStringFormatTrimming(format, &trimming);
165 GdipGetStringFormatDigitSubstitution(format, &digitlang, &digitsub);
166 GdipGetStringFormatTabStopCount(format, &tabcount);
168 expect((StringFormatFlagsNoFitBlackBox |StringFormatFlagsLineLimit | StringFormatFlagsNoClip),
170 expect(HotkeyPrefixNone, n);
171 expect(StringAlignmentNear, align);
172 expect(StringAlignmentNear, align);
173 expect(StringTrimmingNone, trimming);
174 expect(StringDigitSubstituteUser, digitsub);
175 expect(LANG_NEUTRAL, digitlang);
178 stat = GdipDeleteStringFormat(format);
182 static REAL tabstops[] = {0.0, 10.0, 2.0};
183 static void test_tabstops(void)
185 GpStringFormat *format;
191 stat = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
195 stat = GdipGetStringFormatTabStopCount(NULL, NULL);
196 expect(InvalidParameter, stat);
197 stat = GdipGetStringFormatTabStopCount(NULL, &count);
198 expect(InvalidParameter, stat);
199 stat = GdipGetStringFormatTabStopCount(format, NULL);
200 expect(InvalidParameter, stat);
202 stat = GdipSetStringFormatTabStops(NULL, 0.0, 0, NULL);
203 expect(InvalidParameter, stat);
204 stat = GdipSetStringFormatTabStops(format, 0.0, 0, NULL);
205 expect(InvalidParameter, stat);
206 stat = GdipSetStringFormatTabStops(NULL, 0.0, 0, tabstops);
207 expect(InvalidParameter, stat);
209 stat = GdipGetStringFormatTabStops(NULL, 0, NULL, NULL);
210 expect(InvalidParameter, stat);
211 stat = GdipGetStringFormatTabStops(format, 0, NULL, NULL);
212 expect(InvalidParameter, stat);
213 stat = GdipGetStringFormatTabStops(NULL, 0, &firsttab, NULL);
214 expect(InvalidParameter, stat);
215 stat = GdipGetStringFormatTabStops(NULL, 0, NULL, tabs);
216 expect(InvalidParameter, stat);
217 stat = GdipGetStringFormatTabStops(format, 0, &firsttab, NULL);
218 expect(InvalidParameter, stat);
219 stat = GdipGetStringFormatTabStops(format, 0, NULL, tabs);
220 expect(InvalidParameter, stat);
223 stat = GdipGetStringFormatTabStopCount(format, &count);
226 /* negative tabcount */
227 stat = GdipSetStringFormatTabStops(format, 0.0, -1, tabstops);
230 stat = GdipGetStringFormatTabStopCount(format, &count);
234 stat = GdipSetStringFormatTabStops(format, -10.0, 0, tabstops);
236 stat = GdipSetStringFormatTabStops(format, -10.0, 1, tabstops);
237 expect(NotImplemented, stat);
240 tabs[0] = tabs[1] = tabs[2] = -1.0;
241 stat = GdipGetStringFormatTabStops(format, 0, &firsttab, tabs);
243 expectf(-1.0, tabs[0]);
244 expectf(-1.0, tabs[1]);
245 expectf(-1.0, tabs[2]);
246 expectf(0.0, firsttab);
248 stat = GdipSetStringFormatTabStops(format, +0.0, 3, tabstops);
251 stat = GdipGetStringFormatTabStopCount(format, &count);
256 tabs[0] = tabs[1] = tabs[2] = -1.0;
257 stat = GdipGetStringFormatTabStops(format, 3, &firsttab, tabs);
259 expectf(0.0, tabs[0]);
260 expectf(10.0, tabs[1]);
261 expectf(2.0, tabs[2]);
262 expectf(0.0, firsttab);
264 stat = GdipSetStringFormatTabStops(format, 10.0, 3, tabstops);
267 tabs[0] = tabs[1] = tabs[2] = -1.0;
268 stat = GdipGetStringFormatTabStops(format, 0, &firsttab, tabs);
270 expectf(-1.0, tabs[0]);
271 expectf(-1.0, tabs[1]);
272 expectf(-1.0, tabs[2]);
273 expectf(10.0, firsttab);
275 /* zero tabcount, after valid setting to 3 */
276 stat = GdipSetStringFormatTabStops(format, 0.0, 0, tabstops);
279 stat = GdipGetStringFormatTabStopCount(format, &count);
283 stat = GdipDeleteStringFormat(format);
287 static void test_getgenericdefault(void)
289 GpStringFormat *format;
294 StringAlignment align, valign;
295 StringTrimming trimming;
296 StringDigitSubstitute digitsub;
301 stat = GdipStringFormatGetGenericDefault(NULL);
302 expect(InvalidParameter, stat);
304 stat = GdipStringFormatGetGenericDefault(&format);
307 GdipGetStringFormatFlags(format, &flags);
308 GdipGetStringFormatAlign(format, &align);
309 GdipGetStringFormatLineAlign(format, &valign);
310 GdipGetStringFormatHotkeyPrefix(format, &n);
311 GdipGetStringFormatTrimming(format, &trimming);
312 GdipGetStringFormatDigitSubstitution(format, &digitlang, &digitsub);
313 GdipGetStringFormatTabStopCount(format, &tabcount);
316 expect(HotkeyPrefixNone, n);
317 expect(StringAlignmentNear, align);
318 expect(StringAlignmentNear, align);
319 expect(StringTrimmingCharacter, trimming);
320 expect(StringDigitSubstituteUser, digitsub);
321 expect(LANG_NEUTRAL, digitlang);
324 stat = GdipDeleteStringFormat(format);
328 static void test_stringformatflags(void)
330 GpStringFormat *format;
335 stat = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
339 stat = GdipSetStringFormatFlags(NULL, 0);
340 expect(InvalidParameter, stat);
342 stat = GdipSetStringFormatFlags(format, 0);
344 stat = GdipGetStringFormatFlags(format, &flags);
348 /* Check some valid flags */
349 stat = GdipSetStringFormatFlags(format, StringFormatFlagsDirectionRightToLeft);
351 stat = GdipGetStringFormatFlags(format, &flags);
353 expect(StringFormatFlagsDirectionRightToLeft, flags);
355 stat = GdipSetStringFormatFlags(format, StringFormatFlagsNoFontFallback);
357 stat = GdipGetStringFormatFlags(format, &flags);
359 expect(StringFormatFlagsNoFontFallback, flags);
361 /* Check some flag combinations */
362 stat = GdipSetStringFormatFlags(format, StringFormatFlagsDirectionVertical
363 | StringFormatFlagsNoFitBlackBox);
365 stat = GdipGetStringFormatFlags(format, &flags);
367 expect((StringFormatFlagsDirectionVertical
368 | StringFormatFlagsNoFitBlackBox), flags);
370 stat = GdipSetStringFormatFlags(format, StringFormatFlagsDisplayFormatControl
371 | StringFormatFlagsMeasureTrailingSpaces);
373 stat = GdipGetStringFormatFlags(format, &flags);
375 expect((StringFormatFlagsDisplayFormatControl
376 | StringFormatFlagsMeasureTrailingSpaces), flags);
378 /* Check invalid flags */
379 stat = GdipSetStringFormatFlags(format, 0xdeadbeef);
381 stat = GdipGetStringFormatFlags(format, &flags);
383 expect(0xdeadbeef, flags);
385 stat = GdipDeleteStringFormat(format);
389 START_TEST(stringformat)
391 struct GdiplusStartupInput gdiplusStartupInput;
392 ULONG_PTR gdiplusToken;
394 gdiplusStartupInput.GdiplusVersion = 1;
395 gdiplusStartupInput.DebugEventCallback = NULL;
396 gdiplusStartupInput.SuppressBackgroundThread = 0;
397 gdiplusStartupInput.SuppressExternalCodecs = 0;
399 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
402 test_characterrange();
403 test_digitsubstitution();
404 test_getgenerictypographic();
406 test_getgenericdefault();
407 test_stringformatflags();
409 GdiplusShutdown(gdiplusToken);