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