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