[USER32_WINETEST] Sync with Wine Staging 1.9.11 Part 1. CORE-11368
[reactos.git] / 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 #include "wine/test.h"
21 #include "winbase.h"
22 #include "wingdi.h"
23 #include "winuser.h"
24
25 static void test_FillRect(void)
26 {
27 HDC hdc, hdcmem;
28 DWORD bits[64];
29 HBITMAP hbmp, oldhbmp;
30 COLORREF col;
31 HBRUSH old_brush;
32 RECT r;
33
34 /* fill bitmap data with white */
35 memset(bits, 0xff, sizeof(bits));
36
37 hdc = GetDC(0);
38 ok( hdc != NULL, "CreateDC rets %p\n", hdc);
39 /* create a memory dc */
40 hdcmem = CreateCompatibleDC(hdc);
41 ok(hdcmem != NULL, "CreateCompatibleDC rets %p\n", hdcmem);
42 /* test monochrome bitmap: should always work */
43 hbmp = CreateBitmap(32, 32, 1, 1, bits);
44 ok(hbmp != NULL, "CreateBitmap returns %p\n", hbmp);
45 oldhbmp = SelectObject(hdcmem, hbmp);
46 ok(oldhbmp != NULL, "SelectObject returned NULL\n"); /* a memdc always has a bitmap selected */
47 col = GetPixel(hdcmem, 0, 0);
48 ok( col == 0xffffff, "GetPixel returned %08x, expected 0xffffff\n", col);
49
50 /* select black brush */
51 old_brush = SelectObject(hdcmem, GetStockObject(BLACK_BRUSH));
52 SetRect(&r, 0, 0, 5, 5);
53 FillRect(hdcmem, &r, 0);
54 SelectObject(hdcmem, old_brush);
55 /* bitmap filled with last selected brush */
56 col = GetPixel(hdcmem, 0, 0);
57 ok(col == 0, "GetPixel returned %08x, expected 0\n", col);
58
59 SelectObject(hdcmem, oldhbmp);
60 DeleteObject(hbmp);
61 DeleteDC(hdcmem);
62 ReleaseDC(0, hdc);
63 }
64
65 static void test_SubtractRect(void)
66 {
67 RECT rect1;
68 RECT rect2;
69 RECT rectr;
70 BOOL result;
71
72 /* source rectangles don't intersect */
73 SetRect(&rect1, 50, 50, 150, 100);
74 SetRect(&rect2, 250, 200, 1500, 1000);
75 result = SubtractRect(&rectr, &rect1, &rect2);
76 ok(result, "SubtractRect returned FALSE but subtraction should not be empty\n");
77 ok(result && rectr.left == 50 && rectr.top == 50 && rectr.right ==150
78 && rectr.bottom == 100, "wrong rect subtraction of SubtractRect "
79 "(dest rect={%d, %d, %d, %d})\n", rectr.left, rectr.top, rectr.right, rectr.bottom);
80
81 /* source rect 2 partially overlaps rect 1 */
82 SetRect(&rect1, 2431, 626, 3427, 1608);
83 SetRect(&rect2, 2499, 626, 3427, 1608);
84 result = SubtractRect(&rectr, &rect1, &rect2);
85 ok(result, "SubtractRect returned FALSE but subtraction should not be empty\n");
86 ok(result && rectr.left == 2431 && rectr.top == 626 && rectr.right == 2499
87 && rectr.bottom == 1608, "wrong rect subtraction of SubtractRect "
88 "(dest rect={%d, %d, %d, %d})\n", rectr.left, rectr.top, rectr.right, rectr.bottom);
89
90 /* source rect 2 partially overlaps rect 1 - dest is src rect 2 */
91 SetRect(&rect1, 2431, 626, 3427, 1608);
92 SetRect(&rect2, 2499, 626, 3427, 1608);
93 result = SubtractRect(&rect2, &rect1, &rect2);
94 ok(result, "SubtractRect returned FALSE but subtraction should not be empty\n");
95 ok(result && rectr.left == 2431 && rectr.top == 626 && rectr.right == 2499
96 && rectr.bottom == 1608, "wrong rect subtraction of SubtractRect "
97 "(dest rect={%d, %d, %d, %d})\n", rectr.left, rectr.top, rectr.right, rectr.bottom);
98
99 /* source rect 2 completely overlaps rect 1 */
100 SetRect(&rect1, 250, 250, 400, 500);
101 SetRect(&rect2, 50, 50, 1500, 1000);
102 result = SubtractRect(&rectr, &rect1, &rect2);
103 ok(!result, "SubtractRect returned TRUE but subtraction should be empty "
104 "(dest rect={%d, %d, %d, %d})\n", rectr.left, rectr.top, rectr.right, rectr.bottom);
105
106 /* source rect 2 completely overlaps rect 1 - dest is src rect 2 */
107 SetRect(&rect1, 250, 250, 400, 500);
108 SetRect(&rect2, 50, 50, 1500, 1000);
109 result = SubtractRect(&rect2, &rect1, &rect2);
110 ok(!result, "SubtractRect returned TRUE but subtraction should be empty "
111 "(dest rect={%d, %d, %d, %d})\n", rect2.left, rect2.top, rect2.right, rect2.bottom);
112 }
113
114 START_TEST(uitools)
115 {
116 test_FillRect();
117 test_SubtractRect();
118 }