diff options
Diffstat (limited to 'src/pal/tests/palsuite/file_io/SetEndOfFile/test1')
3 files changed, 117 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/file_io/SetEndOfFile/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetEndOfFile/test1/CMakeLists.txt new file mode 100644 index 0000000000..e77ab30b86 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetEndOfFile/test1/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_test1 + ${SOURCES} +) + +add_dependencies(paltest_setendoffile_test1 coreclrpal) + +target_link_libraries(paltest_setendoffile_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/file_io/SetEndOfFile/test1/SetEndOfFile.c b/src/pal/tests/palsuite/file_io/SetEndOfFile/test1/SetEndOfFile.c new file mode 100644 index 0000000000..9078ddc65b --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetEndOfFile/test1/SetEndOfFile.c @@ -0,0 +1,85 @@ +// 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 1) +** +** Purpose: Tests the PAL implementation of the SetEndOfFile function. +** This test will attempt to operate on a NULL file handle and +** also test truncating a file not opened with GENERIC_WRITE +** +** Assumes successful: +** SetEndOfFile +** CreateFile +** CloseHandle +** + +** +**===================================================================*/ + +#include <palsuite.h> + +const char* szTextFile = "text.txt"; + + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE hFile = NULL; + BOOL bRc = FALSE; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + bRc = SetEndOfFile(NULL); + if (bRc == TRUE) + { + Fail("SetEndOfFile: ERROR -> Operation succeeded on a NULL file " + "handle\n"); + } + + /* create a test file */ + hFile = CreateFile(szTextFile, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(hFile == INVALID_HANDLE_VALUE) + { + Fail("SetEndOfFile: ERROR -> Unable to create file \"%s\".\n", + szTextFile); + } + + bRc = SetEndOfFile(hFile); + if (bRc == TRUE) + { + Trace("SetEndOfFile: ERROR -> Operation succeeded on read-only" + " file.\n"); + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Trace("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + PAL_TerminateEx(FAIL); + return FAIL; + } + + bRc = CloseHandle(hFile); + if (bRc != TRUE) + { + Fail("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n", + szTextFile); + } + + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/SetEndOfFile/test1/testinfo.dat b/src/pal/tests/palsuite/file_io/SetEndOfFile/test1/testinfo.dat new file mode 100644 index 0000000000..72fc5e59e6 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SetEndOfFile/test1/testinfo.dat @@ -0,0 +1,13 @@ +# 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 +Type = DEFAULT +EXE1 = setendoffile +Description +=Truncate a file + |