| 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: test3.c |
| 8 | ** |
| 9 | ** Dependencies: PAL_Initialize |
| 10 | ** PAL_Terminate |
| 11 | ** CreateEvent |
| 12 | ** CloseHandle |
| 13 | ** |
| 14 | ** Purpose: |
| 15 | ** |
| 16 | ** Test to ensure proper operation of the ResetEvent() |
| 17 | ** API by calling it on an event handle that's been |
| 18 | ** closed. We expect it to return an appropriate error |
| 19 | ** result. |
| 20 | ** |
| 21 | ** |
| 22 | |
| 23 | ** |
| 24 | **===========================================================================*/ |
| 25 | #include <palsuite.h> |
| 26 | |
| 27 | |
| 28 | |
| 29 | int __cdecl main( int argc, char **argv ) |
| 30 | |
| 31 | { |
| 32 | /* local variables */ |
| 33 | HANDLE hEvent = NULL; |
| 34 | LPSECURITY_ATTRIBUTES lpEventAttributes = NULL; |
| 35 | BOOL bManualReset = TRUE; |
| 36 | BOOL bInitialState = FALSE; |
| 37 | |
| 38 | |
| 39 | /* PAL initialization */ |
| 40 | if( (PAL_Initialize(argc, argv)) != 0 ) |
| 41 | { |
| 42 | return( FAIL ); |
| 43 | } |
| 44 | |
| 45 | |
| 46 | /* create an event which we can use with ResetEvent */ |
| 47 | hEvent = CreateEvent( lpEventAttributes, |
| 48 | bManualReset, |
| 49 | bInitialState, |
| 50 | NULL ); |
| 51 | |
| 52 | if( hEvent == INVALID_HANDLE_VALUE ) |
| 53 | { |
| 54 | /* ERROR */ |
| 55 | Fail( "ERROR:%lu:CreateEvent() call failed\n" , GetLastError() ); |
| 56 | } |
| 57 | |
| 58 | /* close the event handle */ |
| 59 | if( ! CloseHandle( hEvent ) ) |
| 60 | { |
| 61 | Fail( "ERROR:%lu:CloseHandle() call failed\n" , GetLastError() ); |
| 62 | } |
| 63 | |
| 64 | /* try to reset the event */ |
| 65 | if( ResetEvent( hEvent ) ) |
| 66 | { |
| 67 | /* ERROR */ |
| 68 | Fail( "FAIL:ResetEvent() call succeeded on a closed event handle\n" ); |
| 69 | } |
| 70 | |
| 71 | /* verify the result of GetLastError() */ |
| 72 | if( GetLastError() != ERROR_INVALID_HANDLE ) |
| 73 | { |
| 74 | /* ERROR */ |
| 75 | Fail( "FAIL:ResetEvent() call failed on a closed event handle " |
| 76 | "but returned an unexpected error result %lu\n" ); |
| 77 | } |
| 78 | |
| 79 | |
| 80 | |
| 81 | /* PAL termination */ |
| 82 | PAL_Terminate(); |
| 83 | |
| 84 | /* return success */ |
| 85 | return PASS; |
| 86 | } |
| 87 | |