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 ||
71 !compareRectangles(rects, r1_r2, WINPR_ASSERTING_INT_CAST(
int, nbRects)))
75 region16_clear(®ion);
76 region16_rects(®ion, &nbRects);
83 region16_uninit(®ion);
87 static int test_r1_r3(
void)
95 RECTANGLE_16 r1_r3[] = { { 0, 101, 200, 151 }, { 0, 151, 250, 201 }, { 150, 201, 250, 251 } };
96 region16_init(®ion);
110 if (!region16_union_rect(®ion, ®ion, &r1))
113 if (!region16_union_rect(®ion, ®ion, &r3))
116 rects = region16_rects(®ion, &nbRects);
118 if (!rects || nbRects != 3 ||
119 !compareRectangles(rects, r1_r3, WINPR_ASSERTING_INT_CAST(
int, nbRects)))
123 region16_clear(®ion);
125 if (!region16_union_rect(®ion, ®ion, &r3))
128 if (!region16_union_rect(®ion, ®ion, &r1))
131 rects = region16_rects(®ion, &nbRects);
133 if (!rects || nbRects != 3 ||
134 !compareRectangles(rects, r1_r3, WINPR_ASSERTING_INT_CAST(
int, nbRects)))
139 region16_uninit(®ion);
143 static int test_r9_r10(
void)
165 { 200, 0, 300, 100 },
166 { 0, 100, 400, 200 },
167 { 200, 200, 300, 300 },
169 region16_init(®ion);
171 if (!region16_union_rect(®ion, ®ion, &r9))
174 if (!region16_union_rect(®ion, ®ion, &r10))
177 rects = region16_rects(®ion, &nbRects);
179 if (!rects || nbRects != 3 ||
180 !compareRectangles(rects, r9_r10, WINPR_ASSERTING_INT_CAST(
int, nbRects)))
185 region16_uninit(®ion);
189 static int test_r1_r5(
void)
197 RECTANGLE_16 r1_r5[] = { { 0, 101, 200, 121 }, { 0, 121, 300, 131 }, { 0, 131, 200, 201 } };
198 region16_init(®ion);
213 if (!region16_union_rect(®ion, ®ion, &r1))
216 if (!region16_union_rect(®ion, ®ion, &r5))
219 rects = region16_rects(®ion, &nbRects);
221 if (!rects || nbRects != 3 ||
222 !compareRectangles(rects, r1_r5, WINPR_ASSERTING_INT_CAST(
int, nbRects)))
227 region16_uninit(®ion);
231 static int test_r1_r6(
void)
239 region16_init(®ion);
252 region16_clear(®ion);
254 if (!region16_union_rect(®ion, ®ion, &r1))
257 if (!region16_union_rect(®ion, ®ion, &r6))
260 rects = region16_rects(®ion, &nbRects);
262 if (!rects || nbRects != 1 ||
263 !compareRectangles(rects, &r1, WINPR_ASSERTING_INT_CAST(
int, nbRects)))
268 region16_uninit(®ion);
272 static int test_r1_r2_r4(
void)
281 RECTANGLE_16 r1_r2_r4[] = { { 0, 101, 200, 201 }, { 150, 251, 250, 401 } };
299 region16_init(®ion);
301 if (!region16_union_rect(®ion, ®ion, &r1))
304 if (!region16_union_rect(®ion, ®ion, &r2))
307 if (!region16_union_rect(®ion, ®ion, &r4))
310 rects = region16_rects(®ion, &nbRects);
312 if (!rects || nbRects != 2 ||
313 !compareRectangles(rects, r1_r2_r4, WINPR_ASSERTING_INT_CAST(
int, nbRects)))
318 region16_uninit(®ion);
322 static int test_r1_r7_r8(
void)
332 { 0, 101, 200, 121 }, { 300, 101, 500, 121 }, { 0, 121, 500, 131 },
333 { 0, 131, 200, 201 }, { 300, 131, 500, 201 },
347 region16_init(®ion);
349 if (!region16_union_rect(®ion, ®ion, &r1))
352 if (!region16_union_rect(®ion, ®ion, &r7))
355 if (!region16_union_rect(®ion, ®ion, &r8))
358 rects = region16_rects(®ion, &nbRects);
360 if (!rects || nbRects != 5 ||
361 !compareRectangles(rects, r1_r7_r8, WINPR_ASSERTING_INT_CAST(
int, nbRects)))
364 region16_clear(®ion);
366 if (!region16_union_rect(®ion, ®ion, &r1))
369 if (!region16_union_rect(®ion, ®ion, &r8))
372 if (!region16_union_rect(®ion, ®ion, &r7))
375 rects = region16_rects(®ion, &nbRects);
377 if (!rects || nbRects != 5 ||
378 !compareRectangles(rects, r1_r7_r8, WINPR_ASSERTING_INT_CAST(
int, nbRects)))
381 region16_clear(®ion);
383 if (!region16_union_rect(®ion, ®ion, &r8))
386 if (!region16_union_rect(®ion, ®ion, &r7))
389 if (!region16_union_rect(®ion, ®ion, &r1))
392 rects = region16_rects(®ion, &nbRects);
394 if (!rects || nbRects != 5 ||
395 !compareRectangles(rects, r1_r7_r8, WINPR_ASSERTING_INT_CAST(
int, nbRects)))
400 region16_uninit(®ion);
404 static int test_r1_r2_r3_r4(
void)
415 { 0, 101, 200, 151 }, { 0, 151, 250, 201 }, { 150, 201, 250, 251 }, { 150, 301, 250, 401 }
418 { 0, 151, 250, 201 },
419 { 150, 201, 250, 401 } };
420 region16_init(®ion);
437 if (!region16_union_rect(®ion, ®ion, &r1))
440 if (!region16_union_rect(®ion, ®ion, &r2))
443 if (!region16_union_rect(®ion, ®ion, &r3))
446 rects = region16_rects(®ion, &nbRects);
448 if (!rects || nbRects != 4 || !compareRectangles(rects, r1_r2_r3, 4))
467 if (!region16_union_rect(®ion, ®ion, &r4))
470 rects = region16_rects(®ion, &nbRects);
472 if (!rects || nbRects != 3 || !compareRectangles(rects, r1_r2_r3_r4, 3))
477 region16_uninit(®ion);
481 static int test_from_weston(
void)
495 RECTANGLE_16 r1_r2_r3[] = { { 0, 0, 640, 32 }, { 236, 169, 268, 201 }, { 246, 258, 278, 290 } };
496 region16_init(®ion);
513 if (!region16_union_rect(®ion, ®ion, &r1))
516 if (!region16_union_rect(®ion, ®ion, &r2))
519 if (!region16_union_rect(®ion, ®ion, &r3))
522 rects = region16_rects(®ion, &nbRects);
524 if (!rects || nbRects != 3 || !compareRectangles(rects, r1_r2_r3, 3))
529 region16_uninit(®ion);
533 static int test_r1_inter_r3(
void)
543 { 150, 151, 200, 201 },
545 region16_init(®ion);
546 region16_init(&intersection);
559 if (!region16_union_rect(®ion, ®ion, &r1))
562 if (!region16_intersects_rect(®ion, &r3))
565 if (!region16_intersect_rect(&intersection, ®ion, &r3))
568 rects = region16_rects(&intersection, &nbRects);
570 if (!rects || nbRects != 1 ||
571 !compareRectangles(rects, r1_inter_r3, WINPR_ASSERTING_INT_CAST(
int, nbRects)))
576 region16_uninit(®ion);
577 region16_uninit(&intersection);
581 static int test_r1_r3_inter_r11(
void)
592 { 170, 151, 250, 251 },
594 region16_init(®ion);
595 region16_init(&intersection);
617 if (!region16_union_rect(®ion, ®ion, &r1))
620 if (!region16_union_rect(®ion, ®ion, &r3))
623 if (!region16_intersects_rect(®ion, &r11))
626 if (!region16_intersect_rect(&intersection, ®ion, &r11))
629 rects = region16_rects(&intersection, &nbRects);
631 if (!rects || nbRects != 1 ||
632 !compareRectangles(rects, r1_r3_inter_r11, WINPR_ASSERTING_INT_CAST(
int, nbRects)))
637 region16_uninit(&intersection);
638 region16_uninit(®ion);
642 static int test_norbert_case(
void)
649 RECTANGLE_16 inRectangles[5] = { { 1680, 0, 1920, 242 },
650 { 294, 242, 971, 776 },
651 { 1680, 242, 1920, 776 },
652 { 1680, 776, 1920, 1036 },
653 { 2, 1040, 53, 1078 } };
655 RECTANGLE_16 expected_inter_extents = { 2, 0, 1920, 1078 };
656 region16_init(®ion);
657 region16_init(&intersection);
685 for (
int i = 0; i < 5; i++)
687 if (!region16_union_rect(®ion, ®ion, &inRectangles[i]))
691 if (!compareRectangles(region16_extents(®ion), &expected_inter_extents, 1))
694 if (!region16_intersect_rect(&intersection, ®ion, &screenRect))
697 rects = region16_rects(&intersection, &nbRects);
699 if (!rects || nbRects != 5 ||
700 !compareRectangles(rects, inRectangles, WINPR_ASSERTING_INT_CAST(
int, nbRects)))
703 if (!compareRectangles(region16_extents(&intersection), &expected_inter_extents, 1))
708 region16_uninit(&intersection);
709 region16_uninit(®ion);
713 static int test_norbert2_case(
void)
721 region16_init(®ion);
723 if (!region16_union_rect(®ion, ®ion, &rect1))
725 (void)fprintf(stderr,
"%s: Error 1 - region16_union_rect failed\n", __func__);
729 if (!(rects = region16_rects(®ion, &nbRects)))
731 (void)fprintf(stderr,
"%s: Error 2 - region16_rects failed\n", __func__);
737 (void)fprintf(stderr,
"%s: Error 3 - expected nbRects == 1 but got %" PRIu32
"\n", __func__,
742 if (!compareRectangles(&rects[0], &rect1, 1))
744 (void)fprintf(stderr,
"%s: Error 4 - compare failed\n", __func__);
748 if (!region16_union_rect(®ion, ®ion, &rect2))
750 (void)fprintf(stderr,
"%s: Error 5 - region16_union_rect failed\n", __func__);
754 if (!(rects = region16_rects(®ion, &nbRects)))
756 (void)fprintf(stderr,
"%s: Error 6 - region16_rects failed\n", __func__);
762 (void)fprintf(stderr,
"%s: Error 7 - expected nbRects == 2 but got %" PRIu32
"\n", __func__,
767 if (!compareRectangles(&rects[0], &rect2, 1))
769 (void)fprintf(stderr,
"%s: Error 8 - compare failed\n", __func__);
773 if (!compareRectangles(&rects[1], &rect1, 1))
775 (void)fprintf(stderr,
"%s: Error 9 - compare failed\n", __func__);
781 region16_uninit(®ion);
785 static int test_empty_rectangle(
void)
790 RECTANGLE_16 emptyRectangles[3] = { { 0, 0, 0, 0 }, { 10, 10, 10, 11 }, { 10, 10, 11, 10 } };
794 region16_init(®ion);
795 region16_init(&intersection);
798 for (
int i = 0; i < 3; i++)
800 if (!rectangle_is_empty(&emptyRectangles[i]))
805 if (rectangle_is_empty(&firstRect))
809 if (!region16_union_rect(®ion, ®ion, &firstRect))
812 if (!region16_intersect_rect(®ion, ®ion, &anotherRect))
815 if (!compareRectangles(region16_extents(®ion), &expected_inter_extents, 1))
818 if (!region16_is_empty(®ion))
821 if (!rectangle_is_empty(region16_extents(&intersection)))
826 region16_uninit(&intersection);
827 region16_uninit(®ion);
831 typedef int (*TestFunction)(void);
838 static struct UnitaryTest tests[] = { {
"Basic trivial tests", test_basic },
839 {
"R1+R3 and R3+R1", test_r1_r3 },
840 {
"R1+R5", test_r1_r5 },
841 {
"R1+R6", test_r1_r6 },
842 {
"R9+R10", test_r9_r10 },
843 {
"R1+R2+R4", test_r1_r2_r4 },
844 {
"R1+R7+R8 in many orders", test_r1_r7_r8 },
845 {
"R1+R2+R3+R4", test_r1_r2_r3_r4 },
846 {
"data from weston", test_from_weston },
847 {
"R1 & R3", test_r1_inter_r3 },
848 {
"(R1+R3)&R11 (band merge)", test_r1_r3_inter_r11 },
849 {
"norbert's case", test_norbert_case },
850 {
"norbert's case 2", test_norbert2_case },
851 {
"empty rectangle case", test_empty_rectangle },
855 int TestFreeRDPRegion(
int argc,
char* argv[])
862 for (
int i = 0; tests[i].func; i++)
865 (void)fprintf(stderr,
"%d: %s\n", testNb, tests[i].name);
866 retCode = tests[i].func();
873 (void)fprintf(stderr,
"failed for test %d\n", testNb);