1 /*
2  * PROJECT:         ReactOS api tests
3  * LICENSE:         GPL - See COPYING in the top level directory
4  * PURPOSE:         Test for ExcludeClipRect
5  * PROGRAMMERS:     Timo Kreuzer
6  */
7 
8 #include "precomp.h"
9 
10 void Test_ExcludeClipRect()
11 {
12     HDC hdc;
13     HRGN hrgn, hrgn2;
14 
15     hdc = CreateCompatibleDC(NULL);
16     ok(hdc != 0, "CreateCompatibleDC failed, skipping tests.\n");
17     if (!hdc) return;
18 
19     hrgn2 = CreateRectRgn(0, 0, 0, 0);
20 
21     /* Test NULL DC */
22     SetLastError(0x12345);
23     ok_int(ExcludeClipRect(NULL, 0, 0, 0, 0), ERROR);
24     ok_int(GetLastError(), ERROR_INVALID_HANDLE);
25 
26     /* Test invalid DC */
27     SetLastError(0x12345);
28     ok_int(ExcludeClipRect((HDC)(ULONG_PTR)0x12345, 0, 0, 0, 0), ERROR);
29     ok_int(GetLastError(), ERROR_INVALID_HANDLE);
30     SetLastError(0x12345);
31 
32     /* Set a clip region */
33     hrgn = CreateRectRgn(10, 10, 20, 30);
34     ok_int(SelectClipRgn(hdc, hrgn), NULLREGION); // yeah... it's NULLREGION
35     ok_int(GetRandomRgn(hdc, hrgn2, CLIPRGN), 1);
36     ok_int(EqualRgn(hrgn, hrgn2), TRUE); // but in fact it's the region we set
37 
38     /* Exclude something outside of the clip region */
39     ok_int(ExcludeClipRect(hdc, 0, 0, 1, 1), COMPLEXREGION); // in reality it's a rect region
40     ok_int(GetRandomRgn(hdc, hrgn2, CLIPRGN), 1);
41     ok_int(EqualRgn(hrgn, hrgn2), TRUE);
42 
43     /* Exclude something on one side of the clip rect */
44     ok_int(ExcludeClipRect(hdc, 0, 0, 13, 50), COMPLEXREGION);
45     ok_int(GetRandomRgn(hdc, hrgn2, CLIPRGN), 1);
46     ok_int(CombineRgn(hrgn, hrgn2, NULL, RGN_COPY), SIMPLEREGION);
47 
48     /* Exclude something on the edge of the clip rect */
49     ok_int(ExcludeClipRect(hdc, 0, 0, 15, 15), COMPLEXREGION);
50     ok_int(GetRandomRgn(hdc, hrgn2, CLIPRGN), 1);
51     ok_int(CombineRgn(hrgn, hrgn2, NULL, RGN_COPY), COMPLEXREGION);
52 
53     /* Exclude everything left */
54     ok_int(ExcludeClipRect(hdc, 0, 0, 100, 100), NULLREGION);
55     ok_int(GetRandomRgn(hdc, hrgn2, CLIPRGN), 1);
56     ok_int(CombineRgn(hrgn, hrgn2, NULL, RGN_COPY), NULLREGION);
57 
58     /* Reset the clip region */
59     ok_int(SelectClipRgn(hdc, NULL), SIMPLEREGION); // makes sense, it's actually the whole region
60     ok_int(GetRandomRgn(hdc, hrgn2, CLIPRGN), 0); // return value says region is NULL
61     ok_int(ExcludeClipRect(hdc, 0, 0, 1, 1), NULLREGION);
62     ok_int(GetRandomRgn(hdc, hrgn2, CLIPRGN), 1); // but now we have a region
63     ok_int(CombineRgn(hrgn, hrgn2, NULL, RGN_COPY), NULLREGION); // but it's a NULLREGION (aka empty)?
64 
65     /* Test negative rect */
66     ok_int(SelectClipRgn(hdc, NULL), SIMPLEREGION);
67     ok_int(ExcludeClipRect(hdc, -10, -10, 0, 0), COMPLEXREGION); // this time it's a complex region?
68     ok_int(GetRandomRgn(hdc, hrgn2, CLIPRGN), 1);
69     hrgn = CreateRectRgn(0, 0, 1, 1);
70     ok_int(CombineRgn(hrgn2, hrgn2, hrgn, RGN_XOR), NULLREGION);
71 
72     /* Test rect with high coordinates */
73     ok_int(SelectClipRgn(hdc, NULL), SIMPLEREGION);
74     ok_int(ExcludeClipRect(hdc, 100000, 100000, 100010, 100010), COMPLEXREGION); // this time it's a complex region?
75     ok_int(GetRandomRgn(hdc, hrgn2, CLIPRGN), 1);
76     hrgn = CreateRectRgn(0, 0, 1, 1);
77     ok_int(EqualRgn(hrgn, hrgn2), TRUE);
78     DeleteObject(hrgn);
79 
80     /* Test reversed rect negative, but still above 0 */
81     ok_int(SelectClipRgn(hdc, NULL), SIMPLEREGION);
82     ok_int(ExcludeClipRect(hdc, 1, 1, -10, -20), NULLREGION);
83     ok_int(GetRandomRgn(hdc, hrgn2, CLIPRGN), 1);
84     hrgn = CreateRectRgn(0, 0, 0, 0);
85     ok_int(CombineRgn(hrgn, hrgn2, NULL, RGN_COPY), NULLREGION);
86 
87     ok_int(GetLastError(), 0x12345);
88 
89 }
90 
91 
92 START_TEST(ExcludeClipRect)
93 {
94     Test_ExcludeClipRect();
95 }
96