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: test2.c
8**
9** Dependencies: PAL_Initialize
10** PAL_Terminate
11** CreateEvent
12** CloseHandle
13** WaitForSingleObject
14**
15** Purpose:
16**
17** Test to ensure proper operation of the SetEvent()
18** API by calling it on an event handle that's already set.
19**
20
21**
22**===========================================================================*/
23#include <palsuite.h>
24
25
26
27int __cdecl main( int argc, char **argv )
28
29{
30 /* local variables */
31 DWORD dwRet = 0;
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 /* verify that the event isn't signalled yet */
58 dwRet = WaitForSingleObject( hEvent, 0 );
59 if( dwRet != WAIT_TIMEOUT )
60 {
61 /* ERROR */
62 Trace( "ERROR:WaitForSingleObject() call returned %lu, "
63 "expected WAIT_TIMEOUT\n",
64 dwRet );
65 CloseHandle( hEvent );
66 Fail( "Test failed\n" );
67 }
68
69 /* set the event */
70 if( ! SetEvent( hEvent ) )
71 {
72 /* ERROR */
73 Trace( "ERROR:%lu:SetEvent() call failed\n", GetLastError() );
74 CloseHandle( hEvent );
75 Fail( "Test failed\n" );
76 }
77
78 /* verify that the event is signalled */
79 dwRet = WaitForSingleObject( hEvent, 0 );
80 if( dwRet != WAIT_OBJECT_0 )
81 {
82 /* ERROR */
83 Trace( "ERROR:WaitForSingleObject() call returned %lu, "
84 "expected WAIT_OBJECT_0\n",
85 dwRet );
86 CloseHandle( hEvent );
87 Fail( "Test failed\n" );
88 }
89
90 /* try to set the event again */
91 if( ! SetEvent( hEvent ) )
92 {
93 /* ERROR */
94 Trace( "FAIL:%lu:SetEvent() call failed on signalled event\n",
95 GetLastError() );
96 CloseHandle( hEvent );
97 Fail( "Test failed\n" );
98 }
99
100 /* verify that the event is still signalled */
101 dwRet = WaitForSingleObject( hEvent, 0 );
102 if( dwRet != WAIT_OBJECT_0 )
103 {
104 /* ERROR */
105 Trace( "ERROR:WaitForSingleObject() call returned %lu, "
106 "expected WAIT_OBJECT_0\n",
107 dwRet );
108 CloseHandle( hEvent );
109 Fail( "Test failed\n" );
110 }
111
112
113 /* close the event handle */
114 if( ! CloseHandle( hEvent ) )
115 {
116 Fail( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() );
117 }
118
119
120 /* PAL termination */
121 PAL_Terminate();
122
123 /* return success */
124 return PASS;
125}
126