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
Test_SelectDIBSection(void)11 Test_SelectDIBSection(void)
12 {
13 HDC hdc;
14 HBITMAP hbmp;
15 struct
16 {
17 BITMAPINFOHEADER bmiHeader;
18 RGBQUAD bmiColors[100];
19 } bmi;
20 PBITMAPINFO pbmi = (PBITMAPINFO)&bmi;
21 PVOID pvBits;
22
23 hdc = CreateCompatibleDC(0);
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
41 TEST(NtGdiSelectBitmap(hdc, hbmp) != 0);
42
43 }
44
45
START_TEST(NtGdiSelectBitmap)46 START_TEST(NtGdiSelectBitmap)
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
62 hDC = CreateCompatibleDC(GetDC(NULL));
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 */
71 SetLastError(ERROR_SUCCESS);
72 hOldBmp = NtGdiSelectBitmap(NULL, hBmp);
73 TEST(hOldBmp == NULL);
74 TEST(GetLastError() == ERROR_SUCCESS);
75
76 /* Test invalid DC */
77 SetLastError(ERROR_SUCCESS);
78 hOldBmp = NtGdiSelectBitmap((HDC)((ULONG_PTR)hDC & 0x0000ffff), hBmp);
79 TEST(hOldBmp == NULL);
80 TEST(GetLastError() == ERROR_SUCCESS);
81
82 /* Test NULL bitmap */
83 SetLastError(ERROR_SUCCESS);
84 hOldBmp = NtGdiSelectBitmap(hDC, NULL);
85 TEST(hOldBmp == NULL);
86 TEST(GetLastError() == ERROR_SUCCESS);
87
88 /* Test bitmap with only index */
89 SetLastError(ERROR_SUCCESS);
90 hOldBmp = NtGdiSelectBitmap(hDC, (HBITMAP)((ULONG_PTR)hBmp & 0x0000ffff));
91 TEST(hOldBmp == NULL);
92 TEST(GetLastError() == ERROR_SUCCESS);
93
94 /* Test valid bitmap */
95 SetLastError(ERROR_SUCCESS);
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);
109 TEST(GetLastError() == ERROR_SUCCESS);
110
111 /* cleanup */
112 DeleteObject(hBmp);
113 DeleteDC(hDC);
114
115 Test_SelectDIBSection();
116
117 }
118
119