summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/file_io/SetFilePointer/test1/SetFilePointer.cpp
diff options
context:
space:
mode:
authorJiyoung Yun <jy910.yun@samsung.com>2016-12-27 16:46:08 +0900
committerJiyoung Yun <jy910.yun@samsung.com>2016-12-27 16:46:08 +0900
commitdb20f3f1bb8595633a7e16c8900fd401a453a6b5 (patch)
treee5435159cd1bf0519276363a6fe1663d1721bed3 /src/pal/tests/palsuite/file_io/SetFilePointer/test1/SetFilePointer.cpp
parent4b4aad7217d3292650e77eec2cf4c198ea9c3b4b (diff)
downloadcoreclr-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/SetFilePointer/test1/SetFilePointer.cpp')
-rw-r--r--src/pal/tests/palsuite/file_io/SetFilePointer/test1/SetFilePointer.cpp123
1 files changed, 123 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/file_io/SetFilePointer/test1/SetFilePointer.cpp b/src/pal/tests/palsuite/file_io/SetFilePointer/test1/SetFilePointer.cpp
new file mode 100644
index 0000000000..14b5f85e69
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/SetFilePointer/test1/SetFilePointer.cpp
@@ -0,0 +1,123 @@
+// 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: SetFilePointer.c (test 1)
+**
+** Purpose: Tests the PAL implementation of the SetFilePointer function.
+** Set the file pointer using a NULL handle and other invalid
+** options.
+**
+**
+**===================================================================*/
+
+#include <palsuite.h>
+
+
+const char* szTextFile = "text.txt";
+
+
+int __cdecl main(int argc, char *argv[])
+{
+ HANDLE hFile = NULL;
+ DWORD dwByteCount = 0;
+ DWORD dwOffset = 25;
+ DWORD dwRc = 0;
+ BOOL bRc = FALSE;
+ char buffer[100];
+
+
+ if (0 != PAL_Initialize(argc,argv))
+ {
+ return FAIL;
+ }
+
+ /* set the file pointer on a NULL file handle */
+ dwRc = SetFilePointer(NULL, dwOffset, NULL, FILE_BEGIN);
+ if (dwRc != INVALID_SET_FILE_POINTER)
+ {
+ Fail("SetFilePointer: ERROR -> Call to SetFilePointer succeeded "
+ "with a NULL pointer\n");
+ }
+
+
+ /* create a test file without proper permission */
+ hFile = CreateFile(szTextFile,
+ 0,
+ 0,
+ NULL,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if(hFile == INVALID_HANDLE_VALUE)
+ {
+ Fail("SetFilePointer: ERROR -> Unable to create file \"%s\".\n",
+ szTextFile);
+ }
+
+ /* ReadFile fails as expected */
+ bRc = ReadFile(hFile, buffer, 1, &dwByteCount, NULL);
+ if (bRc != FALSE)
+ {
+ Trace("SetFilePointer: ERROR -> ReadFile was successful when it was "
+ "expected to fail\n");
+ if (!CloseHandle(hFile))
+ {
+ Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n",
+ szTextFile);
+ }
+ if (!DeleteFileA(szTextFile))
+ {
+ Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n",
+ szTextFile);
+ }
+ PAL_TerminateEx(FAIL);
+ return FAIL;
+ }
+
+ /* move the file pointer before the beginning of the file */
+ dwRc = SetFilePointer(hFile, -1, NULL, FILE_BEGIN);
+ if (dwRc != INVALID_SET_FILE_POINTER)
+ {
+ Trace("SetFilePointer: ERROR -> Was able to move the pointer before "
+ "the beginning of the file.\n");
+ bRc = CloseHandle(hFile);
+ if (bRc != TRUE)
+ {
+ Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n",
+ szTextFile);
+ }
+ if (!DeleteFileA(szTextFile))
+ {
+ Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n",
+ szTextFile);
+ }
+ PAL_TerminateEx(FAIL);
+ return FAIL;
+ }
+
+ bRc = CloseHandle(hFile);
+ if (bRc != TRUE)
+ {
+ Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n",
+ szTextFile);
+ if (!DeleteFileA(szTextFile))
+ {
+ Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n",
+ szTextFile);
+ }
+ PAL_TerminateEx(FAIL);
+ return FAIL;
+ }
+
+ if (!DeleteFileA(szTextFile))
+ {
+ Fail("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n",
+ szTextFile);
+ }
+ PAL_Terminate();
+ return PASS;
+}