2013-11-07 22:57:05 +04:00
|
|
|
|
|
|
|
#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];
|
2016-06-10 14:10:39 +03:00
|
|
|
DWORD len;
|
2021-07-29 11:18:52 +03:00
|
|
|
WINPR_UNUSED(argc);
|
|
|
|
WINPR_UNUSED(argv);
|
2016-06-10 14:10:39 +03:00
|
|
|
/* Test insufficient buffer size behaviour */
|
|
|
|
SetLastError(ERROR_SUCCESS);
|
|
|
|
len = GetModuleFileNameA(NULL, ModuleFileName, 2);
|
|
|
|
if (len != 2)
|
|
|
|
{
|
2023-07-27 10:02:03 +03:00
|
|
|
printf("%s: GetModuleFileNameA unexpectedly returned %" PRIu32 " instead of 2\n", __func__,
|
|
|
|
len);
|
2016-06-10 14:10:39 +03:00
|
|
|
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",
|
2023-07-27 10:02:03 +03:00
|
|
|
__func__, GetLastError(), ERROR_INSUFFICIENT_BUFFER);
|
2016-06-10 14:10:39 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test with real/sufficient buffer size */
|
|
|
|
SetLastError(ERROR_SUCCESS);
|
|
|
|
len = GetModuleFileNameA(NULL, ModuleFileName, sizeof(ModuleFileName));
|
|
|
|
if (len == 0)
|
|
|
|
{
|
2023-07-27 10:02:03 +03:00
|
|
|
printf("%s: GetModuleFileNameA failed with error 0x%08" PRIX32 "\n", __func__,
|
2019-11-06 17:24:51 +03:00
|
|
|
GetLastError());
|
2016-06-10 14:10:39 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (len == sizeof(ModuleFileName))
|
|
|
|
{
|
2023-07-27 10:02:03 +03:00
|
|
|
printf("%s: GetModuleFileNameA unexpectedly returned nSize\n", __func__);
|
2016-06-10 14:10:39 +03:00
|
|
|
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",
|
2023-07-27 10:02:03 +03:00
|
|
|
__func__, GetLastError(), ERROR_SUCCESS);
|
2016-06-10 14:10:39 +03:00
|
|
|
return -1;
|
|
|
|
}
|
2013-11-07 22:57:05 +04:00
|
|
|
|
|
|
|
printf("GetModuleFileNameA: %s\n", ModuleFileName);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|