From c7b7d527f37d1b095a2e9f8b7754c3854e1a93d5 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Fri, 8 Feb 2019 09:18:16 +0100 Subject: [PATCH] Fixed unused argument warnings for tests. --- libfreerdp/core/test/TestVersion.c | 14 +++++-- winpr/libwinpr/synch/test/TestSynchMutex.c | 45 +++++++++++++--------- winpr/libwinpr/synch/test/TestSynchWaitableTimer.c | 2 + .../synch/test/TestSynchWaitableTimerAPC.c | 30 ++++++--------- winpr/libwinpr/utils/test/TestVersion.c | 14 +++++-- 5 files changed, 61 insertions(+), 44 deletions(-) diff --git a/libfreerdp/core/test/TestVersion.c b/libfreerdp/core/test/TestVersion.c index 146e81f..8882e35 100644 --- a/libfreerdp/core/test/TestVersion.c +++ b/libfreerdp/core/test/TestVersion.c @@ -3,12 +3,14 @@ int TestVersion(int argc, char* argv[]) { - const char *version; - const char *git; - const char *build; + const char* version; + const char* git; + const char* build; int major = 0, minor = 0, revision = 0; - + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); freerdp_get_version(&major, &minor, &revision); + if (major != FREERDP_VERSION_MAJOR) return -1; @@ -19,10 +21,12 @@ int TestVersion(int argc, char* argv[]) return -1; version = freerdp_get_version_string(); + if (!version) return -1; git = freerdp_get_build_revision(); + if (!git) return -1; @@ -30,10 +34,12 @@ int TestVersion(int argc, char* argv[]) return -1; build = freerdp_get_build_date(); + if (!build) return -1; build = freerdp_get_build_config(); + if (!build) return -1; diff --git a/winpr/libwinpr/synch/test/TestSynchMutex.c b/winpr/libwinpr/synch/test/TestSynchMutex.c index 1bab037..66f0500 100644 --- a/winpr/libwinpr/synch/test/TestSynchMutex.c +++ b/winpr/libwinpr/synch/test/TestSynchMutex.c @@ -16,6 +16,7 @@ static BOOL test_mutex_basic(void) } rc = WaitForSingleObject(mutex, INFINITE); + if (rc != WAIT_OBJECT_0) { printf("%s: WaitForSingleObject on mutex failed with %"PRIu32"\n", __FUNCTION__, rc); @@ -39,6 +40,7 @@ static BOOL test_mutex_basic(void) printf("%s: CloseHandle on mutex failed\n", __FUNCTION__); return FALSE; } + return TRUE; } @@ -56,6 +58,7 @@ static BOOL test_mutex_recursive(void) for (i = 0; i < cnt; i++) { rc = WaitForSingleObject(mutex, INFINITE); + if (rc != WAIT_OBJECT_0) { printf("%s: WaitForSingleObject #%"PRIu32" on mutex failed with %"PRIu32"\n", __FUNCTION__, i, rc); @@ -90,10 +93,10 @@ static BOOL test_mutex_recursive(void) printf("%s: CloseHandle on mutex failed\n", __FUNCTION__); return FALSE; } + return TRUE; } - static HANDLE thread1_mutex1 = NULL; static HANDLE thread1_mutex2 = NULL; static BOOL thread1_failed = TRUE; @@ -102,12 +105,13 @@ static DWORD WINAPI test_mutex_thread1(LPVOID lpParam) { HANDLE hStartEvent = (HANDLE)lpParam; DWORD rc = 0; + if (WaitForSingleObject(hStartEvent, INFINITE) != WAIT_OBJECT_0) { fprintf(stderr, "%s: failed to wait for start event\n", __FUNCTION__); return 0; } - + /** * at this point: * thread1_mutex1 is expected to be locked @@ -116,30 +120,33 @@ static DWORD WINAPI test_mutex_thread1(LPVOID lpParam) * try to lock thread1_mutex1 (expected to fail) * lock and unlock thread1_mutex2 (expected to work) */ - rc = WaitForSingleObject(thread1_mutex1, 10); + if (rc != WAIT_TIMEOUT) { - fprintf(stderr, "%s: WaitForSingleObject on thread1_mutex1 unexpectedly returned %"PRIu32" instead of WAIT_TIMEOUT (%u)\n", - __FUNCTION__, rc, WAIT_TIMEOUT); + fprintf(stderr, + "%s: WaitForSingleObject on thread1_mutex1 unexpectedly returned %"PRIu32" instead of WAIT_TIMEOUT (%u)\n", + __FUNCTION__, rc, WAIT_TIMEOUT); return 0; } rc = WaitForSingleObject(thread1_mutex2, 10); + if (rc != WAIT_OBJECT_0) { - fprintf(stderr, "%s: WaitForSingleObject on thread1_mutex2 unexpectedly returned %"PRIu32" instead of WAIT_OBJECT_0\n", - __FUNCTION__, rc); + fprintf(stderr, + "%s: WaitForSingleObject on thread1_mutex2 unexpectedly returned %"PRIu32" instead of WAIT_OBJECT_0\n", + __FUNCTION__, rc); return 0; } - if (!ReleaseMutex(thread1_mutex2)) { + if (!ReleaseMutex(thread1_mutex2)) + { fprintf(stderr, "%s: ReleaseMutex failed on thread1_mutex2\n", __FUNCTION__); return 0; } thread1_failed = FALSE; - return 0; } @@ -211,15 +218,13 @@ static BOOL test_mutex_threading(void) { printf("%s: ReleaseMutex unexpectedly succeeded on thread1_mutex2\n", __FUNCTION__); goto fail; - } + } CloseHandle(hThread); CloseHandle(hStartEvent); CloseHandle(thread1_mutex1); CloseHandle(thread1_mutex2); - - return TRUE; - + return TRUE; fail: ReleaseMutex(thread1_mutex1); ReleaseMutex(thread1_mutex2); @@ -232,15 +237,19 @@ fail: int TestSynchMutex(int argc, char* argv[]) { + int rc = 0; + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + if (!test_mutex_basic()) - return 1; + rc += 1; if (!test_mutex_recursive()) - return 2; + rc += 2; if (!test_mutex_threading()) - return 3; + rc += 4; - printf("TestSynchMutex succeeded\n"); - return 0; + printf("TestSynchMutex result %d\n", rc); + return rc; } diff --git a/winpr/libwinpr/synch/test/TestSynchWaitableTimer.c b/winpr/libwinpr/synch/test/TestSynchWaitableTimer.c index 25e8f02..3d801d4 100644 --- a/winpr/libwinpr/synch/test/TestSynchWaitableTimer.c +++ b/winpr/libwinpr/synch/test/TestSynchWaitableTimer.c @@ -9,6 +9,8 @@ int TestSynchWaitableTimer(int argc, char* argv[]) LONG period; LARGE_INTEGER due; int result = -1; + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); timer = CreateWaitableTimer(NULL, FALSE, NULL); if (!timer) diff --git a/winpr/libwinpr/synch/test/TestSynchWaitableTimerAPC.c b/winpr/libwinpr/synch/test/TestSynchWaitableTimerAPC.c index 97f3e26..19f90c6 100644 --- a/winpr/libwinpr/synch/test/TestSynchWaitableTimerAPC.c +++ b/winpr/libwinpr/synch/test/TestSynchWaitableTimerAPC.c @@ -16,14 +16,14 @@ static VOID CALLBACK TimerAPCProc(LPVOID lpArg, DWORD dwTimerLowValue, DWORD dwT { APC_DATA* apcData; UINT32 CurrentTime = GetTickCount(); + WINPR_UNUSED(dwTimerLowValue); + WINPR_UNUSED(dwTimerHighValue); if (!lpArg) return; apcData = (APC_DATA*) lpArg; - printf("TimerAPCProc: time: %"PRIu32"\n", CurrentTime - apcData->StartTime); - g_Count++; if (g_Count >= 5) @@ -38,16 +38,11 @@ int TestSynchWaitableTimerAPC(int argc, char* argv[]) HANDLE hTimer = NULL; BOOL bSuccess; LARGE_INTEGER due; - APC_DATA* apcData = NULL; - - apcData = (APC_DATA*) malloc(sizeof(APC_DATA)); - if (!apcData) - { - printf("Memory allocation failed\n"); - goto cleanup; - } - + APC_DATA apcData = { 0 }; + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); g_Event = CreateEvent(NULL, TRUE, FALSE, NULL); + if (!g_Event) { printf("Failed to create event\n"); @@ -60,9 +55,8 @@ int TestSynchWaitableTimerAPC(int argc, char* argv[]) goto cleanup; due.QuadPart = -15000000LL; /* 1.5 seconds */ - - apcData->StartTime = GetTickCount(); - bSuccess = SetWaitableTimer(hTimer, &due, 2000, TimerAPCProc, apcData, FALSE); + apcData.StartTime = GetTickCount(); + bSuccess = SetWaitableTimer(hTimer, &due, 2000, TimerAPCProc, &apcData, FALSE); if (!bSuccess) goto cleanup; @@ -73,7 +67,6 @@ int TestSynchWaitableTimerAPC(int argc, char* argv[]) * using SetWaitableTimer. However, the thread must be in an ALERTABLE state. */ - /** * Note: On WIN32 we need to use WaitForSingleObjectEx with parameter bAlertable = TRUE * However, WinPR currently (May 2016) does not have a working WaitForSingleObjectEx implementation @@ -81,7 +74,7 @@ int TestSynchWaitableTimerAPC(int argc, char* argv[]) * timer implementations. **/ - for(;;) + for (;;) { DWORD rc; #ifdef _WIN32 @@ -89,6 +82,7 @@ int TestSynchWaitableTimerAPC(int argc, char* argv[]) #else rc = WaitForSingleObject(g_Event, INFINITE); #endif + if (rc == WAIT_OBJECT_0) break; @@ -100,13 +94,13 @@ int TestSynchWaitableTimerAPC(int argc, char* argv[]) } status = 0; - cleanup: + if (hTimer) CloseHandle(hTimer); + if (g_Event) CloseHandle(g_Event); - free(apcData); return status; } diff --git a/winpr/libwinpr/utils/test/TestVersion.c b/winpr/libwinpr/utils/test/TestVersion.c index 60c4f90..1bd33f3 100644 --- a/winpr/libwinpr/utils/test/TestVersion.c +++ b/winpr/libwinpr/utils/test/TestVersion.c @@ -6,12 +6,14 @@ int TestVersion(int argc, char* argv[]) { - const char *version; - const char *git; - const char *build; + const char* version; + const char* git; + const char* build; int major = 0, minor = 0, revision = 0; - + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); winpr_get_version(&major, &minor, &revision); + if (major != WINPR_VERSION_MAJOR) return -1; @@ -22,10 +24,12 @@ int TestVersion(int argc, char* argv[]) return -1; version = winpr_get_version_string(); + if (!version) return -1; git = winpr_get_build_revision(); + if (!git) return -1; @@ -33,10 +37,12 @@ int TestVersion(int argc, char* argv[]) return -1; build = winpr_get_build_date(); + if (!build) return -1; build = winpr_get_build_config(); + if (!build) return -1; -- 2.7.4