FreeRDP/winpr/libwinpr/library/test/TestLibraryGetModuleFileName.c

57 lines
1.5 KiB
C
Raw Normal View History

#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/path.h>
#include <winpr/tchar.h>
#include <winpr/windows.h>
#include <winpr/library.h>
int TestLibraryGetModuleFileName(int argc, char* argv[])
{
char ModuleFileName[4096];
DWORD len;
2021-07-29 11:18:52 +03:00
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
/* Test insufficient buffer size behaviour */
SetLastError(ERROR_SUCCESS);
len = GetModuleFileNameA(NULL, ModuleFileName, 2);
if (len != 2)
{
printf("%s: GetModuleFileNameA unexpectedly returned %" PRIu32 " instead of 2\n", __func__,
len);
return -1;
}
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
{
2019-11-06 17:24:51 +03:00
printf("%s: Invalid last error value: 0x%08" PRIX32
". Expected 0x%08X (ERROR_INSUFFICIENT_BUFFER)\n",
__func__, GetLastError(), ERROR_INSUFFICIENT_BUFFER);
return -1;
}
/* Test with real/sufficient buffer size */
SetLastError(ERROR_SUCCESS);
len = GetModuleFileNameA(NULL, ModuleFileName, sizeof(ModuleFileName));
if (len == 0)
{
printf("%s: GetModuleFileNameA failed with error 0x%08" PRIX32 "\n", __func__,
2019-11-06 17:24:51 +03:00
GetLastError());
return -1;
}
if (len == sizeof(ModuleFileName))
{
printf("%s: GetModuleFileNameA unexpectedly returned nSize\n", __func__);
return -1;
}
if (GetLastError() != ERROR_SUCCESS)
{
2019-11-06 17:24:51 +03:00
printf("%s: Invalid last error value: 0x%08" PRIX32 ". Expected 0x%08X (ERROR_SUCCESS)\n",
__func__, GetLastError(), ERROR_SUCCESS);
return -1;
}
printf("GetModuleFileNameA: %s\n", ModuleFileName);
return 0;
}