[GDI32_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 <stdio.h>
9 #include <wine/test.h>
10 #include <windows.h>
11
12 void Test_Rectangle(void)
13 {
14 HDC hdc;
15 HBITMAP hBmp;
16 BOOL ret;
17 HBRUSH hBrush;
18 COLORREF color;
19
20 hdc = CreateCompatibleDC(NULL);
21 ok(hdc != NULL, "Failed to create the DC!\n");
22 hBmp = CreateCompatibleBitmap(hdc, 4, 4);
23 ok(hBmp != NULL, "Failed to create the Bitmap!\n");
24 hBmp = SelectObject(hdc, hBmp);
25 ok(hBmp != NULL, "Failed to select the Bitmap!\n");
26
27 hBrush = CreateSolidBrush(RGB(0, 0, 0));
28 ok(hBrush != NULL, "Failed to create a solid brush!\n");
29 hBrush = SelectObject(hdc, hBrush);
30 ok(hBrush != NULL, "Failed to select the brush!\n");
31
32 /* Blank the bitmap */
33 ret = BitBlt(hdc, 0, 0, 4, 4, NULL, 0, 0, WHITENESS);
34 ok(ret, "BitBlt failed to blank the bitmap!\n");
35
36 /* Try inverted rectangle coordinates */
37 ret = Rectangle(hdc, 0, 2, 2, 0);
38 ok(ret, "Rectangle failed!");
39 color = GetPixel(hdc, 0, 0);
40 ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
41 color = GetPixel(hdc, 2, 2);
42 ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
43 color = GetPixel(hdc, 0, 2);
44 ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
45 color = GetPixel(hdc, 2, 0);
46 ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
47 color = GetPixel(hdc, 1, 1);
48 ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
49
50 ret = BitBlt(hdc, 0, 0, 4, 4, NULL, 0, 0, WHITENESS);
51 ok(ret, "BitBlt failed to blank the bitmap!\n");
52 /* Try well ordered rectangle coordinates */
53 ret = Rectangle(hdc, 0, 0, 2, 2);
54 ok(ret, "Rectangle failed!");
55 color = GetPixel(hdc, 0, 0);
56 ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
57 color = GetPixel(hdc, 2, 2);
58 ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
59 color = GetPixel(hdc, 0, 2);
60 ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
61 color = GetPixel(hdc, 2, 0);
62 ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
63 color = GetPixel(hdc, 1, 1);
64 ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
65
66 /* Same tests with GM_ADVANCED */
67 ok(SetGraphicsMode(hdc, GM_ADVANCED) == GM_COMPATIBLE, "Default mode for the DC is not GM_COMPATIBLE.\n");
68
69 /* Blank the bitmap */
70 ret = BitBlt(hdc, 0, 0, 4, 4, NULL, 0, 0, WHITENESS);
71 ok(ret, "BitBlt failed to blank the bitmap!\n");
72
73 /* Try inverted rectangle coordinates */
74 ret = Rectangle(hdc, 0, 2, 2, 0);
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(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
80 color = GetPixel(hdc, 0, 2);
81 ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
82 color = GetPixel(hdc, 2, 0);
83 ok( color == RGB(0, 0, 0), "Expected 0, 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 ret = BitBlt(hdc, 0, 0, 4, 4, NULL, 0, 0, WHITENESS);
88 ok(ret, "BitBlt failed to blank the bitmap!\n");
89 /* Try well ordered rectangle coordinates */
90 ret = Rectangle(hdc, 0, 0, 2, 2);
91 ok(ret, "Rectangle failed!");
92 color = GetPixel(hdc, 0, 0);
93 ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
94 color = GetPixel(hdc, 2, 2);
95 ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
96 color = GetPixel(hdc, 0, 2);
97 ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
98 color = GetPixel(hdc, 2, 0);
99 ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
100 color = GetPixel(hdc, 1, 1);
101 ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
102
103
104 hBmp = SelectObject(hdc, hBmp);
105 hBrush = SelectObject(hdc, hBrush);
106 DeleteObject(hBmp);
107 DeleteObject(hBrush);
108 DeleteDC(hdc);
109 }
110
111
112 START_TEST(Rectangle)
113 {
114 Test_Rectangle();
115 }