ReactOS 0.4.15-dev-7918-g2a2556c
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 27 of file printf.c.

◆ IND

#define IND   __port_ind()

Definition at line 64 of file printf.c.

◆ INFINITY

#define INFINITY   __port_infinity()

Definition at line 48 of file printf.c.

◆ NAN

#define NAN   __port_nan()

Definition at line 55 of file printf.c.

Function Documentation

◆ __port_ind()

static float __port_ind ( void  )
inlinestatic

Definition at line 59 of file printf.c.

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

◆ __port_infinity()

static float __port_infinity ( void  )
inlinestatic

Definition at line 43 of file printf.c.

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

◆ __port_nan()

static float __port_nan ( void  )
inlinestatic

Definition at line 50 of file printf.c.

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

◆ _vscprintf_wrapper()

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

Definition at line 1363 of file printf.c.

1364{
1365 int ret;
1368 ret = p__vscprintf(format, valist);
1370 return ret;
1371}
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
static __ms_va_list valist
Definition: printf.c:66
static static const char __ms_va_list
Definition: printf.c:78
int ret
#define __ms_va_end(list)
Definition: windef.h:458
#define __ms_va_start(list, arg)
Definition: windef.h:457

Referenced by test_vscprintf().

◆ _vscwprintf_wrapper()

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

Definition at line 1387 of file printf.c.

1388{
1389 int ret;
1392 ret = p__vscwprintf(format, valist);
1394 return ret;
1395}

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 1414 of file printf.c.

1416{
1417 int ret;
1420 ret = p__vsnwprintf_s(str, sizeOfBuffer, count, format, valist);
1422 return ret;
1423}
GLuint GLuint GLsizei count
Definition: gl.h:1545
static size_t sizeOfBuffer
Definition: printf.c:68
const WCHAR * str

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 1223 of file printf.c.

1224{
1225 int ret;
1230 return ret;
1231}
GLenum GLsizei len
Definition: glext.h:6722
_CRTIMP int __cdecl _vsnwprintf(wchar_t *_Dest, size_t _Count, const wchar_t *_Format, va_list _Args)

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 1472 of file printf.c.

1474{
1475 int ret;
1478 ret = p__vsprintf_p(str, sizeOfBuffer, format, valist);
1480 return ret;
1481}

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 1297 of file printf.c.

1298{
1299 int ret;
1302 ret = p__vswprintf_c_l(str, size, format, locale, valist);
1304 return ret;
1305}
Definition: _locale.h:75
GLsizeiptr size
Definition: glext.h:5919

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 1287 of file printf.c.

1288{
1289 int ret;
1292 ret = p__vswprintf_c(str, size, format, valist);
1294 return ret;
1295}

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 1277 of file printf.c.

1278{
1279 int ret;
1282 ret = p__vswprintf_l(str, format, locale, valist);
1284 return ret;
1285}

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 1307 of file printf.c.

1308{
1309 int ret;
1312 ret = p__vswprintf_p_l(str, size, format, locale, valist);
1314 return ret;
1315}

Referenced by test_vswprintf().

◆ _vswprintf_wrapper()

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

Definition at line 1267 of file printf.c.

1268{
1269 int ret;
1272 ret = p__vswprintf(str, format, valist);
1274 return ret;
1275}

Referenced by test_vswprintf().

◆ init()

static void init ( void  )
static

Definition at line 90 of file printf.c.

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

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 1546 of file printf.c.

1547{
1548 init();
1549
1550 test_sprintf();
1551 test_swprintf();
1552 test_snprintf();
1553 test_fprintf();
1554 test_fcvt();
1555 test_xcvt();
1563}
static void test_vsnwprintf_s(void)
Definition: printf.c:1425
static void test_vsnwprintf(void)
Definition: printf.c:1233
static void init(void)
Definition: printf.c:90
static void test_swprintf(void)
Definition: printf.c:833
static void test_sprintf(void)
Definition: printf.c:111
static void test__get_output_format(void)
Definition: printf.c:1513
static void test_vsprintf_p(void)
Definition: printf.c:1483
static void test_vscprintf(void)
Definition: printf.c:1373
static void test_fprintf(void)
Definition: printf.c:883
static void test_snprintf(void)
Definition: printf.c:855
static void test_vscwprintf(void)
Definition: printf.c:1397
static void test_vswprintf(void)
Definition: printf.c:1317
static void test_fcvt(void)
Definition: printf.c:970
static void test_xcvt(void)
Definition: printf.c:1117

◆ test__get_output_format()

static void test__get_output_format ( void  )
static

Definition at line 1513 of file printf.c.

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

Referenced by START_TEST().

◆ test_fcvt()

static void test_fcvt ( void  )
static

Definition at line 970 of file printf.c.

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

Referenced by START_TEST().

◆ test_fprintf()

static void test_fprintf ( void  )
static

Definition at line 883 of file printf.c.

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

Referenced by START_TEST().

◆ test_snprintf()

static void test_snprintf ( void  )
static

Definition at line 855 of file printf.c.

856{
857 struct snprintf_test {
858 const char *format;
859 int expected;
860 };
861 /* Pre-2.1 libc behaviour, not C99 compliant. */
862 const struct snprintf_test tests[] = {{"short", 5},
863 {"justfit", 7},
864 {"justfits", 8},
865 {"muchlonger", -1}};
866 char buffer[8];
867 const int bufsiz = sizeof buffer;
868 unsigned int i;
869
870 for (i = 0; i < ARRAY_SIZE(tests); i++) {
871 const char *fmt = tests[i].format;
872 const int expect = tests[i].expected;
873 const int n = _snprintf (buffer, bufsiz, fmt);
874 const int valid = n < 0 ? bufsiz : (n == bufsiz ? n : n+1);
875
876 ok (n == expect, "\"%s\": expected %d, returned %d\n",
877 fmt, expect, n);
878 ok (!memcmp (fmt, buffer, valid),
879 "\"%s\": rendered \"%.*s\"\n", fmt, valid, buffer);
880 }
881}
#define expect(EXPECTED, GOT)
Definition: SystemMenu.c:483
#define ARRAY_SIZE(A)
Definition: main.h:33
BOOLEAN valid
GLdouble n
Definition: glext.h:7729
GLuint buffer
Definition: glext.h:5915
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 struct test_info tests[]
BOOL expected
Definition: store.c:2063
Definition: dsound.c:943
#define _snprintf
Definition: xmlstorage.h:200

Referenced by START_TEST().

◆ test_sprintf()

static void test_sprintf ( void  )
static

Definition at line 111 of file printf.c.

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

Referenced by START_TEST().

◆ test_swprintf()

static void test_swprintf ( void  )
static

Definition at line 833 of file printf.c.

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

Referenced by START_TEST().

◆ test_vscprintf()

static void test_vscprintf ( void  )
static

Definition at line 1373 of file printf.c.

1374{
1375 int ret;
1376
1377 if (!p__vscprintf)
1378 {
1379 win_skip("_vscprintf not available\n");
1380 return;
1381 }
1382
1383 ret = _vscprintf_wrapper( "%s %d", "number", 1 );
1384 ok( ret == 8, "got %d expected 8\n", ret );
1385}
static int WINAPIV _vscprintf_wrapper(const char *format,...)
Definition: printf.c:1363

Referenced by START_TEST().

◆ test_vscwprintf()

static void test_vscwprintf ( void  )
static

Definition at line 1397 of file printf.c.

1398{
1399 const wchar_t format[] = {'%','s',' ','%','d',0};
1400 const wchar_t number[] = {'n','u','m','b','e','r',0};
1401
1402 int ret;
1403
1404 if (!p__vscwprintf)
1405 {
1406 win_skip("_vscwprintf not available\n");
1407 return;
1408 }
1409
1411 ok( ret == 8, "got %d expected 8\n", ret );
1412}
static int WINAPIV _vscwprintf_wrapper(const wchar_t *format,...)
Definition: printf.c:1387
static size_t double number
Definition: printf.c:71

Referenced by START_TEST().

◆ test_vsnwprintf()

static void test_vsnwprintf ( void  )
static

Definition at line 1233 of file printf.c.

1234{
1235 const wchar_t format[] = {'%','w','s','%','w','s','%','w','s',0};
1236 const wchar_t one[] = {'o','n','e',0};
1237 const wchar_t two[] = {'t','w','o',0};
1238 const wchar_t three[] = {'t','h','r','e','e',0};
1239
1240 int ret;
1241 wchar_t str[32];
1242 char buf[32];
1243
1245
1246 ok( ret == 11, "got %d expected 11\n", ret );
1247 WideCharToMultiByte( CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL );
1248 ok( !strcmp(buf, "onetwothree"), "got %s expected 'onetwothree'\n", buf );
1249
1250 ret = _vsnwprintf_wrapper( str, 0, format, one, two, three );
1251 ok( ret == -1, "got %d, expected -1\n", ret );
1252
1253 ret = _vsnwprintf_wrapper( NULL, 0, format, one, two, three );
1254 ok( ret == 11 || broken(ret == -1 /* Win2k */), "got %d, expected 11\n", ret );
1255}
#define NULL
Definition: types.h:112
#define CP_ACP
Definition: compat.h:109
#define WideCharToMultiByte
Definition: compat.h:111
static double two
Definition: jn_yn.c:52
static int WINAPIV _vsnwprintf_wrapper(wchar_t *str, size_t len, const wchar_t *format,...)
Definition: printf.c:1223
int one
Definition: sehframes.cpp:28

Referenced by START_TEST().

◆ test_vsnwprintf_s()

static void test_vsnwprintf_s ( void  )
static

Definition at line 1425 of file printf.c.

1426{
1427 const wchar_t format[] = { 'A','B','%','u','C',0 };
1428 const wchar_t out7[] = { 'A','B','1','2','3','C',0 };
1429 const wchar_t out6[] = { 'A','B','1','2','3',0 };
1430 const wchar_t out2[] = { 'A',0 };
1431 const wchar_t out1[] = { 0 };
1432 wchar_t buffer[14] = { 0 };
1433 int exp, got;
1434
1435 if (!p__vsnwprintf_s)
1436 {
1437 win_skip("_vsnwprintf_s not available\n");
1438 return;
1439 }
1440
1441 /* Enough room. */
1442 exp = wcslen(out7);
1443
1444 got = _vsnwprintf_s_wrapper(buffer, 14, _TRUNCATE, format, 123);
1445 ok( exp == got, "length wrong, expect=%d, got=%d\n", exp, got);
1446 ok( !wcscmp(out7, buffer), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer));
1447
1448 got = _vsnwprintf_s_wrapper(buffer, 12, _TRUNCATE, format, 123);
1449 ok( exp == got, "length wrong, expect=%d, got=%d\n", exp, got);
1450 ok( !wcscmp(out7, buffer), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer));
1451
1453 ok( exp == got, "length wrong, expect=%d, got=%d\n", exp, got);
1454 ok( !wcscmp(out7, buffer), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer));
1455
1456 /* Not enough room. */
1457 exp = -1;
1458
1460 ok( exp == got, "length wrong, expect=%d, got=%d\n", exp, got);
1461 ok( !wcscmp(out6, buffer), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer));
1462
1464 ok( exp == got, "length wrong, expect=%d, got=%d\n", exp, got);
1465 ok( !wcscmp(out2, buffer), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer));
1466
1468 ok( exp == got, "length wrong, expect=%d, got=%d\n", exp, got);
1469 ok( !wcscmp(out1, buffer), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer));
1470}
#define _TRUNCATE
Definition: crtdefs.h:262
static int WINAPIV _vsnwprintf_s_wrapper(wchar_t *str, size_t sizeOfBuffer, size_t count, const wchar_t *format,...)
Definition: printf.c:1414
DWORD exp
Definition: msg.c:16058

Referenced by START_TEST().

◆ test_vsprintf_p()

static void test_vsprintf_p ( void  )
static

Definition at line 1483 of file printf.c.

1484{
1485 char buf[1024];
1486 int ret;
1487
1488 if(!p__vsprintf_p) {
1489 win_skip("vsprintf_p not available\n");
1490 return;
1491 }
1492
1493 ret = _vsprintf_p_wrapper(buf, sizeof(buf), "%s %d", "test", 1234);
1494 ok(ret == 9, "ret = %d\n", ret);
1495 ok(!memcmp(buf, "test 1234", 10), "buf = %s\n", buf);
1496
1497 ret = _vsprintf_p_wrapper(buf, sizeof(buf), "%1$d", 1234, "additional param");
1498 ok(ret == 4, "ret = %d\n", ret);
1499 ok(!memcmp(buf, "1234", 5), "buf = %s\n", buf);
1500
1501 ret = _vsprintf_p_wrapper(buf, sizeof(buf), "%2$s %1$d", 1234, "test");
1502 ok(ret == 9, "ret = %d\n", ret);
1503 ok(!memcmp(buf, "test 1234", 10), "buf = %s\n", buf);
1504
1505 ret = _vsprintf_p_wrapper(buf, sizeof(buf), "%2$*3$s %2$.*1$s", 2, "test", 3);
1506 ok(ret == 7, "ret = %d\n", ret);
1507 ok(!memcmp(buf, "test te", 8), "buf = %s\n", buf);
1508
1509 /* Following test invokes invalid parameter handler */
1510 /* ret = _vsprintf_p_wrapper(buf, sizeof(buf), "%d %1$d", 1234); */
1511}
static int WINAPIV _vsprintf_p_wrapper(char *str, size_t sizeOfBuffer, const char *format,...)
Definition: printf.c:1472

Referenced by START_TEST().

◆ test_vswprintf()

static void test_vswprintf ( void  )
static

Definition at line 1317 of file printf.c.

1318{
1319 const wchar_t format[] = {'%','s',' ','%','d',0};
1320 const wchar_t number[] = {'n','u','m','b','e','r',0};
1321 const wchar_t out[] = {'n','u','m','b','e','r',' ','1','2','3',0};
1322 wchar_t buf[20];
1323
1324 int ret;
1325
1326 if (!p_vswprintf || !p__vswprintf || !p__vswprintf_l ||!p__vswprintf_c
1327 || !p__vswprintf_c_l || !p__vswprintf_p_l)
1328 {
1329 win_skip("_vswprintf or vswprintf not available\n");
1330 return;
1331 }
1332
1334 ok(ret == 10, "got %d, expected 10\n", ret);
1335 ok(!memcmp(buf, out, sizeof(out)), "buf = %s\n", wine_dbgstr_w(buf));
1336
1337 memset(buf, 0, sizeof(buf));
1339 ok(ret == 10, "got %d, expected 10\n", ret);
1340 ok(!memcmp(buf, out, sizeof(out)), "buf = %s\n", wine_dbgstr_w(buf));
1341
1342 memset(buf, 0, sizeof(buf));
1344 ok(ret == 10, "got %d, expected 10\n", ret);
1345 ok(!memcmp(buf, out, sizeof(out)), "buf = %s\n", wine_dbgstr_w(buf));
1346
1347 memset(buf, 0, sizeof(buf));
1349 ok(ret == 10, "got %d, expected 10\n", ret);
1350 ok(!memcmp(buf, out, sizeof(out)), "buf = %s\n", wine_dbgstr_w(buf));
1351
1352 memset(buf, 0, sizeof(buf));
1354 ok(ret == 10, "got %d, expected 10\n", ret);
1355 ok(!memcmp(buf, out, sizeof(out)), "buf = %s\n", wine_dbgstr_w(buf));
1356
1357 memset(buf, 0, sizeof(buf));
1359 ok(ret == 10, "got %d, expected 10\n", ret);
1360 ok(!memcmp(buf, out, sizeof(out)), "buf = %s\n", wine_dbgstr_w(buf));
1361}
static int WINAPIV vswprintf_wrapper(wchar_t *str, const wchar_t *format,...)
Definition: printf.c:1257
static int WINAPIV _vswprintf_p_l_wrapper(wchar_t *str, size_t size, const wchar_t *format, void *locale,...)
Definition: printf.c:1307
static int WINAPIV _vswprintf_l_wrapper(wchar_t *str, const wchar_t *format, void *locale,...)
Definition: printf.c:1277
static int WINAPIV _vswprintf_c_l_wrapper(wchar_t *str, size_t size, const wchar_t *format, void *locale,...)
Definition: printf.c:1297
static int WINAPIV _vswprintf_wrapper(wchar_t *str, const wchar_t *format,...)
Definition: printf.c:1267
static int WINAPIV _vswprintf_c_wrapper(wchar_t *str, size_t size, const wchar_t *format,...)
Definition: printf.c:1287
static FILE * out
Definition: regtests2xml.c:44

Referenced by START_TEST().

◆ test_xcvt()

static void test_xcvt ( void  )
static

Definition at line 1117 of file printf.c.

1118{
1119 char *str;
1120 int i, decpt, sign, err;
1121
1122 for( i = 0; strcmp( test_cvt_testcases[i].expstr_e, "END"); i++){
1123 decpt = sign = 100;
1126 &decpt,
1127 &sign);
1128 ok( 0 == strncmp( str, test_cvt_testcases[i].expstr_e, 15),
1129 "_ecvt() bad return, got \n'%s' expected \n'%s'\n", str,
1132 "_ecvt() decimal point wrong, got %d expected %d\n", decpt,
1135 "_ecvt() sign wrong, got %d expected %d\n", sign,
1137 }
1138 for( i = 0; strcmp( test_cvt_testcases[i].expstr_e, "END"); i++){
1139 decpt = sign = 100;
1142 &decpt,
1143 &sign);
1144 ok( 0 == strncmp( str, test_cvt_testcases[i].expstr_f, 15),
1145 "_fcvt() bad return, got \n'%s' expected \n'%s'\n", str,
1148 "_fcvt() decimal point wrong, got %d expected %d\n", decpt,
1151 "_fcvt() sign wrong, got %d expected %d\n", sign,
1153 }
1154
1155 if (p__ecvt_s)
1156 {
1157 str = malloc(1024);
1158 for( i = 0; strcmp( test_cvt_testcases[i].expstr_e, "END"); i++){
1159 decpt = sign = 100;
1161 ok(err == 0, "_ecvt_s() failed with error code %d\n", err);
1162 ok( 0 == strncmp( str, test_cvt_testcases[i].expstr_e, 15),
1163 "_ecvt_s() bad return, got \n'%s' expected \n'%s'\n", str,
1166 "_ecvt_s() decimal point wrong, got %d expected %d\n", decpt,
1169 "_ecvt_s() sign wrong, got %d expected %d\n", sign,
1171 }
1172 free(str);
1173 }
1174 else
1175 win_skip("_ecvt_s not available\n");
1176
1177 if (p__fcvt_s)
1178 {
1179 int i;
1180
1181 str = malloc(1024);
1182
1183 /* invalid arguments */
1184 err = p__fcvt_s(NULL, 0, 0.0, 0, &i, &i);
1185 ok(err == EINVAL, "got %d, expected EINVAL\n", err);
1186
1187 err = p__fcvt_s(str, 0, 0.0, 0, &i, &i);
1188 ok(err == EINVAL, "got %d, expected EINVAL\n", err);
1189
1190 str[0] = ' ';
1191 str[1] = 0;
1192 err = p__fcvt_s(str, -1, 0.0, 0, &i, &i);
1193 ok(err == 0, "got %d, expected 0\n", err);
1194 ok(str[0] == 0, "got %c, expected 0\n", str[0]);
1195 ok(str[1] == 0, "got %c, expected 0\n", str[1]);
1196
1197 err = p__fcvt_s(str, 1, 0.0, 0, NULL, &i);
1198 ok(err == EINVAL, "got %d, expected EINVAL\n", err);
1199
1200 err = p__fcvt_s(str, 1, 0.0, 0, &i, NULL);
1201 ok(err == EINVAL, "got %d, expected EINVAL\n", err);
1202
1203 for( i = 0; strcmp( test_cvt_testcases[i].expstr_e, "END"); i++){
1204 decpt = sign = 100;
1206 ok(err == 0, "_fcvt_s() failed with error code %d\n", err);
1207 ok( 0 == strncmp( str, test_cvt_testcases[i].expstr_f, 15),
1208 "_fcvt_s() bad return, got '%s' expected '%s'. test %d\n", str,
1211 "_fcvt_s() decimal point wrong, got %d expected %d\n", decpt,
1214 "_fcvt_s() sign wrong, got %d expected %d\n", sign,
1216 }
1217 free(str);
1218 }
1219 else
1220 win_skip("_fcvt_s not available\n");
1221}
#define EINVAL
Definition: acclib.h:90
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
#define free
Definition: debug_ros.c:5
#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)
const char * expstr_f
Definition: printf.c:1073
const char * expstr_e
Definition: printf.c:1072
static struct @1680 test_cvt_testcases[]
int expdecpt_e
Definition: printf.c:1074
int expdecpt_f
Definition: printf.c:1075
int nrdigits
Definition: printf.c:1071
static size_t double int int * decpt
Definition: printf.c:72
int expsign
Definition: printf.c:1076
#define err(...)
Definition: pdh_main.c:94

Referenced by START_TEST().

◆ vswprintf_wrapper()

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

Definition at line 1257 of file printf.c.

1258{
1259 int ret;
1262 ret = p_vswprintf(str, format, valist);
1264 return ret;
1265}

Referenced by test_vswprintf().

Variable Documentation

◆ __ms_va_list

◆ count

Definition at line 69 of file printf.c.

◆ decpt

static size_t double int int * decpt

Definition at line 72 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 1074 of file printf.c.

Referenced by test_xcvt().

◆ expdecpt_f

int expdecpt_f

Definition at line 1075 of file printf.c.

Referenced by test_xcvt().

◆ expsign

int expsign

Definition at line 1076 of file printf.c.

Referenced by test_xcvt().

◆ expstr_e

const char* expstr_e

Definition at line 1072 of file printf.c.

Referenced by test_xcvt().

◆ expstr_f

const char* expstr_f

Definition at line 1073 of file printf.c.

Referenced by test_xcvt().

◆ format

Definition at line 69 of file printf.c.

Referenced by test_sprintf().

◆ length

Definition at line 71 of file printf.c.

◆ locale

Definition at line 82 of file printf.c.

◆ ndigits

◆ nrdigits

int nrdigits

Definition at line 1071 of file printf.c.

Referenced by test_xcvt().

◆ number

static size_t double number

Definition at line 71 of file printf.c.

Referenced by test_vscwprintf(), and test_vswprintf().

◆ sign

static size_t double int int int * sign

Definition at line 72 of file printf.c.

Referenced by test_fcvt(), and test_xcvt().

◆ size

Definition at line 83 of file printf.c.

◆ size_t

static size_t

Definition at line 78 of file printf.c.

◆ sizeOfBuffer

size_t sizeOfBuffer

Definition at line 68 of file printf.c.

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

◆ 

struct { ... } test_cvt_testcases[]

Referenced by test_xcvt().

◆ valist

◆ value

Definition at line 1070 of file printf.c.