3 #include <winpr/print.h>
4 #include <winpr/image.h>
5 #include <winpr/clipboard.h>
7 int TestClipboardFormats(
int argc,
char* argv[])
11 UINT32* pFormatIds = NULL;
12 const char* formatName = NULL;
13 wClipboard* clipboard = NULL;
14 UINT32 utf8StringFormatId = 0;
19 clipboard = ClipboardCreate();
23 const char* mime_types[] = {
"text/html",
"text/html",
"image/bmp",
24 "image/png",
"image/webp",
"image/jpeg" };
25 for (
size_t x = 0; x < ARRAYSIZE(mime_types); x++)
27 const char* mime = mime_types[x];
28 UINT32
id = ClipboardRegisterFormat(clipboard, mime);
29 (void)fprintf(stderr,
"ClipboardRegisterFormat(%s) -> 0x%08" PRIx32
"\n", mime,
id);
34 utf8StringFormatId = ClipboardRegisterFormat(clipboard,
"UTF8_STRING");
36 count = ClipboardGetRegisteredFormatIds(clipboard, &pFormatIds);
38 for (UINT32 index = 0; index < count; index++)
40 UINT32 formatId = pFormatIds[index];
41 formatName = ClipboardGetFormatName(clipboard, formatId);
42 (void)fprintf(stderr,
"Format: 0x%08" PRIX32
" %s\n", formatId, formatName);
52 const char pSrcData[] =
"this is a test string";
53 char* pDstData = NULL;
55 SrcSize = (UINT32)(strnlen(pSrcData, ARRAYSIZE(pSrcData)) + 1);
56 bSuccess = ClipboardSetData(clipboard, utf8StringFormatId, pSrcData, SrcSize);
57 (void)fprintf(stderr,
"ClipboardSetData: %" PRId32
"\n", bSuccess);
59 pDstData = (
char*)ClipboardGetData(clipboard, utf8StringFormatId, &DstSize);
60 (void)fprintf(stderr,
"ClipboardGetData: %s\n", pDstData);
67 char* pSrcData = NULL;
68 WCHAR* pDstData = NULL;
70 pDstData = (WCHAR*)ClipboardGetData(clipboard, CF_UNICODETEXT, &DstSize);
71 pSrcData = ConvertWCharNToUtf8Alloc(pDstData, DstSize /
sizeof(WCHAR), NULL);
73 (void)fprintf(stderr,
"ClipboardGetData (synthetic): %s\n", pSrcData);
79 count = ClipboardGetFormatIds(clipboard, &pFormatIds);
81 for (UINT32 index = 0; index < count; index++)
83 UINT32 formatId = pFormatIds[index];
84 formatName = ClipboardGetFormatName(clipboard, formatId);
85 (void)fprintf(stderr,
"Format: 0x%08" PRIX32
" %s\n", formatId, formatName);
90 const char* name = TEST_CLIP_BMP;
91 BOOL bSuccess = FALSE;
92 UINT32 idBmp = ClipboardRegisterFormat(clipboard,
"image/bmp");
94 wImage* img = winpr_image_new();
98 if (winpr_image_read(img, name) <= 0)
100 winpr_image_free(img, TRUE);
105 void* data = winpr_image_write_buffer(img, WINPR_IMAGE_BITMAP, &bmpsize);
106 bSuccess = ClipboardSetData(clipboard, idBmp, data, bmpsize);
107 (void)fprintf(stderr,
"ClipboardSetData: %" PRId32
"\n", bSuccess);
110 winpr_image_free(img, TRUE);
118 void* pDstData = ClipboardGetData(clipboard,
id, &DstSize);
119 (void)fprintf(stderr,
"ClipboardGetData: [CF_DIB] %p [%" PRIu32
"]\n", pDstData,
123 bSuccess = ClipboardSetData(clipboard,
id, pDstData, DstSize);
129 UINT32
id = ClipboardRegisterFormat(clipboard,
"image/bmp");
132 void* pDstData = ClipboardGetData(clipboard,
id, &DstSize);
133 (void)fprintf(stderr,
"ClipboardGetData: [image/bmp] %p [%" PRIu32
"]\n", pDstData,
138 if (DstSize != bmpsize)
142 #if defined(WINPR_UTILS_IMAGE_PNG)
144 UINT32
id = ClipboardRegisterFormat(clipboard,
"image/png");
147 void* pDstData = ClipboardGetData(clipboard,
id, &DstSize);
148 (void)fprintf(stderr,
"ClipboardGetData: [image/png] %p\n", pDstData);
154 const char* name = TEST_CLIP_PNG;
155 BOOL bSuccess = FALSE;
156 UINT32 idBmp = ClipboardRegisterFormat(clipboard,
"image/png");
158 wImage* img = winpr_image_new();
162 if (winpr_image_read(img, name) <= 0)
164 winpr_image_free(img, TRUE);
169 void* data = winpr_image_write_buffer(img, WINPR_IMAGE_PNG, &bmpsize);
170 bSuccess = ClipboardSetData(clipboard, idBmp, data, bmpsize);
171 (void)fprintf(stderr,
"ClipboardSetData: %" PRId32
"\n", bSuccess);
174 winpr_image_free(img, TRUE);
182 void* pDstData = ClipboardGetData(clipboard,
id, &DstSize);
183 (void)fprintf(stderr,
"ClipboardGetData: [CF_DIB] %p [%" PRIu32
"]\n", pDstData,
187 bSuccess = ClipboardSetData(clipboard,
id, pDstData, DstSize);
194 #if defined(WINPR_UTILS_IMAGE_WEBP)
196 UINT32
id = ClipboardRegisterFormat(clipboard,
"image/webp");
199 void* pDstData = ClipboardGetData(clipboard,
id, &DstSize);
200 (void)fprintf(stderr,
"ClipboardGetData: [image/webp] %p\n", pDstData);
207 #if defined(WINPR_UTILS_IMAGE_JPEG)
209 UINT32
id = ClipboardRegisterFormat(clipboard,
"image/jpeg");
212 void* pDstData = ClipboardGetData(clipboard,
id, &DstSize);
213 (void)fprintf(stderr,
"ClipboardGetData: [image/jpeg] %p\n", pDstData);
225 ClipboardDestroy(clipboard);