2013-07-29 21:07:39 +04:00
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/synch.h>
|
|
|
|
|
|
|
|
int TestSynchWaitableTimer(int argc, char* argv[])
|
|
|
|
{
|
2013-09-19 22:17:00 +04:00
|
|
|
DWORD status;
|
2013-07-29 21:07:39 +04:00
|
|
|
HANDLE timer;
|
|
|
|
LONG period;
|
|
|
|
LARGE_INTEGER due;
|
2016-06-07 18:20:56 +03:00
|
|
|
int result = -1;
|
2013-07-29 21:07:39 +04:00
|
|
|
|
2013-09-19 22:17:00 +04:00
|
|
|
timer = CreateWaitableTimer(NULL, FALSE, NULL);
|
2013-07-29 21:07:39 +04:00
|
|
|
|
|
|
|
if (!timer)
|
|
|
|
{
|
|
|
|
printf("CreateWaitableTimer failure\n");
|
2016-06-07 18:20:56 +03:00
|
|
|
goto out;
|
2013-07-29 21:07:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
due.QuadPart = -15000000LL; /* 1.5 seconds */
|
|
|
|
|
|
|
|
if (!SetWaitableTimer(timer, &due, 0, NULL, NULL, 0))
|
|
|
|
{
|
|
|
|
printf("SetWaitableTimer failure\n");
|
2016-06-07 18:20:56 +03:00
|
|
|
goto out;
|
2013-07-29 21:07:39 +04:00
|
|
|
}
|
|
|
|
|
2013-09-19 22:17:00 +04:00
|
|
|
status = WaitForSingleObject(timer, INFINITE);
|
|
|
|
|
|
|
|
if (status != WAIT_OBJECT_0)
|
2013-07-29 21:07:39 +04:00
|
|
|
{
|
|
|
|
printf("WaitForSingleObject(timer, INFINITE) failure\n");
|
2016-06-07 18:20:56 +03:00
|
|
|
goto out;
|
2013-07-29 21:07:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("Timer Signaled\n");
|
|
|
|
|
2013-09-19 22:17:00 +04:00
|
|
|
status = WaitForSingleObject(timer, 2000);
|
|
|
|
|
|
|
|
if (status != WAIT_TIMEOUT)
|
2013-07-29 21:07:39 +04:00
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
printf("WaitForSingleObject(timer, 2000) failure: Actual: 0x%08"PRIX32", Expected: 0x%08X\n", status, WAIT_TIMEOUT);
|
2016-06-07 18:20:56 +03:00
|
|
|
goto out;
|
2013-07-29 21:07:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
due.QuadPart = 0;
|
|
|
|
|
|
|
|
period = 1200; /* 1.2 seconds */
|
|
|
|
|
|
|
|
if (!SetWaitableTimer(timer, &due, period, NULL, NULL, 0))
|
|
|
|
{
|
|
|
|
printf("SetWaitableTimer failure\n");
|
2016-06-07 18:20:56 +03:00
|
|
|
goto out;
|
2013-07-29 21:07:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (WaitForSingleObject(timer, INFINITE) != WAIT_OBJECT_0)
|
|
|
|
{
|
|
|
|
printf("WaitForSingleObject(timer, INFINITE) failure\n");
|
2016-06-07 18:20:56 +03:00
|
|
|
goto out;
|
2013-07-29 21:07:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("Timer Signaled\n");
|
|
|
|
|
|
|
|
if (WaitForMultipleObjects(1, &timer, FALSE, INFINITE) != WAIT_OBJECT_0)
|
|
|
|
{
|
|
|
|
printf("WaitForMultipleObjects(timer, INFINITE) failure\n");
|
2016-06-07 18:20:56 +03:00
|
|
|
goto out;
|
2013-07-29 21:07:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("Timer Signaled\n");
|
|
|
|
|
2016-06-07 18:20:56 +03:00
|
|
|
result = 0;
|
|
|
|
|
|
|
|
out:
|
2013-07-29 21:07:39 +04:00
|
|
|
CloseHandle(timer);
|
|
|
|
|
2016-06-07 18:20:56 +03:00
|
|
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
if (result == 0)
|
|
|
|
{
|
|
|
|
printf("%s: Error, this test is currently expected not to succeed on this platform.\n",
|
|
|
|
__FUNCTION__);
|
|
|
|
result = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("%s: This test is currently expected to fail on this platform.\n",
|
|
|
|
__FUNCTION__);
|
|
|
|
result = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return result;
|
2013-07-29 21:07:39 +04:00
|
|
|
}
|
|
|
|
|