21#include <winpr/stream.h>
23#include <freerdp/freerdp.h>
28static BOOL read_rectangle(rdpUpdate* update, UINT16 left, UINT16 top, UINT16 right, UINT16 bottom,
29 UINT16 width, UINT16 height)
31 const size_t length = 4ull * width * height;
32 wStream* s = Stream_New(
nullptr, 2 + 18 + length);
36 Stream_Write_UINT16(s, 1);
37 Stream_Write_UINT16(s, left);
38 Stream_Write_UINT16(s, top);
39 Stream_Write_UINT16(s, right);
40 Stream_Write_UINT16(s, bottom);
41 Stream_Write_UINT16(s, width);
42 Stream_Write_UINT16(s, height);
43 Stream_Write_UINT16(s, 32);
44 Stream_Write_UINT16(s, 0);
45 Stream_Write_UINT16(s, (UINT16)length);
46 Stream_Zero(s, length);
48 Stream_ResetPosition(s);
50 BITMAP_UPDATE* bitmapUpdate = update_read_bitmap_update(update, s);
51 const BOOL accepted = (bitmapUpdate !=
nullptr);
52 free_bitmap_update(update->context, bitmapUpdate);
69int TestUpdateBitmap(WINPR_ATTR_UNUSED
int argc, WINPR_ATTR_UNUSED
char* argv[])
72 const test_case cases[] = {
73 {
"bitmap as wide as the rectangle", 0, 0, 11, 3, 12, 4, TRUE },
75 {
"bitmap wider than the rectangle (padded)", 0, 0, 8, 3, 12, 4, TRUE },
76 {
"bitmap taller than the rectangle", 0, 0, 11, 2, 12, 4, TRUE },
77 {
"rectangle wider than the bitmap", 0, 0, 12, 3, 12, 4, FALSE },
78 {
"rectangle taller than the bitmap", 0, 0, 11, 4, 12, 4, FALSE },
79 {
"inverted rectangle", 9, 0, 8, 3, 12, 4, FALSE },
80 {
"inverted rectangle, vertically", 0, 4, 11, 3, 12, 4, FALSE },
84 freerdp* instance = freerdp_new();
85 if (!instance || !freerdp_context_new(instance))
88 for (
size_t x = 0; x < ARRAYSIZE(cases); x++)
90 const test_case* c = &cases[x];
91 const BOOL accepted = read_rectangle(instance->context->update, c->left, c->top, c->right,
92 c->bottom, c->width, c->height);
93 if (accepted != c->accepted)
95 (void)fprintf(stderr,
"%s: %s, expected %s\n", c->what,
96 accepted ?
"accepted" :
"rejected",
97 c->accepted ?
"accepted" :
"rejected");
105 freerdp_context_free(instance);
106 freerdp_free(instance);