Git conversion: Make reactos the root directory, move rosapps, rostests, wallpapers...
[reactos.git] / modules / rostests / winetests / user32 / uitools.c
1 /* Unit test suite for user interface functions
2 *
3 * Copyright 2009 Nikolay Sivov
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19
20 #define WINE_NO_INLINE_RECT
21 #include "wine/test.h"
22 #include "winbase.h"
23 #include "wingdi.h"
24 #include "winuser.h"
25
26 static void test_FillRect(void)
27 {
28 HDC hdc, hdcmem;
29 DWORD bits[64];
30 HBITMAP hbmp, oldhbmp;
31 COLORREF col;
32 HBRUSH old_brush;
33 RECT r;
34
35 /* fill bitmap data with white */
36 memset(bits, 0xff, sizeof(bits));
37
38 hdc = GetDC(0);
39 ok( hdc != NULL, "CreateDC rets %p\n", hdc);
40 /* create a memory dc */
41 hdcmem = CreateCompatibleDC(hdc);
42 ok(hdcmem != NULL, "CreateCompatibleDC rets %p\n", hdcmem);
43 /* test monochrome bitmap: should always work */
44 hbmp = CreateBitmap(32, 32, 1, 1, bits);
45 ok(hbmp != NULL, "CreateBitmap returns %p\n", hbmp);
46 oldhbmp = SelectObject(hdcmem, hbmp);
47 ok(oldhbmp != NULL, "SelectObject returned NULL\n"); /* a memdc always has a bitmap selected */
48 col = GetPixel(hdcmem, 0, 0);
49 ok( col == 0xffffff, "GetPixel returned %08x, expected 0xffffff\n", col);
50
51 /* select black brush */
52 old_brush = SelectObject(hdcmem, GetStockObject(BLACK_BRUSH));
53 SetRect(&r, 0, 0, 5, 5);
54 FillRect(hdcmem, &r, 0);
55 SelectObject(hdcmem, old_brush);
56 /* bitmap filled with last selected brush */
57 col = GetPixel(hdcmem, 0, 0);
58 ok(col == 0, "GetPixel returned %08x, expected 0\n", col);
59
60 SelectObject(hdcmem, oldhbmp);
61 DeleteObject(hbmp);
62 DeleteDC(hdcmem);
63 ReleaseDC(0, hdc);
64 }
65
66 static void test_SubtractRect(void)
67 {
68 RECT rect1;
69 RECT rect2;
70 RECT rectr;
71 BOOL result;
72
73 /* source rectangles don't intersect */
74 SetRect(&rect1, 50, 50, 150, 100);
75 SetRect(&rect2, 250, 200, 1500, 1000);
76 result = SubtractRect(&rectr, &rect1, &rect2);
77 ok(result, "SubtractRect returned FALSE but subtraction should not be empty\n");
78 ok(result && rectr.left == 50 && rectr.top == 50 && rectr.right ==150
79 && rectr.bottom == 100, "wrong rect subtraction of SubtractRect (dest rect=%s)\n",
80 wine_dbgstr_rect(&rectr));
81
82 /* source rect 2 partially overlaps rect 1 */
83 SetRect(&rect1, 2431, 626, 3427, 1608);
84 SetRect(&rect2, 2499, 626, 3427, 1608);
85 result = SubtractRect(&rectr, &rect1, &rect2);
86 ok(result, "SubtractRect returned FALSE but subtraction should not be empty\n");
87 ok(result && rectr.left == 2431 && rectr.top == 626 && rectr.right == 2499
88 && rectr.bottom == 1608, "wrong rect subtraction of SubtractRect (dest rect=%s)\n",
89 wine_dbgstr_rect(&rectr));
90
91 /* source rect 2 partially overlaps rect 1 - dest is src rect 2 */
92 SetRect(&rect1, 2431, 626, 3427, 1608);
93 SetRect(&rect2, 2499, 626, 3427, 1608);
94 result = SubtractRect(&rect2, &rect1, &rect2);
95 ok(result, "SubtractRect returned FALSE but subtraction should not be empty\n");
96 ok(result && rectr.left == 2431 && rectr.top == 626 && rectr.right == 2499
97 && rectr.bottom == 1608, "wrong rect subtraction of SubtractRect (dest rect=%s)\n",
98 wine_dbgstr_rect(&rectr));
99
100 /* source rect 2 completely overlaps rect 1 */
101 SetRect(&rect1, 250, 250, 400, 500);
102 SetRect(&rect2, 50, 50, 1500, 1000);
103 result = SubtractRect(&rectr, &rect1, &rect2);
104 ok(!result, "SubtractRect returned TRUE but subtraction should be empty (dest rect=%s)\n",
105 wine_dbgstr_rect(&rectr));
106
107 /* source rect 2 completely overlaps rect 1 - dest is src rect 2 */
108 SetRect(&rect1, 250, 250, 400, 500);
109 SetRect(&rect2, 50, 50, 1500, 1000);
110 result = SubtractRect(&rect2, &rect1, &rect2);
111 ok(!result, "SubtractRect returned TRUE but subtraction should be empty (dest rect=%s)\n",
112 wine_dbgstr_rect(&rect2));
113 }
114
115 static void test_EqualRect(void)
116 {
117 RECT rect1, rect2;
118 BOOL ret;
119
120 SetRect(&rect1, 0, 0, 0, 0);
121 SetRect(&rect2, 1, 1, 1, 1);
122
123 ret = EqualRect(NULL, NULL);
124 ok(!ret, "got %d\n", ret);
125
126 ret = EqualRect(&rect1, NULL);
127 ok(!ret, "got %d\n", ret);
128
129 ret = EqualRect(NULL, &rect2);
130 ok(!ret, "got %d\n", ret);
131
132 ret = EqualRect(&rect1, &rect2);
133 ok(!ret, "got %d\n", ret);
134
135 SetRect(&rect1, 0, 0, 10, 10);
136 SetRect(&rect2, 10, 10, 0, 0);
137
138 ret = EqualRect(&rect1, &rect2);
139 ok(!ret, "got %d\n", ret);
140
141 ret = EqualRect(&rect1, &rect1);
142 ok(ret, "got %d\n", ret);
143
144 rect2 = rect1;
145 ret = EqualRect(&rect1, &rect2);
146 ok(ret, "got %d\n", ret);
147 }
148
149 static void test_IsRectEmpty(void)
150 {
151 BOOL ret;
152 unsigned int i;
153 static const struct {
154 RECT rect;
155 BOOL ret;
156 } rtest[] = {
157 {{0, 0, 0, 0}, TRUE},
158 {{127, 131, 127, 131}, TRUE},
159 {{MAXLONG, MAXLONG, MAXLONG, MAXLONG}, TRUE},
160 {{-1, -1, -1, -1}, TRUE},
161 {{-2011, -2017, -2011, -2017}, TRUE},
162 {{MINLONG, MINLONG, MINLONG, MINLONG}, TRUE},
163 /* Only width or height are 0 */
164 {{31, 37, 31, 41}, TRUE},
165 {{881, 883, 887, 883}, TRUE},
166 {{-1721, 1723, -1721, 7213}, TRUE},
167 /* Negative width and/or height */
168 {{11, 13, 5, 7}, TRUE},
169 {{-11, -13, -19, -23}, TRUE},
170 {{11, 13, -17, 19}, TRUE},
171 {{11, 13, 17, 11}, TRUE},
172 /* Non empty rects */
173 {{101, 103, 107, 109}, FALSE},
174 {{1, -9, 7, 3}, FALSE},
175 {{-109, -107, -103, -101}, FALSE},
176 };
177
178 for (i = 0; i < sizeof(rtest)/sizeof(rtest[0]); i++) {
179 ret = IsRectEmpty(&rtest[i].rect);
180 ok(ret == rtest[i].ret, "Test %d: IsRectEmpty returned %s for %s\n", i,
181 ret ? "TRUE" : "FALSE", wine_dbgstr_rect(&rtest[i].rect));
182 }
183 }
184
185 static void test_SetRect(void)
186 {
187 RECT rect;
188 BOOL ret;
189
190 ret = SetRect(NULL, 0, 0, 0, 0);
191 ok(!ret, "got %d\n", ret);
192
193 ret = SetRect(&rect, 1, 2, 3, 4);
194 ok(ret, "got %d\n", ret);
195 ok(rect.left == 1 && rect.top == 2 && rect.right == 3 && rect.bottom == 4,
196 "got wrong rectangle\n");
197
198 ret = SetRect(&rect, 10, 10, 5, 5);
199 ok(ret, "got %d\n", ret);
200 ok(rect.left == 10 && rect.top == 10 && rect.right == 5 && rect.bottom == 5,
201 "got wrong rectangle\n");
202 }
203
204 START_TEST(uitools)
205 {
206 test_FillRect();
207 test_SubtractRect();
208 test_EqualRect();
209 test_IsRectEmpty();
210 test_SetRect();
211 }