ReactOS 0.4.16-dev-92-g0c2cdca
stringformat.c
Go to the documentation of this file.
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 "objbase.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
28static void test_constructor(void)
29{
32 INT n, count;
33 StringAlignment align, line_align;
34 StringTrimming trimming;
35 StringDigitSubstitute digitsub;
36 LANGID digitlang;
37
39 expect(Ok, stat);
40
45 GdipGetStringFormatDigitSubstitution(format, &digitlang, &digitsub);
47
50 expect(StringAlignmentNear, line_align);
53 expect(LANG_NEUTRAL, digitlang);
54 expect(0, count);
55
57 expect(Ok, stat);
58}
59
60static void test_characterrange(void)
61{
62 CharacterRange ranges[3];
63 INT count;
66
68 expect(Ok, stat);
72 expect(Ok, stat);
75
77 expect(Ok, stat);
79 expect(Ok, stat);
80 if (stat == Ok) expect(3, count);
81
83 expect(Ok, stat);
84}
85
86static void test_digitsubstitution(void)
87{
90 StringDigitSubstitute digitsub;
91 LANGID digitlang;
92
94 expect(Ok, stat);
95
96 /* NULL arguments */
100 expect(Ok, stat);
105 stat = GdipGetStringFormatDigitSubstitution(NULL, &digitlang, &digitsub);
109
110 /* try to get both and one by one */
111 stat = GdipGetStringFormatDigitSubstitution(format, &digitlang, &digitsub);
112 expect(Ok, stat);
114 expect(LANG_NEUTRAL, digitlang);
115
116 digitsub = StringDigitSubstituteNone;
118 expect(Ok, stat);
120
121 digitlang = LANG_RUSSIAN;
123 expect(Ok, stat);
124 expect(LANG_NEUTRAL, digitlang);
125
126 /* set/get */
129 expect(Ok, stat);
130 digitsub = StringDigitSubstituteNone;
131 digitlang = LANG_RUSSIAN;
132 stat = GdipGetStringFormatDigitSubstitution(format, &digitlang, &digitsub);
133 expect(Ok, stat);
136
138 expect(Ok, stat);
139}
140
142{
143 GpStringFormat *format, *format2;
145 INT flags;
146 INT n;
147 StringAlignment align, line_align;
148 StringTrimming trimming;
149 StringDigitSubstitute digitsub;
150 LANGID digitlang;
151 INT tabcount;
152
153 /* NULL arg */
156
158 expect(Ok, stat);
159
161 expect(Ok, stat);
162 ok(format == format2, "expected same format object\n");
163 stat = GdipDeleteStringFormat(format2);
164 expect(Ok, stat);
165
171 GdipGetStringFormatDigitSubstitution(format, &digitlang, &digitsub);
173
175 flags);
178 expect(StringAlignmentNear, line_align);
179 expect(StringTrimmingNone, trimming);
181 expect(LANG_NEUTRAL, digitlang);
182 expect(0, tabcount);
183
184 /* Change format parameters, release, get format object again. */
186 expect(Ok, stat);
187
189 expect(Ok, stat);
191
193 expect(Ok, stat);
194
196 expect(Ok, stat);
197
199 expect(Ok, stat);
201
203 expect(Ok, stat);
204}
205
206static REAL tabstops[] = {0.0, 10.0, 2.0};
207static void test_tabstops(void)
208{
211 INT count;
212 REAL tabs[3];
213 REAL firsttab;
214
216 expect(Ok, stat);
217
218 /* NULL */
225
232
237 stat = GdipGetStringFormatTabStops(NULL, 0, &firsttab, NULL);
245
246 /* not NULL */
248 expect(Ok, stat);
249 expect(0, count);
250 /* negative tabcount */
252 expect(Ok, stat);
253 count = -1;
255 expect(Ok, stat);
256 expect(0, count);
257
259 expect(Ok, stat);
262
263 firsttab = -1.0;
264 tabs[0] = tabs[1] = tabs[2] = -1.0;
265 stat = GdipGetStringFormatTabStops(format, 0, &firsttab, tabs);
266 expect(Ok, stat);
267 expectf(-1.0, tabs[0]);
268 expectf(-1.0, tabs[1]);
269 expectf(-1.0, tabs[2]);
270 expectf(0.0, firsttab);
271
273 expect(Ok, stat);
274 count = 0;
276 expect(Ok, stat);
277 expect(3, count);
278
279 firsttab = -1.0;
280 tabs[0] = tabs[1] = tabs[2] = -1.0;
281 stat = GdipGetStringFormatTabStops(format, 3, &firsttab, tabs);
282 expect(Ok, stat);
283 expectf(0.0, tabs[0]);
284 expectf(10.0, tabs[1]);
285 expectf(2.0, tabs[2]);
286 expectf(0.0, firsttab);
287
289 expect(Ok, stat);
290 firsttab = -1.0;
291 tabs[0] = tabs[1] = tabs[2] = -1.0;
292 stat = GdipGetStringFormatTabStops(format, 0, &firsttab, tabs);
293 expect(Ok, stat);
294 expectf(-1.0, tabs[0]);
295 expectf(-1.0, tabs[1]);
296 expectf(-1.0, tabs[2]);
297 expectf(10.0, firsttab);
298
299 /* zero tabcount, after valid setting to 3 */
301 expect(Ok, stat);
302 count = 0;
304 expect(Ok, stat);
305 expect(3, count);
306
308 expect(Ok, stat);
309}
310
311static void test_getgenericdefault(void)
312{
313 GpStringFormat *format, *format2;
315
316 INT flags;
317 INT n;
318 StringAlignment align, line_align;
319 StringTrimming trimming;
320 StringDigitSubstitute digitsub;
321 LANGID digitlang;
322 INT tabcount;
323
324 /* NULL arg */
327
329 expect(Ok, stat);
330
332 expect(Ok, stat);
333 ok(format == format2, "expected same format object\n");
334 stat = GdipDeleteStringFormat(format2);
335 expect(Ok, stat);
336
342 GdipGetStringFormatDigitSubstitution(format, &digitlang, &digitsub);
344
345 expect(0, flags);
348 expect(StringAlignmentNear, line_align);
351 expect(LANG_NEUTRAL, digitlang);
352 expect(0, tabcount);
353
354 /* Change default format parameters, release, get format object again. */
356 expect(Ok, stat);
357
359 expect(Ok, stat);
361
363 expect(Ok, stat);
364
366 expect(Ok, stat);
367
369 expect(Ok, stat);
371
373 expect(Ok, stat);
374}
375
376static void test_stringformatflags(void)
377{
380
381 INT flags;
382
384 expect(Ok, stat);
385
386 /* NULL args */
389
391 expect(Ok, stat);
393 expect(Ok, stat);
394 expect(0, flags);
395
396 /* Check some valid flags */
398 expect(Ok, stat);
400 expect(Ok, stat);
402
404 expect(Ok, stat);
406 expect(Ok, stat);
408
409 /* Check some flag combinations */
412 expect(Ok, stat);
414 expect(Ok, stat);
417
420 expect(Ok, stat);
422 expect(Ok, stat);
425
426 /* Check invalid flags */
427 stat = GdipSetStringFormatFlags(format, 0xdeadbeef);
428 expect(Ok, stat);
430 expect(Ok, stat);
431 expect(0xdeadbeef, flags);
432
434 expect(Ok, stat);
435}
436
437START_TEST(stringformat)
438{
439 struct GdiplusStartupInput gdiplusStartupInput;
440 ULONG_PTR gdiplusToken;
441 HMODULE hmsvcrt;
442 int (CDECL * _controlfp_s)(unsigned int *cur, unsigned int newval, unsigned int mask);
443
444 /* Enable all FP exceptions except _EM_INEXACT, which gdi32 can trigger */
445 hmsvcrt = LoadLibraryA("msvcrt");
446 _controlfp_s = (void*)GetProcAddress(hmsvcrt, "_controlfp_s");
447 if (_controlfp_s) _controlfp_s(0, 0, 0x0008001e);
448
449 gdiplusStartupInput.GdiplusVersion = 1;
450 gdiplusStartupInput.DebugEventCallback = NULL;
451 gdiplusStartupInput.SuppressBackgroundThread = 0;
452 gdiplusStartupInput.SuppressExternalCodecs = 0;
453
454 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
455
463
464 GdiplusShutdown(gdiplusToken);
465}
int CDECL _controlfp_s(unsigned int *cur, unsigned int newval, unsigned int mask)
Definition: _controlfp_s.c:19
#define stat
Definition: acwin.h:99
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define NULL
Definition: types.h:112
float REAL
Definition: types.h:41
#define CDECL
Definition: compat.h:29
#define GetProcAddress(x, y)
Definition: compat.h:753
GpStatus WINGDIPAPI GdipGetStringFormatTabStops(GDIPCONST GpStringFormat *format, INT count, REAL *firsttab, REAL *tabs)
Definition: stringformat.c:210
GpStatus WINGDIPAPI GdipStringFormatGetGenericDefault(GpStringFormat **format)
Definition: stringformat.c:120
GpStatus WINGDIPAPI GdipGetStringFormatHotkeyPrefix(GDIPCONST GpStringFormat *format, INT *hkpx)
Definition: stringformat.c:164
GpStatus WINGDIPAPI GdipGetStringFormatDigitSubstitution(GDIPCONST GpStringFormat *format, LANGID *language, StringDigitSubstitute *substitute)
Definition: stringformat.c:141
GpStatus WINGDIPAPI GdipCreateStringFormat(INT attr, LANGID lang, GpStringFormat **format)
Definition: stringformat.c:76
GpStatus WINGDIPAPI GdipSetStringFormatMeasurableCharacterRanges(GpStringFormat *format, INT rangeCount, GDIPCONST CharacterRange *ranges)
Definition: stringformat.c:290
GpStatus WINGDIPAPI GdipGetStringFormatAlign(GpStringFormat *format, StringAlignment *align)
Definition: stringformat.c:130
GpStatus WINGDIPAPI GdipGetStringFormatMeasurableCharacterRangeCount(GDIPCONST GpStringFormat *format, INT *count)
Definition: stringformat.c:186
GpStatus WINGDIPAPI GdipStringFormatGetGenericTypographic(GpStringFormat **format)
Definition: stringformat.c:408
GpStatus WINGDIPAPI GdipSetStringFormatTabStops(GpStringFormat *format, REAL firsttab, INT count, GDIPCONST REAL *tabs)
Definition: stringformat.c:312
GpStatus WINGDIPAPI GdipGetStringFormatTabStopCount(GDIPCONST GpStringFormat *format, INT *count)
Definition: stringformat.c:199
GpStatus WINGDIPAPI GdipGetStringFormatLineAlign(GpStringFormat *format, StringAlignment *align)
Definition: stringformat.c:175
GpStatus WINGDIPAPI GdipGetStringFormatFlags(GDIPCONST GpStringFormat *format, INT *flags)
Definition: stringformat.c:153
GpStatus WINGDIPAPI GdipGetStringFormatTrimming(GpStringFormat *format, StringTrimming *trimming)
Definition: stringformat.c:225
GpStatus WINGDIPAPI GdipSetStringFormatDigitSubstitution(GpStringFormat *format, LANGID language, StringDigitSubstitute substitute)
Definition: stringformat.c:250
GpStatus WINGDIPAPI GdipSetStringFormatFlags(GpStringFormat *format, INT flags)
Definition: stringformat.c:357
GpStatus WINGDIPAPI GdipDeleteStringFormat(GpStringFormat *format)
Definition: stringformat.c:105
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
int align(int length, int align)
Definition: dsound8.c:36
FxCollectionEntry * cur
Status WINAPI GdiplusStartup(ULONG_PTR *token, const struct GdiplusStartupInput *input, struct GdiplusStartupOutput *output)
Definition: gdiplus.c:81
StringTrimming
Definition: gdiplusenums.h:292
@ StringTrimmingNone
Definition: gdiplusenums.h:293
@ StringTrimmingCharacter
Definition: gdiplusenums.h:294
StringAlignment
Definition: gdiplusenums.h:264
@ StringAlignmentNear
Definition: gdiplusenums.h:265
StringDigitSubstitute
Definition: gdiplusenums.h:271
@ StringDigitSubstituteNone
Definition: gdiplusenums.h:273
@ StringDigitSubstituteUser
Definition: gdiplusenums.h:272
@ HotkeyPrefixNone
Definition: gdiplusenums.h:313
@ StringFormatFlagsLineLimit
Definition: gdiplusenums.h:287
@ StringFormatFlagsDirectionVertical
Definition: gdiplusenums.h:281
@ StringFormatFlagsNoWrap
Definition: gdiplusenums.h:286
@ StringFormatFlagsNoClip
Definition: gdiplusenums.h:288
@ StringFormatFlagsDisplayFormatControl
Definition: gdiplusenums.h:283
@ StringFormatFlagsDirectionRightToLeft
Definition: gdiplusenums.h:280
@ StringFormatFlagsMeasureTrailingSpaces
Definition: gdiplusenums.h:285
@ StringFormatFlagsNoFitBlackBox
Definition: gdiplusenums.h:282
@ StringFormatFlagsNoFontFallback
Definition: gdiplusenums.h:284
void WINAPI GdiplusShutdown(ULONG_PTR)
Status
Definition: gdiplustypes.h:25
@ Ok
Definition: gdiplustypes.h:26
@ InvalidParameter
Definition: gdiplustypes.h:28
@ NotImplemented
Definition: gdiplustypes.h:32
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLdouble n
Definition: glext.h:7729
GLenum GLint GLuint mask
Definition: glext.h:6028
GLbitfield flags
Definition: glext.h:7161
USHORT LANGID
Definition: mui.h:9
static void test_tabstops(void)
Definition: stringformat.c:207
static void test_getgenericdefault(void)
Definition: stringformat.c:311
static void test_stringformatflags(void)
Definition: stringformat.c:376
static void test_getgenerictypographic(void)
Definition: stringformat.c:141
#define expect(expected, got)
Definition: stringformat.c:25
static REAL tabstops[]
Definition: stringformat.c:206
#define expectf(expected, got)
Definition: stringformat.c:26
static void test_digitsubstitution(void)
Definition: stringformat.c:86
static void test_constructor(void)
Definition: stringformat.c:28
static void test_characterrange(void)
Definition: stringformat.c:60
#define LANG_NEUTRAL
Definition: nls.h:22
#define MAKELANGID(p, s)
Definition: nls.h:15
#define SUBLANG_CHINESE_TRADITIONAL
Definition: nls.h:208
#define LANG_RUSSIAN
Definition: nls.h:113
#define LANG_CHINESE
Definition: nls.h:42
BOOL SuppressBackgroundThread
Definition: gdiplusinit.h:36
DebugEventProc DebugEventCallback
Definition: gdiplusinit.h:35
Definition: format.c:58
Definition: stat.h:55
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG_PTR
Definition: typedefs.h:65