[SPIDER]
[reactos.git] / rostests / apitests / gdi32 / GetCurrentObject.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for GetCurrentObject
5 * PROGRAMMERS: Timo Kreuzer
6 */
7
8 #include <apitest.h>
9
10 #include <wingdi.h>
11 #include <winddi.h>
12 #include <winuser.h>
13 #include <include/ntgdityp.h>
14 #include <include/ntgdihdl.h>
15
16 void Test_GetCurrentObject()
17 {
18 HWND hWnd;
19 HDC hDC;
20 HBITMAP hBmp;
21 HGDIOBJ hObj;
22
23 /* Create a window */
24 hWnd = CreateWindowW(L"BUTTON", L"TestWindow", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
25 CW_USEDEFAULT, CW_USEDEFAULT, 100, 100,
26 NULL, NULL, 0, 0);
27 /* Get the DC */
28 hDC = GetDC(hWnd);
29
30 /* Test NULL DC */
31 SetLastError(ERROR_SUCCESS);
32 hObj = GetCurrentObject(NULL, 0);
33 ok(hObj == 0, "Expected 0, got %p\n", hObj);
34 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
35
36 SetLastError(ERROR_SUCCESS);
37 hObj = GetCurrentObject(NULL, OBJ_BITMAP);
38 ok(hObj == 0, "Expected 0, got %p\n", hObj);
39 hObj = GetCurrentObject(NULL, OBJ_BRUSH);
40 ok(hObj == 0, "Expected 0, got %p\n", hObj);
41 hObj = GetCurrentObject(NULL, OBJ_COLORSPACE);
42 ok(hObj == 0, "Expected 0, got %p\n", hObj);
43 hObj = GetCurrentObject(NULL, OBJ_FONT);
44 ok(hObj == 0, "Expected 0, got %p\n", hObj);
45 hObj = GetCurrentObject(NULL, OBJ_PAL);
46 ok(hObj == 0, "Expected 0, got %p\n", hObj);
47 hObj = GetCurrentObject(NULL, OBJ_PEN);
48 ok(hObj == 0, "Expected 0, got %p\n", hObj);
49 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
50
51 /* Test invalid DC handle */
52 SetLastError(ERROR_SUCCESS);
53 hObj = GetCurrentObject((HDC)-123, OBJ_PEN);
54 ok(hObj == 0, "Expected 0, got %p\n", hObj);
55 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
56
57 SetLastError(ERROR_SUCCESS);
58 hObj = GetCurrentObject((HDC)-123, OBJ_BITMAP);
59 ok(hObj == 0, "Expected 0, got %p\n", hObj);
60 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
61
62 /* Test invalid types */
63 SetLastError(ERROR_SUCCESS);
64 hObj = GetCurrentObject(hDC, 0);
65 ok(hObj == 0, "Expected 0, got %p\n", hObj);
66 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
67
68 SetLastError(ERROR_SUCCESS);
69 hObj = GetCurrentObject((HDC)-123, 0);
70 ok(hObj == 0, "Expected 0, got %p\n", hObj);
71 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
72
73 SetLastError(ERROR_SUCCESS);
74 hObj = GetCurrentObject(hDC, 3);
75 ok(hObj == 0, "Expected 0, got %p\n", hObj);
76 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
77
78 SetLastError(ERROR_SUCCESS);
79 hObj = GetCurrentObject(NULL, 3);
80 ok(hObj == 0, "Expected 0, got %p\n", hObj);
81 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
82
83 SetLastError(ERROR_SUCCESS);
84 hObj = GetCurrentObject(hDC, 4);
85 ok(hObj == 0, "Expected 0, got %p\n", hObj);
86 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
87
88 SetLastError(ERROR_SUCCESS);
89 hObj = GetCurrentObject(hDC, 8);
90 ok(hObj == 0, "Expected 0, got %p\n", hObj);
91 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
92
93 SetLastError(ERROR_SUCCESS);
94 hObj = GetCurrentObject(hDC, 9);
95 ok(hObj == 0, "Expected 0, got %p\n", hObj);
96 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
97
98 SetLastError(ERROR_SUCCESS);
99 hObj = GetCurrentObject(hDC, 10);
100 ok(hObj == 0, "Expected 0, got %p\n", hObj);
101 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
102
103 SetLastError(ERROR_SUCCESS);
104 hObj = GetCurrentObject(hDC, 12);
105 ok(hObj == 0, "Expected 0, got %p\n", hObj);
106 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
107
108 SetLastError(ERROR_SUCCESS);
109 hObj = GetCurrentObject(hDC, 13);
110 ok(hObj == 0, "Expected 0, got %p\n", hObj);
111 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
112
113 /* Default bitmap */
114 SetLastError(ERROR_SUCCESS);
115 hBmp = GetCurrentObject(hDC, OBJ_BITMAP);
116 ok(GDI_HANDLE_GET_TYPE(hBmp) == GDI_OBJECT_TYPE_BITMAP, "Expected GDI_OBJECT_TYPE_BITMAP, got %lu\n", GDI_HANDLE_GET_TYPE(hBmp));
117 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
118
119 /* Other bitmap */
120 SetLastError(ERROR_SUCCESS);
121 SelectObject(hDC, GetStockObject(21));
122 ok(hBmp == GetCurrentObject(hDC, OBJ_BITMAP), "\n");
123 ok(GDI_HANDLE_GET_TYPE(hBmp) == GDI_OBJECT_TYPE_BITMAP, "Expected GDI_OBJECT_TYPE_BITMAP, got %lu\n", GDI_HANDLE_GET_TYPE(hBmp));
124 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
125
126 /* Default brush */
127 SetLastError(ERROR_SUCCESS);
128 hObj = GetCurrentObject(hDC, OBJ_BRUSH);
129 ok(hObj == GetStockObject(WHITE_BRUSH), "Expected %p, got %p\n", GetStockObject(WHITE_BRUSH), hObj);
130 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
131
132 /* Other brush */
133 SetLastError(ERROR_SUCCESS);
134 SelectObject(hDC, GetStockObject(BLACK_BRUSH));
135 hObj = GetCurrentObject(hDC, OBJ_BRUSH);
136 ok(hObj == GetStockObject(BLACK_BRUSH), "Expected %p, got %p\n", GetStockObject(BLACK_BRUSH), hObj);
137 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
138
139 /* Default colorspace */
140 SetLastError(ERROR_SUCCESS);
141 hObj = GetCurrentObject(hDC, OBJ_COLORSPACE);
142 ok(hObj == GetStockObject(20), "Expected %p, got %p\n", GetStockObject(20), hObj);
143 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
144
145 /* Default font */
146 SetLastError(ERROR_SUCCESS);
147 hObj = GetCurrentObject(hDC, OBJ_FONT);
148 ok(hObj == GetStockObject(SYSTEM_FONT), "Expected %p, got %p\n", GetStockObject(SYSTEM_FONT), hObj);
149 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
150
151 /* Other font */
152 SetLastError(ERROR_SUCCESS);
153 SelectObject(hDC, GetStockObject(DEFAULT_GUI_FONT));
154 hObj = GetCurrentObject(hDC, OBJ_FONT);
155 ok(hObj == GetStockObject(DEFAULT_GUI_FONT), "Expected %p, got %p\n", GetStockObject(DEFAULT_GUI_FONT), hObj);
156 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
157
158 /* Default palette */
159 SetLastError(ERROR_SUCCESS);
160 hObj = GetCurrentObject(hDC, OBJ_PAL);
161 ok(hObj == GetStockObject(DEFAULT_PALETTE), "Expected %p, got %p\n", GetStockObject(DEFAULT_PALETTE), hObj);
162 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
163
164 /* Default pen */
165 SetLastError(ERROR_SUCCESS);
166 hObj = GetCurrentObject(hDC, OBJ_PEN);
167 ok(hObj == GetStockObject(BLACK_PEN), "Expected %p, got %p\n", GetStockObject(BLACK_PEN), hObj);
168 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
169
170 /* Other pen */
171 SetLastError(ERROR_SUCCESS);
172 SelectObject(hDC, GetStockObject(WHITE_PEN));
173 hObj = GetCurrentObject(hDC, OBJ_PEN);
174 ok(hObj == GetStockObject(WHITE_PEN), "Expected %p, got %p\n", GetStockObject(WHITE_PEN), hObj);
175 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
176
177 /* DC pen */
178 SetLastError(ERROR_SUCCESS);
179 SelectObject(hDC, GetStockObject(DC_PEN));
180 hObj = GetCurrentObject(hDC, OBJ_PEN);
181 ok(hObj == GetStockObject(DC_PEN), "Expected %p, got %p\n", GetStockObject(DC_PEN), hObj);
182 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
183
184 ReleaseDC(hWnd, hDC);
185 DestroyWindow(hWnd);
186 }
187
188 START_TEST(GetCurrentObject)
189 {
190 Test_GetCurrentObject();
191 }
192