[GDI32_APITEST]
[reactos.git] / rostests / apitests / gdi32 / ExcludeClipRect.c
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 <apitest.h>
9
10 #include <wingdi.h>
11 #include <winuser.h>
12
13 #define CLIPRGN 1
14
15 #define ok_rect(_prc, _left, _top, _right, _bottom) \
16 ok_int((_prc)->left, _left); \
17 ok_int((_prc)->top, _top); \
18 ok_int((_prc)->right, _right); \
19 ok_int((_prc)->bottom, _bottom); \
20
21 void Test_ExcludeClipRect()
22 {
23 HDC hdc;
24 HRGN hrgn, hrgn2;
25
26 hdc = CreateCompatibleDC(NULL);
27 ok(hdc != 0, "CreateCompatibleDC failed, skipping tests.\n");
28 if (!hdc) return;
29
30 hrgn2 = CreateRectRgn(0, 0, 0, 0);
31
32 /* Test NULL DC */
33 SetLastError(0x12345);
34 ok_int(ExcludeClipRect(NULL, 0, 0, 0, 0), ERROR);
35 ok_int(GetLastError(), ERROR_INVALID_HANDLE);
36
37 /* Test invalid DC */
38 SetLastError(0x12345);
39 ok_int(ExcludeClipRect((HDC)(ULONG_PTR)0x12345, 0, 0, 0, 0), ERROR);
40 ok_int(GetLastError(), ERROR_INVALID_HANDLE);
41 SetLastError(0x12345);
42
43 /* Set a clip region */
44 hrgn = CreateRectRgn(10, 10, 20, 30);
45 ok_int(SelectClipRgn(hdc, hrgn), NULLREGION); // yeah... it's NULLREGION
46 ok_int(GetRandomRgn(hdc, hrgn2, CLIPRGN), 1);
47 ok_int(CombineRgn(hrgn2, hrgn2, hrgn, RGN_XOR), NULLREGION); // but in fact it's a rect region!
48
49 /* Exclude something outside of the clip region */
50 ok_int(ExcludeClipRect(hdc, 0, 0, 1, 1), COMPLEXREGION); // in reality it's a rect region
51 ok_int(GetRandomRgn(hdc, hrgn2, CLIPRGN), 1);
52 ok_int(CombineRgn(hrgn2, hrgn2, hrgn, RGN_XOR), NULLREGION);
53
54 /* Now exclude something for real */
55 ok_int(ExcludeClipRect(hdc, 0, 0, 15, 15), COMPLEXREGION);
56 ok_int(GetRandomRgn(hdc, hrgn2, CLIPRGN), 1);
57 ok_int(CombineRgn(hrgn, hrgn2, NULL, RGN_COPY), COMPLEXREGION);
58
59 /* Exclude everything left */
60 ok_int(ExcludeClipRect(hdc, 0, 0, 100, 100), NULLREGION);
61 ok_int(GetRandomRgn(hdc, hrgn2, CLIPRGN), 1);
62 ok_int(CombineRgn(hrgn, hrgn2, NULL, RGN_COPY), NULLREGION);
63
64 /* Reset the clip region */
65 ok_int(SelectClipRgn(hdc, NULL), SIMPLEREGION); // makes sense, it's actually the whole region
66 ok_int(GetRandomRgn(hdc, hrgn2, CLIPRGN), 0); // return value says region is NULL
67 ok_int(ExcludeClipRect(hdc, 0, 0, 1, 1), NULLREGION);
68 ok_int(GetRandomRgn(hdc, hrgn2, CLIPRGN), 1); // but now we have a region
69 ok_int(CombineRgn(hrgn, hrgn2, NULL, RGN_COPY), NULLREGION); // but it's a NULLREGION (aka empty)?
70
71 /* Test negative rect */
72 ok_int(SelectClipRgn(hdc, NULL), SIMPLEREGION);
73 ok_int(ExcludeClipRect(hdc, -10, -10, 0, 0), COMPLEXREGION); // this time it's a complex region?
74 ok_int(GetRandomRgn(hdc, hrgn2, CLIPRGN), 1);
75 hrgn = CreateRectRgn(0, 0, 1, 1);
76 ok_int(CombineRgn(hrgn2, hrgn2, hrgn, RGN_XOR), NULLREGION);
77
78 /* Test rect with high coordinates */
79 ok_int(SelectClipRgn(hdc, NULL), SIMPLEREGION);
80 ok_int(ExcludeClipRect(hdc, 100000, 100000, 100010, 100010), COMPLEXREGION); // this time it's a complex region?
81 ok_int(GetRandomRgn(hdc, hrgn2, CLIPRGN), 1);
82 hrgn = CreateRectRgn(0, 0, 1, 1);
83 ok_int(CombineRgn(hrgn2, hrgn2, hrgn, RGN_XOR), NULLREGION);
84
85 /* Test reversed rect negative, but still above 0 */
86 ok_int(SelectClipRgn(hdc, NULL), SIMPLEREGION);
87 ok_int(ExcludeClipRect(hdc, 1, 1, -10, -20), NULLREGION);
88 ok_int(GetRandomRgn(hdc, hrgn2, CLIPRGN), 1);
89 hrgn = CreateRectRgn(0, 0, 0, 0);
90 ok_int(CombineRgn(hrgn, hrgn2, NULL, RGN_COPY), NULLREGION);
91
92 ok_int(GetLastError(), 0x12345);
93
94 }
95
96
97 START_TEST(ExcludeClipRect)
98 {
99 Test_ExcludeClipRect();
100 }