2014-01-31 20:02:50 +04:00
|
|
|
/**
|
2014-05-22 23:56:47 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2014-01-31 20:02:50 +04:00
|
|
|
*
|
2014-05-22 23:56:47 +04:00
|
|
|
* Copyright 2014 Thincast Technologies GmbH
|
|
|
|
* Copyright 2014 Hardening <contact@hardening-consulting.com>
|
2014-01-31 20:02:50 +04:00
|
|
|
*
|
2014-05-22 23:56:47 +04:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2014-01-31 20:02:50 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/print.h>
|
|
|
|
|
2014-02-05 18:52:29 +04:00
|
|
|
#include <freerdp/codec/region.h>
|
2014-01-31 20:02:50 +04:00
|
|
|
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static BOOL compareRectangles(const RECTANGLE_16* src1, const RECTANGLE_16* src2, int nb)
|
2014-01-31 20:02:50 +04:00
|
|
|
{
|
|
|
|
int i;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
|
|
|
for (i = 0; i < nb; i++, src1++, src2++)
|
2014-01-31 20:02:50 +04:00
|
|
|
{
|
|
|
|
if (memcmp(src1, src2, sizeof(RECTANGLE_16)))
|
|
|
|
{
|
2017-02-20 20:31:58 +03:00
|
|
|
fprintf(stderr,
|
|
|
|
"expecting rect %d (%"PRIu16",%"PRIu16"-%"PRIu16",%"PRIu16") and have (%"PRIu16",%"PRIu16"-%"PRIu16",%"PRIu16")\n",
|
|
|
|
i, src2->left, src2->top, src2->right, src2->bottom,
|
|
|
|
src1->left, src1->top, src1->right, src1->bottom
|
|
|
|
);
|
2014-01-31 20:02:50 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static int test_basic(void)
|
|
|
|
{
|
2014-01-31 20:02:50 +04:00
|
|
|
REGION16 region;
|
|
|
|
int retCode = -1;
|
2017-02-20 20:31:58 +03:00
|
|
|
const RECTANGLE_16* rects;
|
|
|
|
UINT32 nbRects;
|
2014-01-31 20:02:50 +04:00
|
|
|
/* R1 + R2 ==> disjointed rects */
|
|
|
|
RECTANGLE_16 r1 = { 0, 101, 200, 201};
|
|
|
|
RECTANGLE_16 r2 = {150, 301, 250, 401};
|
2017-02-20 20:31:58 +03:00
|
|
|
RECTANGLE_16 r1_r2[] =
|
|
|
|
{
|
2014-01-31 20:02:50 +04:00
|
|
|
{0, 101, 200, 201},
|
|
|
|
{150, 301, 250, 401}
|
|
|
|
};
|
|
|
|
/* r1 */
|
|
|
|
region16_init(®ion);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!region16_union_rect(®ion, ®ion, &r1))
|
2017-02-20 20:31:58 +03:00
|
|
|
goto out;
|
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
rects = region16_rects(®ion, &nbRects);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!rects || nbRects != 1 || memcmp(rects, &r1, sizeof(RECTANGLE_16)))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* r1 + r2 */
|
|
|
|
if (!region16_union_rect(®ion, ®ion, &r2))
|
2017-02-20 20:31:58 +03:00
|
|
|
goto out;
|
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
rects = region16_rects(®ion, &nbRects);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!rects || nbRects != 2 || !compareRectangles(rects, r1_r2, nbRects))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* clear region */
|
|
|
|
region16_clear(®ion);
|
|
|
|
region16_rects(®ion, &nbRects);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (nbRects)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
retCode = 0;
|
|
|
|
out:
|
|
|
|
region16_uninit(®ion);
|
|
|
|
return retCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static int test_r1_r3(void)
|
|
|
|
{
|
2014-01-31 20:02:50 +04:00
|
|
|
REGION16 region;
|
|
|
|
int retCode = -1;
|
2017-02-20 20:31:58 +03:00
|
|
|
const RECTANGLE_16* rects;
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32 nbRects;
|
2014-01-31 20:02:50 +04:00
|
|
|
RECTANGLE_16 r1 = { 0, 101, 200, 201};
|
|
|
|
RECTANGLE_16 r3 = {150, 151, 250, 251};
|
2017-02-20 20:31:58 +03:00
|
|
|
RECTANGLE_16 r1_r3[] =
|
|
|
|
{
|
2014-01-31 20:02:50 +04:00
|
|
|
{ 0, 101, 200, 151},
|
|
|
|
{ 0, 151, 250, 201},
|
|
|
|
{150, 201, 250, 251}
|
|
|
|
};
|
|
|
|
region16_init(®ion);
|
|
|
|
/*
|
|
|
|
* +===============================================================
|
|
|
|
* |
|
|
|
|
* |+-----+ +-----+
|
|
|
|
* || r1 | | |
|
|
|
|
* || +-+------+ +-----+--------+
|
|
|
|
* || | r3 | | |
|
|
|
|
* |+---+ | ====> +-----+--------+
|
|
|
|
* | | | | |
|
|
|
|
* | +--------+ +--------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* R1 + R3 */
|
|
|
|
if (!region16_union_rect(®ion, ®ion, &r1))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!region16_union_rect(®ion, ®ion, &r3))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
rects = region16_rects(®ion, &nbRects);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!rects || nbRects != 3 || !compareRectangles(rects, r1_r3, nbRects))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* R3 + R1 */
|
|
|
|
region16_clear(®ion);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!region16_union_rect(®ion, ®ion, &r3))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!region16_union_rect(®ion, ®ion, &r1))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
rects = region16_rects(®ion, &nbRects);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!rects || nbRects != 3 || !compareRectangles(rects, r1_r3, nbRects))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
retCode = 0;
|
|
|
|
out:
|
|
|
|
region16_uninit(®ion);
|
|
|
|
return retCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static int test_r9_r10(void)
|
|
|
|
{
|
2014-01-31 20:02:50 +04:00
|
|
|
REGION16 region;
|
|
|
|
int retCode = -1;
|
2017-02-20 20:31:58 +03:00
|
|
|
const RECTANGLE_16* rects;
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32 nbRects;
|
2014-01-31 20:02:50 +04:00
|
|
|
/*
|
|
|
|
* +===============================================================
|
|
|
|
* |
|
|
|
|
* | +---+ +---+
|
|
|
|
* |+--|r10|-+ +--+---+-+
|
|
|
|
* ||r9| | | | |
|
|
|
|
* || | | | | |
|
|
|
|
* || | | | =====> | |
|
|
|
|
* || | | | | |
|
|
|
|
* || | | | | |
|
2016-04-05 18:07:45 +03:00
|
|
|
* |+--| |-+ +--+---+-+
|
|
|
|
* | +---+ +---+
|
2014-01-31 20:02:50 +04:00
|
|
|
*/
|
|
|
|
RECTANGLE_16 r9 = { 0, 100, 400, 200};
|
|
|
|
RECTANGLE_16 r10 = {200, 0, 300, 300};
|
2017-02-20 20:31:58 +03:00
|
|
|
RECTANGLE_16 r9_r10[] =
|
|
|
|
{
|
|
|
|
{200, 0, 300, 100},
|
|
|
|
{ 0, 100, 400, 200},
|
|
|
|
{200, 200, 300, 300},
|
2014-01-31 20:02:50 +04:00
|
|
|
};
|
|
|
|
region16_init(®ion);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!region16_union_rect(®ion, ®ion, &r9))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!region16_union_rect(®ion, ®ion, &r10))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
rects = region16_rects(®ion, &nbRects);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!rects || nbRects != 3 || !compareRectangles(rects, r9_r10, nbRects))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
retCode = 0;
|
|
|
|
out:
|
|
|
|
region16_uninit(®ion);
|
|
|
|
return retCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static int test_r1_r5(void)
|
|
|
|
{
|
2014-01-31 20:02:50 +04:00
|
|
|
REGION16 region;
|
|
|
|
int retCode = -1;
|
2017-02-20 20:31:58 +03:00
|
|
|
const RECTANGLE_16* rects;
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32 nbRects;
|
2014-01-31 20:02:50 +04:00
|
|
|
RECTANGLE_16 r1 = { 0, 101, 200, 201};
|
|
|
|
RECTANGLE_16 r5 = {150, 121, 300, 131};
|
2017-02-20 20:31:58 +03:00
|
|
|
RECTANGLE_16 r1_r5[] =
|
|
|
|
{
|
2014-01-31 20:02:50 +04:00
|
|
|
{ 0, 101, 200, 121},
|
|
|
|
{ 0, 121, 300, 131},
|
|
|
|
{ 0, 131, 200, 201}
|
|
|
|
};
|
|
|
|
region16_init(®ion);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
/*
|
|
|
|
* +===============================================================
|
|
|
|
* |
|
|
|
|
* |+--------+ +--------+
|
|
|
|
* || r1 | | |
|
|
|
|
* || +--+----+ +--------+----+
|
|
|
|
* || | r5 | =====> | |
|
|
|
|
* || +-------+ +--------+----+
|
|
|
|
* || | | |
|
2016-04-05 18:07:45 +03:00
|
|
|
* |+--------+ +--------+
|
|
|
|
* |
|
|
|
|
*
|
2014-01-31 20:02:50 +04:00
|
|
|
*/
|
|
|
|
if (!region16_union_rect(®ion, ®ion, &r1))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!region16_union_rect(®ion, ®ion, &r5))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
rects = region16_rects(®ion, &nbRects);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!rects || nbRects != 3 || !compareRectangles(rects, r1_r5, nbRects))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
retCode = 0;
|
|
|
|
out:
|
|
|
|
region16_uninit(®ion);
|
|
|
|
return retCode;
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static int test_r1_r6(void)
|
|
|
|
{
|
2014-01-31 20:02:50 +04:00
|
|
|
REGION16 region;
|
|
|
|
int retCode = -1;
|
2017-02-20 20:31:58 +03:00
|
|
|
const RECTANGLE_16* rects;
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32 nbRects;
|
2014-01-31 20:02:50 +04:00
|
|
|
RECTANGLE_16 r1 = { 0, 101, 200, 201};
|
|
|
|
RECTANGLE_16 r6 = {150, 121, 170, 131};
|
|
|
|
region16_init(®ion);
|
|
|
|
/*
|
|
|
|
* +===============================================================
|
|
|
|
* |
|
|
|
|
* |+--------+ +--------+
|
|
|
|
* || r1 | | |
|
|
|
|
* || +--+ | | |
|
|
|
|
* || |r6| | =====> | |
|
|
|
|
* || +--+ | | |
|
|
|
|
* || | | |
|
2016-04-05 18:07:45 +03:00
|
|
|
* |+--------+ +--------+
|
|
|
|
* |
|
2014-01-31 20:02:50 +04:00
|
|
|
*/
|
|
|
|
region16_clear(®ion);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!region16_union_rect(®ion, ®ion, &r1))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!region16_union_rect(®ion, ®ion, &r6))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
rects = region16_rects(®ion, &nbRects);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!rects || nbRects != 1 || !compareRectangles(rects, &r1, nbRects))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
retCode = 0;
|
|
|
|
out:
|
|
|
|
region16_uninit(®ion);
|
|
|
|
return retCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static int test_r1_r2_r4(void)
|
|
|
|
{
|
2014-01-31 20:02:50 +04:00
|
|
|
REGION16 region;
|
|
|
|
int retCode = -1;
|
2017-02-20 20:31:58 +03:00
|
|
|
const RECTANGLE_16* rects;
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32 nbRects;
|
2014-01-31 20:02:50 +04:00
|
|
|
RECTANGLE_16 r1 = { 0, 101, 200, 201};
|
|
|
|
RECTANGLE_16 r2 = {150, 301, 250, 401};
|
|
|
|
RECTANGLE_16 r4 = {150, 251, 250, 301};
|
2017-02-20 20:31:58 +03:00
|
|
|
RECTANGLE_16 r1_r2_r4[] =
|
|
|
|
{
|
2014-01-31 20:02:50 +04:00
|
|
|
{ 0, 101, 200, 201},
|
|
|
|
{150, 251, 250, 401}
|
|
|
|
};
|
|
|
|
/*
|
|
|
|
* +===============================================================
|
|
|
|
* |
|
|
|
|
* |+-----+ +-----+
|
|
|
|
* || r1 | | |
|
|
|
|
* || | | |
|
|
|
|
* || | | |
|
|
|
|
* |+-----+ ====> +-----+
|
|
|
|
* |
|
|
|
|
* | +--------+ +--------+
|
|
|
|
* | | r4 | | |
|
|
|
|
* | +--------+ | |
|
|
|
|
* | | r2 | | |
|
|
|
|
* | | | | |
|
|
|
|
* | +--------+ +--------+
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
region16_init(®ion);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!region16_union_rect(®ion, ®ion, &r1))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!region16_union_rect(®ion, ®ion, &r2))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!region16_union_rect(®ion, ®ion, &r4))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
rects = region16_rects(®ion, &nbRects);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!rects || nbRects != 2 || !compareRectangles(rects, r1_r2_r4, nbRects))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
retCode = 0;
|
|
|
|
out:
|
|
|
|
region16_uninit(®ion);
|
|
|
|
return retCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static int test_r1_r7_r8(void)
|
|
|
|
{
|
2014-01-31 20:02:50 +04:00
|
|
|
REGION16 region;
|
|
|
|
int retCode = -1;
|
2017-02-20 20:31:58 +03:00
|
|
|
const RECTANGLE_16* rects;
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32 nbRects;
|
2014-01-31 20:02:50 +04:00
|
|
|
RECTANGLE_16 r1 = { 0, 101, 200, 201};
|
|
|
|
RECTANGLE_16 r7 = {300, 101, 500, 201};
|
|
|
|
RECTANGLE_16 r8 = {150, 121, 400, 131};
|
2017-02-20 20:31:58 +03:00
|
|
|
RECTANGLE_16 r1_r7_r8[] =
|
|
|
|
{
|
2014-01-31 20:02:50 +04:00
|
|
|
{ 0, 101, 200, 121},
|
|
|
|
{300, 101, 500, 121},
|
|
|
|
{ 0, 121, 500, 131},
|
|
|
|
{ 0, 131, 200, 201},
|
|
|
|
{300, 131, 500, 201},
|
|
|
|
};
|
|
|
|
/*
|
|
|
|
* +===============================================================
|
|
|
|
* |
|
|
|
|
* |+--------+ +--------+ +--------+ +--------+
|
|
|
|
* || r1 | | r7 | | | | |
|
|
|
|
* || +------------+ | +--------+---+--------+
|
|
|
|
* || | r8 | | =====> | |
|
|
|
|
* || +------------+ | +--------+---+--------+
|
|
|
|
* || | | | | | | |
|
2016-04-05 18:07:45 +03:00
|
|
|
* |+--------+ +--------+ +--------+ +--------+
|
|
|
|
* |
|
2014-01-31 20:02:50 +04:00
|
|
|
*/
|
|
|
|
region16_init(®ion);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!region16_union_rect(®ion, ®ion, &r1))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!region16_union_rect(®ion, ®ion, &r7))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!region16_union_rect(®ion, ®ion, &r8))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
rects = region16_rects(®ion, &nbRects);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!rects || nbRects != 5 || !compareRectangles(rects, r1_r7_r8, nbRects))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
region16_clear(®ion);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!region16_union_rect(®ion, ®ion, &r1))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!region16_union_rect(®ion, ®ion, &r8))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!region16_union_rect(®ion, ®ion, &r7))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
rects = region16_rects(®ion, &nbRects);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!rects || nbRects != 5 || !compareRectangles(rects, r1_r7_r8, nbRects))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
region16_clear(®ion);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!region16_union_rect(®ion, ®ion, &r8))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!region16_union_rect(®ion, ®ion, &r7))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!region16_union_rect(®ion, ®ion, &r1))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
rects = region16_rects(®ion, &nbRects);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!rects || nbRects != 5 || !compareRectangles(rects, r1_r7_r8, nbRects))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
retCode = 0;
|
|
|
|
out:
|
|
|
|
region16_uninit(®ion);
|
|
|
|
return retCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static int test_r1_r2_r3_r4(void)
|
|
|
|
{
|
2014-01-31 20:02:50 +04:00
|
|
|
REGION16 region;
|
|
|
|
int retCode = -1;
|
2017-02-20 20:31:58 +03:00
|
|
|
const RECTANGLE_16* rects;
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32 nbRects;
|
2014-01-31 20:02:50 +04:00
|
|
|
RECTANGLE_16 r1 = { 0, 101, 200, 201};
|
|
|
|
RECTANGLE_16 r2 = {150, 301, 250, 401};
|
|
|
|
RECTANGLE_16 r3 = {150, 151, 250, 251};
|
|
|
|
RECTANGLE_16 r4 = {150, 251, 250, 301};
|
2017-02-20 20:31:58 +03:00
|
|
|
RECTANGLE_16 r1_r2_r3[] =
|
|
|
|
{
|
2014-01-31 20:02:50 +04:00
|
|
|
{ 0, 101, 200, 151},
|
|
|
|
{ 0, 151, 250, 201},
|
|
|
|
{150, 201, 250, 251},
|
|
|
|
{150, 301, 250, 401}
|
|
|
|
};
|
2017-02-20 20:31:58 +03:00
|
|
|
RECTANGLE_16 r1_r2_r3_r4[] =
|
|
|
|
{
|
2014-01-31 20:02:50 +04:00
|
|
|
{ 0, 101, 200, 151},
|
|
|
|
{ 0, 151, 250, 201},
|
|
|
|
{150, 201, 250, 401}
|
|
|
|
};
|
|
|
|
region16_init(®ion);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
/*
|
|
|
|
* +===============================================================
|
|
|
|
* |
|
|
|
|
* |+-----+ +-----+
|
|
|
|
* || r1 | | |
|
|
|
|
* || +-+------+ +-----+--------+
|
|
|
|
* || | r3 | | |
|
|
|
|
* |+---+ | ====> +-----+--------+
|
|
|
|
* | | | | |
|
|
|
|
* | +--------+ +--------+
|
|
|
|
* | +--------+ +--------+
|
|
|
|
* | | r2 | | |
|
|
|
|
* | | | | |
|
|
|
|
* | +--------+ +--------+
|
|
|
|
*/
|
|
|
|
if (!region16_union_rect(®ion, ®ion, &r1))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!region16_union_rect(®ion, ®ion, &r2))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!region16_union_rect(®ion, ®ion, &r3))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
rects = region16_rects(®ion, &nbRects);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!rects || nbRects != 4 || !compareRectangles(rects, r1_r2_r3, 4))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* +===============================================================
|
|
|
|
* |
|
|
|
|
* |+-----+ +-----+
|
|
|
|
* || | | |
|
2016-04-05 18:07:45 +03:00
|
|
|
* |+-----+--------+ +-----+--------+
|
2014-01-31 20:02:50 +04:00
|
|
|
* || | ==> | |
|
|
|
|
* |+-----+--------+ +-----+--------+
|
|
|
|
* | | | | |
|
|
|
|
* | +--------+ | |
|
|
|
|
* | | + r4 | | |
|
|
|
|
* | +--------+ | |
|
|
|
|
* | | | | |
|
|
|
|
* | | | | |
|
|
|
|
* | +--------+ +--------+
|
|
|
|
*/
|
|
|
|
if (!region16_union_rect(®ion, ®ion, &r4))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
rects = region16_rects(®ion, &nbRects);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!rects || nbRects != 3 || !compareRectangles(rects, r1_r2_r3_r4, 3))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
retCode = 0;
|
|
|
|
out:
|
|
|
|
region16_uninit(®ion);
|
|
|
|
return retCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static int test_from_weston(void)
|
2014-01-31 20:02:50 +04:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* 0: 0,0 -> 640,32 (w=640 h=32)
|
|
|
|
* 1: 236,169 -> 268,201 (w=32 h=32)
|
|
|
|
* 2: 246,258 -> 278,290 (w=32 h=32)
|
|
|
|
*/
|
|
|
|
REGION16 region;
|
|
|
|
int retCode = -1;
|
2017-02-20 20:31:58 +03:00
|
|
|
const RECTANGLE_16* rects;
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32 nbRects;
|
2014-01-31 20:02:50 +04:00
|
|
|
RECTANGLE_16 r1 = { 0, 0, 640, 32};
|
|
|
|
RECTANGLE_16 r2 = {236, 169, 268, 201};
|
|
|
|
RECTANGLE_16 r3 = {246, 258, 278, 290};
|
2017-02-20 20:31:58 +03:00
|
|
|
RECTANGLE_16 r1_r2_r3[] =
|
|
|
|
{
|
|
|
|
{ 0, 0, 640, 32},
|
|
|
|
{236, 169, 268, 201},
|
|
|
|
{246, 258, 278, 290}
|
2014-01-31 20:02:50 +04:00
|
|
|
};
|
|
|
|
region16_init(®ion);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
/*
|
|
|
|
* +===============================================================
|
|
|
|
* |+-------------------------------------------------------------+
|
|
|
|
* || r1 |
|
|
|
|
* |+-------------------------------------------------------------+
|
|
|
|
* |
|
|
|
|
* | +---------------+
|
|
|
|
* | | r2 |
|
|
|
|
* | +---------------+
|
|
|
|
* |
|
|
|
|
* | +---------------+
|
|
|
|
* | | r3 |
|
|
|
|
* | +---------------+
|
|
|
|
* |
|
|
|
|
*/
|
|
|
|
if (!region16_union_rect(®ion, ®ion, &r1))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!region16_union_rect(®ion, ®ion, &r2))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!region16_union_rect(®ion, ®ion, &r3))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
rects = region16_rects(®ion, &nbRects);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!rects || nbRects != 3 || !compareRectangles(rects, r1_r2_r3, 3))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
retCode = 0;
|
|
|
|
out:
|
|
|
|
region16_uninit(®ion);
|
|
|
|
return retCode;
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static int test_r1_inter_r3(void)
|
|
|
|
{
|
2014-01-31 20:02:50 +04:00
|
|
|
REGION16 region, intersection;
|
|
|
|
int retCode = -1;
|
2017-02-20 20:31:58 +03:00
|
|
|
const RECTANGLE_16* rects;
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32 nbRects;
|
2014-01-31 20:02:50 +04:00
|
|
|
RECTANGLE_16 r1 = { 0, 101, 200, 201};
|
|
|
|
RECTANGLE_16 r3 = {150, 151, 250, 251};
|
2017-02-20 20:31:58 +03:00
|
|
|
RECTANGLE_16 r1_inter_r3[] =
|
|
|
|
{
|
2014-01-31 20:02:50 +04:00
|
|
|
{150, 151, 200, 201},
|
|
|
|
};
|
|
|
|
region16_init(®ion);
|
|
|
|
region16_init(&intersection);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* +===============================================================
|
|
|
|
* |
|
|
|
|
* |+-----+
|
|
|
|
* || r1 |
|
|
|
|
* || +-+------+ +-+
|
|
|
|
* || | r3 | r1&r3 | |
|
|
|
|
* |+---+ | ====> +-+
|
|
|
|
* | | |
|
|
|
|
* | +--------+
|
|
|
|
*/
|
|
|
|
if (!region16_union_rect(®ion, ®ion, &r1))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!region16_intersects_rect(®ion, &r3))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (!region16_intersect_rect(&intersection, ®ion, &r3))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
rects = region16_rects(&intersection, &nbRects);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!rects || nbRects != 1 || !compareRectangles(rects, r1_inter_r3, nbRects))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
retCode = 0;
|
|
|
|
out:
|
|
|
|
region16_uninit(®ion);
|
2017-11-15 11:11:12 +03:00
|
|
|
region16_uninit(&intersection);
|
2014-01-31 20:02:50 +04:00
|
|
|
return retCode;
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static int test_r1_r3_inter_r11(void)
|
|
|
|
{
|
2014-01-31 20:02:50 +04:00
|
|
|
REGION16 region, intersection;
|
|
|
|
int retCode = -1;
|
2017-02-20 20:31:58 +03:00
|
|
|
const RECTANGLE_16* rects;
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32 nbRects;
|
2014-01-31 20:02:50 +04:00
|
|
|
RECTANGLE_16 r1 = { 0, 101, 200, 201};
|
|
|
|
RECTANGLE_16 r3 = {150, 151, 250, 251};
|
2017-02-20 20:31:58 +03:00
|
|
|
RECTANGLE_16 r11 = {170, 151, 600, 301};
|
|
|
|
RECTANGLE_16 r1_r3_inter_r11[] =
|
|
|
|
{
|
2014-01-31 20:02:50 +04:00
|
|
|
{170, 151, 250, 251},
|
|
|
|
};
|
|
|
|
region16_init(®ion);
|
|
|
|
region16_init(&intersection);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* +===============================================================
|
|
|
|
* |
|
|
|
|
* |+-----+
|
|
|
|
* || |
|
|
|
|
* || +------+
|
|
|
|
* || r1+r3 | (r1+r3) & r11
|
|
|
|
* || +----------------+ +--------+
|
|
|
|
* |+---+ | | | ====> | |
|
|
|
|
* | | | | | | |
|
|
|
|
* | | | | | | |
|
|
|
|
* | +-|------+ | +--------+
|
|
|
|
* | | r11 |
|
|
|
|
* | +----------------+
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* R1+R3 is made of 3 bands, R11 overlap the second and the third band. The
|
|
|
|
* intersection is made of two band that must be reassembled to give only
|
|
|
|
* one
|
|
|
|
*/
|
|
|
|
if (!region16_union_rect(®ion, ®ion, &r1))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!region16_union_rect(®ion, ®ion, &r3))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (!region16_intersects_rect(®ion, &r11))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (!region16_intersect_rect(&intersection, ®ion, &r11))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
rects = region16_rects(&intersection, &nbRects);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (!rects || nbRects != 1 || !compareRectangles(rects, r1_r3_inter_r11, nbRects))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
retCode = 0;
|
|
|
|
out:
|
|
|
|
region16_uninit(&intersection);
|
|
|
|
region16_uninit(®ion);
|
|
|
|
return retCode;
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static int test_norbert_case(void)
|
|
|
|
{
|
2014-02-07 19:43:48 +04:00
|
|
|
REGION16 region, intersection;
|
|
|
|
int retCode = -1;
|
2017-02-20 20:31:58 +03:00
|
|
|
const RECTANGLE_16* rects;
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32 nbRects, i;
|
2017-02-20 20:31:58 +03:00
|
|
|
RECTANGLE_16 inRectangles[5] =
|
|
|
|
{
|
|
|
|
{1680, 0, 1920, 242},
|
|
|
|
{ 294, 242, 971, 776},
|
|
|
|
{1680, 242, 1920, 776},
|
|
|
|
{1680, 776, 1920, 1036},
|
|
|
|
{ 2, 1040, 53, 1078}
|
2014-02-07 19:43:48 +04:00
|
|
|
};
|
2017-02-20 20:31:58 +03:00
|
|
|
RECTANGLE_16 screenRect =
|
|
|
|
{
|
2014-02-07 19:43:48 +04:00
|
|
|
0, 0, 1920, 1080
|
|
|
|
};
|
2017-02-20 20:31:58 +03:00
|
|
|
RECTANGLE_16 expected_inter_extents =
|
|
|
|
{
|
2015-03-20 15:55:06 +03:00
|
|
|
2, 0, 1920, 1078
|
2014-02-07 19:43:48 +04:00
|
|
|
};
|
|
|
|
region16_init(®ion);
|
|
|
|
region16_init(&intersection);
|
|
|
|
|
2015-03-20 20:07:54 +03:00
|
|
|
/*
|
|
|
|
* Consider following as a screen with resolution 1920*1080
|
|
|
|
* | | | | | | |
|
|
|
|
* | |2 |53 |294 |971 |1680 |
|
|
|
|
* | | | | | | |
|
|
|
|
* 0 +=+======================================+======+
|
|
|
|
* | | | |
|
|
|
|
* | | R[0]|
|
|
|
|
* 242 | +-----------+ +------+
|
|
|
|
* | | | | | |
|
|
|
|
* | | | | |
|
|
|
|
* | | R[1]| | R[2]|
|
|
|
|
* 776 | | +-----------+ +------+
|
|
|
|
* | | |
|
|
|
|
* | | R[3]|
|
|
|
|
* 1036 | | +------+
|
2016-04-05 18:07:45 +03:00
|
|
|
* 1040 | +----+
|
2015-03-20 20:07:54 +03:00
|
|
|
* | |R[4]| Union of R[0-4]|
|
|
|
|
* 1078 | +----+ - - - - - - - -+
|
2016-04-05 18:07:45 +03:00
|
|
|
* 1080 |
|
|
|
|
*
|
|
|
|
*
|
2015-03-20 20:07:54 +03:00
|
|
|
* The result is union of R[0] - R[4].
|
2016-04-05 18:07:45 +03:00
|
|
|
* After intersected with the full screen rect, the
|
2015-03-20 20:07:54 +03:00
|
|
|
* result should keep the same.
|
|
|
|
*/
|
2014-02-07 19:43:48 +04:00
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
{
|
|
|
|
if (!region16_union_rect(®ion, ®ion, &inRectangles[i]))
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
if (!compareRectangles(region16_extents(®ion), &expected_inter_extents, 1))
|
2015-03-20 15:55:06 +03:00
|
|
|
goto out;
|
|
|
|
|
2014-02-07 19:43:48 +04:00
|
|
|
if (!region16_intersect_rect(&intersection, ®ion, &screenRect))
|
|
|
|
goto out;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-02-07 19:43:48 +04:00
|
|
|
rects = region16_rects(&intersection, &nbRects);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-02-07 19:43:48 +04:00
|
|
|
if (!rects || nbRects != 5 || !compareRectangles(rects, inRectangles, nbRects))
|
|
|
|
goto out;
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
if (!compareRectangles(region16_extents(&intersection), &expected_inter_extents, 1))
|
2014-02-07 19:43:48 +04:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
retCode = 0;
|
|
|
|
out:
|
|
|
|
region16_uninit(&intersection);
|
|
|
|
region16_uninit(®ion);
|
|
|
|
return retCode;
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static int test_norbert2_case(void)
|
|
|
|
{
|
2015-09-30 22:14:43 +03:00
|
|
|
REGION16 region;
|
|
|
|
int retCode = -1;
|
2017-02-20 20:31:58 +03:00
|
|
|
const RECTANGLE_16* rects;
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32 nbRects = 0;
|
2015-09-30 22:14:43 +03:00
|
|
|
RECTANGLE_16 rect1 = { 464, 696, 476, 709 };
|
|
|
|
RECTANGLE_16 rect2 = { 0, 0, 1024, 32 };
|
|
|
|
region16_init(®ion);
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
if (!region16_union_rect(®ion, ®ion, &rect1))
|
|
|
|
{
|
2015-09-30 22:14:43 +03:00
|
|
|
fprintf(stderr, "%s: Error 1 - region16_union_rect failed\n", __FUNCTION__);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
if (!(rects = region16_rects(®ion, &nbRects)))
|
|
|
|
{
|
2015-09-30 22:14:43 +03:00
|
|
|
fprintf(stderr, "%s: Error 2 - region16_rects failed\n", __FUNCTION__);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
if (nbRects != 1)
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
fprintf(stderr, "%s: Error 3 - expected nbRects == 1 but got %"PRIu32"\n", __FUNCTION__, nbRects);
|
2015-09-30 22:14:43 +03:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
if (!compareRectangles(&rects[0], &rect1, 1))
|
|
|
|
{
|
2015-09-30 22:14:43 +03:00
|
|
|
fprintf(stderr, "%s: Error 4 - compare failed\n", __FUNCTION__);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
if (!region16_union_rect(®ion, ®ion, &rect2))
|
|
|
|
{
|
2015-09-30 22:14:43 +03:00
|
|
|
fprintf(stderr, "%s: Error 5 - region16_union_rect failed\n", __FUNCTION__);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
if (!(rects = region16_rects(®ion, &nbRects)))
|
|
|
|
{
|
2015-09-30 22:14:43 +03:00
|
|
|
fprintf(stderr, "%s: Error 6 - region16_rects failed\n", __FUNCTION__);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
if (nbRects != 2)
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
fprintf(stderr, "%s: Error 7 - expected nbRects == 2 but got %"PRIu32"\n", __FUNCTION__, nbRects);
|
2015-09-30 22:14:43 +03:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
if (!compareRectangles(&rects[0], &rect2, 1))
|
|
|
|
{
|
2015-09-30 22:14:43 +03:00
|
|
|
fprintf(stderr, "%s: Error 8 - compare failed\n", __FUNCTION__);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
if (!compareRectangles(&rects[1], &rect1, 1))
|
|
|
|
{
|
2015-09-30 22:14:43 +03:00
|
|
|
fprintf(stderr, "%s: Error 9 - compare failed\n", __FUNCTION__);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
retCode = 0;
|
|
|
|
out:
|
|
|
|
region16_uninit(®ion);
|
|
|
|
return retCode;
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static int test_empty_rectangle(void)
|
|
|
|
{
|
2015-03-20 15:55:06 +03:00
|
|
|
REGION16 region, intersection;
|
|
|
|
int retCode = -1;
|
|
|
|
int i;
|
2017-02-20 20:31:58 +03:00
|
|
|
RECTANGLE_16 emptyRectangles[3] =
|
|
|
|
{
|
2015-03-20 18:40:48 +03:00
|
|
|
{ 0, 0, 0, 0},
|
|
|
|
{ 10, 10, 10, 11},
|
2015-03-20 19:04:30 +03:00
|
|
|
{ 10, 10, 11, 10}
|
2015-03-20 15:55:06 +03:00
|
|
|
};
|
2017-02-20 20:31:58 +03:00
|
|
|
RECTANGLE_16 firstRect =
|
|
|
|
{
|
2015-03-20 18:40:48 +03:00
|
|
|
0, 0, 100, 100
|
2015-03-20 15:55:06 +03:00
|
|
|
};
|
2017-02-20 20:31:58 +03:00
|
|
|
RECTANGLE_16 anotherRect =
|
|
|
|
{
|
2015-03-20 18:40:48 +03:00
|
|
|
100, 100, 200, 200
|
2015-03-20 15:55:06 +03:00
|
|
|
};
|
2017-02-20 20:31:58 +03:00
|
|
|
RECTANGLE_16 expected_inter_extents =
|
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
0, 0, 0, 0
|
2015-03-20 15:55:06 +03:00
|
|
|
};
|
|
|
|
region16_init(®ion);
|
|
|
|
region16_init(&intersection);
|
|
|
|
|
2015-03-20 18:40:48 +03:00
|
|
|
/* Check for empty rectangles */
|
2015-03-20 19:04:30 +03:00
|
|
|
for (i = 0; i < 3; i++)
|
2015-03-20 15:55:06 +03:00
|
|
|
{
|
2015-03-20 18:40:48 +03:00
|
|
|
if (!rectangle_is_empty(&emptyRectangles[i]))
|
|
|
|
goto out;
|
2015-03-20 15:55:06 +03:00
|
|
|
}
|
|
|
|
|
2015-03-20 18:40:48 +03:00
|
|
|
/* Check for non-empty rectangles */
|
|
|
|
if (rectangle_is_empty(&firstRect))
|
|
|
|
goto out;
|
2015-03-20 15:55:06 +03:00
|
|
|
|
2015-03-20 18:40:48 +03:00
|
|
|
/* Intersect 2 non-intersect rectangle, result should be empty */
|
|
|
|
if (!region16_union_rect(®ion, ®ion, &firstRect))
|
|
|
|
goto out;
|
2015-03-20 15:55:06 +03:00
|
|
|
|
2015-03-20 18:40:48 +03:00
|
|
|
if (!region16_intersect_rect(®ion, ®ion, &anotherRect))
|
|
|
|
goto out;
|
2015-03-20 15:55:06 +03:00
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
if (!compareRectangles(region16_extents(®ion), &expected_inter_extents, 1))
|
2015-03-20 15:55:06 +03:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (!region16_is_empty(®ion))
|
|
|
|
goto out;
|
|
|
|
|
2015-03-20 18:40:48 +03:00
|
|
|
if (!rectangle_is_empty(region16_extents(&intersection)))
|
|
|
|
goto out;
|
2015-03-20 15:55:06 +03:00
|
|
|
|
|
|
|
retCode = 0;
|
|
|
|
out:
|
|
|
|
region16_uninit(&intersection);
|
|
|
|
region16_uninit(®ion);
|
|
|
|
return retCode;
|
|
|
|
}
|
2014-01-31 20:02:50 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
typedef int (*TestFunction)(void);
|
2017-02-20 20:31:58 +03:00
|
|
|
struct UnitaryTest
|
|
|
|
{
|
|
|
|
const char* name;
|
2014-01-31 20:02:50 +04:00
|
|
|
TestFunction func;
|
|
|
|
};
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static struct UnitaryTest tests[] =
|
|
|
|
{
|
2014-01-31 20:02:50 +04:00
|
|
|
{"Basic trivial tests", test_basic},
|
|
|
|
{"R1+R3 and R3+R1", test_r1_r3},
|
|
|
|
{"R1+R5", test_r1_r5},
|
|
|
|
{"R1+R6", test_r1_r6},
|
|
|
|
{"R9+R10", test_r9_r10},
|
|
|
|
{"R1+R2+R4", test_r1_r2_r4},
|
|
|
|
{"R1+R7+R8 in many orders", test_r1_r7_r8},
|
|
|
|
{"R1+R2+R3+R4", test_r1_r2_r3_r4},
|
|
|
|
{"data from weston", test_from_weston},
|
|
|
|
{"R1 & R3", test_r1_inter_r3},
|
2017-02-20 20:31:58 +03:00
|
|
|
{"(R1+R3)&R11 (band merge)", test_r1_r3_inter_r11},
|
2015-09-30 22:14:43 +03:00
|
|
|
{"norbert's case", test_norbert_case},
|
|
|
|
{"norbert's case 2", test_norbert2_case},
|
2015-03-20 18:40:48 +03:00
|
|
|
{"empty rectangle case", test_empty_rectangle},
|
2014-01-31 20:02:50 +04:00
|
|
|
|
|
|
|
{NULL, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
int TestFreeRDPRegion(int argc, char* argv[])
|
|
|
|
{
|
2014-03-29 20:37:16 +04:00
|
|
|
int i, testNb = 0;
|
2014-01-31 20:02:50 +04:00
|
|
|
int retCode = -1;
|
|
|
|
|
|
|
|
for (i = 0; tests[i].func; i++)
|
|
|
|
{
|
|
|
|
testNb++;
|
|
|
|
fprintf(stderr, "%d: %s\n", testNb, tests[i].name);
|
|
|
|
retCode = tests[i].func();
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-01-31 20:02:50 +04:00
|
|
|
if (retCode < 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (retCode < 0)
|
|
|
|
fprintf(stderr, "failed for test %d\n", testNb);
|
|
|
|
|
|
|
|
return retCode;
|
|
|
|
}
|