diff options
author | Jiyoung Yun <jy910.yun@samsung.com> | 2016-11-23 19:09:09 +0900 |
---|---|---|
committer | Jiyoung Yun <jy910.yun@samsung.com> | 2016-11-23 19:09:09 +0900 |
commit | 4b4aad7217d3292650e77eec2cf4c198ea9c3b4b (patch) | |
tree | 98110734c91668dfdbb126fcc0e15ddbd93738ca /src/pal/tests/palsuite/miscellaneous/GetDateFormatW/test1/GetDateFormatW.c | |
parent | fa45f57ed55137c75ac870356a1b8f76c84b229c (diff) | |
download | coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.tar.gz coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.tar.bz2 coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.zip |
Imported Upstream version 1.1.0upstream/1.1.0
Diffstat (limited to 'src/pal/tests/palsuite/miscellaneous/GetDateFormatW/test1/GetDateFormatW.c')
-rw-r--r-- | src/pal/tests/palsuite/miscellaneous/GetDateFormatW/test1/GetDateFormatW.c | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/test1/GetDateFormatW.c b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/test1/GetDateFormatW.c new file mode 100644 index 0000000000..264e397a49 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/test1/GetDateFormatW.c @@ -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. +// See the LICENSE file in the project root for more information. + +/*============================================================= +** +** Source: GetDateFormatW.c +** +** Purpose: Positive test the GetDateFormatW API. +** Call GetDateFormatW to format a date string for +** a specified locale +** +** +**============================================================*/ +#define UNICODE +#include <palsuite.h> + +int __cdecl main(int argc, char *argv[]) +{ + int err; + WCHAR *wpFormat; + LPCSTR lpString = "gg"; + CONST SYSTEMTIME *lpDate = NULL; + LCID DefaultLocale; + DWORD dwFlags; + int DateSize; + WCHAR *wpBuffer = NULL; + + /*Initialize the PAL environment*/ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + return FAIL; + } + + /*convert to a wide character string*/ + wpFormat = convert((char *)lpString); + + /* + DefaultLocale = GetSystemDefaultLCID() which is not defined in PAL; + + LOCALE_SYSTEM_DEFAULT = MAKELCID(LANG_SYSTEM_DEFAULT, SORT_DEFAULT) + + LANG_SYSTEM_DEFAULT = MAKELANGID(LANG_NEUTRAL,SUBLANG_SYS_DEFAULT); + SUBLANG_SYS_DEFAULT is not defined in PAL, here use hardcoding, + the value is from winnt.h + */ + DefaultLocale = MAKELCID(MAKELANGID(LANG_NEUTRAL, 0x02), SORT_DEFAULT); + + dwFlags = DATE_USE_ALT_CALENDAR; /*set the flags*/ + + + DateSize = 0; + + /*retrieve the buffer size*/ + DateSize = GetDateFormatW( + DefaultLocale, /*system default locale*/ + dwFlags, /*function option*/ + (SYSTEMTIME *)lpDate, /*always is NULL*/ + wpFormat, /*pointer to a picture string*/ + wpBuffer, /*out buffer*/ + DateSize); /*buffer size*/ + + if(DateSize <= 0) + { + free(wpFormat); + Fail("\nRetrieved an invalid buffer size\n"); + } + + + wpBuffer = malloc((DateSize+1)*sizeof(WCHAR)); + if(NULL == wpBuffer) + { + free(wpFormat); + Fail("\nFailed to allocate memory to store a formatted string\n"); + } + + /*retrieve the formatted string for a specified locale*/ + err = GetDateFormatW( + DefaultLocale, /*system default locale*/ + dwFlags, /*function option*/ + (SYSTEMTIME *)lpDate, /*always is NULL*/ + wpFormat, /*pointer to a picture string*/ + wpBuffer, /*out buffer*/ + DateSize); /*buffer size*/ + + if(0 == err) + { + free(wpBuffer); + free(wpFormat); + Fail("\nFailed to call GetDateFormatW to format a system data " + "as a data string for system default locale!\n"); + } + + free(wpBuffer); + free(wpFormat); + + PAL_Terminate(); + return PASS; +} |