2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for SelectObject
5 * PROGRAMMERS: Timo Kreuzer
15 HGDIOBJ hOldObj
, hNewObj
;
16 // PGDI_TABLE_ENTRY pEntry;
20 /* Get the Dc_Attr for later testing */
21 // pEntry = &GdiHandleTable[GDI_HANDLE_GET_INDEX(hdc1)];
22 // pDc_Attr = pEntry->UserData;
23 // ok(pDc_Attr != NULL, "Skipping tests.\n");
24 // if (pDc_Attr == NULL) return;
26 /* Test incomplete dc handle doesn't work */
27 SetLastError(ERROR_SUCCESS
);
28 hNewObj
= GetStockObject(GRAY_BRUSH
);
29 hOldObj
= SelectObject((HDC
)GDI_HANDLE_GET_INDEX(hdc1
), hNewObj
);
30 ok_err(ERROR_INVALID_HANDLE
);
31 ok(hOldObj
== NULL
, "\n");
32 // ok(pDc_Attr->hbrush == GetStockObject(WHITE_BRUSH), "\n");
33 SelectObject(hdc1
, hOldObj
);
35 /* Test incomplete hobj handle works */
36 hNewObj
= GetStockObject(GRAY_BRUSH
);
37 hOldObj
= SelectObject(hdc1
, (HGDIOBJ
)GDI_HANDLE_GET_INDEX(hNewObj
));
38 ok(hOldObj
== GetStockObject(WHITE_BRUSH
), "\n");
39 // ok(pDc_Attr->hbrush == hNewObj, "\n");
40 SelectObject(hdc1
, hOldObj
);
42 /* Test wrong hDC handle type */
43 SetLastError(ERROR_SUCCESS
);
44 hNewObj
= GetStockObject(GRAY_BRUSH
);
45 hdc2
= (HDC
)((UINT_PTR
)hdc1
& ~GDI_HANDLE_TYPE_MASK
);
46 hdc2
= (HDC
)((UINT_PTR
)hdc2
| GDI_OBJECT_TYPE_PEN
);
47 hOldObj
= SelectObject(hdc2
, hNewObj
);
48 ok_err(ERROR_INVALID_HANDLE
);
49 ok(hOldObj
== NULL
, "\n");
50 // RTEST(pDc_Attr->hbrush == GetStockObject(WHITE_BRUSH));
52 /* Test wrong hobj handle type */
53 SetLastError(ERROR_SUCCESS
);
54 hNewObj
= GetStockObject(GRAY_BRUSH
);
55 hNewObj
= (HGDIOBJ
)((UINT_PTR
)hNewObj
& ~GDI_HANDLE_TYPE_MASK
);
56 hNewObj
= (HGDIOBJ
)((UINT_PTR
)hNewObj
| GDI_OBJECT_TYPE_PEN
);
57 hOldObj
= SelectObject(hdc1
, hNewObj
);
58 ok_err(ERROR_SUCCESS
);
59 ok(hOldObj
== NULL
, "\n");
60 // RTEST(pDc_Attr->hbrush == GetStockObject(WHITE_BRUSH));
62 SetLastError(ERROR_SUCCESS
);
63 hNewObj
= (HGDIOBJ
)0x00761234;
64 hOldObj
= SelectObject(hdc1
, hNewObj
);
65 ok(hOldObj
== NULL
, "\n");
66 ok_err(ERROR_SUCCESS
);
67 SelectObject(hdc1
, hOldObj
);
70 SetLastError(ERROR_SUCCESS
);
71 hOldObj
= SelectObject(hdc1
, GetDC(NULL
));
72 ok(hOldObj
== NULL
, "\n");
73 ok_err(ERROR_SUCCESS
);
81 SetLastError(ERROR_SUCCESS
);
82 hNewObj
= GetStockObject(DEFAULT_PALETTE
);
83 hOldObj
= SelectObject(hdc1
, hNewObj
);
84 RTEST(hOldObj
== NULL
);
85 ok_err(ERROR_INVALID_FUNCTION
);
94 hNewObj
= GetStockObject(GRAY_BRUSH
);
95 hOldObj
= SelectObject(hdc1
, hNewObj
);
96 RTEST(hOldObj
== GetStockObject(WHITE_BRUSH
));
97 // RTEST(pDc_Attr->hbrush == hNewObj);
98 RTEST(GDI_HANDLE_GET_TYPE(hOldObj
) == GDI_OBJECT_TYPE_BRUSH
);
99 SelectObject(hdc1
, hOldObj
);
102 hNewObj
= GetStockObject(DC_BRUSH
);
103 hOldObj
= SelectObject(hdc1
, hNewObj
);
104 // RTEST(pDc_Attr->hbrush == hNewObj);
105 SelectObject(hdc1
, hOldObj
);
107 /* Test BRUSH color xform */
108 // hcmXform = (HANDLE)pDc_Attr->hcmXform;
114 SetLastError(ERROR_SUCCESS
);
115 hNewObj
= CreateMetaFile(NULL
);
116 ok(hNewObj
!= 0, "failed to create a meta dc\n");
117 hOldObj
= SelectObject(hdc1
, hNewObj
);
118 RTEST(hOldObj
== NULL
);
119 ok_err(ERROR_SUCCESS
);
121 /* Test ENHMETAFILE */
131 HBITMAP hbmp
, hbmpInvalid
, hbmpOld
;
132 BYTE bmBits
[4] = {0};
135 hbmp
= CreateBitmap(2, 2, 1, 1, &bmBits
);
136 hbmpInvalid
= CreateBitmap(2, 2, 1, 4, &bmBits
);
137 if (!hbmp
|| !hbmpInvalid
)
139 printf("couldn't create bitmaps, skipping\n");
143 hbmpOld
= SelectObject(hdc1
, hbmp
);
144 ok(GDI_HANDLE_GET_TYPE(hbmpOld
) == GDI_OBJECT_TYPE_BITMAP
, "wrong type\n");
146 /* Test invalid BITMAP */
147 ok(SelectObject(hdc1
, hbmpInvalid
) == NULL
, "should fail\n");
149 /* Test if we get the right bitmap back */
150 hbmpOld
= SelectObject(hdc1
, hbmpOld
);
151 ok(hbmpOld
== hbmp
, "didn't get the right bitmap back.\n");
153 /* Test selecting bitmap into 2 DCs */
154 hbmpOld
= SelectObject(hdc1
, hbmp
);
155 ok(SelectObject(hdc2
, hbmp
) == NULL
, "Should fail.\n");
157 /* Test selecting same bitmap twice */
158 hbmpOld
= SelectObject(hdc1
, hbmp
);
159 ok(hbmpOld
== hbmp
, "didn't get the right bitmap back.\n");
160 SelectObject(hdc1
, GetStockObject(DEFAULT_BITMAP
));
162 /* Test selecting and then deleting the DC */
163 hdcTmp
= CreateCompatibleDC(NULL
);
164 hbmpOld
= SelectObject(hdcTmp
, hbmp
);
165 ok(hbmpOld
== GetStockObject(DEFAULT_BITMAP
), "didn't get the right bitmap back.\n");
167 hbmpOld
= SelectObject(hdc1
, hbmp
);
168 ok(hbmpOld
== GetStockObject(DEFAULT_BITMAP
), "didn't get the right bitmap back.\n");
171 DeleteObject(hbmpInvalid
);
180 hpen
= GetStockObject(GRAY_BRUSH
);
181 hpenOld
= SelectObject(hdc1
, hpen
);
182 ok(hpenOld
== GetStockObject(WHITE_BRUSH
), "Got wrong pen.\n");
183 // RTEST(pDc_Attr->hbrush == hpen);
184 ok(GDI_HANDLE_GET_TYPE(hpenOld
) == GDI_OBJECT_TYPE_BRUSH
, "wrong type.\n");
185 SelectObject(hdc1
, hpenOld
);
194 SetLastError(ERROR_SUCCESS
);
195 hrgn
= CreateRectRgn(0,0,0,0);
196 hrgnOld
= SelectObject(hdc1
, hrgn
);
197 ok((UINT_PTR
)hrgnOld
== NULLREGION
, "\n");
200 hrgn
= CreateRectRgn(0,0,10,10);
201 ok((UINT_PTR
)SelectObject(hdc1
, hrgn
) == SIMPLEREGION
, "\n");
202 hrgnOld
= CreateRectRgn(5,5,20,20);
203 ok(CombineRgn(hrgn
, hrgn
, hrgnOld
, RGN_OR
) == COMPLEXREGION
, "\n");
204 DeleteObject(hrgnOld
);
205 ok((UINT_PTR
)SelectObject(hdc1
, hrgn
) == SIMPLEREGION
, "\n"); // ??? Why this?
207 // ok(IsHandleValid(hrgn) == TRUE, "\n");
208 ok_err(ERROR_SUCCESS
);
211 START_TEST(SelectObject
)
213 hdc1
= CreateCompatibleDC(NULL
);
214 hdc2
= CreateCompatibleDC(NULL
);
217 printf("couldn't create DCs, skipping all tests\n");