2014-03-15 22:03:05 +04:00
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/print.h>
|
|
|
|
|
2022-04-28 11:15:31 +03:00
|
|
|
#include "../ncrush.h"
|
2014-03-15 22:03:05 +04:00
|
|
|
|
2014-03-16 06:18:22 +04:00
|
|
|
static const BYTE TEST_BELLS_DATA[] = "for.whom.the.bell.tolls,.the.bell.tolls.for.thee!";
|
|
|
|
|
2017-03-28 17:18:00 +03:00
|
|
|
static const BYTE TEST_BELLS_NCRUSH[] =
|
2017-11-23 12:47:56 +03:00
|
|
|
"\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";
|
2014-03-16 06:18:22 +04:00
|
|
|
|
2017-11-23 12:47:56 +03:00
|
|
|
static BOOL test_NCrushCompressBells(void)
|
2014-03-16 06:18:22 +04:00
|
|
|
{
|
2017-11-23 12:47:56 +03:00
|
|
|
BOOL rc = FALSE;
|
2014-03-16 06:18:22 +04:00
|
|
|
int status;
|
|
|
|
UINT32 Flags;
|
2022-04-27 09:33:19 +03:00
|
|
|
const BYTE* pDstData = NULL;
|
|
|
|
BYTE OutputBuffer[65536] = { 0 };
|
|
|
|
const UINT32 SrcSize = sizeof(TEST_BELLS_DATA) - 1;
|
|
|
|
const BYTE* pSrcData = TEST_BELLS_DATA;
|
|
|
|
const UINT32 expectedSize = sizeof(TEST_BELLS_NCRUSH) - 1;
|
|
|
|
UINT32 DstSize = sizeof(OutputBuffer);
|
2017-03-28 17:18:00 +03:00
|
|
|
NCRUSH_CONTEXT* ncrush = ncrush_context_new(TRUE);
|
2017-11-23 12:47:56 +03:00
|
|
|
|
2017-03-28 17:18:00 +03:00
|
|
|
if (!ncrush)
|
2017-11-23 12:47:56 +03:00
|
|
|
return rc;
|
2017-03-28 17:18:00 +03:00
|
|
|
|
2022-04-27 09:33:19 +03:00
|
|
|
status = ncrush_compress(ncrush, pSrcData, SrcSize, OutputBuffer, &pDstData, &DstSize, &Flags);
|
2017-11-23 12:47:56 +03:00
|
|
|
|
2017-03-28 17:18:00 +03:00
|
|
|
if (status < 0)
|
|
|
|
goto fail;
|
2017-11-23 12:47:56 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("status: %d Flags: 0x%08" PRIX32 " DstSize: %" PRIu32 "\n", status, Flags, DstSize);
|
2014-03-16 06:18:22 +04:00
|
|
|
|
|
|
|
if (DstSize != expectedSize)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("NCrushCompressBells: output size mismatch: Actual: %" PRIu32 ", Expected: %" PRIu32
|
|
|
|
"\n",
|
2017-11-23 12:47:56 +03:00
|
|
|
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);
|
2017-03-28 17:18:00 +03:00
|
|
|
goto fail;
|
2014-03-16 06:18:22 +04:00
|
|
|
}
|
|
|
|
|
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);
|
2017-03-28 17:18:00 +03:00
|
|
|
goto fail;
|
2014-03-16 06:18:22 +04:00
|
|
|
}
|
|
|
|
|
2017-11-23 12:47:56 +03:00
|
|
|
rc = TRUE;
|
2017-03-28 17:18:00 +03:00
|
|
|
fail:
|
2014-03-16 06:18:22 +04:00
|
|
|
ncrush_context_free(ncrush);
|
2017-03-28 17:18:00 +03:00
|
|
|
return rc;
|
2014-03-16 06:18:22 +04:00
|
|
|
}
|
|
|
|
|
2017-11-23 12:47:56 +03:00
|
|
|
static BOOL test_NCrushDecompressBells(void)
|
2014-03-16 06:18:22 +04:00
|
|
|
{
|
2017-11-23 12:47:56 +03:00
|
|
|
BOOL rc = FALSE;
|
2014-03-16 06:18:22 +04:00
|
|
|
int status;
|
|
|
|
UINT32 Flags;
|
2021-12-01 10:23:50 +03:00
|
|
|
const BYTE* pSrcData;
|
2014-03-16 06:18:22 +04:00
|
|
|
UINT32 SrcSize;
|
|
|
|
UINT32 DstSize;
|
|
|
|
UINT32 expectedSize;
|
2022-02-22 13:18:43 +03:00
|
|
|
const BYTE* pDstData = NULL;
|
2017-03-28 17:18:00 +03:00
|
|
|
NCRUSH_CONTEXT* ncrush = ncrush_context_new(FALSE);
|
|
|
|
|
|
|
|
if (!ncrush)
|
2017-11-23 12:47:56 +03:00
|
|
|
return rc;
|
2017-03-28 17:18:00 +03:00
|
|
|
|
2014-03-16 06:18:22 +04:00
|
|
|
SrcSize = sizeof(TEST_BELLS_NCRUSH) - 1;
|
2021-08-02 13:13:34 +03:00
|
|
|
pSrcData = (const BYTE*)TEST_BELLS_NCRUSH;
|
2014-03-16 06:18:22 +04:00
|
|
|
Flags = PACKET_COMPRESSED | 2;
|
|
|
|
expectedSize = sizeof(TEST_BELLS_DATA) - 1;
|
|
|
|
status = ncrush_decompress(ncrush, pSrcData, SrcSize, &pDstData, &DstSize, Flags);
|
2017-11-23 12:47:56 +03:00
|
|
|
|
2017-03-28 17:18:00 +03:00
|
|
|
if (status < 0)
|
|
|
|
goto fail;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("Flags: 0x%08" PRIX32 " DstSize: %" PRIu32 "\n", Flags, DstSize);
|
2014-03-16 06:18:22 +04:00
|
|
|
|
|
|
|
if (DstSize != expectedSize)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("NCrushDecompressBells: output size mismatch: Actual: %" PRIu32
|
|
|
|
", Expected: %" PRIu32 "\n",
|
2017-11-23 12:47:56 +03:00
|
|
|
DstSize, expectedSize);
|
2017-03-28 17:18:00 +03:00
|
|
|
goto fail;
|
2014-03-16 06:18:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (memcmp(pDstData, TEST_BELLS_DATA, DstSize) != 0)
|
|
|
|
{
|
|
|
|
printf("NCrushDecompressBells: output mismatch\n");
|
2017-03-28 17:18:00 +03:00
|
|
|
goto fail;
|
2014-03-16 06:18:22 +04:00
|
|
|
}
|
|
|
|
|
2017-11-23 12:47:56 +03:00
|
|
|
rc = TRUE;
|
2017-03-28 17:18:00 +03:00
|
|
|
fail:
|
2014-03-16 06:18:22 +04:00
|
|
|
ncrush_context_free(ncrush);
|
2017-03-28 17:18:00 +03:00
|
|
|
return rc;
|
2014-03-16 06:18:22 +04:00
|
|
|
}
|
|
|
|
|
2014-03-15 22:03:05 +04:00
|
|
|
int TestFreeRDPCodecNCrush(int argc, char* argv[])
|
|
|
|
{
|
2019-05-08 13:20:43 +03:00
|
|
|
WINPR_UNUSED(argc);
|
|
|
|
WINPR_UNUSED(argv);
|
|
|
|
|
2017-11-23 12:47:56 +03:00
|
|
|
if (!test_NCrushCompressBells())
|
2014-04-01 01:04:19 +04:00
|
|
|
return -1;
|
2014-04-01 22:03:12 +04:00
|
|
|
|
2017-11-23 12:47:56 +03:00
|
|
|
if (!test_NCrushDecompressBells())
|
2014-04-01 01:04:19 +04:00
|
|
|
return -1;
|
2014-03-16 06:18:22 +04:00
|
|
|
|
2014-03-15 22:03:05 +04:00
|
|
|
return 0;
|
|
|
|
}
|