FreeRDP/winpr/libwinpr/synch/test/TestSynchWaitableTimer.c
Norbert Federa f2c825bb76 winpr: fix some tests
TestNtCreateFile, TestPipeCreateNamedPipeOverlapped
- These tests are currently only expected to succeed on _WIN32
- Also reflect the reverse meaning of this fact in the return values

TestSynchWaitableTimer, TestSynchWaitableTimerAPC:
- These tests are currently expected to fail on __APPLE__
- Also reflect the reverse meaning of this fact in the return values

This logic makes sure that we don't forget to fix the tests if the
corresponding WinPR implementations are fixed.

TestLibrary:
- TestLibraryA and TestLibraryB must always get built as shared libraries
2016-06-07 17:20:56 +02:00

97 lines
1.7 KiB
C

#include <winpr/crt.h>
#include <winpr/synch.h>
int TestSynchWaitableTimer(int argc, char* argv[])
{
DWORD status;
HANDLE timer;
LONG period;
LARGE_INTEGER due;
int result = -1;
timer = CreateWaitableTimer(NULL, FALSE, NULL);
if (!timer)
{
printf("CreateWaitableTimer failure\n");
goto out;
}
due.QuadPart = -15000000LL; /* 1.5 seconds */
if (!SetWaitableTimer(timer, &due, 0, NULL, NULL, 0))
{
printf("SetWaitableTimer failure\n");
goto out;
}
status = WaitForSingleObject(timer, INFINITE);
if (status != WAIT_OBJECT_0)
{
printf("WaitForSingleObject(timer, INFINITE) failure\n");
goto out;
}
printf("Timer Signaled\n");
status = WaitForSingleObject(timer, 2000);
if (status != WAIT_TIMEOUT)
{
printf("WaitForSingleObject(timer, 2000) failure: Actual: 0x%04X, Expected: 0x%04X\n", status, WAIT_TIMEOUT);
goto out;
}
due.QuadPart = 0;
period = 1200; /* 1.2 seconds */
if (!SetWaitableTimer(timer, &due, period, NULL, NULL, 0))
{
printf("SetWaitableTimer failure\n");
goto out;
}
if (WaitForSingleObject(timer, INFINITE) != WAIT_OBJECT_0)
{
printf("WaitForSingleObject(timer, INFINITE) failure\n");
goto out;
}
printf("Timer Signaled\n");
if (WaitForMultipleObjects(1, &timer, FALSE, INFINITE) != WAIT_OBJECT_0)
{
printf("WaitForMultipleObjects(timer, INFINITE) failure\n");
goto out;
}
printf("Timer Signaled\n");
result = 0;
out:
CloseHandle(timer);
#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;
}