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