push e1d8a1293d44015bb0894687d02c5c53339996f7
[wine/hacks.git] / dlls / gdiplus / tests / stringformat.c
blobb28dbc6d355020f7f5cf80104c84a7a64ffb9c7d
1 /*
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
21 #include "windows.h"
22 #include "gdiplus.h"
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;
31 GpStatus stat;
32 INT n;
33 StringAlignment align, valign;
34 StringTrimming trimming;
35 StringDigitSubstitute digitsub;
36 LANGID digitlang;
38 stat = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
39 expect(Ok, stat);
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);
55 expect(Ok, stat);
58 static void test_characterrange(void)
60 CharacterRange ranges[3];
61 INT count;
62 GpStringFormat* format;
63 GpStatus stat;
65 stat = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
66 expect(Ok, stat);
67 todo_wine
69 stat = GdipSetStringFormatMeasurableCharacterRanges(format, 3, ranges);
70 expect(Ok, stat);
71 stat = GdipGetStringFormatMeasurableCharacterRangeCount(format, &count);
72 expect(Ok, stat);
73 if (stat == Ok) expect(3, count);
75 stat= GdipDeleteStringFormat(format);
76 expect(Ok, stat);
79 static void test_digitsubstitution(void)
81 GpStringFormat *format;
82 GpStatus stat;
83 StringDigitSubstitute digitsub;
84 LANGID digitlang;
86 stat = GdipCreateStringFormat(0, LANG_RUSSIAN, &format);
87 expect(Ok, stat);
89 /* NULL arguments */
90 stat = GdipGetStringFormatDigitSubstitution(NULL, NULL, NULL);
91 expect(InvalidParameter, stat);
92 stat = GdipGetStringFormatDigitSubstitution(format, NULL, NULL);
93 expect(Ok, stat);
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);
105 expect(Ok, stat);
106 expect(StringDigitSubstituteUser, digitsub);
107 expect(LANG_NEUTRAL, digitlang);
109 digitsub = StringDigitSubstituteNone;
110 stat = GdipGetStringFormatDigitSubstitution(format, NULL, &digitsub);
111 expect(Ok, stat);
112 expect(StringDigitSubstituteUser, digitsub);
114 digitlang = LANG_RUSSIAN;
115 stat = GdipGetStringFormatDigitSubstitution(format, &digitlang, NULL);
116 expect(Ok, stat);
117 expect(LANG_NEUTRAL, digitlang);
119 /* set/get */
120 stat = GdipSetStringFormatDigitSubstitution(format, MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL),
121 StringDigitSubstituteUser);
122 expect(Ok, stat);
123 digitsub = StringDigitSubstituteNone;
124 digitlang = LANG_RUSSIAN;
125 stat = GdipGetStringFormatDigitSubstitution(format, &digitlang, &digitsub);
126 expect(Ok, stat);
127 expect(StringDigitSubstituteUser, digitsub);
128 expect(MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL), digitlang);
130 stat = GdipDeleteStringFormat(format);
131 expect(Ok, stat);
134 static void test_getgenerictypographic(void)
136 GpStringFormat *format;
137 GpStatus stat;
138 INT flags;
139 INT n;
140 StringAlignment align, valign;
141 StringTrimming trimming;
142 StringDigitSubstitute digitsub;
143 LANGID digitlang;
144 INT tabcount;
146 /* NULL arg */
147 stat = GdipStringFormatGetGenericTypographic(NULL);
148 expect(InvalidParameter, stat);
150 stat = GdipStringFormatGetGenericTypographic(&format);
151 expect(Ok, stat);
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),
162 flags);
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);
169 expect(0, tabcount);
171 stat = GdipDeleteStringFormat(format);
172 expect(Ok, stat);
175 static REAL tabstops[] = {0.0, 10.0, 2.0};
176 static void test_tabstops(void)
178 GpStringFormat *format;
179 GpStatus stat;
180 INT count;
181 REAL tabs[3];
182 REAL firsttab;
184 stat = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
185 expect(Ok, stat);
187 /* NULL */
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);
215 /* not NULL */
216 stat = GdipGetStringFormatTabStopCount(format, &count);
217 expect(Ok, stat);
218 expect(0, count);
219 /* negative tabcount */
220 stat = GdipSetStringFormatTabStops(format, 0.0, -1, tabstops);
221 expect(Ok, stat);
222 count = -1;
223 stat = GdipGetStringFormatTabStopCount(format, &count);
224 expect(Ok, stat);
225 expect(0, count);
227 stat = GdipSetStringFormatTabStops(format, -10.0, 0, tabstops);
228 expect(Ok, stat);
229 stat = GdipSetStringFormatTabStops(format, -10.0, 1, tabstops);
230 expect(NotImplemented, stat);
232 firsttab = -1.0;
233 tabs[0] = tabs[1] = tabs[2] = -1.0;
234 stat = GdipGetStringFormatTabStops(format, 0, &firsttab, tabs);
235 expect(Ok, stat);
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);
242 expect(Ok, stat);
243 count = 0;
244 stat = GdipGetStringFormatTabStopCount(format, &count);
245 expect(Ok, stat);
246 expect(3, count);
248 firsttab = -1.0;
249 tabs[0] = tabs[1] = tabs[2] = -1.0;
250 stat = GdipGetStringFormatTabStops(format, 3, &firsttab, tabs);
251 expect(Ok, stat);
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);
258 expect(Ok, stat);
259 firsttab = -1.0;
260 tabs[0] = tabs[1] = tabs[2] = -1.0;
261 stat = GdipGetStringFormatTabStops(format, 0, &firsttab, tabs);
262 expect(Ok, stat);
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);
270 expect(Ok, stat);
271 count = 0;
272 stat = GdipGetStringFormatTabStopCount(format, &count);
273 expect(Ok, stat);
274 expect(3, count);
276 stat = GdipDeleteStringFormat(format);
277 expect(Ok, stat);
280 static void test_getgenericdefault(void)
282 GpStringFormat *format;
283 GpStatus stat;
285 INT flags;
286 INT n;
287 StringAlignment align, valign;
288 StringTrimming trimming;
289 StringDigitSubstitute digitsub;
290 LANGID digitlang;
291 INT tabcount;
293 /* NULL arg */
294 stat = GdipStringFormatGetGenericDefault(NULL);
295 expect(InvalidParameter, stat);
297 stat = GdipStringFormatGetGenericDefault(&format);
298 expect(Ok, stat);
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);
308 expect(0, flags);
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);
315 expect(0, tabcount);
317 stat = GdipDeleteStringFormat(format);
318 expect(Ok, stat);
321 static void test_stringformatflags(void)
323 GpStringFormat *format;
324 GpStatus stat;
326 INT flags;
328 stat = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
329 expect(Ok, stat);
331 /* NULL args */
332 stat = GdipSetStringFormatFlags(NULL, 0);
333 expect(InvalidParameter, stat);
335 stat = GdipSetStringFormatFlags(format, 0);
336 expect(Ok, stat);
337 stat = GdipGetStringFormatFlags(format, &flags);
338 expect(Ok, stat);
339 expect(0, flags);
341 /* Check some valid flags */
342 stat = GdipSetStringFormatFlags(format, StringFormatFlagsDirectionRightToLeft);
343 expect(Ok, stat);
344 stat = GdipGetStringFormatFlags(format, &flags);
345 expect(Ok, stat);
346 expect(StringFormatFlagsDirectionRightToLeft, flags);
348 stat = GdipSetStringFormatFlags(format, StringFormatFlagsNoFontFallback);
349 expect(Ok, stat);
350 stat = GdipGetStringFormatFlags(format, &flags);
351 expect(Ok, stat);
352 expect(StringFormatFlagsNoFontFallback, flags);
354 /* Check some flag combinations */
355 stat = GdipSetStringFormatFlags(format, StringFormatFlagsDirectionVertical
356 | StringFormatFlagsNoFitBlackBox);
357 expect(Ok, stat);
358 stat = GdipGetStringFormatFlags(format, &flags);
359 expect(Ok, stat);
360 expect((StringFormatFlagsDirectionVertical
361 | StringFormatFlagsNoFitBlackBox), flags);
363 stat = GdipSetStringFormatFlags(format, StringFormatFlagsDisplayFormatControl
364 | StringFormatFlagsMeasureTrailingSpaces);
365 expect(Ok, stat);
366 stat = GdipGetStringFormatFlags(format, &flags);
367 expect(Ok, stat);
368 expect((StringFormatFlagsDisplayFormatControl
369 | StringFormatFlagsMeasureTrailingSpaces), flags);
371 /* Check invalid flags */
372 stat = GdipSetStringFormatFlags(format, 0xdeadbeef);
373 expect(Ok, stat);
374 stat = GdipGetStringFormatFlags(format, &flags);
375 expect(Ok, stat);
376 expect(0xdeadbeef, flags);
378 stat = GdipDeleteStringFormat(format);
379 expect(Ok, stat);
382 START_TEST(stringformat)
384 struct GdiplusStartupInput gdiplusStartupInput;
385 ULONG_PTR gdiplusToken;
387 gdiplusStartupInput.GdiplusVersion = 1;
388 gdiplusStartupInput.DebugEventCallback = NULL;
389 gdiplusStartupInput.SuppressBackgroundThread = 0;
390 gdiplusStartupInput.SuppressExternalCodecs = 0;
392 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
394 test_constructor();
395 test_characterrange();
396 test_digitsubstitution();
397 test_getgenerictypographic();
398 test_tabstops();
399 test_getgenericdefault();
400 test_stringformatflags();
402 GdiplusShutdown(gdiplusToken);