1 /*
2  * PROJECT:         ReactOS api tests
3  * LICENSE:         GPL - See COPYING in the top level directory
4  * PURPOSE:         Test for ExtCeateRegion
5  * PROGRAMMERS:     Timo Kreuzer
6  */
7 
8 #include "precomp.h"
9 
10 #include <math.h>
11 
12 VOID
13 InitXFORM(
14     PXFORM pxform,
15     FLOAT eM11,
16     FLOAT eM12,
17     FLOAT eM21,
18     FLOAT eM22,
19     FLOAT eDx,
20     FLOAT eDy)
21 {
22     pxform->eM11 = eM11;
23     pxform->eM12 = eM12;
24     pxform->eM21 = eM21;
25     pxform->eM22 = eM22;
26     pxform->eDx = eDx;
27     pxform->eDy = eDy;
28 }
29 
30 #if 0
31 void Test_ExtCreateRegion_Parameters()
32 {
33     hrgn = ExtCreateRegion(NULL, 1, pRgnData);
34     ok(hrgn != NULL, "ExtCreateRegion failed \n");
35 }
36 #endif // 0
37 
38 #define CheckRect(prect, _left, _top, _right, _bottom) \
39 do { \
40     ok(((prect)->left == _left) && ((prect)->top == _top) && \
41        ((prect)->right == _right) && ((prect)->bottom == _bottom), \
42        "Region does not match, expected (%d,%d,%d,%d) got (%ld,%ld,%ld,%ld)\n", \
43        _left, _top, _right, _bottom, \
44        (prect)->left, (prect)->top, (prect)->right, (prect)->bottom); \
45 } while (0)
46 
47 #define CheckRectRegion(hrgn, _left, _top, _right, _bottom) \
48 do { \
49     HRGN hrgnTemp = CreateRectRgn(_left, _top, _right, _bottom); \
50     RECT rcTemp; \
51     ok(GetRgnBox(hrgn, &rcTemp) == SIMPLEREGION, "Region is not SIMPLEREGION\n"); \
52     CheckRect(&rcTemp, _left, _top, _right, _bottom); \
53     ok(EqualRgn(hrgn, hrgnTemp), "Region does not match\n"); \
54     DeleteObject(hrgnTemp); \
55 } while (0)
56 
57 void Test_ExtCreateRegion_Transform()
58 {
59     struct
60     {
61         RGNDATA rgndata;
62         CHAR data[sizeof(RECT) - 1];
63     } RgnDataBuffer;
64     PRECT prect = (PRECT)&RgnDataBuffer.rgndata.Buffer;
65     const RGNDATA *pRgnData = (const RGNDATA *)&RgnDataBuffer;
66     XFORM xform;
67     FLOAT eAngle;
68     HRGN hrgn;
69     RECT rcTemp;
70 
71     RgnDataBuffer.rgndata.rdh.dwSize = sizeof(RGNDATAHEADER);
72     RgnDataBuffer.rgndata.rdh.iType = RDH_RECTANGLES;
73     RgnDataBuffer.rgndata.rdh.nCount = 1;
74     RgnDataBuffer.rgndata.rdh.nRgnSize = sizeof(RGNDATAHEADER) + sizeof(RECT);
75     RgnDataBuffer.rgndata.rdh.rcBound.left = 0;
76     RgnDataBuffer.rgndata.rdh.rcBound.top = 0;
77     RgnDataBuffer.rgndata.rdh.rcBound.right = 10;
78     RgnDataBuffer.rgndata.rdh.rcBound.bottom = 10;
79     prect->left = 0;
80     prect->top = 0;
81     prect->right = 10;
82     prect->bottom = 10;
83 
84     SetRectEmpty(&RgnDataBuffer.rgndata.rdh.rcBound);
85 
86     hrgn = ExtCreateRegion(NULL, sizeof(RgnDataBuffer), pRgnData);
87     ok(hrgn != NULL, "ExtCreateRegion failed with without transform\n");
88     CheckRectRegion(hrgn, 0, 0, 10, 10);
89 
90     InitXFORM(&xform, 1., 0., 0., 1., 0., 0.);
91     hrgn = ExtCreateRegion(&xform, sizeof(RgnDataBuffer), pRgnData);
92     ok(hrgn != NULL, "ExtCreateRegion failed with identity transform\n");
93     CheckRectRegion(hrgn, 0, 0, 10, 10);
94 
95     InitXFORM(&xform, 1., 0., 0., 1., 10., 10.);
96     hrgn = ExtCreateRegion(&xform, sizeof(RgnDataBuffer), pRgnData);
97     ok(hrgn != NULL, "ExtCreateRegion failed with offset transform\n");
98     CheckRectRegion(hrgn, 10, 10, 20, 20);
99 
100     InitXFORM(&xform, 2.5, 0., 0., 1.5, 0., 0.);
101     hrgn = ExtCreateRegion(&xform, sizeof(RgnDataBuffer), pRgnData);
102     ok(hrgn != NULL, "ExtCreateRegion failed with scaling transform\n");
103     CheckRectRegion(hrgn, 0, 0, 25, 15);
104 
105     InitXFORM(&xform, 2.5, 0., 0., 1.5, 20., 40.);
106     hrgn = ExtCreateRegion(&xform, sizeof(RgnDataBuffer), pRgnData);
107     ok(hrgn != NULL, "ExtCreateRegion failed with scaling+offset transform\n");
108     CheckRectRegion(hrgn, 20, 40, 45, 55);
109 
110     InitXFORM(&xform, 1., 10., 0., 1., 0., 0.);
111     hrgn = ExtCreateRegion(&xform, sizeof(RgnDataBuffer), pRgnData);
112     ok(hrgn != NULL, "ExtCreateRegion failed with shearing transform\n");
113     ok(GetRgnBox(hrgn, &rcTemp) == COMPLEXREGION, "not a complex region\n");
114     CheckRect(&rcTemp, 0, 1, 10, 101);
115 
116     eAngle = 23.6f;
117     InitXFORM(&xform, cosf(eAngle), -sinf(eAngle), sinf(eAngle), cosf(eAngle), 10., 10.);
118     hrgn = ExtCreateRegion(&xform, sizeof(RgnDataBuffer), pRgnData);
119     ok(hrgn != NULL, "ExtCreateRegion failed with rotating transform\n");
120     CheckRectRegion(hrgn, 0, 10, 10, 20);
121 
122 }
123 
124 START_TEST(ExtCreateRegion)
125 {
126     Test_ExtCreateRegion_Transform();
127 }
128 
129