libwinpr: wrote more tests

This commit is contained in:
Marc-André Moreau 2012-10-04 23:19:05 -04:00
parent 94469ffa6f
commit 56ea938fbf
14 changed files with 231 additions and 5 deletions

View File

@ -23,6 +23,7 @@ endif()
option(WITH_CLIENT "Build client binaries" ON)
option(WITH_SERVER "Build server binaries" OFF)
option(WITH_CHANNELS "Build virtual channel plugins" ON)
if(WITH_CLIENT AND WITH_CHANNELS)

View File

@ -33,6 +33,11 @@
#ifndef _WIN32
#ifndef _ERRNO_T_DEFINED
#define _ERRNO_T_DEFINED
typedef int errno_t;
#endif
WINPR_API void* _aligned_malloc(size_t size, size_t alignment);
WINPR_API void* _aligned_realloc(void* memblock, size_t size, size_t alignment);
WINPR_API void* _aligned_recalloc(void* memblock, size_t num, size_t size, size_t alignment);

View File

@ -40,11 +40,13 @@ typedef CHAR TCHAR;
#define _tcsdup _wcsdup
#define _tcscmp wcscmp
#define _tcscpy wcscpy
#define _stprintf_s swprintf_s
#else
#define _tprintf printf
#define _tcsdup _strdup
#define _tcscmp strcmp
#define _tcscpy strcpy
#define _stprintf_s sprintf_s
#endif
#endif

View File

@ -21,6 +21,10 @@ set(MODULE_PREFIX "WINPR_LIBRARY")
set(${MODULE_PREFIX}_SRCS
library.c)
if(MSVC AND (NOT WITH_MONOLITHIC_BUILD))
set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} module.def)
endif()
if(WITH_MONOLITHIC_BUILD)
add_library(${MODULE_NAME} OBJECT ${${MODULE_PREFIX}_SRCS})
else()

View File

@ -0,0 +1,3 @@
LIBRARY "libwinpr-library"
EXPORTS

View File

@ -18,13 +18,14 @@ create_test_sourcelist(${MODULE_PREFIX}_SRCS
add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS})
if(NOT WIN32)
target_link_libraries(${MODULE_NAME} winpr-library)
endif()
target_link_libraries(${MODULE_NAME} winpr-library winpr-path)
foreach(test ${${MODULE_PREFIX}_TESTS})
get_filename_component(TestName ${test} NAME_WE)
add_test(${TestName} ${EXECUTABLE_OUTPUT_PATH}/${MODULE_NAME} ${TestName})
add_test(${TestName} ${EXECUTABLE_OUTPUT_PATH}/${MODULE_NAME} ${TestName} ${EXECUTABLE_OUTPUT_PATH})
endforeach()
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Test")
add_subdirectory(TestLibraryA)
add_subdirectory(TestLibraryB)

View File

@ -0,0 +1,22 @@
# WinPR: Windows Portable Runtime
# libwinpr-library cmake build script
#
# Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set(MODULE_NAME "TestLibraryA")
add_library(${MODULE_NAME} TestLibraryA.c)
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Test/Extra")

View File

@ -0,0 +1,19 @@
#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);
int FunctionA(int a, int b)
{
return (a * b); /* multiply */
}
int FunctionB(int a, int b)
{
return (a / b); /* divide */
}

View File

@ -0,0 +1,22 @@
# WinPR: Windows Portable Runtime
# libwinpr-library cmake build script
#
# Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set(MODULE_NAME "TestLibraryB")
add_library(${MODULE_NAME} TestLibraryB.c)
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Test/Extra")

View File

@ -0,0 +1,19 @@
#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);
int FunctionA(int a, int b)
{
return (a + b); /* add */
}
int FunctionB(int a, int b)
{
return (a - b); /* subtract */
}

View File

@ -2,9 +2,26 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/file.h>
#include <winpr/tchar.h>
#include <winpr/windows.h>
int TestLibraryFreeLibrary(int argc, char* argv[])
{
HINSTANCE library;
library = LoadLibrary(_T("kernel32.dll"));
if (!library)
{
printf("LoadLibrary failure\n");
return -1;
}
if (!FreeLibrary(library))
{
printf("FreeLibrary failure\n");
return -1;
}
return 0;
}

View File

@ -2,9 +2,50 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/file.h>
#include <winpr/path.h>
#include <winpr/tchar.h>
#include <winpr/windows.h>
int TestLibraryGetProcAddress(int argc, char* argv[])
{
char* str;
int length;
LPTSTR BasePath;
HINSTANCE library;
LPTSTR LibraryPath;
str = argv[1];
#ifdef UNICODE
length = MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), NULL, 0);
BasePath = (WCHAR*) malloc((length + 1) * sizeof(WCHAR));
MultiByteToWideChar(CP_UTF8, 0, str, length, (LPWSTR) BasePath, length * sizeof(WCHAR));
BasePath[length] = 0;
#else
BasePath = _strdup(path);
#endif
_tprintf(_T("Base Path: %s\n"), BasePath);
PathAllocCombine(BasePath, _T("TestLibraryA\\TestLibraryA.dll"), 0, &LibraryPath);
//_tprintf(_T("Loading Library: %s\n"), LibraryPath);
/*
library = LoadLibrary(LibraryPath);
if (!library)
{
printf("LoadLibrary failure\n");
return -1;
}
if (!FreeLibrary(library))
{
printf("FreeLibrary failure\n");
return -1;
}*/
return 0;
}

View File

@ -2,9 +2,26 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/file.h>
#include <winpr/tchar.h>
#include <winpr/windows.h>
int TestLibraryLoadLibrary(int argc, char* argv[])
{
HINSTANCE library;
library = LoadLibrary(_T("kernel32.dll"));
if (!library)
{
printf("LoadLibrary failure\n");
return -1;
}
if (!FreeLibrary(library))
{
printf("FreeLibrary failure\n");
return -1;
}
return 0;
}

View File

@ -21,7 +21,9 @@
#include "config.h"
#endif
#include <winpr/crt.h>
#include <winpr/heap.h>
#include <winpr/tchar.h>
#include <winpr/path.h>
@ -152,7 +154,58 @@ HRESULT PathAllocCombineA(PCSTR pszPathIn, PCSTR pszMore, unsigned long dwFlags,
HRESULT PathAllocCombineW(PCWSTR pszPathIn, PCWSTR pszMore, unsigned long dwFlags, PWSTR* ppszPathOut)
{
return 0;
PWSTR pszPathOut;
BOOL backslashIn;
BOOL backslashMore;
int pszMoreLength;
int pszPathInLength;
int pszPathOutLength;
if (!pszPathIn)
return S_FALSE;
if (!pszMore)
return S_FALSE;
pszPathInLength = lstrlenW(pszPathIn);
pszMoreLength = lstrlenW(pszMore);
backslashIn = (pszPathIn[pszPathInLength - 1] == '\\') ? TRUE : FALSE;
backslashMore = (pszMore[0] == '\\') ? TRUE : FALSE;
if (backslashMore)
{
if ((pszPathIn[1] == ':') && (pszPathIn[2] == '\\'))
{
size_t sizeOfBuffer;
pszPathOutLength = 2 + pszMoreLength;
sizeOfBuffer = (pszPathOutLength + 1) * 2;
pszPathOut = (PWSTR) HeapAlloc(GetProcessHeap(), 0, sizeOfBuffer * 2);
_stprintf_s(pszPathOut, sizeOfBuffer, _T("%c:%s"), pszPathIn[0], pszMore);
*ppszPathOut = pszPathOut;
return S_OK;
}
}
else if (backslashIn && !backslashMore)
{
size_t sizeOfBuffer;
pszPathOutLength = pszPathInLength + pszMoreLength;
sizeOfBuffer = (pszPathOutLength + 1) * 2;
pszPathOut = (PWSTR) HeapAlloc(GetProcessHeap(), 0, sizeOfBuffer * 2);
_stprintf_s(pszPathOut, sizeOfBuffer, _T("%s%s"), pszPathIn, pszMore);
*ppszPathOut = pszPathOut;
return S_OK;
}
return S_OK;
}
HRESULT PathCchFindExtensionA(PCSTR pszPath, size_t cchPath, PCSTR* ppszExt)