winex11.drv: Don't call glXSwapBuffers if the context or the drawable are invalid.
[wine.git] / dlls / gdiplus / tests / stringformat.c
blob117e57bd2430f6f4007f9039e266a5a83ff5d760
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, count;
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);
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);
54 expect(0, count);
56 stat = GdipDeleteStringFormat(format);
57 expect(Ok, stat);
60 static void test_characterrange(void)
62 CharacterRange ranges[3];
63 INT count;
64 GpStringFormat* format;
65 GpStatus stat;
67 stat = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
68 expect(Ok, stat);
69 stat = GdipSetStringFormatMeasurableCharacterRanges(NULL, 3, ranges);
70 expect(InvalidParameter, stat);
71 stat = GdipSetStringFormatMeasurableCharacterRanges(format, 0, ranges);
72 expect(Ok, stat);
73 stat = GdipSetStringFormatMeasurableCharacterRanges(format, 3, NULL);
74 expect(InvalidParameter, stat);
76 stat = GdipSetStringFormatMeasurableCharacterRanges(format, 3, ranges);
77 expect(Ok, stat);
78 stat = GdipGetStringFormatMeasurableCharacterRangeCount(format, &count);
79 expect(Ok, stat);
80 if (stat == Ok) expect(3, count);
82 stat= GdipDeleteStringFormat(format);
83 expect(Ok, stat);
86 static void test_digitsubstitution(void)
88 GpStringFormat *format;
89 GpStatus stat;
90 StringDigitSubstitute digitsub;
91 LANGID digitlang;
93 stat = GdipCreateStringFormat(0, LANG_RUSSIAN, &format);
94 expect(Ok, stat);
96 /* NULL arguments */
97 stat = GdipGetStringFormatDigitSubstitution(NULL, NULL, NULL);
98 expect(InvalidParameter, stat);
99 stat = GdipGetStringFormatDigitSubstitution(format, NULL, NULL);
100 expect(Ok, stat);
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);
112 expect(Ok, stat);
113 expect(StringDigitSubstituteUser, digitsub);
114 expect(LANG_NEUTRAL, digitlang);
116 digitsub = StringDigitSubstituteNone;
117 stat = GdipGetStringFormatDigitSubstitution(format, NULL, &digitsub);
118 expect(Ok, stat);
119 expect(StringDigitSubstituteUser, digitsub);
121 digitlang = LANG_RUSSIAN;
122 stat = GdipGetStringFormatDigitSubstitution(format, &digitlang, NULL);
123 expect(Ok, stat);
124 expect(LANG_NEUTRAL, digitlang);
126 /* set/get */
127 stat = GdipSetStringFormatDigitSubstitution(format, MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL),
128 StringDigitSubstituteUser);
129 expect(Ok, stat);
130 digitsub = StringDigitSubstituteNone;
131 digitlang = LANG_RUSSIAN;
132 stat = GdipGetStringFormatDigitSubstitution(format, &digitlang, &digitsub);
133 expect(Ok, stat);
134 expect(StringDigitSubstituteUser, digitsub);
135 expect(MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL), digitlang);
137 stat = GdipDeleteStringFormat(format);
138 expect(Ok, stat);
141 static void test_getgenerictypographic(void)
143 GpStringFormat *format;
144 GpStatus stat;
145 INT flags;
146 INT n;
147 StringAlignment align, valign;
148 StringTrimming trimming;
149 StringDigitSubstitute digitsub;
150 LANGID digitlang;
151 INT tabcount;
153 /* NULL arg */
154 stat = GdipStringFormatGetGenericTypographic(NULL);
155 expect(InvalidParameter, stat);
157 stat = GdipStringFormatGetGenericTypographic(&format);
158 expect(Ok, stat);
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),
169 flags);
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);
176 expect(0, tabcount);
178 stat = GdipDeleteStringFormat(format);
179 expect(Ok, stat);
182 static REAL tabstops[] = {0.0, 10.0, 2.0};
183 static void test_tabstops(void)
185 GpStringFormat *format;
186 GpStatus stat;
187 INT count;
188 REAL tabs[3];
189 REAL firsttab;
191 stat = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
192 expect(Ok, stat);
194 /* NULL */
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);
222 /* not NULL */
223 stat = GdipGetStringFormatTabStopCount(format, &count);
224 expect(Ok, stat);
225 expect(0, count);
226 /* negative tabcount */
227 stat = GdipSetStringFormatTabStops(format, 0.0, -1, tabstops);
228 expect(Ok, stat);
229 count = -1;
230 stat = GdipGetStringFormatTabStopCount(format, &count);
231 expect(Ok, stat);
232 expect(0, count);
234 stat = GdipSetStringFormatTabStops(format, -10.0, 0, tabstops);
235 expect(Ok, stat);
236 stat = GdipSetStringFormatTabStops(format, -10.0, 1, tabstops);
237 expect(NotImplemented, stat);
239 firsttab = -1.0;
240 tabs[0] = tabs[1] = tabs[2] = -1.0;
241 stat = GdipGetStringFormatTabStops(format, 0, &firsttab, tabs);
242 expect(Ok, stat);
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);
249 expect(Ok, stat);
250 count = 0;
251 stat = GdipGetStringFormatTabStopCount(format, &count);
252 expect(Ok, stat);
253 expect(3, count);
255 firsttab = -1.0;
256 tabs[0] = tabs[1] = tabs[2] = -1.0;
257 stat = GdipGetStringFormatTabStops(format, 3, &firsttab, tabs);
258 expect(Ok, stat);
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);
265 expect(Ok, stat);
266 firsttab = -1.0;
267 tabs[0] = tabs[1] = tabs[2] = -1.0;
268 stat = GdipGetStringFormatTabStops(format, 0, &firsttab, tabs);
269 expect(Ok, stat);
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);
277 expect(Ok, stat);
278 count = 0;
279 stat = GdipGetStringFormatTabStopCount(format, &count);
280 expect(Ok, stat);
281 expect(3, count);
283 stat = GdipDeleteStringFormat(format);
284 expect(Ok, stat);
287 static void test_getgenericdefault(void)
289 GpStringFormat *format;
290 GpStatus stat;
292 INT flags;
293 INT n;
294 StringAlignment align, valign;
295 StringTrimming trimming;
296 StringDigitSubstitute digitsub;
297 LANGID digitlang;
298 INT tabcount;
300 /* NULL arg */
301 stat = GdipStringFormatGetGenericDefault(NULL);
302 expect(InvalidParameter, stat);
304 stat = GdipStringFormatGetGenericDefault(&format);
305 expect(Ok, stat);
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);
315 expect(0, flags);
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);
322 expect(0, tabcount);
324 stat = GdipDeleteStringFormat(format);
325 expect(Ok, stat);
328 static void test_stringformatflags(void)
330 GpStringFormat *format;
331 GpStatus stat;
333 INT flags;
335 stat = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
336 expect(Ok, stat);
338 /* NULL args */
339 stat = GdipSetStringFormatFlags(NULL, 0);
340 expect(InvalidParameter, stat);
342 stat = GdipSetStringFormatFlags(format, 0);
343 expect(Ok, stat);
344 stat = GdipGetStringFormatFlags(format, &flags);
345 expect(Ok, stat);
346 expect(0, flags);
348 /* Check some valid flags */
349 stat = GdipSetStringFormatFlags(format, StringFormatFlagsDirectionRightToLeft);
350 expect(Ok, stat);
351 stat = GdipGetStringFormatFlags(format, &flags);
352 expect(Ok, stat);
353 expect(StringFormatFlagsDirectionRightToLeft, flags);
355 stat = GdipSetStringFormatFlags(format, StringFormatFlagsNoFontFallback);
356 expect(Ok, stat);
357 stat = GdipGetStringFormatFlags(format, &flags);
358 expect(Ok, stat);
359 expect(StringFormatFlagsNoFontFallback, flags);
361 /* Check some flag combinations */
362 stat = GdipSetStringFormatFlags(format, StringFormatFlagsDirectionVertical
363 | StringFormatFlagsNoFitBlackBox);
364 expect(Ok, stat);
365 stat = GdipGetStringFormatFlags(format, &flags);
366 expect(Ok, stat);
367 expect((StringFormatFlagsDirectionVertical
368 | StringFormatFlagsNoFitBlackBox), flags);
370 stat = GdipSetStringFormatFlags(format, StringFormatFlagsDisplayFormatControl
371 | StringFormatFlagsMeasureTrailingSpaces);
372 expect(Ok, stat);
373 stat = GdipGetStringFormatFlags(format, &flags);
374 expect(Ok, stat);
375 expect((StringFormatFlagsDisplayFormatControl
376 | StringFormatFlagsMeasureTrailingSpaces), flags);
378 /* Check invalid flags */
379 stat = GdipSetStringFormatFlags(format, 0xdeadbeef);
380 expect(Ok, stat);
381 stat = GdipGetStringFormatFlags(format, &flags);
382 expect(Ok, stat);
383 expect(0xdeadbeef, flags);
385 stat = GdipDeleteStringFormat(format);
386 expect(Ok, stat);
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);
401 test_constructor();
402 test_characterrange();
403 test_digitsubstitution();
404 test_getgenerictypographic();
405 test_tabstops();
406 test_getgenericdefault();
407 test_stringformatflags();
409 GdiplusShutdown(gdiplusToken);