ReactOS 0.4.15-dev-7842-g558ab78
CreateBitmap.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 CreateBitmap
5 * PROGRAMMERS: Timo Kreuzer
6 */
7
8#include "precomp.h"
9
13
15{
17
18 /* All of these should get us the default bitmap */
19 hbmp = CreateBitmap(0, 0, 0, 0, NULL);
20 ok(hbmp == GetStockObject(21), "should get the default bitmap\n");
21 hbmp = CreateBitmap(1, 0, 0, 0, NULL);
22 ok(hbmp == GetStockObject(21), "should get the default bitmap\n");
23 hbmp = CreateBitmap(0, 1, 0, 0, NULL);
24 ok(hbmp == GetStockObject(21), "should get the default bitmap\n");
25 hbmp = CreateBitmap(0, 1, 1, 0, NULL);
26 ok(hbmp == GetStockObject(21), "should get the default bitmap\n");
27 hbmp = CreateBitmap(0, 1, 63, 33, NULL);
28 ok(hbmp == GetStockObject(21), "should get the default bitmap\n");
29 hbmp = CreateBitmap(0, -4, -32, 233, NULL);
30 ok(hbmp == GetStockObject(21), "should get the default bitmap\n");
31
32 SetLastError(0);
33 hbmp = CreateBitmap(1, -1, 1, 0, NULL);
34 ok(hbmp == 0, "CreateBitmap should fail\n");
36
37 SetLastError(0);
38 hbmp = CreateBitmap(-1, 1, 1, 0, NULL);
39 ok(hbmp == 0, "CreateBitmap should fail\n");
41
42 SetLastError(0);
43 hbmp = CreateBitmap(-1, 1, 1, 1, NULL);
44 ok(hbmp == 0, "CreateBitmap should fail\n");
46
47 SetLastError(0);
48 hbmp = CreateBitmap(1, -1, 1, 1, NULL);
49 ok(hbmp == 0, "CreateBitmap should fail\n");
51
52 /* Check if an overflow in cPlanes * cBitsPixel is handled */
53 SetLastError(0);
54 hbmp = CreateBitmap(1, 1, 2, 0x80000004, NULL);
55 ok(hbmp == 0, "CreateBitmap should fail\n");
57
58 /* Check for maximum width */
59 hbmp = CreateBitmap(0x7FFFFFF, 1, 1, 1, NULL);
60 ok(hbmp != 0, "CreateBitmap failed\n");
62
63 SetLastError(0);
64 hbmp = CreateBitmap(0x8000000, 1, 1, 1, NULL);
65 ok(hbmp == 0, "CreateBitmap should fail\n");
67
68 /* Check for maximum height */
69 hbmp = CreateBitmap(1, 0x1FFFFF00, 1, 1, NULL);
70 //ok(hbmp != 0, "\n"); // fails on windows 2003
72
73 SetLastError(0);
74 hbmp = CreateBitmap(1, 0x1FFFFFFF, 1, 1, NULL);
75 ok(hbmp == 0, "CreateBitmap should fail\n");
76 ok_err(0);
77
78 SetLastError(0);
79 hbmp = CreateBitmap(1, -1, 1, 1, NULL);
80 ok(hbmp == 0, "CreateBitmap should fail\n");
82
83 /* Test huge allocation (256 GB) */
84 SetLastError(0);
85 hbmp = CreateBitmap(0x40000, 0x40000, 32, 1, NULL);
86 ok(hbmp == 0, "CreateBitmap should fail\n");
88
89 /* Test planes / bpp */
90 hbmp = CreateBitmap(10, 10, 32, 1, NULL);
91 ok(hbmp != 0, "CreateBitmap failed\n");
93 hbmp = CreateBitmap(10, 10, 5, 5, NULL);
94 ok(hbmp != 0, "CreateBitmap failed\n");
96
97 SetLastError(0);
98 hbmp = CreateBitmap(10, 10, 33, 1, NULL);
99 ok(hbmp == 0, "CreateBitmap should fail\n");
101
102 SetLastError(0);
103 hbmp = CreateBitmap(10, 10, 1, 33, NULL);
104 ok(hbmp == 0, "CreateBitmap should fail\n");
106
107 SetLastError(0);
108 hbmp = CreateBitmap(10, 10, 6, 6, NULL);
109 ok(hbmp == 0, "CreateBitmap should fail\n");
111
112 SetLastError(0);
113 hbmp = CreateBitmap(10, 10, 8, 8, NULL);
114 ok(hbmp == 0, "CreateBitmap should fail\n");
116
117}
118
120{
123 ULONG cjWidthBytes, cBitsPixel, cExpectedBitsPixel;
124
125 hbmp = CreateBitmap(0, 0, 0, 0, NULL);
126 ok(hbmp != 0, "should get a 1x1 bitmap\n");
128 ok_int(GetObject(hbmp, sizeof(bitmap), &bitmap), sizeof(BITMAP));
129 ok_int(bitmap.bmType, 0);
130 ok_int(bitmap.bmWidth, 1);
131 ok_int(bitmap.bmHeight, 1);
132 ok_int(bitmap.bmWidthBytes, 2);
133 ok_int(bitmap.bmPlanes, 1);
134 ok_int(bitmap.bmBitsPixel, 1);
135 ok_ptr(bitmap.bmBits, 0);
137
138 /* Above 32 bpp should fail */
139 hbmp = CreateBitmap(1, 2, 1, 33, NULL);
140 ok(hbmp == 0, "should fail\n");
141
142 hbmp = CreateBitmap(1, 2, 1, 1, NULL);
143 ok(hbmp != 0, "should get a 1x2 bitmap\n");
144 ok_int(GetObject(hbmp, sizeof(bitmap), &bitmap), sizeof(BITMAP));
145 ok_int(bitmap.bmType, 0);
146 ok_int(bitmap.bmWidth, 1);
147 ok_int(bitmap.bmHeight, 2);
148 ok_int(bitmap.bmWidthBytes, 2);
149 ok_int(bitmap.bmPlanes, 1);
150 ok_int(bitmap.bmBitsPixel, 1);
151 ok_ptr(bitmap.bmBits, 0);
153
154 for (cBitsPixel = 0; cBitsPixel <= 32; cBitsPixel++)
155 {
156 /* CreateBitmap API accepts any number as BitsPixels param.
157 but it can only create 1, 4, 8, 16, 24, 32 bpp bitmaps */
158 if (cBitsPixel <= 1) cExpectedBitsPixel = 1;
159 else if (cBitsPixel <= 4) cExpectedBitsPixel = 4;
160 else if (cBitsPixel <= 8) cExpectedBitsPixel = 8;
161 else if (cBitsPixel <= 16) cExpectedBitsPixel = 16;
162 else if (cBitsPixel <= 24) cExpectedBitsPixel = 24;
163 else if (cBitsPixel <= 32) cExpectedBitsPixel = 32;
164
165 hbmp = CreateBitmap(1, 2, 1, cBitsPixel, NULL);
166 ok(hbmp != 0, "should get a 1x2 bitmap %ld\n", cBitsPixel);
167 ok_int(GetObject(hbmp, sizeof(bitmap), &bitmap), sizeof(BITMAP));
168
169 /* Calculate expected line width */
170 cjWidthBytes = ((bitmap.bmWidth * bitmap.bmBitsPixel + 15) & ~15) >> 3;
171
172 ok_int(bitmap.bmType, 0);
173 ok_int(bitmap.bmWidth, 1);
174 ok_int(bitmap.bmHeight, 2);
175 ok_int(bitmap.bmPlanes, 1);
176 ok_int(bitmap.bmBitsPixel, cExpectedBitsPixel);
177 ok_int(bitmap.bmWidthBytes, cjWidthBytes);
178 ok_ptr(bitmap.bmBits, 0);
180 }
181
182 hbmp = CreateBitmap(1, 2, 1, 33, NULL);
183 ok(hbmp == 0, "Expected failure for 33 bpp\n");
184}
185
187{
188 static const WORD pattern_bits[] = { 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa };
189 HBITMAP hbmp,hbmpso,hbmpsoc;
190 INT ret;
191 BITMAP bm;
192
193 hbmp = CreateBitmap(0, 0, 0, 0, NULL);
194 ok(hbmp != 0, "should get a 1x1 bitmap\n");
196 ok(GetBitmapAttributes(hbmp) == 1,"\n");
197
198 ok(SetBitmapAttributes(hbmp, 0x00000002) == 0,"\n");
199 ok(SetBitmapAttributes(hbmp, 0x00000004) == 0,"\n");
200 ok(SetBitmapAttributes(hbmp, 0x00000008) == 0,"\n");
201 ok(SetBitmapAttributes(hbmp, 0x00000010) == 0,"\n");
202 ok(SetBitmapAttributes(hbmp, 0x00000020) == 0,"\n");
203 ok(SetBitmapAttributes(hbmp, 0x00000040) == 0,"\n");
204 ok(SetBitmapAttributes(hbmp, 0x00000080) == 0,"\n");
205 ok(SetBitmapAttributes(hbmp, 0x00000100) == 0,"\n");
206 ok(SetBitmapAttributes(hbmp, 0x00000200) == 0,"\n");
207 ok(SetBitmapAttributes(hbmp, 0x00000400) == 0,"\n");
208 ok(SetBitmapAttributes(hbmp, 0x00000800) == 0,"\n");
209 ok(SetBitmapAttributes(hbmp, 0xFFFFFFFF) == 0,"\n");
210 ok(ClearBitmapAttributes(hbmp, 0x00000002) == 0,"\n");
211 ok(ClearBitmapAttributes(hbmp, 0x00000004) == 0,"\n");
212 ok(ClearBitmapAttributes(hbmp, 0x00000008) == 0,"\n");
213 ok(ClearBitmapAttributes(hbmp, 0x00000010) == 0,"\n");
214 ok(ClearBitmapAttributes(hbmp, 0x00000020) == 0,"\n");
215 ok(ClearBitmapAttributes(hbmp, 0x00000040) == 0,"\n");
216 ok(ClearBitmapAttributes(hbmp, 0x00000080) == 0,"\n");
217 ok(ClearBitmapAttributes(hbmp, 0x00000100) == 0,"\n");
218 ok(ClearBitmapAttributes(hbmp, 0x00000200) == 0,"\n");
219 ok(ClearBitmapAttributes(hbmp, 0x00000400) == 0,"\n");
220 ok(ClearBitmapAttributes(hbmp, 0x00000800) == 0,"\n");
221 ok(ClearBitmapAttributes(hbmp, 0xFFFFFFFF) == 0,"\n");
223
224 hbmp = CreateBitmap( 16, 8, 1, 1, pattern_bits );
225 ok(hbmp != 0, "should get a pattern bitmap\n");
226 ok(GetBitmapAttributes(hbmp) == 0,"\n");
227
228 hbmpso = SetBitmapAttributes(hbmp, 1);
229 ok(hbmpso != 0, "should get stock pattern bitmap\n");
230 ok(GetBitmapAttributes(hbmpso) == 1,"\n");
231 ok(hbmpso != hbmp,"\n");
232
233 DeleteObject(hbmpso);
234 ret = GetObjectW(hbmpso, sizeof(bm), &bm);
235 ok(ret == sizeof(bm), "GetObject returned %d\n", ret);
236
237 hbmpsoc = ClearBitmapAttributes(hbmpso, 1);
238 ok(hbmpsoc != 0, "should get pattern bitmap\n");
239 ok(GetBitmapAttributes(hbmp) == 0,"\n");
240 ok(hbmpsoc == hbmp,"\n");
241
243 ret = GetObjectW(hbmp, sizeof(bm), &bm);
244 ok(ret == 0, "GetObject returned %d\n", ret);
245}
246
248{
252}
DWORD WINAPI GetBitmapAttributes(HBITMAP hbm)
Definition: bitmap.c:1171
void Test_CreateBitmap()
Definition: CreateBitmap.c:119
void Test_CreateBitmap_Params()
Definition: CreateBitmap.c:14
void Test_BitmapAttributes()
Definition: CreateBitmap.c:186
HBITMAP WINAPI SetBitmapAttributes(HBITMAP hbm, DWORD dwFlags)
Definition: bitmap.c:1185
HBITMAP WINAPI ClearBitmapAttributes(HBITMAP hbm, DWORD dwFlags)
Definition: bitmap.c:1199
#define ok(value,...)
Definition: atltest.h:57
#define ok_err(error)
Definition: atltest.h:124
#define START_TEST(x)
Definition: atltest.h:75
#define ok_int(expression, result)
Definition: atltest.h:134
#define ok_ptr(expression, result)
Definition: atltest.h:108
HBITMAP hbmp
#define NULL
Definition: types.h:112
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
pKey DeleteObject()
static HBITMAP
Definition: button.c:44
_In_ HBITMAP hbm
Definition: ntgdi.h:2776
#define DEFAULT_BITMAP
Definition: ntgdityp.h:195
Definition: bl.h:1331
Definition: uimain.c:89
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG
Definition: typedefs.h:59
int ret
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
#define WINAPI
Definition: msvc.h:6
HGDIOBJ WINAPI GetStockObject(_In_ int)
int WINAPI GetObjectW(_In_ HANDLE h, _In_ int c, _Out_writes_bytes_opt_(c) LPVOID pv)
HBITMAP WINAPI CreateBitmap(_In_ INT cx, _In_ INT cy, _In_ UINT cPlanes, _In_ UINT cBitsPerPel, _In_opt_ const VOID *pvBits)
#define GetObject
Definition: wingdi.h:4468