From 1a19c6bbeab1e30b2e7bfc3849f79a8d45bd1ea6 Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Fri, 4 Nov 2022 14:43:43 -0400 Subject: [PATCH] Revert "Remove "wprintf" from PAL (#77852)" This completely broke `dotnet-runtime-perf` pipeline for wasm runs. This reverts commit 803688595257517f4b47e873d11152b0560c204a. Issue: https://github.com/dotnet/runtime/issues/77883 --- .../dlls/mscordac/mscordac_unixexports.src | 2 + src/coreclr/pal/inc/mbusafecrt.h | 3 + src/coreclr/pal/inc/pal.h | 3 + src/coreclr/pal/inc/rt/safecrt.h | 30 +- src/coreclr/pal/src/CMakeLists.txt | 2 + src/coreclr/pal/src/misc/fmtmessage.cpp | 216 +++++++- src/coreclr/pal/src/safecrt/internal.h | 7 + .../pal/src/safecrt/mbusafecrt_internal.h | 1 + src/coreclr/pal/src/safecrt/swprintf.cpp | 100 ++++ src/coreclr/pal/src/safecrt/vswprint.cpp | 178 +++++++ src/coreclr/pal/tests/palsuite/CMakeLists.txt | 54 ++ .../c_runtime/_snwprintf_s/_snwprintf_s.h | 209 ++++++++ .../c_runtime/_snwprintf_s/test1/test1.cpp | 61 +++ .../c_runtime/_snwprintf_s/test10/test10.cpp | 53 ++ .../c_runtime/_snwprintf_s/test11/test11.cpp | 53 ++ .../c_runtime/_snwprintf_s/test12/test12.cpp | 53 ++ .../c_runtime/_snwprintf_s/test13/test13.cpp | 53 ++ .../c_runtime/_snwprintf_s/test14/test14.cpp | 65 +++ .../c_runtime/_snwprintf_s/test15/test15.cpp | 66 +++ .../c_runtime/_snwprintf_s/test16/test16.cpp | 64 +++ .../c_runtime/_snwprintf_s/test17/test17.cpp | 67 +++ .../c_runtime/_snwprintf_s/test18/test18.cpp | 68 +++ .../c_runtime/_snwprintf_s/test19/test19.cpp | 81 +++ .../c_runtime/_snwprintf_s/test2/test2.cpp | 49 ++ .../c_runtime/_snwprintf_s/test3/test3.cpp | 49 ++ .../c_runtime/_snwprintf_s/test4/test4.cpp | 70 +++ .../c_runtime/_snwprintf_s/test6/test6.cpp | 45 ++ .../c_runtime/_snwprintf_s/test7/test7.cpp | 45 ++ .../c_runtime/_snwprintf_s/test8/test8.cpp | 52 ++ .../c_runtime/_snwprintf_s/test9/test9.cpp | 52 ++ .../c_runtime/_vsnwprintf_s/_vsnwprintf_s.h | 139 +++++ .../c_runtime/_vsnwprintf_s/test1/test1.cpp | 59 +++ .../c_runtime/_vsnwprintf_s/test10/test10.cpp | 49 ++ .../c_runtime/_vsnwprintf_s/test11/test11.cpp | 49 ++ .../c_runtime/_vsnwprintf_s/test12/test12.cpp | 49 ++ .../c_runtime/_vsnwprintf_s/test13/test13.cpp | 49 ++ .../c_runtime/_vsnwprintf_s/test14/test14.cpp | 62 +++ .../c_runtime/_vsnwprintf_s/test15/test15.cpp | 63 +++ .../c_runtime/_vsnwprintf_s/test16/test16.cpp | 62 +++ .../c_runtime/_vsnwprintf_s/test17/test17.cpp | 64 +++ .../c_runtime/_vsnwprintf_s/test18/test18.cpp | 64 +++ .../c_runtime/_vsnwprintf_s/test19/test19.cpp | 138 +++++ .../c_runtime/_vsnwprintf_s/test2/test2.cpp | 45 ++ .../c_runtime/_vsnwprintf_s/test3/test3.cpp | 45 ++ .../c_runtime/_vsnwprintf_s/test4/test4.cpp | 120 +++++ .../c_runtime/_vsnwprintf_s/test6/test6.cpp | 42 ++ .../c_runtime/_vsnwprintf_s/test7/test7.cpp | 42 ++ .../c_runtime/_vsnwprintf_s/test8/test8.cpp | 48 ++ .../c_runtime/_vsnwprintf_s/test9/test9.cpp | 48 ++ .../c_runtime/vswprintf/test1/test1.cpp | 39 ++ .../c_runtime/vswprintf/test10/test10.cpp | 47 ++ .../c_runtime/vswprintf/test11/test11.cpp | 47 ++ .../c_runtime/vswprintf/test12/test12.cpp | 47 ++ .../c_runtime/vswprintf/test13/test13.cpp | 47 ++ .../c_runtime/vswprintf/test14/test14.cpp | 60 +++ .../c_runtime/vswprintf/test15/test15.cpp | 61 +++ .../c_runtime/vswprintf/test16/test16.cpp | 60 +++ .../c_runtime/vswprintf/test17/test17.cpp | 62 +++ .../c_runtime/vswprintf/test18/test18.cpp | 62 +++ .../c_runtime/vswprintf/test19/test19.cpp | 136 +++++ .../c_runtime/vswprintf/test2/test2.cpp | 45 ++ .../c_runtime/vswprintf/test3/test3.cpp | 45 ++ .../c_runtime/vswprintf/test4/test4.cpp | 117 +++++ .../c_runtime/vswprintf/test6/test6.cpp | 40 ++ .../c_runtime/vswprintf/test7/test7.cpp | 40 ++ .../c_runtime/vswprintf/test8/test8.cpp | 46 ++ .../c_runtime/vswprintf/test9/test9.cpp | 46 ++ .../palsuite/c_runtime/vswprintf/vswprintf.h | 139 +++++ .../pal/tests/palsuite/compilableTests.txt | 54 ++ .../test1/GetTempFileNameW.cpp | 7 +- .../FormatMessageW/test2/test.cpp | 474 +++++++++++++++++- .../pal/tests/palsuite/paltestlist.txt | 48 ++ .../palsuite/paltestlist_to_be_reviewed.txt | 6 + 73 files changed, 4830 insertions(+), 33 deletions(-) create mode 100644 src/coreclr/pal/src/safecrt/swprintf.cpp create mode 100644 src/coreclr/pal/src/safecrt/vswprint.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/_snwprintf_s.h create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test1/test1.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test10/test10.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test11/test11.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test12/test12.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test13/test13.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test14/test14.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test15/test15.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test16/test16.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test17/test17.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test18/test18.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test19/test19.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test2/test2.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test3/test3.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test4/test4.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test6/test6.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test7/test7.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test8/test8.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test9/test9.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/_vsnwprintf_s.h create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test1/test1.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test10/test10.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test11/test11.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test12/test12.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test13/test13.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test14/test14.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test15/test15.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test16/test16.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test17/test17.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test18/test18.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test19/test19.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test2/test2.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test3/test3.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test4/test4.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test6/test6.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test7/test7.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test8/test8.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test9/test9.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test1/test1.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test10/test10.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test11/test11.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test12/test12.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test13/test13.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test14/test14.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test15/test15.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test16/test16.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test17/test17.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test18/test18.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test19/test19.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test2/test2.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test3/test3.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test4/test4.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test6/test6.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test7/test7.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test8/test8.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test9/test9.cpp create mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/vswprintf.h diff --git a/src/coreclr/dlls/mscordac/mscordac_unixexports.src b/src/coreclr/dlls/mscordac/mscordac_unixexports.src index 2168a5d4c3345e..eedce09f0cac36 100644 --- a/src/coreclr/dlls/mscordac/mscordac_unixexports.src +++ b/src/coreclr/dlls/mscordac/mscordac_unixexports.src @@ -74,7 +74,9 @@ nativeStringResourceTable_mscorrc #sprintf_s #vsprintf_s #_snprintf_s +#_snwprintf_s #_vsnprintf_s +#_vsnwprintf_s #_itow_s #_i64tow_s #memcpy_s diff --git a/src/coreclr/pal/inc/mbusafecrt.h b/src/coreclr/pal/inc/mbusafecrt.h index cdcc2faabeed47..1d02417a8d4b77 100644 --- a/src/coreclr/pal/inc/mbusafecrt.h +++ b/src/coreclr/pal/inc/mbusafecrt.h @@ -86,10 +86,13 @@ extern errno_t _wsplitpath_s( const WCHAR* inPath, WCHAR* outDrive, size_t inDri extern int sprintf_s( char *string, size_t sizeInBytes, const char *format, ... ); extern int _snprintf_s( char *string, size_t sizeInBytes, size_t count, const char *format, ... ); +extern int _snwprintf_s( WCHAR *string, size_t sizeInWords, size_t count, const WCHAR *format, ... ); extern int vsprintf_s( char* string, size_t sizeInBytes, const char* format, va_list arglist ); extern int _vsnprintf_s( char* string, size_t sizeInBytes, size_t count, const char* format, va_list arglist ); +extern int _vsnwprintf_s( WCHAR* string, size_t sizeInWords, size_t count, const WCHAR* format, va_list arglist ); + extern int sscanf_s( const char *string, const char *format, ... ); extern int swscanf_s( const WCHAR *string, const WCHAR *format, ... ); diff --git a/src/coreclr/pal/inc/pal.h b/src/coreclr/pal/inc/pal.h index b6879228acb583..a5e5542aef5453 100644 --- a/src/coreclr/pal/inc/pal.h +++ b/src/coreclr/pal/inc/pal.h @@ -4099,8 +4099,11 @@ PALIMPORT DLLEXPORT int __cdecl _wcsicmp(const WCHAR *, const WCHAR*); PALIMPORT int __cdecl _wcsnicmp(const WCHAR *, const WCHAR *, size_t); PALIMPORT int __cdecl _vsnprintf(char *, size_t, const char *, va_list); PALIMPORT DLLEXPORT int __cdecl _vsnprintf_s(char *, size_t, size_t, const char *, va_list); +PALIMPORT DLLEXPORT int __cdecl _vsnwprintf_s(WCHAR *, size_t, size_t, const WCHAR *, va_list); +PALIMPORT DLLEXPORT int __cdecl _snwprintf_s(WCHAR *, size_t, size_t, const WCHAR *, ...); PALIMPORT DLLEXPORT int __cdecl _snprintf_s(char *, size_t, size_t, const char *, ...); PALIMPORT DLLEXPORT int __cdecl sprintf_s(char *, size_t, const char *, ... ); +PALIMPORT int __cdecl _snwprintf_s(WCHAR *, size_t, size_t, const WCHAR *, ...); PALIMPORT DLLEXPORT int __cdecl sscanf_s(const char *, const char *, ...); PALIMPORT DLLEXPORT errno_t __cdecl _itow_s(int, WCHAR *, size_t, int); diff --git a/src/coreclr/pal/inc/rt/safecrt.h b/src/coreclr/pal/inc/rt/safecrt.h index 4d9d1a176950cf..c990bc8453ff45 100644 --- a/src/coreclr/pal/inc/rt/safecrt.h +++ b/src/coreclr/pal/inc/rt/safecrt.h @@ -385,6 +385,7 @@ void __cdecl _invalid_parameter(const WCHAR *_Message, const WCHAR *_FunctionNam #define _tmakepath_s _wmakepath_s #define _tsplitpath_s _wsplitpath_s #define _stprintf_s swprintf_s +#define _vsntprintf_s _vsnwprintf_s #define _tscanf_s wscanf_s #define _tsscanf_s swscanf_s @@ -1680,7 +1681,7 @@ int __cdecl vsprintf_s(char (&_Dst)[_SizeInBytes], const char *_Format, va_list /* _vsnprintf_s */ /* - * _vsnprintf_s formats a string and copy at max _Count characters into _Dst; + * _snwprintf_s, _vsnprintf_s, _vsnwprintf_s format a string and copy at max _Count characters into _Dst; * need safecrt.lib and msvcrt.dll; * string _Dst will always be null-terminated; * will call _SAFECRT_INVALID_PARAMETER if there is not enough space in _Dst; @@ -1706,6 +1707,33 @@ int __cdecl _vsnprintf_s(char (&_Dst)[_SizeInBytes], size_t _Count, const char * /* no inline version of _vsnprintf_s */ +/* _snwprintf_s, _vsnwprintf_s */ +_SAFECRT__EXTERN_C +int __cdecl _vsnwprintf_s(WCHAR *_Dst, size_t _SizeInWords, size_t _Count, const WCHAR *_Format, va_list _ArgList); + +#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS +template +inline +int __cdecl _snwprintf_s(WCHAR (&_Dst)[_SizeInWords], size_t _Count, const WCHAR *_Format, ...) +{ + int ret; + va_list _ArgList; + va_start(_ArgList, _Format); + ret = _vsnwprintf_s(_Dst, _SizeInWords, _Count, _Format, _ArgList); + va_end(_ArgList); + return ret; +} + +template +inline +int __cdecl _vsnwprintf_s(char (&_Dst)[_SizeInWords], size_t _Count, const char *_Format, va_list _ArgList) +{ + return _vsnwprintf_s(_Dst, _SizeInWords, _Count, _Format, _ArgList); +} +#endif + +/* no inline version of _snwprintf_s, _vsnwprintf_s */ + /* wscanf_s */ _SAFECRT__EXTERN_C int __cdecl wscanf_s(const WCHAR *_Format, ...); diff --git a/src/coreclr/pal/src/CMakeLists.txt b/src/coreclr/pal/src/CMakeLists.txt index 9df78198ca634f..1088bb1791869e 100644 --- a/src/coreclr/pal/src/CMakeLists.txt +++ b/src/coreclr/pal/src/CMakeLists.txt @@ -192,7 +192,9 @@ set(SOURCES safecrt/strncat_s.cpp safecrt/strncpy_s.cpp safecrt/strtok_s.cpp + safecrt/swprintf.cpp safecrt/vsprintf.cpp + safecrt/vswprint.cpp safecrt/wcscat_s.cpp safecrt/wcscpy_s.cpp safecrt/wcslen_s.cpp diff --git a/src/coreclr/pal/src/misc/fmtmessage.cpp b/src/coreclr/pal/src/misc/fmtmessage.cpp index bd9a649a35835b..1b52573d3faae4 100644 --- a/src/coreclr/pal/src/misc/fmtmessage.cpp +++ b/src/coreclr/pal/src/misc/fmtmessage.cpp @@ -180,6 +180,102 @@ of _ADD_TO_STRING, as we will resize the buffer if necessary. */ _ADD_TO_STRING( c );\ } + +/*++ +Function : + + FMTMSG_ProcessPrintf + + Processes the printf formatters based on the format. + + Returns the LPWSTR string, or NULL on failure. +*/ + +static LPWSTR FMTMSG_ProcessPrintf( WCHAR c , + LPWSTR lpPrintfString, + LPWSTR lpInsertString) +{ + LPWSTR lpBuffer = NULL; + LPWSTR lpBuffer2 = NULL; + LPWSTR lpFormat = NULL; +#if _DEBUG + // small size for _DEBUG to exercise buffer reallocation logic + int tmpSize = 4; +#else + int tmpSize = 64; +#endif + UINT nFormatLength = 0; + int nBufferLength = 0; + + TRACE( "FMTMSG_ProcessPrintf( %C, %S, %p )\n", c, + lpPrintfString, lpInsertString ); + + switch ( c ) + { + case 'e' : + /* Fall through */ + case 'E' : + /* Fall through */ + case 'f' : + /* Fall through */ + case 'g' : + /* Fall through */ + case 'G' : + ERROR( "%%%c is not supported by FormatMessage.\n", c ); + SetLastError( ERROR_INVALID_PARAMETER ); + return NULL; + } + + nFormatLength = PAL_wcslen( lpPrintfString ) + 2; /* Need to count % AND NULL */ + lpFormat = (LPWSTR)PAL_malloc( nFormatLength * sizeof( WCHAR ) ); + if ( !lpFormat ) + { + ERROR( "Unable to allocate memory.\n" ); + SetLastError( ERROR_NOT_ENOUGH_MEMORY ); + return NULL; + } + /* Create the format string. */ + memset( lpFormat, 0, nFormatLength * sizeof(WCHAR) ); + *lpFormat = '%'; + + PAL_wcscat( lpFormat, lpPrintfString ); + + lpBuffer = (LPWSTR) PAL_malloc(tmpSize*sizeof(WCHAR)); + + /* try until the buffer is big enough */ + while (TRUE) + { + if (!lpBuffer) + { + ERROR("Unable to allocate memory\n"); + SetLastError( ERROR_NOT_ENOUGH_MEMORY ); + PAL_free(lpFormat); + return NULL; + } + nBufferLength = _snwprintf_s( lpBuffer, tmpSize, tmpSize, + lpFormat, lpInsertString); + + if ((nBufferLength >= 0) && (nBufferLength != tmpSize)) + { + break; /* succeeded */ + } + else + { + tmpSize *= 2; + lpBuffer2 = static_cast( + PAL_realloc(lpBuffer, tmpSize*sizeof(WCHAR))); + if (lpBuffer2 == NULL) + PAL_free(lpBuffer); + lpBuffer = lpBuffer2; + } + } + + PAL_free( lpFormat ); + lpFormat = NULL; + + return lpBuffer; +} + /*++ Function: FormatMessageW @@ -385,33 +481,113 @@ FormatMessageW( } if ( *lpSourceString == '!' ) { - ERROR( "Embedded printf formatting ('!!') is unsupported\n" ); - SetLastError( ERROR_INVALID_PARAMETER ); - lpWorkingString = NULL; - nCount = 0; - goto exit; - } + LPWSTR lpInsertString = NULL; + LPWSTR lpPrintfString = NULL; + LPWSTR lpStartOfFormattedString = NULL; + UINT nPrintfLength = 0; + LPWSTR lpFormattedString = NULL; + UINT nFormattedLength = 0; + + if ( !bIsVaList ) + { + lpInsertString = ((LPWSTR*)Arguments)[ Index - 1 ]; + } + else + { + va_list TheArgs; + + va_copy(TheArgs, *Arguments); + UINT i = 0; + for ( ; i < Index; i++ ) + { + lpInsertString = va_arg( TheArgs, LPWSTR ); + } + } - LPWSTR lpInsert = NULL; - if ( !bIsVaList ) - { - lpInsert = ((LPWSTR*)Arguments)[Index - 1]; + /* Calculate the length, and extract the printf string.*/ + lpSourceString++; + { + LPWSTR p = PAL_wcschr( lpSourceString, '!' ); + + if ( NULL == p ) + { + nPrintfLength = 0; + } + else + { + nPrintfLength = p - lpSourceString; + } + } + + lpPrintfString = + (LPWSTR)PAL_malloc( ( nPrintfLength + 1 ) * sizeof( WCHAR ) ); + + if ( !lpPrintfString ) + { + ERROR( "Unable to allocate memory.\n" ); + SetLastError( ERROR_NOT_ENOUGH_MEMORY ); + lpWorkingString = NULL; + nCount = 0; + goto exit; + } + + PAL_wcsncpy( lpPrintfString, lpSourceString, nPrintfLength ); + *( lpPrintfString + nPrintfLength ) = '\0'; + + lpStartOfFormattedString = lpFormattedString = + FMTMSG_ProcessPrintf( *lpPrintfString, + lpPrintfString, + lpInsertString); + + if ( !lpFormattedString ) + { + ERROR( "Unable to process the format string.\n" ); + /* Function will set the error code. */ + PAL_free( lpPrintfString ); + lpWorkingString = NULL; + goto exit; + } + + + nFormattedLength = PAL_wcslen( lpFormattedString ); + + /* Append the processed printf string into the working string */ + while ( *lpFormattedString ) + { + _CHECKED_ADD_TO_STRING( *lpFormattedString ); + lpFormattedString++; + } + + lpSourceString += nPrintfLength + 1; + PAL_free( lpPrintfString ); + PAL_free( lpStartOfFormattedString ); + lpPrintfString = lpFormattedString = NULL; } else { - va_list TheArgs; - va_copy(TheArgs, *Arguments); - UINT i = 0; - for ( ; i < Index; i++ ) + /* The printf format string defaults to 's'.*/ + LPWSTR lpInsert = NULL; + + if ( !bIsVaList ) { - lpInsert = va_arg( TheArgs, LPWSTR ); + lpInsert = ((LPWSTR*)Arguments)[Index - 1]; + } + else + { + va_list TheArgs; + va_copy(TheArgs, *Arguments); + UINT i = 0; + for ( ; i < Index; i++ ) + { + lpInsert = va_arg( TheArgs, LPWSTR ); + } } - } - while ( *lpInsert ) - { - _CHECKED_ADD_TO_STRING( *lpInsert ); - lpInsert++; + while ( *lpInsert ) + { + _CHECKED_ADD_TO_STRING( *lpInsert ); + lpInsert++; + } } } /* Format specifiers. */ diff --git a/src/coreclr/pal/src/safecrt/internal.h b/src/coreclr/pal/src/safecrt/internal.h index 8c1a6e57243667..b3d8ffbaf5905c 100644 --- a/src/coreclr/pal/src/safecrt/internal.h +++ b/src/coreclr/pal/src/safecrt/internal.h @@ -279,7 +279,10 @@ int __cdecl _output(__inout FILE * _File, _In_z_ __format_string const char *_Fo int __cdecl _woutput(__inout FILE * _File, _In_z_ __format_string const char16_t *_Format, va_list _ArgList); int __cdecl _output_s(__inout FILE * _File, _In_z_ __format_string const char *_Format, va_list _ArgList); int __cdecl _output_p(__inout FILE * _File, _In_z_ __format_string const char *_Format, va_list _ArgList); +int __cdecl _woutput_s(__inout FILE * _File, _In_z_ __format_string const char16_t *_Format, va_list _ArgList); +int __cdecl _woutput_p(__inout FILE * _File, _In_z_ __format_string const char16_t *_Format, va_list _ArgList); typedef int (*OUTPUTFN)(FILE *, const char *, va_list); +typedef int (*WOUTPUTFN)(FILE *, const char16_t *, va_list); #else /* _SAFECRT_IMPL */ @@ -287,7 +290,10 @@ int __cdecl _output_l(__inout FILE * _File, _In_z_ __format_string const char *_ int __cdecl _woutput_l(__inout FILE * _File, _In_z_ __format_string const char16_t *_Format, _In_opt_ _locale_t _Locale, va_list _ArgList); int __cdecl _output_s_l(__inout FILE * _File, _In_z_ __format_string const char *_Format, _In_opt_ _locale_t _Locale, va_list _ArgList); int __cdecl _output_p_l(__inout FILE * _File, _In_z_ __format_string const char *_Format, _In_opt_ _locale_t _Locale, va_list _ArgList); +int __cdecl _woutput_s_l(__inout FILE * _File, _In_z_ __format_string const char16_t *_Format, _In_opt_ _locale_t _Locale, va_list _ArgList); +int __cdecl _woutput_p_l(__inout FILE * _File, _In_z_ __format_string const char16_t *_Format, _In_opt_ _locale_t _Locale, va_list _ArgList); typedef int (*OUTPUTFN)(__inout FILE * _File, const char *, _locale_t, va_list); +typedef int (*WOUTPUTFN)(__inout FILE * _File, const char16_t *, _locale_t, va_list); #endif /* _SAFECRT_IMPL */ @@ -296,6 +302,7 @@ typedef int (*OUTPUTFN)(__inout FILE * _File, const char *, _locale_t, va_list); int __cdecl _input(_In_ FILE * _File, _In_z_ __format_string const unsigned char * _Format, va_list _ArgList); int __cdecl _winput(_In_ FILE * _File, _In_z_ __format_string const char16_t * _Format, va_list _ArgList); int __cdecl _input_s(_In_ FILE * _File, _In_z_ __format_string const unsigned char * _Format, va_list _ArgList); +int __cdecl _winput_s(_In_ FILE * _File, _In_z_ __format_string const char16_t * _Format, va_list _ArgList); typedef int (*INPUTFN)(FILE *, const unsigned char *, va_list); typedef int (*WINPUTFN)(FILE *, const char16_t *, va_list); diff --git a/src/coreclr/pal/src/safecrt/mbusafecrt_internal.h b/src/coreclr/pal/src/safecrt/mbusafecrt_internal.h index 591e213a39aae4..b00bd2b1b30bbe 100644 --- a/src/coreclr/pal/src/safecrt/mbusafecrt_internal.h +++ b/src/coreclr/pal/src/safecrt/mbusafecrt_internal.h @@ -88,6 +88,7 @@ void _safecrt_wfassign(int flag, void* argument, char16_t * number ); int _minimal_chartowchar( char16_t* outWChar, const char* inChar ); int _output_s( miniFILE* outfile, const char* _Format, va_list _ArgList); +int _woutput_s( miniFILE* outfile, const char16_t* _Format, va_list _ArgList); int _output( miniFILE *outfile, const char* _Format, va_list _ArgList); int __tinput_s( miniFILE* inFile, const unsigned char * inFormat, va_list inArgList ); diff --git a/src/coreclr/pal/src/safecrt/swprintf.cpp b/src/coreclr/pal/src/safecrt/swprintf.cpp new file mode 100644 index 00000000000000..1971924463e0d1 --- /dev/null +++ b/src/coreclr/pal/src/safecrt/swprintf.cpp @@ -0,0 +1,100 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*** +*swprintf.c - print formatted to string +* +*Purpose: +* defines _swprintf(), _swprintf_c and _snwprintf() - print formatted data +* to string +* +*******************************************************************************/ + +#include +#include +#include +#include "internal_securecrt.h" + +#include "mbusafecrt_internal.h" + +/*** +*ifndef _COUNT_ +*int _swprintf(string, format, ...) - print formatted data to string +*else +*ifndef _SWPRINTFS_ERROR_RETURN_FIX +*int _snwprintf(string, cnt, format, ...) - print formatted data to string +*else +*int _swprintf_c(string, cnt, format, ...) - print formatted data to string +*endif +*endif +* +*Purpose: +* Prints formatted data to the using the format string to +* format data and getting as many arguments as called for +* Sets up a FILE so file i/o operations can be used, make +* string look like a huge buffer to it, but _flsbuf will +* refuse to flush it if it fills up. Appends '\0' to make +* it a true string. _output does the real work here +* +* Allocate the 'fake' _iob[] entry statically instead of on +* the stack so that other routines can assume that _iob[] +* entries are in are in DGROUP and, thus, are near. +* +* We alias swprintf to _swprintf +* +*ifdef _COUNT_ +*ifndef _SWPRINTFS_ERROR_RETURN_FIX +* The _snwprintf() flavor takes a count argument that is +* the max number of wide characters that should be written to the +* user's buffer. +* We don't expose this function directly in the headers. +*else +* The _swprintf_c() flavor does the same thing as the _snwprintf +* above, but, it also fixes a issue in the return value in the case +* when there isn't enough space to write the null terminator +* We don't fix this issue in _snwprintf because of backward +* compatibility. In new code, however, _snwprintf is #defined to +* _swprintf_c so users get the fix. +* +*endif +* +* Multi-thread: (1) Since there is no stream, this routine must +* never try to get the stream lock (i.e., there is no stream +* lock either). (2) Also, since there is only one statically +* allocated 'fake' iob, we must lock/unlock to prevent collisions. +* +*Entry: +* char16_t *string - pointer to place to put output +*ifdef _COUNT_ +* size_t count - max number of wide characters to put in buffer +*endif +* char16_t *format - format string to control data format/number +* of arguments followed by list of arguments, number and type +* controlled by format string +* +*Exit: +* returns number of wide characters printed +* +*Exceptions: +* +*******************************************************************************/ + +DLLEXPORT int __cdecl _snwprintf_s ( + char16_t *string, + size_t sizeInWords, + size_t count, + const char16_t *format, + ... + ) +{ + int ret; + va_list arglist; + + va_start(arglist, format); + + ret = _vsnwprintf_s(string, sizeInWords, count, format, arglist); + + va_end(arglist); + + return ret; +} diff --git a/src/coreclr/pal/src/safecrt/vswprint.cpp b/src/coreclr/pal/src/safecrt/vswprint.cpp new file mode 100644 index 00000000000000..a5407ed108ef21 --- /dev/null +++ b/src/coreclr/pal/src/safecrt/vswprint.cpp @@ -0,0 +1,178 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*** +*vswprint.c - print formatted data into a string from var arg list +* +*Purpose: +* defines _vsnwprintf_s() - print formatted output to +* a string, get the data from an argument ptr instead of explicit +* arguments. +* +*******************************************************************************/ + + +#include +#include +#include +#include "internal_securecrt.h" + +#include "mbusafecrt_internal.h" + +typedef int (*WOUTPUTFN)(miniFILE *, const char16_t *, va_list); + +static int _vswprintf_helper( WOUTPUTFN outfn, char16_t *string, size_t count, const char16_t *format, va_list ap ); + +/*** +*int _vsnwprintf_s(string, sizeInWords, cnt, format, ap) - print formatted data to string from arg ptr +*Purpose: +* Prints formatted data, but to a string and gets data from an argument +* pointer. +* Sets up a FILE so file i/o operations can be used, make string look +* like a huge buffer to it, but _flsbuf will refuse to flush it if it +* fills up. Appends '\0' to make it a true string. +* +* Allocate the 'fake' _iob[] entryit statically instead of on +* the stack so that other routines can assume that _iob[] entries are in +* are in DGROUP and, thus, are near. +* +* The _vsnwprintf_s() flavor takes a count argument that is +* the max number of bytes that should be written to the +* user's buffer. +* We don't expose this function directly in the headers. +* +* Multi-thread: (1) Since there is no stream, this routine must never try +* to get the stream lock (i.e., there is no stream lock either). (2) +* Also, since there is only one statically allocated 'fake' iob, we must +* lock/unlock to prevent collisions. +* +*Entry: +* char16_t *string - place to put destination string +* size_t sizeInWords - size of the string buffer in char16_t units +* size_t count - max number of bytes to put in buffer +* char16_t *format - format string, describes format of data +* va_list ap - varargs argument pointer +* +*Exit: +* returns number of wide characters in string +* returns -2 if the string has been truncated (only in _vsnprintf_helper) +* returns -1 in other error cases +* +*Exceptions: +* +*******************************************************************************/ + +int __cdecl _vswprintf_helper ( + WOUTPUTFN woutfn, + char16_t *string, + size_t count, + const char16_t *format, + va_list ap + ) +{ + miniFILE str; + miniFILE *outfile = &str; + int retval; + + _VALIDATE_RETURN( (format != NULL), EINVAL, -1); + + _VALIDATE_RETURN( (count == 0) || (string != NULL), EINVAL, -1 ); + + outfile->_flag = _IOWRT|_IOSTRG; + outfile->_ptr = outfile->_base = (char *) string; + + if(count>(INT_MAX/sizeof(char16_t))) + { + /* old-style functions allow any large value to mean unbounded */ + outfile->_cnt = INT_MAX; + } + else + { + outfile->_cnt = (int)(count*sizeof(char16_t)); + } + + retval = woutfn(outfile, format, ap ); + + if(string==NULL) + { + return retval; + } + + if((retval >= 0) && (_putc_nolock('\0',outfile) != EOF) && (_putc_nolock('\0',outfile) != EOF)) + return(retval); + + string[count - 1] = 0; + if (outfile->_cnt < 0) + { + /* the buffer was too small; we return -2 to indicate truncation */ + return -2; + } + return -1; +} + +DLLEXPORT int __cdecl _vsnwprintf_s ( + char16_t *string, + size_t sizeInWords, + size_t count, + const char16_t *format, + va_list ap + ) +{ + int retvalue = -1; + errno_t save_errno = 0; + + /* validation section */ + _VALIDATE_RETURN(format != NULL, EINVAL, -1); + if (count == 0 && string == NULL && sizeInWords == 0) + { + /* this case is allowed; nothing to do */ + return 0; + } + _VALIDATE_RETURN(string != NULL && sizeInWords > 0, EINVAL, -1); + + if (sizeInWords > count) + { + save_errno = errno; + retvalue = _vswprintf_helper(_woutput_s, string, count + 1, format, ap); + if (retvalue == -2) + { + /* the string has been truncated, return -1 */ + _SECURECRT__FILL_STRING(string, sizeInWords, count + 1); + if (errno == ERANGE) + { + errno = save_errno; + } + return -1; + } + } + else /* sizeInWords <= count */ + { + save_errno = errno; + retvalue = _vswprintf_helper(_woutput_s, string, sizeInWords, format, ap); + string[sizeInWords - 1] = 0; + /* we allow truncation if count == _TRUNCATE */ + if (retvalue == -2 && count == _TRUNCATE) + { + if (errno == ERANGE) + { + errno = save_errno; + } + return -1; + } + } + + if (retvalue < 0) + { + string[0] = 0; + _SECURECRT__FILL_STRING(string, sizeInWords, 1); + if (retvalue == -2) + { + _VALIDATE_RETURN(("Buffer too small" && 0), ERANGE, -1); + } + return -1; + } + + _SECURECRT__FILL_STRING(string, sizeInWords, retvalue + 1); + + return (retvalue < 0 ? -1 : retvalue); +} diff --git a/src/coreclr/pal/tests/palsuite/CMakeLists.txt b/src/coreclr/pal/tests/palsuite/CMakeLists.txt index 00fa596f193a94..8526ac88f63bdd 100644 --- a/src/coreclr/pal/tests/palsuite/CMakeLists.txt +++ b/src/coreclr/pal/tests/palsuite/CMakeLists.txt @@ -321,6 +321,24 @@ add_executable_clr(paltests c_runtime/vsprintf/test7/test7.cpp c_runtime/vsprintf/test8/test8.cpp c_runtime/vsprintf/test9/test9.cpp + c_runtime/vswprintf/test1/test1.cpp + c_runtime/vswprintf/test10/test10.cpp + c_runtime/vswprintf/test11/test11.cpp + c_runtime/vswprintf/test12/test12.cpp + c_runtime/vswprintf/test13/test13.cpp + c_runtime/vswprintf/test14/test14.cpp + c_runtime/vswprintf/test15/test15.cpp + c_runtime/vswprintf/test16/test16.cpp + c_runtime/vswprintf/test17/test17.cpp + c_runtime/vswprintf/test18/test18.cpp + c_runtime/vswprintf/test19/test19.cpp + c_runtime/vswprintf/test2/test2.cpp + c_runtime/vswprintf/test3/test3.cpp + c_runtime/vswprintf/test4/test4.cpp + c_runtime/vswprintf/test6/test6.cpp + c_runtime/vswprintf/test7/test7.cpp + c_runtime/vswprintf/test8/test8.cpp + c_runtime/vswprintf/test9/test9.cpp c_runtime/wcscat/test1/test1.cpp c_runtime/wcschr/test1/test1.cpp c_runtime/wcscmp/test1/test1.cpp @@ -371,6 +389,24 @@ add_executable_clr(paltests c_runtime/_snprintf_s/test7/test7.cpp c_runtime/_snprintf_s/test8/test8.cpp c_runtime/_snprintf_s/test9/test9.cpp + c_runtime/_snwprintf_s/test1/test1.cpp + c_runtime/_snwprintf_s/test10/test10.cpp + c_runtime/_snwprintf_s/test11/test11.cpp + c_runtime/_snwprintf_s/test12/test12.cpp + c_runtime/_snwprintf_s/test13/test13.cpp + c_runtime/_snwprintf_s/test14/test14.cpp + c_runtime/_snwprintf_s/test15/test15.cpp + c_runtime/_snwprintf_s/test16/test16.cpp + c_runtime/_snwprintf_s/test17/test17.cpp + c_runtime/_snwprintf_s/test18/test18.cpp + c_runtime/_snwprintf_s/test19/test19.cpp + c_runtime/_snwprintf_s/test2/test2.cpp + c_runtime/_snwprintf_s/test3/test3.cpp + c_runtime/_snwprintf_s/test4/test4.cpp + c_runtime/_snwprintf_s/test6/test6.cpp + c_runtime/_snwprintf_s/test7/test7.cpp + c_runtime/_snwprintf_s/test8/test8.cpp + c_runtime/_snwprintf_s/test9/test9.cpp c_runtime/_stricmp/test1/test1.cpp c_runtime/_strnicmp/test1/test1.cpp c_runtime/_vsnprintf_s/test1/test1.cpp @@ -391,6 +427,24 @@ add_executable_clr(paltests c_runtime/_vsnprintf_s/test7/test7.cpp c_runtime/_vsnprintf_s/test8/test8.cpp c_runtime/_vsnprintf_s/test9/test9.cpp + c_runtime/_vsnwprintf_s/test1/test1.cpp + c_runtime/_vsnwprintf_s/test10/test10.cpp + c_runtime/_vsnwprintf_s/test11/test11.cpp + c_runtime/_vsnwprintf_s/test12/test12.cpp + c_runtime/_vsnwprintf_s/test13/test13.cpp + c_runtime/_vsnwprintf_s/test14/test14.cpp + c_runtime/_vsnwprintf_s/test15/test15.cpp + c_runtime/_vsnwprintf_s/test16/test16.cpp + c_runtime/_vsnwprintf_s/test17/test17.cpp + c_runtime/_vsnwprintf_s/test18/test18.cpp + c_runtime/_vsnwprintf_s/test19/test19.cpp + c_runtime/_vsnwprintf_s/test2/test2.cpp + c_runtime/_vsnwprintf_s/test3/test3.cpp + c_runtime/_vsnwprintf_s/test4/test4.cpp + c_runtime/_vsnwprintf_s/test6/test6.cpp + c_runtime/_vsnwprintf_s/test7/test7.cpp + c_runtime/_vsnwprintf_s/test8/test8.cpp + c_runtime/_vsnwprintf_s/test9/test9.cpp c_runtime/_wcsicmp/test1/test1.cpp c_runtime/_wcslwr_s/test1/test1.cpp c_runtime/_wcsnicmp/test1/test1.cpp diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/_snwprintf_s.h b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/_snwprintf_s.h new file mode 100644 index 00000000000000..cf7f9c22cdbc02 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/_snwprintf_s.h @@ -0,0 +1,209 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*============================================================================ +** +** Source: _snwprintf_s.h +** +** Purpose: Contains common testing functions for _snwprintf_s +** +** +**==========================================================================*/ + +#ifndef ___SNWPRINTF_H__ +#define ___SNWPRINTF_H__ + +inline void DoWStrTest_snwprintf_s(const WCHAR *formatstr, WCHAR *param, const WCHAR *checkstr) +{ + WCHAR buf[256] = { 0 }; + + _snwprintf_s(buf, 256, _TRUNCATE, formatstr, param); + + if (memcmp(buf, checkstr, wcslen(checkstr) * 2 + 2) != 0) + { + Fail("ERROR: failed to insert wide string \"%s\" into \"%s\".\n" + "Expected \"%s\", got \"%s\".\n", convertC(param), + convertC(formatstr), convertC(checkstr), convertC(buf)); + } +} +#define DoWStrTest DoWStrTest_snwprintf_s + +inline void DoStrTest_snwprintf_s(const WCHAR *formatstr, char *param, const WCHAR *checkstr) +{ + WCHAR buf[256] = { 0 }; + + _snwprintf_s(buf, 256, _TRUNCATE, formatstr, param); + + if (memcmp(buf, checkstr, wcslen(checkstr) * 2 + 2) != 0) + { + Fail("ERROR: failed to insert wide string \"%s\" into \"%s\".\n" + "Expected \"%s\", got \"%s\".\n", + param, convertC(formatstr), convertC(checkstr), convertC(buf)); + } +} +#define DoStrTest DoStrTest_snwprintf_s + +inline void DoPointerTest_snwprintf_s(const WCHAR *formatstr, void* param, const WCHAR *checkstr1) +{ + WCHAR buf[256] = { 0 }; + + _snwprintf_s(buf, 256, _TRUNCATE, formatstr, param); + if (memcmp(buf, checkstr1, wcslen(checkstr1)*2 + 2) != 0) + { + Fail("ERROR: failed to insert pointer to %#p into \"%s\"\n" + "Expected \"%s\", got \"%s\".\n", param, convertC(formatstr), + convertC(checkstr1), convertC(buf)); + } +} +#define DoPointerTest DoPointerTest_snwprintf_s + +inline void DoCountTest_snwprintf_s(const WCHAR *formatstr, int param, const WCHAR *checkstr) +{ + WCHAR buf[512] = { 0 }; + int n = -1; + + _snwprintf_s(buf, 512, _TRUNCATE, formatstr, &n); + + if (n != param) + { + Fail("ERROR: Expected count parameter to resolve to %d, got %d\n", + param, n); + } + + if (memcmp(buf, checkstr, wcslen(checkstr)*2 + 2) != 0) + { + Fail("ERROR: Expected \"%s\" got \"%s\".\n", + convertC(checkstr), convertC(buf)); + } +} +#define DoCountTest DoCountTest_snwprintf_s + +inline void DoShortCountTest_snwprintf_s(const WCHAR *formatstr, int param, const WCHAR *checkstr) +{ + WCHAR buf[256] = { 0 }; + short int n = -1; + + _snwprintf_s(buf, 256, _TRUNCATE, formatstr, &n); + + if (n != param) + { + Fail("ERROR: Expected count parameter to resolve to %d, got %d\n", + param, n); + } + + if (memcmp(buf, checkstr, wcslen(checkstr)*2 + 2) != 0) + { + Fail("ERROR: Expected \"%s\" got \"%s\".\n", + convertC(checkstr), convertC(buf)); + } +} +#define DoShortCountTest DoShortCountTest_snwprintf_s + +inline void DoCharTest_snwprintf_s(const WCHAR *formatstr, char param, const WCHAR *checkstr) +{ + WCHAR buf[256] = { 0 }; + + _snwprintf_s(buf, 256, _TRUNCATE, formatstr, param); + if (memcmp(buf, checkstr, wcslen(checkstr)*2 + 2) != 0) + { + Fail("ERROR: failed to insert char \'%c\' (%d) into \"%s\"\n" + "Expected \"%s\" got \"%s\".\n", param, param, + convertC(formatstr), convertC(checkstr), convertC(buf)); + } +} +#define DoCharTest DoCharTest_snwprintf_s + +inline void DoWCharTest_snwprintf_s(const WCHAR *formatstr, WCHAR param, const WCHAR *checkstr) +{ + WCHAR buf[256] = { 0 }; + + _snwprintf_s(buf, 256, _TRUNCATE, formatstr, param); + if (memcmp(buf, checkstr, wcslen(checkstr)*2 + 2) != 0) + { + Fail("ERROR: failed to insert wide char \'%c\' (%d) into \"%s\"\n" + "Expected \"%s\" got \"%s\".\n", (char) param, param, + convertC(formatstr), convertC(checkstr), convertC(buf)); + } +} +#define DoWCharTest DoWCharTest_snwprintf_s + +inline void DoNumTest_snwprintf_s(const WCHAR *formatstr, int value, const WCHAR *checkstr) +{ + WCHAR buf[256] = { 0 }; + + _snwprintf_s(buf, 256, _TRUNCATE, formatstr, value); + if (memcmp(buf, checkstr, wcslen(checkstr)* 2 + 2) != 0) + { + Fail("ERROR: failed to insert %#x into \"%s\"\n" + "Expected \"%s\" got \"%s\".\n", value, convertC(formatstr), + convertC(checkstr), convertC(buf)); + } +} +#define DoNumTest DoNumTest_snwprintf_s + +inline void DoI64Test_snwprintf_s(const WCHAR *formatstr, INT64 param, char *paramdesc, + const WCHAR *checkstr1) +{ + WCHAR buf[256] = { 0 }; + + _snwprintf_s(buf, 256, _TRUNCATE, formatstr, param); + if (memcmp(buf, checkstr1, wcslen(checkstr1)*2 + 2) != 0) + { + Fail("ERROR: failed to insert %s into \"%s\"\n" + "Expected \"%s\", got \"%s\".\n", paramdesc, + convertC(formatstr), convertC(checkstr1), convertC(buf)); + } +} +#define DoI64Test DoI64Test_snwprintf_s + +inline void DoDoubleTest_snwprintf_s(const WCHAR *formatstr, double value, const WCHAR *checkstr1, + const WCHAR *checkstr2) +{ + WCHAR buf[256] = { 0 }; + + _snwprintf_s(buf, 256, _TRUNCATE, formatstr, value); + if (memcmp(buf, checkstr1, wcslen(checkstr1)*2 + 2) != 0 && + memcmp(buf, checkstr2, wcslen(checkstr2)*2 + 2) != 0) + { + Fail("ERROR: failed to insert %f into \"%s\"\n" + "Expected \"%s\" or \"%s\", got \"%s\".\n", + value, convertC(formatstr), convertC(checkstr1), + convertC(checkstr2), convertC(buf)); + } +} +#define DoDoubleTest DoDoubleTest_snwprintf_s + +inline void DoArgumentPrecTest_snwprintf_s(const WCHAR *formatstr, int precision, void *param, + char *paramstr, const WCHAR *checkstr1, const WCHAR *checkstr2) +{ + WCHAR buf[256]; + + _snwprintf_s(buf, 256, _TRUNCATE, formatstr, precision, param); + if (memcmp(buf, checkstr1, wcslen(checkstr1) + 2) != 0 && + memcmp(buf, checkstr2, wcslen(checkstr2) + 2) != 0) + { + Fail("ERROR: failed to insert %s into \"%s\" with precision %d\n" + "Expected \"%s\" or \"%s\", got \"%s\".\n", + paramstr, convertC(formatstr), precision, + convertC(checkstr1), convertC(checkstr2) ,convertC(buf)); + } +} +#define DoArgumentPrecTest DoArgumentPrecTest_snwprintf_s + +inline void DoArgumentPrecDoubleTest_snwprintf_s(const WCHAR *formatstr, int precision, double param, + const WCHAR *checkstr) +{ + WCHAR buf[256]; + + _snwprintf_s(buf, 256, _TRUNCATE, formatstr, precision, param); + if (memcmp(buf, checkstr, wcslen(checkstr) + 2) != 0) + { + Fail("ERROR: failed to insert %f into \"%s\" with precision %d\n" + "Expected \"%s\", got \"%s\".\n", param, convertC(formatstr), + precision, convertC(checkstr), convertC(buf)); + } +} +#define DoArgumentPrecDoubleTest DoArgumentPrecDoubleTest_snwprintf_s + +#endif + diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test1/test1.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test1/test1.cpp new file mode 100644 index 00000000000000..07bf99ca62306f --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test1/test1.cpp @@ -0,0 +1,61 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*============================================================================ +** +** Source: test1.c +** +** Purpose: General test to see if swprintf_s works correctly +** +** +**==========================================================================*/ + + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + + +PALTEST(c_runtime__snwprintf_s_test1_paltest_snwprintf_test1, "c_runtime/_snwprintf_s/test1/paltest_snwprintf_test1") +{ + WCHAR *checkstr; + WCHAR buf[256] = { 0 }; + int ret; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + checkstr = convert("hello world"); + _snwprintf_s(buf, 256, _TRUNCATE, checkstr); + if (memcmp(checkstr, buf, wcslen(checkstr)*2+2) != 0) + { + Fail("ERROR: Expected \"%s\", got \"%s\"\n", + convertC(checkstr), convertC(buf)); + } + + _snwprintf_s(buf, 256, _TRUNCATE, convert("xxxxxxxxxxxxxxxxx")); + ret = _snwprintf_s(buf, 8, _TRUNCATE, checkstr); + if ((memcmp(checkstr, buf, 14) != 0) || (buf[7] != 0)) + { + Fail("ERROR: Expected \"%8s\", got \"%8s\"\n", + convertC(checkstr), convertC(buf)); + } + if (ret >= 0) + { + Fail("ERROR: Expected negative return value, got %d.\n", ret); + } + if (buf[8] != (WCHAR) 'x') + { + Fail("ERROR: buffer overflow using \"%s\" with length 8.\n", + convertC(checkstr)); + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test10/test10.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test10/test10.cpp new file mode 100644 index 00000000000000..a872426e23e408 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test10/test10.cpp @@ -0,0 +1,53 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*============================================================================ +** +** Source: test10.c +** +** Purpose: Tests swprintf_s with octal numbers +** +** +**==========================================================================*/ + + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime__snwprintf_s_test10_paltest_snwprintf_test10, "c_runtime/_snwprintf_s/test10/paltest_snwprintf_test10") +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoNumTest(convert("foo %o"), pos, convert("foo 52")); + DoNumTest(convert("foo %lo"), 0xFFFF, convert("foo 177777")); + DoNumTest(convert("foo %ho"), 0xFFFF, convert("foo 177777")); + DoNumTest(convert("foo %Lo"), pos, convert("foo 52")); + DoI64Test(convert("foo %I64o"), l, "42", convert("foo 52")); + DoNumTest(convert("foo %3o"), pos, convert("foo 52")); + DoNumTest(convert("foo %-3o"), pos, convert("foo 52 ")); + DoNumTest(convert("foo %.1o"), pos, convert("foo 52")); + DoNumTest(convert("foo %.3o"), pos, convert("foo 052")); + DoNumTest(convert("foo %03o"), pos, convert("foo 052")); + DoNumTest(convert("foo %#o"), pos, convert("foo 052")); + DoNumTest(convert("foo %+o"), pos, convert("foo 52")); + DoNumTest(convert("foo % o"), pos, convert("foo 52")); + DoNumTest(convert("foo %+o"), neg, convert("foo 37777777726")); + DoNumTest(convert("foo % o"), neg, convert("foo 37777777726")); + + + PAL_Terminate(); + return PASS; +} + diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test11/test11.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test11/test11.cpp new file mode 100644 index 00000000000000..c05140698c7654 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test11/test11.cpp @@ -0,0 +1,53 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*============================================================================ +** +** Source: test11.c +** +** Purpose: Tests swprintf_s with unsigned numbers +** +** +**==========================================================================*/ + + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime__snwprintf_s_test11_paltest_snwprintf_test11, "c_runtime/_snwprintf_s/test11/paltest_snwprintf_test11") +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoNumTest(convert("foo %u"), pos, convert("foo 42")); + DoNumTest(convert("foo %lu"), 0xFFFF, convert("foo 65535")); + DoNumTest(convert("foo %hu"), 0xFFFF, convert("foo 65535")); + DoNumTest(convert("foo %Lu"), pos, convert("foo 42")); + DoI64Test(convert("foo %I64u"), l, "42", convert("foo 42")); + DoNumTest(convert("foo %3u"), pos, convert("foo 42")); + DoNumTest(convert("foo %-3u"), pos, convert("foo 42 ")); + DoNumTest(convert("foo %.1u"), pos, convert("foo 42")); + DoNumTest(convert("foo %.3u"), pos, convert("foo 042")); + DoNumTest(convert("foo %03u"), pos, convert("foo 042")); + DoNumTest(convert("foo %#u"), pos, convert("foo 42")); + DoNumTest(convert("foo %+u"), pos, convert("foo 42")); + DoNumTest(convert("foo % u"), pos, convert("foo 42")); + DoNumTest(convert("foo %+u"), neg, convert("foo 4294967254")); + DoNumTest(convert("foo % u"), neg, convert("foo 4294967254")); + + + PAL_Terminate(); + return PASS; +} + diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test12/test12.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test12/test12.cpp new file mode 100644 index 00000000000000..fd898e577e4d75 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test12/test12.cpp @@ -0,0 +1,53 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*============================================================================ +** +** Source: test12.c +** +** Purpose: Tests swprintf_s with hex numbers (lowercase) +** +** +**==========================================================================*/ + + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime__snwprintf_s_test12_paltest_snwprintf_test12, "c_runtime/_snwprintf_s/test12/paltest_snwprintf_test12") +{ + int neg = -42; + int pos = 0x1234ab; + INT64 l = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoNumTest(convert("foo %x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %lx"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %hx"), pos, convert("foo 34ab")); + DoNumTest(convert("foo %Lx"), pos, convert("foo 1234ab")); + DoI64Test(convert("foo %I64x"), l, "0x1234567887654321", + convert("foo 1234567887654321")); + DoNumTest(convert("foo %7x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %-7x"), pos, convert("foo 1234ab ")); + DoNumTest(convert("foo %.1x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %.7x"), pos, convert("foo 01234ab")); + DoNumTest(convert("foo %07x"), pos, convert("foo 01234ab")); + DoNumTest(convert("foo %#x"), pos, convert("foo 0x1234ab")); + DoNumTest(convert("foo %+x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo % x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %+x"), neg, convert("foo ffffffd6")); + DoNumTest(convert("foo % x"), neg, convert("foo ffffffd6")); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test13/test13.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test13/test13.cpp new file mode 100644 index 00000000000000..2c28531146a33c --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test13/test13.cpp @@ -0,0 +1,53 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*============================================================================ +** +** Source: test13.c +** +** Purpose: Tests swprintf_s with hex numbers (uppercase) +** +** +**==========================================================================*/ + + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime__snwprintf_s_test13_paltest_snwprintf_test13, "c_runtime/_snwprintf_s/test13/paltest_snwprintf_test13") +{ + int neg = -42; + int pos = 0x1234ab; + INT64 l = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoNumTest(convert("foo %X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %lX"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %hX"), pos, convert("foo 34AB")); + DoNumTest(convert("foo %LX"), pos, convert("foo 1234AB")); + DoI64Test(convert("foo %I64X"), l, "0x1234567887654321", + convert("foo 1234567887654321")); + DoNumTest(convert("foo %7X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %-7X"), pos, convert("foo 1234AB ")); + DoNumTest(convert("foo %.1X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %.7X"), pos, convert("foo 01234AB")); + DoNumTest(convert("foo %07X"), pos, convert("foo 01234AB")); + DoNumTest(convert("foo %#X"), pos, convert("foo 0X1234AB")); + DoNumTest(convert("foo %+X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo % X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %+X"), neg, convert("foo FFFFFFD6")); + DoNumTest(convert("foo % X"), neg, convert("foo FFFFFFD6")); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test14/test14.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test14/test14.cpp new file mode 100644 index 00000000000000..30475b8ff8619a --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test14/test14.cpp @@ -0,0 +1,65 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*============================================================================ +** +** Source: test14.c +** +** Purpose: Tests swprintf_s with exponential format doubles (lowercase) +** +** +**==========================================================================*/ + + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime__snwprintf_s_test14_paltest_snwprintf_test14, "c_runtime/_snwprintf_s/test14/paltest_snwprintf_test14") +{ + double val = 256.0; + double neg = -256.0; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoDoubleTest(convert("foo %e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %le"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %he"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %Le"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %I64e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %14e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %-14e"), val, convert("foo 2.560000e+002 "), + convert("foo 2.560000e+02 ")); + DoDoubleTest(convert("foo %.1e"), val, convert("foo 2.6e+002"), + convert("foo 2.6e+02")); + DoDoubleTest(convert("foo %.8e"), val, convert("foo 2.56000000e+002"), + convert("foo 2.56000000e+02")); + DoDoubleTest(convert("foo %014e"), val, convert("foo 02.560000e+002"), + convert("foo 002.560000e+02")); + DoDoubleTest(convert("foo %#e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %+e"), val, convert("foo +2.560000e+002"), + convert("foo +2.560000e+02")); + DoDoubleTest(convert("foo % e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %+e"), neg, convert("foo -2.560000e+002"), + convert("foo -2.560000e+02")); + DoDoubleTest(convert("foo % e"), neg, convert("foo -2.560000e+002"), + convert("foo -2.560000e+02")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test15/test15.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test15/test15.cpp new file mode 100644 index 00000000000000..5f52e1bae04801 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test15/test15.cpp @@ -0,0 +1,66 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*============================================================================ +** +** Source: test15.c +** +** Purpose: Tests swprintf_s with exponential format doubles (uppercase) +** +** +**==========================================================================*/ + + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + + +PALTEST(c_runtime__snwprintf_s_test15_paltest_snwprintf_test15, "c_runtime/_snwprintf_s/test15/paltest_snwprintf_test15") +{ + double val = 256.0; + double neg = -256.0; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoDoubleTest(convert("foo %E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %lE"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %hE"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %LE"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %I64E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %14E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %-14E"), val, convert("foo 2.560000E+002 "), + convert("foo 2.560000E+02 ")); + DoDoubleTest(convert("foo %.1E"), val, convert("foo 2.6E+002"), + convert("foo 2.6E+02")); + DoDoubleTest(convert("foo %.8E"), val, convert("foo 2.56000000E+002"), + convert("foo 2.56000000E+02")); + DoDoubleTest(convert("foo %014E"), val, convert("foo 02.560000E+002"), + convert("foo 002.560000E+02")); + DoDoubleTest(convert("foo %#E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %+E"), val, convert("foo +2.560000E+002"), + convert("foo +2.560000E+02")); + DoDoubleTest(convert("foo % E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %+E"), neg, convert("foo -2.560000E+002"), + convert("foo -2.560000E+02")); + DoDoubleTest(convert("foo % E"), neg, convert("foo -2.560000E+002"), + convert("foo -2.560000E+02")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test16/test16.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test16/test16.cpp new file mode 100644 index 00000000000000..cc4c4f5649b428 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test16/test16.cpp @@ -0,0 +1,64 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*============================================================================ +** +** Source: test16.c +** +** Purpose: Tests swprintf_s with decimal point format doubles +** +** +**==========================================================================*/ + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime__snwprintf_s_test16_paltest_snwprintf_test16, "c_runtime/_snwprintf_s/test16/paltest_snwprintf_test16") +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoDoubleTest(convert("foo %f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %lf"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %hf"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %Lf"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %I64f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %12f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %-12f"), val, convert("foo 2560.001000 "), + convert("foo 2560.001000 ")); + DoDoubleTest(convert("foo %.1f"), val, convert("foo 2560.0"), + convert("foo 2560.0")); + DoDoubleTest(convert("foo %.8f"), val, convert("foo 2560.00100000"), + convert("foo 2560.00100000")); + DoDoubleTest(convert("foo %012f"), val, convert("foo 02560.001000"), + convert("foo 02560.001000")); + DoDoubleTest(convert("foo %#f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %+f"), val, convert("foo +2560.001000"), + convert("foo +2560.001000")); + DoDoubleTest(convert("foo % f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %+f"), neg, convert("foo -2560.001000"), + convert("foo -2560.001000")); + DoDoubleTest(convert("foo % f"), neg, convert("foo -2560.001000"), + convert("foo -2560.001000")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test17/test17.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test17/test17.cpp new file mode 100644 index 00000000000000..d86213f8bec375 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test17/test17.cpp @@ -0,0 +1,67 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*============================================================================ +** +** Source: test17.c +** +** Purpose: Tests swprintf_s with compact format doubles (lowercase) +** +** +**==========================================================================*/ + + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime__snwprintf_s_test17_paltest_snwprintf_test17, "c_runtime/_snwprintf_s/test17/paltest_snwprintf_test17") +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoDoubleTest(convert("foo %g"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %lg"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %hg"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %Lg"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %I64g"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %5g"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %-5g"), val, convert("foo 2560 "), + convert("foo 2560 ")); + DoDoubleTest(convert("foo %.1g"), val, convert("foo 3e+003"), + convert("foo 3e+03")); + DoDoubleTest(convert("foo %.2g"), val, convert("foo 2.6e+003"), + convert("foo 2.6e+03")); + DoDoubleTest(convert("foo %.12g"), val, convert("foo 2560.001"), + convert("foo 2560.001")); + DoDoubleTest(convert("foo %06g"), val, convert("foo 002560"), + convert("foo 002560")); + DoDoubleTest(convert("foo %#g"), val, convert("foo 2560.00"), + convert("foo 2560.00")); + DoDoubleTest(convert("foo %+g"), val, convert("foo +2560"), + convert("foo +2560")); + DoDoubleTest(convert("foo % g"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %+g"), neg, convert("foo -2560"), + convert("foo -2560")); + DoDoubleTest(convert("foo % g"), neg, convert("foo -2560"), + convert("foo -2560")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test18/test18.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test18/test18.cpp new file mode 100644 index 00000000000000..93c17a4cf9ec15 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test18/test18.cpp @@ -0,0 +1,68 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*============================================================================ +** +** Source: test18.c +** +** Purpose: Tests swprintf_s with compact format doubles (uppercase) +** +** +**==========================================================================*/ + + + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime__snwprintf_s_test18_paltest_snwprintf_test18, "c_runtime/_snwprintf_s/test18/paltest_snwprintf_test18") +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoDoubleTest(convert("foo %G"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %lG"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %hG"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %LG"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %I64G"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %5G"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %-5G"), val, convert("foo 2560 "), + convert("foo 2560 ")); + DoDoubleTest(convert("foo %.1G"), val, convert("foo 3E+003"), + convert("foo 3E+03")); + DoDoubleTest(convert("foo %.2G"), val, convert("foo 2.6E+003"), + convert("foo 2.6E+03")); + DoDoubleTest(convert("foo %.12G"), val, convert("foo 2560.001"), + convert("foo 2560.001")); + DoDoubleTest(convert("foo %06G"), val, convert("foo 002560"), + convert("foo 002560")); + DoDoubleTest(convert("foo %#G"), val, convert("foo 2560.00"), + convert("foo 2560.00")); + DoDoubleTest(convert("foo %+G"), val, convert("foo +2560"), + convert("foo +2560")); + DoDoubleTest(convert("foo % G"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %+G"), neg, convert("foo -2560"), + convert("foo -2560")); + DoDoubleTest(convert("foo % G"), neg, convert("foo -2560"), + convert("foo -2560")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test19/test19.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test19/test19.cpp new file mode 100644 index 00000000000000..eac6828a630147 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test19/test19.cpp @@ -0,0 +1,81 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*============================================================================ +** +** Source: test19.c +** +** Purpose: Tests swprintf_s with argument specified precision +** +** +**==========================================================================*/ + + + +#include +#include "../_snwprintf_s.h" + +PALTEST(c_runtime__snwprintf_s_test19_paltest_snwprintf_test19, "c_runtime/_snwprintf_s/test19/paltest_snwprintf_test19") +{ + int n = -1; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + DoArgumentPrecTest(convert("%.*s"), 2, (void*)convert("bar"), "bar", + convert("ba"), convert("ba")); + DoArgumentPrecTest(convert("%.*S"), 2, (void*)"bar", "bar", + convert("ba"), convert("ba")); + DoArgumentPrecTest(convert("%.*c"), 0, (void*)'a', "a", + convert("a"), convert("a")); + DoArgumentPrecTest(convert("%.*c"), 4, (void*)'a', "a", + convert("a"), convert("a")); + DoArgumentPrecTest(convert("%.*C"), 0, (void*)'a', "a", + convert("a"), convert("a")); + DoArgumentPrecTest(convert("%.*C"), 4, (void*)'a', "a", + convert("a"), convert("a")); + DoArgumentPrecTest(convert("%.*d"), 1, (void*)42, "42", + convert("42"), convert("42")); + DoArgumentPrecTest(convert("%.*d"), 3, (void*)42, "42", + convert("042"), convert("042")); + DoArgumentPrecTest(convert("%.*i"), 1, (void*)42, "42", + convert("42"), convert("42")); + DoArgumentPrecTest(convert("%.*i"), 3, (void*)42, "42", + convert("042"), convert("042")); + DoArgumentPrecTest(convert("%.*o"), 1, (void*)42, "42", + convert("52"), convert("52")); + DoArgumentPrecTest(convert("%.*o"), 3, (void*)42, "42", + convert("052"), convert("052")); + DoArgumentPrecTest(convert("%.*u"), 1, (void*)42, "42", + convert("42"), convert("42")); + DoArgumentPrecTest(convert("%.*u"), 3, (void*)42, "42", + convert("042"), convert("042")); + DoArgumentPrecTest(convert("%.*x"), 1, (void*)0x42, "0x42", + convert("42"), convert("42")); + DoArgumentPrecTest(convert("%.*x"), 3, (void*)0x42, "0x42", + convert("042"), convert("042")); + DoArgumentPrecTest(convert("%.*X"), 1, (void*)0x42, "0x42", + convert("42"), convert("42")); + DoArgumentPrecTest(convert("%.*X"), 3, (void*)0x42, "0x42", + convert("042"), convert("042")); + DoArgumentPrecDoubleTest(convert("%.*e"), 1, 2.01, convert("2.0e+000")); + DoArgumentPrecDoubleTest(convert("%.*e"), 3, 2.01, convert("2.010e+000")); + DoArgumentPrecDoubleTest(convert("%.*E"), 1, 2.01, convert("2.0E+000")); + DoArgumentPrecDoubleTest(convert("%.*E"), 3, 2.01, convert("2.010E+000")); + DoArgumentPrecDoubleTest(convert("%.*f"), 1, 2.01, convert("2.0")); + DoArgumentPrecDoubleTest(convert("%.*f"), 3, 2.01, convert("2.010")); + DoArgumentPrecDoubleTest(convert("%.*g"), 1, 256.01, convert("3e+002")); + DoArgumentPrecDoubleTest(convert("%.*g"), 3, 256.01, convert("256")); + DoArgumentPrecDoubleTest(convert("%.*g"), 4, 256.01, convert("256")); + DoArgumentPrecDoubleTest(convert("%.*g"), 6, 256.01, convert("256.01")); + DoArgumentPrecDoubleTest(convert("%.*G"), 1, 256.01, convert("3E+002")); + DoArgumentPrecDoubleTest(convert("%.*G"), 3, 256.01, convert("256")); + DoArgumentPrecDoubleTest(convert("%.*G"), 4, 256.01, convert("256")); + DoArgumentPrecDoubleTest(convert("%.*G"), 6, 256.01, convert("256.01")); + + PAL_Terminate(); + return PASS; + +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test2/test2.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test2/test2.cpp new file mode 100644 index 00000000000000..5d87d8abef8a37 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test2/test2.cpp @@ -0,0 +1,49 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*============================================================================ +** +** Source: test2.c +** +** Purpose:Tests swprintf_s with strings +** +** +**==========================================================================*/ + + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + + +PALTEST(c_runtime__snwprintf_s_test2_paltest_snwprintf_test2, "c_runtime/_snwprintf_s/test2/paltest_snwprintf_test2") +{ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + DoWStrTest(convert("foo %s"), convert("bar"), convert("foo bar")); + DoStrTest(convert("foo %hs"), "bar", convert("foo bar")); + DoWStrTest(convert("foo %ls"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %ws"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %Ls"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %I64s"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %5s"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %.2s"), convert("bar"), convert("foo ba")); + DoWStrTest(convert("foo %5.2s"), convert("bar"), convert("foo ba")); + DoWStrTest(convert("foo %-5s"), convert("bar"), convert("foo bar ")); + DoWStrTest(convert("foo %05s"), convert("bar"), convert("foo 00bar")); + DoWStrTest(convert("foo %s"), NULL, convert("foo (null)")); + DoStrTest(convert("foo %hs"), NULL, convert("foo (null)")); + DoWStrTest(convert("foo %ls"), NULL, convert("foo (null)")); + DoWStrTest(convert("foo %ws"), NULL, convert("foo (null)")); + DoWStrTest(convert("foo %Ls"), NULL, convert("foo (null)")); + DoWStrTest(convert("foo %I64s"), NULL, convert("foo (null)")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test3/test3.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test3/test3.cpp new file mode 100644 index 00000000000000..4eaf305d2094ab --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test3/test3.cpp @@ -0,0 +1,49 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*============================================================================ +** +** Source: test3.c +** +** Purpose: Tests swprintf_s with wide strings +** +** +**==========================================================================*/ + + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + + +PALTEST(c_runtime__snwprintf_s_test3_paltest_snwprintf_test3, "c_runtime/_snwprintf_s/test3/paltest_snwprintf_test3") +{ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + DoStrTest(convert("foo %S"), "bar", convert("foo bar")); + DoStrTest(convert("foo %hS"), "bar", convert("foo bar")); + DoWStrTest(convert("foo %lS"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %wS"), convert("bar"), convert("foo bar")); + DoStrTest(convert("foo %LS"), "bar", convert("foo bar")); + DoStrTest(convert("foo %I64S"), "bar", convert("foo bar")); + DoStrTest(convert("foo %5S"), "bar", convert("foo bar")); + DoStrTest(convert("foo %.2S"), "bar", convert("foo ba")); + DoStrTest(convert("foo %5.2S"), "bar", convert("foo ba")); + DoStrTest(convert("foo %-5S"), "bar", convert("foo bar ")); + DoStrTest(convert("foo %05S"), "bar", convert("foo 00bar")); + DoStrTest(convert("foo %S"), NULL, convert("foo (null)")); + DoStrTest(convert("foo %hS"), NULL, convert("foo (null)")); + DoWStrTest(convert("foo %lS"), NULL, convert("foo (null)")); + DoWStrTest(convert("foo %wS"), NULL, convert("foo (null)")); + DoStrTest(convert("foo %LS"), NULL, convert("foo (null)")); + DoStrTest(convert("foo %I64S"), NULL, convert("foo (null)")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test4/test4.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test4/test4.cpp new file mode 100644 index 00000000000000..95224422d1e2ad --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test4/test4.cpp @@ -0,0 +1,70 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*============================================================================ +** +** Source: test4.c +** +** Purpose: Tests swprintf_s with pointers +** +** +**==========================================================================*/ + + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + + +PALTEST(c_runtime__snwprintf_s_test4_paltest_snwprintf_test4, "c_runtime/_snwprintf_s/test4/paltest_snwprintf_test4") +{ + void *ptr = (void*) 0x123456; + INT64 lptr = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + +/* +** Run only on 64 bit platforms +*/ +#if defined(HOST_64BIT) + Trace("Testing for 64 Bit Platforms \n"); + DoPointerTest(convert("%p"), NULL, convert("0000000000000000")); + DoPointerTest(convert("%p"), ptr, convert("0000000000123456")); + DoPointerTest(convert("%17p"), ptr, convert(" 0000000000123456")); + DoPointerTest(convert("%17p"), ptr, convert(" 0000000000123456")); + DoPointerTest(convert("%-17p"), ptr, convert("0000000000123456 ")); + DoPointerTest(convert("%+p"), ptr, convert("0000000000123456")); + DoPointerTest(convert("% p"), ptr, convert("0000000000123456")); + DoPointerTest(convert("%#p"), ptr, convert("0X0000000000123456")); + DoPointerTest(convert("%lp"), ptr, convert("00123456")); + DoPointerTest(convert("%hp"), ptr, convert("00003456")); + DoPointerTest(convert("%Lp"), ptr, convert("00123456")); + DoI64Test(convert("%I64p"), lptr, "1234567887654321", + convert("1234567887654321")); +#else + Trace("Testing for Non 64 Bit Platforms \n"); + DoPointerTest(convert("%p"), NULL, convert("00000000")); + DoPointerTest(convert("%p"), ptr, convert("00123456")); + DoPointerTest(convert("%9p"), ptr, convert(" 00123456")); + DoPointerTest(convert("%09p"), ptr, convert(" 00123456")); + DoPointerTest(convert("%-9p"), ptr, convert("00123456 ")); + DoPointerTest(convert("%+p"), ptr, convert("00123456")); + DoPointerTest(convert("% p"), ptr, convert("00123456")); + DoPointerTest(convert("%#p"), ptr, convert("0X00123456")); + DoPointerTest(convert("%lp"), ptr, convert("00123456")); + DoPointerTest(convert("%hp"), ptr, convert("00003456")); + DoPointerTest(convert("%Lp"), ptr, convert("00123456")); + DoI64Test(convert("%I64p"), lptr, "1234567887654321", + convert("1234567887654321")); +#endif + + PAL_Terminate(); + return PASS; +} + diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test6/test6.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test6/test6.cpp new file mode 100644 index 00000000000000..1b2c375905ad4c --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test6/test6.cpp @@ -0,0 +1,45 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*============================================================================ +** +** Source: test6.c +** +** Purpose: Tests swprintf_s with characters +** +** +**==========================================================================*/ + + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime__snwprintf_s_test6_paltest_snwprintf_test6, "c_runtime/_snwprintf_s/test6/paltest_snwprintf_test6") +{ + WCHAR wc = (WCHAR) 'c'; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoWCharTest(convert("foo %c"), wc, convert("foo c")); + DoCharTest(convert("foo %hc"), 'b', convert("foo b")); + DoWCharTest(convert("foo %lc"), wc, convert("foo c")); + DoWCharTest(convert("foo %Lc"), wc, convert("foo c")); + DoWCharTest(convert("foo %I64c"), wc, convert("foo c")); + DoWCharTest(convert("foo %5c"), wc, convert("foo c")); + DoWCharTest(convert("foo %.0c"), wc, convert("foo c")); + DoWCharTest(convert("foo %-5c"), wc, convert("foo c ")); + DoWCharTest(convert("foo %05c"), wc, convert("foo 0000c")); + DoWCharTest(convert("foo % c"), wc, convert("foo c")); + DoWCharTest(convert("foo %#c"), wc, convert("foo c")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test7/test7.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test7/test7.cpp new file mode 100644 index 00000000000000..cca130c140249d --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test7/test7.cpp @@ -0,0 +1,45 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*============================================================================ +** +** Source: test7.c +** +** Purpose: Tests swprintf_s with wide characters +** +** +**==========================================================================*/ + + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime__snwprintf_s_test7_paltest_snwprintf_test7, "c_runtime/_snwprintf_s/test7/paltest_snwprintf_test7") +{ + WCHAR wc = (WCHAR) 'c'; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoCharTest(convert("foo %C"), 'b', convert("foo b")); + DoWCharTest(convert("foo %hC"), wc, convert("foo c")); + DoCharTest(convert("foo %lC"), 'b', convert("foo b")); + DoCharTest(convert("foo %LC"), 'b', convert("foo b")); + DoCharTest(convert("foo %I64C"), 'b', convert("foo b")); + DoCharTest(convert("foo %5C"), 'b', convert("foo b")); + DoCharTest(convert("foo %.0C"), 'b', convert("foo b")); + DoCharTest(convert("foo %-5C"), 'b', convert("foo b ")); + DoCharTest(convert("foo %05C"), 'b', convert("foo 0000b")); + DoCharTest(convert("foo % C"), 'b', convert("foo b")); + DoCharTest(convert("foo %#C"), 'b', convert("foo b")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test8/test8.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test8/test8.cpp new file mode 100644 index 00000000000000..c727f798224568 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test8/test8.cpp @@ -0,0 +1,52 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*============================================================================ +** +** Source: test8.c +** +** Purpose: Tests swprintf_s with decimal numbers +** +** +**==========================================================================*/ + + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime__snwprintf_s_test8_paltest_snwprintf_test8, "c_runtime/_snwprintf_s/test8/paltest_snwprintf_test8") +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoNumTest(convert("foo %d"), pos, convert("foo 42")); + DoNumTest(convert("foo %ld"), 0xFFFF, convert("foo 65535")); + DoNumTest(convert("foo %hd"), 0xFFFF, convert("foo -1")); + DoNumTest(convert("foo %Ld"), pos, convert("foo 42")); + DoI64Test(convert("foo %I64d"), l, "42", convert("foo 42")); + DoNumTest(convert("foo %3d"), pos, convert("foo 42")); + DoNumTest(convert("foo %-3d"), pos, convert("foo 42 ")); + DoNumTest(convert("foo %.1d"), pos, convert("foo 42")); + DoNumTest(convert("foo %.3d"), pos, convert("foo 042")); + DoNumTest(convert("foo %03d"), pos, convert("foo 042")); + DoNumTest(convert("foo %#d"), pos, convert("foo 42")); + DoNumTest(convert("foo %+d"), pos, convert("foo +42")); + DoNumTest(convert("foo % d"), pos, convert("foo 42")); + DoNumTest(convert("foo %+d"), neg, convert("foo -42")); + DoNumTest(convert("foo % d"), neg, convert("foo -42")); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test9/test9.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test9/test9.cpp new file mode 100644 index 00000000000000..b523b2886e6c97 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_snwprintf_s/test9/test9.cpp @@ -0,0 +1,52 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*============================================================================ +** +** Source: test9.c +** +** Purpose: Tests swprintf_s with integer numbers +** +** +**==========================================================================*/ + + + +#include +#include "../_snwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime__snwprintf_s_test9_paltest_snwprintf_test9, "c_runtime/_snwprintf_s/test9/paltest_snwprintf_test9") +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + + DoNumTest(convert("foo %i"), pos, convert("foo 42")); + DoNumTest(convert("foo %li"), 0xFFFF, convert("foo 65535")); + DoNumTest(convert("foo %hi"), 0xFFFF, convert("foo -1")); + DoNumTest(convert("foo %Li"), pos, convert("foo 42")); + DoI64Test(convert("foo %I64i"), l, "42", convert("foo 42")); + DoNumTest(convert("foo %3i"), pos, convert("foo 42")); + DoNumTest(convert("foo %-3i"), pos, convert("foo 42 ")); + DoNumTest(convert("foo %.1i"), pos, convert("foo 42")); + DoNumTest(convert("foo %.3i"), pos, convert("foo 042")); + DoNumTest(convert("foo %03i"), pos, convert("foo 042")); + DoNumTest(convert("foo %#i"), pos, convert("foo 42")); + DoNumTest(convert("foo %+i"), pos, convert("foo +42")); + DoNumTest(convert("foo % i"), pos, convert("foo 42")); + DoNumTest(convert("foo %+i"), neg, convert("foo -42")); + DoNumTest(convert("foo % i"), neg, convert("foo -42")); + + PAL_Terminate(); + return PASS; +} + diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/_vsnwprintf_s.h b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/_vsnwprintf_s.h new file mode 100644 index 00000000000000..540faf4dd5cfed --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/_vsnwprintf_s.h @@ -0,0 +1,139 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*============================================================================ +** +** Source: _vsnwprintf_s.h +** +** Purpose: Contains common testing functions for _vsnwprintf_s +** +** +**==========================================================================*/ + +#ifndef ___VSNWPRINTF_H__ +#define ___VSNWPRINTF_H__ + +/* These functions leaks memory a lot. C'est la vie. */ +inline int TestVsnwprintf_s(char16_t* buf, size_t count, const char16_t* format, ...) +{ + int retVal = 0; + va_list arglist; + + va_start(arglist, format); + retVal = _vsnwprintf_s(buf, count, _TRUNCATE, format, arglist); + va_end(arglist); + + return( retVal); +} + +inline void DoWStrTest_vsnwprintf_s(const WCHAR *formatstr, WCHAR *param, const WCHAR *checkstr) +{ + WCHAR buf[256] = { 0 }; + + TestVsnwprintf_s(buf, 256, formatstr, param); + + if (memcmp(buf, checkstr, wcslen(buf) * 2 + 2) != 0) + { + Fail("ERROR: failed to insert wide string \"%s\" into \"%s\".\n" + "Expected \"%s\", got \"%s\".\n", + convertC(param), convertC(formatstr), + convertC(checkstr), convertC(buf)); + } +} +#define DoWStrTest DoWStrTest_vsnwprintf_s + +inline void DoStrTest_vsnwprintf_s(const WCHAR *formatstr, char *param, const WCHAR *checkstr) +{ + WCHAR buf[256] = { 0 }; + + TestVsnwprintf_s(buf, 256, formatstr, param); + + if (memcmp(buf, checkstr, wcslen(buf) * 2 + 2) != 0) + { + Fail("ERROR: failed to insert wide string \"%s\" into \"%s\".\n" + "Expected \"%s\", got \"%s\".\n", + param, convertC(formatstr), convertC(checkstr), + convertC(buf)); + } +} +#define DoStrTest DoStrTest_vsnwprintf_s + +inline void DoCharTest_vsnwprintf_s(const WCHAR *formatstr, char param, const WCHAR *checkstr) +{ + WCHAR buf[256] = { 0 }; + + TestVsnwprintf_s(buf, 256, formatstr, param); + if (memcmp(buf, checkstr, wcslen(buf)*2 + 2) != 0) + { + Fail("ERROR: failed to insert char \'%c\' (%d) into \"%s\"\n" + "Expected \"%s\" got \"%s\".\n", + param, param, convertC(formatstr), convertC(checkstr), + convertC(buf)); + } +} +#define DoCharTest DoCharTest_vsnwprintf_s + +inline void DoWCharTest_vsnwprintf_s(const WCHAR *formatstr, WCHAR param, const WCHAR *checkstr) +{ + WCHAR buf[256] = { 0 }; + + TestVsnwprintf_s(buf, 256, formatstr, param); + if (memcmp(buf, checkstr, wcslen(buf)*2 + 2) != 0) + { + Fail("ERROR: failed to insert wide char \'%c\' (%d) into \"%s\"\n" + "Expected \"%s\" got \"%s\".\n", + (char) param, param, convertC(formatstr), + convertC(checkstr), convertC(buf)); + } +} +#define DoWCharTest DoWCharTest_vsnwprintf_s + +inline void DoNumTest_vsnwprintf_s(const WCHAR *formatstr, int value, const WCHAR *checkstr) +{ + WCHAR buf[256] = { 0 }; + + TestVsnwprintf_s(buf, 256, formatstr, value); + if (memcmp(buf, checkstr, wcslen(buf)* 2 + 2) != 0) + { + Fail("ERROR: failed to insert %#x into \"%s\"\n" + "Expected \"%s\" got \"%s\".\n", value, convertC(formatstr), + convertC(checkstr), convertC(buf)); + } +} +#define DoNumTest DoNumTest_vsnwprintf_s + +inline void DoI64NumTest_vsnwprintf_s(const WCHAR *formatstr, INT64 value, char *valuestr, const WCHAR *checkstr) +{ + WCHAR buf[256] = { 0 }; + + TestVsnwprintf_s(buf, 256, formatstr, value); + if (memcmp(buf, checkstr, wcslen(buf)* 2 + 2) != 0) + { + Fail("ERROR: failed to insert %s into \"%s\"\n" + "Expected \"%s\" got \"%s\".\n", valuestr, convertC(formatstr), + convertC(checkstr), convertC(buf)); + } +} +#define DoI64NumTest DoI64NumTest_vsnwprintf_s + +inline void DoDoubleTest_vsnwprintf_s(const WCHAR *formatstr, double value, + const WCHAR *checkstr1, const WCHAR *checkstr2) +{ + WCHAR buf[256] = { 0 }; + + TestVsnwprintf_s(buf, 256, formatstr, value); + if (memcmp(buf, checkstr1, wcslen(checkstr1) + 2) != 0 && + memcmp(buf, checkstr2, wcslen(checkstr2) + 2) != 0) + { + Fail("ERROR: failed to insert %f into \"%s\"\n" + "Expected \"%s\" or \"%s\", got \"%s\".\n", + value, + convertC(formatstr), + convertC(checkstr1), + convertC(checkstr2), + convertC(buf)); + } +} +#define DoDoubleTest DoDoubleTest_vsnwprintf_s + +#endif diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test1/test1.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test1/test1.cpp new file mode 100644 index 00000000000000..970a099d80cbed --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test1/test1.cpp @@ -0,0 +1,59 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test1.c +** +** Purpose: Test #1 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + + +PALTEST(c_runtime__vsnwprintf_s_test1_paltest_vsnwprintf_test1, "c_runtime/_vsnwprintf_s/test1/paltest_vsnwprintf_test1") +{ + WCHAR *checkstr; + WCHAR buf[256] = { 0 }; + int ret; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + checkstr = convert("hello world"); + TestVsnwprintf_s(buf, 256, checkstr); + if (memcmp(checkstr, buf, wcslen(checkstr)*2+2) != 0) + { + Fail("ERROR: Expected \"%s\", got \"%s\"\n", + convertC(checkstr), convertC(buf)); + } + + TestVsnwprintf_s(buf, 256, convert("xxxxxxxxxxxxxxxxx")); + ret = TestVsnwprintf_s(buf, 8, checkstr); + if ((memcmp(checkstr, buf, 14)) != 0 || (buf[7] != 0)) + { + Fail("ERROR: Expected \"%8s\", got \"%8s\"\n", + convertC(checkstr), convertC(buf)); + } + if (ret >= 0) + { + Fail("ERROR: Expected negative return value, got %d.\n", ret); + } + if (buf[8] != (WCHAR) 'x') + { + Fail("ERROR: buffer overflow using \"%s\" with length 8.\n", + convertC(checkstr)); + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test10/test10.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test10/test10.cpp new file mode 100644 index 00000000000000..e4edbb8c527336 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test10/test10.cpp @@ -0,0 +1,49 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test10.c +** +** Purpose: Test #10 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime__vsnwprintf_s_test10_paltest_vsnwprintf_test10, "c_runtime/_vsnwprintf_s/test10/paltest_vsnwprintf_test10") +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoNumTest(convert("foo %o"), pos, convert("foo 52")); + DoNumTest(convert("foo %lo"), 0xFFFF, convert("foo 177777")); + DoNumTest(convert("foo %ho"), 0xFFFF, convert("foo 177777")); + DoNumTest(convert("foo %Lo"), pos, convert("foo 52")); + DoI64NumTest(convert("foo %I64o"), l, "42", convert("foo 52")); + DoNumTest(convert("foo %3o"), pos, convert("foo 52")); + DoNumTest(convert("foo %-3o"), pos, convert("foo 52 ")); + DoNumTest(convert("foo %.1o"), pos, convert("foo 52")); + DoNumTest(convert("foo %.3o"), pos, convert("foo 052")); + DoNumTest(convert("foo %03o"), pos, convert("foo 052")); + DoNumTest(convert("foo %#o"), pos, convert("foo 052")); + DoNumTest(convert("foo %+o"), pos, convert("foo 52")); + DoNumTest(convert("foo % o"), pos, convert("foo 52")); + DoNumTest(convert("foo %+o"), neg, convert("foo 37777777726")); + DoNumTest(convert("foo % o"), neg, convert("foo 37777777726")); + + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test11/test11.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test11/test11.cpp new file mode 100644 index 00000000000000..fd3f5bf9f99499 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test11/test11.cpp @@ -0,0 +1,49 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test11.c +** +** Purpose: Test #11 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime__vsnwprintf_s_test11_paltest_vsnwprintf_test11, "c_runtime/_vsnwprintf_s/test11/paltest_vsnwprintf_test11") +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoNumTest(convert("foo %u"), pos, convert("foo 42")); + DoNumTest(convert("foo %lu"), 0xFFFF, convert("foo 65535")); + DoNumTest(convert("foo %hu"), 0xFFFF, convert("foo 65535")); + DoNumTest(convert("foo %Lu"), pos, convert("foo 42")); + DoI64NumTest(convert("foo %I64u"), l, "42", convert("foo 42")); + DoNumTest(convert("foo %3u"), pos, convert("foo 42")); + DoNumTest(convert("foo %-3u"), pos, convert("foo 42 ")); + DoNumTest(convert("foo %.1u"), pos, convert("foo 42")); + DoNumTest(convert("foo %.3u"), pos, convert("foo 042")); + DoNumTest(convert("foo %03u"), pos, convert("foo 042")); + DoNumTest(convert("foo %#u"), pos, convert("foo 42")); + DoNumTest(convert("foo %+u"), pos, convert("foo 42")); + DoNumTest(convert("foo % u"), pos, convert("foo 42")); + DoNumTest(convert("foo %+u"), neg, convert("foo 4294967254")); + DoNumTest(convert("foo % u"), neg, convert("foo 4294967254")); + + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test12/test12.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test12/test12.cpp new file mode 100644 index 00000000000000..d2e6d547ea649e --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test12/test12.cpp @@ -0,0 +1,49 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test12.c +** +** Purpose: Test #12 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime__vsnwprintf_s_test12_paltest_vsnwprintf_test12, "c_runtime/_vsnwprintf_s/test12/paltest_vsnwprintf_test12") +{ + int neg = -42; + int pos = 0x1234ab; + INT64 l = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoNumTest(convert("foo %x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %lx"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %hx"), pos, convert("foo 34ab")); + DoNumTest(convert("foo %Lx"), pos, convert("foo 1234ab")); + DoI64NumTest(convert("foo %I64x"), l, "0x1234567887654321", + convert("foo 1234567887654321")); + DoNumTest(convert("foo %7x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %-7x"), pos, convert("foo 1234ab ")); + DoNumTest(convert("foo %.1x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %.7x"), pos, convert("foo 01234ab")); + DoNumTest(convert("foo %07x"), pos, convert("foo 01234ab")); + DoNumTest(convert("foo %#x"), pos, convert("foo 0x1234ab")); + DoNumTest(convert("foo %+x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo % x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %+x"), neg, convert("foo ffffffd6")); + DoNumTest(convert("foo % x"), neg, convert("foo ffffffd6")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test13/test13.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test13/test13.cpp new file mode 100644 index 00000000000000..64f89cd57149a2 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test13/test13.cpp @@ -0,0 +1,49 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test13.c +** +** Purpose: Test #13 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime__vsnwprintf_s_test13_paltest_vsnwprintf_test13, "c_runtime/_vsnwprintf_s/test13/paltest_vsnwprintf_test13") +{ + int neg = -42; + int pos = 0x1234ab; + INT64 l = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoNumTest(convert("foo %X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %lX"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %hX"), pos, convert("foo 34AB")); + DoNumTest(convert("foo %LX"), pos, convert("foo 1234AB")); + DoI64NumTest(convert("foo %I64X"), l, "0x1234567887654321", + convert("foo 1234567887654321")); + DoNumTest(convert("foo %7X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %-7X"), pos, convert("foo 1234AB ")); + DoNumTest(convert("foo %.1X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %.7X"), pos, convert("foo 01234AB")); + DoNumTest(convert("foo %07X"), pos, convert("foo 01234AB")); + DoNumTest(convert("foo %#X"), pos, convert("foo 0X1234AB")); + DoNumTest(convert("foo %+X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo % X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %+X"), neg, convert("foo FFFFFFD6")); + DoNumTest(convert("foo % X"), neg, convert("foo FFFFFFD6")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test14/test14.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test14/test14.cpp new file mode 100644 index 00000000000000..8fca1904231c6a --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test14/test14.cpp @@ -0,0 +1,62 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test14.c +** +** Purpose: Test #14 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime__vsnwprintf_s_test14_paltest_vsnwprintf_test14, "c_runtime/_vsnwprintf_s/test14/paltest_vsnwprintf_test14") +{ + double val = 256.0; + double neg = -256.0; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoDoubleTest(convert("foo %e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %le"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %he"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %Le"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %I64e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %14e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %-14e"), val, convert("foo 2.560000e+002 "), + convert("foo 2.560000e+02 ")); + DoDoubleTest(convert("foo %.1e"), val, convert("foo 2.6e+002"), + convert("foo 2.6e+02")); + DoDoubleTest(convert("foo %.8e"), val, convert("foo 2.56000000e+002"), + convert("foo 2.56000000e+02")); + DoDoubleTest(convert("foo %014e"), val, convert("foo 02.560000e+002"), + convert("foo 002.560000e+02")); + DoDoubleTest(convert("foo %#e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %+e"), val, convert("foo +2.560000e+002"), + convert("foo +2.560000e+02")); + DoDoubleTest(convert("foo % e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %+e"), neg, convert("foo -2.560000e+002"), + convert("foo -2.560000e+02")); + DoDoubleTest(convert("foo % e"), neg, convert("foo -2.560000e+002"), + convert("foo -2.560000e+02")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test15/test15.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test15/test15.cpp new file mode 100644 index 00000000000000..9fe695ae86caed --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test15/test15.cpp @@ -0,0 +1,63 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test15.c +** +** Purpose: Test #15 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + + +PALTEST(c_runtime__vsnwprintf_s_test15_paltest_vsnwprintf_test15, "c_runtime/_vsnwprintf_s/test15/paltest_vsnwprintf_test15") +{ + double val = 256.0; + double neg = -256.0; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoDoubleTest(convert("foo %E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %lE"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %hE"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %LE"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %I64E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %14E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %-14E"), val, convert("foo 2.560000E+002 "), + convert("foo 2.560000E+02 ")); + DoDoubleTest(convert("foo %.1E"), val, convert("foo 2.6E+002"), + convert("foo 2.6E+02")); + DoDoubleTest(convert("foo %.8E"), val, convert("foo 2.56000000E+002"), + convert("foo 2.56000000E+02")); + DoDoubleTest(convert("foo %014E"), val, convert("foo 02.560000E+002"), + convert("foo 002.560000E+02")); + DoDoubleTest(convert("foo %#E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %+E"), val, convert("foo +2.560000E+002"), + convert("foo +2.560000E+02")); + DoDoubleTest(convert("foo % E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %+E"), neg, convert("foo -2.560000E+002"), + convert("foo -2.560000E+02")); + DoDoubleTest(convert("foo % E"), neg, convert("foo -2.560000E+002"), + convert("foo -2.560000E+002")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test16/test16.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test16/test16.cpp new file mode 100644 index 00000000000000..ac20afefb22dd3 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test16/test16.cpp @@ -0,0 +1,62 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test16.c +** +** Purpose: Test #16 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime__vsnwprintf_s_test16_paltest_vsnwprintf_test16, "c_runtime/_vsnwprintf_s/test16/paltest_vsnwprintf_test16") +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoDoubleTest(convert("foo %f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %lf"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %hf"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %Lf"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %I64f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %12f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %-12f"), val, convert("foo 2560.001000 "), + convert("foo 2560.001000 ")); + DoDoubleTest(convert("foo %.1f"), val, convert("foo 2560.0"), + convert("foo 2560.0")); + DoDoubleTest(convert("foo %.8f"), val, convert("foo 2560.00100000"), + convert("foo 2560.00100000")); + DoDoubleTest(convert("foo %012f"), val, convert("foo 02560.001000"), + convert("foo 02560.001000")); + DoDoubleTest(convert("foo %#f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %+f"), val, convert("foo +2560.001000"), + convert("foo +2560.001000")); + DoDoubleTest(convert("foo % f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %+f"), neg, convert("foo -2560.001000"), + convert("foo -2560.001000")); + DoDoubleTest(convert("foo % f"), neg, convert("foo -2560.001000"), + convert("foo -2560.001000")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test17/test17.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test17/test17.cpp new file mode 100644 index 00000000000000..d4317b17c17461 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test17/test17.cpp @@ -0,0 +1,64 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test17.c +** +** Purpose: Test #17 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime__vsnwprintf_s_test17_paltest_vsnwprintf_test17, "c_runtime/_vsnwprintf_s/test17/paltest_vsnwprintf_test17") +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoDoubleTest(convert("foo %g"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %lg"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %hg"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %Lg"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %I64g"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %5g"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %-5g"), val, convert("foo 2560 "), + convert("foo 2560 ")); + DoDoubleTest(convert("foo %.1g"), val, convert("foo 3e+003"), + convert("foo 3e+03")); + DoDoubleTest(convert("foo %.2g"), val, convert("foo 2.6e+003"), + convert("foo 2.6e+03")); + DoDoubleTest(convert("foo %.12g"), val, convert("foo 2560.001"), + convert("foo 2560.001")); + DoDoubleTest(convert("foo %06g"), val, convert("foo 002560"), + convert("foo 002560")); + DoDoubleTest(convert("foo %#g"), val, convert("foo 2560.00"), + convert("foo 2560.00")); + DoDoubleTest(convert("foo %+g"), val, convert("foo +2560"), + convert("foo +2560")); + DoDoubleTest(convert("foo % g"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %+g"), neg, convert("foo -2560"), + convert("foo -2560")); + DoDoubleTest(convert("foo % g"), neg, convert("foo -2560"), + convert("foo -2560")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test18/test18.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test18/test18.cpp new file mode 100644 index 00000000000000..7ae932f57d7998 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test18/test18.cpp @@ -0,0 +1,64 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test18.c +** +** Purpose: Test #18 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime__vsnwprintf_s_test18_paltest_vsnwprintf_test18, "c_runtime/_vsnwprintf_s/test18/paltest_vsnwprintf_test18") +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoDoubleTest(convert("foo %G"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %lG"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %hG"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %LG"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %I64G"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %5G"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %-5G"), val, convert("foo 2560 "), + convert("foo 2560 ")); + DoDoubleTest(convert("foo %.1G"), val, convert("foo 3E+003"), + convert("foo 3E+03")); + DoDoubleTest(convert("foo %.2G"), val, convert("foo 2.6E+003"), + convert("foo 2.6E+03")); + DoDoubleTest(convert("foo %.12G"), val, convert("foo 2560.001"), + convert("foo 2560.001")); + DoDoubleTest(convert("foo %06G"), val, convert("foo 002560"), + convert("foo 002560")); + DoDoubleTest(convert("foo %#G"), val, convert("foo 2560.00"), + convert("foo 2560.00")); + DoDoubleTest(convert("foo %+G"), val, convert("foo +2560"), + convert("foo +2560")); + DoDoubleTest(convert("foo % G"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %+G"), neg, convert("foo -2560"), + convert("foo -2560")); + DoDoubleTest(convert("foo % G"), neg, convert("foo -2560"), + convert("foo -2560")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test19/test19.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test19/test19.cpp new file mode 100644 index 00000000000000..158ff1a644e0b0 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test19/test19.cpp @@ -0,0 +1,138 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test18.c +** +** Purpose: Test #18 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +#define DOTEST(a,b,c,d,e) DoTest(a,b,(void*)c,d,e) + +void DoArgumentPrecTest_vsnwprintf_s(WCHAR *formatstr, int precision, void *param, + WCHAR *paramstr, WCHAR *checkstr1, WCHAR *checkstr2) +{ + WCHAR buf[256]; + + TestVsnwprintf_s(buf, 256, formatstr, precision, param); + if (memcmp(buf, checkstr1, wcslen(checkstr1) + 2) != 0 && + memcmp(buf, checkstr2, wcslen(checkstr2) + 2) != 0) + { + Fail("ERROR: failed to insert %s into \"%s\" with precision %d\n" + "Expected \"%s\" or \"%s\", got \"%s\".\n", + paramstr, + convertC(formatstr), + precision, + convertC(checkstr1), + convertC(checkstr2), + convertC(buf)); + } +} +void DoArgumentPrecDoubleTest_vsnwprintf_s(WCHAR *formatstr, int precision, double param, + WCHAR *checkstr1, WCHAR *checkstr2) +{ + WCHAR buf[256]; + + TestVsnwprintf_s(buf, 256, formatstr, precision, param); + if (memcmp(buf, checkstr1, wcslen(checkstr1) + 2) != 0 && + memcmp(buf, checkstr2, wcslen(checkstr2) + 2) != 0) + { + Fail("ERROR: failed to insert %f into \"%s\" with precision %d\n" + "Expected \"%s\" or \"%s\", got \"%s\".\n", + param, convertC(formatstr), + precision, + convertC(checkstr1), + convertC(checkstr2), + convertC(buf)); + } +} + +/* + * Uses memcmp & wcslen + */ + +PALTEST(c_runtime__vsnwprintf_s_test19_paltest_vsnwprintf_test19, "c_runtime/_vsnwprintf_s/test19/paltest_vsnwprintf_test19") +{ + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoArgumentPrecTest_vsnwprintf_s(convert("%.*s"), 2, (void*)convert("bar"), convert("bar"), + convert("ba"), convert("ba")); + DoArgumentPrecTest_vsnwprintf_s(convert("%.*c"), 0, (void*)'a', convert("a"), + convert("a"), convert("a")); + DoArgumentPrecTest_vsnwprintf_s(convert("%.*c"), 4, (void*)'a', convert("a"), + convert("a"), convert("a")); + DoArgumentPrecTest_vsnwprintf_s(convert("%.*C"), 0, (void*)'a', convert("a"), + convert("a"), convert("a")); + DoArgumentPrecTest_vsnwprintf_s(convert("%.*C"), 4, (void*)'a', convert("a"), + convert("a"), convert("a")); + DoArgumentPrecTest_vsnwprintf_s(convert("%.*d"), 1, (void*)42, convert("42"), + convert("42"), convert("42")); + DoArgumentPrecTest_vsnwprintf_s(convert("%.*d"), 3, (void*)42, convert("42"), + convert("042"), convert("042")); + DoArgumentPrecTest_vsnwprintf_s(convert("%.*i"), 1, (void*)42, convert("42"), + convert("42"), convert("42")); + DoArgumentPrecTest_vsnwprintf_s(convert("%.*i"), 3, (void*)42, convert("42"), + convert("042"), convert("042")); + DoArgumentPrecTest_vsnwprintf_s(convert("%.*o"), 1, (void*)42, convert("42"), + convert("52"), convert("52")); + DoArgumentPrecTest_vsnwprintf_s(convert("%.*o"), 3, (void*)42, convert("42"), + convert("052"), convert("052")); + DoArgumentPrecTest_vsnwprintf_s(convert("%.*u"), 1, (void*)42, convert("42"), + convert("42"), convert("42")); + DoArgumentPrecTest_vsnwprintf_s(convert("%.*u"), 3, (void*)42, convert("42"), + convert("042"), convert("042")); + DoArgumentPrecTest_vsnwprintf_s(convert("%.*x"), 1, (void*)0x42, convert("0x42"), + convert("42"), convert("42")); + DoArgumentPrecTest_vsnwprintf_s(convert("%.*x"), 3, (void*)0x42, convert("0x42"), + convert("042"), convert("042")); + DoArgumentPrecTest_vsnwprintf_s(convert("%.*X"), 1, (void*)0x42, convert("0x42"), + convert("42"), convert("42")); + DoArgumentPrecTest_vsnwprintf_s(convert("%.*X"), 3, (void*)0x42, convert("0x42"), + convert("042"), convert("042")); + + + DoArgumentPrecDoubleTest_vsnwprintf_s(convert("%.*e"), 1, 2.01, convert("2.0e+000"), + convert("2.0e+00")); + DoArgumentPrecDoubleTest_vsnwprintf_s(convert("%.*e"), 3, 2.01, convert("2.010e+000"), + convert("2.010e+00")); + DoArgumentPrecDoubleTest_vsnwprintf_s(convert("%.*E"), 1, 2.01, convert("2.0E+000"), + convert("2.0E+00")); + DoArgumentPrecDoubleTest_vsnwprintf_s(convert("%.*E"), 3, 2.01, convert("2.010E+000"), + convert("2.010E+00")); + DoArgumentPrecDoubleTest_vsnwprintf_s(convert("%.*f"), 1, 2.01, convert("2.0"), + convert("2.0")); + DoArgumentPrecDoubleTest_vsnwprintf_s(convert("%.*f"), 3, 2.01, convert("2.010"), + convert("2.010")); + DoArgumentPrecDoubleTest_vsnwprintf_s(convert("%.*g"), 1, 256.01, convert("3e+002"), + convert("3e+02")); + DoArgumentPrecDoubleTest_vsnwprintf_s(convert("%.*g"), 3, 256.01, convert("256"), + convert("256")); + DoArgumentPrecDoubleTest_vsnwprintf_s(convert("%.*g"), 4, 256.01, convert("256"), + convert("256")); + DoArgumentPrecDoubleTest_vsnwprintf_s(convert("%.*g"), 6, 256.01, convert("256.01"), + convert("256.01")); + DoArgumentPrecDoubleTest_vsnwprintf_s(convert("%.*G"), 1, 256.01, convert("3E+002"), + convert("3E+02")); + DoArgumentPrecDoubleTest_vsnwprintf_s(convert("%.*G"), 3, 256.01, convert("256"), + convert("256")); + DoArgumentPrecDoubleTest_vsnwprintf_s(convert("%.*G"), 4, 256.01, convert("256"), + convert("256")); + DoArgumentPrecDoubleTest_vsnwprintf_s(convert("%.*G"), 6, 256.01, convert("256.01"), + convert("256.01")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test2/test2.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test2/test2.cpp new file mode 100644 index 00000000000000..ce5a74cc080c19 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test2/test2.cpp @@ -0,0 +1,45 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test2.c +** +** Purpose: Test #2 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + + +PALTEST(c_runtime__vsnwprintf_s_test2_paltest_vsnwprintf_test2, "c_runtime/_vsnwprintf_s/test2/paltest_vsnwprintf_test2") +{ + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoWStrTest(convert("foo %s"), convert("bar"), convert("foo bar")); + DoStrTest(convert("foo %hs"), "bar", convert("foo bar")); + DoWStrTest(convert("foo %ls"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %ws"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %Ls"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %I64s"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %5s"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %.2s"), convert("bar"), convert("foo ba")); + DoWStrTest(convert("foo %5.2s"), convert("bar"), convert("foo ba")); + DoWStrTest(convert("foo %-5s"), convert("bar"), convert("foo bar ")); + DoWStrTest(convert("foo %05s"), convert("bar"), convert("foo 00bar")); + DoWStrTest(convert("foo %s"), NULL, convert("foo (null)")); + DoStrTest(convert("foo %hs"), NULL, convert("foo (null)")); + DoWStrTest(convert("foo %ls"), NULL, convert("foo (null)")); + DoWStrTest(convert("foo %ws"), NULL, convert("foo (null)")); + DoWStrTest(convert("foo %Ls"), NULL, convert("foo (null)")); + DoWStrTest(convert("foo %I64s"), NULL, convert("foo (null)")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test3/test3.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test3/test3.cpp new file mode 100644 index 00000000000000..30aa2d87c5e33b --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test3/test3.cpp @@ -0,0 +1,45 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test3.c +** +** Purpose: Test #3 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + + +PALTEST(c_runtime__vsnwprintf_s_test3_paltest_vsnwprintf_test3, "c_runtime/_vsnwprintf_s/test3/paltest_vsnwprintf_test3") +{ + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoStrTest(convert("foo %S"), "bar", convert("foo bar")); + DoStrTest(convert("foo %hS"), "bar", convert("foo bar")); + DoWStrTest(convert("foo %lS"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %wS"), convert("bar"), convert("foo bar")); + DoStrTest(convert("foo %LS"), "bar", convert("foo bar")); + DoStrTest(convert("foo %I64S"), "bar", convert("foo bar")); + DoStrTest(convert("foo %5S"), "bar", convert("foo bar")); + DoStrTest(convert("foo %.2S"), "bar", convert("foo ba")); + DoStrTest(convert("foo %5.2S"), "bar", convert("foo ba")); + DoStrTest(convert("foo %-5S"), "bar", convert("foo bar ")); + DoStrTest(convert("foo %05S"), "bar", convert("foo 00bar")); + DoStrTest(convert("foo %S"), NULL, convert("foo (null)")); + DoStrTest(convert("foo %hS"), NULL, convert("foo (null)")); + DoWStrTest(convert("foo %lS"), NULL, convert("foo (null)")); + DoWStrTest(convert("foo %wS"), NULL, convert("foo (null)")); + DoStrTest(convert("foo %LS"), NULL, convert("foo (null)")); + DoStrTest(convert("foo %I64S"), NULL, convert("foo (null)")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test4/test4.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test4/test4.cpp new file mode 100644 index 00000000000000..1caa4829db0a05 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test4/test4.cpp @@ -0,0 +1,120 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test4.c +** +** Purpose: Test #4 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ +static void DoPointerTest(WCHAR *formatstr, void* param, WCHAR* paramstr, + WCHAR *checkstr1) +{ + WCHAR buf[256] = { 0 }; + + TestVsnwprintf_s(buf, 256, formatstr, param); + if (memcmp(buf, checkstr1, wcslen(checkstr1) + 2) != 0) + + { + Fail("ERROR: failed to insert pointer to %#p into \"%s\"\n" + "Expected \"%s\" got \"%s\".\n", + paramstr, + convertC(formatstr), + convertC(checkstr1), + convertC(buf)); + } +} + +static void DoI64DoubleTest(WCHAR *formatstr, INT64 value, WCHAR *valuestr, + WCHAR *checkstr1) +{ + WCHAR buf[256] = { 0 }; + + TestVsnwprintf_s(buf, 256, formatstr, value); + if (memcmp(buf, checkstr1, wcslen(checkstr1) + 2) != 0) + { + Fail("ERROR: failed to insert %s into \"%s\"\n" + "Expected \"%s\", got \"%s\".\n", + value, + convertC(formatstr), + convertC(checkstr1), + convertC(buf)); + } +} + +PALTEST(c_runtime__vsnwprintf_s_test4_paltest_vsnwprintf_test4, "c_runtime/_vsnwprintf_s/test4/paltest_vsnwprintf_test4") +{ + void *ptr = (void*) 0x123456; + INT64 lptr = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + +/* +** Run only on 64 bit platforms +*/ +#if defined(HOST_64BIT) + Trace("Testing for 64 Bit Platforms \n"); + DoPointerTest(convert("%p"), NULL, convert("NULL"), convert("00000000")); + DoPointerTest(convert("%p"), ptr, convert("pointer to 0x123456"), + convert("0000000000123456")); + DoPointerTest(convert("%17p"), ptr, convert("pointer to 0x123456"), + convert(" 0000000000123456")); + DoPointerTest(convert("%17p"), ptr, convert("pointer to 0x123456"), + convert(" 0000000000123456")); + DoPointerTest(convert("%-17p"), ptr, convert("pointer to 0x123456"), + convert("0000000000123456 ")); + DoPointerTest(convert("%+p"), ptr, convert("pointer to 0x123456"), + convert("0000000000123456")); + DoPointerTest(convert("%#p"), ptr, convert("pointer to 0x123456"), + convert("0X0000000000123456")); + DoPointerTest(convert("%lp"), ptr, convert("pointer to 0x123456"), + convert("00123456")); + DoPointerTest(convert("%hp"), ptr, convert("pointer to 0x123456"), + convert("00003456")); + DoPointerTest(convert("%Lp"), ptr, convert("pointer to 0x123456"), + convert("00123456")); + DoI64DoubleTest(convert("%I64p"), lptr, + convert("pointer to 0x1234567887654321"), + convert("1234567887654321")); + +#else + Trace("Testing for Non 64 Bit Platforms \n"); + DoPointerTest(convert("%p"), NULL, convert("NULL"), convert("00000000")); + DoPointerTest(convert("%p"), ptr, convert("pointer to 0x123456"), + convert("00123456")); + DoPointerTest(convert("%9p"), ptr, convert("pointer to 0x123456"), + convert(" 00123456")); + DoPointerTest(convert("%09p"), ptr, convert("pointer to 0x123456"), + convert(" 00123456")); + DoPointerTest(convert("%-9p"), ptr, convert("pointer to 0x123456"), + convert("00123456 ")); + DoPointerTest(convert("%+p"), ptr, convert("pointer to 0x123456"), + convert("00123456")); + DoPointerTest(convert("%#p"), ptr, convert("pointer to 0x123456"), + convert("0X00123456")); + DoPointerTest(convert("%lp"), ptr, convert("pointer to 0x123456"), + convert("00123456")); + DoPointerTest(convert("%hp"), ptr, convert("pointer to 0x123456"), + convert("00003456")); + DoPointerTest(convert("%Lp"), ptr, convert("pointer to 0x123456"), + convert("00123456")); + DoI64DoubleTest(convert("%I64p"), lptr, + convert("pointer to 0x1234567887654321"), + convert("1234567887654321")); +#endif + + PAL_Terminate(); + return PASS; +} + diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test6/test6.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test6/test6.cpp new file mode 100644 index 00000000000000..cc0faddf71809c --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test6/test6.cpp @@ -0,0 +1,42 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test6.c +** +** Purpose: Test #6 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime__vsnwprintf_s_test6_paltest_vsnwprintf_test6, "c_runtime/_vsnwprintf_s/test6/paltest_vsnwprintf_test6") +{ + WCHAR wc = (WCHAR) 'c'; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoWCharTest(convert("foo %c"), wc, convert("foo c")); + DoCharTest(convert("foo %hc"), 'b', convert("foo b")); + DoWCharTest(convert("foo %lc"), wc, convert("foo c")); + DoWCharTest(convert("foo %Lc"), wc, convert("foo c")); + DoWCharTest(convert("foo %I64c"), wc, convert("foo c")); + DoWCharTest(convert("foo %5c"), wc, convert("foo c")); + DoWCharTest(convert("foo %.0c"), wc, convert("foo c")); + DoWCharTest(convert("foo %-5c"), wc, convert("foo c ")); + DoWCharTest(convert("foo %05c"), wc, convert("foo 0000c")); + DoWCharTest(convert("foo % c"), wc, convert("foo c")); + DoWCharTest(convert("foo %#c"), wc, convert("foo c")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test7/test7.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test7/test7.cpp new file mode 100644 index 00000000000000..d31e77bb322bce --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test7/test7.cpp @@ -0,0 +1,42 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test7.c +** +** Purpose: Test #7 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime__vsnwprintf_s_test7_paltest_vsnwprintf_test7, "c_runtime/_vsnwprintf_s/test7/paltest_vsnwprintf_test7") +{ + WCHAR wc = (WCHAR) 'c'; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoCharTest(convert("foo %C"), 'b', convert("foo b")); + DoWCharTest(convert("foo %hC"), wc, convert("foo c")); + DoCharTest(convert("foo %lC"), 'b', convert("foo b")); + DoCharTest(convert("foo %LC"), 'b', convert("foo b")); + DoCharTest(convert("foo %I64C"), 'b', convert("foo b")); + DoCharTest(convert("foo %5C"), 'b', convert("foo b")); + DoCharTest(convert("foo %.0C"), 'b', convert("foo b")); + DoCharTest(convert("foo %-5C"), 'b', convert("foo b ")); + DoCharTest(convert("foo %05C"), 'b', convert("foo 0000b")); + DoCharTest(convert("foo % C"), 'b', convert("foo b")); + DoCharTest(convert("foo %#C"), 'b', convert("foo b")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test8/test8.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test8/test8.cpp new file mode 100644 index 00000000000000..e26b49ab8d63b3 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test8/test8.cpp @@ -0,0 +1,48 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test8.c +** +** Purpose: Test #8 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime__vsnwprintf_s_test8_paltest_vsnwprintf_test8, "c_runtime/_vsnwprintf_s/test8/paltest_vsnwprintf_test8") +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoNumTest(convert("foo %d"), pos, convert("foo 42")); + DoNumTest(convert("foo %ld"), 0xFFFF, convert("foo 65535")); + DoNumTest(convert("foo %hd"), 0xFFFF, convert("foo -1")); + DoNumTest(convert("foo %Ld"), pos, convert("foo 42")); + DoI64NumTest(convert("foo %I64d"), l, "42", convert("foo 42")); + DoNumTest(convert("foo %3d"), pos, convert("foo 42")); + DoNumTest(convert("foo %-3d"), pos, convert("foo 42 ")); + DoNumTest(convert("foo %.1d"), pos, convert("foo 42")); + DoNumTest(convert("foo %.3d"), pos, convert("foo 042")); + DoNumTest(convert("foo %03d"), pos, convert("foo 042")); + DoNumTest(convert("foo %#d"), pos, convert("foo 42")); + DoNumTest(convert("foo %+d"), pos, convert("foo +42")); + DoNumTest(convert("foo % d"), pos, convert("foo 42")); + DoNumTest(convert("foo %+d"), neg, convert("foo -42")); + DoNumTest(convert("foo % d"), neg, convert("foo -42")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test9/test9.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test9/test9.cpp new file mode 100644 index 00000000000000..12e8c46aa5541e --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/_vsnwprintf_s/test9/test9.cpp @@ -0,0 +1,48 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test9.c +** +** Purpose: Test #9 for the _vsnwprintf_s function. +** +** +**===================================================================*/ + +#include +#include "../_vsnwprintf_s.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime__vsnwprintf_s_test9_paltest_vsnwprintf_test9, "c_runtime/_vsnwprintf_s/test9/paltest_vsnwprintf_test9") +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + { + return(FAIL); + } + + DoNumTest(convert("foo %i"), pos, convert("foo 42")); + DoNumTest(convert("foo %li"), 0xFFFF, convert("foo 65535")); + DoNumTest(convert("foo %hi"), 0xFFFF, convert("foo -1")); + DoNumTest(convert("foo %Li"), pos, convert("foo 42")); + DoI64NumTest(convert("foo %I64i"), l, "42", convert("foo 42")); + DoNumTest(convert("foo %3i"), pos, convert("foo 42")); + DoNumTest(convert("foo %-3i"), pos, convert("foo 42 ")); + DoNumTest(convert("foo %.1i"), pos, convert("foo 42")); + DoNumTest(convert("foo %.3i"), pos, convert("foo 042")); + DoNumTest(convert("foo %03i"), pos, convert("foo 042")); + DoNumTest(convert("foo %#i"), pos, convert("foo 42")); + DoNumTest(convert("foo %+i"), pos, convert("foo +42")); + DoNumTest(convert("foo % i"), pos, convert("foo 42")); + DoNumTest(convert("foo %+i"), neg, convert("foo -42")); + DoNumTest(convert("foo % i"), neg, convert("foo -42")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test1/test1.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test1/test1.cpp new file mode 100644 index 00000000000000..41e59d6b3a56a5 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test1/test1.cpp @@ -0,0 +1,39 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test1.c +** +** Purpose: Test #1 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime_vswprintf_test1_paltest_vswprintf_test1, "c_runtime/vswprintf/test1/paltest_vswprintf_test1") +{ + WCHAR *checkstr = NULL; + WCHAR buf[256] = { 0 }; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + checkstr = convert("hello world"); + testvswp(buf, ARRAY_SIZE(buf), checkstr); + + if (memcmp(checkstr, buf, wcslen(checkstr)*2+2) != 0) + { + Fail("ERROR: Expected \"%s\", got \"%s\"\n", + convertC(checkstr), convertC(buf)); + } + + free(checkstr); + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test10/test10.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test10/test10.cpp new file mode 100644 index 00000000000000..2ace47428947f7 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test10/test10.cpp @@ -0,0 +1,47 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test10.c +** +** Purpose: Test #10 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime_vswprintf_test10_paltest_vswprintf_test10, "c_runtime/vswprintf/test10/paltest_vswprintf_test10") +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoNumTest(convert("foo %o"), pos, convert("foo 52")); + DoNumTest(convert("foo %lo"), 0xFFFF, convert("foo 177777")); + DoNumTest(convert("foo %ho"), 0xFFFF, convert("foo 177777")); + DoNumTest(convert("foo %Lo"), pos, convert("foo 52")); + DoI64NumTest(convert("foo %I64o"), l, "42", convert("foo 52")); + DoNumTest(convert("foo %3o"), pos, convert("foo 52")); + DoNumTest(convert("foo %-3o"), pos, convert("foo 52 ")); + DoNumTest(convert("foo %.1o"), pos, convert("foo 52")); + DoNumTest(convert("foo %.3o"), pos, convert("foo 052")); + DoNumTest(convert("foo %03o"), pos, convert("foo 052")); + DoNumTest(convert("foo %#o"), pos, convert("foo 052")); + DoNumTest(convert("foo %+o"), pos, convert("foo 52")); + DoNumTest(convert("foo % o"), pos, convert("foo 52")); + DoNumTest(convert("foo %+o"), neg, convert("foo 37777777726")); + DoNumTest(convert("foo % o"), neg, convert("foo 37777777726")); + + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test11/test11.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test11/test11.cpp new file mode 100644 index 00000000000000..2e24f5bfd712e0 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test11/test11.cpp @@ -0,0 +1,47 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test11.c +** +** Purpose: Test #11 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime_vswprintf_test11_paltest_vswprintf_test11, "c_runtime/vswprintf/test11/paltest_vswprintf_test11") +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoNumTest(convert("foo %u"), pos, convert("foo 42")); + DoNumTest(convert("foo %lu"), 0xFFFF, convert("foo 65535")); + DoNumTest(convert("foo %hu"), 0xFFFF, convert("foo 65535")); + DoNumTest(convert("foo %Lu"), pos, convert("foo 42")); + DoI64NumTest(convert("foo %I64u"), l, "42", convert("foo 42")); + DoNumTest(convert("foo %3u"), pos, convert("foo 42")); + DoNumTest(convert("foo %-3u"), pos, convert("foo 42 ")); + DoNumTest(convert("foo %.1u"), pos, convert("foo 42")); + DoNumTest(convert("foo %.3u"), pos, convert("foo 042")); + DoNumTest(convert("foo %03u"), pos, convert("foo 042")); + DoNumTest(convert("foo %#u"), pos, convert("foo 42")); + DoNumTest(convert("foo %+u"), pos, convert("foo 42")); + DoNumTest(convert("foo % u"), pos, convert("foo 42")); + DoNumTest(convert("foo %+u"), neg, convert("foo 4294967254")); + DoNumTest(convert("foo % u"), neg, convert("foo 4294967254")); + + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test12/test12.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test12/test12.cpp new file mode 100644 index 00000000000000..e80c7061756844 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test12/test12.cpp @@ -0,0 +1,47 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test12.c +** +** Purpose: Test #12 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime_vswprintf_test12_paltest_vswprintf_test12, "c_runtime/vswprintf/test12/paltest_vswprintf_test12") +{ + int neg = -42; + int pos = 0x1234ab; + INT64 l = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoNumTest(convert("foo %x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %lx"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %hx"), pos, convert("foo 34ab")); + DoNumTest(convert("foo %Lx"), pos, convert("foo 1234ab")); + DoI64NumTest(convert("foo %I64x"), l, "0x1234567887654321", + convert("foo 1234567887654321")); + DoNumTest(convert("foo %7x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %-7x"), pos, convert("foo 1234ab ")); + DoNumTest(convert("foo %.1x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %.7x"), pos, convert("foo 01234ab")); + DoNumTest(convert("foo %07x"), pos, convert("foo 01234ab")); + DoNumTest(convert("foo %#x"), pos, convert("foo 0x1234ab")); + DoNumTest(convert("foo %+x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo % x"), pos, convert("foo 1234ab")); + DoNumTest(convert("foo %+x"), neg, convert("foo ffffffd6")); + DoNumTest(convert("foo % x"), neg, convert("foo ffffffd6")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test13/test13.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test13/test13.cpp new file mode 100644 index 00000000000000..081c63ea0cb553 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test13/test13.cpp @@ -0,0 +1,47 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test13.c +** +** Purpose: Test #13 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime_vswprintf_test13_paltest_vswprintf_test13, "c_runtime/vswprintf/test13/paltest_vswprintf_test13") +{ + int neg = -42; + int pos = 0x1234ab; + INT64 l = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoNumTest(convert("foo %X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %lX"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %hX"), pos, convert("foo 34AB")); + DoNumTest(convert("foo %LX"), pos, convert("foo 1234AB")); + DoI64NumTest(convert("foo %I64X"), l, "0x1234567887654321", + convert("foo 1234567887654321")); + DoNumTest(convert("foo %7X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %-7X"), pos, convert("foo 1234AB ")); + DoNumTest(convert("foo %.1X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %.7X"), pos, convert("foo 01234AB")); + DoNumTest(convert("foo %07X"), pos, convert("foo 01234AB")); + DoNumTest(convert("foo %#X"), pos, convert("foo 0X1234AB")); + DoNumTest(convert("foo %+X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo % X"), pos, convert("foo 1234AB")); + DoNumTest(convert("foo %+X"), neg, convert("foo FFFFFFD6")); + DoNumTest(convert("foo % X"), neg, convert("foo FFFFFFD6")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test14/test14.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test14/test14.cpp new file mode 100644 index 00000000000000..5e00bf55963e19 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test14/test14.cpp @@ -0,0 +1,60 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test14.c +** +** Purpose: Test #14 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime_vswprintf_test14_paltest_vswprintf_test14, "c_runtime/vswprintf/test14/paltest_vswprintf_test14") +{ + double val = 256.0; + double neg = -256.0; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoDoubleTest(convert("foo %e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %le"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %he"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %Le"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %I64e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %14e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %-14e"), val, convert("foo 2.560000e+002 "), + convert("foo 2.560000e+02 ")); + DoDoubleTest(convert("foo %.1e"), val, convert("foo 2.6e+002"), + convert("foo 2.6e+02")); + DoDoubleTest(convert("foo %.8e"), val, convert("foo 2.56000000e+002"), + convert("foo 2.56000000e+02")); + DoDoubleTest(convert("foo %014e"), val, convert("foo 02.560000e+002"), + convert("foo 002.560000e+02")); + DoDoubleTest(convert("foo %#e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %+e"), val, convert("foo +2.560000e+002"), + convert("foo +2.560000e+02")); + DoDoubleTest(convert("foo % e"), val, convert("foo 2.560000e+002"), + convert("foo 2.560000e+02")); + DoDoubleTest(convert("foo %+e"), neg, convert("foo -2.560000e+002"), + convert("foo -2.560000e+02")); + DoDoubleTest(convert("foo % e"), neg, convert("foo -2.560000e+002"), + convert("foo -2.560000e+02")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test15/test15.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test15/test15.cpp new file mode 100644 index 00000000000000..2dddd1a937d8a7 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test15/test15.cpp @@ -0,0 +1,61 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test15.c +** +** Purpose: Test #15 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + + +PALTEST(c_runtime_vswprintf_test15_paltest_vswprintf_test15, "c_runtime/vswprintf/test15/paltest_vswprintf_test15") +{ + double val = 256.0; + double neg = -256.0; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoDoubleTest(convert("foo %E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %lE"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %hE"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %LE"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %I64E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %14E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %-14E"), val, convert("foo 2.560000E+002 "), + convert("foo 2.560000E+02 ")); + DoDoubleTest(convert("foo %.1E"), val, convert("foo 2.6E+002"), + convert("foo 2.6E+02")); + DoDoubleTest(convert("foo %.8E"), val, convert("foo 2.56000000E+002"), + convert("foo 2.56000000E+02")); + DoDoubleTest(convert("foo %014E"), val, convert("foo 02.560000E+002"), + convert("foo 002.560000E+02")); + DoDoubleTest(convert("foo %#E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %+E"), val, convert("foo +2.560000E+002"), + convert("foo +2.560000E+02")); + DoDoubleTest(convert("foo % E"), val, convert("foo 2.560000E+002"), + convert("foo 2.560000E+02")); + DoDoubleTest(convert("foo %+E"), neg, convert("foo -2.560000E+002"), + convert("foo -2.560000E+02")); + DoDoubleTest(convert("foo % E"), neg, convert("foo -2.560000E+002"), + convert("foo -2.560000E+002")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test16/test16.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test16/test16.cpp new file mode 100644 index 00000000000000..a8f7f8f1b1609c --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test16/test16.cpp @@ -0,0 +1,60 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test16.c +** +** Purpose: Test #16 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime_vswprintf_test16_paltest_vswprintf_test16, "c_runtime/vswprintf/test16/paltest_vswprintf_test16") +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoDoubleTest(convert("foo %f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %lf"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %hf"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %Lf"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %I64f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %12f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %-12f"), val, convert("foo 2560.001000 "), + convert("foo 2560.001000 ")); + DoDoubleTest(convert("foo %.1f"), val, convert("foo 2560.0"), + convert("foo 2560.0")); + DoDoubleTest(convert("foo %.8f"), val, convert("foo 2560.00100000"), + convert("foo 2560.00100000")); + DoDoubleTest(convert("foo %012f"), val, convert("foo 02560.001000"), + convert("foo 02560.001000")); + DoDoubleTest(convert("foo %#f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %+f"), val, convert("foo +2560.001000"), + convert("foo +2560.001000")); + DoDoubleTest(convert("foo % f"), val, convert("foo 2560.001000"), + convert("foo 2560.001000")); + DoDoubleTest(convert("foo %+f"), neg, convert("foo -2560.001000"), + convert("foo -2560.001000")); + DoDoubleTest(convert("foo % f"), neg, convert("foo -2560.001000"), + convert("foo -2560.001000")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test17/test17.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test17/test17.cpp new file mode 100644 index 00000000000000..08ec3fe1b81ba3 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test17/test17.cpp @@ -0,0 +1,62 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test17.c +** +** Purpose: Test #17 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime_vswprintf_test17_paltest_vswprintf_test17, "c_runtime/vswprintf/test17/paltest_vswprintf_test17") +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoDoubleTest(convert("foo %g"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %lg"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %hg"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %Lg"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %I64g"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %5g"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %-5g"), val, convert("foo 2560 "), + convert("foo 2560 ")); + DoDoubleTest(convert("foo %.1g"), val, convert("foo 3e+003"), + convert("foo 3e+03")); + DoDoubleTest(convert("foo %.2g"), val, convert("foo 2.6e+003"), + convert("foo 2.6e+03")); + DoDoubleTest(convert("foo %.12g"), val, convert("foo 2560.001"), + convert("foo 2560.001")); + DoDoubleTest(convert("foo %06g"), val, convert("foo 002560"), + convert("foo 002560")); + DoDoubleTest(convert("foo %#g"), val, convert("foo 2560.00"), + convert("foo 2560.00")); + DoDoubleTest(convert("foo %+g"), val, convert("foo +2560"), + convert("foo +2560")); + DoDoubleTest(convert("foo % g"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %+g"), neg, convert("foo -2560"), + convert("foo -2560")); + DoDoubleTest(convert("foo % g"), neg, convert("foo -2560"), + convert("foo -2560")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test18/test18.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test18/test18.cpp new file mode 100644 index 00000000000000..cf59b137da1522 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test18/test18.cpp @@ -0,0 +1,62 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test18.c +** +** Purpose: Test #18 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime_vswprintf_test18_paltest_vswprintf_test18, "c_runtime/vswprintf/test18/paltest_vswprintf_test18") +{ + double val = 2560.001; + double neg = -2560.001; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoDoubleTest(convert("foo %G"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %lG"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %hG"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %LG"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %I64G"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %5G"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %-5G"), val, convert("foo 2560 "), + convert("foo 2560 ")); + DoDoubleTest(convert("foo %.1G"), val, convert("foo 3E+003"), + convert("foo 3E+03")); + DoDoubleTest(convert("foo %.2G"), val, convert("foo 2.6E+003"), + convert("foo 2.6E+03")); + DoDoubleTest(convert("foo %.12G"), val, convert("foo 2560.001"), + convert("foo 2560.001")); + DoDoubleTest(convert("foo %06G"), val, convert("foo 002560"), + convert("foo 002560")); + DoDoubleTest(convert("foo %#G"), val, convert("foo 2560.00"), + convert("foo 2560.00")); + DoDoubleTest(convert("foo %+G"), val, convert("foo +2560"), + convert("foo +2560")); + DoDoubleTest(convert("foo % G"), val, convert("foo 2560"), + convert("foo 2560")); + DoDoubleTest(convert("foo %+G"), neg, convert("foo -2560"), + convert("foo -2560")); + DoDoubleTest(convert("foo % G"), neg, convert("foo -2560"), + convert("foo -2560")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test19/test19.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test19/test19.cpp new file mode 100644 index 00000000000000..eed7f216d255bb --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test19/test19.cpp @@ -0,0 +1,136 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test18.c +** +** Purpose: Test #18 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +#define DOTEST(a,b,c,d,e) DoTest(a,b,(void*)c,d,e) + +void DoArgumentPrecTest_vswprintf(WCHAR *formatstr, int precision, void *param, + WCHAR *paramstr, WCHAR *checkstr1, WCHAR *checkstr2) +{ + WCHAR buf[256]; + + testvswp(buf, ARRAY_SIZE(buf), formatstr, precision, param); + if (memcmp(buf, checkstr1, wcslen(checkstr1) + 2) != 0 && + memcmp(buf, checkstr2, wcslen(checkstr2) + 2) != 0) + { + Fail("ERROR: failed to insert %s into \"%s\" with precision %d\n" + "Expected \"%s\" or \"%s\", got \"%s\".\n", + paramstr, + convertC(formatstr), + precision, + convertC(checkstr1), + convertC(checkstr2), + convertC(buf)); + } +} +void DoArgumentPrecDoubleTest_vswprintf(WCHAR *formatstr, int precision, double param, + WCHAR *checkstr1, WCHAR *checkstr2) +{ + WCHAR buf[256]; + + testvswp(buf, ARRAY_SIZE(buf), formatstr, precision, param); + if (memcmp(buf, checkstr1, wcslen(checkstr1) + 2) != 0 && + memcmp(buf, checkstr2, wcslen(checkstr2) + 2) != 0) + { + Fail("ERROR: failed to insert %f into \"%s\" with precision %d\n" + "Expected \"%s\" or \"%s\", got \"%s\".\n", + param, convertC(formatstr), + precision, + convertC(checkstr1), + convertC(checkstr2), + convertC(buf)); + } +} + +/* + * Uses memcmp & wcslen + */ + +PALTEST(c_runtime_vswprintf_test19_paltest_vswprintf_test19, "c_runtime/vswprintf/test19/paltest_vswprintf_test19") +{ + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoArgumentPrecTest_vswprintf(convert("%.*s"), 2, (void*)convert("bar"), convert("bar"), + convert("ba"), convert("ba")); + DoArgumentPrecTest_vswprintf(convert("%.*c"), 0, (void*)'a', convert("a"), + convert("a"), convert("a")); + DoArgumentPrecTest_vswprintf(convert("%.*c"), 4, (void*)'a', convert("a"), + convert("a"), convert("a")); + DoArgumentPrecTest_vswprintf(convert("%.*C"), 0, (void*)'a', convert("a"), + convert("a"), convert("a")); + DoArgumentPrecTest_vswprintf(convert("%.*C"), 4, (void*)'a', convert("a"), + convert("a"), convert("a")); + DoArgumentPrecTest_vswprintf(convert("%.*d"), 1, (void*)42, convert("42"), + convert("42"), convert("42")); + DoArgumentPrecTest_vswprintf(convert("%.*d"), 3, (void*)42, convert("42"), + convert("042"), convert("042")); + DoArgumentPrecTest_vswprintf(convert("%.*i"), 1, (void*)42, convert("42"), + convert("42"), convert("42")); + DoArgumentPrecTest_vswprintf(convert("%.*i"), 3, (void*)42, convert("42"), + convert("042"), convert("042")); + DoArgumentPrecTest_vswprintf(convert("%.*o"), 1, (void*)42, convert("42"), + convert("52"), convert("52")); + DoArgumentPrecTest_vswprintf(convert("%.*o"), 3, (void*)42, convert("42"), + convert("052"), convert("052")); + DoArgumentPrecTest_vswprintf(convert("%.*u"), 1, (void*)42, convert("42"), + convert("42"), convert("42")); + DoArgumentPrecTest_vswprintf(convert("%.*u"), 3, (void*)42, convert("42"), + convert("042"), convert("042")); + DoArgumentPrecTest_vswprintf(convert("%.*x"), 1, (void*)0x42, convert("0x42"), + convert("42"), convert("42")); + DoArgumentPrecTest_vswprintf(convert("%.*x"), 3, (void*)0x42, convert("0x42"), + convert("042"), convert("042")); + DoArgumentPrecTest_vswprintf(convert("%.*X"), 1, (void*)0x42, convert("0x42"), + convert("42"), convert("42")); + DoArgumentPrecTest_vswprintf(convert("%.*X"), 3, (void*)0x42, convert("0x42"), + convert("042"), convert("042")); + + + DoArgumentPrecDoubleTest_vswprintf(convert("%.*e"), 1, 2.01, convert("2.0e+000"), + convert("2.0e+00")); + DoArgumentPrecDoubleTest_vswprintf(convert("%.*e"), 3, 2.01, convert("2.010e+000"), + convert("2.010e+00")); + DoArgumentPrecDoubleTest_vswprintf(convert("%.*E"), 1, 2.01, convert("2.0E+000"), + convert("2.0E+00")); + DoArgumentPrecDoubleTest_vswprintf(convert("%.*E"), 3, 2.01, convert("2.010E+000"), + convert("2.010E+00")); + DoArgumentPrecDoubleTest_vswprintf(convert("%.*f"), 1, 2.01, convert("2.0"), + convert("2.0")); + DoArgumentPrecDoubleTest_vswprintf(convert("%.*f"), 3, 2.01, convert("2.010"), + convert("2.010")); + DoArgumentPrecDoubleTest_vswprintf(convert("%.*g"), 1, 256.01, convert("3e+002"), + convert("3e+02")); + DoArgumentPrecDoubleTest_vswprintf(convert("%.*g"), 3, 256.01, convert("256"), + convert("256")); + DoArgumentPrecDoubleTest_vswprintf(convert("%.*g"), 4, 256.01, convert("256"), + convert("256")); + DoArgumentPrecDoubleTest_vswprintf(convert("%.*g"), 6, 256.01, convert("256.01"), + convert("256.01")); + DoArgumentPrecDoubleTest_vswprintf(convert("%.*G"), 1, 256.01, convert("3E+002"), + convert("3E+02")); + DoArgumentPrecDoubleTest_vswprintf(convert("%.*G"), 3, 256.01, convert("256"), + convert("256")); + DoArgumentPrecDoubleTest_vswprintf(convert("%.*G"), 4, 256.01, convert("256"), + convert("256")); + DoArgumentPrecDoubleTest_vswprintf(convert("%.*G"), 6, 256.01, convert("256.01"), + convert("256.01")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test2/test2.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test2/test2.cpp new file mode 100644 index 00000000000000..4b1b09619e5d65 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test2/test2.cpp @@ -0,0 +1,45 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test2.c +** +** Purpose: Test #2 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + + +PALTEST(c_runtime_vswprintf_test2_paltest_vswprintf_test2, "c_runtime/vswprintf/test2/paltest_vswprintf_test2") +{ + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoWStrTest(convert("foo %s"), convert("bar"), convert("foo bar")); + DoStrTest(convert("foo %hs"), "bar", convert("foo bar")); + DoWStrTest(convert("foo %ls"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %ws"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %Ls"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %I64s"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %5s"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %.2s"), convert("bar"), convert("foo ba")); + DoWStrTest(convert("foo %5.2s"), convert("bar"), convert("foo ba")); + DoWStrTest(convert("foo %-5s"), convert("bar"), convert("foo bar ")); + DoWStrTest(convert("foo %05s"), convert("bar"), convert("foo 00bar")); + DoWStrTest(convert("foo %s"), NULL, convert("foo (null)")); + DoStrTest(convert("foo %hs"), NULL, convert("foo (null)")); + DoWStrTest(convert("foo %ls"), NULL, convert("foo (null)")); + DoWStrTest(convert("foo %ws"), NULL, convert("foo (null)")); + DoWStrTest(convert("foo %Ls"), NULL, convert("foo (null)")); + DoWStrTest(convert("foo %I64s"), NULL, convert("foo (null)")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test3/test3.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test3/test3.cpp new file mode 100644 index 00000000000000..2644c4a96be6a8 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test3/test3.cpp @@ -0,0 +1,45 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test3.c +** +** Purpose: Test #3 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + + +PALTEST(c_runtime_vswprintf_test3_paltest_vswprintf_test3, "c_runtime/vswprintf/test3/paltest_vswprintf_test3") +{ + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoStrTest(convert("foo %S"), "bar", convert("foo bar")); + DoStrTest(convert("foo %hS"), "bar", convert("foo bar")); + DoWStrTest(convert("foo %lS"), convert("bar"), convert("foo bar")); + DoWStrTest(convert("foo %wS"), convert("bar"), convert("foo bar")); + DoStrTest(convert("foo %LS"), "bar", convert("foo bar")); + DoStrTest(convert("foo %I64S"), "bar", convert("foo bar")); + DoStrTest(convert("foo %5S"), "bar", convert("foo bar")); + DoStrTest(convert("foo %.2S"), "bar", convert("foo ba")); + DoStrTest(convert("foo %5.2S"), "bar", convert("foo ba")); + DoStrTest(convert("foo %-5S"), "bar", convert("foo bar ")); + DoStrTest(convert("foo %05S"), "bar", convert("foo 00bar")); + DoStrTest(convert("foo %S"), NULL, convert("foo (null)")); + DoStrTest(convert("foo %hS"), NULL, convert("foo (null)")); + DoWStrTest(convert("foo %lS"), NULL, convert("foo (null)")); + DoWStrTest(convert("foo %wS"), NULL, convert("foo (null)")); + DoStrTest(convert("foo %LS"), NULL, convert("foo (null)")); + DoStrTest(convert("foo %I64S"), NULL, convert("foo (null)")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test4/test4.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test4/test4.cpp new file mode 100644 index 00000000000000..4d933e1dcfbb37 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test4/test4.cpp @@ -0,0 +1,117 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test4.c +** +** Purpose: Test #4 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ +static void DoPointerTest(WCHAR *formatstr, void* param, WCHAR* paramstr, + WCHAR *checkstr1) +{ + WCHAR buf[256] = { 0 }; + + testvswp(buf, ARRAY_SIZE(buf), formatstr, param); + if (memcmp(buf, checkstr1, wcslen(checkstr1) + 2) != 0) + + { + Fail("ERROR: failed to insert pointer to %#p into \"%s\"\n" + "Expected \"%s\" got \"%s\".\n", + paramstr, + convertC(formatstr), + convertC(checkstr1), + convertC(buf)); + } +} + +static void DoI64DoubleTest(WCHAR *formatstr, INT64 value, WCHAR *valuestr, + WCHAR *checkstr1) +{ + WCHAR buf[256] = { 0 }; + + testvswp(buf, ARRAY_SIZE(buf), formatstr, value); + if (memcmp(buf, checkstr1, wcslen(checkstr1) + 2) != 0) + { + Fail("ERROR: failed to insert %s into \"%s\"\n" + "Expected \"%s\", got \"%s\".\n", + value, + convertC(formatstr), + convertC(checkstr1), + convertC(buf)); + } +} + +PALTEST(c_runtime_vswprintf_test4_paltest_vswprintf_test4, "c_runtime/vswprintf/test4/paltest_vswprintf_test4") +{ + void *ptr = (void*) 0x123456; + INT64 lptr = I64(0x1234567887654321); + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + +/* +** Run only on 64 bit platforms +*/ +#if defined(HOST_64BIT) + Trace("Testing for 64 Bit Platforms \n"); + DoPointerTest(convert("%p"), NULL, convert("NULL"), convert("0000000000000000")); + DoPointerTest(convert("%p"), ptr, convert("pointer to 0x123456"), + convert("0000000000123456")); + DoPointerTest(convert("%17p"), ptr, convert("pointer to 0x123456"), + convert(" 0000000000123456")); + DoPointerTest(convert("%17p"), ptr, convert("pointer to 0x123456"), + convert(" 0000000000123456")); + DoPointerTest(convert("%-17p"), ptr, convert("pointer to 0x123456"), + convert("0000000000123456 ")); + DoPointerTest(convert("%+p"), ptr, convert("pointer to 0x123456"), + convert("0000000000123456")); + DoPointerTest(convert("%#p"), ptr, convert("pointer to 0x123456"), + convert("0X0000000000123456")); + DoPointerTest(convert("%lp"), ptr, convert("pointer to 0x123456"), + convert("00123456")); + DoPointerTest(convert("%hp"), ptr, convert("pointer to 0x123456"), + convert("00003456")); + DoPointerTest(convert("%Lp"), ptr, convert("pointer to 0x123456"), + convert("00123456")); + DoI64DoubleTest(convert("%I64p"), lptr, + convert("pointer to 0x1234567887654321"), convert("1234567887654321")); + +#else + Trace("Testing for Non 64 Bit Platforms \n"); + DoPointerTest(convert("%p"), NULL, convert("NULL"), convert("00000000")); + DoPointerTest(convert("%p"), ptr, convert("pointer to 0x123456"), + convert("00123456")); + DoPointerTest(convert("%9p"), ptr, convert("pointer to 0x123456"), + convert(" 00123456")); + DoPointerTest(convert("%09p"), ptr, convert("pointer to 0x123456"), + convert(" 00123456")); + DoPointerTest(convert("%-9p"), ptr, convert("pointer to 0x123456"), + convert("00123456 ")); + DoPointerTest(convert("%+p"), ptr, convert("pointer to 0x123456"), + convert("00123456")); + DoPointerTest(convert("%#p"), ptr, convert("pointer to 0x123456"), + convert("0X00123456")); + DoPointerTest(convert("%lp"), ptr, convert("pointer to 0x123456"), + convert("00123456")); + DoPointerTest(convert("%hp"), ptr, convert("pointer to 0x123456"), + convert("00003456")); + DoPointerTest(convert("%Lp"), ptr, convert("pointer to 0x123456"), + convert("00123456")); + DoI64DoubleTest(convert("%I64p"), lptr, + convert("pointer to 0x1234567887654321"), convert("1234567887654321")); + +#endif + + PAL_Terminate(); + return PASS; +} + diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test6/test6.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test6/test6.cpp new file mode 100644 index 00000000000000..e6c3de0641bcac --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test6/test6.cpp @@ -0,0 +1,40 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test6.c +** +** Purpose: Test #6 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime_vswprintf_test6_paltest_vswprintf_test6, "c_runtime/vswprintf/test6/paltest_vswprintf_test6") +{ + WCHAR wc = (WCHAR) 'c'; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoWCharTest(convert("foo %c"), wc, convert("foo c")); + DoCharTest(convert("foo %hc"), 'b', convert("foo b")); + DoWCharTest(convert("foo %lc"), wc, convert("foo c")); + DoWCharTest(convert("foo %Lc"), wc, convert("foo c")); + DoWCharTest(convert("foo %I64c"), wc, convert("foo c")); + DoWCharTest(convert("foo %5c"), wc, convert("foo c")); + DoWCharTest(convert("foo %.0c"), wc, convert("foo c")); + DoWCharTest(convert("foo %-5c"), wc, convert("foo c ")); + DoWCharTest(convert("foo %05c"), wc, convert("foo 0000c")); + DoWCharTest(convert("foo % c"), wc, convert("foo c")); + DoWCharTest(convert("foo %#c"), wc, convert("foo c")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test7/test7.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test7/test7.cpp new file mode 100644 index 00000000000000..22f87093de340f --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test7/test7.cpp @@ -0,0 +1,40 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test7.c +** +** Purpose: Test #7 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime_vswprintf_test7_paltest_vswprintf_test7, "c_runtime/vswprintf/test7/paltest_vswprintf_test7") +{ + WCHAR wc = (WCHAR) 'c'; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoCharTest(convert("foo %C"), 'b', convert("foo b")); + DoWCharTest(convert("foo %hC"), wc, convert("foo c")); + DoCharTest(convert("foo %lC"), 'b', convert("foo b")); + DoCharTest(convert("foo %LC"), 'b', convert("foo b")); + DoCharTest(convert("foo %I64C"), 'b', convert("foo b")); + DoCharTest(convert("foo %5C"), 'b', convert("foo b")); + DoCharTest(convert("foo %.0C"), 'b', convert("foo b")); + DoCharTest(convert("foo %-5C"), 'b', convert("foo b ")); + DoCharTest(convert("foo %05C"), 'b', convert("foo 0000b")); + DoCharTest(convert("foo % C"), 'b', convert("foo b")); + DoCharTest(convert("foo %#C"), 'b', convert("foo b")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test8/test8.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test8/test8.cpp new file mode 100644 index 00000000000000..7ffcf2355e4296 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test8/test8.cpp @@ -0,0 +1,46 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test8.c +** +** Purpose: Test #8 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime_vswprintf_test8_paltest_vswprintf_test8, "c_runtime/vswprintf/test8/paltest_vswprintf_test8") +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoNumTest(convert("foo %d"), pos, convert("foo 42")); + DoNumTest(convert("foo %ld"), 0xFFFF, convert("foo 65535")); + DoNumTest(convert("foo %hd"), 0xFFFF, convert("foo -1")); + DoNumTest(convert("foo %Ld"), pos, convert("foo 42")); + DoI64NumTest(convert("foo %I64d"), l, "42", convert("foo 42")); + DoNumTest(convert("foo %3d"), pos, convert("foo 42")); + DoNumTest(convert("foo %-3d"), pos, convert("foo 42 ")); + DoNumTest(convert("foo %.1d"), pos, convert("foo 42")); + DoNumTest(convert("foo %.3d"), pos, convert("foo 042")); + DoNumTest(convert("foo %03d"), pos, convert("foo 042")); + DoNumTest(convert("foo %#d"), pos, convert("foo 42")); + DoNumTest(convert("foo %+d"), pos, convert("foo +42")); + DoNumTest(convert("foo % d"), pos, convert("foo 42")); + DoNumTest(convert("foo %+d"), neg, convert("foo -42")); + DoNumTest(convert("foo % d"), neg, convert("foo -42")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test9/test9.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test9/test9.cpp new file mode 100644 index 00000000000000..b965466afffb4c --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/test9/test9.cpp @@ -0,0 +1,46 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*===================================================================== +** +** Source: test9.c +** +** Purpose: Test #9 for the vswprintf function. +** +** +**===================================================================*/ + +#include +#include "../vswprintf.h" + +/* memcmp is used to verify the results, so this test is dependent on it. */ +/* ditto with wcslen */ + +PALTEST(c_runtime_vswprintf_test9_paltest_vswprintf_test9, "c_runtime/vswprintf/test9/paltest_vswprintf_test9") +{ + int neg = -42; + int pos = 42; + INT64 l = 42; + + if (PAL_Initialize(argc, argv) != 0) + return(FAIL); + + DoNumTest(convert("foo %i"), pos, convert("foo 42")); + DoNumTest(convert("foo %li"), 0xFFFF, convert("foo 65535")); + DoNumTest(convert("foo %hi"), 0xFFFF, convert("foo -1")); + DoNumTest(convert("foo %Li"), pos, convert("foo 42")); + DoI64NumTest(convert("foo %I64i"), l, "42", convert("foo 42")); + DoNumTest(convert("foo %3i"), pos, convert("foo 42")); + DoNumTest(convert("foo %-3i"), pos, convert("foo 42 ")); + DoNumTest(convert("foo %.1i"), pos, convert("foo 42")); + DoNumTest(convert("foo %.3i"), pos, convert("foo 042")); + DoNumTest(convert("foo %03i"), pos, convert("foo 042")); + DoNumTest(convert("foo %#i"), pos, convert("foo 42")); + DoNumTest(convert("foo %+i"), pos, convert("foo +42")); + DoNumTest(convert("foo % i"), pos, convert("foo 42")); + DoNumTest(convert("foo %+i"), neg, convert("foo -42")); + DoNumTest(convert("foo % i"), neg, convert("foo -42")); + + PAL_Terminate(); + return PASS; +} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/vswprintf.h b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/vswprintf.h new file mode 100644 index 00000000000000..e8aa6cc1d491f3 --- /dev/null +++ b/src/coreclr/pal/tests/palsuite/c_runtime/vswprintf/vswprintf.h @@ -0,0 +1,139 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*============================================================================ +** +** Source: vswprintf.h +** +** Purpose: Contains common testing functions for vswprintf +** +** +**==========================================================================*/ + +#ifndef __vswprintf_H__ +#define __vswprintf_H__ + +/* These functions leaks memory a lot. C'est la vie. */ +inline int testvswp(char16_t* buf, size_t buffSize, const char16_t* format, ...) +{ + int retVal = 0; + va_list arglist; + + va_start(arglist, format); + retVal = _vsnwprintf_s(buf, buffSize, _TRUNCATE, format, arglist); + va_end(arglist); + + return( retVal); +} + +inline void DoWStrTest_vswprintf_s(const WCHAR *formatstr, WCHAR *param, const WCHAR *checkstr) +{ + WCHAR buf[256] = { 0 }; + + testvswp(buf, ARRAY_SIZE(buf), formatstr, param); + + if (memcmp(buf, checkstr, wcslen(buf) * 2 + 2) != 0) + { + Fail("ERROR: failed to insert wide string \"%s\" into \"%s\".\n" + "Expected \"%s\", got \"%s\".\n", + convertC(param), convertC(formatstr), + convertC(checkstr), convertC(buf)); + } +} +#define DoWStrTest DoWStrTest_vswprintf_s + +inline void DoStrTest_vswprintf_s(const WCHAR *formatstr, char *param, const WCHAR *checkstr) +{ + WCHAR buf[256] = { 0 }; + + testvswp(buf, ARRAY_SIZE(buf), formatstr, param); + + if (memcmp(buf, checkstr, wcslen(buf) * 2 + 2) != 0) + { + Fail("ERROR: failed to insert wide string \"%s\" into \"%s\".\n" + "Expected \"%s\", got \"%s\".\n", + param, convertC(formatstr), convertC(checkstr), + convertC(buf)); + } +} +#define DoStrTest DoStrTest_vswprintf_s + +inline void DoCharTest_vswprintf_s(const WCHAR *formatstr, char param, const WCHAR *checkstr) +{ + WCHAR buf[256] = { 0 }; + + testvswp(buf, ARRAY_SIZE(buf), formatstr, param); + if (memcmp(buf, checkstr, wcslen(buf)*2 + 2) != 0) + { + Fail("ERROR: failed to insert char \'%c\' (%d) into \"%s\"\n" + "Expected \"%s\" got \"%s\".\n", + param, param, convertC(formatstr), convertC(checkstr), + convertC(buf)); + } +} +#define DoCharTest DoCharTest_vswprintf_s + +inline void DoWCharTest_vswprintf_s(const WCHAR *formatstr, WCHAR param, const WCHAR *checkstr) +{ + WCHAR buf[256] = { 0 }; + + testvswp(buf, ARRAY_SIZE(buf), formatstr, param); + if (memcmp(buf, checkstr, wcslen(buf)*2 + 2) != 0) + { + Fail("ERROR: failed to insert wide char \'%c\' (%d) into \"%s\"\n" + "Expected \"%s\" got \"%s\".\n", + (char) param, param, convertC(formatstr), convertC(checkstr), + convertC(buf)); + } +} +#define DoWCharTest DoWCharTest_vswprintf_s + +inline void DoNumTest_vswprintf_s(const WCHAR *formatstr, int value, const WCHAR *checkstr) +{ + WCHAR buf[256] = { 0 }; + + testvswp(buf, ARRAY_SIZE(buf), formatstr, value); + if (memcmp(buf, checkstr, wcslen(buf)* 2 + 2) != 0) + { + Fail("ERROR: failed to insert %#x into \"%s\"\n" + "Expected \"%s\" got \"%s\".\n", value, convertC(formatstr), + convertC(checkstr), convertC(buf)); + } +} +#define DoNumTest DoNumTest_vswprintf_s + +inline void DoI64NumTest_vswprintf_s(const WCHAR *formatstr, INT64 value, char *valuestr, const WCHAR *checkstr) +{ + WCHAR buf[256] = { 0 }; + + testvswp(buf, ARRAY_SIZE(buf), formatstr, value); + if (memcmp(buf, checkstr, wcslen(buf)* 2 + 2) != 0) + { + Fail("ERROR: failed to insert %s into \"%s\"\n" + "Expected \"%s\" got \"%s\".\n", valuestr, convertC(formatstr), + convertC(checkstr), convertC(buf)); + } +} +#define DoI64NumTest DoI64NumTest_vswprintf_s + +inline void DoDoubleTest_vswprintf_s(const WCHAR *formatstr, double value, const WCHAR *checkstr1, WCHAR + *checkstr2) +{ + WCHAR buf[256] = { 0 }; + + testvswp(buf, ARRAY_SIZE(buf), formatstr, value); + if (memcmp(buf, checkstr1, wcslen(checkstr1) + 2) != 0 && + memcmp(buf, checkstr2, wcslen(checkstr2) + 2) != 0) + { + Fail("ERROR: failed to insert %f into \"%s\"\n" + "Expected \"%s\" or \"%s\", got \"%s\".\n", + value, + convertC(formatstr), + convertC(checkstr1), + convertC(checkstr2), + convertC(buf)); + } +} +#define DoDoubleTest DoDoubleTest_vswprintf_s + +#endif diff --git a/src/coreclr/pal/tests/palsuite/compilableTests.txt b/src/coreclr/pal/tests/palsuite/compilableTests.txt index f3741be500a4cb..798f5ceb57c72f 100644 --- a/src/coreclr/pal/tests/palsuite/compilableTests.txt +++ b/src/coreclr/pal/tests/palsuite/compilableTests.txt @@ -255,6 +255,24 @@ c_runtime/vsprintf/test6/paltest_vsprintf_test6 c_runtime/vsprintf/test7/paltest_vsprintf_test7 c_runtime/vsprintf/test8/paltest_vsprintf_test8 c_runtime/vsprintf/test9/paltest_vsprintf_test9 +c_runtime/vswprintf/test1/paltest_vswprintf_test1 +c_runtime/vswprintf/test10/paltest_vswprintf_test10 +c_runtime/vswprintf/test11/paltest_vswprintf_test11 +c_runtime/vswprintf/test12/paltest_vswprintf_test12 +c_runtime/vswprintf/test13/paltest_vswprintf_test13 +c_runtime/vswprintf/test14/paltest_vswprintf_test14 +c_runtime/vswprintf/test15/paltest_vswprintf_test15 +c_runtime/vswprintf/test16/paltest_vswprintf_test16 +c_runtime/vswprintf/test17/paltest_vswprintf_test17 +c_runtime/vswprintf/test18/paltest_vswprintf_test18 +c_runtime/vswprintf/test19/paltest_vswprintf_test19 +c_runtime/vswprintf/test2/paltest_vswprintf_test2 +c_runtime/vswprintf/test3/paltest_vswprintf_test3 +c_runtime/vswprintf/test4/paltest_vswprintf_test4 +c_runtime/vswprintf/test6/paltest_vswprintf_test6 +c_runtime/vswprintf/test7/paltest_vswprintf_test7 +c_runtime/vswprintf/test8/paltest_vswprintf_test8 +c_runtime/vswprintf/test9/paltest_vswprintf_test9 c_runtime/wcscat/test1/paltest_wcscat_test1 c_runtime/wcschr/test1/paltest_wcschr_test1 c_runtime/wcscmp/test1/paltest_wcscmp_test1 @@ -303,6 +321,24 @@ c_runtime/_snprintf_s/test6/paltest_snprintf_test6 c_runtime/_snprintf_s/test7/paltest_snprintf_test7 c_runtime/_snprintf_s/test8/paltest_snprintf_test8 c_runtime/_snprintf_s/test9/paltest_snprintf_test9 +c_runtime/_snwprintf_s/test1/paltest_snwprintf_test1 +c_runtime/_snwprintf_s/test10/paltest_snwprintf_test10 +c_runtime/_snwprintf_s/test11/paltest_snwprintf_test11 +c_runtime/_snwprintf_s/test12/paltest_snwprintf_test12 +c_runtime/_snwprintf_s/test13/paltest_snwprintf_test13 +c_runtime/_snwprintf_s/test14/paltest_snwprintf_test14 +c_runtime/_snwprintf_s/test15/paltest_snwprintf_test15 +c_runtime/_snwprintf_s/test16/paltest_snwprintf_test16 +c_runtime/_snwprintf_s/test17/paltest_snwprintf_test17 +c_runtime/_snwprintf_s/test18/paltest_snwprintf_test18 +c_runtime/_snwprintf_s/test19/paltest_snwprintf_test19 +c_runtime/_snwprintf_s/test2/paltest_snwprintf_test2 +c_runtime/_snwprintf_s/test3/paltest_snwprintf_test3 +c_runtime/_snwprintf_s/test4/paltest_snwprintf_test4 +c_runtime/_snwprintf_s/test6/paltest_snwprintf_test6 +c_runtime/_snwprintf_s/test7/paltest_snwprintf_test7 +c_runtime/_snwprintf_s/test8/paltest_snwprintf_test8 +c_runtime/_snwprintf_s/test9/paltest_snwprintf_test9 c_runtime/_stricmp/test1/paltest_stricmp_test1 c_runtime/_strnicmp/test1/paltest_strnicmp_test1 c_runtime/_vsnprintf_s/test1/paltest_vsnprintf_test1 @@ -323,6 +359,24 @@ c_runtime/_vsnprintf_s/test6/paltest_vsnprintf_test6 c_runtime/_vsnprintf_s/test7/paltest_vsnprintf_test7 c_runtime/_vsnprintf_s/test8/paltest_vsnprintf_test8 c_runtime/_vsnprintf_s/test9/paltest_vsnprintf_test9 +c_runtime/_vsnwprintf_s/test1/paltest_vsnwprintf_test1 +c_runtime/_vsnwprintf_s/test10/paltest_vsnwprintf_test10 +c_runtime/_vsnwprintf_s/test11/paltest_vsnwprintf_test11 +c_runtime/_vsnwprintf_s/test12/paltest_vsnwprintf_test12 +c_runtime/_vsnwprintf_s/test13/paltest_vsnwprintf_test13 +c_runtime/_vsnwprintf_s/test14/paltest_vsnwprintf_test14 +c_runtime/_vsnwprintf_s/test15/paltest_vsnwprintf_test15 +c_runtime/_vsnwprintf_s/test16/paltest_vsnwprintf_test16 +c_runtime/_vsnwprintf_s/test17/paltest_vsnwprintf_test17 +c_runtime/_vsnwprintf_s/test18/paltest_vsnwprintf_test18 +c_runtime/_vsnwprintf_s/test19/paltest_vsnwprintf_test19 +c_runtime/_vsnwprintf_s/test2/paltest_vsnwprintf_test2 +c_runtime/_vsnwprintf_s/test3/paltest_vsnwprintf_test3 +c_runtime/_vsnwprintf_s/test4/paltest_vsnwprintf_test4 +c_runtime/_vsnwprintf_s/test6/paltest_vsnwprintf_test6 +c_runtime/_vsnwprintf_s/test7/paltest_vsnwprintf_test7 +c_runtime/_vsnwprintf_s/test8/paltest_vsnwprintf_test8 +c_runtime/_vsnwprintf_s/test9/paltest_vsnwprintf_test9 c_runtime/_wcsicmp/test1/paltest_wcsicmp_test1 c_runtime/_wcslwr_s/test1/paltest_wcslwr_s_test1 c_runtime/_wcsnicmp/test1/paltest_wcsnicmp_test1 diff --git a/src/coreclr/pal/tests/palsuite/file_io/GetTempFileNameW/test1/GetTempFileNameW.cpp b/src/coreclr/pal/tests/palsuite/file_io/GetTempFileNameW/test1/GetTempFileNameW.cpp index f1be5b66525798..a49da3e4a1c32b 100644 --- a/src/coreclr/pal/tests/palsuite/file_io/GetTempFileNameW/test1/GetTempFileNameW.cpp +++ b/src/coreclr/pal/tests/palsuite/file_io/GetTempFileNameW/test1/GetTempFileNameW.cpp @@ -103,12 +103,7 @@ PALTEST(file_io_GetTempFileNameW_test1_paltest_gettempfilenamew_test1, "file_io/ } // now verify that it only used the first 3 characters of the prefix - WCHAR* wCurr = wTempString; - memcpy(wCurr, wPath, wcslen(wPath) * sizeof(WCHAR)); - wCurr += wcslen(wPath); - wcscat(wCurr, W("\\")); - wCurr += wcslen(W("\\")); - wcscat(wCurr, wPrefix); + _snwprintf_s(wTempString, ARRAY_SIZE(wTempString), _TRUNCATE, convert("%s\\%s"), wPath, wPrefix); if (memcmp(wTempString, wReturnedName, wcslen(wTempString)*sizeof(WCHAR)) == 0) { free (wPath); diff --git a/src/coreclr/pal/tests/palsuite/miscellaneous/FormatMessageW/test2/test.cpp b/src/coreclr/pal/tests/palsuite/miscellaneous/FormatMessageW/test2/test.cpp index e7b30213f2332d..fabf8fda884a47 100644 --- a/src/coreclr/pal/tests/palsuite/miscellaneous/FormatMessageW/test2/test.cpp +++ b/src/coreclr/pal/tests/palsuite/miscellaneous/FormatMessageW/test2/test.cpp @@ -20,7 +20,7 @@ WCHAR OutBuffer_FormatMessageW_test2[1024]; int test1(int num, ...) { - WCHAR * TheString = convert("Pal %1 Testing"); + WCHAR * TheString = convert("Pal %1!s! Testing"); int ReturnResult; va_list TheList; va_start(TheList,num); @@ -58,6 +58,8 @@ int test1(int num, ...) return PASS; } +/* Pass this test the int 40 and it will succeed */ + int test2(int num, ...) { @@ -80,10 +82,458 @@ int test2(int num, ...) va_end(TheList); - if(ReturnResult != 0) + if(ReturnResult == 0) + { + Fail("ERROR: The return value was 0, which indicates failure. " + "The function failed when trying to Format a simple string," + " with the 'i' formatter."); + } + + if(memcmp(OutBuffer_FormatMessageW_test2, convert("Pal 40 Testing"),wcslen(OutBuffer_FormatMessageW_test2)*2+2) != 0) + { + Fail("ERROR: The formatted string should have been 'Pal 40 Testing' " + "but '%s' was returned.", convertC(OutBuffer_FormatMessageW_test2)); + } + return PASS; +} + +/* Pass this test the character 'a' and it will succeed */ + +int test3(int num, ...) { + + WCHAR * TheString = convert("Pal %1!c! Testing"); + int ReturnResult; + va_list TheList; + va_start(TheList,num); + memset( OutBuffer_FormatMessageW_test2, 0, 1024 * sizeof(OutBuffer_FormatMessageW_test2[0]) ); + ReturnResult = FormatMessage( + FORMAT_MESSAGE_FROM_STRING, /* source and processing options */ + TheString, /* message source */ + 0, /* message identifier */ + 0, /* language identifier */ + OutBuffer_FormatMessageW_test2, /* message buffer */ + 1024, /* maximum size of message buffer */ + &TheList /* array of message inserts */ + ); + + va_end(TheList); + + if(ReturnResult == 0) + { + Fail("ERROR: The return value was 0, which indicates failure. " + "The function failed when trying to Format a simple string," + " with the 'c' formatter."); + } + + if(memcmp(OutBuffer_FormatMessageW_test2, convert("Pal a Testing"),wcslen(OutBuffer_FormatMessageW_test2)*2+2) != 0) + { + Fail("ERROR: The formatted string should have been 'Pal a Testing' " + "but '%s' was returned.", convertC(OutBuffer_FormatMessageW_test2)); + + } + + return PASS; +} + +/* Pass this test the character 'a' and it will succeed */ + +int test4(int num, ...) { + + WCHAR * TheString = convert("Pal %1!C! Testing"); + int ReturnResult; + va_list TheList; + va_start(TheList,num); + memset( OutBuffer_FormatMessageW_test2, 0, 1024 * sizeof(OutBuffer_FormatMessageW_test2[0]) ); + ReturnResult = FormatMessage( + FORMAT_MESSAGE_FROM_STRING, /* source and processing options */ + TheString, /* message source */ + 0, /* message identifier */ + 0, /* language identifier */ + OutBuffer_FormatMessageW_test2, /* message buffer */ + 1024, /* maximum size of message buffer */ + &TheList /* array of message inserts */ + ); + + va_end(TheList); + + if(ReturnResult == 0) + { + Fail("ERROR: The return value was 0, which indicates failure. " + "The function failed when trying to Format a simple string," + " with the 'C' formatter."); + } + + if(memcmp(OutBuffer_FormatMessageW_test2, convert("Pal a Testing"),wcslen(OutBuffer_FormatMessageW_test2)*2+2) != 0) + { + Fail("ERROR: The formatted string should have been 'Pal a Testing' " + "but '%s' was returned.",convertC(OutBuffer_FormatMessageW_test2)); + } + + return PASS; +} + +/* Pass this test the number 57 and it will succeed */ + +int test5(int num, ...) +{ + + WCHAR * TheString = convert("Pal %1!d! Testing"); + int ReturnResult; + va_list TheList; + va_start(TheList,num); + memset( OutBuffer_FormatMessageW_test2, 0, 1024 * sizeof(OutBuffer_FormatMessageW_test2[0]) ); + + ReturnResult = FormatMessage( + FORMAT_MESSAGE_FROM_STRING, /* source and processing options */ + TheString, /* message source */ + 0, /* message identifier */ + 0, /* language identifier */ + OutBuffer_FormatMessageW_test2, /* message buffer */ + 1024, /* maximum size of message buffer */ + &TheList /* array of message inserts */ + ); + + va_end(TheList); + + if(ReturnResult == 0) + { + Fail("ERROR: The return value was 0, which indicates failure. " + "The function failed when trying to Format a simple string, " + "with the 'd' formatter."); + + } + + if(memcmp(OutBuffer_FormatMessageW_test2, convert("Pal 57 Testing"),wcslen(OutBuffer_FormatMessageW_test2)*2+2) != 0) + { + Fail("ERROR: The formatted string should have been 'Pal 57 Testing' " + "but '%s' was returned.",convertC(OutBuffer_FormatMessageW_test2)); + + } + + return PASS; +} + +/* Pass this test the characters 'a' and 'b' and it will succeed. */ + +int test6(int num, ...) { + + WCHAR * TheString = convert("Pal %1!hc! and %2!hC! Testing"); + int ReturnResult; + va_list TheList; + va_start(TheList,num); + memset( OutBuffer_FormatMessageW_test2, 0, 1024 * sizeof(OutBuffer_FormatMessageW_test2[0]) ); + + ReturnResult = FormatMessage( + FORMAT_MESSAGE_FROM_STRING, /* source and processing options */ + TheString, /* message source */ + 0, /* message identifier */ + 0, /* language identifier */ + OutBuffer_FormatMessageW_test2, /* message buffer */ + 1024, /* maximum size of message buffer */ + &TheList /* array of message inserts */ + ); + + va_end(TheList); + + if(ReturnResult == 0) + { + Fail("ERROR: The return value was 0, which indicates failure. " + "The function failed when trying to Format a simple string, " + "with the 'hc' and 'hC' formatters."); + + } + + if(memcmp(OutBuffer_FormatMessageW_test2, convert("Pal a and b Testing"), + wcslen(OutBuffer_FormatMessageW_test2)*2+2) != 0) + { + Fail("ERROR: The formatted string should have been 'Pal a and b " + "Testing' but '%s' was returned.", convertC(OutBuffer_FormatMessageW_test2)); + + } + + return PASS; +} + +/* Pass this test 90, the string 'foo' and the string 'bar' to succeed */ + +int test7(int num, ...) +{ + + WCHAR * TheString = convert("Pal %1!hd! and %2!hs! and %3!hS! Testing"); + int ReturnResult; + va_list TheList; + va_start(TheList,num); + memset( OutBuffer_FormatMessageW_test2, 0, 1024 * sizeof(OutBuffer_FormatMessageW_test2[0]) ); + + ReturnResult = FormatMessage( + FORMAT_MESSAGE_FROM_STRING, /* source and processing options */ + TheString, /* message source */ + 0, /* message identifier */ + 0, /* language identifier */ + OutBuffer_FormatMessageW_test2, /* message buffer */ + 1024, /* maximum size of message buffer */ + &TheList /* array of message inserts */ + ); + + va_end(TheList); + + if(ReturnResult == 0) + { + Fail("ERROR: The return value was 0, which indicates failure. " + "The function failed when trying to Format a simple string, " + "with the 'hd', 'hs' and 'hS' formatters."); + + } + + if(memcmp(OutBuffer_FormatMessageW_test2, + convert("Pal 90 and foo and bar Testing"), + wcslen(OutBuffer_FormatMessageW_test2)*2+2) != 0) + { + Fail("ERROR: The formatted string should have been 'Pal 90 and foo " + "and bar Testing' but '%s' was returned.",convertC(OutBuffer_FormatMessageW_test2)); + } + + return PASS; +} + +/* Pass this test the characters 'a', 'b' and the numbers 50 and 100 */ + +int test8(int num, ...) +{ + + WCHAR * TheString = + convert("Pal %1!lc! and %2!lC! and %3!ld! and %4!li! Testing"); + int ReturnResult; + va_list TheList; + va_start(TheList,num); + memset( OutBuffer_FormatMessageW_test2, 0, 1024 * sizeof(OutBuffer_FormatMessageW_test2[0]) ); + + ReturnResult = FormatMessage( + FORMAT_MESSAGE_FROM_STRING, /* source and processing options */ + TheString, /* message source */ + 0, /* message identifier */ + 0, /* language identifier */ + OutBuffer_FormatMessageW_test2, /* message buffer */ + 1024, /* maximum size of message buffer */ + &TheList /* array of message inserts */ + ); + + va_end(TheList); + + if(ReturnResult == 0) + { + Fail("ERROR: The return value was 0, which indicates failure. " + "The function failed when trying to Format a simple string, " + "with the 'lc', 'lC', 'ld' and 'li' formatters."); + + } + + if(memcmp(OutBuffer_FormatMessageW_test2, + convert("Pal a and b and 50 and 100 Testing"), + wcslen(OutBuffer_FormatMessageW_test2)*2+2) != 0) + { + Fail("ERROR: The formatted string should have been 'Pal a and b and 50" + " and 100 Testing' but '%s' was returned.",convertC(OutBuffer_FormatMessageW_test2)); + + } + + return PASS; +} + +/* Pass this test the wide string 'foo' and 'bar' and the unsigned + int 56 to pass +*/ + +int test9(int num, ...) { + + WCHAR * TheString = convert("Pal %1!ls! and %2!ls! and %3!lu! Testing"); + int ReturnResult; + va_list TheList; + va_start(TheList,num); + memset( OutBuffer_FormatMessageW_test2, 0, 1024 * sizeof(OutBuffer_FormatMessageW_test2[0]) ); + ReturnResult = FormatMessage( + FORMAT_MESSAGE_FROM_STRING, /* source and processing options */ + TheString, /* message source */ + 0, /* message identifier */ + 0, /* language identifier */ + OutBuffer_FormatMessageW_test2, /* message buffer */ + 1024, /* maximum size of message buffer */ + &TheList /* array of message inserts */ + ); + + va_end(TheList); + + if(ReturnResult == 0) + { + Fail("ERROR: The return value was 0, which indicates failure. " + "The function failed when trying to Format a simple string," + " with the 'ls', 'lS' and 'lu' formatters."); + + } + + if(memcmp(OutBuffer_FormatMessageW_test2, + convert("Pal foo and bar and 56 Testing"), + wcslen(OutBuffer_FormatMessageW_test2)*2+2) != 0) + { + Fail("ERROR: The formatted string should have been 'Pal foo and bar " + "and 56 Testing' but '%s' was returned.",convertC(OutBuffer_FormatMessageW_test2)); + + } + + return PASS; +} + +/* Pass this test the hex values 0x123ab and 0x123cd */ + +int test10(int num, ...) +{ + + WCHAR * TheString = convert("Pal %1!lx! and %2!lX! Testing"); + int ReturnResult; + va_list TheList; + va_start(TheList,num); + memset( OutBuffer_FormatMessageW_test2, 0, 1024 * sizeof(OutBuffer_FormatMessageW_test2[0]) ); + ReturnResult = FormatMessage( + FORMAT_MESSAGE_FROM_STRING, /* source and processing options */ + TheString, /* message source */ + 0, /* message identifier */ + 0, /* language identifier */ + OutBuffer_FormatMessageW_test2, /* message buffer */ + 1024, /* maximum size of message buffer */ + &TheList /* array of message inserts */ + ); + + va_end(TheList); + + if(ReturnResult == 0) + { + Fail("ERROR: The return value was 0, which indicates failure. " + "The function failed when trying to Format a simple string, " + "with the 'lx' and 'lX' formatters."); + + } + + if(memcmp(OutBuffer_FormatMessageW_test2, + convert("Pal 123ab and 123CD Testing"), + wcslen(OutBuffer_FormatMessageW_test2)*2+2) != 0) + { + Fail("ERROR: The formatted string should have been 'Pal 123ab and " + "123CD Testing' but '%s' was returned.", convertC(OutBuffer_FormatMessageW_test2)); + + } + + return PASS; +} + +/* Pass this test a pointer to 0x123ab and the string 'foo' to pass */ + +int test11(int num, ...) +{ + + WCHAR * TheString = convert("Pal %1!p! and %2!S! Testing"); + int ReturnResult; + va_list TheList; + va_start(TheList,num); + memset( OutBuffer_FormatMessageW_test2, 0, 1024 * sizeof(OutBuffer_FormatMessageW_test2[0]) ); + + ReturnResult = FormatMessage( + FORMAT_MESSAGE_FROM_STRING, /* source and processing options */ + TheString, /* message source */ + 0, /* message identifier */ + 0, /* language identifier */ + OutBuffer_FormatMessageW_test2, /* message buffer */ + 1024, /* maximum size of message buffer */ + &TheList /* array of message inserts */ + ); + + va_end(TheList); + + if(ReturnResult == 0) + { + Fail("ERROR: The return value was 0, which indicates failure. " + "The function failed when trying to Format a simple string, " + "with the 'p' and 'S' formatters."); + + } + +/* +** Run only on 64 bit platforms +*/ +#if defined(HOST_64BIT) + Trace("Testing for 64 Bit Platforms \n"); + if(memcmp(OutBuffer_FormatMessageW_test2, + convert("Pal 00000000000123AB and foo Testing"), + wcslen(OutBuffer_FormatMessageW_test2)*2+2) != 0 && + /* BSD style */ + memcmp( OutBuffer_FormatMessageW_test2, + convert( "Pal 0x123ab and foo Testing" ), + wcslen(OutBuffer_FormatMessageW_test2)*2+2 ) != 0 ) + { + Fail("ERROR: The formatted string should have been 'Pal 000123AB and " + "foo Testing' but '%s' was returned.",convertC(OutBuffer_FormatMessageW_test2)); + + } + +#else + Trace("Testing for Non 64 Bit Platforms \n"); + if(memcmp(OutBuffer_FormatMessageW_test2, + convert("Pal 000123AB and foo Testing"), + wcslen(OutBuffer_FormatMessageW_test2)*2+2) != 0 && + /* BSD style */ + memcmp( OutBuffer_FormatMessageW_test2, + convert( "Pal 0x123ab and foo Testing" ), + wcslen(OutBuffer_FormatMessageW_test2)*2+2 ) != 0 ) + { + Fail("ERROR: The formatted string should have been 'Pal 000123AB and " + "foo Testing' but '%s' was returned.",convertC(OutBuffer_FormatMessageW_test2)); + + } + +#endif + + return PASS; +} + +/* Pass this test the unsigned int 100 and the hex values 0x123ab and 0x123cd +to succeed */ + +int test12(int num, ...) +{ + + WCHAR * TheString = convert("Pal %1!u! and %2!x! and %3!X! Testing"); + int ReturnResult; + va_list TheList; + va_start(TheList,num); + memset( OutBuffer_FormatMessageW_test2, 0, 1024 * sizeof(OutBuffer_FormatMessageW_test2[0]) ); + + ReturnResult = FormatMessage( + FORMAT_MESSAGE_FROM_STRING, /* source and processing options */ + TheString, /* message source */ + 0, /* message identifier */ + 0, /* language identifier */ + OutBuffer_FormatMessageW_test2, /* message buffer */ + 1024, /* maximum size of message buffer */ + &TheList /* array of message inserts */ + ); + + va_end(TheList); + + if(ReturnResult == 0) + { + Fail("ERROR: The return value was 0, which indicates failure. " + "The function failed when trying to Format a simple string, " + "with the 'u', 'x' and 'X' formatters."); + + } + + if(memcmp(OutBuffer_FormatMessageW_test2, + convert("Pal 100 and 123ab and 123CD Testing"), + wcslen(OutBuffer_FormatMessageW_test2)*2+2) != 0) { - Fail("ERROR: The return value was non-0, which indicates success. " - "The function should fail when trying to Format with embedded printf formats."); + Fail("ERROR: The formatted string should have been 'Pal 100 and " + "123ab and 123CD Testing' but '%s' was returned.", + convertC(OutBuffer_FormatMessageW_test2)); + } return PASS; @@ -92,6 +542,8 @@ int test2(int num, ...) PALTEST(miscellaneous_FormatMessageW_test2_paltest_formatmessagew_test2, "miscellaneous/FormatMessageW/test2/paltest_formatmessagew_test2") { WCHAR szwInsert[] = {'I','N','S','E','R','T','\0'}; + WCHAR szwFoo[] = {'f','o','o','\0'}; + WCHAR szwBar[] = {'b','a','r','\0'}; /* * Initialize the PAL and return FAILURE if this fails @@ -102,8 +554,18 @@ PALTEST(miscellaneous_FormatMessageW_test2_paltest_formatmessagew_test2, "miscel return FAIL; } - if(test1(0,szwInsert) || /* Test %s */ - test2(0,40)) /* Test embedded printf format fails */ + if(test1(0,szwInsert) || /* Test %s */ + test2(0,40) || /* Test %i */ + test3(0,'a') || /* Test %c */ + test4(0,'a') || /* Test %C */ + test5(0,57) || /* Test %d */ + test6(0,'a','b') || /* Test %hc, %hC */ + test7(0,90,"foo","bar") || /* Test %hd,hs,hS */ + test8(0,'a','b',50,100) || /* Test %lc, lC, ld, li */ + test9(0,szwFoo,szwBar,56) || /* Test %ls,lS,lu */ + test10(0,0x123ab,0x123cd) || /* Test %lx, %lX */ + test11(0,(void *)0x123ab,"foo") || /* Test %p, %S */ + test12(0,100,0x123ab,0x123cd)) /* Test %u,x,X */ { diff --git a/src/coreclr/pal/tests/palsuite/paltestlist.txt b/src/coreclr/pal/tests/palsuite/paltestlist.txt index 04e480a184be1f..9b610181be3df6 100644 --- a/src/coreclr/pal/tests/palsuite/paltestlist.txt +++ b/src/coreclr/pal/tests/palsuite/paltestlist.txt @@ -247,6 +247,22 @@ c_runtime/vsprintf/test6/paltest_vsprintf_test6 c_runtime/vsprintf/test7/paltest_vsprintf_test7 c_runtime/vsprintf/test8/paltest_vsprintf_test8 c_runtime/vsprintf/test9/paltest_vsprintf_test9 +c_runtime/vswprintf/test1/paltest_vswprintf_test1 +c_runtime/vswprintf/test10/paltest_vswprintf_test10 +c_runtime/vswprintf/test11/paltest_vswprintf_test11 +c_runtime/vswprintf/test12/paltest_vswprintf_test12 +c_runtime/vswprintf/test13/paltest_vswprintf_test13 +c_runtime/vswprintf/test14/paltest_vswprintf_test14 +c_runtime/vswprintf/test15/paltest_vswprintf_test15 +c_runtime/vswprintf/test16/paltest_vswprintf_test16 +c_runtime/vswprintf/test17/paltest_vswprintf_test17 +c_runtime/vswprintf/test18/paltest_vswprintf_test18 +c_runtime/vswprintf/test19/paltest_vswprintf_test19 +c_runtime/vswprintf/test3/paltest_vswprintf_test3 +c_runtime/vswprintf/test4/paltest_vswprintf_test4 +c_runtime/vswprintf/test6/paltest_vswprintf_test6 +c_runtime/vswprintf/test8/paltest_vswprintf_test8 +c_runtime/vswprintf/test9/paltest_vswprintf_test9 c_runtime/wcscat/test1/paltest_wcscat_test1 c_runtime/wcschr/test1/paltest_wcschr_test1 c_runtime/wcscmp/test1/paltest_wcscmp_test1 @@ -295,6 +311,22 @@ c_runtime/_snprintf_s/test6/paltest_snprintf_test6 c_runtime/_snprintf_s/test7/paltest_snprintf_test7 c_runtime/_snprintf_s/test8/paltest_snprintf_test8 c_runtime/_snprintf_s/test9/paltest_snprintf_test9 +c_runtime/_snwprintf_s/test1/paltest_snwprintf_test1 +c_runtime/_snwprintf_s/test10/paltest_snwprintf_test10 +c_runtime/_snwprintf_s/test11/paltest_snwprintf_test11 +c_runtime/_snwprintf_s/test12/paltest_snwprintf_test12 +c_runtime/_snwprintf_s/test13/paltest_snwprintf_test13 +c_runtime/_snwprintf_s/test14/paltest_snwprintf_test14 +c_runtime/_snwprintf_s/test15/paltest_snwprintf_test15 +c_runtime/_snwprintf_s/test16/paltest_snwprintf_test16 +c_runtime/_snwprintf_s/test17/paltest_snwprintf_test17 +c_runtime/_snwprintf_s/test18/paltest_snwprintf_test18 +c_runtime/_snwprintf_s/test19/paltest_snwprintf_test19 +c_runtime/_snwprintf_s/test3/paltest_snwprintf_test3 +c_runtime/_snwprintf_s/test4/paltest_snwprintf_test4 +c_runtime/_snwprintf_s/test6/paltest_snwprintf_test6 +c_runtime/_snwprintf_s/test8/paltest_snwprintf_test8 +c_runtime/_snwprintf_s/test9/paltest_snwprintf_test9 c_runtime/_stricmp/test1/paltest_stricmp_test1 c_runtime/_strnicmp/test1/paltest_strnicmp_test1 c_runtime/_vsnprintf_s/test1/paltest_vsnprintf_test1 @@ -315,6 +347,22 @@ c_runtime/_vsnprintf_s/test6/paltest_vsnprintf_test6 c_runtime/_vsnprintf_s/test7/paltest_vsnprintf_test7 c_runtime/_vsnprintf_s/test8/paltest_vsnprintf_test8 c_runtime/_vsnprintf_s/test9/paltest_vsnprintf_test9 +c_runtime/_vsnwprintf_s/test1/paltest_vsnwprintf_test1 +c_runtime/_vsnwprintf_s/test10/paltest_vsnwprintf_test10 +c_runtime/_vsnwprintf_s/test11/paltest_vsnwprintf_test11 +c_runtime/_vsnwprintf_s/test12/paltest_vsnwprintf_test12 +c_runtime/_vsnwprintf_s/test13/paltest_vsnwprintf_test13 +c_runtime/_vsnwprintf_s/test14/paltest_vsnwprintf_test14 +c_runtime/_vsnwprintf_s/test15/paltest_vsnwprintf_test15 +c_runtime/_vsnwprintf_s/test16/paltest_vsnwprintf_test16 +c_runtime/_vsnwprintf_s/test17/paltest_vsnwprintf_test17 +c_runtime/_vsnwprintf_s/test18/paltest_vsnwprintf_test18 +c_runtime/_vsnwprintf_s/test19/paltest_vsnwprintf_test19 +c_runtime/_vsnwprintf_s/test3/paltest_vsnwprintf_test3 +c_runtime/_vsnwprintf_s/test4/paltest_vsnwprintf_test4 +c_runtime/_vsnwprintf_s/test6/paltest_vsnwprintf_test6 +c_runtime/_vsnwprintf_s/test8/paltest_vsnwprintf_test8 +c_runtime/_vsnwprintf_s/test9/paltest_vsnwprintf_test9 c_runtime/_wcsicmp/test1/paltest_wcsicmp_test1 c_runtime/_wcslwr_s/test1/paltest_wcslwr_s_test1 c_runtime/_wcsnicmp/test1/paltest_wcsnicmp_test1 diff --git a/src/coreclr/pal/tests/palsuite/paltestlist_to_be_reviewed.txt b/src/coreclr/pal/tests/palsuite/paltestlist_to_be_reviewed.txt index 77149d5bbf65ef..f8e39c42bd9b21 100644 --- a/src/coreclr/pal/tests/palsuite/paltestlist_to_be_reviewed.txt +++ b/src/coreclr/pal/tests/palsuite/paltestlist_to_be_reviewed.txt @@ -11,9 +11,15 @@ c_runtime/fread/test3/paltest_fread_test3 c_runtime/ftell/test1/paltest_ftell_test1 c_runtime/iswprint/test1/paltest_iswprint_test1 c_runtime/vprintf/test1/paltest_vprintf_test1 +c_runtime/vswprintf/test2/paltest_vswprintf_test2 +c_runtime/vswprintf/test7/paltest_vswprintf_test7 c_runtime/_gcvt/test1/paltest_gcvt_test1 c_runtime/_gcvt/test2/paltest_gcvt_test2 c_runtime/_getw/test1/paltest_getw_test1 +c_runtime/_snwprintf_s/test2/paltest_snwprintf_test2 +c_runtime/_snwprintf_s/test7/paltest_snwprintf_test7 +c_runtime/_vsnwprintf_s/test2/paltest_vsnwprintf_test2 +c_runtime/_vsnwprintf_s/test7/paltest_vsnwprintf_test7 debug_api/DebugBreak/test1/paltest_debugbreak_test1 debug_api/OutputDebugStringA/test1/paltest_outputdebugstringa_test1 debug_api/WriteProcessMemory/test1/paltest_writeprocessmemory_test1