[SHELL32_APITEST] -Add some tests for SHParseDisplayName for CORE-12882.
[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(EqualRgn(hrgn, hrgn2), TRUE); // but in fact it's the region we set
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(EqualRgn(hrgn, hrgn2), TRUE);
53
54 /* Exclude something on one side of the clip rect */
55 ok_int(ExcludeClipRect(hdc, 0, 0, 13, 50), COMPLEXREGION);
56 ok_int(GetRandomRgn(hdc, hrgn2, CLIPRGN), 1);
57 ok_int(CombineRgn(hrgn, hrgn2, NULL, RGN_COPY), SIMPLEREGION);
58
59 /* Exclude something on the edge of the clip rect */
60 ok_int(ExcludeClipRect(hdc, 0, 0, 15, 15), COMPLEXREGION);
61 ok_int(GetRandomRgn(hdc, hrgn2, CLIPRGN), 1);
62 ok_int(CombineRgn(hrgn, hrgn2, NULL, RGN_COPY), COMPLEXREGION);
63
64 /* Exclude everything left */
65 ok_int(ExcludeClipRect(hdc, 0, 0, 100, 100), NULLREGION);
66 ok_int(GetRandomRgn(hdc, hrgn2, CLIPRGN), 1);
67 ok_int(CombineRgn(hrgn, hrgn2, NULL, RGN_COPY), NULLREGION);
68
69 /* Reset the clip region */
70 ok_int(SelectClipRgn(hdc, NULL), SIMPLEREGION); // makes sense, it's actually the whole region
71 ok_int(GetRandomRgn(hdc, hrgn2, CLIPRGN), 0); // return value says region is NULL
72 ok_int(ExcludeClipRect(hdc, 0, 0, 1, 1), NULLREGION);
73 ok_int(GetRandomRgn(hdc, hrgn2, CLIPRGN), 1); // but now we have a region
74 ok_int(CombineRgn(hrgn, hrgn2, NULL, RGN_COPY), NULLREGION); // but it's a NULLREGION (aka empty)?
75
76 /* Test negative rect */
77 ok_int(SelectClipRgn(hdc, NULL), SIMPLEREGION);
78 ok_int(ExcludeClipRect(hdc, -10, -10, 0, 0), COMPLEXREGION); // this time it's a complex region?
79 ok_int(GetRandomRgn(hdc, hrgn2, CLIPRGN), 1);
80 hrgn = CreateRectRgn(0, 0, 1, 1);
81 ok_int(CombineRgn(hrgn2, hrgn2, hrgn, RGN_XOR), NULLREGION);
82
83 /* Test rect with high coordinates */
84 ok_int(SelectClipRgn(hdc, NULL), SIMPLEREGION);
85 ok_int(ExcludeClipRect(hdc, 100000, 100000, 100010, 100010), COMPLEXREGION); // this time it's a complex region?
86 ok_int(GetRandomRgn(hdc, hrgn2, CLIPRGN), 1);
87 hrgn = CreateRectRgn(0, 0, 1, 1);
88 ok_int(EqualRgn(hrgn, hrgn2), TRUE);
89 DeleteObject(hrgn);
90
91 /* Test reversed rect negative, but still above 0 */
92 ok_int(SelectClipRgn(hdc, NULL), SIMPLEREGION);
93 ok_int(ExcludeClipRect(hdc, 1, 1, -10, -20), NULLREGION);
94 ok_int(GetRandomRgn(hdc, hrgn2, CLIPRGN), 1);
95 hrgn = CreateRectRgn(0, 0, 0, 0);
96 ok_int(CombineRgn(hrgn, hrgn2, NULL, RGN_COPY), NULLREGION);
97
98 ok_int(GetLastError(), 0x12345);
99
100 }
101
102
103 START_TEST(ExcludeClipRect)
104 {
105 Test_ExcludeClipRect();
106 }