2013-07-29 21:07:39 +04:00
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/synch.h>
|
|
|
|
|
|
|
|
int TestSynchEvent(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
HANDLE event;
|
2015-06-17 15:13:28 +03:00
|
|
|
int i;
|
2021-07-29 11:18:52 +03:00
|
|
|
WINPR_UNUSED(argc);
|
|
|
|
WINPR_UNUSED(argv);
|
2015-06-17 15:13:28 +03:00
|
|
|
if (ResetEvent(NULL))
|
|
|
|
{
|
|
|
|
printf("ResetEvent(NULL) unexpectedly succeeded\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SetEvent(NULL))
|
|
|
|
{
|
|
|
|
printf("SetEvent(NULL) unexpectedly succeeded\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2013-07-29 21:07:39 +04:00
|
|
|
|
|
|
|
event = CreateEvent(NULL, TRUE, TRUE, NULL);
|
|
|
|
|
|
|
|
if (!event)
|
|
|
|
{
|
|
|
|
printf("CreateEvent failure\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (WaitForSingleObject(event, INFINITE) != WAIT_OBJECT_0)
|
|
|
|
{
|
2015-06-17 15:13:28 +03:00
|
|
|
printf("WaitForSingleObject failure 1\n");
|
2013-07-29 21:07:39 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-06-17 15:13:28 +03:00
|
|
|
if (!ResetEvent(event))
|
|
|
|
{
|
|
|
|
printf("ResetEvent failure with signaled event object\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2013-07-29 21:07:39 +04:00
|
|
|
|
|
|
|
if (WaitForSingleObject(event, 0) != WAIT_TIMEOUT)
|
|
|
|
{
|
2015-06-17 15:13:28 +03:00
|
|
|
printf("WaitForSingleObject failure 2\n");
|
2013-07-29 21:07:39 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-06-17 15:13:28 +03:00
|
|
|
if (!ResetEvent(event))
|
|
|
|
{
|
|
|
|
/* Note: ResetEvent must also succeed if event is currently nonsignaled */
|
|
|
|
printf("ResetEvent failure with nonsignaled event object\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!SetEvent(event))
|
|
|
|
{
|
|
|
|
printf("SetEvent failure with nonsignaled event object\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2013-07-29 21:07:39 +04:00
|
|
|
|
|
|
|
if (WaitForSingleObject(event, 0) != WAIT_OBJECT_0)
|
|
|
|
{
|
2015-06-17 15:13:28 +03:00
|
|
|
printf("WaitForSingleObject failure 3\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 10000; i++)
|
|
|
|
{
|
|
|
|
if (!SetEvent(event))
|
|
|
|
{
|
|
|
|
printf("SetEvent failure with signaled event object (i = %d)\n", i);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ResetEvent(event))
|
|
|
|
{
|
|
|
|
printf("ResetEvent failure after multiple SetEvent calls\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Independent of the amount of the previous SetEvent calls, a single
|
|
|
|
ResetEvent must be sufficient to get into nonsignaled state */
|
|
|
|
|
|
|
|
if (WaitForSingleObject(event, 0) != WAIT_TIMEOUT)
|
|
|
|
{
|
|
|
|
printf("WaitForSingleObject failure 4\n");
|
2013-07-29 21:07:39 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseHandle(event);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|