2 #include <winpr/print.h>
3 #include <winpr/bitstream.h>
5 #include <freerdp/freerdp.h>
6 #include <freerdp/codec/zgfx.h>
7 #include <freerdp/log.h>
10 static const BYTE TEST_FOX_DATA[] =
"The quick brown "
14 static const BYTE TEST_FOX_DATA_SINGLE[] =
15 "\xE0\x04\x54\x68\x65\x20\x71\x75\x69\x63\x6B\x20\x62\x72\x6F\x77"
16 "\x6E\x20\x66\x6F\x78\x20\x6A\x75\x6D\x70\x73\x20\x6F\x76\x65\x72"
17 "\x20\x74\x68\x65\x20\x6C\x61\x7A\x79\x20\x64\x6F\x67";
19 static const BYTE TEST_FOX_DATA_MULTIPART[] =
20 "\xE1\x03\x00\x2B\x00\x00\x00\x11\x00\x00\x00\x04\x54\x68\x65\x20"
21 "\x71\x75\x69\x63\x6B\x20\x62\x72\x6F\x77\x6E\x20\x0E\x00\x00\x00"
22 "\x04\x66\x6F\x78\x20\x6A\x75\x6D\x70\x73\x20\x6F\x76\x65\x10\x00"
23 "\x00\x00\x24\x39\x08\x0E\x91\xF8\xD8\x61\x3D\x1E\x44\x06\x43\x79"
26 static int test_ZGfxCompressFox(
void)
31 const BYTE* pSrcData = NULL;
34 BYTE* pDstData = NULL;
35 ZGFX_CONTEXT* zgfx = NULL;
36 UINT32 expectedSize = 0;
37 zgfx = zgfx_context_new(TRUE);
42 SrcSize =
sizeof(TEST_FOX_DATA) - 1;
43 pSrcData = (
const BYTE*)TEST_FOX_DATA;
45 expectedSize =
sizeof(TEST_FOX_DATA_SINGLE) - 1;
46 status = zgfx_compress(zgfx, pSrcData, SrcSize, &pDstData, &DstSize, &Flags);
51 printf(
"flags: 0x%08" PRIX32
" size: %" PRIu32
"\n", Flags, DstSize);
53 if (DstSize != expectedSize)
55 printf(
"test_ZGfxCompressFox: output size mismatch: Actual: %" PRIu32
", Expected: %" PRIu32
57 DstSize, expectedSize);
61 if (memcmp(pDstData, TEST_FOX_DATA_SINGLE, DstSize) != 0)
63 printf(
"test_ZGfxCompressFox: output mismatch\n");
65 BitDump(__func__, WLOG_INFO, pDstData, DstSize * 8, 0);
67 BitDump(__func__, WLOG_INFO, TEST_FOX_DATA_SINGLE, DstSize * 8, 0);
74 zgfx_context_free(zgfx);
78 static int test_ZGfxDecompressFoxSingle(
void)
83 const BYTE* pSrcData = NULL;
86 BYTE* pDstData = NULL;
87 ZGFX_CONTEXT* zgfx = NULL;
88 UINT32 expectedSize = 0;
89 zgfx = zgfx_context_new(TRUE);
94 SrcSize =
sizeof(TEST_FOX_DATA_SINGLE) - 1;
95 pSrcData = (
const BYTE*)TEST_FOX_DATA_SINGLE;
97 expectedSize =
sizeof(TEST_FOX_DATA) - 1;
98 status = zgfx_decompress(zgfx, pSrcData, SrcSize, &pDstData, &DstSize, Flags);
103 printf(
"flags: 0x%08" PRIX32
" size: %" PRIu32
"\n", Flags, DstSize);
105 if (DstSize != expectedSize)
107 printf(
"test_ZGfxDecompressFoxSingle: output size mismatch: Actual: %" PRIu32
108 ", Expected: %" PRIu32
"\n",
109 DstSize, expectedSize);
113 if (memcmp(pDstData, TEST_FOX_DATA, DstSize) != 0)
115 printf(
"test_ZGfxDecompressFoxSingle: output mismatch\n");
117 BitDump(__func__, WLOG_INFO, pDstData, DstSize * 8, 0);
118 printf(
"Expected\n");
119 BitDump(__func__, WLOG_INFO, TEST_FOX_DATA, DstSize * 8, 0);
126 zgfx_context_free(zgfx);
130 static int test_ZGfxDecompressFoxMultipart(
void)
135 const BYTE* pSrcData = NULL;
138 BYTE* pDstData = NULL;
139 ZGFX_CONTEXT* zgfx = NULL;
140 UINT32 expectedSize = 0;
141 zgfx = zgfx_context_new(TRUE);
146 SrcSize =
sizeof(TEST_FOX_DATA_MULTIPART) - 1;
147 pSrcData = (
const BYTE*)TEST_FOX_DATA_MULTIPART;
149 expectedSize =
sizeof(TEST_FOX_DATA) - 1;
150 status = zgfx_decompress(zgfx, pSrcData, SrcSize, &pDstData, &DstSize, Flags);
155 printf(
"flags: 0x%08" PRIX32
" size: %" PRIu32
"\n", Flags, DstSize);
157 if (DstSize != expectedSize)
159 printf(
"test_ZGfxDecompressFoxSingle: output size mismatch: Actual: %" PRIu32
160 ", Expected: %" PRIu32
"\n",
161 DstSize, expectedSize);
165 if (memcmp(pDstData, TEST_FOX_DATA, DstSize) != 0)
167 printf(
"test_ZGfxDecompressFoxSingle: output mismatch\n");
169 BitDump(__func__, WLOG_INFO, pDstData, DstSize * 8, 0);
170 printf(
"Expected\n");
171 BitDump(__func__, WLOG_INFO, TEST_FOX_DATA, DstSize * 8, 0);
178 zgfx_context_free(zgfx);
182 static int test_ZGfxCompressConsistent(
void)
188 const BYTE* pSrcData = NULL;
191 BYTE* pDstData = NULL;
193 BYTE* pDstData2 = NULL;
194 ZGFX_CONTEXT* zgfx = NULL;
195 UINT32 expectedSize = 0;
196 BYTE BigBuffer[65536];
197 memset(BigBuffer, 0xaa,
sizeof(BigBuffer));
198 memcpy(BigBuffer, TEST_FOX_DATA,
sizeof(TEST_FOX_DATA) - 1);
199 zgfx = zgfx_context_new(TRUE);
205 expectedSize = SrcSize =
sizeof(BigBuffer);
206 pSrcData = (
const BYTE*)BigBuffer;
208 status = zgfx_compress(zgfx, pSrcData, SrcSize, &pDstData2, &DstSize2, &Flags);
213 printf(
"Compress: flags: 0x%08" PRIX32
" size: %" PRIu32
"\n", Flags, DstSize2);
215 status = zgfx_decompress(zgfx, pDstData2, DstSize2, &pDstData, &DstSize, Flags);
220 printf(
"Decompress: flags: 0x%08" PRIX32
" size: %" PRIu32
"\n", Flags, DstSize);
222 if (DstSize != expectedSize)
224 printf(
"test_ZGfxDecompressFoxSingle: output size mismatch: Actual: %" PRIu32
225 ", Expected: %" PRIu32
"\n",
226 DstSize, expectedSize);
230 if (memcmp(pDstData, BigBuffer, DstSize) != 0)
232 printf(
"test_ZGfxDecompressFoxSingle: output mismatch\n");
234 BitDump(__func__, WLOG_INFO, pDstData, 64 * 8, 0);
236 BitDump(__func__, WLOG_INFO, pDstData + DstSize - 64, 64 * 8, 0);
237 printf(
"Expected\n");
238 BitDump(__func__, WLOG_INFO, BigBuffer, 64 * 8, 0);
240 BitDump(__func__, WLOG_INFO, BigBuffer + DstSize - 64, 64 * 8, 0);
241 printf(
"Middle Result\n");
242 BitDump(__func__, WLOG_INFO, pDstData2, 64 * 8, 0);
244 BitDump(__func__, WLOG_INFO, pDstData2 + DstSize2 - 64, 64 * 8, 0);
252 zgfx_context_free(zgfx);
256 int TestFreeRDPCodecZGfx(
int argc,
char* argv[])
261 if (test_ZGfxCompressFox() < 0)
264 if (test_ZGfxDecompressFoxSingle() < 0)
267 if (test_ZGfxDecompressFoxMultipart() < 0)
270 if (test_ZGfxCompressConsistent() < 0)