wtsapi: add TestWtsApiExtra

Move wtsapi tests that only make sense when run within a session
("interactive") to TestWtsApiExtra since they either brake automated
builds or don't make sense if the return value isn't checked.

TestWtsApiExtra is not build by default but can be enabled by specifying
-DTESTS_WTSAPI_EXTRA=ON (this option is only available if BUILD_TESTING
is enabled).

The tests set the ctest label WTSAPI_EXTRA and can therefore also
be run explicitly with ctest -L WTSAPI_EXTRA.
This commit is contained in:
Bernhard Miklautz 2015-02-10 18:05:40 +01:00
parent fc0a2e529d
commit 67fb97f68f
8 changed files with 157 additions and 14 deletions

View File

@ -1,3 +1,4 @@
include(CMakeDependentOption)
if((CMAKE_SYSTEM_PROCESSOR MATCHES "i386|i686|x86|AMD64") AND (CMAKE_SIZEOF_VOID_P EQUAL 4))
set(TARGET_ARCH "x86")
@ -59,6 +60,8 @@ endif()
option(WITH_SMARTCARD_INSPECT "Enable SmartCard API Inspector" OFF)
option(BUILD_TESTING "Build unit tests" OFF)
CMAKE_DEPENDENT_OPTION(TESTS_WTSAPI_EXTRA "Build extra WTSAPI tests (interactive)" OFF "BUILD_TESTING" ON)
option(WITH_SAMPLE "Build sample code" OFF)
option(WITH_CLIENT "Build client binaries" ON)

View File

@ -1,3 +1,4 @@
TestWtsApi
TestWtsApi.c
TestWtsApiExtra
TestWtsApiExtra.c

View File

@ -8,11 +8,10 @@ set(${MODULE_PREFIX}_TESTS
TestWtsApiEnumerateProcesses.c
TestWtsApiEnumerateSessions.c
TestWtsApiQuerySessionInformation.c
TestWtsApiLogoffSession.c
TestWtsApiShutdownSystem.c
TestWtsApiSessionNotification.c
TestWtsApiWaitSystemEvent.c
TestWtsApiVirtualChannel.c)
)
create_test_sourcelist(${MODULE_PREFIX}_SRCS
${${MODULE_PREFIX}_DRIVER}
@ -32,3 +31,36 @@ endforeach()
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Test")
if(TESTS_WTSAPI_EXTRA)
set(MODULE_NAME "TestWtsApiExtra")
set(MODULE_PREFIX "TEST_WTSAPI_EXTRA")
set(${MODULE_PREFIX}_DRIVER ${MODULE_NAME}.c)
set(${MODULE_PREFIX}_TESTS
TestWtsApiExtraDisconnectSession.c
TestWtsApiExtraDynamicVirtualChannel.c
TestWtsApiExtraLogoffSession.c
TestWtsApiExtraSendMessage.c
TestWtsApiExtraVirtualChannel.c
)
create_test_sourcelist(${MODULE_PREFIX}_SRCS
${${MODULE_PREFIX}_DRIVER}
${${MODULE_PREFIX}_TESTS})
add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS})
target_link_libraries(${MODULE_NAME} winpr)
set_target_properties(${MODULE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}")
foreach(test ${${MODULE_PREFIX}_TESTS})
get_filename_component(TestName ${test} NAME_WE)
add_test(${TestName} ${TESTING_OUTPUT_DIRECTORY}/${MODULE_NAME} ${TestName})
set_tests_properties(${TestName} PROPERTIES LABELS "WTSAPI_EXTRA")
endforeach()
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Test")
endif()

View File

@ -0,0 +1,22 @@
#include <winpr/crt.h>
#include <winpr/error.h>
#include <winpr/wtsapi.h>
int TestWtsApiExtraDisconnectSession(int argc, char* argv[])
{
BOOL bSuccess;
HANDLE hServer;
hServer = WTS_CURRENT_SERVER_HANDLE;
bSuccess = WTSDisconnectSession(hServer, WTS_CURRENT_SESSION, FALSE);
if (!bSuccess)
{
printf("WTSDisconnectSession failed: %d\n", (int) GetLastError());
return -1;
}
return 0;
}

View File

@ -0,0 +1,54 @@
#include <winpr/crt.h>
#include <winpr/error.h>
#include <winpr/wtsapi.h>
int TestWtsApiExtraDynamicVirtualChannel(int argc, char* argv[])
{
BOOL bSuccess;
ULONG length;
ULONG bytesRead;
ULONG bytesWritten;
BYTE buffer[1024];
HANDLE hVirtualChannel;
length = sizeof(buffer);
hVirtualChannel = WTSVirtualChannelOpenEx( WTS_CURRENT_SESSION, "ECHO",WTS_CHANNEL_OPTION_DYNAMIC);
if (hVirtualChannel == INVALID_HANDLE_VALUE)
{
printf("WTSVirtualChannelOpen failed: %d\n", (int) GetLastError());
return -1;
}
printf("WTSVirtualChannelOpen opend");
bytesWritten = 0;
bSuccess = WTSVirtualChannelWrite(hVirtualChannel, (PCHAR) buffer, length, &bytesWritten);
if (!bSuccess)
{
printf("WTSVirtualChannelWrite failed: %d\n", (int) GetLastError());
return -1;
}
printf("WTSVirtualChannelWrite written");
bytesRead = 0;
bSuccess = WTSVirtualChannelRead(hVirtualChannel, 5000, (PCHAR) buffer, length, &bytesRead);
if (!bSuccess)
{
printf("WTSVirtualChannelRead failed: %d\n", (int) GetLastError());
return -1;
}
printf("WTSVirtualChannelRead read");
if (!WTSVirtualChannelClose(hVirtualChannel))
{
printf("WTSVirtualChannelClose failed\n");
return -1;
}
return 0;
}

View File

@ -3,7 +3,7 @@
#include <winpr/error.h>
#include <winpr/wtsapi.h>
int TestWtsApiLogoffSession(int argc, char* argv[])
int TestWtsApiExtraLogoffSession(int argc, char* argv[])
{
BOOL bSuccess;
HANDLE hServer;
@ -12,12 +12,12 @@ int TestWtsApiLogoffSession(int argc, char* argv[])
sessionId = 123;
hServer = WTS_CURRENT_SERVER_HANDLE;
bSuccess = WTSLogoffSession(hServer, sessionId, FALSE);
bSuccess = WTSLogoffSession(hServer, WTS_CURRENT_SESSION, FALSE);
if (!bSuccess)
{
printf("WTSLogoffSession failed: %d\n", (int) GetLastError());
//return -1;
return -1;
}
return 0;

View File

@ -0,0 +1,29 @@
#include <winpr/crt.h>
#include <winpr/error.h>
#include <winpr/wtsapi.h>
#include <winpr/user.h>
#define TITLE "thats the title"
#define MESSAGE "thats the message"
int TestWtsApiExtraSendMessage(int argc, char* argv[])
{
BOOL bSuccess;
HANDLE hServer;
DWORD result;
hServer = WTS_CURRENT_SERVER_HANDLE;
bSuccess = WTSSendMessage(hServer, WTS_CURRENT_SESSION,TITLE,strlen(TITLE) + 1, MESSAGE, strlen(MESSAGE) + 1, MB_CANCELTRYCONTINUE, 3 , &result,TRUE);
if (!bSuccess)
{
printf("WTSSendMessage failed: %d\n", (int) GetLastError());
return -1;
}
printf("WTSSendMessage got result: %d\n", (int) result);
return 0;
}

View File

@ -3,7 +3,7 @@
#include <winpr/error.h>
#include <winpr/wtsapi.h>
int TestWtsApiVirtualChannel(int argc, char* argv[])
int TestWtsApiExtraVirtualChannel(int argc, char* argv[])
{
BOOL bSuccess;
ULONG length;
@ -14,22 +14,23 @@ int TestWtsApiVirtualChannel(int argc, char* argv[])
length = sizeof(buffer);
hVirtualChannel = WTSVirtualChannelOpen(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, "RDPDBG");
hVirtualChannel = WTSVirtualChannelOpen(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, "sample");
if (!hVirtualChannel)
if (hVirtualChannel == INVALID_HANDLE_VALUE)
{
printf("WTSVirtualChannelOpen failed: %d\n", (int) GetLastError());
//return -1;
return -1;
}
printf("WTSVirtualChannelOpen opend");
bytesWritten = 0;
bSuccess = WTSVirtualChannelWrite(hVirtualChannel, (PCHAR) buffer, length, &bytesWritten);
if (!bSuccess)
{
printf("WTSVirtualChannelWrite failed: %d\n", (int) GetLastError());
//return -1;
return -1;
}
printf("WTSVirtualChannelWrite written");
bytesRead = 0;
bSuccess = WTSVirtualChannelRead(hVirtualChannel, 5000, (PCHAR) buffer, length, &bytesRead);
@ -37,13 +38,14 @@ int TestWtsApiVirtualChannel(int argc, char* argv[])
if (!bSuccess)
{
printf("WTSVirtualChannelRead failed: %d\n", (int) GetLastError());
//return -1;
return -1;
}
printf("WTSVirtualChannelRead read");
if (!WTSVirtualChannelClose(hVirtualChannel))
{
printf("WTSVirtualChannelClose failed\n");
//return -1;
return -1;
}
return 0;