Extended test, now also checks, if lock / unlock is working.

This commit is contained in:
Armin Novak 2013-11-15 08:38:59 +01:00
parent 013a3b9956
commit efd2d833c2
1 changed files with 33 additions and 1 deletions

View File

@ -4,16 +4,48 @@
int TestSynchMutex(int argc, char* argv[])
{
DWORD rc;
HANDLE mutex;
mutex = CreateMutex(NULL, FALSE, NULL);
if (!mutex)
{
printf("CreateMutex failure\n");
return -1;
}
/* Lock the mutex */
rc = WaitForSingleObject(mutex, INFINITE);
if (WAIT_OBJECT_0 != rc)
{
printf("WaitForSingleObject on mutex failed with %d\n", rc);
return -2;
}
/* TryLock should now fail. */
rc = WaitForSingleObject(mutex, 0);
if (WAIT_TIMEOUT != rc)
{
printf("Timed WaitForSingleObject on locked mutex failed with %d\n", rc);
return -3;
}
/* Unlock the mutex */
rc = ReleaseMutex(mutex);
if (!rc)
{
printf("ReleaseMutex failed.\n");
return -4;
}
/* TryLock should now succeed. */
rc = WaitForSingleObject(mutex, 0);
if (WAIT_OBJECT_0 != rc)
{
printf("Timed WaitForSingleObject on free mutex failed with %d\n", rc);
return -5;
}
CloseHandle(mutex);
return 0;