ReactOS  0.4.15-dev-320-g2dc9f0a
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 
121  hbmp = CreateBitmap(0, 0, 0, 0, NULL);
122  ok(hbmp != 0, "should get a 1x1 bitmap\n");
124  ok_int(GetObject(hbmp, sizeof(bitmap), &bitmap), sizeof(BITMAP));
125  ok_int(bitmap.bmType, 0);
126  ok_int(bitmap.bmWidth, 1);
127  ok_int(bitmap.bmHeight, 1);
128  ok_int(bitmap.bmWidthBytes, 2);
129  ok_int(bitmap.bmPlanes, 1);
130  ok_int(bitmap.bmBitsPixel, 1);
131  ok_ptr(bitmap.bmBits, 0);
133 
134  /* Above 32 bpp should fail */
135  hbmp = CreateBitmap(1, 2, 1, 33, NULL);
136  ok(hbmp == 0, "should fail\n");
137 
138  hbmp = CreateBitmap(1, 2, 1, 1, NULL);
139  ok(hbmp != 0, "should get a 1x2 bitmap\n");
140  ok_int(GetObject(hbmp, sizeof(bitmap), &bitmap), sizeof(BITMAP));
141  ok_int(bitmap.bmType, 0);
142  ok_int(bitmap.bmWidth, 1);
143  ok_int(bitmap.bmHeight, 2);
144  ok_int(bitmap.bmWidthBytes, 2);
145  ok_int(bitmap.bmPlanes, 1);
146  ok_int(bitmap.bmBitsPixel, 1);
147  ok_ptr(bitmap.bmBits, 0);
149 
150  for (cBitsPixel = 0; cBitsPixel <= 32; cBitsPixel++)
151  {
152  /* CreateBitmap API accepts any number as BitsPixels param.
153  but it can only create 1, 4, 8, 16, 24, 32 bpp bitmaps */
154  if (cBitsPixel <= 1) cExpectedBitsPixel = 1;
155  else if (cBitsPixel <= 4) cExpectedBitsPixel = 4;
156  else if (cBitsPixel <= 8) cExpectedBitsPixel = 8;
157  else if (cBitsPixel <= 16) cExpectedBitsPixel = 16;
158  else if (cBitsPixel <= 24) cExpectedBitsPixel = 24;
159  else if (cBitsPixel <= 32) cExpectedBitsPixel = 32;
160 
161  hbmp = CreateBitmap(1, 2, 1, cBitsPixel, NULL);
162  ok(hbmp != 0, "should get a 1x2 bitmap %ld\n", cBitsPixel);
163  ok_int(GetObject(hbmp, sizeof(bitmap), &bitmap), sizeof(BITMAP));
164 
165  /* Calculate expected line width */
166  cjWidthBytes = ((bitmap.bmWidth * bitmap.bmBitsPixel + 15) & ~15) >> 3;
167 
168  ok_int(bitmap.bmType, 0);
169  ok_int(bitmap.bmWidth, 1);
170  ok_int(bitmap.bmHeight, 2);
171  ok_int(bitmap.bmPlanes, 1);
172  ok_int(bitmap.bmBitsPixel, cExpectedBitsPixel);
173  ok_int(bitmap.bmWidthBytes, cjWidthBytes);
174  ok_ptr(bitmap.bmBits, 0);
176  }
177 
178  hbmp = CreateBitmap(1, 2, 1, 33, NULL);
179  ok(hbmp == 0, "Expected failure for 33 bpp\n");
180 }
181 
183 {
186 
187 }
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:195
HBITMAP hbmp
Definition: uimain.c:88
#define SetLastError(x)
Definition: compat.h:418
START_TEST(CreateBitmap)
Definition: CreateBitmap.c:182
#define GetObject
Definition: wingdi.h:4467
#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
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)