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: test1.c
8**
9** Purpose: Test for ResetEvent. Create an event with an intial
10** state signaled. Then reset that signal, and check to see that
11** the event is now not signaled.
12**
13**
14**=========================================================*/
15
16#include <palsuite.h>
17
18BOOL ResetEventTest()
19{
20 BOOL bRet = FALSE;
21 DWORD dwRet = 0;
22
23 LPSECURITY_ATTRIBUTES lpEventAttributes = 0;
24 BOOL bManualReset = TRUE;
25 BOOL bInitialState = TRUE;
26
27 /* Create an Event, ensure it is valid */
28 HANDLE hEvent = CreateEvent( lpEventAttributes,
29 bManualReset, bInitialState, NULL);
30
31 if (hEvent != INVALID_HANDLE_VALUE)
32 {
33 /* Check that WaitFor returns WAIT_OBJECT_0, indicating that
34 the event is signaled.
35 */
36
37 dwRet = WaitForSingleObject(hEvent,0);
38
39 if (dwRet != WAIT_OBJECT_0)
40 {
41 Fail("ResetEventTest:WaitForSingleObject failed (%x)\n", GetLastError());
42 }
43 else
44 {
45 /* Call ResetEvent, which will reset the signal */
46 bRet = ResetEvent(hEvent);
47
48 if (!bRet)
49 {
50 Fail("ResetEventTest:ResetEvent failed (%x)\n", GetLastError());
51 }
52 else
53 {
54 /* Call WaitFor again, and since it has been reset,
55 the return value should now be WAIT_TIMEOUT
56 */
57 dwRet = WaitForSingleObject(hEvent,0);
58
59 if (dwRet != WAIT_TIMEOUT)
60 {
61 Fail("ResetEventTest:WaitForSingleObject %s failed (%x)\n", GetLastError());
62 }
63 else
64 {
65 bRet = CloseHandle(hEvent);
66
67 if (!bRet)
68 {
69 Fail("ResetEventTest:CloseHandle failed (%x)\n", GetLastError());
70 }
71 }
72 }
73 }
74 }
75 else
76 {
77 Fail("ResetEventTest:CreateEvent failed (%x)\n", GetLastError());
78 }
79
80 return bRet;
81}
82
83int __cdecl main(int argc, char **argv)
84{
85
86 if(0 != (PAL_Initialize(argc, argv)))
87 {
88 return ( FAIL );
89 }
90
91 if(!ResetEventTest())
92 {
93 Fail ("Test failed\n");
94 }
95
96 PAL_Terminate();
97 return ( PASS );
98
99}
100