2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for GetCurrentObject
5 * PROGRAMMERS: Timo Kreuzer
12 #include <reactos/win32k/ntgdityp.h>
13 #include <reactos/win32k/ntgdihdl.h>
15 void Test_GetCurrentObject()
23 hWnd
= CreateWindowW(L
"BUTTON", L
"TestWindow", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
24 CW_USEDEFAULT
, CW_USEDEFAULT
, 100, 100,
30 SetLastError(ERROR_SUCCESS
);
31 hObj
= GetCurrentObject(NULL
, 0);
32 ok(hObj
== 0, "Expected 0, got %p\n", hObj
);
33 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
35 SetLastError(ERROR_SUCCESS
);
36 hObj
= GetCurrentObject(NULL
, OBJ_BITMAP
);
37 ok(hObj
== 0, "Expected 0, got %p\n", hObj
);
38 hObj
= GetCurrentObject(NULL
, OBJ_BRUSH
);
39 ok(hObj
== 0, "Expected 0, got %p\n", hObj
);
40 hObj
= GetCurrentObject(NULL
, OBJ_COLORSPACE
);
41 ok(hObj
== 0, "Expected 0, got %p\n", hObj
);
42 hObj
= GetCurrentObject(NULL
, OBJ_FONT
);
43 ok(hObj
== 0, "Expected 0, got %p\n", hObj
);
44 hObj
= GetCurrentObject(NULL
, OBJ_PAL
);
45 ok(hObj
== 0, "Expected 0, got %p\n", hObj
);
46 hObj
= GetCurrentObject(NULL
, OBJ_PEN
);
47 ok(hObj
== 0, "Expected 0, got %p\n", hObj
);
48 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
50 /* Test invalid DC handle */
51 SetLastError(ERROR_SUCCESS
);
52 hObj
= GetCurrentObject((HDC
)-123, 0);
53 ok(hObj
== 0, "Expected 0, got %p\n", hObj
);
54 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
56 SetLastError(ERROR_SUCCESS
);
57 hObj
= GetCurrentObject((HDC
)-123, OBJ_BITMAP
);
58 ok(hObj
== 0, "Expected 0, got %p\n", hObj
);
59 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
61 /* Test invalid types */
62 SetLastError(ERROR_SUCCESS
);
63 hObj
= GetCurrentObject(hDC
, 0);
64 ok(hObj
== 0, "Expected 0, got %p\n", hObj
);
65 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
67 SetLastError(ERROR_SUCCESS
);
68 hObj
= GetCurrentObject(hDC
, 3);
69 ok(hObj
== 0, "Expected 0, got %p\n", hObj
);
70 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
72 SetLastError(ERROR_SUCCESS
);
73 hObj
= GetCurrentObject(hDC
, 4);
74 ok(hObj
== 0, "Expected 0, got %p\n", hObj
);
75 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
77 SetLastError(ERROR_SUCCESS
);
78 hObj
= GetCurrentObject(hDC
, 8);
79 ok(hObj
== 0, "Expected 0, got %p\n", hObj
);
80 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
82 SetLastError(ERROR_SUCCESS
);
83 hObj
= GetCurrentObject(hDC
, 9);
84 ok(hObj
== 0, "Expected 0, got %p\n", hObj
);
85 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
87 SetLastError(ERROR_SUCCESS
);
88 hObj
= GetCurrentObject(hDC
, 10);
89 ok(hObj
== 0, "Expected 0, got %p\n", hObj
);
90 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
92 SetLastError(ERROR_SUCCESS
);
93 hObj
= GetCurrentObject(hDC
, 12);
94 ok(hObj
== 0, "Expected 0, got %p\n", hObj
);
95 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
97 SetLastError(ERROR_SUCCESS
);
98 hObj
= GetCurrentObject(hDC
, 13);
99 ok(hObj
== 0, "Expected 0, got %p\n", hObj
);
100 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
103 SetLastError(ERROR_SUCCESS
);
104 hBmp
= GetCurrentObject(hDC
, OBJ_BITMAP
);
105 ok(GDI_HANDLE_GET_TYPE(hBmp
) == GDI_OBJECT_TYPE_BITMAP
, "Expected GDI_OBJECT_TYPE_BITMAP, got %lu\n", GDI_HANDLE_GET_TYPE(hBmp
));
106 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
109 SetLastError(ERROR_SUCCESS
);
110 SelectObject(hDC
, GetStockObject(21));
111 ok(hBmp
== GetCurrentObject(hDC
, OBJ_BITMAP
), "\n");
112 ok(GDI_HANDLE_GET_TYPE(hBmp
) == GDI_OBJECT_TYPE_BITMAP
, "Expected GDI_OBJECT_TYPE_BITMAP, got %lu\n", GDI_HANDLE_GET_TYPE(hBmp
));
113 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
116 SetLastError(ERROR_SUCCESS
);
117 hObj
= GetCurrentObject(hDC
, OBJ_BRUSH
);
118 ok(hObj
== GetStockObject(WHITE_BRUSH
), "Expected %p, got %p\n", GetStockObject(WHITE_BRUSH
), hObj
);
119 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
122 SetLastError(ERROR_SUCCESS
);
123 SelectObject(hDC
, GetStockObject(BLACK_BRUSH
));
124 hObj
= GetCurrentObject(hDC
, OBJ_BRUSH
);
125 ok(hObj
== GetStockObject(BLACK_BRUSH
), "Expected %p, got %p\n", GetStockObject(BLACK_BRUSH
), hObj
);
126 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
128 /* Default colorspace */
129 SetLastError(ERROR_SUCCESS
);
130 hObj
= GetCurrentObject(hDC
, OBJ_COLORSPACE
);
131 ok(hObj
== GetStockObject(20), "Expected %p, got %p\n", GetStockObject(20), hObj
);
132 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
135 SetLastError(ERROR_SUCCESS
);
136 hObj
= GetCurrentObject(hDC
, OBJ_FONT
);
137 ok(hObj
== GetStockObject(SYSTEM_FONT
), "Expected %p, got %p\n", GetStockObject(SYSTEM_FONT
), hObj
);
138 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
141 SetLastError(ERROR_SUCCESS
);
142 SelectObject(hDC
, GetStockObject(DEFAULT_GUI_FONT
));
143 hObj
= GetCurrentObject(hDC
, OBJ_FONT
);
144 ok(hObj
== GetStockObject(DEFAULT_GUI_FONT
), "Expected %p, got %p\n", GetStockObject(DEFAULT_GUI_FONT
), hObj
);
145 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
147 /* Default palette */
148 SetLastError(ERROR_SUCCESS
);
149 hObj
= GetCurrentObject(hDC
, OBJ_PAL
);
150 ok(hObj
== GetStockObject(DEFAULT_PALETTE
), "Expected %p, got %p\n", GetStockObject(DEFAULT_PALETTE
), hObj
);
151 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
154 SetLastError(ERROR_SUCCESS
);
155 hObj
= GetCurrentObject(hDC
, OBJ_PEN
);
156 ok(hObj
== GetStockObject(BLACK_PEN
), "Expected %p, got %p\n", GetStockObject(BLACK_PEN
), hObj
);
157 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
160 SetLastError(ERROR_SUCCESS
);
161 SelectObject(hDC
, GetStockObject(WHITE_PEN
));
162 hObj
= GetCurrentObject(hDC
, OBJ_PEN
);
163 ok(hObj
== GetStockObject(WHITE_PEN
), "Expected %p, got %p\n", GetStockObject(WHITE_PEN
), hObj
);
164 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
167 SetLastError(ERROR_SUCCESS
);
168 SelectObject(hDC
, GetStockObject(DC_PEN
));
169 hObj
= GetCurrentObject(hDC
, OBJ_PEN
);
170 ok(hObj
== GetStockObject(DC_PEN
), "Expected %p, got %p\n", GetStockObject(DC_PEN
), hObj
);
171 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
173 ReleaseDC(hWnd
, hDC
);
177 START_TEST(GetCurrentObject
)
179 Test_GetCurrentObject();