1 /* Unit test suite for user interface functions
3 * Copyright 2009 Nikolay Sivov
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.
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.
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
20 #define WINE_NO_INLINE_RECT
21 #include "wine/test.h"
26 static void test_FillRect(void)
30 HBITMAP hbmp
, oldhbmp
;
35 /* fill bitmap data with white */
36 memset(bits
, 0xff, sizeof(bits
));
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
);
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
);
60 SelectObject(hdcmem
, oldhbmp
);
66 static void test_SubtractRect(void)
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
));
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
));
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
));
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
));
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
));
115 static void test_EqualRect(void)
120 SetRect(&rect1
, 0, 0, 0, 0);
121 SetRect(&rect2
, 1, 1, 1, 1);
123 ret
= EqualRect(NULL
, NULL
);
124 ok(!ret
, "got %d\n", ret
);
126 ret
= EqualRect(&rect1
, NULL
);
127 ok(!ret
, "got %d\n", ret
);
129 ret
= EqualRect(NULL
, &rect2
);
130 ok(!ret
, "got %d\n", ret
);
132 ret
= EqualRect(&rect1
, &rect2
);
133 ok(!ret
, "got %d\n", ret
);
135 SetRect(&rect1
, 0, 0, 10, 10);
136 SetRect(&rect2
, 10, 10, 0, 0);
138 ret
= EqualRect(&rect1
, &rect2
);
139 ok(!ret
, "got %d\n", ret
);
141 ret
= EqualRect(&rect1
, &rect1
);
142 ok(ret
, "got %d\n", ret
);
145 ret
= EqualRect(&rect1
, &rect2
);
146 ok(ret
, "got %d\n", ret
);
149 static void test_IsRectEmpty(void)
153 static const struct {
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
},
178 for (i
= 0; i
< ARRAY_SIZE(rtest
); 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
));
185 static void test_SetRect(void)
190 ret
= SetRect(NULL
, 0, 0, 0, 0);
191 ok(!ret
, "got %d\n", ret
);
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");
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");