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 SetEvent() |
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 | #include <palsuite.h> |
25 | |
26 | |
27 | |
28 | int __cdecl main( int argc, char **argv ) |
29 | |
30 | { |
31 | /* local variables */ |
32 | HANDLE hEvent = NULL; |
33 | LPSECURITY_ATTRIBUTES lpEventAttributes = NULL; |
34 | BOOL bManualReset = TRUE; |
35 | BOOL bInitialState = FALSE; |
36 | |
37 | |
38 | /* PAL initialization */ |
39 | if( (PAL_Initialize(argc, argv)) != 0 ) |
40 | { |
41 | return( FAIL ); |
42 | } |
43 | |
44 | |
45 | /* create an event which we can use with SetEvent */ |
46 | hEvent = CreateEvent( lpEventAttributes, |
47 | bManualReset, |
48 | bInitialState, |
49 | NULL ); |
50 | |
51 | if( hEvent == INVALID_HANDLE_VALUE ) |
52 | { |
53 | /* ERROR */ |
54 | Fail( "ERROR:%lu:CreateEvent() call failed\n" , GetLastError() ); |
55 | } |
56 | |
57 | /* close the event handle */ |
58 | if( ! CloseHandle( hEvent ) ) |
59 | { |
60 | Fail( "ERROR:%lu:CloseHandle() call failed\n" , GetLastError() ); |
61 | } |
62 | |
63 | /* try to set the event */ |
64 | if( SetEvent( hEvent ) ) |
65 | { |
66 | /* ERROR */ |
67 | Fail( "FAIL:SetEvent() call succeeded on a closed event handle\n" ); |
68 | } |
69 | |
70 | /* verify the result of GetLastError() */ |
71 | if( GetLastError() != ERROR_INVALID_HANDLE ) |
72 | { |
73 | /* ERROR */ |
74 | Fail( "FAIL:SetEvent() call failed on a closed event handle" |
75 | "but returned an unexpected error result %lu\n" ); |
76 | } |
77 | |
78 | |
79 | |
80 | /* PAL termination */ |
81 | PAL_Terminate(); |
82 | |
83 | /* return success */ |
84 | return PASS; |
85 | } |
86 | |