ReactOS  0.4.14-dev-583-g2a1ba2c
printf.c File Reference
#include <stdio.h>
#include <errno.h>
#include <math.h>
#include <locale.h>
#include "windef.h"
#include "winbase.h"
#include "winnls.h"
#include "wine/test.h"
Include dependency graph for printf.c:

Go to the source code of this file.

Macros

#define _CRT_NON_CONFORMING_SWPRINTFS
 
#define INFINITY   __port_infinity()
 
#define NAN   __port_nan()
 
#define IND   __port_ind()
 

Functions

static float __port_infinity (void)
 
static float __port_nan (void)
 
static float __port_ind (void)
 
static int (__cdecl *p__vscprintf)(const char *format
 
static int (WINAPIV *p_sprintf)(char *
 
static void init (void)
 
static void test_sprintf (void)
 
static void test_swprintf (void)
 
static void test_snprintf (void)
 
static void test_fprintf (void)
 
static void test_fcvt (void)
 
static void test_xcvt (void)
 
static int WINAPIV _vsnwprintf_wrapper (wchar_t *str, size_t len, const wchar_t *format,...)
 
static void test_vsnwprintf (void)
 
static int WINAPIV vswprintf_wrapper (wchar_t *str, const wchar_t *format,...)
 
static int WINAPIV _vswprintf_wrapper (wchar_t *str, const wchar_t *format,...)
 
static int WINAPIV _vswprintf_l_wrapper (wchar_t *str, const wchar_t *format, void *locale,...)
 
static int WINAPIV _vswprintf_c_wrapper (wchar_t *str, size_t size, const wchar_t *format,...)
 
static int WINAPIV _vswprintf_c_l_wrapper (wchar_t *str, size_t size, const wchar_t *format, void *locale,...)
 
static int WINAPIV _vswprintf_p_l_wrapper (wchar_t *str, size_t size, const wchar_t *format, void *locale,...)
 
static void test_vswprintf (void)
 
static int WINAPIV _vscprintf_wrapper (const char *format,...)
 
static void test_vscprintf (void)
 
static int WINAPIV _vscwprintf_wrapper (const wchar_t *format,...)
 
static void test_vscwprintf (void)
 
static int WINAPIV _vsnwprintf_s_wrapper (wchar_t *str, size_t sizeOfBuffer, size_t count, const wchar_t *format,...)
 
static void test_vsnwprintf_s (void)
 
static int WINAPIV _vsprintf_p_wrapper (char *str, size_t sizeOfBuffer, const char *format,...)
 
static void test_vsprintf_p (void)
 
static void test__get_output_format (void)
 
 START_TEST (printf)
 

Variables

static __ms_va_list valist
 
static size_t sizeOfBuffer
 
static size_t size_t count
 
static size_t size_t const wchar_tformat
 
static size_t length
 
static size_t double number
 
static size_t double int ndigits
 
static size_t double int intdecpt
 
static size_t double int int intsign
 
static static size_t
 
static static const char __ms_va_list
 
static const wchar_t voidlocale
 
static size_t size
 
struct {
   double   value
 
   int   nrdigits
 
   const char *   expstr_e
 
   const char *   expstr_f
 
   int   expdecpt_e
 
   int   expdecpt_f
 
   int   expsign
 
test_cvt_testcases []
 

Macro Definition Documentation

◆ _CRT_NON_CONFORMING_SWPRINTFS

#define _CRT_NON_CONFORMING_SWPRINTFS

Definition at line 26 of file printf.c.

◆ IND

#define IND   __port_ind()

Definition at line 62 of file printf.c.

◆ INFINITY

#define INFINITY   __port_infinity()

Definition at line 46 of file printf.c.

◆ NAN

#define NAN   __port_nan()

Definition at line 53 of file printf.c.

Function Documentation

◆ __port_ind()

static float __port_ind ( void  )
inlinestatic

Definition at line 57 of file printf.c.

58 {
59  static const unsigned __ind_bytes = 0xffc00000;
60  return *(const float *)&__ind_bytes;
61 }

◆ __port_infinity()

static float __port_infinity ( void  )
inlinestatic

Definition at line 41 of file printf.c.

42 {
43  static const unsigned __inf_bytes = 0x7f800000;
44  return *(const float *)&__inf_bytes;
45 }

◆ __port_nan()

static float __port_nan ( void  )
inlinestatic

Definition at line 48 of file printf.c.

49 {
50  static const unsigned __nan_bytes = 0x7fc00000;
51  return *(const float *)&__nan_bytes;
52 }

◆ _vscprintf_wrapper()

static int WINAPIV _vscprintf_wrapper ( const char format,
  ... 
)
static

Definition at line 1361 of file printf.c.

1362 {
1363  int ret;
1366  ret = p__vscprintf(format, valist);
1368  return ret;
1369 }
static static const char __ms_va_list
Definition: printf.c:76
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
int ret
#define __ms_va_end(list)
Definition: windef.h:458
#define __ms_va_start(list, arg)
Definition: windef.h:457
static __ms_va_list valist
Definition: printf.c:64

Referenced by test_vscprintf().

◆ _vscwprintf_wrapper()

static int WINAPIV _vscwprintf_wrapper ( const wchar_t format,
  ... 
)
static

Definition at line 1385 of file printf.c.

1386 {
1387  int ret;
1390  ret = p__vscwprintf(format, valist);
1392  return ret;
1393 }
static static const char __ms_va_list
Definition: printf.c:76
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
int ret
#define __ms_va_end(list)
Definition: windef.h:458
#define __ms_va_start(list, arg)
Definition: windef.h:457
static __ms_va_list valist
Definition: printf.c:64

Referenced by test_vscwprintf().

◆ _vsnwprintf_s_wrapper()

static int WINAPIV _vsnwprintf_s_wrapper ( wchar_t str,
size_t  sizeOfBuffer,
size_t  count,
const wchar_t format,
  ... 
)
static

Definition at line 1412 of file printf.c.

1414 {
1415  int ret;
1418  ret = p__vsnwprintf_s(str, sizeOfBuffer, count, format, valist);
1420  return ret;
1421 }
static static const char __ms_va_list
Definition: printf.c:76
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
const WCHAR * str
int ret
#define __ms_va_end(list)
Definition: windef.h:458
#define __ms_va_start(list, arg)
Definition: windef.h:457
static __ms_va_list valist
Definition: printf.c:64
static size_t sizeOfBuffer
Definition: printf.c:66

Referenced by test_vsnwprintf_s().

◆ _vsnwprintf_wrapper()

static int WINAPIV _vsnwprintf_wrapper ( wchar_t str,
size_t  len,
const wchar_t format,
  ... 
)
static

Definition at line 1221 of file printf.c.

1222 {
1223  int ret;
1228  return ret;
1229 }
static static const char __ms_va_list
Definition: printf.c:76
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
const WCHAR * str
int ret
GLenum GLsizei len
Definition: glext.h:6722
_CRTIMP int __cdecl _vsnwprintf(wchar_t *_Dest, size_t _Count, const wchar_t *_Format, va_list _Args)
#define __ms_va_end(list)
Definition: windef.h:458
#define __ms_va_start(list, arg)
Definition: windef.h:457
static __ms_va_list valist
Definition: printf.c:64

Referenced by test_vsnwprintf().

◆ _vsprintf_p_wrapper()

static int WINAPIV _vsprintf_p_wrapper ( char str,
size_t  sizeOfBuffer,
const char format,
  ... 
)
static

Definition at line 1470 of file printf.c.

1472 {
1473  int ret;
1476  ret = p__vsprintf_p(str, sizeOfBuffer, format, valist);
1478  return ret;
1479 }
static static const char __ms_va_list
Definition: printf.c:76
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
const WCHAR * str
int ret
#define __ms_va_end(list)
Definition: windef.h:458
#define __ms_va_start(list, arg)
Definition: windef.h:457
static __ms_va_list valist
Definition: printf.c:64
static size_t sizeOfBuffer
Definition: printf.c:66

Referenced by test_vsprintf_p().

◆ _vswprintf_c_l_wrapper()

static int WINAPIV _vswprintf_c_l_wrapper ( wchar_t str,
size_t  size,
const wchar_t format,
void locale,
  ... 
)
static

Definition at line 1295 of file printf.c.

1296 {
1297  int ret;
1300  ret = p__vswprintf_c_l(str, size, format, locale, valist);
1302  return ret;
1303 }
static static const char __ms_va_list
Definition: printf.c:76
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
Definition: _locale.h:75
const WCHAR * str
GLsizeiptr size
Definition: glext.h:5919
int ret
#define __ms_va_end(list)
Definition: windef.h:458
#define __ms_va_start(list, arg)
Definition: windef.h:457
static __ms_va_list valist
Definition: printf.c:64

Referenced by test_vswprintf().

◆ _vswprintf_c_wrapper()

static int WINAPIV _vswprintf_c_wrapper ( wchar_t str,
size_t  size,
const wchar_t format,
  ... 
)
static

Definition at line 1285 of file printf.c.

1286 {
1287  int ret;
1290  ret = p__vswprintf_c(str, size, format, valist);
1292  return ret;
1293 }
static static const char __ms_va_list
Definition: printf.c:76
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
const WCHAR * str
GLsizeiptr size
Definition: glext.h:5919
int ret
#define __ms_va_end(list)
Definition: windef.h:458
#define __ms_va_start(list, arg)
Definition: windef.h:457
static __ms_va_list valist
Definition: printf.c:64

Referenced by test_vswprintf().

◆ _vswprintf_l_wrapper()

static int WINAPIV _vswprintf_l_wrapper ( wchar_t str,
const wchar_t format,
void locale,
  ... 
)
static

Definition at line 1275 of file printf.c.

1276 {
1277  int ret;
1280  ret = p__vswprintf_l(str, format, locale, valist);
1282  return ret;
1283 }
static static const char __ms_va_list
Definition: printf.c:76
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
Definition: _locale.h:75
const WCHAR * str
int ret
#define __ms_va_end(list)
Definition: windef.h:458
#define __ms_va_start(list, arg)
Definition: windef.h:457
static __ms_va_list valist
Definition: printf.c:64

Referenced by test_vswprintf().

◆ _vswprintf_p_l_wrapper()

static int WINAPIV _vswprintf_p_l_wrapper ( wchar_t str,
size_t  size,
const wchar_t format,
void locale,
  ... 
)
static

Definition at line 1305 of file printf.c.

1306 {
1307  int ret;
1310  ret = p__vswprintf_p_l(str, size, format, locale, valist);
1312  return ret;
1313 }
static static const char __ms_va_list
Definition: printf.c:76
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
Definition: _locale.h:75
const WCHAR * str
GLsizeiptr size
Definition: glext.h:5919
int ret
#define __ms_va_end(list)
Definition: windef.h:458
#define __ms_va_start(list, arg)
Definition: windef.h:457
static __ms_va_list valist
Definition: printf.c:64

Referenced by test_vswprintf().

◆ _vswprintf_wrapper()

static int WINAPIV _vswprintf_wrapper ( wchar_t str,
const wchar_t format,
  ... 
)
static

Definition at line 1265 of file printf.c.

1266 {
1267  int ret;
1270  ret = p__vswprintf(str, format, valist);
1272  return ret;
1273 }
static static const char __ms_va_list
Definition: printf.c:76
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
const WCHAR * str
int ret
#define __ms_va_end(list)
Definition: windef.h:458
#define __ms_va_start(list, arg)
Definition: windef.h:457
static __ms_va_list valist
Definition: printf.c:64

Referenced by test_vswprintf().

◆ init()

static void init ( void  )
static

Definition at line 88 of file printf.c.

89 {
90  HMODULE hmod = GetModuleHandleA("msvcrt.dll");
91 
92  p_sprintf = (void *)GetProcAddress(hmod, "sprintf");
93  p__vscprintf = (void *)GetProcAddress(hmod, "_vscprintf");
94  p__vscwprintf = (void *)GetProcAddress(hmod, "_vscwprintf");
95  p__vsnwprintf_s = (void *)GetProcAddress(hmod, "_vsnwprintf_s");
96  p__ecvt_s = (void *)GetProcAddress(hmod, "_ecvt_s");
97  p__fcvt_s = (void *)GetProcAddress(hmod, "_fcvt_s");
98  p__get_output_format = (void *)GetProcAddress(hmod, "_get_output_format");
99  p__set_output_format = (void *)GetProcAddress(hmod, "_set_output_format");
100  p__vsprintf_p = (void*)GetProcAddress(hmod, "_vsprintf_p");
101  p_vswprintf = (void*)GetProcAddress(hmod, "vswprintf");
102  p__vswprintf = (void*)GetProcAddress(hmod, "_vswprintf");
103  p__vswprintf_l = (void*)GetProcAddress(hmod, "_vswprintf_l");
104  p__vswprintf_c = (void*)GetProcAddress(hmod, "_vswprintf_c");
105  p__vswprintf_c_l = (void*)GetProcAddress(hmod, "_vswprintf_c_l");
106  p__vswprintf_p_l = (void*)GetProcAddress(hmod, "_vswprintf_p_l");
107 }
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:821
static PEXPLICIT_ACCESSW *static HMODULE hmod
Definition: security.c:141
#define GetProcAddress(x, y)
Definition: compat.h:418

Referenced by START_TEST().

◆ int() [1/2]

static int ( __cdecl p__vscprintf) const
static

◆ int() [2/2]

static int ( WINAPIV p_sprintf)
static

◆ START_TEST()

START_TEST ( printf  )

Definition at line 1544 of file printf.c.

1545 {
1546  init();
1547 
1548  test_sprintf();
1549  test_swprintf();
1550  test_snprintf();
1551  test_fprintf();
1552  test_fcvt();
1553  test_xcvt();
1554  test_vsnwprintf();
1555  test_vscprintf();
1556  test_vscwprintf();
1557  test_vswprintf();
1559  test_vsprintf_p();
1561 }
static void test_xcvt(void)
Definition: printf.c:1115
static void test_vscprintf(void)
Definition: printf.c:1371
static void test_snprintf(void)
Definition: printf.c:853
static void test_sprintf(void)
Definition: printf.c:109
static void test_fcvt(void)
Definition: printf.c:968
static void test_fprintf(void)
Definition: printf.c:881
static void test__get_output_format(void)
Definition: printf.c:1511
static void test_vsprintf_p(void)
Definition: printf.c:1481
static void test_vswprintf(void)
Definition: printf.c:1315
static void test_vsnwprintf(void)
Definition: printf.c:1231
static void test_vscwprintf(void)
Definition: printf.c:1395
static void test_swprintf(void)
Definition: printf.c:831
static void test_vsnwprintf_s(void)
Definition: printf.c:1423
static void init(void)
Definition: printf.c:88

◆ test__get_output_format()

static void test__get_output_format ( void  )
static

Definition at line 1511 of file printf.c.

1512 {
1513  unsigned int ret;
1514  char buf[64];
1515  int c;
1516 
1517  if (!p__get_output_format || !p__set_output_format)
1518  {
1519  win_skip("_get_output_format or _set_output_format is not available\n");
1520  return;
1521  }
1522 
1523  ret = p__get_output_format();
1524  ok(ret == 0, "got %d\n", ret);
1525 
1526  c = p_sprintf(buf, "%E", 1.23);
1527  ok(c == 13, "c = %d\n", c);
1528  ok(!strcmp(buf, "1.230000E+000"), "buf = %s\n", buf);
1529 
1530  ret = p__set_output_format(_TWO_DIGIT_EXPONENT);
1531  ok(ret == 0, "got %d\n", ret);
1532 
1533  c = p_sprintf(buf, "%E", 1.23);
1534  ok(c == 12, "c = %d\n", c);
1535  ok(!strcmp(buf, "1.230000E+00"), "buf = %s\n", buf);
1536 
1537  ret = p__get_output_format();
1538  ok(ret == _TWO_DIGIT_EXPONENT, "got %d\n", ret);
1539 
1540  ret = p__set_output_format(_TWO_DIGIT_EXPONENT);
1541  ok(ret == _TWO_DIGIT_EXPONENT, "got %d\n", ret);
1542 }
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
const GLubyte * c
Definition: glext.h:8905
int ret
#define ok(value,...)
Definition: atltest.h:57
#define c
Definition: ke_i.h:80
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define win_skip
Definition: test.h:150
#define _TWO_DIGIT_EXPONENT
Definition: stdio.h:139

Referenced by START_TEST().

◆ test_fcvt()

static void test_fcvt ( void  )
static

Definition at line 968 of file printf.c.

969 {
970  char *str;
971  int dec=100, sign=100;
972 
973  /* Numbers less than 1.0 with different precisions */
974  str = _fcvt(0.0001, 1, &dec, &sign );
975  ok( 0 == strcmp(str,""), "bad return '%s'\n", str);
976  ok( -3 == dec, "dec wrong %d\n", dec);
977  ok( 0 == sign, "sign wrong\n");
978 
979  str = _fcvt(0.0001, -10, &dec, &sign );
980  ok( 0 == strcmp(str,""), "bad return '%s'\n", str);
981  ok( -3 == dec, "dec wrong %d\n", dec);
982  ok( 0 == sign, "sign wrong\n");
983 
984  str = _fcvt(0.0001, 10, &dec, &sign );
985  ok( 0 == strcmp(str,"1000000"), "bad return '%s'\n", str);
986  ok( -3 == dec, "dec wrong %d\n", dec);
987  ok( 0 == sign, "sign wrong\n");
988 
989  /* Basic sign test */
990  str = _fcvt(-111.0001, 5, &dec, &sign );
991  ok( 0 == strcmp(str,"11100010"), "bad return '%s'\n", str);
992  ok( 3 == dec, "dec wrong %d\n", dec);
993  ok( 1 == sign, "sign wrong\n");
994 
995  str = _fcvt(111.0001, 5, &dec, &sign );
996  ok( 0 == strcmp(str,"11100010"), "bad return '%s'\n", str);
997  ok( 3 == dec, "dec wrong\n");
998  ok( 0 == sign, "sign wrong\n");
999 
1000  /* 0.0 with different precisions */
1001  str = _fcvt(0.0, 5, &dec, &sign );
1002  ok( 0 == strcmp(str,"00000"), "bad return '%s'\n", str);
1003  ok( 0 == dec, "dec wrong %d\n", dec);
1004  ok( 0 == sign, "sign wrong\n");
1005 
1006  str = _fcvt(0.0, 0, &dec, &sign );
1007  ok( 0 == strcmp(str,""), "bad return '%s'\n", str);
1008  ok( 0 == dec, "dec wrong %d\n", dec);
1009  ok( 0 == sign, "sign wrong\n");
1010 
1011  str = _fcvt(0.0, -1, &dec, &sign );
1012  ok( 0 == strcmp(str,""), "bad return '%s'\n", str);
1013  ok( 0 == dec, "dec wrong %d\n", dec);
1014  ok( 0 == sign, "sign wrong\n");
1015 
1016  /* Numbers > 1.0 with 0 or -ve precision */
1017  str = _fcvt(-123.0001, 0, &dec, &sign );
1018  ok( 0 == strcmp(str,"123"), "bad return '%s'\n", str);
1019  ok( 3 == dec, "dec wrong %d\n", dec);
1020  ok( 1 == sign, "sign wrong\n");
1021 
1022  str = _fcvt(-123.0001, -1, &dec, &sign );
1023  ok( 0 == strcmp(str,"12"), "bad return '%s'\n", str);
1024  ok( 3 == dec, "dec wrong %d\n", dec);
1025  ok( 1 == sign, "sign wrong\n");
1026 
1027  str = _fcvt(-123.0001, -2, &dec, &sign );
1028  ok( 0 == strcmp(str,"1"), "bad return '%s'\n", str);
1029  ok( 3 == dec, "dec wrong %d\n", dec);
1030  ok( 1 == sign, "sign wrong\n");
1031 
1032  str = _fcvt(-123.0001, -3, &dec, &sign );
1033  ok( 0 == strcmp(str,""), "bad return '%s'\n", str);
1034  ok( 3 == dec, "dec wrong %d\n", dec);
1035  ok( 1 == sign, "sign wrong\n");
1036 
1037  /* Numbers > 1.0, but with rounding at the point of precision */
1038  str = _fcvt(99.99, 1, &dec, &sign );
1039  ok( 0 == strcmp(str,"1000"), "bad return '%s'\n", str);
1040  ok( 3 == dec, "dec wrong %d\n", dec);
1041  ok( 0 == sign, "sign wrong\n");
1042 
1043  /* Numbers < 1.0 where rounding occurs at the point of precision */
1044  str = _fcvt(0.00636, 2, &dec, &sign );
1045  ok( 0 == strcmp(str,"1"), "bad return '%s'\n", str);
1046  ok( -1 == dec, "dec wrong %d\n", dec);
1047  ok( 0 == sign, "sign wrong\n");
1048 
1049  str = _fcvt(0.00636, 3, &dec, &sign );
1050  ok( 0 == strcmp(str,"6"), "bad return '%s'\n", str);
1051  ok( -2 == dec, "dec wrong %d\n", dec);
1052  ok( 0 == sign, "sign wrong\n");
1053 
1054  str = _fcvt(0.09999999996, 2, &dec, &sign );
1055  ok( 0 == strcmp(str,"10"), "bad return '%s'\n", str);
1056  ok( 0 == dec, "dec wrong %d\n", dec);
1057  ok( 0 == sign, "sign wrong\n");
1058 
1059  str = _fcvt(0.6, 0, &dec, &sign );
1060  ok( 0 == strcmp(str,"1"), "bad return '%s'\n", str);
1061  ok( 1 == dec, "dec wrong %d\n", dec);
1062  ok( 0 == sign, "sign wrong\n");
1063 }
static size_t double int int int * sign
Definition: printf.c:69
ios_base &_STLP_CALL dec(ios_base &__s)
Definition: _ios_base.h:321
const WCHAR * str
_Check_return_ _CRTIMP char *__cdecl _fcvt(_In_ double _Val, _In_ int _NumOfDec, _Out_ int *_PtDec, _Out_ int *_PtSign)
#define ok(value,...)
Definition: atltest.h:57
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469

Referenced by START_TEST().

◆ test_fprintf()

static void test_fprintf ( void  )
static

Definition at line 881 of file printf.c.

882 {
883  static const char file_name[] = "fprintf.tst";
884  static const WCHAR utf16_test[] = {'u','n','i','c','o','d','e','\n',0};
885 
886  FILE *fp = fopen(file_name, "wb");
887  char buf[1024];
888  int ret;
889 
890  ret = fprintf(fp, "simple test\n");
891  ok(ret == 12, "ret = %d\n", ret);
892  ret = ftell(fp);
893  ok(ret == 12, "ftell returned %d\n", ret);
894 
895  ret = fprintf(fp, "contains%cnull\n", '\0');
896  ok(ret == 14, "ret = %d\n", ret);
897  ret = ftell(fp);
898  ok(ret == 26, "ftell returned %d\n", ret);
899 
900  ret = fwprintf(fp, utf16_test);
901  ok(ret == 8, "ret = %d\n", ret);
902  ret = ftell(fp);
903  ok(ret == 42, "ftell returned %d\n", ret);
904 
905  fclose(fp);
906 
907  fp = fopen(file_name, "rb");
908  ret = fscanf(fp, "%[^\n] ", buf);
909  ok(ret == 1, "ret = %d\n", ret);
910  ret = ftell(fp);
911  ok(ret == 12, "ftell returned %d\n", ret);
912  ok(!strcmp(buf, "simple test"), "buf = %s\n", buf);
913 
914  fgets(buf, sizeof(buf), fp);
915  ret = ftell(fp);
916  ok(ret == 26, "ret = %d\n", ret);
917  ok(!memcmp(buf, "contains\0null\n", 14), "buf = %s\n", buf);
918 
919  memset(buf, 0, sizeof(buf));
920  fgets(buf, sizeof(buf), fp);
921  ret = ftell(fp);
922  ok(ret == 41, "ret = %d\n", ret);
923  ok(!memcmp(buf, utf16_test, sizeof(utf16_test)),
924  "buf = %s\n", wine_dbgstr_w((WCHAR*)buf));
925 
926  fclose(fp);
927 
928  fp = fopen(file_name, "wt");
929 
930  ret = fprintf(fp, "simple test\n");
931  ok(ret == 12, "ret = %d\n", ret);
932  ret = ftell(fp);
933  ok(ret == 13, "ftell returned %d\n", ret);
934 
935  ret = fprintf(fp, "contains%cnull\n", '\0');
936  ok(ret == 14, "ret = %d\n", ret);
937  ret = ftell(fp);
938  ok(ret == 28, "ftell returned %d\n", ret);
939 
940  ret = fwprintf(fp, utf16_test);
941  ok(ret == 8, "ret = %d\n", ret);
942  ret = ftell(fp);
943  ok(ret == 37, "ftell returned %d\n", ret);
944 
945  fclose(fp);
946 
947  fp = fopen(file_name, "rb");
948  ret = fscanf(fp, "%[^\n] ", buf);
949  ok(ret == 1, "ret = %d\n", ret);
950  ret = ftell(fp);
951  ok(ret == 13, "ftell returned %d\n", ret);
952  ok(!strcmp(buf, "simple test\r"), "buf = %s\n", buf);
953 
954  fgets(buf, sizeof(buf), fp);
955  ret = ftell(fp);
956  ok(ret == 28, "ret = %d\n", ret);
957  ok(!memcmp(buf, "contains\0null\r\n", 15), "buf = %s\n", buf);
958 
959  fgets(buf, sizeof(buf), fp);
960  ret = ftell(fp);
961  ok(ret == 37, "ret = %d\n", ret);
962  ok(!strcmp(buf, "unicode\r\n"), "buf = %s\n", buf);
963 
964  fclose(fp);
965  unlink(file_name);
966 }
_Check_return_ _CRTIMP int __cdecl fscanf(_Inout_ FILE *_File, _In_z_ _Scanf_format_string_ const char *_Format,...)
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
#define unlink
Definition: syshdrs.h:54
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_Check_return_opt_ _CRTIMP int __cdecl fwprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const wchar_t *_Format,...)
__wchar_t WCHAR
Definition: xmlstorage.h:180
int ret
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP char *__cdecl fgets(_Out_writes_z_(_MaxCount) char *_Buf, _In_ int _MaxCount, _Inout_ FILE *_File)
#define ok(value,...)
Definition: atltest.h:57
static LPCWSTR file_name
Definition: protocol.c:147
_Check_return_ _CRTIMP long __cdecl ftell(_Inout_ FILE *_File)
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define memset(x, y, z)
Definition: compat.h:39

Referenced by START_TEST().

◆ test_snprintf()

static void test_snprintf ( void  )
static

Definition at line 853 of file printf.c.

854 {
855  struct snprintf_test {
856  const char *format;
857  int expected;
858  };
859  /* Pre-2.1 libc behaviour, not C99 compliant. */
860  const struct snprintf_test tests[] = {{"short", 5},
861  {"justfit", 7},
862  {"justfits", 8},
863  {"muchlonger", -1}};
864  char buffer[8];
865  const int bufsiz = sizeof buffer;
866  unsigned int i;
867 
868  for (i = 0; i < ARRAY_SIZE(tests); i++) {
869  const char *fmt = tests[i].format;
870  const int expect = tests[i].expected;
871  const int n = _snprintf (buffer, bufsiz, fmt);
872  const int valid = n < 0 ? bufsiz : (n == bufsiz ? n : n+1);
873 
874  ok (n == expect, "\"%s\": expected %d, returned %d\n",
875  fmt, expect, n);
876  ok (!memcmp (fmt, buffer, valid),
877  "\"%s\": rendered \"%.*s\"\n", fmt, valid, buffer);
878  }
879 }
struct param_test tests[]
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
GLdouble n
Definition: glext.h:7729
GLuint buffer
Definition: glext.h:5915
#define _snprintf
Definition: xmlstorage.h:200
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static size_t size_t const wchar_t * format
Definition: printf.c:66
#define ARRAY_SIZE(a)
Definition: main.h:24
#define ok(value,...)
Definition: atltest.h:57
#define expect(expected, got)
Definition: combo.c:36
Definition: dsound.c:943
BOOL expected
Definition: store.c:2063

Referenced by START_TEST().

◆ test_sprintf()

static void test_sprintf ( void  )
static

Definition at line 109 of file printf.c.

110 {
111  char buffer[100];
112  const char *format;
113  double pnumber=789456123;
114  int x, r;
115  WCHAR wide[] = { 'w','i','d','e',0};
116  WCHAR buf_w[2];
117 
118  format = "%+#23.15e";
119  r = p_sprintf(buffer,format,pnumber);
120  ok(!strcmp(buffer,"+7.894561230000000e+008"),"+#23.15e failed: '%s'\n", buffer);
121  ok( r==23, "return count wrong\n");
122 
123  format = "%-#23.15e";
124  r = p_sprintf(buffer,format,pnumber);
125  ok(!strcmp(buffer,"7.894561230000000e+008 "),"-#23.15e failed: '%s'\n", buffer);
126  ok( r==23, "return count wrong\n");
127 
128  format = "%#23.15e";
129  r = p_sprintf(buffer,format,pnumber);
130  ok(!strcmp(buffer," 7.894561230000000e+008"),"#23.15e failed: '%s'\n", buffer);
131  ok( r==23, "return count wrong\n");
132 
133  format = "%#1.1g";
134  r = p_sprintf(buffer,format,pnumber);
135  ok(!strcmp(buffer,"8.e+008"),"#1.1g failed: '%s'\n", buffer);
136  ok( r==7, "return count wrong\n");
137 
138  format = "%I64d";
139  r = p_sprintf(buffer,format,((ULONGLONG)0xffffffff)*0xffffffff);
140  ok(!strcmp(buffer,"-8589934591"),"Problem with long long\n");
141  ok( r==11, "return count wrong\n");
142 
143  format = "%+8I64d";
144  r = p_sprintf(buffer,format,(LONGLONG)100);
145  ok(!strcmp(buffer," +100") && r==8,"+8I64d failed: '%s'\n", buffer);
146 
147  format = "%+.8I64d";
148  r = p_sprintf(buffer,format,(LONGLONG)100);
149  ok(!strcmp(buffer,"+00000100") && r==9,"+.8I64d failed: '%s'\n", buffer);
150 
151  format = "%+10.8I64d";
152  r = p_sprintf(buffer,format,(LONGLONG)100);
153  ok(!strcmp(buffer," +00000100") && r==10,"+10.8I64d failed: '%s'\n", buffer);
154  format = "%_1I64d";
155  r = p_sprintf(buffer,format,(LONGLONG)100);
156  ok(!strcmp(buffer,"_1I64d") && r==6,"_1I64d failed\n");
157 
158  format = "%-1.5I64d";
159  r = p_sprintf(buffer,format,(LONGLONG)-100);
160  ok(!strcmp(buffer,"-00100") && r==6,"-1.5I64d failed: '%s'\n", buffer);
161 
162  format = "%5I64d";
163  r = p_sprintf(buffer,format,(LONGLONG)100);
164  ok(!strcmp(buffer," 100") && r==5,"5I64d failed: '%s'\n", buffer);
165 
166  format = "%5I64d";
167  r = p_sprintf(buffer,format,(LONGLONG)-100);
168  ok(!strcmp(buffer," -100") && r==5,"5I64d failed: '%s'\n", buffer);
169 
170  format = "%-5I64d";
171  r = p_sprintf(buffer,format,(LONGLONG)100);
172  ok(!strcmp(buffer,"100 ") && r==5,"-5I64d failed: '%s'\n", buffer);
173 
174  format = "%-5I64d";
175  r = p_sprintf(buffer,format,(LONGLONG)-100);
176  ok(!strcmp(buffer,"-100 ") && r==5,"-5I64d failed: '%s'\n", buffer);
177 
178  format = "%-.5I64d";
179  r = p_sprintf(buffer,format,(LONGLONG)100);
180  ok(!strcmp(buffer,"00100") && r==5,"-.5I64d failed: '%s'\n", buffer);
181 
182  format = "%-.5I64d";
183  r = p_sprintf(buffer,format,(LONGLONG)-100);
184  ok(!strcmp(buffer,"-00100") && r==6,"-.5I64d failed: '%s'\n", buffer);
185 
186  format = "%-8.5I64d";
187  r = p_sprintf(buffer,format,(LONGLONG)100);
188  ok(!strcmp(buffer,"00100 ") && r==8,"-8.5I64d failed: '%s'\n", buffer);
189 
190  format = "%-8.5I64d";
191  r = p_sprintf(buffer,format,(LONGLONG)-100);
192  ok(!strcmp(buffer,"-00100 ") && r==8,"-8.5I64d failed: '%s'\n", buffer);
193 
194  format = "%05I64d";
195  r = p_sprintf(buffer,format,(LONGLONG)100);
196  ok(!strcmp(buffer,"00100") && r==5,"05I64d failed: '%s'\n", buffer);
197 
198  format = "%05I64d";
199  r = p_sprintf(buffer,format,(LONGLONG)-100);
200  ok(!strcmp(buffer,"-0100") && r==5,"05I64d failed: '%s'\n", buffer);
201 
202  format = "% I64d";
203  r = p_sprintf(buffer,format,(LONGLONG)100);
204  ok(!strcmp(buffer," 100") && r==4,"' I64d' failed: '%s'\n", buffer);
205 
206  format = "% I64d";
207  r = p_sprintf(buffer,format,(LONGLONG)-100);
208  ok(!strcmp(buffer,"-100") && r==4,"' I64d' failed: '%s'\n", buffer);
209 
210  format = "% 5I64d";
211  r = p_sprintf(buffer,format,(LONGLONG)100);
212  ok(!strcmp(buffer," 100") && r==5,"' 5I64d' failed: '%s'\n", buffer);
213 
214  format = "% 5I64d";
215  r = p_sprintf(buffer,format,(LONGLONG)-100);
216  ok(!strcmp(buffer," -100") && r==5,"' 5I64d' failed: '%s'\n", buffer);
217 
218  format = "% .5I64d";
219  r = p_sprintf(buffer,format,(LONGLONG)100);
220  ok(!strcmp(buffer," 00100") && r==6,"' .5I64d' failed: '%s'\n", buffer);
221 
222  format = "% .5I64d";
223  r = p_sprintf(buffer,format,(LONGLONG)-100);
224  ok(!strcmp(buffer,"-00100") && r==6,"' .5I64d' failed: '%s'\n", buffer);
225 
226  format = "% 8.5I64d";
227  r = p_sprintf(buffer,format,(LONGLONG)100);
228  ok(!strcmp(buffer," 00100") && r==8,"' 8.5I64d' failed: '%s'\n", buffer);
229 
230  format = "% 8.5I64d";
231  r = p_sprintf(buffer,format,(LONGLONG)-100);
232  ok(!strcmp(buffer," -00100") && r==8,"' 8.5I64d' failed: '%s'\n", buffer);
233 
234  format = "%.0I64d";
235  r = p_sprintf(buffer,format,(LONGLONG)0);
236  ok(r==0,".0I64d failed: '%s'\n", buffer);
237 
238  format = "%#+21.18I64x";
239  r = p_sprintf(buffer,format,(LONGLONG)-100);
240  ok(!strcmp(buffer," 0x00ffffffffffffff9c") && r==21,"#+21.18I64x failed: '%s'\n", buffer);
241 
242  format = "%#.25I64o";
243  r = p_sprintf(buffer,format,(LONGLONG)-100);
244  ok(!strcmp(buffer,"0001777777777777777777634") && r==25,"#.25I64o failed: '%s'\n", buffer);
245 
246  format = "%#+24.20I64o";
247  r = p_sprintf(buffer,format,(LONGLONG)-100);
248  ok(!strcmp(buffer," 01777777777777777777634") && r==24,"#+24.20I64o failed: '%s'\n", buffer);
249 
250  format = "%#+18.21I64X";
251  r = p_sprintf(buffer,format,(LONGLONG)-100);
252  ok(!strcmp(buffer,"0X00000FFFFFFFFFFFFFF9C") && r==23,"#+18.21I64X failed: '%s '\n", buffer);
253 
254  format = "%#+20.24I64o";
255  r = p_sprintf(buffer,format,(LONGLONG)-100);
256  ok(!strcmp(buffer,"001777777777777777777634") && r==24,"#+20.24I64o failed: '%s'\n", buffer);
257 
258  format = "%#+25.22I64u";
259  r = p_sprintf(buffer,format,(LONGLONG)-1);
260  ok(!strcmp(buffer," 0018446744073709551615") && r==25,"#+25.22I64u conversion failed: '%s'\n", buffer);
261 
262  format = "%#+25.22I64u";
263  r = p_sprintf(buffer,format,(LONGLONG)-1);
264  ok(!strcmp(buffer," 0018446744073709551615") && r==25,"#+25.22I64u failed: '%s'\n", buffer);
265 
266  format = "%#+30.25I64u";
267  r = p_sprintf(buffer,format,(LONGLONG)-1);
268  ok(!strcmp(buffer," 0000018446744073709551615") && r==30,"#+30.25I64u failed: '%s'\n", buffer);
269 
270  format = "%+#25.22I64d";
271  r = p_sprintf(buffer,format,(LONGLONG)-1);
272  ok(!strcmp(buffer," -0000000000000000000001") && r==25,"+#25.22I64d failed: '%s'\n", buffer);
273 
274  format = "%#-8.5I64o";
275  r = p_sprintf(buffer,format,(LONGLONG)100);
276  ok(!strcmp(buffer,"00144 ") && r==8,"-8.5I64o failed: '%s'\n", buffer);
277 
278  format = "%#-+ 08.5I64d";
279  r = p_sprintf(buffer,format,(LONGLONG)100);
280  ok(!strcmp(buffer,"+00100 ") && r==8,"'#-+ 08.5I64d failed: '%s'\n", buffer);
281 
282  format = "%#-+ 08.5I64d";
283  r = p_sprintf(buffer,format,(LONGLONG)100);
284  ok(!strcmp(buffer,"+00100 ") && r==8,"#-+ 08.5I64d failed: '%s'\n", buffer);
285 
286  format = "%.80I64d";
287  r = p_sprintf(buffer,format,(LONGLONG)1);
288  ok(r==80,"%s format failed\n", format);
289 
290  format = "% .80I64d";
291  r = p_sprintf(buffer,format,(LONGLONG)1);
292  ok(r==81,"%s format failed\n", format);
293 
294  format = "% .80d";
295  r = p_sprintf(buffer,format,1);
296  ok(r==81,"%s format failed\n", format);
297 
298  format = "%lld";
299  r = p_sprintf(buffer,format,((ULONGLONG)0xffffffff)*0xffffffff);
300  ok( r == 1 || r == 11, "return count wrong %d\n", r);
301  if (r == 11) /* %ll works on Vista */
302  ok(!strcmp(buffer, "-8589934591"), "Problem with \"ll\" interpretation '%s'\n", buffer);
303  else
304  ok(!strcmp(buffer, "1"), "Problem with \"ll\" interpretation '%s'\n", buffer);
305 
306  format = "%I";
307  r = p_sprintf(buffer,format,1);
308  ok(!strcmp(buffer, "I"), "Problem with \"I\" interpretation\n");
309  ok( r==1, "return count wrong\n");
310 
311  format = "%I0d";
312  r = p_sprintf(buffer,format,1);
313  ok(!strcmp(buffer,"I0d"),"I0d failed\n");
314  ok( r==3, "return count wrong\n");
315 
316  format = "%I32d";
317  r = p_sprintf(buffer,format,1);
318  if (r == 1)
319  {
320  ok(!strcmp(buffer,"1"),"I32d failed, got '%s'\n",buffer);
321  }
322  else
323  {
324  /* Older versions don't grok I32 format */
325  ok(r == 4 && !strcmp(buffer,"I32d"),"I32d failed, got '%s',%d\n",buffer,r);
326  }
327 
328  format = "%I64D";
329  r = p_sprintf(buffer,format,(LONGLONG)-1);
330  ok(!strcmp(buffer,"D"),"I64D failed: %s\n",buffer);
331  ok( r==1, "return count wrong\n");
332 
333  format = "%zx";
334  r = p_sprintf(buffer,format,1);
335  ok(!strcmp(buffer, "zx"), "Problem with \"z\" interpretation\n");
336  ok( r==2, "return count wrong\n");
337 
338  format = "% d";
339  r = p_sprintf(buffer,format,1);
340  ok(!strcmp(buffer, " 1"),"Problem with sign place-holder: '%s'\n",buffer);
341  ok( r==2, "return count wrong\n");
342 
343  format = "%+ d";
344  r = p_sprintf(buffer,format,1);
345  ok(!strcmp(buffer, "+1"),"Problem with sign flags: '%s'\n",buffer);
346  ok( r==2, "return count wrong\n");
347 
348  format = "%S";
349  r = p_sprintf(buffer,format,wide);
350  ok(!strcmp(buffer,"wide"),"Problem with wide string format\n");
351  ok( r==4, "return count wrong\n");
352 
353  format = "%04c";
354  r = p_sprintf(buffer,format,'1');
355  ok(!strcmp(buffer,"0001"),"Character not zero-prefixed \"%s\"\n",buffer);
356  ok( r==4, "return count wrong\n");
357 
358  format = "%-04c";
359  r = p_sprintf(buffer,format,'1');
360  ok(!strcmp(buffer,"1 "),"Character zero-padded and/or not left-adjusted \"%s\"\n",buffer);
361  ok( r==4, "return count wrong\n");
362 
363  format = "%#012x";
364  r = p_sprintf(buffer,format,1);
365  ok(!strcmp(buffer,"0x0000000001"),"Hexadecimal zero-padded \"%s\"\n",buffer);
366  ok( r==12, "return count wrong\n");
367 
368  r = p_sprintf(buffer,format,0);
369  ok(!strcmp(buffer,"000000000000"),"Hexadecimal zero-padded \"%s\"\n",buffer);
370  ok( r==12, "return count wrong\n");
371 
372  format = "%#04.8x";
373  r = p_sprintf(buffer,format,1);
374  ok(!strcmp(buffer,"0x00000001"), "Hexadecimal zero-padded precision \"%s\"\n",buffer);
375  ok( r==10, "return count wrong\n");
376 
377  r = p_sprintf(buffer,format,0);
378  ok(!strcmp(buffer,"00000000"), "Hexadecimal zero-padded precision \"%s\"\n",buffer);
379  ok( r==8, "return count wrong\n");
380 
381  format = "%#-08.2x";
382  r = p_sprintf(buffer,format,1);
383  ok(!strcmp(buffer,"0x01 "), "Hexadecimal zero-padded not left-adjusted \"%s\"\n",buffer);
384  ok( r==8, "return count wrong\n");
385 
386  r = p_sprintf(buffer,format,0);
387  ok(!strcmp(buffer,"00 "), "Hexadecimal zero-padded not left-adjusted \"%s\"\n",buffer);
388  ok( r==8, "return count wrong\n");
389 
390  format = "%#.0x";
391  r = p_sprintf(buffer,format,1);
392  ok(!strcmp(buffer,"0x1"), "Hexadecimal zero-padded zero-precision \"%s\"\n",buffer);
393  ok( r==3, "return count wrong\n");
394 
395  r = p_sprintf(buffer,format,0);
396  ok(!strcmp(buffer,""), "Hexadecimal zero-padded zero-precision \"%s\"\n",buffer);
397  ok( r==0, "return count wrong\n");
398 
399  format = "%#08o";
400  r = p_sprintf(buffer,format,1);
401  ok(!strcmp(buffer,"00000001"), "Octal zero-padded \"%s\"\n",buffer);
402  ok( r==8, "return count wrong\n");
403 
404  format = "%#o";
405  r = p_sprintf(buffer,format,1);
406  ok(!strcmp(buffer,"01"), "Octal zero-padded \"%s\"\n",buffer);
407  ok( r==2, "return count wrong\n");
408 
409  r = p_sprintf(buffer,format,0);
410  ok(!strcmp(buffer,"0"), "Octal zero-padded \"%s\"\n",buffer);
411  ok( r==1, "return count wrong\n");
412 
413  if (sizeof(void *) == 8)
414  {
415  format = "%p";
416  r = p_sprintf(buffer,format,(void *)57);
417  ok(!strcmp(buffer,"0000000000000039"),"Pointer formatted incorrectly \"%s\"\n",buffer);
418  ok( r==16, "return count wrong\n");
419 
420  format = "%#020p";
421  r = p_sprintf(buffer,format,(void *)57);
422  ok(!strcmp(buffer," 0X0000000000000039"),"Pointer formatted incorrectly\n");
423  ok( r==20, "return count wrong\n");
424 
425  format = "%Fp";
426  r = p_sprintf(buffer,format,(void *)57);
427  ok(!strcmp(buffer,"0000000000000039"),"Pointer formatted incorrectly \"%s\"\n",buffer);
428  ok( r==16, "return count wrong\n");
429 
430  format = "%Np";
431  r = p_sprintf(buffer,format,(void *)57);
432  ok(!strcmp(buffer,"0000000000000039"),"Pointer formatted incorrectly \"%s\"\n",buffer);
433  ok( r==16, "return count wrong\n");
434 
435  format = "%#-020p";
436  r = p_sprintf(buffer,format,(void *)57);
437  ok(!strcmp(buffer,"0X0000000000000039 "),"Pointer formatted incorrectly\n");
438  ok( r==20, "return count wrong\n");
439 
440  format = "%Ix %d";
441  r = p_sprintf(buffer,format,(size_t)0x12345678123456,1);
442  ok(!strcmp(buffer,"12345678123456 1"),"buffer = %s\n",buffer);
443  ok( r==16, "return count wrong\n");
444  }
445  else
446  {
447  format = "%p";
448  r = p_sprintf(buffer,format,(void *)57);
449  ok(!strcmp(buffer,"00000039"),"Pointer formatted incorrectly \"%s\"\n",buffer);
450  ok( r==8, "return count wrong\n");
451 
452  format = "%#012p";
453  r = p_sprintf(buffer,format,(void *)57);
454  ok(!strcmp(buffer," 0X00000039"),"Pointer formatted incorrectly\n");
455  ok( r==12, "return count wrong\n");
456 
457  format = "%Fp";
458  r = p_sprintf(buffer,format,(void *)57);
459  ok(!strcmp(buffer,"00000039"),"Pointer formatted incorrectly \"%s\"\n",buffer);
460  ok( r==8, "return count wrong\n");
461 
462  format = "%Np";
463  r = p_sprintf(buffer,format,(void *)57);
464  ok(!strcmp(buffer,"00000039"),"Pointer formatted incorrectly \"%s\"\n",buffer);
465  ok( r==8, "return count wrong\n");
466 
467  format = "%#-012p";
468  r = p_sprintf(buffer,format,(void *)57);
469  ok(!strcmp(buffer,"0X00000039 "),"Pointer formatted incorrectly\n");
470  ok( r==12, "return count wrong\n");
471 
472  format = "%Ix %d";
473  r = p_sprintf(buffer,format,0x123456,1);
474  ok(!strcmp(buffer,"123456 1"),"buffer = %s\n",buffer);
475  ok( r==8, "return count wrong\n");
476  }
477 
478  format = "%04s";
479  r = p_sprintf(buffer,format,"foo");
480  ok(!strcmp(buffer,"0foo"),"String not zero-prefixed \"%s\"\n",buffer);
481  ok( r==4, "return count wrong\n");
482 
483  format = "%.1s";
484  r = p_sprintf(buffer,format,"foo");
485  ok(!strcmp(buffer,"f"),"Precision ignored \"%s\"\n",buffer);
486  ok( r==1, "return count wrong\n");
487 
488  format = "%.*s";
489  r = p_sprintf(buffer,format,1,"foo");
490  ok(!strcmp(buffer,"f"),"Precision ignored \"%s\"\n",buffer);
491  ok( r==1, "return count wrong\n");
492 
493  format = "%*s";
494  r = p_sprintf(buffer,format,-5,"foo");
495  ok(!strcmp(buffer,"foo "),"Negative field width ignored \"%s\"\n",buffer);
496  ok( r==5, "return count wrong\n");
497 
498  format = "hello";
499  r = p_sprintf(buffer, format);
500  ok(!strcmp(buffer,"hello"), "failed\n");
501  ok( r==5, "return count wrong\n");
502 
503  format = "%ws";
504  r = p_sprintf(buffer, format, wide);
505  ok(!strcmp(buffer,"wide"), "failed\n");
506  ok( r==4, "return count wrong\n");
507 
508  format = "%-10ws";
509  r = p_sprintf(buffer, format, wide );
510  ok(!strcmp(buffer,"wide "), "failed\n");
511  ok( r==10, "return count wrong\n");
512 
513  format = "%10ws";
514  r = p_sprintf(buffer, format, wide );
515  ok(!strcmp(buffer," wide"), "failed\n");
516  ok( r==10, "return count wrong\n");
517 
518  format = "%#+ -03whlls";
519  r = p_sprintf(buffer, format, wide );
520  ok(!strcmp(buffer,"wide"), "failed\n");
521  ok( r==4, "return count wrong\n");
522 
523  format = "%w0s";
524  r = p_sprintf(buffer, format, wide );
525  ok(!strcmp(buffer,"0s"), "failed\n");
526  ok( r==2, "return count wrong\n");
527 
528  format = "%w-s";
529  r = p_sprintf(buffer, format, wide );
530  ok(!strcmp(buffer,"-s"), "failed\n");
531  ok( r==2, "return count wrong\n");
532 
533  format = "%ls";
534  r = p_sprintf(buffer, format, wide );
535  ok(!strcmp(buffer,"wide"), "failed\n");
536  ok( r==4, "return count wrong\n");
537 
538  format = "%Ls";
539  r = p_sprintf(buffer, format, "not wide" );
540  ok(!strcmp(buffer,"not wide"), "failed\n");
541  ok( r==8, "return count wrong\n");
542 
543  format = "%b";
544  r = p_sprintf(buffer, format);
545  ok(!strcmp(buffer,"b"), "failed\n");
546  ok( r==1, "return count wrong\n");
547 
548  format = "%3c";
549  r = p_sprintf(buffer, format,'a');
550  ok(!strcmp(buffer," a"), "failed\n");
551  ok( r==3, "return count wrong\n");
552 
553  format = "%3d";
554  r = p_sprintf(buffer, format,1234);
555  ok(!strcmp(buffer,"1234"), "failed\n");
556  ok( r==4, "return count wrong\n");
557 
558  format = "%3h";
559  r = p_sprintf(buffer, format);
560  ok(!strcmp(buffer,""), "failed\n");
561  ok( r==0, "return count wrong\n");
562 
563  format = "%j%k%m%q%r%t%v%y%z";
564  r = p_sprintf(buffer, format);
565  ok(!strcmp(buffer,"jkmqrtvyz"), "failed\n");
566  ok( r==9, "return count wrong\n");
567 
568  format = "asdf%n";
569  x = 0;
570  r = p_sprintf(buffer, format, &x );
571  if (r == -1)
572  {
573  /* %n format is disabled by default on vista */
574  /* FIXME: should test with _set_printf_count_output */
575  ok(x == 0, "should not write to x: %d\n", x);
576  }
577  else
578  {
579  ok(x == 4, "should write to x: %d\n", x);
580  ok(!strcmp(buffer,"asdf"), "failed\n");
581  ok( r==4, "return count wrong: %d\n", r);
582  }
583 
584  format = "%-1d";
585  r = p_sprintf(buffer, format,2);
586  ok(!strcmp(buffer,"2"), "failed\n");
587  ok( r==1, "return count wrong\n");
588 
589  format = "%2.4f";
590  r = p_sprintf(buffer, format,8.6);
591  ok(!strcmp(buffer,"8.6000"), "failed\n");
592  ok( r==6, "return count wrong\n");
593 
594  format = "%0f";
595  r = p_sprintf(buffer, format,0.6);
596  ok(!strcmp(buffer,"0.600000"), "failed\n");
597  ok( r==8, "return count wrong\n");
598 
599  format = "%.0f";
600  r = p_sprintf(buffer, format,0.6);
601  ok(!strcmp(buffer,"1"), "failed\n");
602  ok( r==1, "return count wrong\n");
603 
604  format = "%2.4e";
605  r = p_sprintf(buffer, format,8.6);
606  ok(!strcmp(buffer,"8.6000e+000"), "failed\n");
607  ok( r==11, "return count wrong\n");
608 
609  format = "% 2.4e";
610  r = p_sprintf(buffer, format,8.6);
611  ok(!strcmp(buffer," 8.6000e+000"), "failed: %s\n", buffer);
612  ok( r==12, "return count wrong\n");
613 
614  format = "% 014.4e";
615  r = p_sprintf(buffer, format,8.6);
616  ok(!strcmp(buffer," 008.6000e+000"), "failed: %s\n", buffer);
617  ok( r==14, "return count wrong\n");
618 
619  format = "% 2.4e";
620  r = p_sprintf(buffer, format,-8.6);
621  ok(!strcmp(buffer,"-8.6000e+000"), "failed: %s\n", buffer);
622  ok( r==12, "return count wrong\n");
623 
624  format = "%+2.4e";
625  r = p_sprintf(buffer, format,8.6);
626  ok(!strcmp(buffer,"+8.6000e+000"), "failed: %s\n", buffer);
627  ok( r==12, "return count wrong\n");
628 
629  format = "%2.4g";
630  r = p_sprintf(buffer, format,8.6);
631  ok(!strcmp(buffer,"8.6"), "failed\n");
632  ok( r==3, "return count wrong\n");
633 
634  format = "%-i";
635  r = p_sprintf(buffer, format,-1);
636  ok(!strcmp(buffer,"-1"), "failed\n");
637  ok( r==2, "return count wrong\n");
638 
639  format = "%-i";
640  r = p_sprintf(buffer, format,1);
641  ok(!strcmp(buffer,"1"), "failed\n");
642  ok( r==1, "return count wrong\n");
643 
644  format = "%+i";
645  r = p_sprintf(buffer, format,1);
646  ok(!strcmp(buffer,"+1"), "failed\n");
647  ok( r==2, "return count wrong\n");
648 
649  format = "%o";
650  r = p_sprintf(buffer, format,10);
651  ok(!strcmp(buffer,"12"), "failed\n");
652  ok( r==2, "return count wrong\n");
653 
654  format = "%p";
655  r = p_sprintf(buffer, format,0);
656  if (sizeof(void *) == 8)
657  {
658  ok(!strcmp(buffer,"0000000000000000"), "failed\n");
659  ok( r==16, "return count wrong\n");
660  }
661  else
662  {
663  ok(!strcmp(buffer,"00000000"), "failed\n");
664  ok( r==8, "return count wrong\n");
665  }
666 
667  format = "%s";
668  r = p_sprintf(buffer, format,0);
669  ok(!strcmp(buffer,"(null)"), "failed\n");
670  ok( r==6, "return count wrong\n");
671 
672  format = "%s";
673  r = p_sprintf(buffer, format,"%%%%");
674  ok(!strcmp(buffer,"%%%%"), "failed\n");
675  ok( r==4, "return count wrong\n");
676 
677  format = "%u";
678  r = p_sprintf(buffer, format,-1);
679  ok(!strcmp(buffer,"4294967295"), "failed\n");
680  ok( r==10, "return count wrong\n");
681 
682  format = "%w";
683  r = p_sprintf(buffer, format,-1);
684  ok(!strcmp(buffer,""), "failed\n");
685  ok( r==0, "return count wrong\n");
686 
687  format = "%h";
688  r = p_sprintf(buffer, format,-1);
689  ok(!strcmp(buffer,""), "failed\n");
690  ok( r==0, "return count wrong\n");
691 
692  format = "%z";
693  r = p_sprintf(buffer, format,-1);
694  ok(!strcmp(buffer,"z"), "failed\n");
695  ok( r==1, "return count wrong\n");
696 
697  format = "%j";
698  r = p_sprintf(buffer, format,-1);
699  ok(!strcmp(buffer,"j"), "failed\n");
700  ok( r==1, "return count wrong\n");
701 
702  format = "%F";
703  r = p_sprintf(buffer, format,-1);
704  ok(!strcmp(buffer,""), "failed\n");
705  ok( r==0, "return count wrong\n");
706 
707  format = "%N";
708  r = p_sprintf(buffer, format,-1);
709  ok(!strcmp(buffer,""), "failed\n");
710  ok( r==0, "return count wrong\n");
711 
712  format = "%H";
713  r = p_sprintf(buffer, format,-1);
714  ok(!strcmp(buffer,"H"), "failed\n");
715  ok( r==1, "return count wrong\n");
716 
717  format = "x%cx";
718  r = p_sprintf(buffer, format, 0x100+'X');
719  ok(!strcmp(buffer,"xXx"), "failed\n");
720  ok( r==3, "return count wrong\n");
721 
722  format = "%%0";
723  r = p_sprintf(buffer, format);
724  ok(!strcmp(buffer,"%0"), "failed: \"%s\"\n", buffer);
725  ok( r==2, "return count wrong\n");
726 
727  format = "%hx";
728  r = p_sprintf(buffer, format, 0x12345);
729  ok(!strcmp(buffer,"2345"), "failed \"%s\"\n", buffer);
730 
731  format = "%hhx";
732  r = p_sprintf(buffer, format, 0x123);
733  ok(!strcmp(buffer,"123"), "failed: \"%s\"\n", buffer);
734  r = p_sprintf(buffer, format, 0x12345);
735  ok(!strcmp(buffer,"2345"), "failed \"%s\"\n", buffer);
736 
737  format = "%lf";
738  r = p_sprintf(buffer, format, IND);
739  ok(r==9, "r = %d\n", r);
740  ok(!strcmp(buffer, "-1.#IND00"), "failed: \"%s\"\n", buffer);
741  r = p_sprintf(buffer, format, NAN);
742  ok(r==8, "r = %d\n", r);
743  ok(!strcmp(buffer, "1.#QNAN0"), "failed: \"%s\"\n", buffer);
744  r = p_sprintf(buffer, format, INFINITY);
745  ok(r==8, "r = %d\n", r);
746  ok(!strcmp(buffer, "1.#INF00"), "failed: \"%s\"\n", buffer);
747 
748  format = "%le";
749  r = p_sprintf(buffer, format, IND);
750  ok(r==14, "r = %d\n", r);
751  ok(!strcmp(buffer, "-1.#IND00e+000"), "failed: \"%s\"\n", buffer);
752  r = p_sprintf(buffer, format, NAN);
753  ok(r==13, "r = %d\n", r);
754  ok(!strcmp(buffer, "1.#QNAN0e+000"), "failed: \"%s\"\n", buffer);
755  r = p_sprintf(buffer, format, INFINITY);
756  ok(r==13, "r = %d\n", r);
757  ok(!strcmp(buffer, "1.#INF00e+000"), "failed: \"%s\"\n", buffer);
758 
759  format = "%lg";
760  r = p_sprintf(buffer, format, IND);
761  ok(r==7, "r = %d\n", r);
762  ok(!strcmp(buffer, "-1.#IND"), "failed: \"%s\"\n", buffer);
763  r = p_sprintf(buffer, format, NAN);
764  ok(r==7, "r = %d\n", r);
765  ok(!strcmp(buffer, "1.#QNAN"), "failed: \"%s\"\n", buffer);
766  r = p_sprintf(buffer, format, INFINITY);
767  ok(r==6, "r = %d\n", r);
768  ok(!strcmp(buffer, "1.#INF"), "failed: \"%s\"\n", buffer);
769 
770  format = "%010.2lf";
771  r = p_sprintf(buffer, format, IND);
772  ok(r==10, "r = %d\n", r);
773  ok(!strcmp(buffer, "-000001.#J"), "failed: \"%s\"\n", buffer);
774  r = p_sprintf(buffer, format, NAN);
775  ok(r==10, "r = %d\n", r);
776  ok(!strcmp(buffer, "0000001.#R"), "failed: \"%s\"\n", buffer);
777  r = p_sprintf(buffer, format, INFINITY);
778  ok(r==10, "r = %d\n", r);
779  ok(!strcmp(buffer, "0000001.#J"), "failed: \"%s\"\n", buffer);
780 
781  format = "%c";
782  r = p_sprintf(buffer, format, 'a');
783  ok(r==1, "r = %d\n", r);
784  ok(!strcmp(buffer, "a"), "failed: \"%s\"\n", buffer);
785  r = p_sprintf(buffer, format, 0xa082);
786  ok(r==1, "r = %d\n", r);
787  ok(!strcmp(buffer, "\x82"), "failed: \"%s\"\n", buffer);
788 
789  format = "%C";
790  r = p_sprintf(buffer, format, 'a');
791  ok(r==1, "r = %d\n", r);
792  ok(!strcmp(buffer, "a"), "failed: \"%s\"\n", buffer);
793  r = p_sprintf(buffer, format, 0x3042);
794  ok(r==0, "r = %d\n", r);
795  ok(!strcmp(buffer, ""), "failed: \"%s\"\n", buffer);
796 
797  format = "a%Cb";
798  r = p_sprintf(buffer, format, 0x3042);
799  ok(r==2, "r = %d\n", r);
800  ok(!strcmp(buffer, "ab"), "failed: \"%s\"\n", buffer);
801 
802  format = "%S";
803  buf_w[0] = 0x3042;
804  buf_w[1] = 0;
805  r = p_sprintf(buffer, format, buf_w);
806  ok(r==-1 || broken(!r), "r = %d\n", r);
807 
808  if(!setlocale(LC_ALL, "Japanese_Japan.932")) {
809  win_skip("Japanese_Japan.932 locale not available\n");
810  return;
811  }
812 
813  format = "%c";
814  r = p_sprintf(buffer, format, 0xa082);
815  ok(r==1, "r = %d\n", r);
816  ok(!strcmp(buffer, "\x82"), "failed: \"%s\"\n", buffer);
817 
818  format = "%C";
819  r = p_sprintf(buffer, format, 0x3042);
820  ok(r==2, "r = %d\n", r);
821  ok(!strcmp(buffer, "\x82\xa0"), "failed: \"%s\"\n", buffer);
822 
823  strcpy(buffer, " string to copy");
824  r = p_sprintf(buffer, buffer+1);
825  ok(r==14, "r = %d\n", r);
826  ok(!strcmp(buffer, "string to copy"), "failed: \"%s\"\n", buffer);
827 
828  setlocale(LC_ALL, "C");
829 }
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define NAN
Definition: printf.c:53
GLuint buffer
Definition: glext.h:5915
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
#define IND
Definition: printf.c:62
static size_t size_t const wchar_t * format
Definition: printf.c:66
int64_t LONGLONG
Definition: typedefs.h:66
#define LC_ALL
Definition: locale.h:25
__wchar_t WCHAR
Definition: xmlstorage.h:180
uint64_t ULONGLONG
Definition: typedefs.h:65
#define broken(x)
Definition: _sntprintf.h:21
#define ok(value,...)
Definition: atltest.h:57
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define setlocale(n, s)
Definition: locale.h:46
#define INFINITY
Definition: printf.c:46
#define win_skip
Definition: test.h:150

Referenced by START_TEST().

◆ test_swprintf()

static void test_swprintf ( void  )
static

Definition at line 831 of file printf.c.

832 {
833  wchar_t buffer[100];
834  const wchar_t I64d[] = {'%','I','6','4','d',0};
835  double pnumber=789456123;
836  const wchar_t TwentyThreePoint15e[]= {'%','+','#','2','3','.','1','5','e',0};
837  const wchar_t e008[] = {'e','+','0','0','8',0};
838  const wchar_t string_w[] = {'s','t','r','i','n','g',0};
839  const char string[] = "string";
840  const wchar_t S[]={'%','S',0};
841  const wchar_t hs[] = {'%', 'h', 's', 0};
842 
843  swprintf(buffer,TwentyThreePoint15e,pnumber);
844  ok(wcsstr(buffer,e008) != 0,"Sprintf different\n");
845  swprintf(buffer,I64d,((ULONGLONG)0xffffffff)*0xffffffff);
846  ok(wcslen(buffer) == 11,"Problem with long long\n");
847  swprintf(buffer,S,string);
848  ok(wcslen(buffer) == 6,"Problem with \"%%S\" interpretation\n");
849  swprintf(buffer, hs, string);
850  ok( wcscmp(string_w,buffer) == 0, "swprintf failed with %%hs\n");
851 }
_CONST_RETURN wchar_t *__cdecl wcsstr(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_SubStr)
GLuint buffer
Definition: glext.h:5915
Definition: movable.cpp:7
uint64_t ULONGLONG
Definition: typedefs.h:65
#define swprintf(buf, format,...)
Definition: sprintf.c:56
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define ok(value,...)
Definition: atltest.h:57
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by START_TEST().

◆ test_vscprintf()

static void test_vscprintf ( void  )
static

Definition at line 1371 of file printf.c.

1372 {
1373  int ret;
1374 
1375  if (!p__vscprintf)
1376  {
1377  win_skip("_vscprintf not available\n");
1378  return;
1379  }
1380 
1381  ret = _vscprintf_wrapper( "%s %d", "number", 1 );
1382  ok( ret == 8, "got %d expected 8\n", ret );
1383 }
static int WINAPIV _vscprintf_wrapper(const char *format,...)
Definition: printf.c:1361
int ret
#define ok(value,...)
Definition: atltest.h:57
#define win_skip
Definition: test.h:150

Referenced by START_TEST().

◆ test_vscwprintf()

static void test_vscwprintf ( void  )
static

Definition at line 1395 of file printf.c.

1396 {
1397  const wchar_t format[] = {'%','s',' ','%','d',0};
1398  const wchar_t number[] = {'n','u','m','b','e','r',0};
1399 
1400  int ret;
1401 
1402  if (!p__vscwprintf)
1403  {
1404  win_skip("_vscwprintf not available\n");
1405  return;
1406  }
1407 
1409  ok( ret == 8, "got %d expected 8\n", ret );
1410 }
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
static size_t double number
Definition: printf.c:69
int ret
static int WINAPIV _vscwprintf_wrapper(const wchar_t *format,...)
Definition: printf.c:1385
#define ok(value,...)
Definition: atltest.h:57
#define win_skip
Definition: test.h:150

Referenced by START_TEST().

◆ test_vsnwprintf()

static void test_vsnwprintf ( void  )
static

Definition at line 1231 of file printf.c.

1232 {
1233  const wchar_t format[] = {'%','w','s','%','w','s','%','w','s',0};
1234  const wchar_t one[] = {'o','n','e',0};
1235  const wchar_t two[] = {'t','w','o',0};
1236  const wchar_t three[] = {'t','h','r','e','e',0};
1237 
1238  int ret;
1239  wchar_t str[32];
1240  char buf[32];
1241 
1243 
1244  ok( ret == 11, "got %d expected 11\n", ret );
1245  WideCharToMultiByte( CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL );
1246  ok( !strcmp(buf, "onetwothree"), "got %s expected 'onetwothree'\n", buf );
1247 
1248  ret = _vsnwprintf_wrapper( str, 0, format, one, two, three );
1249  ok( ret == -1, "got %d, expected -1\n", ret );
1250 
1251  ret = _vsnwprintf_wrapper( NULL, 0, format, one, two, three );
1252  ok( ret == 11 || broken(ret == -1 /* Win2k */), "got %d, expected 11\n", ret );
1253 }
#define WideCharToMultiByte
Definition: compat.h:101
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define CP_ACP
Definition: compat.h:99
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
static double one
Definition: j0_y0.c:80
static double two
Definition: jn_yn.c:52
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
int ret
#define broken(x)
Definition: _sntprintf.h:21
#define ARRAY_SIZE(a)
Definition: main.h:24
#define ok(value,...)
Definition: atltest.h:57
static int WINAPIV _vsnwprintf_wrapper(wchar_t *str, size_t len, const wchar_t *format,...)
Definition: printf.c:1221
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469

Referenced by START_TEST().

◆ test_vsnwprintf_s()

static void test_vsnwprintf_s ( void  )
static

Definition at line 1423 of file printf.c.

1424 {
1425  const wchar_t format[] = { 'A','B','%','u','C',0 };
1426  const wchar_t out7[] = { 'A','B','1','2','3','C',0 };
1427  const wchar_t out6[] = { 'A','B','1','2','3',0 };
1428  const wchar_t out2[] = { 'A',0 };
1429  const wchar_t out1[] = { 0 };
1430  wchar_t buffer[14] = { 0 };
1431  int exp, got;
1432 
1433  if (!p__vsnwprintf_s)
1434  {
1435  win_skip("_vsnwprintf_s not available\n");
1436  return;
1437  }
1438 
1439  /* Enough room. */
1440  exp = wcslen(out7);
1441 
1442  got = _vsnwprintf_s_wrapper(buffer, 14, _TRUNCATE, format, 123);
1443  ok( exp == got, "length wrong, expect=%d, got=%d\n", exp, got);
1444  ok( !wcscmp(out7, buffer), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer));
1445 
1446  got = _vsnwprintf_s_wrapper(buffer, 12, _TRUNCATE, format, 123);
1447  ok( exp == got, "length wrong, expect=%d, got=%d\n", exp, got);
1448  ok( !wcscmp(out7, buffer), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer));
1449 
1450  got = _vsnwprintf_s_wrapper(buffer, 7, _TRUNCATE, format, 123);
1451  ok( exp == got, "length wrong, expect=%d, got=%d\n", exp, got);
1452  ok( !wcscmp(out7, buffer), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer));
1453 
1454  /* Not enough room. */
1455  exp = -1;
1456 
1457  got = _vsnwprintf_s_wrapper(buffer, 6, _TRUNCATE, format, 123);
1458  ok( exp == got, "length wrong, expect=%d, got=%d\n", exp, got);
1459  ok( !wcscmp(out6, buffer), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer));
1460 
1461  got = _vsnwprintf_s_wrapper(buffer, 2, _TRUNCATE, format, 123);
1462  ok( exp == got, "length wrong, expect=%d, got=%d\n", exp, got);
1463  ok( !wcscmp(out2, buffer), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer));
1464 
1465  got = _vsnwprintf_s_wrapper(buffer, 1, _TRUNCATE, format, 123);
1466  ok( exp == got, "length wrong, expect=%d, got=%d\n", exp, got);
1467  ok( !wcscmp(out1, buffer), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer));
1468 }
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
GLuint buffer
Definition: glext.h:5915
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
#define _TRUNCATE
Definition: crtdefs.h:241
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define ok(value,...)
Definition: atltest.h:57
static int WINAPIV _vsnwprintf_s_wrapper(wchar_t *str, size_t sizeOfBuffer, size_t count, const wchar_t *format,...)
Definition: printf.c:1412
DWORD exp
Definition: msg.c:16038
#define win_skip
Definition: test.h:150
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by START_TEST().

◆ test_vsprintf_p()

static void test_vsprintf_p ( void  )
static

Definition at line 1481 of file printf.c.

1482 {
1483  char buf[1024];
1484  int ret;
1485 
1486  if(!p__vsprintf_p) {
1487  win_skip("vsprintf_p not available\n");
1488  return;
1489  }
1490 
1491  ret = _vsprintf_p_wrapper(buf, sizeof(buf), "%s %d", "test", 1234);
1492  ok(ret == 9, "ret = %d\n", ret);
1493  ok(!memcmp(buf, "test 1234", 10), "buf = %s\n", buf);
1494 
1495  ret = _vsprintf_p_wrapper(buf, sizeof(buf), "%1$d", 1234, "additional param");
1496  ok(ret == 4, "ret = %d\n", ret);
1497  ok(!memcmp(buf, "1234", 5), "buf = %s\n", buf);
1498 
1499  ret = _vsprintf_p_wrapper(buf, sizeof(buf), "%2$s %1$d", 1234, "test");
1500  ok(ret == 9, "ret = %d\n", ret);
1501  ok(!memcmp(buf, "test 1234", 10), "buf = %s\n", buf);
1502 
1503  ret = _vsprintf_p_wrapper(buf, sizeof(buf), "%2$*3$s %2$.*1$s", 2, "test", 3);
1504  ok(ret == 7, "ret = %d\n", ret);
1505  ok(!memcmp(buf, "test te", 8), "buf = %s\n", buf);
1506 
1507  /* Following test invokes invalid parameter handler */
1508  /* ret = _vsprintf_p_wrapper(buf, sizeof(buf), "%d %1$d", 1234); */
1509 }
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
int ret
#define ok(value,...)
Definition: atltest.h:57
static int WINAPIV _vsprintf_p_wrapper(char *str, size_t sizeOfBuffer, const char *format,...)
Definition: printf.c:1470
#define win_skip
Definition: test.h:150

Referenced by START_TEST().

◆ test_vswprintf()

static void test_vswprintf ( void  )
static

Definition at line 1315 of file printf.c.

1316 {
1317  const wchar_t format[] = {'%','s',' ','%','d',0};
1318  const wchar_t number[] = {'n','u','m','b','e','r',0};
1319  const wchar_t out[] = {'n','u','m','b','e','r',' ','1','2','3',0};
1320  wchar_t buf[20];
1321 
1322  int ret;
1323 
1324  if (!p_vswprintf || !p__vswprintf || !p__vswprintf_l ||!p__vswprintf_c
1325  || !p__vswprintf_c_l || !p__vswprintf_p_l)
1326  {
1327  win_skip("_vswprintf or vswprintf not available\n");
1328  return;
1329  }
1330 
1332  ok(ret == 10, "got %d, expected 10\n", ret);
1333  ok(!memcmp(buf, out, sizeof(out)), "buf = %s\n", wine_dbgstr_w(buf));
1334 
1335  memset(buf, 0, sizeof(buf));
1337  ok(ret == 10, "got %d, expected 10\n", ret);
1338  ok(!memcmp(buf, out, sizeof(out)), "buf = %s\n", wine_dbgstr_w(buf));
1339 
1340  memset(buf, 0, sizeof(buf));
1342  ok(ret == 10, "got %d, expected 10\n", ret);
1343  ok(!memcmp(buf, out, sizeof(out)), "buf = %s\n", wine_dbgstr_w(buf));
1344 
1345  memset(buf, 0, sizeof(buf));
1346  ret = _vswprintf_c_wrapper(buf, 20, format, number, 123);
1347  ok(ret == 10, "got %d, expected 10\n", ret);
1348  ok(!memcmp(buf, out, sizeof(out)), "buf = %s\n", wine_dbgstr_w(buf));
1349 
1350  memset(buf, 0, sizeof(buf));
1352  ok(ret == 10, "got %d, expected 10\n", ret);
1353  ok(!memcmp(buf, out, sizeof(out)), "buf = %s\n", wine_dbgstr_w(buf));
1354 
1355  memset(buf, 0, sizeof(buf));
1357  ok(ret == 10, "got %d, expected 10\n", ret);
1358  ok(!memcmp(buf, out, sizeof(out)), "buf = %s\n", wine_dbgstr_w(buf));
1359 }
static int WINAPIV vswprintf_wrapper(wchar_t *str, const wchar_t *format,...)
Definition: printf.c:1255
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
static int WINAPIV _vswprintf_c_l_wrapper(wchar_t *str, size_t size, const wchar_t *format, void *locale,...)
Definition: printf.c:1295
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
static size_t double number
Definition: printf.c:69
smooth NULL
Definition: ftsmooth.c:416
static int WINAPIV _vswprintf_c_wrapper(wchar_t *str, size_t size, const wchar_t *format,...)
Definition: printf.c:1285
static FILE * out
Definition: regtests2xml.c:44
int ret
static int WINAPIV _vswprintf_l_wrapper(wchar_t *str, const wchar_t *format, void *locale,...)
Definition: printf.c:1275
static int WINAPIV _vswprintf_wrapper(wchar_t *str, const wchar_t *format,...)
Definition: printf.c:1265
#define ok(value,...)
Definition: atltest.h:57
#define memset(x, y, z)
Definition: compat.h:39
#define win_skip
Definition: test.h:150
static int WINAPIV _vswprintf_p_l_wrapper(wchar_t *str, size_t size, const wchar_t *format, void *locale,...)
Definition: printf.c:1305

Referenced by START_TEST().

◆ test_xcvt()

static void test_xcvt ( void  )
static

Definition at line 1115 of file printf.c.

1116 {
1117  char *str;
1118  int i, decpt, sign, err;
1119 
1120  for( i = 0; strcmp( test_cvt_testcases[i].expstr_e, "END"); i++){
1121  decpt = sign = 100;
1124  &decpt,
1125  &sign);
1126  ok( 0 == strncmp( str, test_cvt_testcases[i].expstr_e, 15),
1127  "_ecvt() bad return, got \n'%s' expected \n'%s'\n", str,
1130  "_ecvt() decimal point wrong, got %d expected %d\n", decpt,
1133  "_ecvt() sign wrong, got %d expected %d\n", sign,
1135  }
1136  for( i = 0; strcmp( test_cvt_testcases[i].expstr_e, "END"); i++){
1137  decpt = sign = 100;
1140  &decpt,
1141  &sign);
1142  ok( 0 == strncmp( str, test_cvt_testcases[i].expstr_f, 15),
1143  "_fcvt() bad return, got \n'%s' expected \n'%s'\n", str,
1146  "_fcvt() decimal point wrong, got %d expected %d\n", decpt,
1149  "_fcvt() sign wrong, got %d expected %d\n", sign,
1151  }
1152 
1153  if (p__ecvt_s)
1154  {
1155  str = malloc(1024);
1156  for( i = 0; strcmp( test_cvt_testcases[i].expstr_e, "END"); i++){
1157  decpt = sign = 100;
1158  err = p__ecvt_s(str, 1024, test_cvt_testcases[i].value, test_cvt_testcases[i].nrdigits, &decpt, &sign);
1159  ok(err == 0, "_ecvt_s() failed with error code %d\n", err);
1160  ok( 0 == strncmp( str, test_cvt_testcases[i].expstr_e, 15),
1161  "_ecvt_s() bad return, got \n'%s' expected \n'%s'\n", str,
1164  "_ecvt_s() decimal point wrong, got %d expected %d\n", decpt,
1167  "_ecvt_s() sign wrong, got %d expected %d\n", sign,
1169  }
1170  free(str);
1171  }
1172  else
1173  win_skip("_ecvt_s not available\n");
1174 
1175  if (p__fcvt_s)
1176  {
1177  int i;
1178 
1179  str = malloc(1024);
1180 
1181  /* invalid arguments */
1182  err = p__fcvt_s(NULL, 0, 0.0, 0, &i, &i);
1183  ok(err == EINVAL, "got %d, expected EINVAL\n", err);
1184 
1185  err = p__fcvt_s(str, 0, 0.0, 0, &i, &i);
1186  ok(err == EINVAL, "got %d, expected EINVAL\n", err);
1187 
1188  str[0] = ' ';
1189  str[1] = 0;
1190  err = p__fcvt_s(str, -1, 0.0, 0, &i, &i);
1191  ok(err == 0, "got %d, expected 0\n", err);
1192  ok(str[0] == 0, "got %c, expected 0\n", str[0]);
1193  ok(str[1] == 0, "got %c, expected 0\n", str[1]);
1194 
1195  err = p__fcvt_s(str, 1, 0.0, 0, NULL, &i);
1196  ok(err == EINVAL, "got %d, expected EINVAL\n", err);
1197 
1198  err = p__fcvt_s(str, 1, 0.0, 0, &i, NULL);
1199  ok(err == EINVAL, "got %d, expected EINVAL\n", err);
1200 
1201  for( i = 0; strcmp( test_cvt_testcases[i].expstr_e, "END"); i++){
1202  decpt = sign = 100;
1203  err = p__fcvt_s(str, 1024, test_cvt_testcases[i].value, test_cvt_testcases[i].nrdigits, &decpt, &sign);
1204  ok(err == 0, "_fcvt_s() failed with error code %d\n", err);
1205  ok( 0 == strncmp( str, test_cvt_testcases[i].expstr_f, 15),
1206  "_fcvt_s() bad return, got '%s' expected '%s'. test %d\n", str,
1209  "_fcvt_s() decimal point wrong, got %d expected %d\n", decpt,
1212  "_fcvt_s() sign wrong, got %d expected %d\n", sign,
1214  }
1215  free(str);
1216  }
1217  else
1218  win_skip("_fcvt_s not available\n");
1219 }
static size_t double int int int * sign
Definition: printf.c:69
static struct @1634 test_cvt_testcases[]
int expdecpt_f
Definition: printf.c:1073
int nrdigits
Definition: printf.c:1069
int expsign
Definition: printf.c:1074
Definition: arc.h:39
#define free
Definition: debug_ros.c:5
const char * expstr_e
Definition: printf.c:1070
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
int expdecpt_e
Definition: printf.c:1072
static size_t double int int * decpt
Definition: printf.c:69
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
_Check_return_ _CRTIMP char *__cdecl _fcvt(_In_ double _Val, _In_ int _NumOfDec, _Out_ int *_PtDec, _Out_ int *_PtSign)
const char * expstr_f
Definition: printf.c:1071
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
#define err(...)
#define ok(value,...)
Definition: atltest.h:57
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define malloc
Definition: debug_ros.c:4
_Check_return_ _CRTIMP char *__cdecl _ecvt(_In_ double _Val, _In_ int _NumOfDigits, _Out_ int *_PtDec, _Out_ int *_PtSign)
#define win_skip
Definition: test.h:150

Referenced by START_TEST().

◆ vswprintf_wrapper()

static int WINAPIV vswprintf_wrapper ( wchar_t str,
const wchar_t format,
  ... 
)
static

Definition at line 1255 of file printf.c.

1256 {
1257  int ret;
1260  ret = p_vswprintf(str, format, valist);
1262  return ret;
1263 }
static static const char __ms_va_list
Definition: printf.c:76
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
const WCHAR * str
int ret
#define __ms_va_end(list)
Definition: windef.h:458
#define __ms_va_start(list, arg)
Definition: windef.h:457
static __ms_va_list valist
Definition: printf.c:64

Referenced by test_vswprintf().

Variable Documentation

◆ __ms_va_list

◆ count

Definition at line 66 of file printf.c.

◆ decpt

static size_t double int int * decpt

Definition at line 69 of file printf.c.

Referenced by __get_floor_digits(), __write_floatT(), _ecvt(), _fcvt(), cvt(), fcvtbuf(), ftoes(), ftofs(), and test_xcvt().

◆ expdecpt_e

int expdecpt_e

Definition at line 1072 of file printf.c.

Referenced by test_xcvt().

◆ expdecpt_f

int expdecpt_f

Definition at line 1073 of file printf.c.

Referenced by test_xcvt().

◆ expsign

int expsign

Definition at line 1074 of file printf.c.

Referenced by test_xcvt().

◆ expstr_e

const char* expstr_e

Definition at line 1070 of file printf.c.

Referenced by test_xcvt().

◆ expstr_f

const char* expstr_f

Definition at line 1071 of file printf.c.

Referenced by test_xcvt().

◆ format

Definition at line 66 of file printf.c.

Referenced by test_snprintf(), and test_sprintf().

◆ length

Definition at line 69 of file printf.c.

◆ locale

◆ ndigits

◆ nrdigits

int nrdigits

Definition at line 1069 of file printf.c.

Referenced by test_xcvt().

◆ number

static size_t double number

Definition at line 69 of file printf.c.

Referenced by _chgsignl(), _copysignl(), alloc_number(), auto_rename(), cff_parse_fixed_dynamic(), cff_parse_real(), CheckColors(), create_error(), create_number(), create_number_constr(), CreateDeviceName(), DATETIME_IncreaseField(), DrawLeds(), EnumColorProfilesA(), EnumColorProfilesW(), evalStack(), even_or_odd(), exec_closeparent(), exec_infix2postfix(), fileformat_number(), get_stream_name(), get_tablecolumns(), get_value_bstr(), GetLocaleInfoW(), getprotobynumber(), ipv6_to_number(), Link(), mbstowcs(), mpg123_encodings(), mpg123_rates(), msi_table_load_transform(), myabs64(), Number_get_value(), Number_toExponential(), Number_toFixed(), Number_toPrecision(), Number_toString(), Number_valueOf(), number_with_units(), ParseFile(), query_headers(), sqrti(), TABLE_add_column(), table_calc_column_offsets(), TABLE_remove_column(), tabstops_proc(), test_EnumColorProfilesA(), test_EnumColorProfilesW(), test_enumdisplaydevices(), test_enumdisplaydevices_adapter(), test_enumdisplaydevices_monitor(), test_message_from_64bit_number(), test_sscanf(), test_VarFormatFromTokens(), test_vscwprintf(), test_vswprintf(), TRIO_ARGS1(), TRIO_ARGS2(), TRIO_ARGS3(), TRIO_ARGS4(), TRIO_ARGS5(), TRIO_ARGS6(), units_to_twips(), Unlink(), VfdCloseImage(), VfdOpenImage(), VfdSetGlobalLink(), VfdSetLocalLink(), VfdWriteProtect(), Widget_DoSomething(), WPRINTF_GetLen(), wvnsprintfA(), wvnsprintfW(), xmlReallocLoc(), xsltDefaultSortFunction(), xsltFormatNumberConversion(), xsltNumberFormat(), xsltNumberFormatAlpha(), xsltNumberFormatDecimal(), xsltNumberFormatGetValue(), xsltNumberFormatInsertNumbers(), and xsltNumberFormatRoman().

◆ sign

◆ size

Definition at line 81 of file printf.c.

◆ size_t

static size_t

Definition at line 76 of file printf.c.

◆ sizeOfBuffer

size_t sizeOfBuffer

Definition at line 66 of file printf.c.

Referenced by _sxprintf(), _vsnprintf_s(), _vsnwprintf_s_wrapper(), and _vsprintf_p_wrapper().

◆ test_cvt_testcases

struct { ... } test_cvt_testcases[]

Referenced by test_xcvt().

◆ valist

◆ value

Definition at line 1068 of file printf.c.