ReactOS  0.4.14-dev-376-gaedba84
NtGdiSelectBitmap.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 NtGdiSelectBitmap
5  * PROGRAMMERS:
6  */
7 
8 #include <win32nt.h>
9 
10 void
12 {
13  HDC hdc;
14  HBITMAP hbmp;
15  struct
16  {
17  BITMAPINFOHEADER bmiHeader;
18  RGBQUAD bmiColors[100];
19  } bmi;
21  PVOID pvBits;
22 
24  ASSERT(hdc);
25 
26  bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
27  bmi.bmiHeader.biWidth = 2;
28  bmi.bmiHeader.biHeight = 2;
29  bmi.bmiHeader.biPlanes = 1;
30  bmi.bmiHeader.biBitCount = 1;
31  bmi.bmiHeader.biCompression = BI_RGB;
32  bmi.bmiHeader.biSizeImage = 0;
33  bmi.bmiHeader.biXPelsPerMeter = 100;
34  bmi.bmiHeader.biYPelsPerMeter = 100;
35  bmi.bmiHeader.biClrUsed = 2;
36  bmi.bmiHeader.biClrImportant = 2;
37 
38  hbmp = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, &pvBits, NULL, 0);
39  ASSERT(hbmp);
40 
42 
43 }
44 
45 
47 {
48  HDC hDC;
49  HBITMAP hBmp, hOldBmp;
50  HPALETTE hOldPalette, hPalette;
51  LOGPALETTE logpal = {0x300, 1, {{12,13,14,15}}};
52 
53  hBmp = CreateBitmap(2,2,1,1,NULL);
54  ASSERT(hBmp);
55 
56  /* We cannot select a bitmap into a display DC */
57  hDC = GetDC(NULL);
58  ASSERT(hDC);
59  hOldBmp = NtGdiSelectBitmap(hDC, hBmp);
60  TEST(hOldBmp == NULL);
61 
63  ASSERT(hDC);
64 
65  /* Check the palette before we mess it up*/
66  hPalette = CreatePalette(&logpal);
67  hOldPalette = SelectPalette(hDC, hPalette, 0);
68  TEST(hOldPalette == GetStockObject(DEFAULT_PALETTE));
69 
70  /* Test NULL DC */
72  hOldBmp = NtGdiSelectBitmap(NULL, hBmp);
73  TEST(hOldBmp == NULL);
75 
76  /* Test invalid DC */
78  hOldBmp = NtGdiSelectBitmap((HDC)((ULONG_PTR)hDC & 0x0000ffff), hBmp);
79  TEST(hOldBmp == NULL);
81 
82  /* Test NULL bitmap */
84  hOldBmp = NtGdiSelectBitmap(hDC, NULL);
85  TEST(hOldBmp == NULL);
87 
88  /* Test bitmap with only index */
90  hOldBmp = NtGdiSelectBitmap(hDC, (HBITMAP)((ULONG_PTR)hBmp & 0x0000ffff));
91  TEST(hOldBmp == NULL);
93 
94  /* Test valid bitmap */
96  hOldBmp = NtGdiSelectBitmap(hDC, hBmp);
97  TEST(hOldBmp != NULL);
98  /* The default bitmap should be GetStockObject(21) */
99  TEST(hOldBmp == GetStockObject(21));
100 
101  /* Check the palette */
102  hOldPalette = SelectPalette(hDC, hOldPalette, 0);
103  TEST(hOldPalette == hPalette);
104  DeleteObject(hPalette);
105 
106  /* Select the old one again and check */
107  hOldBmp = NtGdiSelectBitmap(hDC, hOldBmp);
108  TEST(hOldBmp == hBmp);
110 
111  /* cleanup */
112  DeleteObject(hBmp);
113  DeleteDC(hDC);
114 
116 
117 }
118 
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define ERROR_SUCCESS
Definition: deptool.c:10
#define DIB_PAL_COLORS
Definition: wingdi.h:365
HDC WINAPI GetDC(_In_opt_ HWND)
_In_ HBITMAP _In_ UINT _In_ UINT _Inout_ LPBITMAPINFO pbmi
Definition: ntgdi.h:2780
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
static HDC
Definition: imagelist.c:92
__kernel_entry W32KAPI HBITMAP APIENTRY NtGdiSelectBitmap(_In_ HDC hdc, _In_ HBITMAP hbm)
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
uint32_t ULONG_PTR
Definition: typedefs.h:63
START_TEST(NtGdiSelectBitmap)
HPALETTE WINAPI SelectPalette(_In_ HDC, _In_ HPALETTE, _In_ BOOL)
smooth NULL
Definition: ftsmooth.c:416
HBITMAP hbmp
#define DEFAULT_PALETTE
Definition: wingdi.h:912
#define TEST(x)
Definition: precomp.h:20
HPALETTE WINAPI CreatePalette(_In_reads_(_Inexpressible_(2 *sizeof(WORD)+plpal->palNumEntries *sizeof(PALETTEENTRY))) const LOGPALETTE *)
#define SetLastError(x)
Definition: compat.h:417
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
HDC hdc
Definition: main.c:9
void Test_SelectDIBSection(void)
static HDC hDC
Definition: 3dtext.c:33
BOOL WINAPI DeleteDC(_In_ HDC)
HBITMAP WINAPI CreateDIBSection(HDC hDC, CONST BITMAPINFO *BitmapInfo, UINT Usage, VOID **Bits, HANDLE hSection, DWORD dwOffset)
Definition: bitmap.c:197
struct tagBITMAPINFO * PBITMAPINFO
static HBITMAP
Definition: button.c:44
#define BI_RGB
Definition: precomp.h:34
HBITMAP WINAPI CreateBitmap(_In_ INT cx, _In_ INT cy, _In_ UINT cPlanes, _In_ UINT cBitsPerPel, _In_opt_ const VOID *pvBits)