Create a branch for Thomas Faber's work on creating a kernel mode test suite for...
[reactos.git] / 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 <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 void Test_GetCurrentObject()
16 {
17 HWND hWnd;
18 HDC hDC;
19 HBITMAP hBmp;
20 HGDIOBJ hObj;
21
22 /* Create a window */
23 hWnd = CreateWindowW(L"BUTTON", L"TestWindow", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
24 CW_USEDEFAULT, CW_USEDEFAULT, 100, 100,
25 NULL, NULL, 0, 0);
26 /* Get the DC */
27 hDC = GetDC(hWnd);
28
29 /* Test NULL DC */
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());
34
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());
49
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());
55
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());
60
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());
66
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());
71
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());
76
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());
81
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());
86
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());
91
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());
96
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());
101
102 /* Default bitmap */
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());
107
108 /* Other bitmap */
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());
114
115 /* Default brush */
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());
120
121 /* Other brush */
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());
127
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());
133
134 /* Default font */
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());
139
140 /* Other font */
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());
146
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());
152
153 /* Default pen */
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());
158
159 /* Other pen */
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());
165
166 /* DC pen */
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());
172
173 ReleaseDC(hWnd, hDC);
174 DestroyWindow(hWnd);
175 }
176
177 START_TEST(GetCurrentObject)
178 {
179 Test_GetCurrentObject();
180 }
181