[MMEBUDDY]
[reactos.git] / rostests / apitests / gdi32 / SelectObject.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for SelectObject
5 * PROGRAMMERS: Timo Kreuzer
6 */
7
8 #include <stdio.h>
9 #include <wine/test.h>
10 #include <windows.h>
11 #include <winddi.h>
12 #include <reactos/win32k/ntgdityp.h>
13 #include <reactos/win32k/ntgdihdl.h>
14
15 #define TEST(x) ok(x, #x"\n")
16 #define RTEST(x) ok(x, #x"\n")
17
18 void Test_SelectObject()
19 {
20 HGDIOBJ hOldObj, hNewObj;
21 HDC hScreenDC, hDC, hDC2;
22 // PGDI_TABLE_ENTRY pEntry;
23 // PDC_ATTR pDc_Attr;
24 // HANDLE hcmXform;
25 BYTE bmBits[4] = {0};
26
27 hScreenDC = GetDC(NULL);
28 ok(hScreenDC != NULL, "GetDC failed. Skipping tests.\n");
29 if (hScreenDC == NULL) return;
30 hDC = CreateCompatibleDC(hScreenDC);
31 ok(hDC != NULL, "CreateCompatibleDC failed. Skipping tests.\n");
32 if (hDC == NULL) return;
33
34 /* Get the Dc_Attr for later testing */
35 // pEntry = &GdiHandleTable[GDI_HANDLE_GET_INDEX(hDC)];
36 // pDc_Attr = pEntry->UserData;
37 // ok(pDc_Attr != NULL, "Skipping tests.\n");
38 // if (pDc_Attr == NULL) return;
39
40 /* Test incomplete dc handle doesn't work */
41 SetLastError(ERROR_SUCCESS);
42 hNewObj = GetStockObject(GRAY_BRUSH);
43 hOldObj = SelectObject((HDC)GDI_HANDLE_GET_INDEX(hDC), hNewObj);
44 RTEST(GetLastError() == ERROR_INVALID_HANDLE);
45 RTEST(hOldObj == NULL);
46 // RTEST(pDc_Attr->hbrush == GetStockObject(WHITE_BRUSH));
47 SelectObject(hDC, hOldObj);
48
49 /* Test incomplete hobj handle works */
50 hNewObj = GetStockObject(GRAY_BRUSH);
51 hOldObj = SelectObject(hDC, (HGDIOBJ)GDI_HANDLE_GET_INDEX(hNewObj));
52 RTEST(hOldObj == GetStockObject(WHITE_BRUSH));
53 // RTEST(pDc_Attr->hbrush == hNewObj);
54 SelectObject(hDC, hOldObj);
55
56 /* Test wrong hDC handle type */
57 SetLastError(ERROR_SUCCESS);
58 hNewObj = GetStockObject(GRAY_BRUSH);
59 hDC2 = (HDC)((UINT_PTR)hDC & ~GDI_HANDLE_TYPE_MASK);
60 hDC2 = (HDC)((UINT_PTR)hDC2 | GDI_OBJECT_TYPE_PEN);
61 hOldObj = SelectObject(hDC2, hNewObj);
62 RTEST(GetLastError() == ERROR_INVALID_HANDLE);
63 RTEST(hOldObj == NULL);
64 // RTEST(pDc_Attr->hbrush == GetStockObject(WHITE_BRUSH));
65
66 /* Test wrong hobj handle type */
67 SetLastError(ERROR_SUCCESS);
68 hNewObj = GetStockObject(GRAY_BRUSH);
69 hNewObj = (HGDIOBJ)((UINT_PTR)hNewObj & ~GDI_HANDLE_TYPE_MASK);
70 hNewObj = (HGDIOBJ)((UINT_PTR)hNewObj | GDI_OBJECT_TYPE_PEN);
71 hOldObj = SelectObject(hDC, hNewObj);
72 RTEST(GetLastError() == ERROR_SUCCESS);
73 RTEST(hOldObj == NULL);
74 // RTEST(pDc_Attr->hbrush == GetStockObject(WHITE_BRUSH));
75
76 SetLastError(ERROR_SUCCESS);
77 hNewObj = (HGDIOBJ)0x00761234;
78 hOldObj = SelectObject(hDC, hNewObj);
79 RTEST(hOldObj == NULL);
80 RTEST(GetLastError() == ERROR_SUCCESS);
81 SelectObject(hDC, hOldObj);
82
83 /* Test DC */
84 SetLastError(ERROR_SUCCESS);
85 hOldObj = SelectObject(hDC, hScreenDC);
86 RTEST(hOldObj == NULL);
87 TEST(GetLastError() == ERROR_SUCCESS);
88
89 /* Test REGION */
90 SetLastError(ERROR_SUCCESS);
91 hNewObj = CreateRectRgn(0,0,0,0);
92 hOldObj = SelectObject(hDC, hNewObj);
93 RTEST((UINT_PTR)hOldObj == NULLREGION);
94 DeleteObject(hNewObj);
95
96 hNewObj = CreateRectRgn(0,0,10,10);
97 RTEST((UINT_PTR)SelectObject(hDC, hNewObj) == SIMPLEREGION);
98 hOldObj = CreateRectRgn(5,5,20,20);
99 RTEST(CombineRgn(hNewObj, hNewObj, hOldObj, RGN_OR) == COMPLEXREGION);
100 DeleteObject(hOldObj);
101 RTEST((UINT_PTR)SelectObject(hDC, hNewObj) == SIMPLEREGION); // ??? Why this?
102 DeleteObject(hNewObj);
103 // TEST(IsHandleValid(hNewObj) == TRUE);
104
105 RTEST(GetLastError() == ERROR_SUCCESS);
106
107 /* Test BITMAP */
108 hNewObj = CreateBitmap(2, 2, 1, 1, &bmBits);
109 ok(hNewObj != NULL, "CreateBitmap failed. Skipping tests.\n");
110 if (hNewObj == NULL) return;
111 hOldObj = SelectObject(hDC, hNewObj);
112 RTEST(GDI_HANDLE_GET_TYPE(hOldObj) == GDI_OBJECT_TYPE_BITMAP);
113 hOldObj = SelectObject(hDC, hOldObj);
114 RTEST(hOldObj == hNewObj);
115
116 /* Test invalid BITMAP */
117 hNewObj = CreateBitmap(2, 2, 1, 4, &bmBits);
118 ok(hNewObj != NULL, "CreateBitmap failed. Skipping tests.\n");
119 if (hNewObj == NULL) return;
120 hOldObj = SelectObject(hDC, hNewObj);
121 ok(hOldObj == NULL, "should fail\n");
122
123 /* Test CLIOBJ */
124
125 /* Test PATH */
126
127 /* Test PALETTE */
128 SetLastError(ERROR_SUCCESS);
129 hNewObj = GetStockObject(DEFAULT_PALETTE);
130 hOldObj = SelectObject(hDC, hNewObj);
131 RTEST(hOldObj == NULL);
132 RTEST(GetLastError() == ERROR_INVALID_FUNCTION);
133
134 /* Test COLORSPACE */
135
136 /* Test FONT */
137
138 /* Test PFE */
139
140 /* Test BRUSH */
141 hNewObj = GetStockObject(GRAY_BRUSH);
142 hOldObj = SelectObject(hDC, hNewObj);
143 RTEST(hOldObj == GetStockObject(WHITE_BRUSH));
144 // RTEST(pDc_Attr->hbrush == hNewObj);
145 RTEST(GDI_HANDLE_GET_TYPE(hOldObj) == GDI_OBJECT_TYPE_BRUSH);
146 SelectObject(hDC, hOldObj);
147
148 /* Test DC_BRUSH */
149 hNewObj = GetStockObject(DC_BRUSH);
150 hOldObj = SelectObject(hDC, hNewObj);
151 // RTEST(pDc_Attr->hbrush == hNewObj);
152 SelectObject(hDC, hOldObj);
153
154 /* Test BRUSH color xform */
155 // hcmXform = (HANDLE)pDc_Attr->hcmXform;
156
157
158 /* Test EMF */
159
160 /* test METAFILE */
161
162 /* Test ENHMETAFILE */
163
164 /* Test PEN */
165 hNewObj = GetStockObject(GRAY_BRUSH);
166 hOldObj = SelectObject(hDC, hNewObj);
167 RTEST(hOldObj == GetStockObject(WHITE_BRUSH));
168 // RTEST(pDc_Attr->hbrush == hNewObj);
169 RTEST(GDI_HANDLE_GET_TYPE(hOldObj) == GDI_OBJECT_TYPE_BRUSH);
170 SelectObject(hDC, hOldObj);
171
172
173 /* Test EXTPEN */
174
175 /* Test METADC */
176 }
177
178 START_TEST(SelectObject)
179 {
180 Test_SelectObject();
181 }
182