ReactOS  0.4.14-dev-297-g23e575c
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 
11 {
12  HBITMAP hbmp;
13 
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");
27 
28  SetLastError(0);
29  hbmp = CreateBitmap(1, -1, 1, 0, NULL);
30  ok(hbmp == 0, "CreateBitmap should fail\n");
32 
33  SetLastError(0);
34  hbmp = CreateBitmap(-1, 1, 1, 0, NULL);
35  ok(hbmp == 0, "CreateBitmap should fail\n");
37 
38  SetLastError(0);
39  hbmp = CreateBitmap(-1, 1, 1, 1, NULL);
40  ok(hbmp == 0, "CreateBitmap should fail\n");
42 
43  SetLastError(0);
44  hbmp = CreateBitmap(1, -1, 1, 1, NULL);
45  ok(hbmp == 0, "CreateBitmap should fail\n");
47 
48  /* Check if an overflow in cPlanes * cBitsPixel is handled */
49  SetLastError(0);
50  hbmp = CreateBitmap(1, 1, 2, 0x80000004, NULL);
51  ok(hbmp == 0, "CreateBitmap should fail\n");
53 
54  /* Check for maximum width */
55  hbmp = CreateBitmap(0x7FFFFFF, 1, 1, 1, NULL);
56  ok(hbmp != 0, "CreateBitmap failed\n");
58 
59  SetLastError(0);
60  hbmp = CreateBitmap(0x8000000, 1, 1, 1, NULL);
61  ok(hbmp == 0, "CreateBitmap should fail\n");
63 
64  /* Check for maximum height */
65  hbmp = CreateBitmap(1, 0x1FFFFF00, 1, 1, NULL);
66  //ok(hbmp != 0, "\n"); // fails on windows 2003
68 
69  SetLastError(0);
70  hbmp = CreateBitmap(1, 0x1FFFFFFF, 1, 1, NULL);
71  ok(hbmp == 0, "CreateBitmap should fail\n");
72  ok_err(0);
73 
74  SetLastError(0);
75  hbmp = CreateBitmap(1, -1, 1, 1, NULL);
76  ok(hbmp == 0, "CreateBitmap should fail\n");
78 
79  /* Test huge allocation (256 GB) */
80  SetLastError(0);
81  hbmp = CreateBitmap(0x40000, 0x40000, 32, 1, NULL);
82  ok(hbmp == 0, "CreateBitmap should fail\n");
84 
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");
92 
93  SetLastError(0);
94  hbmp = CreateBitmap(10, 10, 33, 1, NULL);
95  ok(hbmp == 0, "CreateBitmap should fail\n");
97 
98  SetLastError(0);
99  hbmp = CreateBitmap(10, 10, 1, 33, NULL);
100  ok(hbmp == 0, "CreateBitmap should fail\n");
102 
103  SetLastError(0);
104  hbmp = CreateBitmap(10, 10, 6, 6, NULL);
105  ok(hbmp == 0, "CreateBitmap should fail\n");
107 
108  SetLastError(0);
109  hbmp = CreateBitmap(10, 10, 8, 8, NULL);
110  ok(hbmp == 0, "CreateBitmap should fail\n");
112 
113 }
114 
116 {
117  HBITMAP hbmp;
118  BITMAP bitmap;
119  ULONG cjWidthBytes, cBitsPixel, cExpectedBitsPixel;
120  int result, TestBitsPixel, ExpectedBitsPixel;
121 
122  hbmp = CreateBitmap(0, 0, 0, 0, NULL);
123  ok(hbmp != 0, "should get a 1x1 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);
134 
135  /* Above 32 bpp should fail */
136  hbmp = CreateBitmap(1, 2, 1, 33, NULL);
137  ok(hbmp == 0, "should fail\n");
138 
139  for (TestBitsPixel = 0; TestBitsPixel <= 32; TestBitsPixel++)
140  {
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;
149 
150  /* Calculate proper bmWidthBytes */
151 
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);
163  }
164 
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);
176 
177  for (cBitsPixel = 0; cBitsPixel <= 32; cBitsPixel++)
178  {
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;
187 
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));
191 
192  /* calculate expected line width */
193  cjWidthBytes = ((((ULONG)bitmap.bmWidth) * ((ULONG)bitmap.bmBitsPixel) + 15) & ~15) >> 3;
194 
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);
203 
204  }
205 
206  hbmp = CreateBitmap(1, 2, 1, 33, NULL);
207  ok(hbmp == 0, "Expected failure for 33 bpp\n");
208 
209 
210 
211 }
212 
214 {
217 
218 }
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
void Test_CreateBitmap()
Definition: CreateBitmap.c:115
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
#define ok_ptr(expression, result)
Definition: atltest.h:108
smooth NULL
Definition: ftsmooth.c:416
#define ok_int(expression, result)
Definition: atltest.h:134
#define DEFAULT_BITMAP
Definition: ntgdityp.h:194
HBITMAP hbmp
Definition: uimain.c:88
#define SetLastError(x)
Definition: compat.h:409
START_TEST(CreateBitmap)
Definition: CreateBitmap.c:213
#define GetObject
Definition: wingdi.h:4463
#define ok_err(error)
Definition: atltest.h:124
#define ok(value,...)
Definition: atltest.h:57
Definition: bl.h:1331
unsigned int ULONG
Definition: retypes.h:1
static HBITMAP bitmap
Definition: clipboard.c:1344
static HBITMAP
Definition: button.c:44
GLuint64EXT * result
Definition: glext.h:11304
void Test_CreateBitmap_Params()
Definition: CreateBitmap.c:10
HBITMAP WINAPI CreateBitmap(_In_ INT cx, _In_ INT cy, _In_ UINT cPlanes, _In_ UINT cBitsPerPel, _In_opt_ const VOID *pvBits)