Initial commit - from Precise source
[freerdp-ubuntu-pcb-backport.git] / cunit / test_orders.c
1 /**
2  * FreeRDP: A Remote Desktop Protocol Client
3  * Drawing Orders Unit Tests
4  *
5  * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 #include <freerdp/freerdp.h>
21 #include <freerdp/utils/hexdump.h>
22 #include <freerdp/utils/stream.h>
23
24 #include "test_orders.h"
25 #include "libfreerdp-core/orders.h"
26 #include "libfreerdp-core/update.h"
27
28 ORDER_INFO* orderInfo;
29
30 int init_orders_suite(void)
31 {
32         orderInfo = (ORDER_INFO*) malloc(sizeof(ORDER_INFO));
33         return 0;
34 }
35
36 int clean_orders_suite(void)
37 {
38         free(orderInfo);
39         return 0;
40 }
41
42 int add_orders_suite(void)
43 {
44         add_test_suite(orders);
45
46         add_test_function(read_dstblt_order);
47         add_test_function(read_patblt_order);
48         add_test_function(read_scrblt_order);
49         add_test_function(read_opaque_rect_order);
50         add_test_function(read_draw_nine_grid_order);
51         add_test_function(read_multi_opaque_rect_order);
52         add_test_function(read_line_to_order);
53         add_test_function(read_polyline_order);
54         add_test_function(read_glyph_index_order);
55         add_test_function(read_fast_index_order);
56         add_test_function(read_fast_glyph_order);
57         add_test_function(read_polygon_cb_order);
58
59         add_test_function(read_cache_bitmap_order);
60         add_test_function(read_cache_bitmap_v2_order);
61         add_test_function(read_cache_bitmap_v3_order);
62         add_test_function(read_cache_brush_order);
63
64         add_test_function(read_create_offscreen_bitmap_order);
65         add_test_function(read_switch_surface_order);
66
67         add_test_function(update_recv_orders);
68
69         return 0;
70 }
71
72 uint8 dstblt_order[] = "\x48\x00\x37\x01";
73
74 void test_read_dstblt_order(void)
75 {
76         STREAM _s, *s;
77         DSTBLT_ORDER dstblt;
78
79         s = &_s;
80         s->p = s->data = dstblt_order;
81
82         memset(orderInfo, 0, sizeof(ORDER_INFO));
83         orderInfo->fieldFlags = 0x0C;
84         memset(&dstblt, 0, sizeof(DSTBLT_ORDER));
85
86         update_read_dstblt_order(s, orderInfo, &dstblt);
87
88         CU_ASSERT(dstblt.nLeftRect == 0);
89         CU_ASSERT(dstblt.nTopRect == 0);
90         CU_ASSERT(dstblt.nWidth == 72);
91         CU_ASSERT(dstblt.nHeight == 311);
92         CU_ASSERT(dstblt.bRop == 0);
93
94         CU_ASSERT(stream_get_length(s) == (sizeof(dstblt_order) - 1));
95 }
96
97 uint8 patblt_order[] = "\x1a\x00\xc3\x01\x0d\x00\x0d\x00\xf0\xff\xff\x00\x5b\xef\x00\x81";
98
99 void test_read_patblt_order(void)
100 {
101         STREAM _s, *s;
102         PATBLT_ORDER patblt;
103
104         s = &_s;
105         s->p = s->data = patblt_order;
106
107         memset(orderInfo, 0, sizeof(ORDER_INFO));
108         orderInfo->fieldFlags = 0x027F;
109         memset(&patblt, 0, sizeof(PATBLT_ORDER));
110
111         update_read_patblt_order(s, orderInfo, &patblt);
112
113         CU_ASSERT(patblt.nLeftRect == 26);
114         CU_ASSERT(patblt.nTopRect == 451);
115         CU_ASSERT(patblt.nWidth == 13);
116         CU_ASSERT(patblt.nHeight == 13);
117         CU_ASSERT(patblt.bRop == 240);
118         CU_ASSERT(patblt.backColor == 0x00FFFF);
119         CU_ASSERT(patblt.foreColor == 0x00EF5B);
120         CU_ASSERT(patblt.brush.x == 0);
121         CU_ASSERT(patblt.brush.y == 0);
122         CU_ASSERT(patblt.brush.style == (BMF_1BPP | CACHED_BRUSH));
123
124         CU_ASSERT(stream_get_length(s) == (sizeof(patblt_order) - 1));
125 }
126
127 uint8 scrblt_order[] = "\x07\x00\xa1\x01\xf1\x00\xcc\x2f\x01\x8e\x00";
128
129 void test_read_scrblt_order(void)
130 {
131         STREAM _s, *s;
132         SCRBLT_ORDER scrblt;
133
134         s = &_s;
135         s->p = s->data = scrblt_order;
136
137         memset(orderInfo, 0, sizeof(ORDER_INFO));
138         orderInfo->fieldFlags = 0x7D;
139         memset(&scrblt, 0, sizeof(SCRBLT_ORDER));
140
141         update_read_scrblt_order(s, orderInfo, &scrblt);
142
143         CU_ASSERT(scrblt.nLeftRect == 7);
144         CU_ASSERT(scrblt.nTopRect == 0);
145         CU_ASSERT(scrblt.nWidth == 417);
146         CU_ASSERT(scrblt.nHeight == 241);
147         CU_ASSERT(scrblt.bRop == 204);
148         CU_ASSERT(scrblt.nXSrc == 303);
149         CU_ASSERT(scrblt.nYSrc == 142);
150
151         CU_ASSERT(stream_get_length(s) == (sizeof(scrblt_order) - 1));
152 }
153
154 uint8 opaque_rect_order[] = "\x00\x04\x00\x03\x73\x02\x06";
155
156 void test_read_opaque_rect_order(void)
157 {
158         STREAM _s, *s;
159         OPAQUE_RECT_ORDER opaque_rect;
160
161         s = &_s;
162         s->p = s->data = opaque_rect_order;
163
164         memset(orderInfo, 0, sizeof(ORDER_INFO));
165         orderInfo->fieldFlags = 0x7C;
166         memset(&opaque_rect, 0, sizeof(OPAQUE_RECT_ORDER));
167
168         update_read_opaque_rect_order(s, orderInfo, &opaque_rect);
169
170         CU_ASSERT(opaque_rect.nLeftRect == 0);
171         CU_ASSERT(opaque_rect.nTopRect == 0);
172         CU_ASSERT(opaque_rect.nWidth == 1024);
173         CU_ASSERT(opaque_rect.nHeight == 768);
174         CU_ASSERT(opaque_rect.color == 0x00060273);
175
176         CU_ASSERT(stream_get_length(s) == (sizeof(opaque_rect_order) - 1));
177 }
178
179 uint8 draw_nine_grid_order[] = "\xfb\xf9\x0d\x00";
180
181 void test_read_draw_nine_grid_order(void)
182 {
183         STREAM _s, *s;
184         DRAW_NINE_GRID_ORDER draw_nine_grid;
185
186         s = &_s;
187         s->p = s->data = draw_nine_grid_order;
188
189         memset(orderInfo, 0, sizeof(ORDER_INFO));
190         orderInfo->fieldFlags = 0x1C;
191         orderInfo->deltaCoordinates = true;
192
193         memset(&draw_nine_grid, 0, sizeof(DRAW_NINE_GRID_ORDER));
194         draw_nine_grid.srcRight = 38;
195         draw_nine_grid.srcBottom = 40;
196
197         update_read_draw_nine_grid_order(s, orderInfo, &draw_nine_grid);
198
199         CU_ASSERT(draw_nine_grid.srcLeft == 0);
200         CU_ASSERT(draw_nine_grid.srcTop == 0);
201         CU_ASSERT(draw_nine_grid.srcRight == 33);
202         CU_ASSERT(draw_nine_grid.srcBottom == 33);
203         CU_ASSERT(draw_nine_grid.bitmapId == 13);
204
205         CU_ASSERT(stream_get_length(s) == (sizeof(draw_nine_grid_order) - 1));
206 }
207
208
209 uint8 multi_opaque_rect_order[] =
210         "\x87\x01\x1c\x01\xf1\x00\x12\x00\x5c\xef\x04\x16\x00\x08\x40\x81"
211         "\x87\x81\x1c\x80\xf1\x01\x01\x01\x10\x80\xf0\x01\x10\xff\x10\x10"
212         "\x80\xf1\x01";
213
214 void test_read_multi_opaque_rect_order(void)
215 {
216         STREAM _s, *s;
217         MULTI_OPAQUE_RECT_ORDER multi_opaque_rect;
218
219         s = &_s;
220         s->p = s->data = multi_opaque_rect_order;
221
222         memset(orderInfo, 0, sizeof(ORDER_INFO));
223         orderInfo->fieldFlags = 0x01BF;
224         memset(&multi_opaque_rect, 0, sizeof(MULTI_OPAQUE_RECT_ORDER));
225
226         update_read_multi_opaque_rect_order(s, orderInfo, &multi_opaque_rect);
227
228         CU_ASSERT(multi_opaque_rect.nLeftRect == 391);
229         CU_ASSERT(multi_opaque_rect.nTopRect == 284);
230         CU_ASSERT(multi_opaque_rect.nWidth == 241);
231         CU_ASSERT(multi_opaque_rect.nHeight == 18);
232         CU_ASSERT(multi_opaque_rect.color == 0x0000EF5C);
233         CU_ASSERT(multi_opaque_rect.cbData == 22);
234         CU_ASSERT(multi_opaque_rect.numRectangles == 4);
235
236         CU_ASSERT(multi_opaque_rect.rectangles[1].left == 391);
237         CU_ASSERT(multi_opaque_rect.rectangles[1].top == 284);
238         CU_ASSERT(multi_opaque_rect.rectangles[1].width == 241);
239         CU_ASSERT(multi_opaque_rect.rectangles[1].height == 1);
240
241         CU_ASSERT(multi_opaque_rect.rectangles[2].left == 391);
242         CU_ASSERT(multi_opaque_rect.rectangles[2].top == 285);
243         CU_ASSERT(multi_opaque_rect.rectangles[2].width == 1);
244         CU_ASSERT(multi_opaque_rect.rectangles[2].height == 16);
245
246         CU_ASSERT(multi_opaque_rect.rectangles[3].left == 631);
247         CU_ASSERT(multi_opaque_rect.rectangles[3].top == 285);
248         CU_ASSERT(multi_opaque_rect.rectangles[3].width == 1);
249         CU_ASSERT(multi_opaque_rect.rectangles[3].height == 16);
250
251         CU_ASSERT(multi_opaque_rect.rectangles[4].left == 391);
252         CU_ASSERT(multi_opaque_rect.rectangles[4].top == 301);
253         CU_ASSERT(multi_opaque_rect.rectangles[4].width == 241);
254         CU_ASSERT(multi_opaque_rect.rectangles[4].height == 1);
255
256         CU_ASSERT(stream_get_length(s) == (sizeof(multi_opaque_rect_order) - 1));
257 }
258
259 uint8 line_to_order[] = "\x03\xb1\x0e\xa6\x5b\xef\x00";
260
261 void test_read_line_to_order(void)
262 {
263         STREAM _s, *s;
264         LINE_TO_ORDER line_to;
265
266         s = &_s;
267         s->p = s->data = line_to_order;
268
269         memset(orderInfo, 0, sizeof(ORDER_INFO));
270         orderInfo->fieldFlags = 0x021E;
271         orderInfo->deltaCoordinates = true;
272
273         memset(&line_to, 0, sizeof(LINE_TO_ORDER));
274         line_to.nXStart = 826;
275         line_to.nYStart = 350;
276         line_to.nXEnd = 829;
277         line_to.nYEnd = 347;
278
279         update_read_line_to_order(s, orderInfo, &line_to);
280
281         CU_ASSERT(line_to.nXStart == 829);
282         CU_ASSERT(line_to.nYStart == 271);
283         CU_ASSERT(line_to.nXEnd == 843);
284         CU_ASSERT(line_to.nYEnd == 257);
285         CU_ASSERT(line_to.backColor == 0);
286         CU_ASSERT(line_to.bRop2 == 0);
287         CU_ASSERT(line_to.penStyle == 0);
288         CU_ASSERT(line_to.penWidth == 0);
289         CU_ASSERT(line_to.penColor == 0x00EF5B);
290
291         CU_ASSERT(stream_get_length(s) == (sizeof(line_to_order) - 1));
292 }
293
294 uint8 polyline_order[] =
295         "\xf8\x01\xb8\x02\x00\xc0\x00\x20\x6c\x00\x00\x00\x00\x00\x04\x00"
296         "\x00\xff\x7e\x76\xff\x41\x6c\xff\x24\x62\xff\x2b\x59\xff\x55\x51"
297         "\xff\x9c\x49\x73\x43\x80\x4d\xff\xbe\x80\x99\xff\xba\x80\xcd\xff"
298         "\xb7\x80\xde\xff\xb6\x80\xca\xff\xb6\x80\x96\xff\xb7\x80\x48\xff"
299         "\xba\x6f\xff\xbe\xff\x97\x43\xff\x52\x4a\xff\x2b\x51\xff\x24\x59"
300         "\xff\x44\x63\xff\x81\x6c\x56\x76\x2f\x80\x82\x0a\x80\xbf\x14\x80"
301         "\xdd\x1e\x80\xd4\x27\x80\xab\x2f\x80\x64\x37\x0d\x3d\xff\xb3\x80"
302         "\x42\xff\x67\x80\x46";
303
304 void test_read_polyline_order(void)
305 {
306         STREAM _s, *s;
307         POLYLINE_ORDER polyline;
308
309         s = &_s;
310         s->p = s->data = polyline_order;
311
312         memset(orderInfo, 0, sizeof(ORDER_INFO));
313         orderInfo->fieldFlags = 0x73;
314
315         memset(&polyline, 0, sizeof(POLYLINE_ORDER));
316
317         update_read_polyline_order(s, orderInfo, &polyline);
318
319         CU_ASSERT(polyline.xStart == 504);
320         CU_ASSERT(polyline.yStart == 696);
321         CU_ASSERT(polyline.bRop2 == 0);
322         CU_ASSERT(polyline.penColor == 0x0000C000);
323         CU_ASSERT(polyline.numPoints == 32);
324         CU_ASSERT(polyline.cbData == 108);
325
326         CU_ASSERT(polyline.points[0].x == -130);
327         CU_ASSERT(polyline.points[1].x == -191);
328         CU_ASSERT(polyline.points[2].x == -220);
329         CU_ASSERT(polyline.points[3].x == -213);
330         CU_ASSERT(polyline.points[4].x == -171);
331         CU_ASSERT(polyline.points[5].x == -100);
332         CU_ASSERT(polyline.points[6].x == -13);
333         CU_ASSERT(polyline.points[7].x == 77);
334         CU_ASSERT(polyline.points[8].x == 153);
335         CU_ASSERT(polyline.points[9].x == 205);
336         CU_ASSERT(polyline.points[10].x == 222);
337         CU_ASSERT(polyline.points[11].x == 202);
338         CU_ASSERT(polyline.points[12].x == 150);
339         CU_ASSERT(polyline.points[13].x == 72);
340         CU_ASSERT(polyline.points[14].x == -17);
341         CU_ASSERT(polyline.points[15].x == -105);
342         CU_ASSERT(polyline.points[16].x == -174);
343         CU_ASSERT(polyline.points[17].x == -213);
344         CU_ASSERT(polyline.points[18].x == -220);
345         CU_ASSERT(polyline.points[19].x == -188);
346         CU_ASSERT(polyline.points[20].x == -127);
347         CU_ASSERT(polyline.points[21].x == -42);
348         CU_ASSERT(polyline.points[22].x == 47);
349         CU_ASSERT(polyline.points[23].x == 130);
350         CU_ASSERT(polyline.points[24].x == 191);
351         CU_ASSERT(polyline.points[25].x == 221);
352         CU_ASSERT(polyline.points[26].x == 212);
353         CU_ASSERT(polyline.points[27].x == 171);
354         CU_ASSERT(polyline.points[28].x == 100);
355         CU_ASSERT(polyline.points[29].x == 13);
356         CU_ASSERT(polyline.points[30].x == -77);
357         CU_ASSERT(polyline.points[31].x == -153);
358         CU_ASSERT(polyline.points[32].x == 0);
359
360         CU_ASSERT(stream_get_length(s) == (sizeof(polyline_order) - 1));
361 }
362
363 uint8 glyph_index_order_1[] =
364         "\x6a\x02\x27\x38\x00\x39\x07\x3a\x06\x3b\x07\x3c\x06\x3d\x06\x18"
365         "\x04\x1f\x06\x17\x02\x14\x04\x1b\x06\x19\x06\x45\x05\x18\x06\x1f"
366         "\x06\x1f\x02\x14\x02\x46\x06\xff\x15\x24";
367
368 uint8 glyph_index_order_2[] =
369         "\x00\xff\xff\xff\x0c\x02\x6e\x01\x4d\x02\x7b\x01\x09\x02\x6e\x01"
370         "\xf6\x02\x7b\x01\x0c\x02\x79\x01\x03\xfe\x04\x00";
371
372 void test_read_glyph_index_order(void)
373 {
374         STREAM _s, *s;
375         GLYPH_INDEX_ORDER glyph_index;
376
377         s = &_s;
378         s->p = s->data = glyph_index_order_1;
379
380         memset(orderInfo, 0, sizeof(ORDER_INFO));
381         orderInfo->fieldFlags = 0x200100;
382         orderInfo->deltaCoordinates = true;
383
384         memset(&glyph_index, 0, sizeof(GLYPH_INDEX_ORDER));
385
386         update_read_glyph_index_order(s, orderInfo, &glyph_index);
387
388         CU_ASSERT(glyph_index.bkRight == 618);
389
390         CU_ASSERT(stream_get_length(s) == (sizeof(glyph_index_order_1) - 1));
391
392         s->p = s->data = glyph_index_order_2;
393
394         memset(orderInfo, 0, sizeof(ORDER_INFO));
395         orderInfo->fieldFlags = 0x383FE8;
396         orderInfo->deltaCoordinates = true;
397
398         memset(&glyph_index, 0, sizeof(GLYPH_INDEX_ORDER));
399
400         update_read_glyph_index_order(s, orderInfo, &glyph_index);
401
402         CU_ASSERT(glyph_index.fOpRedundant == 0);
403         CU_ASSERT(glyph_index.foreColor == 0x00FFFFFF);
404         CU_ASSERT(glyph_index.bkLeft == 524);
405         CU_ASSERT(glyph_index.bkTop == 366);
406         CU_ASSERT(glyph_index.bkRight == 589);
407         CU_ASSERT(glyph_index.bkBottom == 379);
408         CU_ASSERT(glyph_index.opLeft == 521);
409         CU_ASSERT(glyph_index.opTop == 366);
410         CU_ASSERT(glyph_index.opRight == 758);
411         CU_ASSERT(glyph_index.opBottom == 379);
412         CU_ASSERT(glyph_index.x == 524);
413         CU_ASSERT(glyph_index.y == 377);
414
415         CU_ASSERT(stream_get_length(s) == (sizeof(glyph_index_order_2) - 1));
416 }
417
418 uint8 fast_index_order[] =
419         "\x07\x00\x03\xff\xff\x00\x74\x3b\x00\x0e\x00\x71\x00\x42\x00\x7e"
420         "\x00\x00\x80\x7c\x00\x15\x00\x00\x01\x06\x02\x04\x03\x08\x05\x09"
421         "\x06\x06\x06\x06\x07\x06\x08\x02\xff\x00\x12";
422
423 void test_read_fast_index_order(void)
424 {
425         STREAM _s, *s;
426         FAST_INDEX_ORDER fast_index;
427
428         s = &_s;
429         s->p = s->data = fast_index_order;
430
431         memset(orderInfo, 0, sizeof(ORDER_INFO));
432         orderInfo->fieldFlags = 0x70FF;
433
434         memset(&fast_index, 0, sizeof(FAST_INDEX_ORDER));
435         update_read_fast_index_order(s, orderInfo, &fast_index);
436
437         CU_ASSERT(fast_index.cacheId == 7);
438         CU_ASSERT(fast_index.flAccel == 3);
439         CU_ASSERT(fast_index.ulCharInc == 0);
440         CU_ASSERT(fast_index.backColor == 0x0000FFFF);
441         CU_ASSERT(fast_index.foreColor == 0x00003B74);
442         CU_ASSERT(fast_index.bkLeft == 14);
443         CU_ASSERT(fast_index.bkTop == 113);
444         CU_ASSERT(fast_index.bkRight == 66);
445         CU_ASSERT(fast_index.bkBottom == 126);
446         CU_ASSERT(fast_index.opLeft == 0);
447         CU_ASSERT(fast_index.opTop == 0);
448         CU_ASSERT(fast_index.opRight == 0);
449         CU_ASSERT(fast_index.opBottom == 0);
450         CU_ASSERT(fast_index.x == -32768);
451         CU_ASSERT(fast_index.y == 124);
452
453         CU_ASSERT(stream_get_length(s) == (sizeof(fast_index_order) - 1));
454 }
455
456 uint8 fast_glyph_order[] =
457         "\x06\x00\x03\xff\xff\x00\x8b\x00\xb1\x00\x93\x00\xbe\x00\x0d\x00"
458         "\xfe\x7f\x00\x80\x00\x80\xbb\x00\x13\x00\x01\x4a\x06\x0a\x80\x80"
459         "\x80\xb8\xc4\x84\x84\x84\x84\x84\x00\x00\x68\x00";
460
461 void test_read_fast_glyph_order(void)
462 {
463         STREAM _s, *s;
464         FAST_GLYPH_ORDER fast_glyph;
465
466         s = &_s;
467         s->p = s->data = fast_glyph_order;
468
469         memset(orderInfo, 0, sizeof(ORDER_INFO));
470         orderInfo->fieldFlags = 0x7EFB;
471
472         memset(&fast_glyph, 0, sizeof(FAST_GLYPH_ORDER));
473
474         update_read_fast_glyph_order(s, orderInfo, &fast_glyph);
475
476         CU_ASSERT(fast_glyph.backColor == 0);
477         CU_ASSERT(fast_glyph.foreColor == 0x0000FFFF);
478         CU_ASSERT(fast_glyph.bkLeft == 139);
479         CU_ASSERT(fast_glyph.bkTop == 177);
480         CU_ASSERT(fast_glyph.bkRight == 147);
481         CU_ASSERT(fast_glyph.bkBottom == 190);
482         CU_ASSERT(fast_glyph.opLeft == 0);
483         CU_ASSERT(fast_glyph.opTop == 13);
484         CU_ASSERT(fast_glyph.opRight == 32766);
485         CU_ASSERT(fast_glyph.opBottom == -32768);
486         CU_ASSERT(fast_glyph.x == -32768);
487         CU_ASSERT(fast_glyph.y == 187);
488
489         CU_ASSERT(stream_get_length(s) == (sizeof(fast_glyph_order) - 1));
490 }
491
492 uint8 polygon_cb_order[] =
493         "\xea\x00\x46\x01\x0d\x01\x08\x00\x00\x04\x03\x81\x08\x03\x05\x88"
494         "\x09\x26\x09\x77";
495
496 void test_read_polygon_cb_order(void)
497 {
498         STREAM _s, *s;
499         POLYGON_CB_ORDER polygon_cb;
500
501         s = &_s;
502         s->p = s->data = polygon_cb_order;
503
504         memset(orderInfo, 0, sizeof(ORDER_INFO));
505         orderInfo->fieldFlags = 0x1BEF;
506
507         memset(&polygon_cb, 0, sizeof(POLYGON_CB_ORDER));
508
509         update_read_polygon_cb_order(s, orderInfo, &polygon_cb);
510
511         CU_ASSERT(polygon_cb.xStart == 234);
512         CU_ASSERT(polygon_cb.yStart == 326);
513         CU_ASSERT(polygon_cb.bRop2 == 0x0D);
514         CU_ASSERT(polygon_cb.fillMode == 1);
515         CU_ASSERT(polygon_cb.backColor == 0);
516         CU_ASSERT(polygon_cb.foreColor == 0x00000008);
517         CU_ASSERT(polygon_cb.brush.x == 4);
518         CU_ASSERT(polygon_cb.brush.y == 3);
519         CU_ASSERT(polygon_cb.brush.style == 0x81);
520         CU_ASSERT(polygon_cb.nDeltaEntries == 3);
521         CU_ASSERT(polygon_cb.cbData == 5);
522
523         CU_ASSERT(stream_get_length(s) == (sizeof(polygon_cb_order) - 1));
524 }
525
526 uint8 cache_bitmap_order[] = "\x00\x00\x10\x01\x08\x01\x00\x00\x00\x10";
527
528 void test_read_cache_bitmap_order(void)
529 {
530         STREAM _s, *s;
531         uint16 extraFlags;
532         CACHE_BITMAP_ORDER cache_bitmap;
533
534         s = &_s;
535         extraFlags = 0x0400;
536         s->p = s->data = cache_bitmap_order;
537
538         memset(&cache_bitmap, 0, sizeof(CACHE_BITMAP_ORDER));
539
540         update_read_cache_bitmap_order(s, &cache_bitmap, true, extraFlags);
541
542         CU_ASSERT(cache_bitmap.cacheId == 0);
543         CU_ASSERT(cache_bitmap.bitmapWidth == 16);
544         CU_ASSERT(cache_bitmap.bitmapHeight == 1);
545         CU_ASSERT(cache_bitmap.bitmapBpp == 8);
546         CU_ASSERT(cache_bitmap.bitmapLength == 1);
547         CU_ASSERT(cache_bitmap.cacheIndex == 0);
548
549         CU_ASSERT(stream_get_length(s) == (sizeof(cache_bitmap_order) - 1));
550 }
551
552 uint8 cache_bitmap_v2_order[] =
553         "\x20\x40\xdc\xff\xff\x85\xff\xff\x99\xd6\x99\xd6\x99\xd6\x99\xd6"
554         "\x06\x8b\x99\xd6\x99\xd6\x99\xd6\x10\x84\x08\x42\x08\x42\x10\x84"
555         "\x99\xd6\x99\xd6\x99\xd6\x99\xd6\x06\x84\x99\xd6\x99\xd6\x99\xd6"
556         "\xff\xff\x16\x69\x99\xd6\x06\x69\x99\xd6\x04\xcc\x89\x52\x03\x6e"
557         "\xff\xff\x02\x6e\x08\x42\x01\x70\x08\x42\x71\xff\xff\xce\x18\xc6"
558         "\x01\x81\x08\x42\xce\x66\x29\x02\xcd\x89\x52\x03\x88\x10\x84\x99"
559         "\xd6\x99\xd6\x99\xd6\x00\x00\x00\x00\x00\x00\x00\x00\xd8\x99\xd6"
560         "\x03\xf8\x01\x00\x00\x00\x00\xf0\x66\x99\xd6\x05\x6a\x99\xd6\x00"
561         "\xc4\xcc\x89\x52\x03\x6e\xff\xff\x02\x6e\x08\x42\x01\x70\x08\x42"
562         "\x71\xff\xff\xce\x18\xc6\x01\x81\x08\x42\xce\x66\x29\x02\xcd\x89"
563         "\x52\x03\x00\x04\xd6\x99\xd6\xc3\x80\x61\x00\xa5\x80\x40\xec\x52"
564         "\x00\x5a\x00\x2d\x00\x24\x00\x12\x00\x24\x00\x12\x00\x5a\x00\x2d"
565         "\x00\xa5\x80\x52\x00\xc3\x80\x61\x00\x00\x00\x00\x00\xcc\x89\x52"
566         "\x03\x6e\xff\xff\x02\xcb\x18\xc6\x84\x08\x42\x08\x42\x08\x42\xff"
567         "\xff";
568
569 void test_read_cache_bitmap_v2_order(void)
570 {
571         STREAM _s, *s;
572         uint16 extraFlags;
573         CACHE_BITMAP_V2_ORDER cache_bitmap_v2;
574
575         s = &_s;
576         extraFlags = 0x0CA1;
577         s->p = s->data = cache_bitmap_v2_order;
578
579         memset(&cache_bitmap_v2, 0, sizeof(CACHE_BITMAP_V2_ORDER));
580
581         update_read_cache_bitmap_v2_order(s, &cache_bitmap_v2, true, extraFlags);
582
583         CU_ASSERT(cache_bitmap_v2.cacheId == 1);
584         CU_ASSERT(cache_bitmap_v2.bitmapBpp == 16);
585         CU_ASSERT(cache_bitmap_v2.flags == 0x19);
586         CU_ASSERT(cache_bitmap_v2.bitmapWidth == 32);
587         CU_ASSERT(cache_bitmap_v2.bitmapHeight == 32);
588         CU_ASSERT(cache_bitmap_v2.bitmapLength == 220);
589         CU_ASSERT(cache_bitmap_v2.cacheIndex == 32767);
590
591         CU_ASSERT(stream_get_length(s) == (sizeof(cache_bitmap_v2_order) - 1));
592 }
593
594 uint8 cache_bitmap_v3_order[] =
595         "\xff\x7f\x35\x50\xec\xbc\x74\x52\x65\xb7\x20\x00\x00\x00\x05\x00"
596         "\x02\x00\x28\x00\x00\x00\x5b\x4f\x45\xff\x5b\x4f\x45\xff\x5b\x4f"
597         "\x45\xff\x5b\x4f\x45\xff\x5b\x4f\x45\xff\x5b\x50\x45\xff\x5b\x50"
598         "\x45\xff\x5b\x50\x45\xff\x5b\x50\x45\xff\x5b\x50\x45\xff";
599
600 void test_read_cache_bitmap_v3_order(void)
601 {
602         STREAM _s, *s;
603         uint16 extraFlags;
604         CACHE_BITMAP_V3_ORDER cache_bitmap_v3;
605
606         s = &_s;
607         extraFlags = 0x0C30;
608         s->p = s->data = cache_bitmap_v3_order;
609
610         memset(&cache_bitmap_v3, 0, sizeof(CACHE_BITMAP_V3_ORDER));
611
612         update_read_cache_bitmap_v3_order(s, &cache_bitmap_v3, true, extraFlags);
613
614         CU_ASSERT(cache_bitmap_v3.cacheIndex == 32767);
615         CU_ASSERT(cache_bitmap_v3.key1 == 0xBCEC5035);
616         CU_ASSERT(cache_bitmap_v3.key2 == 0xB7655274);
617         CU_ASSERT(cache_bitmap_v3.bpp == 32);
618
619         CU_ASSERT(cache_bitmap_v3.bitmapData.bpp == 32);
620         CU_ASSERT(cache_bitmap_v3.bitmapData.codecID == 0);
621         CU_ASSERT(cache_bitmap_v3.bitmapData.width == 5);
622         CU_ASSERT(cache_bitmap_v3.bitmapData.height == 2);
623         CU_ASSERT(cache_bitmap_v3.bitmapData.length == 40);
624
625         CU_ASSERT(stream_get_length(s) == (sizeof(cache_bitmap_v3_order) - 1));
626 }
627
628 uint8 cache_brush_order[] = "\x00\x01\x08\x08\x81\x08\xaa\x55\xaa\x55\xaa\x55\xaa\x55";
629
630 void test_read_cache_brush_order(void)
631 {
632         STREAM _s, *s;
633         CACHE_BRUSH_ORDER cache_brush;
634
635         s = &_s;
636         s->p = s->data = cache_brush_order;
637
638         memset(&cache_brush, 0, sizeof(CACHE_BRUSH_ORDER));
639
640         update_read_cache_brush_order(s, &cache_brush, 0);
641
642         CU_ASSERT(cache_brush.index == 0);
643         CU_ASSERT(cache_brush.bpp == 1);
644         CU_ASSERT(cache_brush.cx == 8);
645         CU_ASSERT(cache_brush.cy == 8);
646         CU_ASSERT(cache_brush.style == 0x81);
647         CU_ASSERT(cache_brush.length == 8);
648
649         CU_ASSERT(stream_get_length(s) == (sizeof(cache_brush_order) - 1));
650 }
651
652 uint8 create_offscreen_bitmap_order[] = "\x00\x80\x60\x01\x10\x00\x01\x00\x02\x00";
653
654 void test_read_create_offscreen_bitmap_order(void)
655 {
656         STREAM _s, *s;
657         OFFSCREEN_DELETE_LIST* deleteList;
658         CREATE_OFFSCREEN_BITMAP_ORDER create_offscreen_bitmap;
659
660         s = &_s;
661         s->p = s->data = create_offscreen_bitmap_order;
662
663         memset(&create_offscreen_bitmap, 0, sizeof(CREATE_OFFSCREEN_BITMAP_ORDER));
664
665         deleteList = &(create_offscreen_bitmap.deleteList);
666         deleteList->cIndices = 0;
667         deleteList->sIndices = 16;
668         deleteList->indices = malloc(sizeof(uint16) * deleteList->sIndices);
669
670         update_read_create_offscreen_bitmap_order(s, &create_offscreen_bitmap);
671
672         CU_ASSERT(create_offscreen_bitmap.id == 0);
673         CU_ASSERT(create_offscreen_bitmap.cx == 352);
674         CU_ASSERT(create_offscreen_bitmap.cy == 16);
675         CU_ASSERT(create_offscreen_bitmap.deleteList.cIndices == 1);
676
677         CU_ASSERT(stream_get_length(s) == (sizeof(create_offscreen_bitmap_order) - 1));
678 }
679
680 uint8 switch_surface_order[] = "\xff\xff";
681
682 void test_read_switch_surface_order(void)
683 {
684         STREAM _s, *s;
685         SWITCH_SURFACE_ORDER switch_surface;
686
687         s = &_s;
688         s->p = s->data = switch_surface_order;
689
690         memset(&switch_surface, 0, sizeof(SWITCH_SURFACE_ORDER));
691
692         update_read_switch_surface_order(s, &switch_surface);
693
694         CU_ASSERT(switch_surface.bitmapId == 0xFFFF);
695
696         CU_ASSERT(stream_get_length(s) == (sizeof(switch_surface_order) - 1));
697 }
698
699 int opaque_rect_count;
700 int polyline_count;
701 int patblt_count;
702
703 uint8 orders_update_1[] =
704         "\x00\x00\x33\xd0\x07\x00\x80\xba\x0d\x0a\x7f\x1e\x2c\x4d\x00\x36"
705         "\x02\xd3\x00\x47\x00\x4d\x00\xf0\x01\x87\x00\xc2\xdc\xff\x05\x7f"
706         "\x0f\x67\x01\x90\x01\x8e\x01\xa5\x01\x67\x01\x90\x01\x28\x00\x16"
707         "\x00\xf0\xf0\xf0\x15\x0f\xf0\x2d\x01\x19\xfe\x2d\x01\xec\xfd\x0d"
708         "\x16\x77\xf0\xff\xff\x01\x01\xa8\x01\x90\x01\x0d\xf0\xf0\xf0\x04"
709         "\x05\x66\x6b\x14\x15\x6c\x1d\x0a\x0f\xd0\x16\x64\x01\x15\xff\x50"
710         "\x03\x15\x0f\xf0\x65\x01\x15\xfe\x65\x01\xb0\xfd\x1d\x16\x01\xf0"
711         "\xff\xff\x01\x01\x7a";
712
713 uint8 orders_update_2[] =
714         "\x00\x00\x45\x62\x03\x00\x93\x14\x55\x01\x50\xff\xff\xff\x55\x01"
715         "\x50\x01\x01\x01\x55\x01\x50\xff\xff\xff\x16\x00\x17\x00\xea\x03"
716         "\xea\x03\x02\x00\x85\x02\x16\x00\x02\x00\x00\x00\x03\x00\x14\xb2";
717
718 void test_opaque_rect(rdpContext* context, OPAQUE_RECT_ORDER* opaque_rect)
719 {
720         opaque_rect_count++;
721 }
722
723 void test_polyline(rdpContext* context, POLYLINE_ORDER* polyline)
724 {
725         polyline_count++;
726 }
727
728 void test_patblt(rdpContext* context, PATBLT_ORDER* patblt)
729 {
730         patblt_count++;
731 }
732
733 void test_update_recv_orders(void)
734 {
735         rdpRdp* rdp;
736         STREAM _s, *s;
737         rdpUpdate* update;
738
739         s = &_s;
740         rdp = rdp_new(NULL);
741         update = update_new(rdp);
742
743         update->context = malloc(sizeof(rdpContext));
744         update->context->rdp = rdp;
745
746         opaque_rect_count = 0;
747         polyline_count = 0;
748         patblt_count = 0;
749
750         update->primary->OpaqueRect = test_opaque_rect;
751         update->primary->Polyline = test_polyline;
752         update->primary->PatBlt = test_patblt;
753
754         s->p = s->data = orders_update_1;
755         s->size = sizeof(orders_update_1);
756
757         update_recv(update, s);
758
759         CU_ASSERT(opaque_rect_count == 5);
760         CU_ASSERT(polyline_count == 2);
761
762         update->primary->order_info.orderType = ORDER_TYPE_PATBLT;
763         s->p = s->data = orders_update_2;
764         s->size = sizeof(orders_update_2);
765
766         update_recv(update, s);
767
768         CU_ASSERT(patblt_count == 3);
769
770         free(update->context);
771 }
772