ReactOS  0.4.14-dev-376-gaedba84
Rectangle.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS api tests
3  * LICENSE: GPL - See COPYING in the top level directory
4  * PURPOSE: Test for Rectangle
5  * PROGRAMMERS: Jérôme Gardou
6  */
7 
8 #include "precomp.h"
9 
10 void Test_Rectangle(void)
11 {
12  HDC hdc;
13  HBITMAP hBmp;
14  BOOL ret;
15  HBRUSH hBrush;
16  HPEN hPen;
18 
20  ok(hdc != NULL, "Failed to create the DC!\n");
21  hBmp = CreateCompatibleBitmap(hdc, 4, 4);
22  ok(hBmp != NULL, "Failed to create the Bitmap!\n");
23  hBmp = SelectObject(hdc, hBmp);
24  ok(hBmp != NULL, "Failed to select the Bitmap!\n");
25 
26  hBrush = CreateSolidBrush(RGB(0, 0, 0));
27  ok(hBrush != NULL, "Failed to create a solid brush!\n");
28  hBrush = SelectObject(hdc, hBrush);
29  ok(hBrush != NULL, "Failed to select the brush!\n");
30 
31  /* Blank the bitmap */
32  ret = BitBlt(hdc, 0, 0, 4, 4, NULL, 0, 0, WHITENESS);
33  ok(ret, "BitBlt failed to blank the bitmap!\n");
34 
35  /* Try inverted rectangle coordinates */
36  ret = Rectangle(hdc, 0, 2, 2, 0);
37  ok(ret, "Rectangle failed!");
38  color = GetPixel(hdc, 0, 0);
39  ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
40  color = GetPixel(hdc, 2, 2);
41  ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
42  color = GetPixel(hdc, 0, 2);
43  ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
44  color = GetPixel(hdc, 2, 0);
45  ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
46  color = GetPixel(hdc, 1, 1);
47  ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
48 
49  ret = BitBlt(hdc, 0, 0, 4, 4, NULL, 0, 0, WHITENESS);
50  ok(ret, "BitBlt failed to blank the bitmap!\n");
51  /* Try well ordered rectangle coordinates */
52  ret = Rectangle(hdc, 0, 0, 2, 2);
53  ok(ret, "Rectangle failed!");
54  color = GetPixel(hdc, 0, 0);
55  ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
56  color = GetPixel(hdc, 2, 2);
57  ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
58  color = GetPixel(hdc, 0, 2);
59  ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
60  color = GetPixel(hdc, 2, 0);
61  ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
62  color = GetPixel(hdc, 1, 1);
63  ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
64 
65  /* tests with NULL pen */
67 
68  /* Blank the bitmap */
69  ret = BitBlt(hdc, 0, 0, 4, 4, NULL, 0, 0, WHITENESS);
70  ok(ret, "BitBlt failed to blank the bitmap!\n");
71 
72  ret = Rectangle(hdc, 0, 0, 3, 3);
73  ok(ret, "Rectangle failed!");
74  color = GetPixel(hdc, 0, 0);
75  ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
76  color = GetPixel(hdc, 2, 2);
77  ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
78  color = GetPixel(hdc, 0, 2);
79  ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
80  color = GetPixel(hdc, 2, 0);
81  ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
82  color = GetPixel(hdc, 1, 1);
83  ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
84 
85  SelectObject(hdc, hPen);
86 
87  /* Same tests with GM_ADVANCED */
88  ok(SetGraphicsMode(hdc, GM_ADVANCED) == GM_COMPATIBLE, "Default mode for the DC is not GM_COMPATIBLE.\n");
89 
90  /* Blank the bitmap */
91  ret = BitBlt(hdc, 0, 0, 4, 4, NULL, 0, 0, WHITENESS);
92  ok(ret, "BitBlt failed to blank the bitmap!\n");
93 
94  /* Try inverted rectangle coordinates */
95  ret = Rectangle(hdc, 0, 2, 2, 0);
96  ok(ret, "Rectangle failed!");
97  color = GetPixel(hdc, 0, 0);
98  ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
99  color = GetPixel(hdc, 2, 2);
100  ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
101  color = GetPixel(hdc, 0, 2);
102  ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
103  color = GetPixel(hdc, 2, 0);
104  ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
105  color = GetPixel(hdc, 1, 1);
106  ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
107 
108  ret = BitBlt(hdc, 0, 0, 4, 4, NULL, 0, 0, WHITENESS);
109  ok(ret, "BitBlt failed to blank the bitmap!\n");
110  /* Try well ordered rectangle coordinates */
111  ret = Rectangle(hdc, 0, 0, 2, 2);
112  ok(ret, "Rectangle failed!");
113  color = GetPixel(hdc, 0, 0);
114  ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
115  color = GetPixel(hdc, 2, 2);
116  ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
117  color = GetPixel(hdc, 0, 2);
118  ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
119  color = GetPixel(hdc, 2, 0);
120  ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
121  color = GetPixel(hdc, 1, 1);
122  ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
123 
124 
125  hBmp = SelectObject(hdc, hBmp);
126  hBrush = SelectObject(hdc, hBrush);
127  DeleteObject(hBmp);
128  DeleteObject(hBrush);
129  DeleteDC(hdc);
130 }
131 
132 
134 {
135  Test_Rectangle();
136 }
HGDIOBJ WINAPI GetStockObject(_In_ int)
BOOL WINAPI Rectangle(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int)
HBITMAP WINAPI CreateCompatibleBitmap(_In_ HDC hdc, _In_ INT cx, _In_ INT cy)
static HDC
Definition: imagelist.c:92
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
DWORD GetPixel(LPDIRECTDRAWSURFACE7 Surface, UINT x, UINT y)
Definition: blt.cpp:2
static VOID NTAPI BitBlt(IN ULONG Left, IN ULONG Top, IN ULONG Width, IN ULONG Height, IN PUCHAR Buffer, IN ULONG BitsPerPixel, IN ULONG Delta)
Definition: vga.c:410
unsigned int BOOL
Definition: ntddk_ex.h:94
GLuint color
Definition: glext.h:6243
#define NULL_PEN
Definition: wingdi.h:903
smooth NULL
Definition: ftsmooth.c:416
DWORD COLORREF
Definition: windef.h:285
#define RGB(r, g, b)
Definition: wingdi.h:2935
#define GM_COMPATIBLE
Definition: wingdi.h:863
int ret
HDC hdc
Definition: main.c:9
START_TEST(Rectangle)
Definition: Rectangle.c:133
#define WHITENESS
Definition: wingdi.h:336
BOOL WINAPI DeleteDC(_In_ HDC)
#define ok(value,...)
Definition: atltest.h:57
unsigned int UINT
Definition: ndis.h:50
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)
static HBITMAP
Definition: button.c:44
void Test_Rectangle(void)
Definition: Rectangle.c:10
int WINAPI SetGraphicsMode(_In_ HDC, _In_ int)
Definition: dc.c:1202
#define GM_ADVANCED
Definition: wingdi.h:864