diff options
author | Jiyoung Yun <jy910.yun@samsung.com> | 2016-12-27 16:46:08 +0900 |
---|---|---|
committer | Jiyoung Yun <jy910.yun@samsung.com> | 2016-12-27 16:46:08 +0900 |
commit | db20f3f1bb8595633a7e16c8900fd401a453a6b5 (patch) | |
tree | e5435159cd1bf0519276363a6fe1663d1721bed3 /src/pal/tests/palsuite/file_io/GetFullPathNameA/test1/GetFullPathNameA.cpp | |
parent | 4b4aad7217d3292650e77eec2cf4c198ea9c3b4b (diff) | |
download | coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.tar.gz coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.tar.bz2 coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.zip |
Imported Upstream version 1.0.0.9127upstream/1.0.0.9127
Diffstat (limited to 'src/pal/tests/palsuite/file_io/GetFullPathNameA/test1/GetFullPathNameA.cpp')
-rw-r--r-- | src/pal/tests/palsuite/file_io/GetFullPathNameA/test1/GetFullPathNameA.cpp | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/file_io/GetFullPathNameA/test1/GetFullPathNameA.cpp b/src/pal/tests/palsuite/file_io/GetFullPathNameA/test1/GetFullPathNameA.cpp new file mode 100644 index 0000000000..de9a266f5a --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetFullPathNameA/test1/GetFullPathNameA.cpp @@ -0,0 +1,122 @@ +// 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: GetFullPathNameA.c (test 1) +** +** Purpose: Tests the PAL implementation of the GetFullPathNameA function. +** +** +**===================================================================*/ + +#include <palsuite.h> + +const char* szFileName = "testing.tmp"; + +int __cdecl main(int argc, char *argv[]) +{ + DWORD dwRc = 0; + char szReturnedPath[_MAX_DIR+1]; + char szShortBuff[2]; + LPSTR pPathPtr; + HANDLE hFile = NULL; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* perform a short buffer test */ + if (GetFullPathNameA(szFileName, 2, szShortBuff, &pPathPtr) <= 2) + { + /* this test should have failed but didn't */ + Fail("GetFullPathNameA: ERROR -> The API was passed a buffer that was" + " too small for the path name and yet it apparently passed.\n"); + } + + memset(szReturnedPath, 0, _MAX_DIR+1); + dwRc = GetFullPathNameA(szFileName, + _MAX_DIR, + szReturnedPath, + &pPathPtr); + + if (dwRc == 0) + { + // this test should have passed but didn't + Fail("GetFullPathNameA: ERROR -> Function failed for the " + "file \"%s\" with error code: %ld.\n", szFileName, GetLastError()); + } + + // the returned value should be the current directory with the + // file name appended + hFile = CreateFileA(szFileName, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + if (hFile == INVALID_HANDLE_VALUE) + { + Fail("GetFullPathNameA: ERROR -> CreateFileA failed to create " + "file \"%s\" with error code: %ld.\n", + szFileName, + GetLastError()); + } + if (CloseHandle(hFile) != TRUE) + { + Fail("GetFullPathNameA: ERROR -> CloseHandle failed with error " + "code: %ld.\n", GetLastError()); + } + + // now try to create the file based on the returned value with the + // CREATE_NEW option which should fail since the file should + // already exist + hFile = CreateFileA(szReturnedPath, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + CREATE_NEW, + FILE_ATTRIBUTE_NORMAL, + NULL); + if (hFile != INVALID_HANDLE_VALUE) + { + Fail("GetFullPathNameA: ERROR -> CreateFileA was able to " + "CREATE_NEW the returned file \"%s\". The returned file " + "name is therefore apparently wrong.\n", + szReturnedPath); + if (CloseHandle(hFile) != TRUE) + { + Fail("GetFullPathNameA: ERROR -> CloseHandle failed with " + "error code: %ld.\n", GetLastError()); + } + if ((DeleteFileA(szReturnedPath) != TRUE) || + (DeleteFileA(szFileName) != TRUE)) + { + Fail("GetFullPathNameA: ERROR -> DeleteFileA failed to " + "delete the test files with error code: %ld.\n", + GetLastError()); + } + } + + // now make sure the pPathPtr is the same as the file name + if (strcmp(pPathPtr, szFileName) != 0) + { + Fail("GetFullPathNameA: ERROR -> %s != %s\n", + pPathPtr, szFileName); + } + if (DeleteFileA(szFileName) != TRUE) + { + Fail("GetFullPathNameA: ERROR -> DeleteFileA failed to " + "delete \"%s\" with error code: %ld.\n", + szFileName, + GetLastError()); + } + + PAL_Terminate(); + return PASS; +} + |