mirror of
https://github.com/FreeRDP/FreeRDP.git
synced 2025-06-03 00:00:20 +00:00
[winpr,clipboard] add image clipboard tests
This commit is contained in:
parent
bc4022eb3b
commit
7dfdadbe53
@ -8,6 +8,20 @@ set(${MODULE_PREFIX}_TESTS
|
|||||||
TestUri.c
|
TestUri.c
|
||||||
TestClipboardFormats.c)
|
TestClipboardFormats.c)
|
||||||
|
|
||||||
|
set(TEST_CLIP_PNG "${CMAKE_SOURCE_DIR}/resources/FreeRDP_Icon.png")
|
||||||
|
file(TO_NATIVE_PATH "${TEST_CLIP_PNG}" TEST_CLIP_PNG)
|
||||||
|
|
||||||
|
set(TEST_CLIP_BMP "${CMAKE_SOURCE_DIR}/resources/FreeRDP_Install.bmp")
|
||||||
|
file(TO_NATIVE_PATH "${TEST_CLIP_BMP}" TEST_CLIP_BMP)
|
||||||
|
|
||||||
|
if (WIN32)
|
||||||
|
string(REPLACE "\\" "\\\\" TEST_CLIP_PNG "${TEST_CLIP_PNG}")
|
||||||
|
string(REPLACE "\\" "\\\\" TEST_CLIP_BMP "${TEST_CLIP_BMP}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_definitions(-DTEST_CLIP_BMP="${TEST_CLIP_BMP}")
|
||||||
|
add_definitions(-DTEST_CLIP_PNG="${TEST_CLIP_PNG}")
|
||||||
|
|
||||||
create_test_sourcelist(${MODULE_PREFIX}_SRCS
|
create_test_sourcelist(${MODULE_PREFIX}_SRCS
|
||||||
${${MODULE_PREFIX}_DRIVER}
|
${${MODULE_PREFIX}_DRIVER}
|
||||||
${${MODULE_PREFIX}_TESTS})
|
${${MODULE_PREFIX}_TESTS})
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
|
|
||||||
#include <winpr/crt.h>
|
#include <winpr/crt.h>
|
||||||
#include <winpr/print.h>
|
#include <winpr/print.h>
|
||||||
|
#include <winpr/image.h>
|
||||||
#include <winpr/clipboard.h>
|
#include <winpr/clipboard.h>
|
||||||
|
|
||||||
int TestClipboardFormats(int argc, char* argv[])
|
int TestClipboardFormats(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
int rc = -1;
|
||||||
UINT32 count = 0;
|
UINT32 count = 0;
|
||||||
UINT32* pFormatIds = NULL;
|
UINT32* pFormatIds = NULL;
|
||||||
const char* formatName = NULL;
|
const char* formatName = NULL;
|
||||||
@ -18,9 +20,16 @@ int TestClipboardFormats(int argc, char* argv[])
|
|||||||
if (!clipboard)
|
if (!clipboard)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
ClipboardRegisterFormat(clipboard, "text/html");
|
const char* mime_types[] = { "text/html", "text/html", "image/bmp",
|
||||||
ClipboardRegisterFormat(clipboard, "image/bmp");
|
"image/png", "image/webp", "image/jpeg" };
|
||||||
ClipboardRegisterFormat(clipboard, "image/png");
|
for (size_t x = 0; x < ARRAYSIZE(mime_types); x++)
|
||||||
|
{
|
||||||
|
const char* mime = mime_types[x];
|
||||||
|
UINT32 id = ClipboardRegisterFormat(clipboard, mime);
|
||||||
|
fprintf(stderr, "ClipboardRegisterFormat(%s) -> 0x%08" PRIx32 "\n", mime, id);
|
||||||
|
if (id == 0)
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
utf8StringFormatId = ClipboardRegisterFormat(clipboard, "UTF8_STRING");
|
utf8StringFormatId = ClipboardRegisterFormat(clipboard, "UTF8_STRING");
|
||||||
pFormatIds = NULL;
|
pFormatIds = NULL;
|
||||||
@ -76,7 +85,140 @@ int TestClipboardFormats(int argc, char* argv[])
|
|||||||
fprintf(stderr, "Format: 0x%08" PRIX32 " %s\n", formatId, formatName);
|
fprintf(stderr, "Format: 0x%08" PRIX32 " %s\n", formatId, formatName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (1)
|
||||||
|
{
|
||||||
|
const char* name = TEST_CLIP_BMP;
|
||||||
|
BOOL bSuccess = FALSE;
|
||||||
|
UINT32 idBmp = ClipboardRegisterFormat(clipboard, "image/bmp");
|
||||||
|
|
||||||
|
wImage* img = winpr_image_new();
|
||||||
|
if (!img)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
if (winpr_image_read(img, name) <= 0)
|
||||||
|
{
|
||||||
|
winpr_image_free(img, TRUE);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t bmpsize = 0;
|
||||||
|
void* data = winpr_image_write_buffer(img, WINPR_IMAGE_BITMAP, &bmpsize);
|
||||||
|
bSuccess = ClipboardSetData(clipboard, idBmp, data, bmpsize);
|
||||||
|
fprintf(stderr, "ClipboardSetData: %" PRId32 "\n", bSuccess);
|
||||||
|
|
||||||
|
free(data);
|
||||||
|
winpr_image_free(img, TRUE);
|
||||||
|
if (!bSuccess)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
{
|
||||||
|
UINT32 id = CF_DIB;
|
||||||
|
|
||||||
|
UINT32 DstSize = 0;
|
||||||
|
void* pDstData = ClipboardGetData(clipboard, id, &DstSize);
|
||||||
|
fprintf(stderr, "ClipboardGetData: [CF_DIB] %p [%" PRIu32 "]\n", pDstData, DstSize);
|
||||||
|
if (!pDstData)
|
||||||
|
goto fail;
|
||||||
|
bSuccess = ClipboardSetData(clipboard, id, pDstData, DstSize);
|
||||||
|
free(pDstData);
|
||||||
|
if (!bSuccess)
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
UINT32 id = ClipboardRegisterFormat(clipboard, "image/bmp");
|
||||||
|
|
||||||
|
UINT32 DstSize = 0;
|
||||||
|
void* pDstData = ClipboardGetData(clipboard, id, &DstSize);
|
||||||
|
fprintf(stderr, "ClipboardGetData: [image/bmp] %p [%" PRIu32 "]\n", pDstData, DstSize);
|
||||||
|
if (!pDstData)
|
||||||
|
goto fail;
|
||||||
|
free(pDstData);
|
||||||
|
if (DstSize != bmpsize)
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(WINPR_UTILS_IMAGE_PNG)
|
||||||
|
{
|
||||||
|
UINT32 id = ClipboardRegisterFormat(clipboard, "image/png");
|
||||||
|
|
||||||
|
UINT32 DstSize = 0;
|
||||||
|
void* pDstData = ClipboardGetData(clipboard, id, &DstSize);
|
||||||
|
fprintf(stderr, "ClipboardGetData: [image/png] %p\n", pDstData);
|
||||||
|
if (!pDstData)
|
||||||
|
goto fail;
|
||||||
|
free(pDstData);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const char* name = TEST_CLIP_PNG;
|
||||||
|
BOOL bSuccess = FALSE;
|
||||||
|
UINT32 idBmp = ClipboardRegisterFormat(clipboard, "image/png");
|
||||||
|
|
||||||
|
wImage* img = winpr_image_new();
|
||||||
|
if (!img)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
if (winpr_image_read(img, name) <= 0)
|
||||||
|
{
|
||||||
|
winpr_image_free(img, TRUE);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t bmpsize = 0;
|
||||||
|
void* data = winpr_image_write_buffer(img, WINPR_IMAGE_PNG, &bmpsize);
|
||||||
|
bSuccess = ClipboardSetData(clipboard, idBmp, data, bmpsize);
|
||||||
|
fprintf(stderr, "ClipboardSetData: %" PRId32 "\n", bSuccess);
|
||||||
|
|
||||||
|
free(data);
|
||||||
|
winpr_image_free(img, TRUE);
|
||||||
|
if (!bSuccess)
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
UINT32 id = CF_DIB;
|
||||||
|
|
||||||
|
UINT32 DstSize = 0;
|
||||||
|
void* pDstData = ClipboardGetData(clipboard, id, &DstSize);
|
||||||
|
fprintf(stderr, "ClipboardGetData: [CF_DIB] %p [%" PRIu32 "]\n", pDstData, DstSize);
|
||||||
|
if (!pDstData)
|
||||||
|
goto fail;
|
||||||
|
bSuccess = ClipboardSetData(clipboard, id, pDstData, DstSize);
|
||||||
|
free(pDstData);
|
||||||
|
if (!bSuccess)
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(WINPR_UTILS_IMAGE_WEBP)
|
||||||
|
{
|
||||||
|
UINT32 id = ClipboardRegisterFormat(clipboard, "image/webp");
|
||||||
|
|
||||||
|
UINT32 DstSize = 0;
|
||||||
|
void* pDstData = ClipboardGetData(clipboard, id, &DstSize);
|
||||||
|
fprintf(stderr, "ClipboardGetData: [image/webp] %p\n", pDstData);
|
||||||
|
if (!pDstData)
|
||||||
|
goto fail;
|
||||||
|
free(pDstData);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(WINPR_UTILS_IMAGE_JPEG)
|
||||||
|
{
|
||||||
|
UINT32 id = ClipboardRegisterFormat(clipboard, "image/jpeg");
|
||||||
|
|
||||||
|
UINT32 DstSize = 0;
|
||||||
|
void* pDstData = ClipboardGetData(clipboard, id, &DstSize);
|
||||||
|
fprintf(stderr, "ClipboardGetData: [image/jpeg] %p\n", pDstData);
|
||||||
|
if (!pDstData)
|
||||||
|
goto fail;
|
||||||
|
free(pDstData);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = 0;
|
||||||
|
|
||||||
|
fail:
|
||||||
free(pFormatIds);
|
free(pFormatIds);
|
||||||
ClipboardDestroy(clipboard);
|
ClipboardDestroy(clipboard);
|
||||||
return 0;
|
return rc;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user