ReactOS  0.4.15-dev-1171-gab82533
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 
28 static void test_constructor(void)
29 {
31  GpStatus stat;
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 
60 static void test_characterrange(void)
61 {
62  CharacterRange ranges[3];
63  INT count;
65  GpStatus stat;
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 
86 static void test_digitsubstitution(void)
87 {
89  GpStatus stat;
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 
141 static void test_getgenerictypographic(void)
142 {
143  GpStringFormat *format, *format2;
144  GpStatus stat;
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 
168  GdipGetStringFormatLineAlign(format, &line_align);
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 
206 static REAL tabstops[] = {0.0, 10.0, 2.0};
207 static void test_tabstops(void)
208 {
210  GpStatus stat;
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);
241  stat = GdipGetStringFormatTabStops(format, 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 
311 static void test_getgenericdefault(void)
312 {
313  GpStringFormat *format, *format2;
314  GpStatus stat;
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 
339  GdipGetStringFormatLineAlign(format, &line_align);
342  GdipGetStringFormatDigitSubstitution(format, &digitlang, &digitsub);
344 
345  expect(0, flags);
348  expect(StringAlignmentNear, line_align);
349  expect(StringTrimmingCharacter, trimming);
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 
376 static void test_stringformatflags(void)
377 {
379  GpStatus stat;
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 
437 START_TEST(stringformat)
438 {
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 
455 
460  test_tabstops();
463 
465 }
GpStatus WINGDIPAPI GdipGetStringFormatFlags(GDIPCONST GpStringFormat *format, INT *flags)
Definition: stringformat.c:153
static void test_characterrange(void)
Definition: stringformat.c:60
GpStatus WINGDIPAPI GdipStringFormatGetGenericTypographic(GpStringFormat **format)
Definition: stringformat.c:408
GpStatus WINGDIPAPI GdipSetStringFormatMeasurableCharacterRanges(GpStringFormat *format, INT rangeCount, GDIPCONST CharacterRange *ranges)
Definition: stringformat.c:290
#define SUBLANG_CHINESE_TRADITIONAL
Definition: nls.h:208
static void test_digitsubstitution(void)
Definition: stringformat.c:86
#define LANG_NEUTRAL
Definition: nls.h:22
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLdouble n
Definition: glext.h:7729
GpStatus WINGDIPAPI GdipStringFormatGetGenericDefault(GpStringFormat **format)
Definition: stringformat.c:120
GpStatus WINGDIPAPI GdipGetStringFormatTabStops(GDIPCONST GpStringFormat *format, INT count, REAL *firsttab, REAL *tabs)
Definition: stringformat.c:210
GpStatus WINGDIPAPI GdipGetStringFormatDigitSubstitution(GDIPCONST GpStringFormat *format, LANGID *language, StringDigitSubstitute *substitute)
Definition: stringformat.c:141
WORD LANGID
Definition: typedefs.h:81
int align(int length, int align)
Definition: dsound8.c:36
int32_t INT
Definition: typedefs.h:58
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
StringAlignment
Definition: gdiplusenums.h:263
GpStatus WINGDIPAPI GdipGetStringFormatTabStopCount(GDIPCONST GpStringFormat *format, INT *count)
Definition: stringformat.c:199
uint32_t ULONG_PTR
Definition: typedefs.h:65
GpStatus WINGDIPAPI GdipGetStringFormatHotkeyPrefix(GDIPCONST GpStringFormat *format, INT *hkpx)
Definition: stringformat.c:164
GLenum GLint GLuint mask
Definition: glext.h:6028
static void test_constructor(void)
Definition: stringformat.c:28
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
smooth NULL
Definition: ftsmooth.c:416
GpStatus WINGDIPAPI GdipGetStringFormatMeasurableCharacterRangeCount(GDIPCONST GpStringFormat *format, INT *count)
Definition: stringformat.c:186
static void test_stringformatflags(void)
Definition: stringformat.c:376
GpStatus WINGDIPAPI GdipDeleteStringFormat(GpStringFormat *format)
Definition: stringformat.c:105
GpStatus WINGDIPAPI GdipGetStringFormatTrimming(GpStringFormat *format, StringTrimming *trimming)
Definition: stringformat.c:225
GpStatus WINGDIPAPI GdipSetStringFormatTabStops(GpStringFormat *format, REAL firsttab, INT count, GDIPCONST REAL *tabs)
Definition: stringformat.c:312
int CDECL _controlfp_s(unsigned int *cur, unsigned int newval, unsigned int mask)
Definition: cntrlfp.c:120
GpStatus WINGDIPAPI GdipGetStringFormatAlign(GpStringFormat *format, StringAlignment *align)
Definition: stringformat.c:130
GpStatus WINGDIPAPI GdipSetStringFormatFlags(GpStringFormat *format, INT flags)
Definition: stringformat.c:357
StringTrimming
Definition: gdiplusenums.h:291
void WINAPI GdiplusShutdown(ULONG_PTR)
static void test_getgenerictypographic(void)
Definition: stringformat.c:141
Status WINAPI GdiplusStartup(ULONG_PTR *token, const struct GdiplusStartupInput *input, struct GdiplusStartupOutput *output)
Definition: gdiplus.c:81
#define expectf(expected, got)
Definition: stringformat.c:26
#define LANG_RUSSIAN
Definition: nls.h:113
GLbitfield flags
Definition: glext.h:7161
Status
Definition: gdiplustypes.h:24
static REAL tabstops[]
Definition: stringformat.c:206
Definition: stat.h:55
#define expect(expected, got)
Definition: stringformat.c:25
_CRTIMP int __cdecl stat(const char *_Filename, struct stat *_Stat)
Definition: stat.h:345
Gdiplus::GdiplusStartupInput gdiplusStartupInput
Definition: winmain.cpp:38
ULONG_PTR gdiplusToken
Definition: winmain.cpp:39
#define CDECL
Definition: compat.h:29
#define ok(value,...)
Definition: atltest.h:57
StringDigitSubstitute
Definition: gdiplusenums.h:270
GpStatus WINGDIPAPI GdipGetStringFormatLineAlign(GpStringFormat *format, StringAlignment *align)
Definition: stringformat.c:175
#define LANG_CHINESE
Definition: nls.h:42
START_TEST(stringformat)
Definition: stringformat.c:437
#define MAKELANGID(p, s)
Definition: nls.h:15
#define GetProcAddress(x, y)
Definition: compat.h:501
static void test_tabstops(void)
Definition: stringformat.c:207
float REAL
Definition: types.h:41
static void test_getgenericdefault(void)
Definition: stringformat.c:311
GpStatus WINGDIPAPI GdipSetStringFormatDigitSubstitution(GpStringFormat *format, LANGID language, StringDigitSubstitute substitute)
Definition: stringformat.c:250
GpStatus WINGDIPAPI GdipCreateStringFormat(INT attr, LANGID lang, GpStringFormat **format)
Definition: stringformat.c:76
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31