winpr/library: fix win32 test and some cleanup
authorNorbert Federa <norbert.federa@thincast.com>
Thu, 26 May 2016 10:19:36 +0000 (12:19 +0200)
committerNorbert Federa <norbert.federa@thincast.com>
Fri, 27 May 2016 12:34:41 +0000 (14:34 +0200)
On Windows we seem to have to load the TestLibrary[AB] test libraries
from in same folder the test executable runs.

Also removed the empty RemoveDllDirectory, SetDefaultDllDirectories,
AddDllDirectory tests and the redundant FreeLibrary test.

TestLibrary now works and succeeds on Win32.

sadasd

winpr/libwinpr/library/test/CMakeLists.txt
winpr/libwinpr/library/test/TestLibraryA/TestLibraryA.c
winpr/libwinpr/library/test/TestLibraryAddDllDirectory.c [deleted file]
winpr/libwinpr/library/test/TestLibraryB/TestLibraryB.c
winpr/libwinpr/library/test/TestLibraryFreeLibrary.c [deleted file]
winpr/libwinpr/library/test/TestLibraryGetProcAddress.c
winpr/libwinpr/library/test/TestLibraryLoadLibrary.c
winpr/libwinpr/library/test/TestLibraryRemoveDllDirectory.c [deleted file]
winpr/libwinpr/library/test/TestLibrarySetDefaultDllDirectories.c [deleted file]

index 2962663..ca57ad3 100644 (file)
@@ -5,11 +5,7 @@ set(MODULE_PREFIX "TEST_LIBRARY")
 set(${MODULE_PREFIX}_DRIVER ${MODULE_NAME}.c)
 
 set(${MODULE_PREFIX}_TESTS
-       TestLibraryAddDllDirectory.c
-       TestLibraryRemoveDllDirectory.c
-       TestLibrarySetDefaultDllDirectories.c
        TestLibraryLoadLibrary.c
-       TestLibraryFreeLibrary.c
        TestLibraryGetProcAddress.c
        TestLibraryGetModuleFileName.c)
 
index 3915531..d11bc4d 100644 (file)
@@ -1,12 +1,7 @@
+#include <winpr/spec.h>
 
-#include <stdio.h>
-#include <winpr/crt.h>
-#include <winpr/file.h>
-#include <winpr/tchar.h>
-#include <winpr/windows.h>
-
-WINPR_API int FunctionA(int a, int b);
-WINPR_API int FunctionB(int a, int b);
+DECLSPEC_EXPORT int FunctionA(int a, int b);
+DECLSPEC_EXPORT int FunctionB(int a, int b);
 
 int FunctionA(int a, int b)
 {
diff --git a/winpr/libwinpr/library/test/TestLibraryAddDllDirectory.c b/winpr/libwinpr/library/test/TestLibraryAddDllDirectory.c
deleted file mode 100644 (file)
index 0c1c7c4..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-
-#include <stdio.h>
-#include <winpr/crt.h>
-#include <winpr/file.h>
-#include <winpr/tchar.h>
-#include <winpr/windows.h>
-#include <winpr/library.h>
-
-int TestLibraryAddDllDirectory(int argc, char* argv[])
-{
-       return 0;
-}
index 7fb9633..eac586e 100644 (file)
@@ -1,12 +1,7 @@
+#include <winpr/spec.h>
 
-#include <stdio.h>
-#include <winpr/crt.h>
-#include <winpr/file.h>
-#include <winpr/tchar.h>
-#include <winpr/windows.h>
-
-WINPR_API int FunctionA(int a, int b);
-WINPR_API int FunctionB(int a, int b);
+DECLSPEC_EXPORT int FunctionA(int a, int b);
+DECLSPEC_EXPORT int FunctionB(int a, int b);
 
 int FunctionA(int a, int b)
 {
diff --git a/winpr/libwinpr/library/test/TestLibraryFreeLibrary.c b/winpr/libwinpr/library/test/TestLibraryFreeLibrary.c
deleted file mode 100644 (file)
index a909884..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-
-#include <stdio.h>
-#include <winpr/crt.h>
-#include <winpr/path.h>
-#include <winpr/tchar.h>
-#include <winpr/windows.h>
-#include <winpr/library.h>
-
-int TestLibraryFreeLibrary(int argc, char* argv[])
-{
-       char* str;
-       int length;
-       LPTSTR BasePath;
-       HINSTANCE library;
-       LPCTSTR SharedLibraryExtension;
-       TCHAR LibraryPath[PATHCCH_MAX_CCH];
-
-       str = argv[1];
-
-#ifdef UNICODE
-       length = MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), NULL, 0);
-       BasePath = (WCHAR*) malloc((length + 1) * sizeof(WCHAR));
-       if (!BasePath)
-       {
-               _tprintf(_T("Memory allocation failed\n"));
-               return -1;
-       }
-       MultiByteToWideChar(CP_UTF8, 0, str, length, (LPWSTR) BasePath, length * sizeof(WCHAR));
-       BasePath[length] = 0;
-#else
-       BasePath = _strdup(str);
-       if (!BasePath)
-       {
-               printf("Memory allocation failed");
-               return -1;
-       }
-       length = strlen(BasePath);
-#endif
-
-       CopyMemory(LibraryPath, BasePath, length * sizeof(TCHAR));
-       LibraryPath[length] = 0;
-
-       NativePathCchAppend(LibraryPath, PATHCCH_MAX_CCH, _T("TestLibraryA")); /* subdirectory */
-       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);
-
-       library = LoadLibrary(LibraryPath);
-
-       if (!library)
-       {
-               _tprintf(_T("LoadLibrary failure\n"));
-               return -1;
-       }
-
-       if (!FreeLibrary(library))
-       {
-               _tprintf(_T("FreeLibrary failure\n"));
-               return -1;
-       }
-
-       return 0;
-}
index ff0303f..47f145a 100644 (file)
@@ -10,16 +10,18 @@ typedef int (*TEST_AB_FN)(int a, int b);
 
 int TestLibraryGetProcAddress(int argc, char* argv[])
 {
-       char* str;
-       int length;
        int a, b, c;
-       LPTSTR BasePath;
        HINSTANCE library;
        TEST_AB_FN pFunctionA;
        TEST_AB_FN pFunctionB;
        LPCTSTR SharedLibraryExtension;
        TCHAR LibraryPath[PATHCCH_MAX_CCH];
 
+#ifndef _WIN32
+       char* str;
+       int length;
+       LPTSTR BasePath;
+
        str = argv[1];
 
 #ifdef UNICODE
@@ -46,6 +48,14 @@ int TestLibraryGetProcAddress(int argc, char* argv[])
        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);
index 9256a38..084fb81 100644 (file)
@@ -8,13 +8,14 @@
 
 int TestLibraryLoadLibrary(int argc, char* argv[])
 {
-       char* str;
-       int length;
-       LPTSTR BasePath;
        HINSTANCE library;
        LPCTSTR SharedLibraryExtension;
        TCHAR LibraryPath[PATHCCH_MAX_CCH];
 
+#ifndef _WIN32
+       char* str;
+       int length;
+       LPTSTR BasePath;
        str = argv[1];
 
 #ifdef UNICODE
@@ -42,6 +43,14 @@ int TestLibraryLoadLibrary(int argc, char* argv[])
        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);
diff --git a/winpr/libwinpr/library/test/TestLibraryRemoveDllDirectory.c b/winpr/libwinpr/library/test/TestLibraryRemoveDllDirectory.c
deleted file mode 100644 (file)
index bf77956..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-
-#include <stdio.h>
-#include <winpr/crt.h>
-#include <winpr/file.h>
-#include <winpr/tchar.h>
-#include <winpr/windows.h>
-#include <winpr/library.h>
-
-int TestLibraryRemoveDllDirectory(int argc, char* argv[])
-{
-       return 0;
-}
diff --git a/winpr/libwinpr/library/test/TestLibrarySetDefaultDllDirectories.c b/winpr/libwinpr/library/test/TestLibrarySetDefaultDllDirectories.c
deleted file mode 100644 (file)
index 86cd92d..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-
-#include <stdio.h>
-#include <winpr/crt.h>
-#include <winpr/file.h>
-#include <winpr/tchar.h>
-#include <winpr/windows.h>
-#include <winpr/library.h>
-
-int TestLibrarySetDefaultDllDirectories(int argc, char* argv[])
-{
-       return 0;
-}