| 1 | // Licensed to the .NET Foundation under one or more agreements. |
| 2 | // The .NET Foundation licenses this file to you under the MIT license. |
| 3 | // See the LICENSE file in the project root for more information. |
| 4 | |
| 5 | /*===================================================================== |
| 6 | ** |
| 7 | ** Source: SetEndOfFile.c (test 1) |
| 8 | ** |
| 9 | ** Purpose: Tests the PAL implementation of the SetEndOfFile function. |
| 10 | ** This test will attempt to operate on a NULL file handle and |
| 11 | ** also test truncating a file not opened with GENERIC_WRITE |
| 12 | ** |
| 13 | ** Assumes successful: |
| 14 | ** SetEndOfFile |
| 15 | ** CreateFile |
| 16 | ** CloseHandle |
| 17 | ** |
| 18 | |
| 19 | ** |
| 20 | **===================================================================*/ |
| 21 | |
| 22 | #include <palsuite.h> |
| 23 | |
| 24 | const char* szTextFile = "text.txt" ; |
| 25 | |
| 26 | |
| 27 | int __cdecl main(int argc, char *argv[]) |
| 28 | { |
| 29 | HANDLE hFile = NULL; |
| 30 | BOOL bRc = FALSE; |
| 31 | |
| 32 | |
| 33 | if (0 != PAL_Initialize(argc,argv)) |
| 34 | { |
| 35 | return FAIL; |
| 36 | } |
| 37 | |
| 38 | bRc = SetEndOfFile(NULL); |
| 39 | if (bRc == TRUE) |
| 40 | { |
| 41 | Fail("SetEndOfFile: ERROR -> Operation succeeded on a NULL file " |
| 42 | "handle\n" ); |
| 43 | } |
| 44 | |
| 45 | /* create a test file */ |
| 46 | hFile = CreateFile(szTextFile, |
| 47 | GENERIC_READ, |
| 48 | FILE_SHARE_READ, |
| 49 | NULL, |
| 50 | OPEN_ALWAYS, |
| 51 | FILE_ATTRIBUTE_NORMAL, |
| 52 | NULL); |
| 53 | |
| 54 | if(hFile == INVALID_HANDLE_VALUE) |
| 55 | { |
| 56 | Fail("SetEndOfFile: ERROR -> Unable to create file \"%s\".\n" , |
| 57 | szTextFile); |
| 58 | } |
| 59 | |
| 60 | bRc = SetEndOfFile(hFile); |
| 61 | if (bRc == TRUE) |
| 62 | { |
| 63 | Trace("SetEndOfFile: ERROR -> Operation succeeded on read-only" |
| 64 | " file.\n" ); |
| 65 | bRc = CloseHandle(hFile); |
| 66 | if (bRc != TRUE) |
| 67 | { |
| 68 | Trace("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n" , |
| 69 | szTextFile); |
| 70 | } |
| 71 | PAL_TerminateEx(FAIL); |
| 72 | return FAIL; |
| 73 | } |
| 74 | |
| 75 | bRc = CloseHandle(hFile); |
| 76 | if (bRc != TRUE) |
| 77 | { |
| 78 | Fail("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n" , |
| 79 | szTextFile); |
| 80 | } |
| 81 | |
| 82 | |
| 83 | PAL_Terminate(); |
| 84 | return PASS; |
| 85 | } |
| 86 | |