summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/file_io/GetFullPathNameW/test2/test2.cpp
diff options
context:
space:
mode:
authorJiyoung Yun <jy910.yun@samsung.com>2016-12-27 07:46:08 (GMT)
committerJiyoung Yun <jy910.yun@samsung.com>2016-12-27 07:46:08 (GMT)
commitdb20f3f1bb8595633a7e16c8900fd401a453a6b5 (patch)
treee5435159cd1bf0519276363a6fe1663d1721bed3 /src/pal/tests/palsuite/file_io/GetFullPathNameW/test2/test2.cpp
parent4b4aad7217d3292650e77eec2cf4c198ea9c3b4b (diff)
downloadcoreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.zip
coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.tar.gz
coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.tar.bz2
Imported Upstream version 1.0.0.9127upstream/1.0.0.9127
Diffstat (limited to 'src/pal/tests/palsuite/file_io/GetFullPathNameW/test2/test2.cpp')
-rw-r--r--src/pal/tests/palsuite/file_io/GetFullPathNameW/test2/test2.cpp159
1 files changed, 159 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/file_io/GetFullPathNameW/test2/test2.cpp b/src/pal/tests/palsuite/file_io/GetFullPathNameW/test2/test2.cpp
new file mode 100644
index 0000000..fae042d
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/GetFullPathNameW/test2/test2.cpp
@@ -0,0 +1,159 @@
+// 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: test2.c
+**
+** Purpose: Tests the PAL implementation of the GetFullPathNameW function.
+** Get the full path for a file name and verify the results.
+** This test will use a relative path, containing '..\'. To
+** add to this test, we will also call SetCurrentDirectory to
+** ensure this is handled properly.
+**
+**
+**===================================================================*/
+
+#include <palsuite.h>
+
+WCHAR szwDotDot[] = {'.','.','\\','\0'};
+WCHAR szwFileName[] = {'t','e','s','t','i','n','g','.','t','m','p','\0'};
+
+int __cdecl main(int argc, char *argv[])
+{
+ DWORD dwRc = 0;
+ WCHAR szwReturnedPath[_MAX_DIR+1];
+ WCHAR szwFullFileName[_MAX_DIR+1];
+ char *szReturnedPath;
+ char *szFileName;
+ LPWSTR pPathPtr;
+ HANDLE hFile = NULL;
+
+ if (0 != PAL_Initialize(argc,argv))
+ {
+ return FAIL;
+ }
+
+ /* change the directory */
+ if (!SetCurrentDirectoryW(szwDotDot))
+ {
+ Fail("ERROR: SetCurrentDirectoryW failed with error code %u"
+ " when passed \"%S\".\n",
+ GetLastError(),
+ szwDotDot);
+ }
+
+ /* Initialize the receiving char buffers.
+ */
+ memset(szwReturnedPath, 0, _MAX_DIR+1);
+ memset(szwFullFileName, 0, _MAX_DIR+1);
+
+ /* Create Full filename to pass, will include '..\'
+ * as a pre-fix. */
+ wcscat(szwFullFileName, szwDotDot);
+ wcscat(szwFullFileName, szwFileName);
+
+ /* Convert wide char strings to multibyte, to us
+ * incase of error messages.*/
+ szFileName = convertC(szwFileName);
+
+ /* Get the full path to the filename.
+ */
+ dwRc = GetFullPathNameW(szwFullFileName,
+ _MAX_DIR,
+ szwReturnedPath,
+ &pPathPtr);
+
+ szReturnedPath = convertC(szwReturnedPath);
+
+ if (dwRc == 0)
+ {
+ Trace("ERROR :%ld: Failed to get path to \"%s\".\n",
+ GetLastError(),
+ szReturnedPath);
+ free(szReturnedPath);
+ free(szFileName);
+ Fail("");
+ }
+
+ /*
+ * The returned value should be the parent directory with the
+ * file name appended.
+ */
+ hFile = CreateFileW(szwReturnedPath,
+ GENERIC_READ,
+ FILE_SHARE_READ,
+ NULL,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+ if (hFile == INVALID_HANDLE_VALUE)
+ {
+ Trace("ERROR :%ld: CreateFileW failed to create file \"%s\".\n",
+ GetLastError(),
+ szReturnedPath);
+ free(szFileName);
+ free(szReturnedPath);
+ Fail("");
+ }
+
+ /* Close the handle to the create file.*/
+ if (CloseHandle(hFile) != TRUE)
+ {
+ Trace("ERROR :%ld: Failed to close handle hFile=0x%lx.\n",
+ GetLastError(),
+ hFile);
+ goto terminate;
+ }
+
+ /* Verify that the file was created, attempt to create
+ * the file again. */
+ hFile = CreateFileW(szwReturnedPath,
+ GENERIC_READ,
+ FILE_SHARE_READ,
+ NULL,
+ CREATE_NEW,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+ if ((hFile != INVALID_HANDLE_VALUE) &&
+ (GetLastError() != ERROR_ALREADY_EXISTS))
+ {
+ Trace("ERROR :%ld: CreateFileW succeeded to create file "
+ "\"%s\", that already existed.\n",
+ GetLastError(),
+ szReturnedPath);
+ goto terminate;
+ }
+
+ /* Verify that the returned filename is the same as the supplied.
+ */
+ if (wcsncmp(pPathPtr, szwFileName, wcslen(szwFileName)) != 0)
+ {
+ Trace("ERROR : Returned filename is not equal to \"%s\".\n",
+ szFileName);
+ goto terminate;
+ }
+
+terminate:
+ /* Delete the create file.
+ */
+ if (DeleteFileW(szwFullFileName) != TRUE)
+ {
+ Trace("ERROR :%ld: DeleteFileW failed to delete \"%s\".\n",
+ szFileName,
+ GetLastError());
+ free(szFileName);
+ free(szReturnedPath);
+ Fail("");
+ }
+
+ free(szFileName);
+ free(szReturnedPath);
+
+ /* Terminate the PAL.
+ */
+ PAL_Terminate();
+ return PASS;
+}
+