e4da9ee91adb84f67d93f1e0bb435b9bbc9d5d84
[reactos.git] / rostests / apitests / gdi32 / CreateBitmap.c
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 <wine/test.h>
9 #include <wingdi.h>
10
11 #define DEFAULT_BITMAP 21
12
13 void Test_CreateBitmap_Params()
14 {
15 HBITMAP hbmp;
16
17 /* All of these should get us the default bitmap */
18 hbmp = CreateBitmap(0, 0, 0, 0, NULL);
19 ok(hbmp == GetStockObject(21), "should get the default bitmap\n");
20 hbmp = CreateBitmap(1, 0, 0, 0, NULL);
21 ok(hbmp == GetStockObject(21), "should get the default bitmap\n");
22 hbmp = CreateBitmap(0, 1, 0, 0, NULL);
23 ok(hbmp == GetStockObject(21), "should get the default bitmap\n");
24 hbmp = CreateBitmap(0, 1, 1, 0, NULL);
25 ok(hbmp == GetStockObject(21), "should get the default bitmap\n");
26 hbmp = CreateBitmap(0, 1, 63, 33, NULL);
27 ok(hbmp == GetStockObject(21), "should get the default bitmap\n");
28 hbmp = CreateBitmap(0, -4, -32, 233, NULL);
29 ok(hbmp == GetStockObject(21), "should get the default bitmap\n");
30
31 SetLastError(0);
32 hbmp = CreateBitmap(1, -1, 1, 0, NULL);
33 ok(hbmp == 0, "\n");
34 ok_err(ERROR_INVALID_PARAMETER);
35
36 SetLastError(0);
37 hbmp = CreateBitmap(-1, 1, 1, 0, NULL);
38 ok(hbmp == 0, "\n");
39 ok_err(ERROR_INVALID_PARAMETER);
40
41 SetLastError(0);
42 hbmp = CreateBitmap(-1, 1, 1, 1, NULL);
43 ok(hbmp == 0, "\n");
44 ok_err(ERROR_INVALID_PARAMETER);
45
46 SetLastError(0);
47 hbmp = CreateBitmap(1, -1, 1, 1, NULL);
48 ok(hbmp == 0, "\n");
49 ok_err(ERROR_INVALID_PARAMETER);
50
51 /* Check if an overflow in cPlanes * cBitsPixel is handled */
52 SetLastError(0);
53 hbmp = CreateBitmap(1, 1, 2, 0x80000004, NULL);
54 ok(hbmp == 0, "\n");
55 ok_err(ERROR_INVALID_PARAMETER);
56
57 /* Check for maximum width */
58 hbmp = CreateBitmap(0x7FFFFFF, 1, 1, 1, NULL);
59 ok(hbmp != 0, "\n");
60 DeleteObject(hbmp);
61
62 SetLastError(0);
63 hbmp = CreateBitmap(0x8000000, 1, 1, 1, NULL);
64 ok(hbmp == 0, "\n");
65 ok_err(ERROR_INVALID_PARAMETER);
66
67 /* Check for maximum height */
68 hbmp = CreateBitmap(1, 0x1FFFFF00, 1, 1, NULL);
69 //ok(hbmp != 0, "\n"); // fails on windows 2003
70 DeleteObject(hbmp);
71
72 SetLastError(0);
73 hbmp = CreateBitmap(1, 0x1FFFFFFF, 1, 1, NULL);
74 ok(hbmp == 0, "\n");
75 ok_err(0);
76
77 /* Check for overflow in width * height */
78 hbmp = CreateBitmap(0x20000, 0x1FFFF, 1, 1, NULL);
79 //ok(hbmp != 0, "\n"); // fails on windows 2003
80 DeleteObject(hbmp);
81
82 SetLastError(0);
83 hbmp = CreateBitmap(0x20000, 0x20000, 1, 1, NULL);
84 ok(hbmp == 0, "\n");
85 ok_err(0);
86
87 /* Check huge allocation */
88 SetLastError(0);
89 hbmp = CreateBitmap(0x2000, 0x20000, 32, 1, NULL);
90 ok(hbmp == 0, "\n");
91 ok_err(ERROR_INVALID_PARAMETER);
92
93 }
94
95 void Test_CreateBitmap()
96 {
97 HBITMAP hbmp;
98 BITMAP bitmap;
99 ULONG cjWidthBytes, cBitsPixel, cExpectedBitsPixel;
100
101 hbmp = CreateBitmap(0, 0, 0, 0, NULL);
102 ok(hbmp != 0, "should get a 1x1 bitmap\n");
103 ok(hbmp == GetStockObject(DEFAULT_BITMAP), "\n");
104 ok_int(GetObject(hbmp, sizeof(bitmap), &bitmap), sizeof(BITMAP));
105 ok_int(bitmap.bmType, 0);
106 ok_int(bitmap.bmWidth, 1);
107 ok_int(bitmap.bmHeight, 1);
108 ok_int(bitmap.bmWidthBytes, 2);
109 ok_int(bitmap.bmPlanes, 1);
110 ok_int(bitmap.bmBitsPixel, 1);
111 ok_ptr(bitmap.bmBits, 0);
112 DeleteObject(hbmp);
113
114 hbmp = CreateBitmap(1, 2, 1, 1, NULL);
115 ok(hbmp != 0, "should get a 1x2 bitmap\n");
116 ok_int(GetObject(hbmp, sizeof(bitmap), &bitmap), sizeof(BITMAP));
117 ok_int(bitmap.bmType, 0);
118 ok_int(bitmap.bmWidth, 1);
119 ok_int(bitmap.bmHeight, 2);
120 ok_int(bitmap.bmWidthBytes, 2);
121 ok_int(bitmap.bmPlanes, 1);
122 ok_int(bitmap.bmBitsPixel, 1);
123 ok_ptr(bitmap.bmBits, 0);
124 DeleteObject(hbmp);
125
126 for (cBitsPixel = 0; cBitsPixel <= 32; cBitsPixel++)
127 {
128 /* CreateBitmap API accepts any number as BitsPixels param.
129 but it just can create 1, 4, 8, 16, 24, 32 bpp Bitmaps */
130 if (cBitsPixel <= 1) cExpectedBitsPixel = 1;
131 else if (cBitsPixel <= 4) cExpectedBitsPixel = 4;
132 else if (cBitsPixel <= 8) cExpectedBitsPixel = 8;
133 else if (cBitsPixel <= 16) cExpectedBitsPixel = 16;
134 else if (cBitsPixel <= 24) cExpectedBitsPixel = 24;
135 else if (cBitsPixel <= 32) cExpectedBitsPixel = 32;
136
137 hbmp = CreateBitmap(1, 2, 1, cBitsPixel, NULL);
138 ok(hbmp != 0, "should get a 1x2 bitmap %ld\n", cBitsPixel);
139 ok_int(GetObject(hbmp, sizeof(bitmap), &bitmap), sizeof(BITMAP));
140
141 /* calculate expected line width */
142 cjWidthBytes = ((((ULONG)bitmap.bmWidth) * ((ULONG)bitmap.bmBitsPixel) + 15) & ~15) >> 3;
143
144 ok_int(bitmap.bmType, 0);
145 ok_int(bitmap.bmWidth, 1);
146 ok_int(bitmap.bmHeight, 2);
147 ok_int(bitmap.bmPlanes, 1);
148 ok_int(bitmap.bmBitsPixel, cExpectedBitsPixel);
149 ok_int(bitmap.bmWidthBytes, cjWidthBytes);
150 ok_ptr(bitmap.bmBits, 0);
151 DeleteObject(hbmp);
152
153 }
154
155 hbmp = CreateBitmap(1, 2, 1, 33, NULL);
156 ok(hbmp == 0, "Expected failure for 33 bpp\n");
157
158
159
160 }
161
162 START_TEST(CreateBitmap)
163 {
164 //Test_CreateBitmap_Params();
165 Test_CreateBitmap();
166
167 }