diff options
Diffstat (limited to 'src/pal/tests/palsuite/miscellaneous/GetDateFormatW')
10 files changed, 372 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/CMakeLists.txt new file mode 100644 index 0000000000..80b6a0d41d --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(GetDateFormatW_neg1) +add_subdirectory(GetDateFormatW_neg2) +add_subdirectory(test1) + diff --git a/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg1/CMakeLists.txt new file mode 100644 index 0000000000..5a340c6cfb --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + GetDateFormatW_neg.c +) + +add_executable(paltest_getdateformatw_getdateformatw_neg1 + ${SOURCES} +) + +add_dependencies(paltest_getdateformatw_getdateformatw_neg1 coreclrpal) + +target_link_libraries(paltest_getdateformatw_getdateformatw_neg1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg1/GetDateFormatW_neg.c b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg1/GetDateFormatW_neg.c new file mode 100644 index 0000000000..c64dc74cb6 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg1/GetDateFormatW_neg.c @@ -0,0 +1,85 @@ +// 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_neg.c +** +** Purpose: Negative test the GetDateFormatW API. +** Call GetDateFormatW by passing an invalid parameter +** +** +**============================================================*/ +#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); + + 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 the formatted string\n"); + } + + /*format a date by passing an invalid locale indentifier*/ + err = GetDateFormatW( + -1, /*invalid locale identifier*/ + dwFlags, /*function option*/ + (SYSTEMTIME *)lpDate, /*always is NULL, or use system date*/ + wpFormat, /*pointer to a picture string*/ + wpBuffer, /*out buffer*/ + DateSize); /*buffer size*/ + + free(wpBuffer); + free(wpFormat); + + if(0 != err || GetLastError() != ERROR_INVALID_PARAMETER) + { + Fail("\nFailed to call GetDateFormatW for a negative test by " + "passing an invalid parameter, error code=%d\n", GetLastError()); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg1/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg1/testinfo.dat new file mode 100644 index 0000000000..f02271650c --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg1/testinfo.dat @@ -0,0 +1,8 @@ +Version = 1.0 +Section = miscellaneous +Function = GetDateFormatW +Name = Negative test for GetDateFormatW by passing an invlid locale identifier +TYPE = DEFAULT +EXE1 = getdateformatw_neg +Description +=negative test GetDateFormatW by passing an invalid locale identifier diff --git a/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg2/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg2/CMakeLists.txt new file mode 100644 index 0000000000..646de9160b --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg2/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + GetDateFormatW_neg.c +) + +add_executable(paltest_getdateformatw_getdateformatw_neg2 + ${SOURCES} +) + +add_dependencies(paltest_getdateformatw_getdateformatw_neg2 coreclrpal) + +target_link_libraries(paltest_getdateformatw_getdateformatw_neg2 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg2/GetDateFormatW_neg.c b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg2/GetDateFormatW_neg.c new file mode 100644 index 0000000000..676038f03a --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg2/GetDateFormatW_neg.c @@ -0,0 +1,98 @@ +// 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_neg.c +** +** Purpose: Negative test the GetDateFormatW API. +** Call GetDateFormatW by passing an invalid flag +** +** +**============================================================*/ +#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 the formatted string\n"); + } + + err = GetDateFormatW( + DefaultLocale, /*system default locale*/ + 0x00000001|0x00000008,/*DATE_SHORTDATE|DATE_YEARMONTH */ + /*an invalid flag*/ + (SYSTEMTIME *)lpDate, /*always is NULL, or use system date*/ + wpFormat, /*pointer to a picture string*/ + wpBuffer, /*out buffer*/ + DateSize); /*buffer size*/ + + free(wpBuffer); + free(wpFormat); + + if(0 != err || GetLastError() != ERROR_INVALID_FLAGS) + { + Fail("\nFailed to call GetDateFormatW for a negative test by " + "passing an invalid flag, error code=%d\n", GetLastError()); + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg2/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg2/testinfo.dat new file mode 100644 index 0000000000..fe5bc9b06e --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/GetDateFormatW_neg2/testinfo.dat @@ -0,0 +1,9 @@ +Version = 1.0 +Section = miscellaneous +Function = GetDateFormatW +Name = Negative test for GetDateFormatW by passing an invalid flag +TYPE = DEFAULT +EXE1 = getdateformatw_neg +Description +=test for GetDateFormatW by passing an invalid flag which is not +=supported diff --git a/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/test1/CMakeLists.txt new file mode 100644 index 0000000000..8c1e4b024e --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + GetDateFormatW.c +) + +add_executable(paltest_getdateformatw_test1 + ${SOURCES} +) + +add_dependencies(paltest_getdateformatw_test1 coreclrpal) + +target_link_libraries(paltest_getdateformatw_test1 + pthread + m + coreclrpal +) 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; +} diff --git a/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/test1/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/test1/testinfo.dat new file mode 100644 index 0000000000..6ed9ee7cef --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/GetDateFormatW/test1/testinfo.dat @@ -0,0 +1,9 @@ +Version = 1.0 +Section = miscellaneous +Function = GetDateFormatW +Name = Positive test for GetDateFormatW to format a date as a date string +TYPE = DEFAULT +EXE1 = getdateformatw +Description +=test for GetDateFormatW to format a date as a date string +=for a specified locale |