| 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 WaitForSingleObjectTest. Create two events, one | 
|---|
| 10 | ** with a TRUE and one with FALSE intial state.  Ensure that WaitForSingle | 
|---|
| 11 | ** returns correct values for each of these. | 
|---|
| 12 | ** | 
|---|
| 13 | ** | 
|---|
| 14 | **=========================================================*/ | 
|---|
| 15 |  | 
|---|
| 16 | #include <palsuite.h> | 
|---|
| 17 |  | 
|---|
| 18 | BOOL WaitForSingleObjectTest() | 
|---|
| 19 | { | 
|---|
| 20 |  | 
|---|
| 21 | BOOL bRet = FALSE; | 
|---|
| 22 | DWORD dwRet = 0; | 
|---|
| 23 |  | 
|---|
| 24 | LPSECURITY_ATTRIBUTES lpEventAttributes = 0; | 
|---|
| 25 | BOOL bManualReset = TRUE; | 
|---|
| 26 | BOOL bInitialState = TRUE; | 
|---|
| 27 |  | 
|---|
| 28 | HANDLE hEvent; | 
|---|
| 29 |  | 
|---|
| 30 | /* Create an event, and ensure the HANDLE is valid */ | 
|---|
| 31 | hEvent  = CreateEvent(lpEventAttributes, bManualReset, | 
|---|
| 32 | bInitialState, NULL); | 
|---|
| 33 |  | 
|---|
| 34 | if (hEvent != INVALID_HANDLE_VALUE) | 
|---|
| 35 | { | 
|---|
| 36 |  | 
|---|
| 37 | /* Call WaitForSingleObject with 0 time on the event.  It | 
|---|
| 38 | should return WAIT_OBJECT_0 | 
|---|
| 39 | */ | 
|---|
| 40 |  | 
|---|
| 41 | dwRet = WaitForSingleObject(hEvent,0); | 
|---|
| 42 |  | 
|---|
| 43 | if (dwRet != WAIT_OBJECT_0) | 
|---|
| 44 | { | 
|---|
| 45 | Trace( "WaitForSingleObjectTest:WaitForSingleObject failed (%x)\n", GetLastError()); | 
|---|
| 46 | } | 
|---|
| 47 | else | 
|---|
| 48 | { | 
|---|
| 49 | bRet = CloseHandle(hEvent); | 
|---|
| 50 |  | 
|---|
| 51 | if (!bRet) | 
|---|
| 52 | { | 
|---|
| 53 | Trace( "WaitForSingleObjectTest:CloseHandle failed (%x)\n", GetLastError()); | 
|---|
| 54 | } | 
|---|
| 55 | } | 
|---|
| 56 | } | 
|---|
| 57 | else | 
|---|
| 58 | { | 
|---|
| 59 | Trace( "WaitForSingleObjectTest:CreateEvent failed (%x)\n", GetLastError()); | 
|---|
| 60 | } | 
|---|
| 61 |  | 
|---|
| 62 | /* If the first section passed, Create another event, with the | 
|---|
| 63 | intial state being FALSE this time. | 
|---|
| 64 | */ | 
|---|
| 65 |  | 
|---|
| 66 | if (bRet) | 
|---|
| 67 | { | 
|---|
| 68 | bRet = FALSE; | 
|---|
| 69 |  | 
|---|
| 70 | bInitialState = FALSE; | 
|---|
| 71 |  | 
|---|
| 72 | hEvent = CreateEvent( lpEventAttributes, | 
|---|
| 73 | bManualReset, bInitialState, NULL); | 
|---|
| 74 |  | 
|---|
| 75 | if (hEvent != INVALID_HANDLE_VALUE) | 
|---|
| 76 | { | 
|---|
| 77 |  | 
|---|
| 78 | /* Test WaitForSingleObject and ensure that it returns | 
|---|
| 79 | WAIT_TIMEOUT in this case. | 
|---|
| 80 | */ | 
|---|
| 81 |  | 
|---|
| 82 | dwRet = WaitForSingleObject(hEvent,0); | 
|---|
| 83 |  | 
|---|
| 84 | if (dwRet != WAIT_TIMEOUT) | 
|---|
| 85 | { | 
|---|
| 86 | Trace( "WaitForSingleObjectTest:WaitForSingleObject failed (%x)\n", GetLastError()); | 
|---|
| 87 | } | 
|---|
| 88 | else | 
|---|
| 89 | { | 
|---|
| 90 | bRet = CloseHandle(hEvent); | 
|---|
| 91 |  | 
|---|
| 92 | if (!bRet) | 
|---|
| 93 | { | 
|---|
| 94 | Trace( "WaitForSingleObjectTest:CloseHandle failed (%x)\n", GetLastError()); | 
|---|
| 95 | } | 
|---|
| 96 | } | 
|---|
| 97 | } | 
|---|
| 98 | else | 
|---|
| 99 | { | 
|---|
| 100 | Trace( "WaitForSingleObjectTest::CreateEvent failed (%x)\n", GetLastError()); | 
|---|
| 101 | } | 
|---|
| 102 | } | 
|---|
| 103 | return bRet; | 
|---|
| 104 | } | 
|---|
| 105 |  | 
|---|
| 106 | int __cdecl main(int argc, char **argv) | 
|---|
| 107 | { | 
|---|
| 108 | if(0 != (PAL_Initialize(argc, argv))) | 
|---|
| 109 | { | 
|---|
| 110 | return ( FAIL ); | 
|---|
| 111 | } | 
|---|
| 112 |  | 
|---|
| 113 | if(!WaitForSingleObjectTest()) | 
|---|
| 114 | { | 
|---|
| 115 | Fail ( "Test failed\n"); | 
|---|
| 116 | } | 
|---|
| 117 |  | 
|---|
| 118 | PAL_Terminate(); | 
|---|
| 119 | return ( PASS ); | 
|---|
| 120 |  | 
|---|
| 121 | } | 
|---|
| 122 |  | 
|---|