DWORD GetModuleFileNameW(HMODULE hModule, LPWSTR lpFilename, DWORD nSize)
{
+ WLog_ERR(TAG, "%s is not implemented", __FUNCTION__);
+ SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return 0;
}
status = readlink(path, buffer, sizeof(buffer));
if (status < 0)
+ {
+ SetLastError(ERROR_INTERNAL_ERROR);
return 0;
+ }
buffer[status] = '\0';
length = strlen(buffer);
{
CopyMemory(lpFilename, buffer, length);
lpFilename[length] = '\0';
- }
- else
- {
- CopyMemory(lpFilename, buffer, nSize - 1);
- lpFilename[nSize - 1] = '\0';
+ return length;
}
- return 0;
+ CopyMemory(lpFilename, buffer, nSize - 1);
+ lpFilename[nSize - 1] = '\0';
+ SetLastError(ERROR_INSUFFICIENT_BUFFER);
+ return nSize;
}
#elif defined(__MACOSX__)
if (status != 0)
{
/* path too small */
+ SetLastError(ERROR_INTERNAL_ERROR);
return 0;
}
{
CopyMemory(lpFilename, buffer, length);
lpFilename[length] = '\0';
- }
- else
- {
- CopyMemory(lpFilename, buffer, nSize - 1);
- lpFilename[nSize - 1] = '\0';
+ return length;
}
- return 0;
+ CopyMemory(lpFilename, buffer, nSize - 1);
+ lpFilename[nSize - 1] = '\0';
+ SetLastError(ERROR_INSUFFICIENT_BUFFER);
+ return nSize;
}
#endif
+ WLog_ERR(TAG, "%s is not implemented", __FUNCTION__);
+ SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return 0;
}
foreach(test ${${MODULE_PREFIX}_TESTS})
get_filename_component(TestName ${test} NAME_WE)
- add_test(${TestName} ${TESTING_OUTPUT_DIRECTORY}/${MODULE_NAME} ${TestName} "${TESTING_OUTPUT_DIRECTORY}/${TEST_AREA}")
+ add_test(${TestName} ${TESTING_OUTPUT_DIRECTORY}/${MODULE_NAME} ${TestName})
endforeach()
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Test")
set_target_properties(${MODULE_NAME} PROPERTIES PREFIX "")
-set_target_properties(${MODULE_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}/${TEST_AREA}/${MODULE_NAME}")
+set_target_properties(${MODULE_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}")
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Test/Extra")
set_target_properties(${MODULE_NAME} PROPERTIES PREFIX "")
-set_target_properties(${MODULE_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}/${TEST_AREA}/${MODULE_NAME}")
+set_target_properties(${MODULE_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}")
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Test/Extra")
int TestLibraryGetModuleFileName(int argc, char* argv[])
{
char ModuleFileName[4096];
+ DWORD len;
- GetModuleFileNameA(NULL, ModuleFileName, sizeof(ModuleFileName));
+ /* Test insufficient buffer size behaviour */
+ SetLastError(ERROR_SUCCESS);
+ len = GetModuleFileNameA(NULL, ModuleFileName, 2);
+ if (len != 2)
+ {
+ printf("%s: GetModuleFileNameA unexpectedly returned %u instead of 2\n",
+ __FUNCTION__, len);
+ return -1;
+ }
+ if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
+ {
+ printf("%s: Invalid last error value: 0x%08X. Expected 0x%08X (ERROR_INSUFFICIENT_BUFFER)\n",
+ __FUNCTION__, 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%08X\n",
+ __FUNCTION__, GetLastError());
+ return -1;
+ }
+ if (len == sizeof(ModuleFileName))
+ {
+ printf("%s: GetModuleFileNameA unexpectedly returned nSize\n",
+ __FUNCTION__);
+ return -1;
+ }
+ if (GetLastError() != ERROR_SUCCESS)
+ {
+ printf("%s: Invalid last error value: 0x%08X. Expected 0x%08X (ERROR_SUCCESS)\n",
+ __FUNCTION__, GetLastError(), ERROR_SUCCESS);
+ return -1;
+ }
printf("GetModuleFileNameA: %s\n", ModuleFileName);
HINSTANCE library;
TEST_AB_FN pFunctionA;
TEST_AB_FN pFunctionB;
- LPCTSTR SharedLibraryExtension;
- TCHAR LibraryPath[PATHCCH_MAX_CCH];
+ LPCSTR SharedLibraryExtension;
+ CHAR LibraryPath[PATHCCH_MAX_CCH];
+ PCHAR p;
-#ifndef _WIN32
- char* str;
- int length;
- LPTSTR BasePath;
-
- str = argv[1];
-
-#ifdef UNICODE
- length = MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), NULL, 0);
- BasePath = (WCHAR*) malloc((length + 1) * sizeof(WCHAR));
- if (!BasePath)
+ if (!GetModuleFileNameA(NULL, LibraryPath, PATHCCH_MAX_CCH))
{
- _tprintf(_T("Memory allocation failed\n"));
+ printf("%s: GetModuleFilenameA failed: 0x%08X\n", __FUNCTION__, GetLastError());
return -1;
}
- MultiByteToWideChar(CP_UTF8, 0, str, length, (LPWSTR) BasePath, length * sizeof(WCHAR));
- BasePath[length] = 0;
-#else
- BasePath = _strdup(str);
- if (!BasePath)
+
+ /* PathCchRemoveFileSpec is not implemented in WinPR */
+
+ if (!(p = strrchr(LibraryPath, PathGetSeparatorA(PATH_STYLE_NATIVE))))
{
- printf("Memory allocation failed");
+ printf("%s: Error identifying module directory path\n", __FUNCTION__);
return -1;
}
- length = strlen(BasePath);
-#endif
-
- CopyMemory(LibraryPath, BasePath, length * sizeof(TCHAR));
- LibraryPath[length] = 0;
-
- NativePathCchAppend(LibraryPath, PATHCCH_MAX_CCH, _T("TestLibraryA")); /* subdirectory */
-
-#else /* _WIN32 */
+ *p = 0;
- /* On Windows the test libraries are in same folder as the test executable */
- GetModuleFileName(NULL, LibraryPath, PATHCCH_MAX_CCH);
- PathRemoveFileSpec(LibraryPath);
-#endif
+ NativePathCchAppendA(LibraryPath, PATHCCH_MAX_CCH, "TestLibraryA");
+ SharedLibraryExtension = PathGetSharedLibraryExtensionA(PATH_SHARED_LIB_EXT_WITH_DOT);
+ NativePathCchAddExtensionA(LibraryPath, PATHCCH_MAX_CCH, SharedLibraryExtension);
- NativePathCchAppend(LibraryPath, PATHCCH_MAX_CCH, _T("TestLibraryA")); /* file name without extension */
+ printf("%s: Loading Library: '%s'\n", __FUNCTION__, LibraryPath);
- SharedLibraryExtension = PathGetSharedLibraryExtension(PATH_SHARED_LIB_EXT_WITH_DOT);
- NativePathCchAddExtension(LibraryPath, PATHCCH_MAX_CCH, SharedLibraryExtension); /* add shared library extension */
-
- _tprintf(_T("Loading Library: %s\n"), LibraryPath);
-
- library = LoadLibrary(LibraryPath);
-
- if (!library)
+ if (!(library = LoadLibraryA(LibraryPath)))
{
- _tprintf(_T("LoadLibrary failure\n"));
+ printf("%s: LoadLibraryA failure: 0x%08X\n", __FUNCTION__, GetLastError());
return -1;
}
- pFunctionA = (TEST_AB_FN) GetProcAddress(library, "FunctionA");
-
- if (!pFunctionA)
+ if (!(pFunctionA = (TEST_AB_FN) GetProcAddress(library, "FunctionA")))
{
- _tprintf(_T("GetProcAddress failure (FunctionA)\n"));
+ printf("%s: GetProcAddress failure (FunctionA)\n", __FUNCTION__);
return -1;
}
- pFunctionB = (TEST_AB_FN) GetProcAddress(library, "FunctionB");
-
- if (!pFunctionB)
+ if (!(pFunctionB = (TEST_AB_FN) GetProcAddress(library, "FunctionB")))
{
- _tprintf(_T("GetProcAddress failure (FunctionB)\n"));
+ printf("%s: GetProcAddress failure (FunctionB)\n", __FUNCTION__);
return -1;
}
if (c != (a * b))
{
- _tprintf(_T("pFunctionA call failed\n"));
+ printf("%s: pFunctionA call failed\n", __FUNCTION__);
return -1;
}
if (c != (a / b))
{
- _tprintf(_T("pFunctionB call failed\n"));
+ printf("%s: pFunctionB call failed\n", __FUNCTION__);
return -1;
}
if (!FreeLibrary(library))
{
- _tprintf(_T("FreeLibrary failure\n"));
+ printf("%s: FreeLibrary failure: 0x%08X\n", __FUNCTION__, GetLastError());
return -1;
}
int TestLibraryLoadLibrary(int argc, char* argv[])
{
HINSTANCE library;
- LPCTSTR SharedLibraryExtension;
- TCHAR LibraryPath[PATHCCH_MAX_CCH];
+ LPCSTR SharedLibraryExtension;
+ CHAR LibraryPath[PATHCCH_MAX_CCH];
+ PCHAR p;
-#ifndef _WIN32
- char* str;
- int length;
- LPTSTR BasePath;
- str = argv[1];
-
-#ifdef UNICODE
- length = MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), NULL, 0);
- BasePath = (WCHAR*) malloc((length + 1) * sizeof(WCHAR));
- if (!BasePath)
+ if (!GetModuleFileNameA(NULL, LibraryPath, PATHCCH_MAX_CCH))
{
- _tprintf(_T("Memory allocation failed\n"));
+ printf("%s: GetModuleFilenameA failed: 0x%08X\n", __FUNCTION__, GetLastError());
return -1;
}
- MultiByteToWideChar(CP_UTF8, 0, str, length, (LPWSTR) BasePath, length * sizeof(WCHAR));
- BasePath[length] = 0;
-#else
- BasePath = _strdup(str);
- if (!BasePath)
+
+ /* PathCchRemoveFileSpec is not implemented in WinPR */
+
+ if (!(p = strrchr(LibraryPath, PathGetSeparatorA(PATH_STYLE_NATIVE))))
{
- printf("Memory allocation failed");
+ printf("%s: Error identifying module directory path\n", __FUNCTION__);
return -1;
}
+ *p = 0;
- length = strlen(BasePath);
-#endif
-
- CopyMemory(LibraryPath, BasePath, length * sizeof(TCHAR));
- LibraryPath[length] = 0;
-
- NativePathCchAppend(LibraryPath, PATHCCH_MAX_CCH, _T("TestLibraryA")); /* subdirectory */
-
-#else /* _WIN32 */
-
- /* On Windows the test libraries are in same folder as the test executable */
- GetModuleFileName(NULL, LibraryPath, PATHCCH_MAX_CCH);
- PathRemoveFileSpec(LibraryPath);
-#endif
-
- NativePathCchAppend(LibraryPath, PATHCCH_MAX_CCH, _T("TestLibraryA")); /* file name without extension */
-
- SharedLibraryExtension = PathGetSharedLibraryExtension(PATH_SHARED_LIB_EXT_WITH_DOT);
- NativePathCchAddExtension(LibraryPath, PATHCCH_MAX_CCH, SharedLibraryExtension); /* add shared library extension */
-
- _tprintf(_T("Loading Library: %s\n"), LibraryPath);
+ NativePathCchAppendA(LibraryPath, PATHCCH_MAX_CCH, "TestLibraryA");
+ SharedLibraryExtension = PathGetSharedLibraryExtensionA(PATH_SHARED_LIB_EXT_WITH_DOT);
+ NativePathCchAddExtensionA(LibraryPath, PATHCCH_MAX_CCH, SharedLibraryExtension);
- library = LoadLibrary(LibraryPath);
+ printf("%s: Loading Library: '%s'\n", __FUNCTION__, LibraryPath);
- if (!library)
+ if (!(library = LoadLibraryA(LibraryPath)))
{
- _tprintf(_T("LoadLibrary failure\n"));
+ printf("%s: LoadLibraryA failure: 0x%08X\n", __FUNCTION__, GetLastError());
return -1;
}
if (!FreeLibrary(library))
{
- _tprintf(_T("FreeLibrary failure\n"));
+ printf("%s: FreeLibrary failure: 0x%08X\n", __FUNCTION__, GetLastError());
return -1;
}