Milestone 5: deliver embedded RDP sessions and lifecycle hardening
This commit is contained in:
30
third_party/FreeRDP/winpr/libwinpr/library/test/CMakeLists.txt
vendored
Normal file
30
third_party/FreeRDP/winpr/libwinpr/library/test/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
add_subdirectory(TestLibraryA)
|
||||
add_subdirectory(TestLibraryB)
|
||||
|
||||
set(MODULE_NAME "TestLibrary")
|
||||
set(MODULE_PREFIX "TEST_LIBRARY")
|
||||
|
||||
disable_warnings_for_directory(${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
set(${MODULE_PREFIX}_DRIVER ${MODULE_NAME}.c)
|
||||
|
||||
set(${MODULE_PREFIX}_TESTS TestLibraryLoadLibrary.c TestLibraryGetProcAddress.c TestLibraryGetModuleFileName.c)
|
||||
|
||||
create_test_sourcelist(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_DRIVER} ${${MODULE_PREFIX}_TESTS})
|
||||
|
||||
add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS})
|
||||
|
||||
add_dependencies(${MODULE_NAME} TestLibraryA TestLibraryB)
|
||||
|
||||
target_link_libraries(${MODULE_NAME} winpr)
|
||||
|
||||
set_target_properties(${MODULE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}")
|
||||
|
||||
set(TEST_AREA "${MODULE_NAME}Area")
|
||||
|
||||
foreach(test ${${MODULE_PREFIX}_TESTS})
|
||||
get_filename_component(TestName ${test} NAME_WE)
|
||||
add_test(${TestName} ${TESTING_OUTPUT_DIRECTORY}/${MODULE_NAME} ${TestName})
|
||||
endforeach()
|
||||
|
||||
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Test")
|
||||
30
third_party/FreeRDP/winpr/libwinpr/library/test/TestLibraryA/CMakeLists.txt
vendored
Normal file
30
third_party/FreeRDP/winpr/libwinpr/library/test/TestLibraryA/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
# 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")
|
||||
set(MODULE_PREFIX "TEST_LIBRARY_A")
|
||||
|
||||
set(SRCS TestLibraryA.c)
|
||||
|
||||
add_library(${MODULE_NAME} SHARED ${SRCS})
|
||||
set_target_properties(${MODULE_NAME} PROPERTIES PREFIX "")
|
||||
set_target_properties(
|
||||
${MODULE_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}" RUNTIME_OUTPUT_DIRECTORY
|
||||
"${TESTING_OUTPUT_DIRECTORY}"
|
||||
)
|
||||
|
||||
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Test/Extra")
|
||||
14
third_party/FreeRDP/winpr/libwinpr/library/test/TestLibraryA/TestLibraryA.c
vendored
Normal file
14
third_party/FreeRDP/winpr/libwinpr/library/test/TestLibraryA/TestLibraryA.c
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <winpr/spec.h>
|
||||
|
||||
DECLSPEC_EXPORT int FunctionA(int a, int b);
|
||||
DECLSPEC_EXPORT 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 */
|
||||
}
|
||||
31
third_party/FreeRDP/winpr/libwinpr/library/test/TestLibraryB/CMakeLists.txt
vendored
Normal file
31
third_party/FreeRDP/winpr/libwinpr/library/test/TestLibraryB/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
# 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")
|
||||
set(MODULE_PREFIX "TEST_LIBRARY_B")
|
||||
|
||||
set(SRCS TestLibraryB.c)
|
||||
|
||||
add_library(${MODULE_NAME} SHARED ${SRCS})
|
||||
|
||||
set_target_properties(${MODULE_NAME} PROPERTIES PREFIX "")
|
||||
set_target_properties(
|
||||
${MODULE_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}" RUNTIME_OUTPUT_DIRECTORY
|
||||
"${TESTING_OUTPUT_DIRECTORY}"
|
||||
)
|
||||
|
||||
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Test/Extra")
|
||||
14
third_party/FreeRDP/winpr/libwinpr/library/test/TestLibraryB/TestLibraryB.c
vendored
Normal file
14
third_party/FreeRDP/winpr/libwinpr/library/test/TestLibraryB/TestLibraryB.c
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <winpr/spec.h>
|
||||
|
||||
DECLSPEC_EXPORT int FunctionA(int a, int b);
|
||||
DECLSPEC_EXPORT 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 */
|
||||
}
|
||||
56
third_party/FreeRDP/winpr/libwinpr/library/test/TestLibraryGetModuleFileName.c
vendored
Normal file
56
third_party/FreeRDP/winpr/libwinpr/library/test/TestLibraryGetModuleFileName.c
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
|
||||
#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 = 0;
|
||||
WINPR_UNUSED(argc);
|
||||
WINPR_UNUSED(argv);
|
||||
/* Test insufficient buffer size behaviour */
|
||||
SetLastError(ERROR_SUCCESS);
|
||||
len = GetModuleFileNameA(nullptr, ModuleFileName, 2);
|
||||
if (len != 2)
|
||||
{
|
||||
printf("%s: GetModuleFileNameA unexpectedly returned %" PRIu32 " instead of 2\n", __func__,
|
||||
len);
|
||||
return -1;
|
||||
}
|
||||
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
|
||||
{
|
||||
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(nullptr, ModuleFileName, sizeof(ModuleFileName));
|
||||
if (len == 0)
|
||||
{
|
||||
printf("%s: GetModuleFileNameA failed with error 0x%08" PRIX32 "\n", __func__,
|
||||
GetLastError());
|
||||
return -1;
|
||||
}
|
||||
if (len == sizeof(ModuleFileName))
|
||||
{
|
||||
printf("%s: GetModuleFileNameA unexpectedly returned nSize\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
if (GetLastError() != ERROR_SUCCESS)
|
||||
{
|
||||
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;
|
||||
}
|
||||
105
third_party/FreeRDP/winpr/libwinpr/library/test/TestLibraryGetProcAddress.c
vendored
Normal file
105
third_party/FreeRDP/winpr/libwinpr/library/test/TestLibraryGetProcAddress.c
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/path.h>
|
||||
#include <winpr/tchar.h>
|
||||
#include <winpr/windows.h>
|
||||
#include <winpr/library.h>
|
||||
#include <winpr/nt.h>
|
||||
|
||||
typedef int (*TEST_AB_FN)(int a, int b);
|
||||
|
||||
int TestLibraryGetProcAddress(int argc, char* argv[])
|
||||
{
|
||||
int a = 0;
|
||||
int b = 0;
|
||||
int c = 0;
|
||||
HINSTANCE library = nullptr;
|
||||
TEST_AB_FN pFunctionA = nullptr;
|
||||
TEST_AB_FN pFunctionB = nullptr;
|
||||
LPCSTR SharedLibraryExtension = nullptr;
|
||||
CHAR LibraryPath[PATHCCH_MAX_CCH] = WINPR_C_ARRAY_INIT;
|
||||
PCHAR p = nullptr;
|
||||
WINPR_UNUSED(argc);
|
||||
WINPR_UNUSED(argv);
|
||||
if (!GetModuleFileNameA(nullptr, LibraryPath, PATHCCH_MAX_CCH))
|
||||
{
|
||||
const UINT32 err = GetLastError();
|
||||
const HRESULT herr = HRESULT_FROM_WIN32(err);
|
||||
printf("%s: GetModuleFilenameA failed: %s - %s [0x%08" PRIX32 "]\n", __func__,
|
||||
NtStatus2Tag(herr), Win32ErrorCode2Tag(err), err);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* PathCchRemoveFileSpec is not implemented in WinPR */
|
||||
|
||||
if (!(p = strrchr(LibraryPath, PathGetSeparatorA(PATH_STYLE_NATIVE))))
|
||||
{
|
||||
printf("%s: Error identifying module directory path\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*p = 0;
|
||||
NativePathCchAppendA(LibraryPath, PATHCCH_MAX_CCH, "TestLibraryA");
|
||||
SharedLibraryExtension = PathGetSharedLibraryExtensionA(PATH_SHARED_LIB_EXT_WITH_DOT);
|
||||
NativePathCchAddExtensionA(LibraryPath, PATHCCH_MAX_CCH, SharedLibraryExtension);
|
||||
printf("%s: Loading Library: '%s'\n", __func__, LibraryPath);
|
||||
|
||||
if (!(library = LoadLibraryA(LibraryPath)))
|
||||
{
|
||||
const UINT32 err = GetLastError();
|
||||
const HRESULT herr = HRESULT_FROM_WIN32(err);
|
||||
printf("%s: LoadLibraryA failure: %s - %s [0x%08" PRIX32 "]\n", __func__,
|
||||
NtStatus2Tag(herr), Win32ErrorCode2Tag(err), err);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!(pFunctionA = GetProcAddressAs(library, "FunctionA", TEST_AB_FN)))
|
||||
{
|
||||
const UINT32 err = GetLastError();
|
||||
const HRESULT herr = HRESULT_FROM_WIN32(err);
|
||||
printf("%s: GetProcAddress failure (FunctionA) %s - %s [0x%08" PRIX32 "]\n", __func__,
|
||||
NtStatus2Tag(herr), Win32ErrorCode2Tag(err), err);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!(pFunctionB = GetProcAddressAs(library, "FunctionB", TEST_AB_FN)))
|
||||
{
|
||||
const UINT32 err = GetLastError();
|
||||
const HRESULT herr = HRESULT_FROM_WIN32(err);
|
||||
printf("%s: GetProcAddress failure (FunctionB) %s - %s [0x%08" PRIX32 "]\n", __func__,
|
||||
NtStatus2Tag(herr), Win32ErrorCode2Tag(err), err);
|
||||
return -1;
|
||||
}
|
||||
|
||||
a = 2;
|
||||
b = 3;
|
||||
c = pFunctionA(a, b); /* LibraryA / FunctionA multiplies a and b */
|
||||
|
||||
if (c != (a * b))
|
||||
{
|
||||
printf("%s: pFunctionA call failed\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
a = 10;
|
||||
b = 5;
|
||||
c = pFunctionB(a, b); /* LibraryA / FunctionB divides a by b */
|
||||
|
||||
if (c != (a / b))
|
||||
{
|
||||
printf("%s: pFunctionB call failed\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!FreeLibrary(library))
|
||||
{
|
||||
const UINT32 err = GetLastError();
|
||||
const HRESULT herr = HRESULT_FROM_WIN32(err);
|
||||
printf("%s: FreeLibrary failure: %s - %s [0x%08" PRIX32 "]\n", __func__, NtStatus2Tag(herr),
|
||||
Win32ErrorCode2Tag(err), err);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
61
third_party/FreeRDP/winpr/libwinpr/library/test/TestLibraryLoadLibrary.c
vendored
Normal file
61
third_party/FreeRDP/winpr/libwinpr/library/test/TestLibraryLoadLibrary.c
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/path.h>
|
||||
#include <winpr/tchar.h>
|
||||
#include <winpr/windows.h>
|
||||
#include <winpr/library.h>
|
||||
#include <winpr/nt.h>
|
||||
|
||||
int TestLibraryLoadLibrary(int argc, char* argv[])
|
||||
{
|
||||
HINSTANCE library = nullptr;
|
||||
LPCSTR SharedLibraryExtension = nullptr;
|
||||
CHAR LibraryPath[PATHCCH_MAX_CCH] = WINPR_C_ARRAY_INIT;
|
||||
PCHAR p = nullptr;
|
||||
WINPR_UNUSED(argc);
|
||||
WINPR_UNUSED(argv);
|
||||
if (!GetModuleFileNameA(nullptr, LibraryPath, PATHCCH_MAX_CCH))
|
||||
{
|
||||
const UINT32 err = GetLastError();
|
||||
const HRESULT herr = HRESULT_FROM_WIN32(err);
|
||||
printf("%s: GetModuleFilenameA failed: %s - %s [0x%08" PRIX32 "]\n", __func__,
|
||||
NtStatus2Tag(herr), Win32ErrorCode2Tag(err), err);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* PathCchRemoveFileSpec is not implemented in WinPR */
|
||||
|
||||
if (!(p = strrchr(LibraryPath, PathGetSeparatorA(PATH_STYLE_NATIVE))))
|
||||
{
|
||||
printf("%s: Error identifying module directory path\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
*p = 0;
|
||||
|
||||
NativePathCchAppendA(LibraryPath, PATHCCH_MAX_CCH, "TestLibraryA");
|
||||
SharedLibraryExtension = PathGetSharedLibraryExtensionA(PATH_SHARED_LIB_EXT_WITH_DOT);
|
||||
NativePathCchAddExtensionA(LibraryPath, PATHCCH_MAX_CCH, SharedLibraryExtension);
|
||||
|
||||
printf("%s: Loading Library: '%s'\n", __func__, LibraryPath);
|
||||
|
||||
if (!(library = LoadLibraryA(LibraryPath)))
|
||||
{
|
||||
const UINT32 err = GetLastError();
|
||||
const HRESULT herr = HRESULT_FROM_WIN32(err);
|
||||
printf("%s: LoadLibraryA failure: %s - %s [0x%08" PRIX32 "]\n", __func__,
|
||||
NtStatus2Tag(herr), Win32ErrorCode2Tag(err), err);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!FreeLibrary(library))
|
||||
{
|
||||
const UINT32 err = GetLastError();
|
||||
const HRESULT herr = HRESULT_FROM_WIN32(err);
|
||||
printf("%s: FreeLibrary failure: %s - %s [0x%08" PRIX32 "]\n", __func__, NtStatus2Tag(herr),
|
||||
Win32ErrorCode2Tag(err), err);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user