Fix copy paste error in file header
[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)
16 #define RTEST(x) ok(x, #x)
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 CLIOBJ */
117
118 /* Test PATH */
119
120 /* Test PALETTE */
121 SetLastError(ERROR_SUCCESS);
122 hNewObj = GetStockObject(DEFAULT_PALETTE);
123 hOldObj = SelectObject(hDC, hNewObj);
124 RTEST(hOldObj == NULL);
125 RTEST(GetLastError() == ERROR_INVALID_FUNCTION);
126
127 /* Test COLORSPACE */
128
129 /* Test FONT */
130
131 /* Test PFE */
132
133 /* Test BRUSH */
134 hNewObj = GetStockObject(GRAY_BRUSH);
135 hOldObj = SelectObject(hDC, hNewObj);
136 RTEST(hOldObj == GetStockObject(WHITE_BRUSH));
137 // RTEST(pDc_Attr->hbrush == hNewObj);
138 RTEST(GDI_HANDLE_GET_TYPE(hOldObj) == GDI_OBJECT_TYPE_BRUSH);
139 SelectObject(hDC, hOldObj);
140
141 /* Test DC_BRUSH */
142 hNewObj = GetStockObject(DC_BRUSH);
143 hOldObj = SelectObject(hDC, hNewObj);
144 // RTEST(pDc_Attr->hbrush == hNewObj);
145 SelectObject(hDC, hOldObj);
146
147 /* Test BRUSH color xform */
148 // hcmXform = (HANDLE)pDc_Attr->hcmXform;
149
150
151 /* Test EMF */
152
153 /* test METAFILE */
154
155 /* Test ENHMETAFILE */
156
157 /* Test PEN */
158 hNewObj = GetStockObject(GRAY_BRUSH);
159 hOldObj = SelectObject(hDC, hNewObj);
160 RTEST(hOldObj == GetStockObject(WHITE_BRUSH));
161 // RTEST(pDc_Attr->hbrush == hNewObj);
162 RTEST(GDI_HANDLE_GET_TYPE(hOldObj) == GDI_OBJECT_TYPE_BRUSH);
163 SelectObject(hDC, hOldObj);
164
165
166 /* Test EXTPEN */
167
168 /* Test METADC */
169 }
170
171 START_TEST(SelectObject)
172 {
173 Test_SelectObject();
174 }
175