diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 01:24:41 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 01:24:41 +0000 |
commit | a9bcc81f821d7c66f623779fa5147e728eb3c388 (patch) | |
tree | 98676963bcdd537ae5908a067a8eb110b93486a6 /winpr/libwinpr/clipboard/test | |
parent | Initial commit. (diff) | |
download | freerdp3-a9bcc81f821d7c66f623779fa5147e728eb3c388.tar.xz freerdp3-a9bcc81f821d7c66f623779fa5147e728eb3c388.zip |
Adding upstream version 3.3.0+dfsg1.upstream/3.3.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'winpr/libwinpr/clipboard/test')
-rw-r--r-- | winpr/libwinpr/clipboard/test/CMakeLists.txt | 27 | ||||
-rw-r--r-- | winpr/libwinpr/clipboard/test/TestClipboardFormats.c | 82 | ||||
-rw-r--r-- | winpr/libwinpr/clipboard/test/TestUri.c | 69 |
3 files changed, 178 insertions, 0 deletions
diff --git a/winpr/libwinpr/clipboard/test/CMakeLists.txt b/winpr/libwinpr/clipboard/test/CMakeLists.txt new file mode 100644 index 0000000..90996c0 --- /dev/null +++ b/winpr/libwinpr/clipboard/test/CMakeLists.txt @@ -0,0 +1,27 @@ + +set(MODULE_NAME "TestClipboard") +set(MODULE_PREFIX "TEST_CLIPBOARD") + +set(${MODULE_PREFIX}_DRIVER ${MODULE_NAME}.c) + +set(${MODULE_PREFIX}_TESTS + TestUri.c + TestClipboardFormats.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}) +endforeach() + +set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Test") + diff --git a/winpr/libwinpr/clipboard/test/TestClipboardFormats.c b/winpr/libwinpr/clipboard/test/TestClipboardFormats.c new file mode 100644 index 0000000..615f8a0 --- /dev/null +++ b/winpr/libwinpr/clipboard/test/TestClipboardFormats.c @@ -0,0 +1,82 @@ + +#include <winpr/crt.h> +#include <winpr/print.h> +#include <winpr/clipboard.h> + +int TestClipboardFormats(int argc, char* argv[]) +{ + UINT32 count = 0; + UINT32* pFormatIds = NULL; + const char* formatName = NULL; + wClipboard* clipboard = NULL; + UINT32 utf8StringFormatId = 0; + + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + + clipboard = ClipboardCreate(); + if (!clipboard) + return -1; + + ClipboardRegisterFormat(clipboard, "text/html"); + ClipboardRegisterFormat(clipboard, "image/bmp"); + ClipboardRegisterFormat(clipboard, "image/png"); + + utf8StringFormatId = ClipboardRegisterFormat(clipboard, "UTF8_STRING"); + pFormatIds = NULL; + count = ClipboardGetRegisteredFormatIds(clipboard, &pFormatIds); + + for (UINT32 index = 0; index < count; index++) + { + UINT32 formatId = pFormatIds[index]; + formatName = ClipboardGetFormatName(clipboard, formatId); + fprintf(stderr, "Format: 0x%08" PRIX32 " %s\n", formatId, formatName); + } + + free(pFormatIds); + + if (1) + { + BOOL bSuccess = 0; + UINT32 SrcSize = 0; + UINT32 DstSize = 0; + const char pSrcData[] = "this is a test string"; + char* pDstData = NULL; + + SrcSize = (UINT32)(strnlen(pSrcData, ARRAYSIZE(pSrcData)) + 1); + bSuccess = ClipboardSetData(clipboard, utf8StringFormatId, pSrcData, SrcSize); + fprintf(stderr, "ClipboardSetData: %" PRId32 "\n", bSuccess); + DstSize = 0; + pDstData = (char*)ClipboardGetData(clipboard, utf8StringFormatId, &DstSize); + fprintf(stderr, "ClipboardGetData: %s\n", pDstData); + free(pDstData); + } + + if (1) + { + UINT32 DstSize = 0; + char* pSrcData = NULL; + WCHAR* pDstData = NULL; + DstSize = 0; + pDstData = (WCHAR*)ClipboardGetData(clipboard, CF_UNICODETEXT, &DstSize); + pSrcData = ConvertWCharNToUtf8Alloc(pDstData, DstSize / sizeof(WCHAR), NULL); + + fprintf(stderr, "ClipboardGetData (synthetic): %s\n", pSrcData); + free(pDstData); + free(pSrcData); + } + + pFormatIds = NULL; + count = ClipboardGetFormatIds(clipboard, &pFormatIds); + + for (UINT32 index = 0; index < count; index++) + { + UINT32 formatId = pFormatIds[index]; + formatName = ClipboardGetFormatName(clipboard, formatId); + fprintf(stderr, "Format: 0x%08" PRIX32 " %s\n", formatId, formatName); + } + + free(pFormatIds); + ClipboardDestroy(clipboard); + return 0; +} diff --git a/winpr/libwinpr/clipboard/test/TestUri.c b/winpr/libwinpr/clipboard/test/TestUri.c new file mode 100644 index 0000000..c1cccd3 --- /dev/null +++ b/winpr/libwinpr/clipboard/test/TestUri.c @@ -0,0 +1,69 @@ + +#include <stdio.h> +#include <string.h> +#include <memory.h> +#include <stdlib.h> +#include <winpr/winpr.h> +#include "winpr/wlog.h" + +#include "../clipboard.h" + +#define WINPR_TAG(tag) "com.winpr." tag +#define TAG WINPR_TAG("clipboard.posix") + +int TestUri(int argc, char* argv[]) +{ + int nRet = 0; + const char* input[] = { /*uri, file or NULL*/ + "file://root/a.txt", + NULL, + "file:a.txt", + NULL, + "file:///c:/windows/a.txt", + "c:/windows/a.txt", + "file:c:/windows/a.txt", + "c:/windows/a.txt", + "file:c|/windows/a.txt", + "c:/windows/a.txt", + "file:///root/a.txt", + "/root/a.txt", + "file:/root/a.txt", + "/root/a.txt" + }; + + const size_t nLen = ARRAYSIZE(input); + + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + + printf("input length:%" PRIuz "\n", nLen / 2); + + for (size_t i = 0; i < nLen; i += 2) + { + const char* in = input[i]; + const char* cmp = input[i + 1]; + int bTest = 0; + char* name = parse_uri_to_local_file(in, strlen(in)); + if (name) + { + bTest = !strcmp(name, cmp); + if (!bTest) + { + printf("Test error: input: %s; Expected value: %s; output: %s\n", in, cmp, name); + nRet++; + } + free(name); + } + else + { + if (cmp) + { + printf("Test error: input: %s; Expected value: %s; output: %s\n", in, cmp, name); + nRet++; + } + } + } + + printf("TestUri return value: %d\n", nRet); + return nRet; +} |