[NETAPI32]
[reactos.git] / rostests / apitests / gdi32 / GetClipBox.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for GetClipBox
5 * PROGRAMMERS: Timo Kreuzer
6 */
7
8 #include <apitest.h>
9
10 #include <wingdi.h>
11 #include <winuser.h>
12
13 #define ok_rect(_prc, _left, _top, _right, _bottom) \
14 ok_int((_prc)->left, _left); \
15 ok_int((_prc)->top, _top); \
16 ok_int((_prc)->right, _right); \
17 ok_int((_prc)->bottom, _bottom); \
18
19 void Test_GetClipBox()
20 {
21 HWND hWnd;
22 HDC hdc;
23 RECT rect;
24 HRGN hrgn, hrgn2;
25 int ret;
26
27 /* Create a window */
28 hWnd = CreateWindowW(L"BUTTON", L"TestWindow", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
29 CW_USEDEFAULT, CW_USEDEFAULT, 100, 100,
30 NULL, NULL, 0, 0);
31 ok(hWnd != NULL, "CreateWindowW failed\n");
32 if (hWnd == NULL)
33 {
34 return;
35 }
36
37 hdc = GetDC(hWnd);
38
39 /* Test invalid DC */
40 SetLastError(ERROR_SUCCESS);
41 ret = GetClipBox((HDC)0x12345, &rect);
42 ok(ret == ERROR, "Expected ERROR, got %d\n", ret);
43 ok(GetLastError() == 0, "Expected 0, got %ld\n", GetLastError());
44
45 //ret = GetClipBox(hdc, &rect);
46 //ok_int(ret, SIMPLEREGION);
47 //ok_rect(&rect, 0, 0, 132, 68);
48
49 /* Create a clip region */
50 hrgn = CreateRectRgn(5, 7, 50, 50);
51 SelectClipRgn(hdc, hrgn);
52 DeleteObject(hrgn);
53 ret = GetClipBox(hdc, &rect);
54 ok_int(ret, SIMPLEREGION);
55 ok_rect(&rect, 5, 7, 50, 50);
56
57 /* Set clip region as meta region */
58 SetMetaRgn(hdc);
59
60 /* Create a new clip region */
61 hrgn = CreateRectRgn(10, 10, 100, 100);
62 SelectClipRgn(hdc, hrgn);
63 DeleteObject(hrgn);
64 ret = GetClipBox(hdc, &rect);
65 ok_int(ret, SIMPLEREGION);
66 ok_rect(&rect, 10, 10, 50, 50);
67
68 /* Create an empty clip region */
69 hrgn = CreateRectRgn(10, 10, 10, 30);
70 SelectClipRgn(hdc, hrgn);
71 DeleteObject(hrgn);
72 ret = GetClipBox(hdc, &rect);
73 ok_int(ret, NULLREGION);
74 ok_rect(&rect, 0, 0, 0, 0);
75
76 /* Create a complex region */
77 hrgn = CreateRectRgn(10, 10, 30, 30);
78 hrgn2 = CreateRectRgn(20, 20, 60, 60);
79 ok_int(CombineRgn(hrgn, hrgn, hrgn2, RGN_OR), COMPLEXREGION);
80 SelectClipRgn(hdc, hrgn);
81 DeleteObject(hrgn2);
82 ret = GetClipBox(hdc, &rect);
83 ok_int(ret, COMPLEXREGION);
84 ok_rect(&rect, 10, 10, 50, 50);
85
86 /* Set scaling but keep the mapping mode (viewport should not be changed) */
87 ok_int(SetViewportExtEx(hdc, 1000, 1000, NULL), 1);
88 ret = GetClipBox(hdc, &rect);
89 ok_int(ret, COMPLEXREGION);
90 ok_rect(&rect, 10, 10, 50, 50);
91
92 /* Set unisotropic mode, ClipBox should be unchanged */
93 ok_int(SetMapMode(hdc, MM_ANISOTROPIC), 1);
94 ret = GetClipBox(hdc, &rect);
95 ok_int(ret, COMPLEXREGION);
96 ok_rect(&rect, 10, 10, 50, 50);
97
98 /* Now set viewport again */
99 ok_int(SetViewportExtEx(hdc, 200, 400, NULL), 1);
100 ret = GetClipBox(hdc, &rect);
101 ok_int(ret, COMPLEXREGION); // obviously some special secret feature...
102 ok_rect(&rect, 0, 0, 0, 0);
103
104 /* Reset clip region */
105 SelectClipRgn(hdc, NULL);
106 SetMetaRgn(hdc);
107 ret = GetClipBox(hdc, &rect);
108 ok_int(ret, SIMPLEREGION);
109 ok_rect(&rect, 0, 0, 0, 0);
110
111 hrgn = CreateRectRgn(10, 10, 190, 190);
112 SelectClipRgn(hdc, hrgn);
113 ret = GetClipBox(hdc, &rect);
114 ok_int(ret, SIMPLEREGION);
115 ok_rect(&rect, 0, 0, 0, 0);
116
117 /* Now also set the window extension */
118 ok_int(SetWindowExtEx(hdc, 400, 600, NULL), 1);
119 ret = GetClipBox(hdc, &rect);
120 ok_int(ret, SIMPLEREGION);
121 ok_rect(&rect, 20, 15, 100, 75);
122
123 hrgn = CreateRectRgn(30, 30, 300, 300);
124 SelectClipRgn(hdc, hrgn);
125 SetMetaRgn(hdc);
126 ret = GetClipBox(hdc, &rect);
127 ok_int(ret, SIMPLEREGION);
128 ok_rect(&rect, 60, 45, 100, 75);
129
130 ReleaseDC(hWnd, hdc);
131 DestroyWindow(hWnd);
132 }
133
134 START_TEST(GetClipBox)
135 {
136 Test_GetClipBox();
137 }
138