From db20f3f1bb8595633a7e16c8900fd401a453a6b5 Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Tue, 27 Dec 2016 16:46:08 +0900 Subject: Imported Upstream version 1.0.0.9127 --- .../file_io/SetEndOfFile/test4/CMakeLists.txt | 2 +- .../file_io/SetEndOfFile/test4/setendoffile.c | 138 --------------------- .../file_io/SetEndOfFile/test4/setendoffile.cpp | 138 +++++++++++++++++++++ 3 files changed, 139 insertions(+), 139 deletions(-) delete mode 100644 src/pal/tests/palsuite/file_io/SetEndOfFile/test4/setendoffile.c create mode 100644 src/pal/tests/palsuite/file_io/SetEndOfFile/test4/setendoffile.cpp (limited to 'src/pal/tests/palsuite/file_io/SetEndOfFile/test4') diff --git a/src/pal/tests/palsuite/file_io/SetEndOfFile/test4/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetEndOfFile/test4/CMakeLists.txt index ff0b6f999c..1dc4f68aef 100644 --- a/src/pal/tests/palsuite/file_io/SetEndOfFile/test4/CMakeLists.txt +++ b/src/pal/tests/palsuite/file_io/SetEndOfFile/test4/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - setendoffile.c + setendoffile.cpp ) add_executable(paltest_setendoffile_test4 diff --git a/src/pal/tests/palsuite/file_io/SetEndOfFile/test4/setendoffile.c b/src/pal/tests/palsuite/file_io/SetEndOfFile/test4/setendoffile.c deleted file mode 100644 index 98a6ec63da..0000000000 --- a/src/pal/tests/palsuite/file_io/SetEndOfFile/test4/setendoffile.c +++ /dev/null @@ -1,138 +0,0 @@ -// 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 - - -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/setendoffile.cpp b/src/pal/tests/palsuite/file_io/SetEndOfFile/test4/setendoffile.cpp new file mode 100644 index 0000000000..98a6ec63da --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetEndOfFile/test4/setendoffile.cpp @@ -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 + + +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; +} -- cgit v1.2.3