From 4b4aad7217d3292650e77eec2cf4c198ea9c3b4b Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Wed, 23 Nov 2016 19:09:09 +0900 Subject: Imported Upstream version 1.1.0 --- .../file_io/SetFilePointer/test1/SetFilePointer.c | 123 +++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 src/pal/tests/palsuite/file_io/SetFilePointer/test1/SetFilePointer.c (limited to 'src/pal/tests/palsuite/file_io/SetFilePointer/test1/SetFilePointer.c') diff --git a/src/pal/tests/palsuite/file_io/SetFilePointer/test1/SetFilePointer.c b/src/pal/tests/palsuite/file_io/SetFilePointer/test1/SetFilePointer.c new file mode 100644 index 0000000000..14b5f85e69 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetFilePointer/test1/SetFilePointer.c @@ -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 + + +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; +} -- cgit v1.2.3