20 #include <winpr/crt.h>
21 #include <winpr/print.h>
23 #include <freerdp/codec/region.h>
27 for (
int i = 0; i < nb; i++, src1++, src2++)
32 "expecting rect %d (%" PRIu16
",%" PRIu16
"-%" PRIu16
",%" PRIu16
33 ") and have (%" PRIu16
",%" PRIu16
"-%" PRIu16
",%" PRIu16
")\n",
34 i, src2->left, src2->top, src2->right, src2->bottom, src1->left,
35 src1->top, src1->right, src1->bottom);
43 static int test_basic(
void)
52 RECTANGLE_16 r1_r2[] = { { 0, 101, 200, 201 }, { 150, 301, 250, 401 } };
54 region16_init(®ion);
56 if (!region16_union_rect(®ion, ®ion, &r1))
59 rects = region16_rects(®ion, &nbRects);
61 if (!rects || nbRects != 1 || memcmp(rects, &r1,
sizeof(
RECTANGLE_16)) != 0)
65 if (!region16_union_rect(®ion, ®ion, &r2))
68 rects = region16_rects(®ion, &nbRects);
70 if (!rects || nbRects != 2 || !compareRectangles(rects, r1_r2, nbRects))
74 region16_clear(®ion);
75 region16_rects(®ion, &nbRects);
82 region16_uninit(®ion);
86 static int test_r1_r3(
void)
94 RECTANGLE_16 r1_r3[] = { { 0, 101, 200, 151 }, { 0, 151, 250, 201 }, { 150, 201, 250, 251 } };
95 region16_init(®ion);
109 if (!region16_union_rect(®ion, ®ion, &r1))
112 if (!region16_union_rect(®ion, ®ion, &r3))
115 rects = region16_rects(®ion, &nbRects);
117 if (!rects || nbRects != 3 || !compareRectangles(rects, r1_r3, nbRects))
121 region16_clear(®ion);
123 if (!region16_union_rect(®ion, ®ion, &r3))
126 if (!region16_union_rect(®ion, ®ion, &r1))
129 rects = region16_rects(®ion, &nbRects);
131 if (!rects || nbRects != 3 || !compareRectangles(rects, r1_r3, nbRects))
136 region16_uninit(®ion);
140 static int test_r9_r10(
void)
162 { 200, 0, 300, 100 },
163 { 0, 100, 400, 200 },
164 { 200, 200, 300, 300 },
166 region16_init(®ion);
168 if (!region16_union_rect(®ion, ®ion, &r9))
171 if (!region16_union_rect(®ion, ®ion, &r10))
174 rects = region16_rects(®ion, &nbRects);
176 if (!rects || nbRects != 3 || !compareRectangles(rects, r9_r10, nbRects))
181 region16_uninit(®ion);
185 static int test_r1_r5(
void)
193 RECTANGLE_16 r1_r5[] = { { 0, 101, 200, 121 }, { 0, 121, 300, 131 }, { 0, 131, 200, 201 } };
194 region16_init(®ion);
209 if (!region16_union_rect(®ion, ®ion, &r1))
212 if (!region16_union_rect(®ion, ®ion, &r5))
215 rects = region16_rects(®ion, &nbRects);
217 if (!rects || nbRects != 3 || !compareRectangles(rects, r1_r5, nbRects))
222 region16_uninit(®ion);
226 static int test_r1_r6(
void)
234 region16_init(®ion);
247 region16_clear(®ion);
249 if (!region16_union_rect(®ion, ®ion, &r1))
252 if (!region16_union_rect(®ion, ®ion, &r6))
255 rects = region16_rects(®ion, &nbRects);
257 if (!rects || nbRects != 1 || !compareRectangles(rects, &r1, nbRects))
262 region16_uninit(®ion);
266 static int test_r1_r2_r4(
void)
275 RECTANGLE_16 r1_r2_r4[] = { { 0, 101, 200, 201 }, { 150, 251, 250, 401 } };
293 region16_init(®ion);
295 if (!region16_union_rect(®ion, ®ion, &r1))
298 if (!region16_union_rect(®ion, ®ion, &r2))
301 if (!region16_union_rect(®ion, ®ion, &r4))
304 rects = region16_rects(®ion, &nbRects);
306 if (!rects || nbRects != 2 || !compareRectangles(rects, r1_r2_r4, nbRects))
311 region16_uninit(®ion);
315 static int test_r1_r7_r8(
void)
325 { 0, 101, 200, 121 }, { 300, 101, 500, 121 }, { 0, 121, 500, 131 },
326 { 0, 131, 200, 201 }, { 300, 131, 500, 201 },
340 region16_init(®ion);
342 if (!region16_union_rect(®ion, ®ion, &r1))
345 if (!region16_union_rect(®ion, ®ion, &r7))
348 if (!region16_union_rect(®ion, ®ion, &r8))
351 rects = region16_rects(®ion, &nbRects);
353 if (!rects || nbRects != 5 || !compareRectangles(rects, r1_r7_r8, nbRects))
356 region16_clear(®ion);
358 if (!region16_union_rect(®ion, ®ion, &r1))
361 if (!region16_union_rect(®ion, ®ion, &r8))
364 if (!region16_union_rect(®ion, ®ion, &r7))
367 rects = region16_rects(®ion, &nbRects);
369 if (!rects || nbRects != 5 || !compareRectangles(rects, r1_r7_r8, nbRects))
372 region16_clear(®ion);
374 if (!region16_union_rect(®ion, ®ion, &r8))
377 if (!region16_union_rect(®ion, ®ion, &r7))
380 if (!region16_union_rect(®ion, ®ion, &r1))
383 rects = region16_rects(®ion, &nbRects);
385 if (!rects || nbRects != 5 || !compareRectangles(rects, r1_r7_r8, nbRects))
390 region16_uninit(®ion);
394 static int test_r1_r2_r3_r4(
void)
405 { 0, 101, 200, 151 }, { 0, 151, 250, 201 }, { 150, 201, 250, 251 }, { 150, 301, 250, 401 }
408 { 0, 151, 250, 201 },
409 { 150, 201, 250, 401 } };
410 region16_init(®ion);
427 if (!region16_union_rect(®ion, ®ion, &r1))
430 if (!region16_union_rect(®ion, ®ion, &r2))
433 if (!region16_union_rect(®ion, ®ion, &r3))
436 rects = region16_rects(®ion, &nbRects);
438 if (!rects || nbRects != 4 || !compareRectangles(rects, r1_r2_r3, 4))
457 if (!region16_union_rect(®ion, ®ion, &r4))
460 rects = region16_rects(®ion, &nbRects);
462 if (!rects || nbRects != 3 || !compareRectangles(rects, r1_r2_r3_r4, 3))
467 region16_uninit(®ion);
471 static int test_from_weston(
void)
485 RECTANGLE_16 r1_r2_r3[] = { { 0, 0, 640, 32 }, { 236, 169, 268, 201 }, { 246, 258, 278, 290 } };
486 region16_init(®ion);
503 if (!region16_union_rect(®ion, ®ion, &r1))
506 if (!region16_union_rect(®ion, ®ion, &r2))
509 if (!region16_union_rect(®ion, ®ion, &r3))
512 rects = region16_rects(®ion, &nbRects);
514 if (!rects || nbRects != 3 || !compareRectangles(rects, r1_r2_r3, 3))
519 region16_uninit(®ion);
523 static int test_r1_inter_r3(
void)
533 { 150, 151, 200, 201 },
535 region16_init(®ion);
536 region16_init(&intersection);
549 if (!region16_union_rect(®ion, ®ion, &r1))
552 if (!region16_intersects_rect(®ion, &r3))
555 if (!region16_intersect_rect(&intersection, ®ion, &r3))
558 rects = region16_rects(&intersection, &nbRects);
560 if (!rects || nbRects != 1 || !compareRectangles(rects, r1_inter_r3, nbRects))
565 region16_uninit(®ion);
566 region16_uninit(&intersection);
570 static int test_r1_r3_inter_r11(
void)
581 { 170, 151, 250, 251 },
583 region16_init(®ion);
584 region16_init(&intersection);
606 if (!region16_union_rect(®ion, ®ion, &r1))
609 if (!region16_union_rect(®ion, ®ion, &r3))
612 if (!region16_intersects_rect(®ion, &r11))
615 if (!region16_intersect_rect(&intersection, ®ion, &r11))
618 rects = region16_rects(&intersection, &nbRects);
620 if (!rects || nbRects != 1 || !compareRectangles(rects, r1_r3_inter_r11, nbRects))
625 region16_uninit(&intersection);
626 region16_uninit(®ion);
630 static int test_norbert_case(
void)
637 RECTANGLE_16 inRectangles[5] = { { 1680, 0, 1920, 242 },
638 { 294, 242, 971, 776 },
639 { 1680, 242, 1920, 776 },
640 { 1680, 776, 1920, 1036 },
641 { 2, 1040, 53, 1078 } };
643 RECTANGLE_16 expected_inter_extents = { 2, 0, 1920, 1078 };
644 region16_init(®ion);
645 region16_init(&intersection);
673 for (
int i = 0; i < 5; i++)
675 if (!region16_union_rect(®ion, ®ion, &inRectangles[i]))
679 if (!compareRectangles(region16_extents(®ion), &expected_inter_extents, 1))
682 if (!region16_intersect_rect(&intersection, ®ion, &screenRect))
685 rects = region16_rects(&intersection, &nbRects);
687 if (!rects || nbRects != 5 || !compareRectangles(rects, inRectangles, nbRects))
690 if (!compareRectangles(region16_extents(&intersection), &expected_inter_extents, 1))
695 region16_uninit(&intersection);
696 region16_uninit(®ion);
700 static int test_norbert2_case(
void)
708 region16_init(®ion);
710 if (!region16_union_rect(®ion, ®ion, &rect1))
712 (void)fprintf(stderr,
"%s: Error 1 - region16_union_rect failed\n", __func__);
716 if (!(rects = region16_rects(®ion, &nbRects)))
718 (void)fprintf(stderr,
"%s: Error 2 - region16_rects failed\n", __func__);
724 (void)fprintf(stderr,
"%s: Error 3 - expected nbRects == 1 but got %" PRIu32
"\n", __func__,
729 if (!compareRectangles(&rects[0], &rect1, 1))
731 (void)fprintf(stderr,
"%s: Error 4 - compare failed\n", __func__);
735 if (!region16_union_rect(®ion, ®ion, &rect2))
737 (void)fprintf(stderr,
"%s: Error 5 - region16_union_rect failed\n", __func__);
741 if (!(rects = region16_rects(®ion, &nbRects)))
743 (void)fprintf(stderr,
"%s: Error 6 - region16_rects failed\n", __func__);
749 (void)fprintf(stderr,
"%s: Error 7 - expected nbRects == 2 but got %" PRIu32
"\n", __func__,
754 if (!compareRectangles(&rects[0], &rect2, 1))
756 (void)fprintf(stderr,
"%s: Error 8 - compare failed\n", __func__);
760 if (!compareRectangles(&rects[1], &rect1, 1))
762 (void)fprintf(stderr,
"%s: Error 9 - compare failed\n", __func__);
768 region16_uninit(®ion);
772 static int test_empty_rectangle(
void)
777 RECTANGLE_16 emptyRectangles[3] = { { 0, 0, 0, 0 }, { 10, 10, 10, 11 }, { 10, 10, 11, 10 } };
781 region16_init(®ion);
782 region16_init(&intersection);
785 for (
int i = 0; i < 3; i++)
787 if (!rectangle_is_empty(&emptyRectangles[i]))
792 if (rectangle_is_empty(&firstRect))
796 if (!region16_union_rect(®ion, ®ion, &firstRect))
799 if (!region16_intersect_rect(®ion, ®ion, &anotherRect))
802 if (!compareRectangles(region16_extents(®ion), &expected_inter_extents, 1))
805 if (!region16_is_empty(®ion))
808 if (!rectangle_is_empty(region16_extents(&intersection)))
813 region16_uninit(&intersection);
814 region16_uninit(®ion);
818 typedef int (*TestFunction)(void);
825 static struct UnitaryTest tests[] = { {
"Basic trivial tests", test_basic },
826 {
"R1+R3 and R3+R1", test_r1_r3 },
827 {
"R1+R5", test_r1_r5 },
828 {
"R1+R6", test_r1_r6 },
829 {
"R9+R10", test_r9_r10 },
830 {
"R1+R2+R4", test_r1_r2_r4 },
831 {
"R1+R7+R8 in many orders", test_r1_r7_r8 },
832 {
"R1+R2+R3+R4", test_r1_r2_r3_r4 },
833 {
"data from weston", test_from_weston },
834 {
"R1 & R3", test_r1_inter_r3 },
835 {
"(R1+R3)&R11 (band merge)", test_r1_r3_inter_r11 },
836 {
"norbert's case", test_norbert_case },
837 {
"norbert's case 2", test_norbert2_case },
838 {
"empty rectangle case", test_empty_rectangle },
842 int TestFreeRDPRegion(
int argc,
char* argv[])
849 for (
int i = 0; tests[i].func; i++)
852 (void)fprintf(stderr,
"%d: %s\n", testNb, tests[i].name);
853 retCode = tests[i].func();
860 (void)fprintf(stderr,
"failed for test %d\n", testNb);