2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for GetCurrentObject
5 * PROGRAMMERS: Timo Kreuzer
13 #include <include/ntgdityp.h>
14 #include <include/ntgdihdl.h>
16 void Test_GetCurrentObject()
24 hWnd
= CreateWindowW(L
"BUTTON", L
"TestWindow", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
25 CW_USEDEFAULT
, CW_USEDEFAULT
, 100, 100,
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
184 ReleaseDC(hWnd
, hDC
);
188 START_TEST(GetCurrentObject
)
190 Test_GetCurrentObject();