ReactOS  0.4.15-dev-492-ga1108f6
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,
19  CW_USEDEFAULT, CW_USEDEFAULT, 100, 100,
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);
39  hObj = GetCurrentObject(NULL, OBJ_PAL);
40  ok(hObj == 0, "Expected 0, got %p\n", hObj);
41  hObj = GetCurrentObject(NULL, OBJ_PEN);
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 */
122  hObj = GetCurrentObject(hDC, OBJ_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 */
129  hObj = GetCurrentObject(hDC, OBJ_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 */
141  hObj = GetCurrentObject(hDC, OBJ_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 */
148  hObj = GetCurrentObject(hDC, OBJ_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 */
154  hObj = GetCurrentObject(hDC, OBJ_PAL);
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 */
160  hObj = GetCurrentObject(hDC, OBJ_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 */
167  hObj = GetCurrentObject(hDC, OBJ_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 */
173  SelectObject(hDC, GetStockObject(DC_PEN));
174  hObj = GetCurrentObject(hDC, OBJ_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 
178  ReleaseDC(hWnd, hDC);
180 }
181 
183 {
185 }
186 
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define ERROR_SUCCESS
Definition: deptool.c:10
HDC WINAPI GetDC(_In_opt_ HWND)
#define WHITE_PEN
Definition: wingdi.h:904
void Test_GetCurrentObject()
static HDC
Definition: imagelist.c:92
HWND hWnd
Definition: settings.c:17
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define WHITE_BRUSH
Definition: wingdi.h:901
BOOL WINAPI DestroyWindow(_In_ HWND)
#define CreateWindowW(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4291
#define OBJ_PEN
Definition: objidl.idl:1409
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define OBJ_COLORSPACE
Definition: wingdi.h:703
#define CW_USEDEFAULT
Definition: winuser.h:225
smooth NULL
Definition: ftsmooth.c:416
#define SYSTEM_FONT
Definition: wingdi.h:910
START_TEST(GetCurrentObject)
#define GDI_HANDLE_GET_TYPE(h)
Definition: gdi.h:31
#define BLACK_BRUSH
Definition: wingdi.h:895
#define DEFAULT_PALETTE
Definition: wingdi.h:912
#define SetLastError(x)
Definition: compat.h:418
#define OBJ_PAL
Definition: objidl.idl:1413
#define OBJ_FONT
Definition: objidl.idl:1414
#define DEFAULT_GUI_FONT
Definition: wingdi.h:908
static const WCHAR L[]
Definition: oid.c:1250
#define GDI_OBJECT_TYPE_BITMAP
Definition: gdi.h:48
static HDC hDC
Definition: 3dtext.c:33
#define OBJ_BRUSH
Definition: objidl.idl:1410
#define BLACK_PEN
Definition: wingdi.h:902
#define ok(value,...)
Definition: atltest.h:57
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
static HBITMAP
Definition: button.c:44
#define WS_VISIBLE
Definition: pedump.c:620
#define OBJ_BITMAP
Definition: objidl.idl:1415
HGDIOBJ WINAPI GetCurrentObject(_In_ HDC, _In_ UINT)
Definition: dc.c:439