[GDI32_APITEST] Fix MSVC build
[reactos.git] / modules / 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 "precomp.h"
9
10 void Test_Rectangle(void)
11 {
12 HDC hdc;
13 HBITMAP hBmp;
14 BOOL ret;
15 HBRUSH hBrush;
16 HPEN hPen;
17 COLORREF color;
18
19 hdc = CreateCompatibleDC(NULL);
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 */
66 hPen = SelectObject(hdc, GetStockObject(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
133 START_TEST(Rectangle)
134 {
135 Test_Rectangle();
136 }