[IPHLPAPI_APITEST]
[reactos.git] / rostests / apitests / gdi32 / Rectangle.c
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 <apitest.h>
9
10 #include <wingdi.h>
11
12 void Test_Rectangle(void)
13 {
14 HDC hdc;
15 HBITMAP hBmp;
16 BOOL ret;
17 HBRUSH hBrush;
18 HPEN hPen;
19 COLORREF color;
20
21 hdc = CreateCompatibleDC(NULL);
22 ok(hdc != NULL, "Failed to create the DC!\n");
23 hBmp = CreateCompatibleBitmap(hdc, 4, 4);
24 ok(hBmp != NULL, "Failed to create the Bitmap!\n");
25 hBmp = SelectObject(hdc, hBmp);
26 ok(hBmp != NULL, "Failed to select the Bitmap!\n");
27
28 hBrush = CreateSolidBrush(RGB(0, 0, 0));
29 ok(hBrush != NULL, "Failed to create a solid brush!\n");
30 hBrush = SelectObject(hdc, hBrush);
31 ok(hBrush != NULL, "Failed to select the brush!\n");
32
33 /* Blank the bitmap */
34 ret = BitBlt(hdc, 0, 0, 4, 4, NULL, 0, 0, WHITENESS);
35 ok(ret, "BitBlt failed to blank the bitmap!\n");
36
37 /* Try inverted rectangle coordinates */
38 ret = Rectangle(hdc, 0, 2, 2, 0);
39 ok(ret, "Rectangle failed!");
40 color = GetPixel(hdc, 0, 0);
41 ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
42 color = GetPixel(hdc, 2, 2);
43 ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
44 color = GetPixel(hdc, 0, 2);
45 ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
46 color = GetPixel(hdc, 2, 0);
47 ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
48 color = GetPixel(hdc, 1, 1);
49 ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
50
51 ret = BitBlt(hdc, 0, 0, 4, 4, NULL, 0, 0, WHITENESS);
52 ok(ret, "BitBlt failed to blank the bitmap!\n");
53 /* Try well ordered rectangle coordinates */
54 ret = Rectangle(hdc, 0, 0, 2, 2);
55 ok(ret, "Rectangle failed!");
56 color = GetPixel(hdc, 0, 0);
57 ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
58 color = GetPixel(hdc, 2, 2);
59 ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
60 color = GetPixel(hdc, 0, 2);
61 ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
62 color = GetPixel(hdc, 2, 0);
63 ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
64 color = GetPixel(hdc, 1, 1);
65 ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
66
67 /* tests with NULL pen */
68 hPen = SelectObject(hdc, GetStockObject(NULL_PEN));
69
70 /* Blank the bitmap */
71 ret = BitBlt(hdc, 0, 0, 4, 4, NULL, 0, 0, WHITENESS);
72 ok(ret, "BitBlt failed to blank the bitmap!\n");
73
74 ret = Rectangle(hdc, 0, 0, 3, 3);
75 ok(ret, "Rectangle failed!");
76 color = GetPixel(hdc, 0, 0);
77 ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
78 color = GetPixel(hdc, 2, 2);
79 ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
80 color = GetPixel(hdc, 0, 2);
81 ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
82 color = GetPixel(hdc, 2, 0);
83 ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
84 color = GetPixel(hdc, 1, 1);
85 ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
86
87 SelectObject(hdc, hPen);
88
89 /* Same tests with GM_ADVANCED */
90 ok(SetGraphicsMode(hdc, GM_ADVANCED) == GM_COMPATIBLE, "Default mode for the DC is not GM_COMPATIBLE.\n");
91
92 /* Blank the bitmap */
93 ret = BitBlt(hdc, 0, 0, 4, 4, NULL, 0, 0, WHITENESS);
94 ok(ret, "BitBlt failed to blank the bitmap!\n");
95
96 /* Try inverted rectangle coordinates */
97 ret = Rectangle(hdc, 0, 2, 2, 0);
98 ok(ret, "Rectangle failed!");
99 color = GetPixel(hdc, 0, 0);
100 ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
101 color = GetPixel(hdc, 2, 2);
102 ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
103 color = GetPixel(hdc, 0, 2);
104 ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
105 color = GetPixel(hdc, 2, 0);
106 ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
107 color = GetPixel(hdc, 1, 1);
108 ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
109
110 ret = BitBlt(hdc, 0, 0, 4, 4, NULL, 0, 0, WHITENESS);
111 ok(ret, "BitBlt failed to blank the bitmap!\n");
112 /* Try well ordered rectangle coordinates */
113 ret = Rectangle(hdc, 0, 0, 2, 2);
114 ok(ret, "Rectangle failed!");
115 color = GetPixel(hdc, 0, 0);
116 ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
117 color = GetPixel(hdc, 2, 2);
118 ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
119 color = GetPixel(hdc, 0, 2);
120 ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
121 color = GetPixel(hdc, 2, 0);
122 ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
123 color = GetPixel(hdc, 1, 1);
124 ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
125
126
127 hBmp = SelectObject(hdc, hBmp);
128 hBrush = SelectObject(hdc, hBrush);
129 DeleteObject(hBmp);
130 DeleteObject(hBrush);
131 DeleteDC(hdc);
132 }
133
134
135 START_TEST(Rectangle)
136 {
137 Test_Rectangle();
138 }