ReactOS 0.4.15-dev-7942-gd23573b
uitools.c
Go to the documentation of this file.
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
26static 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);
62 DeleteDC(hdcmem);
63 ReleaseDC(0, hdc);
64}
65
66static void test_SubtractRect(void)
67{
68 RECT rect1;
69 RECT rect2;
70 RECT rectr;
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",
113}
114
115static 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
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
149static 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},
160 {{-1, -1, -1, -1}, TRUE},
161 {{-2011, -2017, -2011, -2017}, 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 < 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));
182 }
183}
184
185static 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
205{
210 test_SetRect();
211}
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
static const char * wine_dbgstr_rect(const RECT *prc)
Definition: atltest.h:160
#define ARRAY_SIZE(A)
Definition: main.h:33
DWORD GetPixel(LPDIRECTDRAWSURFACE7 Surface, UINT x, UINT y)
Definition: blt.cpp:2
HBITMAP hbmp
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
RECT rect2
Definition: edittest.c:51
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
pKey DeleteObject()
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * bits
Definition: glext.h:10929
GLuint64EXT * result
Definition: glext.h:11304
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
HDC hdc
Definition: main.c:9
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:92
#define memset(x, y, z)
Definition: compat.h:39
& rect
Definition: startmenu.cpp:1413
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
static void test_FillRect(void)
Definition: uitools.c:26
static void test_SetRect(void)
Definition: uitools.c:185
static void test_EqualRect(void)
Definition: uitools.c:115
static void test_SubtractRect(void)
Definition: uitools.c:66
static void test_IsRectEmpty(void)
Definition: uitools.c:149
#define MAXLONG
Definition: umtypes.h:116
#define MINLONG
Definition: umtypes.h:115
int ret
DWORD COLORREF
Definition: windef.h:300
HGDIOBJ WINAPI GetStockObject(_In_ int)
HBITMAP WINAPI CreateBitmap(_In_ INT cx, _In_ INT cy, _In_ UINT cPlanes, _In_ UINT cBitsPerPel, _In_opt_ const VOID *pvBits)
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1539
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define BLACK_BRUSH
Definition: wingdi.h:896
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
BOOL WINAPI DeleteDC(_In_ HDC)
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
BOOL WINAPI IsRectEmpty(_In_ LPCRECT)
HDC WINAPI GetDC(_In_opt_ HWND)
BOOL WINAPI EqualRect(_In_ LPCRECT, _In_ LPCRECT)
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)
BOOL WINAPI SubtractRect(_Out_ LPRECT, _In_ LPCRECT, _In_ LPCRECT)