ReactOS  0.4.14-dev-552-g2fad488
NtGdiRestoreDC.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 NtGdiRestoreDC
5  * PROGRAMMERS:
6  */
7 
8 #include <win32nt.h>
9 
10 static HBRUSH hbrush;
12 static HPEN hpen;
13 static HFONT hfont;
14 static HRGN hrgn, hrgn2;
15 
16 static
17 void
19 {
20  /* Select spcial Objects */
26 
27  /* Colors */
28  SetDCBrushColor(hdc, RGB(12,34,56));
29  SetDCPenColor(hdc, RGB(23,34,45));
30 
31  /* Coordinates */
34  SetWindowOrgEx(hdc, 12, 34, NULL);
35  SetViewportOrgEx(hdc, 56, 78, NULL);
36  SetWindowExtEx(hdc, 123, 456, NULL);
37  SetViewportExtEx(hdc, 234, 567, NULL);
38 
39 
40 
41 }
42 
43 static
44 void
46 {
47  /* Select spcial Objects */
48  SelectObject(hdc, GetStockObject(DC_BRUSH));
53 
54  /* Colors */
55  SetDCBrushColor(hdc, RGB(65,43,21));
56  SetDCPenColor(hdc, RGB(54,43,32));
57 
58  /* Coordinates */
61  SetWindowOrgEx(hdc, 43, 21, NULL);
62  SetViewportOrgEx(hdc, 87, 65, NULL);
63  SetWindowExtEx(hdc, 654, 321, NULL);
64  SetViewportExtEx(hdc, 765, 432, NULL);
65 
66 
67 }
68 
69 static
70 void
72 {
73  POINT pt;
74  SIZE sz;
75 
76  /* Test Objects */
77  TEST(SelectObject(hdc, GetStockObject(DC_BRUSH)) == hbrush);
78  TEST(SelectObject(hdc, GetStockObject(DC_PEN)) == hpen);
80  if (bMemDC)
81  {
83  TEST(SelectObject(hdc, hrgn2) == (PVOID)1);
84  }
85  else
86  {
88  TEST(SelectObject(hdc, hrgn2) == (PVOID)2);
89  }
90 
91  /* Test colors */
92  TEST(GetDCBrushColor(hdc) == RGB(12,34,56));
93  TEST(GetDCPenColor(hdc) == RGB(23,34,45));
94 
95  /* Test coordinates */
99  TEST(pt.x == 12);
100  TEST(pt.y == 34);
102  TEST(pt.x == 56);
103  TEST(pt.y == 78);
104  GetWindowExtEx(hdc, &sz);
105  ok(sz.cx == 123, "sz.cx == %ld\n", sz.cx);
106  ok(sz.cy == 456, "sz.cy == %ld\n", sz.cy);
107  GetViewportExtEx(hdc, &sz);
108  TEST(sz.cx == 234);
109  TEST(sz.cy == 567);
110 
111 
112 }
113 
114 
115 static
116 void
118 {
120  NtGdiSaveDC(hdc);
122 
123  SetLastError(0);
124  TEST(NtGdiRestoreDC(hdc, 2) == 0);
126 
127  SetLastError(0);
128  TEST(NtGdiRestoreDC(hdc, 0) == 0);
130 
131  SetLastError(0);
132  TEST(NtGdiRestoreDC(hdc, -2) == 0);
134 
135  SetLastError(0);
136  TEST(NtGdiRestoreDC(hdc, 1) == 1);
137  TEST(GetLastError() == 0);
138 
139  Test_IsSpecialState(hdc, bMemDC);
140 }
141 
142 
144 {
145  HDC hdc;
146 
147  hdc = CreateCompatibleDC(0);
149 
150  SetLastError(0);
151  TEST(NtGdiRestoreDC(0, -10) == 0);
153 
154  SetLastError(0);
155  TEST(NtGdiRestoreDC(hdc, 0) == 0);
157 
158  SetLastError(0);
159  TEST(NtGdiRestoreDC(hdc, 1) == 0);
161 
162  /* Initialize objects */
163  hbrush = CreateSolidBrush(12345);
165  hpen = CreatePen(PS_SOLID, 4, RGB(10,12,32));
167  hbitmap = CreateBitmap(10, 10, 1, 1, NULL);
169  hfont = CreateFont(10, 0, 0, 0, FW_NORMAL, 0, 0, 0, ANSI_CHARSET,
171  DEFAULT_PITCH, "Arial");
173  hrgn = CreateRectRgn(12, 14, 14, 17);
175  hrgn2 = CreateRectRgn(1, 1, 2, 2);
177 
178  /* Test mem dc */
180  DeleteDC(hdc);
181 
182  /* Test screen DC */
183  hdc = GetDC(0);
186  ReleaseDC(0, hdc);
187 
188  /* Test info dc */
189  hdc = CreateICW(L"DISPLAY", NULL, NULL, NULL);
192  DeleteDC(hdc);
193 
194 }
195 
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define MM_ISOTROPIC
Definition: wingdi.h:869
static void Test_IsSpecialState(HDC hdc, BOOL bMemDC)
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
BOOL WINAPI SetViewportOrgEx(_In_ HDC, _In_ int, _In_ int, _Out_opt_ LPPOINT)
Definition: coord.c:655
#define TRUE
Definition: types.h:120
HPEN WINAPI CreatePen(_In_ int, _In_ int, _In_ COLORREF)
BOOL WINAPI SetWindowExtEx(_In_ HDC, _In_ int, _In_ int, _Out_opt_ LPSIZE)
static HBRUSH hbrush
#define DEFAULT_QUALITY
Definition: wingdi.h:435
HDC WINAPI GetDC(_In_opt_ HWND)
BOOL WINAPI GetWindowOrgEx(_In_ HDC, _Out_ LPPOINT)
Definition: coord.c:439
#define pt(x, y)
Definition: drawing.c:79
static HRGN hrgn2
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
BOOL GdiIsHandleValid(_In_ HGDIOBJ hobj)
Definition: gditools.c:29
static HDC
Definition: imagelist.c:92
__kernel_entry W32KAPI BOOL APIENTRY NtGdiRestoreDC(_In_ HDC hdc, _In_ INT iLevel)
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
static HPEN hpen
#define PS_SOLID
Definition: wingdi.h:585
__kernel_entry W32KAPI INT APIENTRY NtGdiSaveDC(_In_ HDC hdc)
COLORREF WINAPI SetDCBrushColor(_In_ HDC hdc, _In_ COLORREF crColor)
Definition: dc.c:881
unsigned int BOOL
Definition: ntddk_ex.h:94
int WINAPI SetMapMode(_In_ HDC, _In_ int)
#define CLIP_DEFAULT_PRECIS
Definition: wingdi.h:425
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
static void SetSpecialDCState(HDC hdc)
#define CreateFont
Definition: wingdi.h:4442
smooth NULL
Definition: ftsmooth.c:416
LONG cx
Definition: windef.h:334
#define DEFAULT_BITMAP
Definition: ntgdityp.h:194
static HFONT hfont
HRGN WINAPI CreateRectRgn(_In_ int, _In_ int, _In_ int, _In_ int)
#define DEFAULT_PITCH
Definition: wingdi.h:442
BOOL WINAPI GetViewportExtEx(_In_ HDC, _Out_ LPSIZE)
Definition: coord.c:351
#define TEST(x)
Definition: precomp.h:20
int WINAPI GetGraphicsMode(_In_ HDC)
BOOL WINAPI GetWindowExtEx(_In_ HDC, _Out_ LPSIZE)
Definition: coord.c:411
#define RGB(r, g, b)
Definition: wingdi.h:2939
#define OUT_DEFAULT_PRECIS
Definition: wingdi.h:414
BOOL WINAPI GetViewportOrgEx(_In_ HDC, _Out_ LPPOINT)
Definition: coord.c:383
#define SetLastError(x)
Definition: compat.h:417
#define DEFAULT_GUI_FONT
Definition: wingdi.h:908
#define GM_COMPATIBLE
Definition: wingdi.h:863
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static HRGN hrgn
static const WCHAR L[]
Definition: oid.c:1250
HDC hdc
Definition: main.c:9
#define MM_ANISOTROPIC
Definition: wingdi.h:866
int WINAPI GetMapMode(_In_ HDC)
Definition: coord.c:114
static void Test_SaveRestore(HDC hdc, BOOL bMemDC)
BOOL WINAPI DeleteDC(_In_ HDC)
COLORREF WINAPI GetDCBrushColor(_In_ HDC hdc)
Definition: dc.c:839
#define ok(value,...)
Definition: atltest.h:57
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)
HDC WINAPI CreateICW(_In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_opt_ const DEVMODEW *)
#define FW_NORMAL
Definition: wingdi.h:372
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
COLORREF WINAPI GetDCPenColor(_In_ HDC hdc)
Definition: dc.c:860
static void SetSpecialDCState2(HDC hdc)
BOOL WINAPI SetWindowOrgEx(_In_ HDC, _In_ int, _In_ int, _Out_opt_ LPPOINT)
Definition: coord.c:532
static HBITMAP hbitmap
static HBITMAP
Definition: button.c:44
START_TEST(NtGdiRestoreDC)
COLORREF WINAPI SetDCPenColor(_In_ HDC hdc, _In_ COLORREF crColor)
Definition: dc.c:917
BOOL WINAPI SetViewportExtEx(_In_ HDC, _In_ int, _In_ int, _Out_opt_ LPSIZE)
Definition: coord.c:465
#define ANSI_CHARSET
Definition: wingdi.h:382
int WINAPI SetGraphicsMode(_In_ HDC, _In_ int)
Definition: dc.c:1202
LONG cy
Definition: windef.h:335
HBITMAP WINAPI CreateBitmap(_In_ INT cx, _In_ INT cy, _In_ UINT cPlanes, _In_ UINT cBitsPerPel, _In_opt_ const VOID *pvBits)
#define GM_ADVANCED
Definition: wingdi.h:864