ReactOS 0.4.16-dev-753-g705a985
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 IND   __port_ind()
 

Functions

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

Function Documentation

◆ __port_ind()

static float __port_ind ( void  )
inlinestatic

Definition at line 39 of file printf.c.

40{
41 static const unsigned __ind_bytes = 0xffc00000;
42 return *(const float *)&__ind_bytes;
43}

◆ _vscprintf_wrapper()

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

Definition at line 960 of file printf.c.

961{
962 int ret;
965 ret = p__vscprintf(format, valist);
966 va_end(valist);
967 return ret;
968}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
static va_list valist
Definition: printf.c:46
Definition: format.c:58
int ret

Referenced by test_vscprintf().

◆ _vscwprintf_wrapper()

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

Definition at line 984 of file printf.c.

985{
986 int ret;
989 ret = p__vscwprintf(format, valist);
990 va_end(valist);
991 return ret;
992}

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

1010{
1011 int ret;
1014 ret = p__vsnwprintf_s(str, sizeOfBuffer, count, format, valist);
1015 va_end(valist);
1016 return ret;
1017}
GLuint GLuint GLsizei count
Definition: gl.h:1545
static size_t sizeOfBuffer
Definition: printf.c:48
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 825 of file printf.c.

826{
827 int ret;
831 va_end(valist);
832 return ret;
833}
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 1057 of file printf.c.

1059{
1060 int ret;
1063 ret = p__vsprintf_p(str, sizeOfBuffer, format, valist);
1064 va_end(valist);
1065 return ret;
1066}

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

894{
895 int ret;
898 ret = p__vswprintf_c_l(str, size, format, locale, valist);
899 va_end(valist);
900 return ret;
901}
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 883 of file printf.c.

884{
885 int ret;
888 ret = p__vswprintf_c(str, size, format, valist);
889 va_end(valist);
890 return ret;
891}

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

874{
875 int ret;
878 ret = p__vswprintf_l(str, format, locale, valist);
879 va_end(valist);
880 return ret;
881}

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

904{
905 int ret;
908 ret = p__vswprintf_p_l(str, size, format, locale, valist);
909 va_end(valist);
910 return ret;
911}

Referenced by test_vswprintf().

◆ _vswprintf_wrapper()

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

Definition at line 863 of file printf.c.

864{
865 int ret;
868 ret = p__vswprintf(str, format, valist);
869 va_end(valist);
870 return ret;
871}

Referenced by test_vswprintf().

◆ init()

static void init ( void  )
static

Definition at line 70 of file printf.c.

71{
72 HMODULE hmod = GetModuleHandleA("msvcrt.dll");
73
74 p_sprintf = (void *)GetProcAddress(hmod, "sprintf");
75 p__vscprintf = (void *)GetProcAddress(hmod, "_vscprintf");
76 p__vscwprintf = (void *)GetProcAddress(hmod, "_vscwprintf");
77 p__vsnwprintf_s = (void *)GetProcAddress(hmod, "_vsnwprintf_s");
78 p__ecvt_s = (void *)GetProcAddress(hmod, "_ecvt_s");
79 p__fcvt_s = (void *)GetProcAddress(hmod, "_fcvt_s");
80 p__get_output_format = (void *)GetProcAddress(hmod, "_get_output_format");
81 p__set_output_format = (void *)GetProcAddress(hmod, "_set_output_format");
82 p__vsprintf_p = (void*)GetProcAddress(hmod, "_vsprintf_p");
83 p_vswprintf = (void*)GetProcAddress(hmod, "vswprintf");
84 p__vswprintf = (void*)GetProcAddress(hmod, "_vswprintf");
85 p__vswprintf_l = (void*)GetProcAddress(hmod, "_vswprintf_l");
86 p__vswprintf_c = (void*)GetProcAddress(hmod, "_vswprintf_c");
87 p__vswprintf_c_l = (void*)GetProcAddress(hmod, "_vswprintf_c_l");
88 p__vswprintf_p_l = (void*)GetProcAddress(hmod, "_vswprintf_p_l");
89}
#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 1131 of file printf.c.

1132{
1133 init();
1134
1135 test_sprintf();
1136 test_swprintf();
1137 test_snprintf();
1138 test_fprintf();
1139 test_fcvt();
1140 test_xcvt();
1148}
static void test_vsnwprintf_s(void)
Definition: printf.c:1019
static void test_vsnwprintf(void)
Definition: printf.c:835
static void init(void)
Definition: printf.c:70
static void test_swprintf(void)
Definition: printf.c:431
static void test_sprintf(void)
Definition: printf.c:91
static void test__get_output_format(void)
Definition: printf.c:1098
static void test_vsprintf_p(void)
Definition: printf.c:1068
static void test_vscprintf(void)
Definition: printf.c:970
static void test_fprintf(void)
Definition: printf.c:477
static void test_snprintf(void)
Definition: printf.c:447
static void test_vscwprintf(void)
Definition: printf.c:994
static void test_vswprintf(void)
Definition: printf.c:913
static void test_fcvt(void)
Definition: printf.c:560
static void test_xcvt(void)
Definition: printf.c:709

◆ test__get_output_format()

static void test__get_output_format ( void  )
static

Definition at line 1098 of file printf.c.

1099{
1100 unsigned int ret;
1101 char buf[64];
1102 int c;
1103
1104 if (!p__get_output_format || !p__set_output_format)
1105 {
1106 win_skip("_get_output_format or _set_output_format is not available\n");
1107 return;
1108 }
1109
1110 ret = p__get_output_format();
1111 ok(ret == 0, "got %d\n", ret);
1112
1113 c = p_sprintf(buf, "%E", 1.23);
1114 ok(c == 13, "c = %d\n", c);
1115 ok(!strcmp(buf, "1.230000E+000"), "buf = %s\n", buf);
1116
1117 ret = p__set_output_format(_TWO_DIGIT_EXPONENT);
1118 ok(ret == 0, "got %d\n", ret);
1119
1120 c = p_sprintf(buf, "%E", 1.23);
1121 ok(c == 12, "c = %d\n", c);
1122 ok(!strcmp(buf, "1.230000E+00"), "buf = %s\n", buf);
1123
1124 ret = p__get_output_format();
1125 ok(ret == _TWO_DIGIT_EXPONENT, "got %d\n", ret);
1126
1127 ret = p__set_output_format(_TWO_DIGIT_EXPONENT);
1128 ok(ret == _TWO_DIGIT_EXPONENT, "got %d\n", ret);
1129}
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:164

Referenced by START_TEST().

◆ test_fcvt()

static void test_fcvt ( void  )
static

Definition at line 560 of file printf.c.

561{
562 char *str;
563 int dec=100, sign=100;
564
565 /* Numbers less than 1.0 with different precisions */
566 str = _fcvt(0.0001, 1, &dec, &sign );
567 ok( 0 == strcmp(str,""), "bad return '%s'\n", str);
568 ok( -3 == dec, "dec wrong %d\n", dec);
569 ok( 0 == sign, "sign wrong\n");
570
571 str = _fcvt(0.0001, -10, &dec, &sign );
572 ok( 0 == strcmp(str,""), "bad return '%s'\n", str);
573 ok( -3 == dec, "dec wrong %d\n", dec);
574 ok( 0 == sign, "sign wrong\n");
575
576 str = _fcvt(0.0001, 10, &dec, &sign );
577 ok( 0 == strcmp(str,"1000000"), "bad return '%s'\n", str);
578 ok( -3 == dec, "dec wrong %d\n", dec);
579 ok( 0 == sign, "sign wrong\n");
580
581 /* Basic sign test */
582 str = _fcvt(-111.0001, 5, &dec, &sign );
583 ok( 0 == strcmp(str,"11100010"), "bad return '%s'\n", str);
584 ok( 3 == dec, "dec wrong %d\n", dec);
585 ok( 1 == sign, "sign wrong\n");
586
587 str = _fcvt(111.0001, 5, &dec, &sign );
588 ok( 0 == strcmp(str,"11100010"), "bad return '%s'\n", str);
589 ok( 3 == dec, "dec wrong\n");
590 ok( 0 == sign, "sign wrong\n");
591
592 /* 0.0 with different precisions */
593 str = _fcvt(0.0, 5, &dec, &sign );
594 ok( 0 == strcmp(str,"00000"), "bad return '%s'\n", str);
595 ok( 0 == dec, "dec wrong %d\n", dec);
596 ok( 0 == sign, "sign wrong\n");
597
598 str = _fcvt(0.0, 0, &dec, &sign );
599 ok( 0 == strcmp(str,""), "bad return '%s'\n", str);
600 ok( 0 == dec, "dec wrong %d\n", dec);
601 ok( 0 == sign, "sign wrong\n");
602
603 str = _fcvt(0.0, -1, &dec, &sign );
604 ok( 0 == strcmp(str,""), "bad return '%s'\n", str);
605 ok( 0 == dec, "dec wrong %d\n", dec);
606 ok( 0 == sign, "sign wrong\n");
607
608 /* Numbers > 1.0 with 0 or -ve precision */
609 str = _fcvt(-123.0001, 0, &dec, &sign );
610 ok( 0 == strcmp(str,"123"), "bad return '%s'\n", str);
611 ok( 3 == dec, "dec wrong %d\n", dec);
612 ok( 1 == sign, "sign wrong\n");
613
614 str = _fcvt(-123.0001, -1, &dec, &sign );
615 ok( 0 == strcmp(str,"12"), "bad return '%s'\n", str);
616 ok( 3 == dec, "dec wrong %d\n", dec);
617 ok( 1 == sign, "sign wrong\n");
618
619 str = _fcvt(-123.0001, -2, &dec, &sign );
620 ok( 0 == strcmp(str,"1"), "bad return '%s'\n", str);
621 ok( 3 == dec, "dec wrong %d\n", dec);
622 ok( 1 == sign, "sign wrong\n");
623
624 str = _fcvt(-123.0001, -3, &dec, &sign );
625 ok( 0 == strcmp(str,""), "bad return '%s'\n", str);
626 ok( 3 == dec, "dec wrong %d\n", dec);
627 ok( 1 == sign, "sign wrong\n");
628
629 /* Numbers > 1.0, but with rounding at the point of precision */
630 str = _fcvt(99.99, 1, &dec, &sign );
631 ok( 0 == strcmp(str,"1000"), "bad return '%s'\n", str);
632 ok( 3 == dec, "dec wrong %d\n", dec);
633 ok( 0 == sign, "sign wrong\n");
634
635 /* Numbers < 1.0 where rounding occurs at the point of precision */
636 str = _fcvt(0.00636, 2, &dec, &sign );
637 ok( 0 == strcmp(str,"1"), "bad return '%s'\n", str);
638 ok( -1 == dec, "dec wrong %d\n", dec);
639 ok( 0 == sign, "sign wrong\n");
640
641 str = _fcvt(0.00636, 3, &dec, &sign );
642 ok( 0 == strcmp(str,"6"), "bad return '%s'\n", str);
643 ok( -2 == dec, "dec wrong %d\n", dec);
644 ok( 0 == sign, "sign wrong\n");
645
646 str = _fcvt(0.09999999996, 2, &dec, &sign );
647 ok( 0 == strcmp(str,"10"), "bad return '%s'\n", str);
648 ok( 0 == dec, "dec wrong %d\n", dec);
649 ok( 0 == sign, "sign wrong\n");
650
651 str = _fcvt(0.6, 0, &dec, &sign );
652 ok( 0 == strcmp(str,"1"), "bad return '%s'\n", str);
653 ok( 1 == dec, "dec wrong %d\n", dec);
654 ok( 0 == sign, "sign wrong\n");
655}
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:52

Referenced by START_TEST().

◆ test_fprintf()

static void test_fprintf ( void  )
static

Definition at line 477 of file printf.c.

478{
479 FILE *fp = fopen("fprintf.tst", "wb");
480 char buf[1024];
481 int ret;
482
483 ret = fprintf(fp, "simple test\n");
484 ok(ret == 12, "ret = %d\n", ret);
485 ret = ftell(fp);
486 ok(ret == 12, "ftell returned %d\n", ret);
487
488 ret = fprintf(fp, "contains%cnull\n", '\0');
489 ok(ret == 14, "ret = %d\n", ret);
490 ret = ftell(fp);
491 ok(ret == 26, "ftell returned %d\n", ret);
492
493 ret = fwprintf(fp, L"unicode\n");
494 ok(ret == 8, "ret = %d\n", ret);
495 ret = ftell(fp);
496 ok(ret == 42, "ftell returned %d\n", ret);
497
498 fclose(fp);
499
500 fp = fopen("fprintf.tst", "rb");
501 ret = fscanf(fp, "%[^\n] ", buf);
502 ok(ret == 1, "ret = %d\n", ret);
503 ret = ftell(fp);
504 ok(ret == 12, "ftell returned %d\n", ret);
505 ok(!strcmp(buf, "simple test"), "buf = %s\n", buf);
506
507 fgets(buf, sizeof(buf), fp);
508 ret = ftell(fp);
509 ok(ret == 26, "ret = %d\n", ret);
510 ok(!memcmp(buf, "contains\0null\n", 14), "buf = %s\n", buf);
511
512 memset(buf, 0, sizeof(buf));
513 fgets(buf, sizeof(buf), fp);
514 ret = ftell(fp);
515 ok(ret == 41, "ret = %d\n", ret);
516 ok(!wcscmp((wchar_t*)buf, L"unicode\n"), "buf = %s\n", wine_dbgstr_w((WCHAR*)buf));
517
518 fclose(fp);
519
520 fp = fopen("fprintf.tst", "wt");
521
522 ret = fprintf(fp, "simple test\n");
523 ok(ret == 12, "ret = %d\n", ret);
524 ret = ftell(fp);
525 ok(ret == 13, "ftell returned %d\n", ret);
526
527 ret = fprintf(fp, "contains%cnull\n", '\0');
528 ok(ret == 14, "ret = %d\n", ret);
529 ret = ftell(fp);
530 ok(ret == 28, "ftell returned %d\n", ret);
531
532 ret = fwprintf(fp, L"unicode\n");
533 ok(ret == 8, "ret = %d\n", ret);
534 ret = ftell(fp);
535 ok(ret == 37, "ftell returned %d\n", ret);
536
537 fclose(fp);
538
539 fp = fopen("fprintf.tst", "rb");
540 ret = fscanf(fp, "%[^\n] ", buf);
541 ok(ret == 1, "ret = %d\n", ret);
542 ret = ftell(fp);
543 ok(ret == 13, "ftell returned %d\n", ret);
544 ok(!strcmp(buf, "simple test\r"), "buf = %s\n", buf);
545
546 fgets(buf, sizeof(buf), fp);
547 ret = ftell(fp);
548 ok(ret == 28, "ret = %d\n", ret);
549 ok(!memcmp(buf, "contains\0null\r\n", 15), "buf = %s\n", buf);
550
551 fgets(buf, sizeof(buf), fp);
552 ret = ftell(fp);
553 ok(ret == 37, "ret = %d\n", ret);
554 ok(!strcmp(buf, "unicode\r\n"), "buf = %s\n", buf);
555
556 fclose(fp);
557 unlink("fprintf.tst");
558}
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
#define L(x)
Definition: ntvdm.h:50
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#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 447 of file printf.c.

448{
449 struct snprintf_test {
450 const char *format;
451 int expected;
452 };
453 /* Pre-2.1 libc behaviour, not C99 compliant. */
454 const struct snprintf_test tests[] = {{"short", 5},
455 {"justfit", 7},
456 {"justfits", 8},
457 {"muchlonger", -1}};
458 char buffer[8];
459 const int bufsiz = sizeof buffer;
460 unsigned int i;
461
462 int (__cdecl *p_snprintf)(char*,size_t,const char*,...) = _snprintf;
463
464 for (i = 0; i < ARRAY_SIZE(tests); i++) {
465 const char *fmt = tests[i].format;
466 const int expect = tests[i].expected;
467 const int n = p_snprintf(buffer, bufsiz, fmt);
468 const int valid = n < 0 ? bufsiz : (n == bufsiz ? n : n+1);
469
470 ok (n == expect, "\"%s\": expected %d, returned %d\n",
471 fmt, expect, n);
472 ok (!memcmp (fmt, buffer, valid),
473 "\"%s\": rendered \"%.*s\"\n", fmt, valid, buffer);
474 }
475}
#define expect(EXPECTED, GOT)
Definition: SystemMenu.c:483
#define __cdecl
Definition: accygwin.h:79
#define ARRAY_SIZE(A)
Definition: main.h:20
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
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
static static size_t
Definition: printf.c:58
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 91 of file printf.c.

92{
93 enum {
94 NO_ARG,
95 INT_ARG,
96 ULONGLONG_ARG,
97 DOUBLE_ARG,
98 PTR_ARG,
99 TODO_FLAG = 0x1000
100 };
101
102 struct {
103 const char *format;
104 const char *out;
105 const char *broken;
106 int type;
107 int arg_i;
108 ULONGLONG arg_ull;
109 double arg_d;
110 const void *arg_ptr;
111 } tests[] = {
112 { "%+#23.15e", "+7.894561230000000e+008", 0, DOUBLE_ARG, 0, 0, 789456123 },
113 { "%-#23.15e", "7.894561230000000e+008 ", 0, DOUBLE_ARG, 0, 0, 789456123 },
114 { "%#23.15e", " 7.894561230000000e+008", 0, DOUBLE_ARG, 0, 0, 789456123 },
115 { "%#1.1g", "8.e+008", 0, DOUBLE_ARG, 0, 0, 789456123 },
116 { "%I64d", "-8589934591", 0, ULONGLONG_ARG, 0, ((ULONGLONG)0xffffffff)*0xffffffff },
117 { "%+8I64d", " +100", 0, ULONGLONG_ARG, 0, 100 },
118 { "%+.8I64d", "+00000100", 0, ULONGLONG_ARG, 0, 100 },
119 { "%+10.8I64d", " +00000100", 0, ULONGLONG_ARG, 0, 100 },
120 { "%_1I64d", "_1I64d", 0, ULONGLONG_ARG, 0, 100 },
121 { "%-1.5I64d", "-00100", 0, ULONGLONG_ARG, 0, -100 },
122 { "%5I64d", " 100", 0, ULONGLONG_ARG, 0, 100 },
123 { "%5I64d", " -100", 0, ULONGLONG_ARG, 0, -100 },
124 { "%-5I64d", "100 ", 0, ULONGLONG_ARG, 0, 100 },
125 { "%-5I64d", "-100 ", 0, ULONGLONG_ARG, 0, -100 },
126 { "%-.5I64d", "00100", 0, ULONGLONG_ARG, 0, 100 },
127 { "%-.5I64d", "-00100", 0, ULONGLONG_ARG, 0, -100 },
128 { "%-8.5I64d", "00100 ", 0, ULONGLONG_ARG, 0, 100 },
129 { "%-8.5I64d", "-00100 ", 0, ULONGLONG_ARG, 0, -100 },
130 { "%05I64d", "00100", 0, ULONGLONG_ARG, 0, 100 },
131 { "%05I64d", "-0100", 0, ULONGLONG_ARG, 0, -100 },
132 { "% I64d", " 100", 0, ULONGLONG_ARG, 0, 100 },
133 { "% I64d", "-100", 0, ULONGLONG_ARG, 0, -100 },
134 { "% 5I64d", " 100", 0, ULONGLONG_ARG, 0, 100 },
135 { "% 5I64d", " -100", 0, ULONGLONG_ARG, 0, -100 },
136 { "% .5I64d", " 00100", 0, ULONGLONG_ARG, 0, 100 },
137 { "% .5I64d", "-00100", 0, ULONGLONG_ARG, 0, -100 },
138 { "% 8.5I64d", " 00100", 0, ULONGLONG_ARG, 0, 100 },
139 { "% 8.5I64d", " -00100", 0, ULONGLONG_ARG, 0, -100 },
140 { "%.0I64d", "", 0, ULONGLONG_ARG },
141 { "%#+21.18I64x", " 0x00ffffffffffffff9c", 0, ULONGLONG_ARG, 0, -100 },
142 { "%#.25I64o", "0001777777777777777777634", 0, ULONGLONG_ARG, 0, -100 },
143 { "%#+24.20I64o", " 01777777777777777777634", 0, ULONGLONG_ARG, 0, -100 },
144 { "%#+18.21I64X", "0X00000FFFFFFFFFFFFFF9C", 0, ULONGLONG_ARG, 0, -100 },
145 { "%#+20.24I64o", "001777777777777777777634", 0, ULONGLONG_ARG, 0, -100 },
146 { "%#+25.22I64u", " 0018446744073709551615", 0, ULONGLONG_ARG, 0, -1 },
147 { "%#+25.22I64u", " 0018446744073709551615", 0, ULONGLONG_ARG, 0, -1 },
148 { "%#+30.25I64u", " 0000018446744073709551615", 0, ULONGLONG_ARG, 0, -1 },
149 { "%+#25.22I64d", " -0000000000000000000001", 0, ULONGLONG_ARG, 0, -1 },
150 { "%#-8.5I64o", "00144 ", 0, ULONGLONG_ARG, 0, 100 },
151 { "%#-+ 08.5I64d", "+00100 ", 0, ULONGLONG_ARG, 0, 100 },
152 { "%.80I64d",
153 "00000000000000000000000000000000000000000000000000000000000000000000000000000001",
154 0, ULONGLONG_ARG, 0, 1 },
155 { "% .80I64d",
156 " 00000000000000000000000000000000000000000000000000000000000000000000000000000001",
157 0, ULONGLONG_ARG, 0, 1 },
158 { "% .80d",
159 " 00000000000000000000000000000000000000000000000000000000000000000000000000000001",
160 0, INT_ARG, 1 },
161 { "%I", "I", 0, INT_ARG, 1 },
162 { "%Iq", "Iq", 0, INT_ARG, 1 },
163 { "%Ihd", "Ihd", 0, INT_ARG, 1 },
164 { "%I0d", "I0d", 0, INT_ARG, 1 },
165 { "%I64D", "D", 0, ULONGLONG_ARG, 0, -1 },
166 { "%zx", "1", "zx", INT_ARG, 1 },
167 { "%z", "z", 0, INT_ARG, 1 },
168 { "%tx", "1", "tx", INT_ARG, 1 },
169 { "%t", "t", 0, INT_ARG, 1 },
170 { "% d", " 1", 0, INT_ARG, 1 },
171 { "%+ d", "+1", 0, INT_ARG, 1 },
172 { "%S", "wide", 0, PTR_ARG, 0, 0, 0, L"wide" },
173 { "%04c", "0001", 0, INT_ARG, '1' },
174 { "%-04c", "1 ", 0, INT_ARG, '1' },
175 { "%#012x", "0x0000000001", 0, INT_ARG, 1 },
176 { "%#012x", "000000000000", 0, INT_ARG, 0 },
177 { "%#04.8x", "0x00000001", 0, INT_ARG, 1 },
178 { "%#04.8x", "00000000", 0, INT_ARG, 0 },
179 { "%#-08.2x", "0x01 ", 0, INT_ARG, 1 },
180 { "%#-08.2x", "00 ", 0, INT_ARG, 0 },
181 { "%#.0x", "0x1", 0, INT_ARG, 1 },
182 { "%#.0x", "", 0, INT_ARG, 0 },
183 { "%#08o", "00000001", 0, INT_ARG, 1 },
184 { "%#o", "01", 0, INT_ARG, 1 },
185 { "%#o", "0", 0, INT_ARG, 0 },
186 { "%04s", "0foo", 0, PTR_ARG, 0, 0, 0, "foo" },
187 { "%.1s", "f", 0, PTR_ARG, 0, 0, 0, "foo" },
188 { "hello", "hello", 0, NO_ARG },
189 { "%ws", "wide", 0, PTR_ARG, 0, 0, 0, L"wide" },
190 { "%-10ws", "wide ", 0, PTR_ARG, 0, 0, 0, L"wide" },
191 { "%10ws", " wide", 0, PTR_ARG, 0, 0, 0, L"wide" },
192 { "%#+ -03whlls", "wide", 0, PTR_ARG, 0, 0, 0, L"wide" },
193 { "%w0s", "0s", 0, PTR_ARG, 0, 0, 0, L"wide" },
194 { "%w-s", "-s", 0, PTR_ARG, 0, 0, 0, L"wide" },
195 { "%ls", "wide", 0, PTR_ARG, 0, 0, 0, L"wide" },
196 { "%Ls", "not wide", 0, PTR_ARG, 0, 0, 0, "not wide" },
197 { "%b", "b", 0, NO_ARG },
198 { "%3c", " a", 0, INT_ARG, 'a' },
199 { "%3d", "1234", 0, INT_ARG, 1234 },
200 { "%3h", "", 0, NO_ARG },
201 { "%k%m%q%r%t%v%y%z", "kmqrtvyz", 0, NO_ARG },
202 { "%-1d", "2", 0, INT_ARG, 2 },
203 { "%2.4f", "8.6000", 0, DOUBLE_ARG, 0, 0, 8.6 },
204 { "%0f", "0.600000", 0, DOUBLE_ARG, 0, 0, 0.6 },
205 { "%.0f", "1", 0, DOUBLE_ARG, 0, 0, 0.6 },
206 { "%2.4e", "8.6000e+000", 0, DOUBLE_ARG, 0, 0, 8.6 },
207 { "% 2.4e", " 8.6000e+000", 0, DOUBLE_ARG, 0, 0, 8.6 },
208 { "% 014.4e", " 008.6000e+000", 0, DOUBLE_ARG, 0, 0, 8.6 },
209 { "% 2.4e", "-8.6000e+000", 0, DOUBLE_ARG, 0, 0, -8.6 },
210 { "%+2.4e", "+8.6000e+000", 0, DOUBLE_ARG, 0, 0, 8.6 },
211 { "%2.4g", "8.6", 0, DOUBLE_ARG, 0, 0, 8.6 },
212 { "%-i", "-1", 0, INT_ARG, -1 },
213 { "%-i", "1", 0, INT_ARG, 1 },
214 { "%+i", "+1", 0, INT_ARG, 1 },
215 { "%o", "12", 0, INT_ARG, 10 },
216 { "%s", "(null)", 0, PTR_ARG, 0, 0, 0, NULL },
217 { "%s", "%%%%", 0, PTR_ARG, 0, 0, 0, "%%%%" },
218 { "%u", "4294967295", 0, INT_ARG, -1 },
219 { "%w", "", 0, INT_ARG, -1 },
220 { "%h", "", 0, INT_ARG, -1 },
221 { "%j", "", "j", ULONGLONG_ARG, 0, -1 },
222 { "%jd", "-1", "jd", ULONGLONG_ARG, 0, -1 },
223 { "%F", "", 0, INT_ARG, -1 },
224 { "%N", "", 0, INT_ARG, -1 },
225 { "%H", "H", 0, INT_ARG, -1 },
226 { "x%cx", "xXx", 0, INT_ARG, 0x100+'X' },
227 { "%%0", "%0", 0, NO_ARG },
228 { "%hx", "2345", 0, INT_ARG, 0x12345 },
229 { "%hhx", "123", 0, INT_ARG, 0x123 },
230 { "%hhx", "2345", 0, INT_ARG, 0x12345 },
231 { "%lf", "-1.#IND00", 0, DOUBLE_ARG, 0, 0, IND },
232 { "%lf", "1.#QNAN0", 0, DOUBLE_ARG, 0, 0, NAN },
233 { "%lf", "1.#INF00", 0, DOUBLE_ARG, 0, 0, INFINITY },
234 { "%le", "-1.#IND00e+000", 0, DOUBLE_ARG, 0, 0, IND },
235 { "%le", "1.#QNAN0e+000", 0, DOUBLE_ARG, 0, 0, NAN },
236 { "%le", "1.#INF00e+000", 0, DOUBLE_ARG, 0, 0, INFINITY },
237 { "%lg", "-1.#IND", 0, DOUBLE_ARG, 0, 0, IND },
238 { "%lg", "1.#QNAN", 0, DOUBLE_ARG, 0, 0, NAN },
239 { "%lg", "1.#INF", 0, DOUBLE_ARG, 0, 0, INFINITY },
240 { "%010.2lf", "-000001.#J", 0, DOUBLE_ARG, 0, 0, IND },
241 { "%010.2lf", "0000001.#R", 0, DOUBLE_ARG, 0, 0, NAN },
242 { "%010.2lf", "0000001.#J", 0, DOUBLE_ARG, 0, 0, INFINITY },
243 { "%c", "a", 0, INT_ARG, 'a' },
244 { "%c", "\x82", 0, INT_ARG, 0xa082 },
245 { "%C", "a", 0, INT_ARG, 'a' },
246 { "%C", "", 0, INT_ARG, 0x3042 },
247 { "a%Cb", "ab", 0, INT_ARG, 0x3042 },
248 { "%lld", "-8589934591", "1", ULONGLONG_ARG, 0, ((ULONGLONG)0xffffffff)*0xffffffff },
249 { "%I32d", "1", "I32d", INT_ARG, 1 },
250 { "%.0f", "-2", 0, DOUBLE_ARG, 0, 0, -1.5 },
251 { "%.0f", "-1", 0, DOUBLE_ARG, 0, 0, -0.5 },
252 { "%.0f", "1", 0, DOUBLE_ARG, 0, 0, 0.5 },
253 { "%.0f", "2", 0, DOUBLE_ARG, 0, 0, 1.5 },
254 { "%.30f", "0.333333333333333310000000000000", 0, TODO_FLAG | DOUBLE_ARG, 0, 0, 1.0/3.0 },
255 { "%.30lf", "1.414213562373095100000000000000", 0, TODO_FLAG | DOUBLE_ARG, 0, 0, sqrt(2) },
256 { "%f", "3.141593", 0, DOUBLE_ARG, 0, 0, 3.141592653590000 },
257 { "%.10f", "3.1415926536", 0, DOUBLE_ARG, 0, 0, 3.141592653590000 },
258 { "%.11f", "3.14159265359", 0, DOUBLE_ARG, 0, 0, 3.141592653590000 },
259 { "%.15f", "3.141592653590000", 0, DOUBLE_ARG, 0, 0, 3.141592653590000 },
260 { "%.15f", "3.141592653589793", 0, DOUBLE_ARG, 0, 0, M_PI },
261 { "%.13f", "37.8662615745371", 0, DOUBLE_ARG, 0, 0, 37.866261574537077 },
262 { "%.14f", "37.86626157453708", 0, DOUBLE_ARG, 0, 0, 37.866261574537077 },
263 { "%.15f", "37.866261574537077", 0, DOUBLE_ARG, 0, 0, 37.866261574537077 },
264 { "%g", "0.0005", 0, DOUBLE_ARG, 0, 0, 0.0005 },
265 { "%g", "5e-005", 0, DOUBLE_ARG, 0, 0, 0.00005 },
266 { "%g", "5e-006", 0, DOUBLE_ARG, 0, 0, 0.000005 },
267 { "%g", "1e+015", 0, DOUBLE_ARG, 0, 0, 999999999999999.0 },
268 { "%g", "1e+015", 0, DOUBLE_ARG, 0, 0, 1000000000000000.0 },
269 { "%.15g", "0.0005", 0, DOUBLE_ARG, 0, 0, 0.0005 },
270 { "%.15g", "5e-005", 0, DOUBLE_ARG, 0, 0, 0.00005 },
271 { "%.15g", "5e-006", 0, DOUBLE_ARG, 0, 0, 0.000005 },
272 { "%.15g", "999999999999999", 0, DOUBLE_ARG, 0, 0, 999999999999999.0 },
273 { "%.15g", "1e+015", 0, DOUBLE_ARG, 0, 0, 1000000000000000.0 },
274 };
275
276 char buffer[100];
277 int i, x, r;
278
279 for (i=0; i<ARRAY_SIZE(tests); i++) {
280 memset(buffer, 'x', sizeof(buffer));
281 switch(tests[i].type & 0xff) {
282 case NO_ARG:
283 r = p_sprintf(buffer, tests[i].format);
284 break;
285 case INT_ARG:
286 r = p_sprintf(buffer, tests[i].format, tests[i].arg_i);
287 break;
288 case ULONGLONG_ARG:
289 r = p_sprintf(buffer, tests[i].format, tests[i].arg_ull);
290 break;
291 case DOUBLE_ARG:
292 r = p_sprintf(buffer, tests[i].format, tests[i].arg_d);
293 break;
294 case PTR_ARG:
295 r = p_sprintf(buffer, tests[i].format, tests[i].arg_ptr);
296 break;
297 default:
298 ok(0, "tests[%d].type = %x\n", i, tests[i].type);
299 continue;
300 }
301
302 ok(r == strlen(buffer), "%d) r = %d, buffer = \"%s\"\n", i, r, buffer);
303 todo_wine_if(tests[i].type & TODO_FLAG)
304 {
305 ok(!strcmp(buffer, tests[i].out) ||
307 "%d) buffer = \"%s\"\n", i, buffer);
308 }
309 }
310
311 if (sizeof(void *) == 8)
312 {
313 r = p_sprintf(buffer, "%p", (void *)57);
314 ok(!strcmp(buffer,"0000000000000039"),"Pointer formatted incorrectly \"%s\"\n",buffer);
315 ok( r==16, "return count wrong\n");
316
317 r = p_sprintf(buffer, "%#020p", (void *)57);
318 ok(!strcmp(buffer," 0X0000000000000039"),"Pointer formatted incorrectly\n");
319 ok( r==20, "return count wrong\n");
320
321 r = p_sprintf(buffer, "%Fp", (void *)57);
322 ok(!strcmp(buffer,"0000000000000039"),"Pointer formatted incorrectly \"%s\"\n",buffer);
323 ok( r==16, "return count wrong\n");
324
325 r = p_sprintf(buffer, "%Np", (void *)57);
326 ok(!strcmp(buffer,"0000000000000039"),"Pointer formatted incorrectly \"%s\"\n",buffer);
327 ok( r==16, "return count wrong\n");
328
329 r = p_sprintf(buffer, "%#-020p", (void *)57);
330 ok(!strcmp(buffer,"0X0000000000000039 "),"Pointer formatted incorrectly\n");
331 ok( r==20, "return count wrong\n");
332
333 r = p_sprintf(buffer, "%Ix %d", (size_t)0x12345678123456,1);
334 ok(!strcmp(buffer,"12345678123456 1"),"buffer = %s\n",buffer);
335 ok( r==16, "return count wrong\n");
336
337 r = p_sprintf(buffer, "%p", 0);
338 ok(!strcmp(buffer,"0000000000000000"), "failed\n");
339 ok( r==16, "return count wrong\n");
340 }
341 else
342 {
343 r = p_sprintf(buffer, "%p", (void *)57);
344 ok(!strcmp(buffer,"00000039"),"Pointer formatted incorrectly \"%s\"\n",buffer);
345 ok( r==8, "return count wrong\n");
346
347 r = p_sprintf(buffer, "%#012p", (void *)57);
348 ok(!strcmp(buffer," 0X00000039"),"Pointer formatted incorrectly\n");
349 ok( r==12, "return count wrong\n");
350
351 r = p_sprintf(buffer, "%Fp", (void *)57);
352 ok(!strcmp(buffer,"00000039"),"Pointer formatted incorrectly \"%s\"\n",buffer);
353 ok( r==8, "return count wrong\n");
354
355 r = p_sprintf(buffer, "%Np",(void *)57);
356 ok(!strcmp(buffer,"00000039"),"Pointer formatted incorrectly \"%s\"\n",buffer);
357 ok( r==8, "return count wrong\n");
358
359 r = p_sprintf(buffer, "%#-012p", (void *)57);
360 ok(!strcmp(buffer,"0X00000039 "),"Pointer formatted incorrectly\n");
361 ok( r==12, "return count wrong\n");
362
363 r = p_sprintf(buffer, "%Ix %d", 0x123456, 1);
364 ok(!strcmp(buffer,"123456 1"),"buffer = %s\n",buffer);
365 ok( r==8, "return count wrong\n");
366
367 r = p_sprintf(buffer, "%p", 0);
368 ok(!strcmp(buffer,"00000000"), "failed\n");
369 ok( r==8, "return count wrong\n");
370 }
371
372 r = p_sprintf(buffer, "%.*s", 1, "foo");
373 ok(!strcmp(buffer,"f"),"Precision ignored \"%s\"\n",buffer);
374 ok( r==1, "return count wrong\n");
375
376 r = p_sprintf(buffer, "%*s", -5, "foo");
377 ok(!strcmp(buffer,"foo "),"Negative field width ignored \"%s\"\n",buffer);
378 ok( r==5, "return count wrong\n");
379
380 x = 0;
381 r = p_sprintf(buffer, "asdf%n", &x );
382 if (r == -1)
383 {
384 /* %n format is disabled by default on vista */
385 /* FIXME: should test with _set_printf_count_output */
386 ok(x == 0, "should not write to x: %d\n", x);
387 }
388 else
389 {
390 ok(x == 4, "should write to x: %d\n", x);
391 ok(!strcmp(buffer,"asdf"), "failed\n");
392 ok( r==4, "return count wrong: %d\n", r);
393 }
394
395 r = p_sprintf(buffer, "%S", L"\x3042");
396 ok(r==-1 || broken(!r), "r = %d\n", r);
397
398 if(!setlocale(LC_ALL, "Japanese_Japan.932")) {
399 win_skip("Japanese_Japan.932 locale not available\n");
400 return;
401 }
402
403 r = p_sprintf(buffer, "%c", 0xa082);
404 ok(r==1, "r = %d\n", r);
405 ok(!strcmp(buffer, "\x82"), "failed: \"%s\"\n", buffer);
406
407 r = p_sprintf(buffer, "%C", 0x3042);
408 ok(r==2, "r = %d\n", r);
409 ok(!strcmp(buffer, "\x82\xa0"), "failed: \"%s\"\n", buffer);
410
411 strcpy(buffer, " string to copy");
412 r = p_sprintf(buffer, buffer+1);
413 ok(r==14, "r = %d\n", r);
414 ok(!strcmp(buffer, "string to copy"), "failed: \"%s\"\n", buffer);
415
416 setlocale(LC_ALL, "C");
417
418 r = p_sprintf(buffer, "%*1d", 1, 3);
419 ok(r==11, "r = %d\n", r);
420 ok(!strcmp(buffer, " 3"), "failed: \"%s\"\n", buffer);
421
422 r = p_sprintf(buffer, "%0*0d", 1, 2);
423 ok(r==10, "r = %d\n", r);
424 ok(!strcmp(buffer, "0000000002"), "failed: \"%s\"\n", buffer);
425
426 r = p_sprintf(buffer, "% *2d", 0, 7);
427 ok(r==2, "r = %d\n", r);
428 ok(!strcmp(buffer, " 7"), "failed: \"%s\"\n", buffer);
429}
_STLP_DECLSPEC complex< float > _STLP_CALL sqrt(const complex< float > &)
Definition: complex.cpp:188
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define broken(x)
Definition: atltest.h:178
#define NULL
Definition: types.h:112
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define LC_ALL
Definition: locale.h:17
#define INFINITY
Definition: math.h:56
#define M_PI
Definition: macros.h:263
#define NAN
Definition: mesh.c:39
#define todo_wine_if(is_todo)
Definition: custom.c:86
static size_t size_t const wchar_t * format
Definition: printf.c:49
#define IND
Definition: printf.c:44
strcpy
Definition: string.h:131
#define setlocale(n, s)
Definition: locale.h:46
uint64_t ULONGLONG
Definition: typedefs.h:67
wchar_t tm const _CrtWcstime_Writes_and_advances_ptr_ count wchar_t ** out
Definition: wcsftime.cpp:383

Referenced by START_TEST().

◆ test_swprintf()

static void test_swprintf ( void  )
static

Definition at line 431 of file printf.c.

432{
433 wchar_t buffer[100];
434 double pnumber = 789456123;
435 const char string[] = "string";
436
437 swprintf(buffer, L"%+#23.15e", pnumber);
438 ok(wcsstr(buffer, L"e+008") != 0, "Sprintf different\n");
439 swprintf(buffer, L"%I64d", ((ULONGLONG)0xffffffff)*0xffffffff);
440 ok(wcslen(buffer) == 11, "Problem with long long\n");
441 swprintf(buffer, L"%S", string);
442 ok(wcslen(buffer) == 6, "Problem with \"%%S\" interpretation\n");
443 swprintf(buffer, L"%hs", string);
444 ok(!wcscmp(L"string", buffer), "swprintf failed with %%hs\n");
445}
#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)

Referenced by START_TEST().

◆ test_vscprintf()

static void test_vscprintf ( void  )
static

Definition at line 970 of file printf.c.

971{
972 int ret;
973
974 if (!p__vscprintf)
975 {
976 win_skip("_vscprintf not available\n");
977 return;
978 }
979
980 ret = _vscprintf_wrapper( "%s %d", "number", 1 );
981 ok( ret == 8, "got %d expected 8\n", ret );
982}
static int WINAPIV _vscprintf_wrapper(const char *format,...)
Definition: printf.c:960

Referenced by START_TEST().

◆ test_vscwprintf()

static void test_vscwprintf ( void  )
static

Definition at line 994 of file printf.c.

995{
996 int ret;
997
998 if (!p__vscwprintf)
999 {
1000 win_skip("_vscwprintf not available\n");
1001 return;
1002 }
1003
1004 ret = _vscwprintf_wrapper(L"%s %d", L"number", 1 );
1005 ok( ret == 8, "got %d expected 8\n", ret );
1006}
static int WINAPIV _vscwprintf_wrapper(const wchar_t *format,...)
Definition: printf.c:984

Referenced by START_TEST().

◆ test_vsnwprintf()

static void test_vsnwprintf ( void  )
static

Definition at line 835 of file printf.c.

836{
837 int ret;
838 wchar_t str[32];
839 char buf[32];
840
841 ret = _vsnwprintf_wrapper( str, ARRAY_SIZE(str), L"%ws%ws%ws", L"one", L"two", L"three" );
842 ok( ret == 11, "got %d expected 11\n", ret );
843 WideCharToMultiByte( CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL );
844 ok( !strcmp(buf, "onetwothree"), "got %s expected 'onetwothree'\n", buf );
845
846 ret = _vsnwprintf_wrapper( str, 0, L"%ws%ws%ws", L"one", L"two", L"three" );
847 ok( ret == -1, "got %d, expected -1\n", ret );
848
849 ret = _vsnwprintf_wrapper( NULL, 0, L"%ws%ws%ws", L"one", L"two", L"three" );
850 ok( ret == 11 || broken(ret == -1 /* Win2k */), "got %d, expected 11\n", ret );
851}
#define CP_ACP
Definition: compat.h:109
#define WideCharToMultiByte
Definition: compat.h:111
static int WINAPIV _vsnwprintf_wrapper(wchar_t *str, size_t len, const wchar_t *format,...)
Definition: printf.c:825

Referenced by START_TEST().

◆ test_vsnwprintf_s()

static void test_vsnwprintf_s ( void  )
static

Definition at line 1019 of file printf.c.

1020{
1021 wchar_t buffer[14] = { 0 };
1022 int ret;
1023
1024 if (!p__vsnwprintf_s)
1025 {
1026 win_skip("_vsnwprintf_s not available\n");
1027 return;
1028 }
1029
1030 /* Enough room. */
1031 ret = _vsnwprintf_s_wrapper(buffer, 14, _TRUNCATE, L"AB%uC", 123);
1032 ok( ret == 6, "length wrong, expect=6, got=%d\n", ret);
1033 ok( !wcscmp(L"AB123C", buffer), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer));
1034
1035 ret = _vsnwprintf_s_wrapper(buffer, 12, _TRUNCATE, L"AB%uC", 123);
1036 ok( ret == 6, "length wrong, expect=6, got=%d\n", ret);
1037 ok( !wcscmp(L"AB123C", buffer), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer));
1038
1039 ret = _vsnwprintf_s_wrapper(buffer, 7, _TRUNCATE, L"AB%uC", 123);
1040 ok( ret == 6, "length wrong, expect=6, got=%d\n", ret);
1041 ok( !wcscmp(L"AB123C", buffer), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer));
1042
1043 /* Not enough room. */
1044 ret = _vsnwprintf_s_wrapper(buffer, 6, _TRUNCATE, L"AB%uC", 123);
1045 ok( ret == -1, "length wrong, expect=-1, got=%d\n", ret);
1046 ok( !wcscmp(L"AB123", buffer), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer));
1047
1048 ret = _vsnwprintf_s_wrapper(buffer, 2, _TRUNCATE, L"AB%uC", 123);
1049 ok( ret == -1, "length wrong, expect=-1, got=%d\n", ret);
1050 ok( !wcscmp(L"A", buffer), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer));
1051
1052 ret = _vsnwprintf_s_wrapper(buffer, 1, _TRUNCATE, L"AB%uC", 123);
1053 ok( ret == -1, "length wrong, expect=-1, got=%d\n", ret);
1054 ok( !wcscmp(L"", buffer), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer));
1055}
static int WINAPIV _vsnwprintf_s_wrapper(wchar_t *str, size_t sizeOfBuffer, size_t count, const wchar_t *format,...)
Definition: printf.c:1008
#define _TRUNCATE
Definition: corecrt.h:278

Referenced by START_TEST().

◆ test_vsprintf_p()

static void test_vsprintf_p ( void  )
static

Definition at line 1068 of file printf.c.

1069{
1070 char buf[1024];
1071 int ret;
1072
1073 if(!p__vsprintf_p) {
1074 win_skip("vsprintf_p not available\n");
1075 return;
1076 }
1077
1078 ret = _vsprintf_p_wrapper(buf, sizeof(buf), "%s %d", "test", 1234);
1079 ok(ret == 9, "ret = %d\n", ret);
1080 ok(!memcmp(buf, "test 1234", 10), "buf = %s\n", buf);
1081
1082 ret = _vsprintf_p_wrapper(buf, sizeof(buf), "%1$d", 1234, "additional param");
1083 ok(ret == 4, "ret = %d\n", ret);
1084 ok(!memcmp(buf, "1234", 5), "buf = %s\n", buf);
1085
1086 ret = _vsprintf_p_wrapper(buf, sizeof(buf), "%2$s %1$d", 1234, "test");
1087 ok(ret == 9, "ret = %d\n", ret);
1088 ok(!memcmp(buf, "test 1234", 10), "buf = %s\n", buf);
1089
1090 ret = _vsprintf_p_wrapper(buf, sizeof(buf), "%2$*3$s %2$.*1$s", 2, "test", 3);
1091 ok(ret == 7, "ret = %d\n", ret);
1092 ok(!memcmp(buf, "test te", 8), "buf = %s\n", buf);
1093
1094 /* Following test invokes invalid parameter handler */
1095 /* ret = _vsprintf_p_wrapper(buf, sizeof(buf), "%d %1$d", 1234); */
1096}
static int WINAPIV _vsprintf_p_wrapper(char *str, size_t sizeOfBuffer, const char *format,...)
Definition: printf.c:1057

Referenced by START_TEST().

◆ test_vswprintf()

static void test_vswprintf ( void  )
static

Definition at line 913 of file printf.c.

914{
915 wchar_t buf[20];
916 int ret;
917
918 if (!p_vswprintf || !p__vswprintf || !p__vswprintf_l ||!p__vswprintf_c
919 || !p__vswprintf_c_l || !p__vswprintf_p_l)
920 {
921 win_skip("_vswprintf or vswprintf not available\n");
922 return;
923 }
924
925 ret = vswprintf_wrapper(buf, L"%s %d", L"number", 123);
926 ok(ret == 10, "got %d, expected 10\n", ret);
927 ok(!wcscmp(buf, L"number 123"), "buf = %s\n", wine_dbgstr_w(buf));
928
929 memset(buf, 0, sizeof(buf));
930 ret = _vswprintf_wrapper(buf, L"%s %d", L"number", 123);
931 ok(ret == 10, "got %d, expected 10\n", ret);
932 ok(!wcscmp(buf, L"number 123"), "buf = %s\n", wine_dbgstr_w(buf));
933
934 memset(buf, 0, sizeof(buf));
935 ret = _vswprintf_l_wrapper(buf, L"%s %d", NULL, L"number", 123);
936 ok(ret == 10, "got %d, expected 10\n", ret);
937 ok(!wcscmp(buf, L"number 123"), "buf = %s\n", wine_dbgstr_w(buf));
938
939 memset(buf, 0, sizeof(buf));
940 ret = _vswprintf_c_wrapper(buf, 20, L"%s %d", L"number", 123);
941 ok(ret == 10, "got %d, expected 10\n", ret);
942 ok(!wcscmp(buf, L"number 123"), "buf = %s\n", wine_dbgstr_w(buf));
943
944 memset(buf, 'x', sizeof(buf));
945 ret = _vswprintf_c_wrapper(buf, 10, L"%s %d", L"number", 123);
946 ok(ret == -1, "got %d, expected -1\n", ret);
947 ok(!wcscmp(buf, L"number 12"), "buf = %s\n", wine_dbgstr_w(buf));
948
949 memset(buf, 0, sizeof(buf));
950 ret = _vswprintf_c_l_wrapper(buf, 20, L"%s %d", NULL, L"number", 123);
951 ok(ret == 10, "got %d, expected 10\n", ret);
952 ok(!wcscmp(buf, L"number 123"), "buf = %s\n", wine_dbgstr_w(buf));
953
954 memset(buf, 0, sizeof(buf));
955 ret = _vswprintf_p_l_wrapper(buf, 20, L"%s %d", NULL, L"number", 123);
956 ok(ret == 10, "got %d, expected 10\n", ret);
957 ok(!wcscmp(buf, L"number 123"), "buf = %s\n", wine_dbgstr_w(buf));
958}
static int WINAPIV vswprintf_wrapper(wchar_t *str, const wchar_t *format,...)
Definition: printf.c:853
static int WINAPIV _vswprintf_p_l_wrapper(wchar_t *str, size_t size, const wchar_t *format, void *locale,...)
Definition: printf.c:903
static int WINAPIV _vswprintf_l_wrapper(wchar_t *str, const wchar_t *format, void *locale,...)
Definition: printf.c:873
static int WINAPIV _vswprintf_c_l_wrapper(wchar_t *str, size_t size, const wchar_t *format, void *locale,...)
Definition: printf.c:893
static int WINAPIV _vswprintf_wrapper(wchar_t *str, const wchar_t *format,...)
Definition: printf.c:863
static int WINAPIV _vswprintf_c_wrapper(wchar_t *str, size_t size, const wchar_t *format,...)
Definition: printf.c:883

Referenced by START_TEST().

◆ test_xcvt()

static void test_xcvt ( void  )
static

Definition at line 709 of file printf.c.

710{
711 char *str;
712 int i, decpt, sign, err;
713
714 for( i = 0; strcmp( test_cvt_testcases[i].expstr_e, "END"); i++){
715 decpt = sign = 100;
718 &decpt,
719 &sign);
721 "%d) _ecvt() bad return, got '%s' expected '%s'\n", i, str,
724 "%d) _ecvt() decimal point wrong, got %d expected %d\n", i, decpt,
726 if (((i == 10) || (i == 11) || (i == 12)) && (_winver < 0x600))
727 {
728 skip("broken on win 2003\n");
729 continue;
730 }
732 "%d) _ecvt() sign wrong, got %d expected %d\n", i, sign,
734 }
735 for( i = 0; strcmp( test_cvt_testcases[i].expstr_e, "END"); i++){
736 decpt = sign = 100;
739 &decpt,
740 &sign);
742 "%d) _fcvt() bad return, got '%s' expected '%s'\n", i, str,
745 "%d) _fcvt() decimal point wrong, got %d expected %d\n", i, decpt,
747 if (((i == 10) || (i == 11) || (i == 12)) && (_winver < 0x600))
748 {
749 skip("broken on win 2003\n");
750 continue;
751 }
753 "%d) _fcvt() sign wrong, got %d expected %d\n", i, sign,
755 }
756
757 if (p__ecvt_s)
758 {
759 str = malloc(1024);
760 for( i = 0; strcmp( test_cvt_testcases[i].expstr_e, "END"); i++){
761 decpt = sign = 100;
763 ok(err == 0, "_ecvt_s() failed with error code %d\n", err);
765 "%d) _ecvt_s() bad return, got '%s' expected '%s'\n", i, str,
768 "%d) _ecvt_s() decimal point wrong, got %d expected %d\n", i, decpt,
771 "%d) _ecvt_s() sign wrong, got %d expected %d\n", i, sign,
773 }
774 free(str);
775 }
776 else
777 win_skip("_ecvt_s not available\n");
778
779 if (p__fcvt_s)
780 {
781 int i;
782
783 str = malloc(1024);
784
785 /* invalid arguments */
786 err = p__fcvt_s(NULL, 0, 0.0, 0, &i, &i);
787 ok(err == EINVAL, "got %d, expected EINVAL\n", err);
788
789 err = p__fcvt_s(str, 0, 0.0, 0, &i, &i);
790 ok(err == EINVAL, "got %d, expected EINVAL\n", err);
791
792 str[0] = ' ';
793 str[1] = 0;
794 err = p__fcvt_s(str, -1, 0.0, 0, &i, &i);
795 ok(err == 0, "got %d, expected 0\n", err);
796 ok(str[0] == 0, "got %c, expected 0\n", str[0]);
797 ok(str[1] == 0, "got %c, expected 0\n", str[1]);
798
799 err = p__fcvt_s(str, 1, 0.0, 0, NULL, &i);
800 ok(err == EINVAL, "got %d, expected EINVAL\n", err);
801
802 err = p__fcvt_s(str, 1, 0.0, 0, &i, NULL);
803 ok(err == EINVAL, "got %d, expected EINVAL\n", err);
804
805 for( i = 0; strcmp( test_cvt_testcases[i].expstr_e, "END"); i++){
806 decpt = sign = 100;
808 ok(!err, "%d) _fcvt_s() failed with error code %d\n", i, err);
810 "%d) _fcvt_s() bad return, got '%s' expected '%s'. test %d\n", i, str,
813 "%d) _fcvt_s() decimal point wrong, got %d expected %d\n", i, decpt,
816 "%d) _fcvt_s() sign wrong, got %d expected %d\n", i, sign,
818 }
819 free(str);
820 }
821 else
822 win_skip("_fcvt_s not available\n");
823}
#define EINVAL
Definition: acclib.h:90
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
#define skip(...)
Definition: atltest.h:64
#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:663
const char * expstr_e
Definition: printf.c:662
int expdecpt_e
Definition: printf.c:664
int expdecpt_f
Definition: printf.c:665
int nrdigits
Definition: printf.c:661
static struct @1693 test_cvt_testcases[]
static size_t double int int * decpt
Definition: printf.c:52
int expsign
Definition: printf.c:666
unsigned int _winver
Definition: environ.c:14
#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 853 of file printf.c.

854{
855 int ret;
858 ret = p_vswprintf(str, format, valist);
859 va_end(valist);
860 return ret;
861}

Referenced by test_vswprintf().

Variable Documentation

◆ count

Definition at line 49 of file printf.c.

◆ decpt

static size_t double int int * decpt

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

Referenced by test_xcvt().

◆ expdecpt_f

int expdecpt_f

Definition at line 665 of file printf.c.

Referenced by test_xcvt().

◆ expsign

int expsign

Definition at line 666 of file printf.c.

Referenced by test_xcvt().

◆ expstr_e

const char* expstr_e

Definition at line 662 of file printf.c.

Referenced by test_xcvt().

◆ expstr_f

const char* expstr_f

Definition at line 663 of file printf.c.

Referenced by test_xcvt().

◆ format

Definition at line 49 of file printf.c.

Referenced by test_sprintf().

◆ length

Definition at line 51 of file printf.c.

◆ locale

Initial value:
{
static __forceinline int fast_check_given_locale(int const c, int const mask, _locale_t const locale)
Definition: _ctype.cpp:61
#define _UPPER
Definition: ctype.h:65

Definition at line 62 of file printf.c.

◆ ndigits

◆ nrdigits

int nrdigits

Definition at line 661 of file printf.c.

Referenced by test_xcvt().

◆ number

static size_t double number

Definition at line 51 of file printf.c.

◆ sign

static size_t double int int int * sign

Definition at line 52 of file printf.c.

Referenced by test_fcvt(), and test_xcvt().

◆ size

Definition at line 63 of file printf.c.

◆ size_t

static size_t

Definition at line 58 of file printf.c.

Referenced by test_snprintf().

◆ sizeOfBuffer

size_t sizeOfBuffer

Definition at line 48 of file printf.c.

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

◆ 

struct { ... } test_cvt_testcases[]

Referenced by test_xcvt().

◆ va_list

static const char va_list

Definition at line 58 of file printf.c.

◆ valist

◆ value

Definition at line 660 of file printf.c.