2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for CreateBitmap
5 * PROGRAMMERS: Timo Kreuzer
10 void Test_CreateBitmap_Params()
14 /* All of these should get us the default bitmap */
15 hbmp
= CreateBitmap(0, 0, 0, 0, NULL
);
16 ok(hbmp
== GetStockObject(21), "should get the default bitmap\n");
17 hbmp
= CreateBitmap(1, 0, 0, 0, NULL
);
18 ok(hbmp
== GetStockObject(21), "should get the default bitmap\n");
19 hbmp
= CreateBitmap(0, 1, 0, 0, NULL
);
20 ok(hbmp
== GetStockObject(21), "should get the default bitmap\n");
21 hbmp
= CreateBitmap(0, 1, 1, 0, NULL
);
22 ok(hbmp
== GetStockObject(21), "should get the default bitmap\n");
23 hbmp
= CreateBitmap(0, 1, 63, 33, NULL
);
24 ok(hbmp
== GetStockObject(21), "should get the default bitmap\n");
25 hbmp
= CreateBitmap(0, -4, -32, 233, NULL
);
26 ok(hbmp
== GetStockObject(21), "should get the default bitmap\n");
29 hbmp
= CreateBitmap(1, -1, 1, 0, NULL
);
30 ok(hbmp
== 0, "CreateBitmap should fail\n");
31 ok_err(ERROR_INVALID_PARAMETER
);
34 hbmp
= CreateBitmap(-1, 1, 1, 0, NULL
);
35 ok(hbmp
== 0, "CreateBitmap should fail\n");
36 ok_err(ERROR_INVALID_PARAMETER
);
39 hbmp
= CreateBitmap(-1, 1, 1, 1, NULL
);
40 ok(hbmp
== 0, "CreateBitmap should fail\n");
41 ok_err(ERROR_INVALID_PARAMETER
);
44 hbmp
= CreateBitmap(1, -1, 1, 1, NULL
);
45 ok(hbmp
== 0, "CreateBitmap should fail\n");
46 ok_err(ERROR_INVALID_PARAMETER
);
48 /* Check if an overflow in cPlanes * cBitsPixel is handled */
50 hbmp
= CreateBitmap(1, 1, 2, 0x80000004, NULL
);
51 ok(hbmp
== 0, "CreateBitmap should fail\n");
52 ok_err(ERROR_INVALID_PARAMETER
);
54 /* Check for maximum width */
55 hbmp
= CreateBitmap(0x7FFFFFF, 1, 1, 1, NULL
);
56 ok(hbmp
!= 0, "CreateBitmap failed\n");
60 hbmp
= CreateBitmap(0x8000000, 1, 1, 1, NULL
);
61 ok(hbmp
== 0, "CreateBitmap should fail\n");
62 ok_err(ERROR_INVALID_PARAMETER
);
64 /* Check for maximum height */
65 hbmp
= CreateBitmap(1, 0x1FFFFF00, 1, 1, NULL
);
66 //ok(hbmp != 0, "\n"); // fails on windows 2003
70 hbmp
= CreateBitmap(1, 0x1FFFFFFF, 1, 1, NULL
);
71 ok(hbmp
== 0, "CreateBitmap should fail\n");
75 hbmp
= CreateBitmap(1, -1, 1, 1, NULL
);
76 ok(hbmp
== 0, "CreateBitmap should fail\n");
77 ok_err(ERROR_INVALID_PARAMETER
);
79 /* Test huge allocation (256 GB) */
81 hbmp
= CreateBitmap(0x40000, 0x40000, 32, 1, NULL
);
82 ok(hbmp
== 0, "CreateBitmap should fail\n");
83 ok_err(ERROR_INVALID_PARAMETER
);
85 /* Test planes / bpp */
86 hbmp
= CreateBitmap(10, 10, 32, 1, NULL
);
87 ok(hbmp
!= 0, "CreateBitmap failed\n");
89 hbmp
= CreateBitmap(10, 10, 5, 5, NULL
);
90 ok(hbmp
!= 0, "CreateBitmap failed\n");
94 hbmp
= CreateBitmap(10, 10, 33, 1, NULL
);
95 ok(hbmp
== 0, "CreateBitmap should fail\n");
96 ok_err(ERROR_INVALID_PARAMETER
);
99 hbmp
= CreateBitmap(10, 10, 1, 33, NULL
);
100 ok(hbmp
== 0, "CreateBitmap should fail\n");
101 ok_err(ERROR_INVALID_PARAMETER
);
104 hbmp
= CreateBitmap(10, 10, 6, 6, NULL
);
105 ok(hbmp
== 0, "CreateBitmap should fail\n");
106 ok_err(ERROR_INVALID_PARAMETER
);
109 hbmp
= CreateBitmap(10, 10, 8, 8, NULL
);
110 ok(hbmp
== 0, "CreateBitmap should fail\n");
111 ok_err(ERROR_INVALID_PARAMETER
);
115 void Test_CreateBitmap()
119 ULONG cjWidthBytes
, cBitsPixel
, cExpectedBitsPixel
;
120 int result
, TestBitsPixel
, ExpectedBitsPixel
;
122 hbmp
= CreateBitmap(0, 0, 0, 0, NULL
);
123 ok(hbmp
!= 0, "should get a 1x1 bitmap\n");
124 ok(hbmp
== GetStockObject(DEFAULT_BITMAP
), "\n");
125 ok_int(GetObject(hbmp
, sizeof(bitmap
), &bitmap
), sizeof(BITMAP
));
126 ok_int(bitmap
.bmType
, 0);
127 ok_int(bitmap
.bmWidth
, 1);
128 ok_int(bitmap
.bmHeight
, 1);
129 ok_int(bitmap
.bmWidthBytes
, 2);
130 ok_int(bitmap
.bmPlanes
, 1);
131 ok_int(bitmap
.bmBitsPixel
, 1);
132 ok_ptr(bitmap
.bmBits
, 0);
135 /* Above 32 bpp should fail */
136 hbmp
= CreateBitmap(1, 2, 1, 33, NULL
);
137 ok(hbmp
== 0, "should fail\n");
139 for (TestBitsPixel
= 0; TestBitsPixel
<= 32; TestBitsPixel
++)
141 /* CreateBitmap API accepts any number as BitsPixels param.
142 but it can only create 1, 4, 8, 16, 24, 32 bpp bitmaps */
143 if (TestBitsPixel
<= 1) ExpectedBitsPixel
= 1;
144 else if(TestBitsPixel
<= 4) ExpectedBitsPixel
= 4;
145 else if(TestBitsPixel
<= 8) ExpectedBitsPixel
= 8;
146 else if(TestBitsPixel
<= 16) ExpectedBitsPixel
= 16;
147 else if(TestBitsPixel
<= 24) ExpectedBitsPixel
= 24;
148 else if(TestBitsPixel
<= 32) ExpectedBitsPixel
= 32;
150 /* Calculate proper bmWidthBytes */
152 hbmp
= CreateBitmap(1, 2, 1, TestBitsPixel
, NULL
);
153 ok(hbmp
!= 0, "should get a 1x2 bitmap\n");
154 result
= GetObject(hbmp
, sizeof(bitmap
), &bitmap
);
155 ok(result
> 0, "result = %d\n", result
);
156 ok(bitmap
.bmType
== 0, "bmType = %ld\n", bitmap
.bmType
);
157 ok(bitmap
.bmWidth
== 1, "bmWidth = %ld\n", bitmap
.bmWidth
);
158 ok(bitmap
.bmHeight
== 2, "bmHeight = %ld\n", bitmap
.bmHeight
);
159 ok(bitmap
.bmPlanes
== 1, "bmPlanes = %d\n", bitmap
.bmPlanes
);
160 ok(bitmap
.bmBitsPixel
== ExpectedBitsPixel
, "bmBitsPixel = %d ExpectedBitsPixel= %d \n", bitmap
.bmBitsPixel
, ExpectedBitsPixel
);
161 ok(bitmap
.bmBits
== 0, "bmBits = %p\n", bitmap
.bmBits
);
165 hbmp
= CreateBitmap(1, 2, 1, 1, NULL
);
166 ok(hbmp
!= 0, "should get a 1x2 bitmap\n");
167 ok_int(GetObject(hbmp
, sizeof(bitmap
), &bitmap
), sizeof(BITMAP
));
168 ok_int(bitmap
.bmType
, 0);
169 ok_int(bitmap
.bmWidth
, 1);
170 ok_int(bitmap
.bmHeight
, 2);
171 ok_int(bitmap
.bmWidthBytes
, 2);
172 ok_int(bitmap
.bmPlanes
, 1);
173 ok_int(bitmap
.bmBitsPixel
, 1);
174 ok_ptr(bitmap
.bmBits
, 0);
177 for (cBitsPixel
= 0; cBitsPixel
<= 32; cBitsPixel
++)
179 /* CreateBitmap API accepts any number as BitsPixels param.
180 but it just can create 1, 4, 8, 16, 24, 32 bpp Bitmaps */
181 if (cBitsPixel
<= 1) cExpectedBitsPixel
= 1;
182 else if (cBitsPixel
<= 4) cExpectedBitsPixel
= 4;
183 else if (cBitsPixel
<= 8) cExpectedBitsPixel
= 8;
184 else if (cBitsPixel
<= 16) cExpectedBitsPixel
= 16;
185 else if (cBitsPixel
<= 24) cExpectedBitsPixel
= 24;
186 else if (cBitsPixel
<= 32) cExpectedBitsPixel
= 32;
188 hbmp
= CreateBitmap(1, 2, 1, cBitsPixel
, NULL
);
189 ok(hbmp
!= 0, "should get a 1x2 bitmap %ld\n", cBitsPixel
);
190 ok_int(GetObject(hbmp
, sizeof(bitmap
), &bitmap
), sizeof(BITMAP
));
192 /* calculate expected line width */
193 cjWidthBytes
= ((((ULONG
)bitmap
.bmWidth
) * ((ULONG
)bitmap
.bmBitsPixel
) + 15) & ~15) >> 3;
195 ok_int(bitmap
.bmType
, 0);
196 ok_int(bitmap
.bmWidth
, 1);
197 ok_int(bitmap
.bmHeight
, 2);
198 ok_int(bitmap
.bmPlanes
, 1);
199 ok_int(bitmap
.bmBitsPixel
, cExpectedBitsPixel
);
200 ok_int(bitmap
.bmWidthBytes
, cjWidthBytes
);
201 ok_ptr(bitmap
.bmBits
, 0);
206 hbmp
= CreateBitmap(1, 2, 1, 33, NULL
);
207 ok(hbmp
== 0, "Expected failure for 33 bpp\n");
213 START_TEST(CreateBitmap
)
215 Test_CreateBitmap_Params();