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/SetEndOfFile/test4 | |
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/SetEndOfFile/test4')
3 files changed, 172 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/file_io/SetEndOfFile/test4/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetEndOfFile/test4/CMakeLists.txt new file mode 100644 index 0000000000..ff0b6f999c --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetEndOfFile/test4/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + setendoffile.c +) + +add_executable(paltest_setendoffile_test4 + ${SOURCES} +) + +add_dependencies(paltest_setendoffile_test4 coreclrpal) + +target_link_libraries(paltest_setendoffile_test4 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/file_io/SetEndOfFile/test4/setendoffile.c b/src/pal/tests/palsuite/file_io/SetEndOfFile/test4/setendoffile.c new file mode 100644 index 0000000000..98a6ec63da --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetEndOfFile/test4/setendoffile.c @@ -0,0 +1,138 @@ +// 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: setendoffile.c (test 4) +** +** Purpose: Tests the PAL implementation of the SetEndOfFile function. +** Verify that the file pointer is the same before +** and after a SetEndOfFile using SetFilePointer with +** FILE_BEGIN, FILE_CURRENT and FILE_END +** +** +**===================================================================*/ + +#include <palsuite.h> + + +const char* szStringTest = "The quick fox jumped over the lazy dog's back."; +const char* szTextFile = "test.tmp"; + +static void Cleanup(HANDLE hFile) +{ + if (!CloseHandle(hFile)) + { + Trace("SetEndOfFile: ERROR -> Unable to close file \"%s\". ", + "GetLastError returned %u.\n", + szTextFile, + GetLastError()); + } + if (!DeleteFileA(szTextFile)) + { + Trace("SetEndOfFile: ERROR -> Unable to delete file \"%s\". ", + "GetLastError returned %u.\n", + szTextFile, + GetLastError()); + } +} + +static void DoTest(HANDLE hFile, DWORD dwOffset, DWORD dwMethod) +{ + DWORD dwFP1 = 0; + DWORD dwFP2 = 0; + DWORD dwError; + + /* set the pointer*/ + dwFP1 = SetFilePointer(hFile, dwOffset, NULL, dwMethod); + if ((dwFP1 == INVALID_SET_FILE_POINTER) && + ((dwError = GetLastError()) != ERROR_SUCCESS)) + { + Trace("SetEndOfFile: ERROR -> Unable to set the pointer to the " + "end of the file. GetLastError returned %u.\n", + dwError); + Cleanup(hFile); + Fail(""); + } + + /* set EOF */ + if (!SetEndOfFile(hFile)) + { + Trace("SetEndOfFile: ERROR -> Unable to set end of file. " + "GetLastError returned %u.\n", + GetLastError()); + Cleanup(hFile); + Fail(""); + } + + /* get current file pointer pointer */ + dwFP2 = SetFilePointer(hFile, 0, NULL, FILE_CURRENT); + if ((dwFP1 == INVALID_SET_FILE_POINTER) && + ((dwError = GetLastError()) != ERROR_SUCCESS)) + { + Trace("SetEndOfFile: ERROR -> Unable to set the pointer to the " + "end of the file. GetLastError returned %u.\n", + dwError); + Cleanup(hFile); + Fail(""); + } + + /* are they the same? */ + if (dwFP1 != dwFP2) + { + Trace("SetEndOfFile: ERROR -> File pointer before (%u) the " + "SetEndOfFile call was different than after (%u).\n", + dwFP1, + dwFP2); + Cleanup(hFile); + Fail(""); + } +} + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE hFile = NULL; + DWORD dwBytesWritten; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* create a test file */ + hFile = CreateFile(szTextFile, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + Fail("SetEndOfFile: ERROR -> Unable to create file \"%s\". " + "GetLastError returned %u.\n", + szTextFile, + GetLastError()); + } + + if (!WriteFile(hFile, szStringTest, strlen(szStringTest), &dwBytesWritten, NULL)) + { + Trace("SetEndOfFile: ERROR -> Unable to write to \"%s\". ", + "GetLastError returned %u.\n", + szTextFile, + GetLastError()); + Cleanup(hFile); + Fail(""); + } + + DoTest(hFile, -2, FILE_END); /* test the end */ + DoTest(hFile, -10, FILE_CURRENT); /* test the middle-ish */ + DoTest(hFile, 0, FILE_BEGIN); /* test the start */ + + Cleanup(hFile); + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/SetEndOfFile/test4/testinfo.dat b/src/pal/tests/palsuite/file_io/SetEndOfFile/test4/testinfo.dat new file mode 100644 index 0000000000..51d9185343 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetEndOfFile/test4/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 = SetEndOfFile +Name = Positive Test for SetEndOfFile (test 4) +Type = DEFAULT +EXE1 = setendoffile +Description += Tests the PAL implementation of the SetEndOfFile function. += Verify that the file pointer is the same before += and after a SetEndOfFile using SetFilePointer with += FILE_BEGIN, FILE_CURRENT and FILE_END |