gdiplus: Fix rectangles of horizontal and vertical gradients.
[wine] / dlls / gdiplus / tests / stringformat.c
1 /*
2  * Unit test suite for string format
3  *
4  * Copyright (C) 2007 Google (Evan Stade)
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "windows.h"
22 #include "gdiplus.h"
23 #include "wine/test.h"
24
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)
27
28 static void test_constructor(void)
29 {
30     GpStringFormat *format;
31     GpStatus stat;
32     INT n;
33     StringAlignment align, valign;
34     StringTrimming trimming;
35     StringDigitSubstitute digitsub;
36     LANGID digitlang;
37
38     stat = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
39     expect(Ok, stat);
40
41     GdipGetStringFormatAlign(format, &align);
42     GdipGetStringFormatLineAlign(format, &valign);
43     GdipGetStringFormatHotkeyPrefix(format, &n);
44     GdipGetStringFormatTrimming(format, &trimming);
45     GdipGetStringFormatDigitSubstitution(format, &digitlang, &digitsub);
46
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);
53
54     stat = GdipDeleteStringFormat(format);
55     expect(Ok, stat);
56 }
57
58 static void test_characterrange(void)
59 {
60     CharacterRange ranges[3];
61     INT count;
62     GpStringFormat* format;
63     GpStatus stat;
64
65     stat = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
66     expect(Ok, stat);
67 todo_wine
68 {
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);
74 }
75     stat= GdipDeleteStringFormat(format);
76     expect(Ok, stat);
77 }
78
79 static void test_digitsubstitution(void)
80 {
81     GpStringFormat *format;
82     GpStatus stat;
83     StringDigitSubstitute digitsub;
84     LANGID digitlang;
85
86     stat = GdipCreateStringFormat(0, LANG_RUSSIAN, &format);
87     expect(Ok, stat);
88
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);
102
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);
108
109     digitsub  = StringDigitSubstituteNone;
110     stat = GdipGetStringFormatDigitSubstitution(format, NULL, &digitsub);
111     expect(Ok, stat);
112     expect(StringDigitSubstituteUser, digitsub);
113
114     digitlang = LANG_RUSSIAN;
115     stat = GdipGetStringFormatDigitSubstitution(format, &digitlang, NULL);
116     expect(Ok, stat);
117     expect(LANG_NEUTRAL, digitlang);
118
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);
129
130     stat = GdipDeleteStringFormat(format);
131     expect(Ok, stat);
132 }
133
134 static void test_getgenerictypographic(void)
135 {
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;
145
146     /* NULL arg */
147     stat = GdipStringFormatGetGenericTypographic(NULL);
148     expect(InvalidParameter, stat);
149
150     stat = GdipStringFormatGetGenericTypographic(&format);
151     expect(Ok, stat);
152
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);
160
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);
170
171     stat = GdipDeleteStringFormat(format);
172     expect(Ok, stat);
173 }
174
175 static REAL tabstops[] = {0.0, 10.0, 2.0};
176 static void test_tabstops(void)
177 {
178     GpStringFormat *format;
179     GpStatus stat;
180     INT count;
181     REAL tabs[3];
182     REAL firsttab;
183
184     stat = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
185     expect(Ok, stat);
186
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);
194
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);
201
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);
214
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);
226
227     stat = GdipSetStringFormatTabStops(format, -10.0, 0, tabstops);
228     expect(Ok, stat);
229     stat = GdipSetStringFormatTabStops(format, -10.0, 1, tabstops);
230     expect(NotImplemented, stat);
231
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);
240
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);
247
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);
256
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);
267
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);
275
276     stat = GdipDeleteStringFormat(format);
277     expect(Ok, stat);
278 }
279
280 static void test_getgenericdefault(void)
281 {
282     GpStringFormat *format;
283     GpStatus stat;
284
285     INT flags;
286     INT n;
287     StringAlignment align, valign;
288     StringTrimming trimming;
289     StringDigitSubstitute digitsub;
290     LANGID digitlang;
291     INT tabcount;
292
293     /* NULL arg */
294     stat = GdipStringFormatGetGenericDefault(NULL);
295     expect(InvalidParameter, stat);
296
297     stat = GdipStringFormatGetGenericDefault(&format);
298     expect(Ok, stat);
299
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);
307
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);
316
317     stat = GdipDeleteStringFormat(format);
318     expect(Ok, stat);
319 }
320
321 static void test_stringformatflags(void)
322 {
323     GpStringFormat *format;
324     GpStatus stat;
325
326     INT flags;
327
328     stat = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
329     expect(Ok, stat);
330
331     /* NULL args */
332     stat = GdipSetStringFormatFlags(NULL, 0);
333     expect(InvalidParameter, stat);
334
335     stat = GdipSetStringFormatFlags(format, 0);
336     expect(Ok, stat);
337     stat = GdipGetStringFormatFlags(format, &flags);
338     expect(Ok, stat);
339     expect(0, flags);
340
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);
347
348     stat = GdipSetStringFormatFlags(format, StringFormatFlagsNoFontFallback);
349     expect(Ok, stat);
350     stat = GdipGetStringFormatFlags(format, &flags);
351     expect(Ok, stat);
352     expect(StringFormatFlagsNoFontFallback, flags);
353
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);
362
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);
370
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);
377
378     stat = GdipDeleteStringFormat(format);
379     expect(Ok, stat);
380 }
381
382 START_TEST(stringformat)
383 {
384     struct GdiplusStartupInput gdiplusStartupInput;
385     ULONG_PTR gdiplusToken;
386
387     gdiplusStartupInput.GdiplusVersion              = 1;
388     gdiplusStartupInput.DebugEventCallback          = NULL;
389     gdiplusStartupInput.SuppressBackgroundThread    = 0;
390     gdiplusStartupInput.SuppressExternalCodecs      = 0;
391
392     GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
393
394     test_constructor();
395     test_characterrange();
396     test_digitsubstitution();
397     test_getgenerictypographic();
398     test_tabstops();
399     test_getgenericdefault();
400     test_stringformatflags();
401
402     GdiplusShutdown(gdiplusToken);
403 }