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/file_io/GetTempFileNameW | |
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/file_io/GetTempFileNameW')
10 files changed, 480 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameW/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetTempFileNameW/CMakeLists.txt new file mode 100644 index 0000000000..1962ade358 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetTempFileNameW/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) +add_subdirectory(test2) +add_subdirectory(test3) + diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameW/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test1/CMakeLists.txt new file mode 100644 index 0000000000..1b6c599da4 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + GetTempFileNameW.c +) + +add_executable(paltest_gettempfilenamew_test1 + ${SOURCES} +) + +add_dependencies(paltest_gettempfilenamew_test1 coreclrpal) + +target_link_libraries(paltest_gettempfilenamew_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameW/test1/GetTempFileNameW.c b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test1/GetTempFileNameW.c new file mode 100644 index 0000000000..43cda8f447 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test1/GetTempFileNameW.c @@ -0,0 +1,129 @@ +// 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: GetTempFileNameW.c (test 1) +** +** Purpose: Tests the PAL implementation of the GetTempFileNameW function. +** +** +**===================================================================*/ + +#include <palsuite.h> + + + +int __cdecl main(int argc, char *argv[]) +{ + UINT uiError = 0; + const UINT uUnique = 0; + WCHAR* wPrefix = NULL; + WCHAR* wPath = NULL; + WCHAR wReturnedName[256]; + WCHAR wTempString[256]; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + + // valid path with null ext + wPath = convert("."); + uiError = GetTempFileNameW(wPath, wPrefix, uUnique, wReturnedName); + free (wPath); + if (uiError == 0) + { + Fail("GetTempFileNameW: ERROR -> Call failed with a valid path " + "with the error code: %ld\n", GetLastError()); + } + else + { + // verify temp file was created + if (GetFileAttributesW(wReturnedName) == -1) + { + Fail("GetTempFileNameW: ERROR -> GetFileAttributes failed on the " + "returned temp file with error code: %ld.\n", GetLastError()); + } + if (DeleteFileW(wReturnedName) != TRUE) + { + Fail("GetTempFileNameW: ERROR -> DeleteFileW failed to delete" + "the created temp file with error code: %lld.\n", GetLastError()); + } + } + + + // valid path with valid prefix + wPath = convert("."); + wPrefix = convert("cfr"); + uiError = GetTempFileNameW(wPath, wPrefix, uUnique, wReturnedName); + free (wPath); + free (wPrefix); + if (uiError == 0) + { + Fail("GetTempFileNameW: ERROR -> Call failed with a valid path and " + "prefix with the error code: %ld\n", GetLastError()); + } + else + { + // verify temp file was created + if (GetFileAttributesW(wReturnedName) == -1) + { + Fail("GetTempFileNameW: ERROR -> GetFileAttributes failed on the " + "returned temp file with error code: %ld.\n", GetLastError()); + } + if (DeleteFileW(wReturnedName) != TRUE) + { + Fail("GetTempFileNameW: ERROR -> DeleteFileW failed to delete" + "the created temp file with error code: %lld.\n", GetLastError()); + } + } + + // valid path with long prefix + wPath = convert("."); + wPrefix = convert("cfrwxyz"); + uiError = GetTempFileNameW(wPath, wPrefix, uUnique, wReturnedName); + if (uiError == 0) + { + free (wPath); + free (wPrefix); + Fail("GetTempFileNameW: ERROR -> Call failed with a valid path and " + "prefix with the error code: %ld\n", GetLastError()); + } + else + { + // verify temp file was created + if (GetFileAttributesW(wReturnedName) == -1) + { + free (wPath); + free (wPrefix); + Fail("GetTempFileNameW: ERROR -> GetFileAttributes failed on the " + "returned temp file with error code: %ld.\n", GetLastError()); + } + + // now verify that it only used the first 3 characters of the prefix + swprintf(wTempString, convert("%s\\%s"), wPath, wPrefix); + if (memcmp(wTempString, wReturnedName, wcslen(wTempString)*sizeof(WCHAR)) == 0) + { + free (wPath); + free (wPrefix); + Fail("GetTempFileNameW: ERROR -> It appears that an improper prefix " + "was used.\n"); + } + + if (DeleteFileW(wReturnedName) != TRUE) + { + free (wPath); + free (wPrefix); + Fail("GetTempFileNameW: ERROR -> DeleteFileW failed to delete" + "the created temp file with error code: %lld.\n", GetLastError()); + } + } + + free (wPath); + free (wPrefix); + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameW/test1/testinfo.dat b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test1/testinfo.dat new file mode 100644 index 0000000000..72af6930d9 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test1/testinfo.dat @@ -0,0 +1,13 @@ +# 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. + +Version = 1.0 +Section = file_io +Function = GetTempFileNameW +Name = Test for GetTempFileNameW (test 1) +Type = DEFAULT +EXE1 = gettempfilenamew +Description += Test all the different options of GetTempFileNameW + diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameW/test2/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test2/CMakeLists.txt new file mode 100644 index 0000000000..851030d9ae --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test2/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + GetTempFileNameW.c +) + +add_executable(paltest_gettempfilenamew_test2 + ${SOURCES} +) + +add_dependencies(paltest_gettempfilenamew_test2 coreclrpal) + +target_link_libraries(paltest_gettempfilenamew_test2 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameW/test2/GetTempFileNameW.c b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test2/GetTempFileNameW.c new file mode 100644 index 0000000000..2c8b19e081 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test2/GetTempFileNameW.c @@ -0,0 +1,84 @@ +// 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: GetTempFileNameW.c (test 2) +** +** Purpose: Tests the PAL implementation of the GetTempFileNameW function. +** +** +**===================================================================*/ + +#include <palsuite.h> + + + +int __cdecl main(int argc, char *argv[]) +{ + UINT uiError = 0; + DWORD dwError = 0; + const UINT uUnique = 0; + WCHAR* wPrefix = NULL; + WCHAR* wPath = NULL; + WCHAR wReturnedName[256]; + DWORD i; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + + // test the number of temp files that can be created + wPrefix = convert("cfr"); + wPath = convert("."); + for (i = 0; i < 0x10005; i++) + { + uiError = GetTempFileNameW(wPath, wPrefix, uUnique, wReturnedName); + if (uiError == 0) + { + dwError = GetLastError(); + if (dwError == ERROR_FILE_EXISTS) + { + // file already existes so break out of the loop + i--; // decrement the count because it wasn't successful + break; + } + else + { + // it was something other than the file already existing? + free (wPath); + free (wPrefix); + Fail("GetTempFileNameW: ERROR -> Call failed with a valid " + "path and prefix with the error code: %ld\n", GetLastError()); + } + } + else + { + // verify temp file was created + if (GetFileAttributesW(wReturnedName) == -1) + { + free (wPath); + free (wPrefix); + Fail("GetTempFileNameW: ERROR -> GetFileAttributes failed " + "on the returned temp file with error code: %ld.\n", + GetLastError()); + } + } + } + + free (wPath); + free (wPrefix); + + // did it create more than 0xffff files + if (i > 0xffff) + { + Fail("GetTempFileNameW: ERROR -> Was able to create more than 0xffff" + " temp files.\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameW/test2/testinfo.dat b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test2/testinfo.dat new file mode 100644 index 0000000000..72500111ad --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test2/testinfo.dat @@ -0,0 +1,15 @@ +# 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. + +Version = 1.0 +Section = file_io +Function = GetTempFileNameW +Name = Test for GetTempFileNameW (test 2) +Type = DEFAULT +EXE1 = gettempfilenamew +Description += This test attempts to create over 65000 files and will += have to be run manually because it will take longer than += the maximum 60 seconds allowed per test + diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameW/test3/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test3/CMakeLists.txt new file mode 100644 index 0000000000..82dd0a9f3f --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test3/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + gettempfilenamew.c +) + +add_executable(paltest_gettempfilenamew_test3 + ${SOURCES} +) + +add_dependencies(paltest_gettempfilenamew_test3 coreclrpal) + +target_link_libraries(paltest_gettempfilenamew_test3 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameW/test3/gettempfilenamew.c b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test3/gettempfilenamew.c new file mode 100644 index 0000000000..96d8e66410 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test3/gettempfilenamew.c @@ -0,0 +1,161 @@ +// 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: GetTempFileNameW.c (test 3) +** +** Purpose: Tests the PAL implementation of the GetTempFileNameW function. +** Checks the file attributes and ensures that getting a file name, +** deleting the file and getting another doesn't produce the same +** as the just deleted file. Also checks the file size is 0. +** +** Depends on: +** GetFileAttributesW +** DeleteFileW +** CreateFileW +** GetFileSize +** CloseHandle +** +** +**===================================================================*/ + +#include <palsuite.h> + + + +int __cdecl main(int argc, char *argv[]) +{ + const UINT uUnique = 0; + UINT uiError; + WCHAR szwReturnedName[MAX_LONGPATH]; + WCHAR szwReturnedName_02[MAX_LONGPATH]; + DWORD dwFileSize = 0; + HANDLE hFile; + const WCHAR szwDot[] = {'.','\0'}; + const WCHAR szwPre[] = {'c','\0'}; + + if (0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + + /* valid path with null prefix */ + uiError = GetTempFileNameW(szwDot, szwPre, uUnique, szwReturnedName); + if (uiError == 0) + { + Fail("GetTempFileNameW: ERROR -> Call failed with a valid path " + "with the error code: %u.\n", + GetLastError()); + } + + /* verify temp file was created */ + if (GetFileAttributesW(szwReturnedName) == -1) + { + Fail("GetTempFileNameW: ERROR -> GetFileAttributes failed on the " + "returned temp file \"%S\" with error code: %u.\n", + szwReturnedName, + GetLastError()); + } + + /* + ** verify that the file size is 0 bytes + */ + + hFile = CreateFileW(szwReturnedName, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); + if (hFile == INVALID_HANDLE_VALUE) + { + Trace("GetTempFileNameW: ERROR -> CreateFileW failed to open" + " the created temp file with error code: %u.\n", + GetLastError()); + if (!DeleteFileW(szwReturnedName)) + { + Trace("GetTempFileNameW: ERROR -> DeleteFileW failed to delete" + " the created temp file with error code: %u.\n", + GetLastError()); + } + Fail(""); + } + + if ((dwFileSize = GetFileSize(hFile, NULL)) != (DWORD)0) + { + Trace("GetTempFileNameW: ERROR -> GetFileSize returned %u whereas" + "it should have returned 0.\n", + dwFileSize); + if (!CloseHandle(hFile)) + { + Trace("GetTempFileNameW: ERROR -> CloseHandle was unable to close the " + "opened file. GetLastError returned %u.\n", + GetLastError()); + } + if (!DeleteFileW(szwReturnedName)) + { + Trace("GetTempFileNameW: ERROR -> DeleteFileW failed to delete" + " the created temp file with error code: %u.\n", + GetLastError()); + } + Fail(""); + } + + if (!CloseHandle(hFile)) + { + Fail("GetTempFileNameW: ERROR -> CloseHandle was unable to close the " + "opened file. GetLastError returned %u.\n", + GetLastError()); + } + + + /* delete the file to see if we get the same name next time around */ + if (DeleteFileW(szwReturnedName) != TRUE) + { + Fail("GetTempFileNameW: ERROR -> DeleteFileW failed to delete" + " the created temp file with error code: %u.\n", + GetLastError()); + } + + /* get another and make sure it's not the same as the last */ + uiError = GetTempFileNameW(szwDot, szwPre, uUnique, szwReturnedName_02); + if (uiError == 0) + { + Fail("GetTempFileNameW: ERROR -> Call failed with a valid path " + "with the error code: %u.\n", + GetLastError()); + } + + /* did we get different names? */ + if (wcsncmp(szwReturnedName, szwReturnedName_02, wcslen(szwReturnedName)) == 0) + { + Fail("GetTempFileNameW: ERROR -> The first call returned \"%S\". " + "The second call returned \"%S\" and the two should not be" + " the same.\n", + szwReturnedName, + szwReturnedName_02); + if (!DeleteFileW(szwReturnedName_02)) + { + Trace("GetTempFileNameW: ERROR -> DeleteFileW failed to delete" + " the created temp file with error code: %u.\n", + GetLastError()); + } + Fail(""); + } + + /* clean up */ + if (!DeleteFileW(szwReturnedName_02)) + { + Fail("GetTempFileNameW: ERROR -> DeleteFileW failed to delete" + " the created temp file with error code: %u.\n", + GetLastError()); + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameW/test3/testinfo.dat b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test3/testinfo.dat new file mode 100644 index 0000000000..dd482dbde5 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetTempFileNameW/test3/testinfo.dat @@ -0,0 +1,15 @@ +# 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. + +Version = 1.0 +Section = file_io +Function = GetTempFileNameW +Name = Test for GetTempFileNameW (test 3) +Type = DEFAULT +EXE1 = gettempfilenamew +Description += Tests the PAL implementation of the GetTempFileNameW function. += Checks the file attributes and ensures that getting a file name, += deleting the file and getting another doesn't produce the same += as the just deleted file. Also checks the file size is 0. |