| 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: GetStdHandle.c (test 2) |
| 8 | ** |
| 9 | ** Purpose: Smoke Tests the PAL implementation of the GetStdHandle function. |
| 10 | ** |
| 11 | ** |
| 12 | **===================================================================*/ |
| 13 | |
| 14 | #include <palsuite.h> |
| 15 | |
| 16 | |
| 17 | int __cdecl main(int argc, char *argv[]) |
| 18 | { |
| 19 | HANDLE hFile = NULL; |
| 20 | |
| 21 | if (0 != PAL_Initialize(argc,argv)) |
| 22 | { |
| 23 | return FAIL; |
| 24 | } |
| 25 | |
| 26 | /* |
| 27 | * attempt to get an invalid handle |
| 28 | */ |
| 29 | hFile = GetStdHandle(-2); |
| 30 | if (hFile != INVALID_HANDLE_VALUE) |
| 31 | { |
| 32 | Fail("GetStdHandle: ERROR -> A request for the STD_INPUT_HANDLE " |
| 33 | "returned an invalid handle.\n" ); |
| 34 | } |
| 35 | |
| 36 | |
| 37 | /* |
| 38 | * test the STD_INPUT_HANDLE handle |
| 39 | */ |
| 40 | hFile = GetStdHandle(STD_INPUT_HANDLE); |
| 41 | if (hFile == INVALID_HANDLE_VALUE) |
| 42 | { |
| 43 | Fail("GetStdHandle: ERROR -> A request for the STD_INPUT_HANDLE " |
| 44 | "returned an invalid handle.\n" ); |
| 45 | } |
| 46 | |
| 47 | |
| 48 | /* |
| 49 | * test the STD_OUTPUT_HANDLE handle |
| 50 | */ |
| 51 | hFile = GetStdHandle(STD_OUTPUT_HANDLE); |
| 52 | if (hFile == INVALID_HANDLE_VALUE) |
| 53 | { |
| 54 | Fail("GetStdHandle: ERROR -> A request for the STD_OUTPUT_HANDLE " |
| 55 | "returned an invalid handle.\n" ); |
| 56 | } |
| 57 | |
| 58 | /* test the STD_ERROR_HANDLE handle */ |
| 59 | hFile = GetStdHandle(STD_ERROR_HANDLE); |
| 60 | if (hFile == INVALID_HANDLE_VALUE) |
| 61 | { |
| 62 | Fail("GetStdHandle: ERROR -> A request for the STD_ERROR_HANDLE " |
| 63 | "returned an invalid handle.\n" ); |
| 64 | } |
| 65 | |
| 66 | |
| 67 | /* check to see if we can CloseHandle works on the STD_ERROR_HANDLE */ |
| 68 | if (!CloseHandle(hFile)) |
| 69 | { |
| 70 | Fail("GetStdHandle: ERROR -> CloseHandle failed. GetLastError " |
| 71 | "returned %u.\n" , |
| 72 | GetLastError()); |
| 73 | } |
| 74 | |
| 75 | |
| 76 | PAL_Terminate(); |
| 77 | return PASS; |
| 78 | } |
| 79 | |
| 80 | |