FreeRDP
Loading...
Searching...
No Matches
TestUpdateBitmap.c
1
20#include <winpr/crt.h>
21#include <winpr/stream.h>
22
23#include <freerdp/freerdp.h>
24
25#include "../update.h"
26
27/* One uncompressed 32 bpp rectangle; returns whether it was accepted */
28static BOOL read_rectangle(rdpUpdate* update, UINT16 left, UINT16 top, UINT16 right, UINT16 bottom,
29 UINT16 width, UINT16 height)
30{
31 const size_t length = 4ull * width * height;
32 wStream* s = Stream_New(nullptr, 2 + 18 + length);
33 if (!s)
34 return FALSE;
35
36 Stream_Write_UINT16(s, 1); /* numberRectangles */
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); /* bitsPerPixel */
44 Stream_Write_UINT16(s, 0); /* flags: uncompressed */
45 Stream_Write_UINT16(s, (UINT16)length);
46 Stream_Zero(s, length);
47 Stream_SealLength(s);
48 Stream_ResetPosition(s);
49
50 BITMAP_UPDATE* bitmapUpdate = update_read_bitmap_update(update, s);
51 const BOOL accepted = (bitmapUpdate != nullptr);
52 free_bitmap_update(update->context, bitmapUpdate);
53 Stream_Free(s, TRUE);
54 return accepted;
55}
56
57typedef struct
58{
59 const char* what;
60 UINT16 left;
61 UINT16 top;
62 UINT16 right;
63 UINT16 bottom;
64 UINT16 width;
65 UINT16 height;
66 BOOL accepted;
67} test_case;
68
69int TestUpdateBitmap(WINPR_ATTR_UNUSED int argc, WINPR_ATTR_UNUSED char* argv[])
70{
71 /* destRight and destBottom are inclusive */
72 const test_case cases[] = {
73 { "bitmap as wide as the rectangle", 0, 0, 11, 3, 12, 4, TRUE },
74 /* xrdp: a 9 pixel wide rectangle, the bitmap padded to 12 */
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 },
81 };
82 int rc = -1;
83
84 freerdp* instance = freerdp_new();
85 if (!instance || !freerdp_context_new(instance))
86 goto fail;
87
88 for (size_t x = 0; x < ARRAYSIZE(cases); x++)
89 {
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)
94 {
95 (void)fprintf(stderr, "%s: %s, expected %s\n", c->what,
96 accepted ? "accepted" : "rejected",
97 c->accepted ? "accepted" : "rejected");
98 goto fail;
99 }
100 }
101
102 rc = 0;
103fail:
104 if (instance)
105 freerdp_context_free(instance);
106 freerdp_free(instance);
107 return rc;
108}