ReactOS  0.4.14-dev-614-gbfd8a84
SelectObject.c
Go to the documentation of this file.
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 "precomp.h"
9 
11 
12 static void
14 {
15  HGDIOBJ hOldObj, hNewObj;
16 // PGDI_TABLE_ENTRY pEntry;
17 // PDC_ATTR pDc_Attr;
18 // HANDLE hcmXform;
19 
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;
25 
26  /* Test incomplete dc handle doesn't work */
28  hNewObj = GetStockObject(GRAY_BRUSH);
29  hOldObj = SelectObject((HDC)GDI_HANDLE_GET_INDEX(hdc1), hNewObj);
31  ok(hOldObj == NULL, "\n");
32 // ok(pDc_Attr->hbrush == GetStockObject(WHITE_BRUSH), "\n");
33  SelectObject(hdc1, hOldObj);
34 
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);
41 
42  /* Test wrong hDC handle type */
44  hNewObj = GetStockObject(GRAY_BRUSH);
47  hOldObj = SelectObject(hdc2, hNewObj);
49  ok(hOldObj == NULL, "\n");
50 // RTEST(pDc_Attr->hbrush == GetStockObject(WHITE_BRUSH));
51 
52  /* Test wrong hobj handle type */
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);
59  ok(hOldObj == NULL, "\n");
60 // RTEST(pDc_Attr->hbrush == GetStockObject(WHITE_BRUSH));
61 
63  hNewObj = (HGDIOBJ)0x00761234;
64  hOldObj = SelectObject(hdc1, hNewObj);
65  ok(hOldObj == NULL, "\n");
67  SelectObject(hdc1, hOldObj);
68 
69  /* Test DC */
71  hOldObj = SelectObject(hdc1, GetDC(NULL));
72  ok(hOldObj == NULL, "\n");
74 
75 
76  /* Test CLIOBJ */
77 
78  /* Test PATH */
79 
80  /* Test PALETTE */
83  hOldObj = SelectObject(hdc1, hNewObj);
84  RTEST(hOldObj == NULL);
86 
87  /* Test COLORSPACE */
88 
89  /* Test FONT */
90 
91  /* Test PFE */
92 
93  /* Test BRUSH */
94  hNewObj = GetStockObject(GRAY_BRUSH);
95  hOldObj = SelectObject(hdc1, hNewObj);
96  RTEST(hOldObj == GetStockObject(WHITE_BRUSH));
97 // RTEST(pDc_Attr->hbrush == hNewObj);
99  SelectObject(hdc1, hOldObj);
100 
101  /* Test DC_BRUSH */
102  hNewObj = GetStockObject(DC_BRUSH);
103  hOldObj = SelectObject(hdc1, hNewObj);
104 // RTEST(pDc_Attr->hbrush == hNewObj);
105  SelectObject(hdc1, hOldObj);
106 
107  /* Test BRUSH color xform */
108 // hcmXform = (HANDLE)pDc_Attr->hcmXform;
109 
110 
111  /* Test EMF */
112 
113  /* test METAFILE */
115  hNewObj = CreateMetaFile(NULL);
116  ok(hNewObj != 0, "failed to create a meta dc\n");
117  hOldObj = SelectObject(hdc1, hNewObj);
118  RTEST(hOldObj == NULL);
120 
121  /* Test ENHMETAFILE */
122 
123  /* Test EXTPEN */
124 
125  /* Test METADC */
126 }
127 
128 static void
130 {
131  HBITMAP hbmp, hbmpInvalid, hbmpOld;
132  BYTE bmBits[4] = {0};
133  HDC hdcTmp;
134 
135  hbmp = CreateBitmap(2, 2, 1, 1, &bmBits);
136  hbmpInvalid = CreateBitmap(2, 2, 1, 4, &bmBits);
137  if (!hbmp || !hbmpInvalid)
138  {
139  printf("couldn't create bitmaps, skipping\n");
140  return;
141  }
142 
145 
146  /* Test invalid BITMAP */
147  ok(SelectObject(hdc1, hbmpInvalid) == NULL, "should fail\n");
148 
149  /* Test if we get the right bitmap back */
151  ok(hbmpOld == hbmp, "didn't get the right bitmap back.\n");
152 
153  /* Test selecting bitmap into 2 DCs */
155  ok(SelectObject(hdc2, hbmp) == NULL, "Should fail.\n");
156 
157  /* Test selecting same bitmap twice */
159  ok(hbmpOld == hbmp, "didn't get the right bitmap back.\n");
161 
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");
166  DeleteDC(hdcTmp);
168  ok(hbmpOld == GetStockObject(DEFAULT_BITMAP), "didn't get the right bitmap back.\n");
169 
171  DeleteObject(hbmpInvalid);
172 }
173 
174 static void
176 {
177  HPEN hpen, hpenOld;
178 
179  /* Test PEN */
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);
186 }
187 
188 static void
190 {
191  HRGN hrgn, hrgnOld;
192 
193  /* Test REGION */
195  hrgn = CreateRectRgn(0,0,0,0);
196  hrgnOld = SelectObject(hdc1, hrgn);
197  ok((UINT_PTR)hrgnOld == NULLREGION, "\n");
199 
200  hrgn = CreateRectRgn(0,0,10,10);
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");
209 }
210 
212 {
215  if (!hdc1 || !hdc2)
216  {
217  printf("couldn't create DCs, skipping all tests\n");
218  return;
219  }
220 
222  Test_Bitmap();
223  Test_Pen();
224  Test_Region();
225 }
226 
HGDIOBJ WINAPI GetStockObject(_In_ int)
int WINAPI CombineRgn(_In_opt_ HRGN hrgnDest, _In_opt_ HRGN hrgnSrc1, _In_opt_ HRGN hrgnSrc2, _In_ int fnCombineMode)
#define GDI_HANDLE_GET_INDEX(h)
Definition: gdi.h:28
#define ERROR_SUCCESS
Definition: deptool.c:10
HDC WINAPI GetDC(_In_opt_ HWND)
#define ERROR_INVALID_FUNCTION
Definition: dderror.h:6
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
static HDC
Definition: imagelist.c:92
#define COMPLEXREGION
Definition: wingdi.h:362
#define NULLREGION
Definition: wingdi.h:360
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
#define WHITE_BRUSH
Definition: wingdi.h:901
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
static HPEN hpen
HDC hdc2
Definition: SelectObject.c:10
HANDLE hbmpOld
Definition: magnifier.c:54
#define GDI_OBJECT_TYPE_BRUSH
Definition: gdi.h:52
smooth NULL
Definition: ftsmooth.c:416
#define RGN_OR
Definition: wingdi.h:358
HDC hdc1
Definition: SelectObject.c:10
#define GRAY_BRUSH
Definition: wingdi.h:897
#define DEFAULT_BITMAP
Definition: ntgdityp.h:194
static void Test_Region()
Definition: SelectObject.c:189
#define GDI_HANDLE_GET_TYPE(h)
Definition: gdi.h:31
HRGN WINAPI CreateRectRgn(_In_ int, _In_ int, _In_ int, _In_ int)
HBITMAP hbmp
#define DEFAULT_PALETTE
Definition: wingdi.h:912
#define GDI_OBJECT_TYPE_PEN
Definition: gdi.h:54
#define SetLastError(x)
Definition: compat.h:417
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
static HRGN hrgn
Definition: win.c:55
#define GDI_OBJECT_TYPE_BITMAP
Definition: gdi.h:48
START_TEST(SelectObject)
Definition: SelectObject.c:211
unsigned char BYTE
Definition: mem.h:68
#define ok_err(error)
Definition: atltest.h:124
static void Test_Pen()
Definition: SelectObject.c:175
#define CreateMetaFile
Definition: wingdi.h:4446
#define SIMPLEREGION
Definition: wingdi.h:361
static void Test_SelectObject()
Definition: SelectObject.c:13
void * HGDIOBJ
Definition: windef.h:252
BOOL WINAPI DeleteDC(_In_ HDC)
#define ok(value,...)
Definition: atltest.h:57
static void Test_Bitmap()
Definition: SelectObject.c:129
static HBITMAP
Definition: button.c:44
#define GDI_HANDLE_TYPE_MASK
Definition: gdi.h:17
#define printf
Definition: config.h:203
#define RTEST(x)
Definition: precomp.h:21
HBITMAP WINAPI CreateBitmap(_In_ INT cx, _In_ INT cy, _In_ UINT cPlanes, _In_ UINT cBitsPerPel, _In_opt_ const VOID *pvBits)