ReactOS 0.4.16-dev-311-g9382aa2
SelectObject.c File Reference
#include "precomp.h"
Include dependency graph for SelectObject.c:

Go to the source code of this file.

Functions

static void Test_SelectObject ()
 
static void Test_Bitmap ()
 
static void Test_Pen ()
 
static void Test_Region ()
 
 START_TEST (SelectObject)
 

Variables

HDC hdc1
 
HDC hdc2
 

Function Documentation

◆ START_TEST()

START_TEST ( SelectObject  )

Definition at line 211 of file SelectObject.c.

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}
static void Test_Pen()
Definition: SelectObject.c:175
HDC hdc1
Definition: SelectObject.c:10
static void Test_Region()
Definition: SelectObject.c:189
static void Test_SelectObject()
Definition: SelectObject.c:13
static void Test_Bitmap()
Definition: SelectObject.c:129
HDC hdc2
Definition: SelectObject.c:10
#define NULL
Definition: types.h:112
#define printf
Definition: freeldr.h:97
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)

◆ Test_Bitmap()

static void Test_Bitmap ( void  )
static

Definition at line 129 of file SelectObject.c.

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}
#define ok(value,...)
Definition: atltest.h:57
HBITMAP hbmp
pKey DeleteObject()
#define GDI_HANDLE_GET_TYPE(h)
Definition: gdi.h:31
#define GDI_OBJECT_TYPE_BITMAP
Definition: gdi.h:48
HANDLE hbmpOld
Definition: magnifier.c:54
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:88
#define DEFAULT_BITMAP
Definition: ntgdityp.h:195
HGDIOBJ WINAPI GetStockObject(_In_ int)
HBITMAP WINAPI CreateBitmap(_In_ INT cx, _In_ INT cy, _In_ UINT cPlanes, _In_ UINT cBitsPerPel, _In_opt_ const VOID *pvBits)
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1546
BOOL WINAPI DeleteDC(_In_ HDC)
unsigned char BYTE
Definition: xxhash.c:193

Referenced by START_TEST().

◆ Test_Pen()

static void Test_Pen ( void  )
static

Definition at line 175 of file SelectObject.c.

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}
static HPEN hpen
#define GDI_OBJECT_TYPE_BRUSH
Definition: gdi.h:52
#define WHITE_BRUSH
Definition: wingdi.h:902
#define GRAY_BRUSH
Definition: wingdi.h:898

Referenced by START_TEST().

◆ Test_Region()

static void Test_Region ( void  )
static

Definition at line 189 of file SelectObject.c.

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}
static HRGN hrgn
#define ok_err(error)
Definition: atltest.h:124
#define ERROR_SUCCESS
Definition: deptool.c:10
#define SetLastError(x)
Definition: compat.h:752
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
#define COMPLEXREGION
Definition: wingdi.h:363
HRGN WINAPI CreateRectRgn(_In_ int, _In_ int, _In_ int, _In_ int)
#define NULLREGION
Definition: wingdi.h:361
int WINAPI CombineRgn(_In_opt_ HRGN hrgnDest, _In_opt_ HRGN hrgnSrc1, _In_opt_ HRGN hrgnSrc2, _In_ int fnCombineMode)
#define SIMPLEREGION
Definition: wingdi.h:362
#define RGN_OR
Definition: wingdi.h:359

Referenced by START_TEST().

◆ Test_SelectObject()

static void Test_SelectObject ( )
static

Definition at line 13 of file SelectObject.c.

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);
45 hdc2 = (HDC)((UINT_PTR)hdc1 & ~GDI_HANDLE_TYPE_MASK);
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}
#define ERROR_INVALID_FUNCTION
Definition: dderror.h:6
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
#define GDI_HANDLE_GET_INDEX(h)
Definition: gdi.h:28
#define GDI_OBJECT_TYPE_PEN
Definition: gdi.h:54
#define RTEST(x)
Definition: precomp.h:21
void * HGDIOBJ
Definition: windef.h:252
#define CreateMetaFile
Definition: wingdi.h:4447
#define DEFAULT_PALETTE
Definition: wingdi.h:913
HDC WINAPI GetDC(_In_opt_ HWND)

Referenced by START_TEST().

Variable Documentation

◆ hdc1

◆ hdc2