ReactOS 0.4.16-dev-303-g11d5cb8
GetCurrentObject.c
Go to the documentation of this file.
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 "precomp.h"
9
11{
12 HWND hWnd;
13 HDC hDC;
14 HBITMAP hBmp;
15 HGDIOBJ hObj;
16
17 /* Create a window */
18 hWnd = CreateWindowW(L"BUTTON", L"TestWindow", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
20 NULL, NULL, 0, 0);
21 /* Get the DC */
22 hDC = GetDC(hWnd);
23
24 /* Test NULL DC */
26 hObj = GetCurrentObject(NULL, 0);
27 ok(hObj == 0, "Expected 0, got %p\n", hObj);
28 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
29
32 ok(hObj == 0, "Expected 0, got %p\n", hObj);
34 ok(hObj == 0, "Expected 0, got %p\n", hObj);
36 ok(hObj == 0, "Expected 0, got %p\n", hObj);
38 ok(hObj == 0, "Expected 0, got %p\n", hObj);
40 ok(hObj == 0, "Expected 0, got %p\n", hObj);
42 ok(hObj == 0, "Expected 0, got %p\n", hObj);
43 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
44
45 /* Test invalid DC handle */
47 hObj = GetCurrentObject((HDC)-123, 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
52 hObj = GetCurrentObject((HDC)-123, OBJ_BITMAP);
53 ok(hObj == 0, "Expected 0, got %p\n", hObj);
54 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
55
56 /* Test invalid types */
58 hObj = GetCurrentObject(hDC, 0);
59 ok(hObj == 0, "Expected 0, got %p\n", hObj);
60 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
61
63 hObj = GetCurrentObject((HDC)-123, 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
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
73 hObj = GetCurrentObject(NULL, 3);
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
78 hObj = GetCurrentObject(hDC, 4);
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
83 hObj = GetCurrentObject(hDC, 8);
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
88 hObj = GetCurrentObject(hDC, 9);
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
93 hObj = GetCurrentObject(hDC, 10);
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
98 hObj = GetCurrentObject(hDC, 12);
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
103 hObj = GetCurrentObject(hDC, 13);
104 ok(hObj == 0, "Expected 0, got %p\n", hObj);
105 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
106
107 /* Default bitmap */
110 ok(GDI_HANDLE_GET_TYPE(hBmp) == GDI_OBJECT_TYPE_BITMAP, "Expected GDI_OBJECT_TYPE_BITMAP, got %lu\n", GDI_HANDLE_GET_TYPE(hBmp));
111 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
112
113 /* Other bitmap */
116 ok(hBmp == GetCurrentObject(hDC, OBJ_BITMAP), "\n");
117 ok(GDI_HANDLE_GET_TYPE(hBmp) == GDI_OBJECT_TYPE_BITMAP, "Expected GDI_OBJECT_TYPE_BITMAP, got %lu\n", GDI_HANDLE_GET_TYPE(hBmp));
118 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
119
120 /* Default brush */
123 ok(hObj == GetStockObject(WHITE_BRUSH), "Expected %p, got %p\n", GetStockObject(WHITE_BRUSH), hObj);
124 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
125
126 /* Other brush */
130 ok(hObj == GetStockObject(BLACK_BRUSH), "Expected %p, got %p\n", GetStockObject(BLACK_BRUSH), hObj);
131 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
132
133 /* Default colorspace */
136 ok(hObj == GetStockObject(20), "Expected %p, got %p\n", GetStockObject(20), hObj);
137 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
138
139 /* Default font */
142 ok(hObj == GetStockObject(SYSTEM_FONT), "Expected %p, got %p\n", GetStockObject(SYSTEM_FONT), hObj);
143 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
144
145 /* Other font */
149 ok(hObj == GetStockObject(DEFAULT_GUI_FONT), "Expected %p, got %p\n", GetStockObject(DEFAULT_GUI_FONT), hObj);
150 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
151
152 /* Default palette */
155 ok(hObj == GetStockObject(DEFAULT_PALETTE), "Expected %p, got %p\n", GetStockObject(DEFAULT_PALETTE), hObj);
156 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
157
158 /* Default pen */
161 ok(hObj == GetStockObject(BLACK_PEN), "Expected %p, got %p\n", GetStockObject(BLACK_PEN), hObj);
162 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
163
164 /* Other pen */
168 ok(hObj == GetStockObject(WHITE_PEN), "Expected %p, got %p\n", GetStockObject(WHITE_PEN), hObj);
169 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
170
171 /* DC pen */
175 ok(hObj == GetStockObject(DC_PEN), "Expected %p, got %p\n", GetStockObject(DC_PEN), hObj);
176 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
177
180}
181
183{
185}
186
static HDC hDC
Definition: 3dtext.c:33
void Test_GetCurrentObject()
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
HWND hWnd
Definition: settings.c:17
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
#define GDI_HANDLE_GET_TYPE(h)
Definition: gdi.h:31
#define GDI_OBJECT_TYPE_BITMAP
Definition: gdi.h:48
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:88
#define L(x)
Definition: ntvdm.h:50
#define OBJ_PEN
Definition: objidl.idl:1409
#define OBJ_BRUSH
Definition: objidl.idl:1410
#define OBJ_FONT
Definition: objidl.idl:1414
#define OBJ_BITMAP
Definition: objidl.idl:1415
#define OBJ_PAL
Definition: objidl.idl:1413
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
#define WS_VISIBLE
Definition: pedump.c:620
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define DEFAULT_PALETTE
Definition: wingdi.h:913
#define OBJ_COLORSPACE
Definition: wingdi.h:704
HGDIOBJ WINAPI GetCurrentObject(_In_ HDC, _In_ UINT)
Definition: dc.c:428
#define DEFAULT_GUI_FONT
Definition: wingdi.h:909
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1546
#define WHITE_PEN
Definition: wingdi.h:905
#define WHITE_BRUSH
Definition: wingdi.h:902
#define BLACK_PEN
Definition: wingdi.h:903
#define BLACK_BRUSH
Definition: wingdi.h:896
#define SYSTEM_FONT
Definition: wingdi.h:911
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
HDC WINAPI GetDC(_In_opt_ HWND)
#define CreateWindowW(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4319
#define CW_USEDEFAULT
Definition: winuser.h:225
BOOL WINAPI DestroyWindow(_In_ HWND)