2014-03-15 22:03:05 +04:00
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/print.h>
|
|
|
|
|
|
|
|
#include <freerdp/codec/ncrush.h>
|
|
|
|
|
2014-03-16 06:18:22 +04:00
|
|
|
static const BYTE TEST_BELLS_DATA[] = "for.whom.the.bell.tolls,.the.bell.tolls.for.thee!";
|
|
|
|
|
|
|
|
const BYTE TEST_BELLS_NCRUSH[] =
|
|
|
|
"\xfb\x1d\x7e\xe4\xda\xc7\x1d\x70\xf8\xa1\x6b\x1f\x7d\xc0\xbe\x6b"
|
|
|
|
"\xef\xb5\xef\x21\x87\xd0\xc5\xe1\x85\x71\xd4\x10\x16\xe7\xda\xfb"
|
|
|
|
"\x1d\x7e\xe4\xda\x47\x1f\xb0\xef\xbe\xbd\xff\x2f";
|
|
|
|
|
|
|
|
int test_NCrushCompressBells()
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
UINT32 Flags;
|
|
|
|
UINT32 SrcSize;
|
|
|
|
BYTE* pSrcData;
|
|
|
|
UINT32 DstSize;
|
2014-04-21 07:19:09 +04:00
|
|
|
BYTE* pDstData;
|
2014-03-16 06:18:22 +04:00
|
|
|
UINT32 expectedSize;
|
|
|
|
BYTE OutputBuffer[65536];
|
|
|
|
NCRUSH_CONTEXT* ncrush;
|
|
|
|
ncrush = ncrush_context_new(TRUE);
|
|
|
|
SrcSize = sizeof(TEST_BELLS_DATA) - 1;
|
|
|
|
pSrcData = (BYTE*) TEST_BELLS_DATA;
|
|
|
|
expectedSize = sizeof(TEST_BELLS_NCRUSH) - 1;
|
2014-04-21 07:19:09 +04:00
|
|
|
pDstData = OutputBuffer;
|
|
|
|
DstSize = sizeof(OutputBuffer);
|
2014-04-01 20:18:13 +04:00
|
|
|
ZeroMemory(OutputBuffer, sizeof(OutputBuffer));
|
2014-04-21 07:19:09 +04:00
|
|
|
status = ncrush_compress(ncrush, pSrcData, SrcSize, &pDstData, &DstSize, &Flags);
|
2014-04-01 01:04:19 +04:00
|
|
|
printf("status: %d Flags: 0x%04X DstSize: %d\n", status, Flags, DstSize);
|
2014-03-16 06:18:22 +04:00
|
|
|
|
|
|
|
if (DstSize != expectedSize)
|
|
|
|
{
|
|
|
|
printf("NCrushCompressBells: output size mismatch: Actual: %d, Expected: %d\n", DstSize, expectedSize);
|
2014-04-01 20:18:13 +04:00
|
|
|
printf("Actual\n");
|
2014-08-19 20:26:39 +04:00
|
|
|
BitDump(__FUNCTION__, WLOG_INFO, pDstData, DstSize * 8, 0);
|
2014-04-01 20:18:13 +04:00
|
|
|
printf("Expected\n");
|
2014-08-19 20:26:39 +04:00
|
|
|
BitDump(__FUNCTION__, WLOG_INFO, TEST_BELLS_NCRUSH, expectedSize * 8, 0);
|
2014-03-16 06:18:22 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-04-21 07:19:09 +04:00
|
|
|
if (memcmp(pDstData, TEST_BELLS_NCRUSH, DstSize) != 0)
|
2014-03-16 06:18:22 +04:00
|
|
|
{
|
|
|
|
printf("NCrushCompressBells: output mismatch\n");
|
|
|
|
printf("Actual\n");
|
2014-08-19 20:26:39 +04:00
|
|
|
BitDump(__FUNCTION__, WLOG_INFO, pDstData, DstSize * 8, 0);
|
2014-03-16 06:18:22 +04:00
|
|
|
printf("Expected\n");
|
2014-08-19 20:26:39 +04:00
|
|
|
BitDump(__FUNCTION__, WLOG_INFO, TEST_BELLS_NCRUSH, expectedSize * 8, 0);
|
2014-03-16 06:18:22 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ncrush_context_free(ncrush);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int test_NCrushDecompressBells()
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
UINT32 Flags;
|
|
|
|
BYTE* pSrcData;
|
|
|
|
UINT32 SrcSize;
|
|
|
|
UINT32 DstSize;
|
|
|
|
UINT32 expectedSize;
|
|
|
|
BYTE* pDstData = NULL;
|
|
|
|
NCRUSH_CONTEXT* ncrush;
|
|
|
|
ncrush = ncrush_context_new(FALSE);
|
|
|
|
SrcSize = sizeof(TEST_BELLS_NCRUSH) - 1;
|
|
|
|
pSrcData = (BYTE*) TEST_BELLS_NCRUSH;
|
|
|
|
Flags = PACKET_COMPRESSED | 2;
|
|
|
|
expectedSize = sizeof(TEST_BELLS_DATA) - 1;
|
|
|
|
status = ncrush_decompress(ncrush, pSrcData, SrcSize, &pDstData, &DstSize, Flags);
|
|
|
|
printf("Flags: 0x%04X DstSize: %d\n", Flags, DstSize);
|
|
|
|
|
|
|
|
if (DstSize != expectedSize)
|
|
|
|
{
|
|
|
|
printf("NCrushDecompressBells: output size mismatch: Actual: %d, Expected: %d\n", DstSize, expectedSize);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (memcmp(pDstData, TEST_BELLS_DATA, DstSize) != 0)
|
|
|
|
{
|
|
|
|
printf("NCrushDecompressBells: output mismatch\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ncrush_context_free(ncrush);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-03-15 22:03:05 +04:00
|
|
|
int TestFreeRDPCodecNCrush(int argc, char* argv[])
|
|
|
|
{
|
2014-04-01 01:04:19 +04:00
|
|
|
if (test_NCrushCompressBells() < 0)
|
|
|
|
return -1;
|
2014-04-01 22:03:12 +04:00
|
|
|
|
2014-04-01 01:04:19 +04:00
|
|
|
if (test_NCrushDecompressBells() < 0)
|
|
|
|
return -1;
|
2014-03-16 06:18:22 +04:00
|
|
|
|
2014-03-15 22:03:05 +04:00
|
|
|
return 0;
|
|
|
|
}
|