27100a7fdd36dbd6adc81650087fe76d91715ba3
[reactos.git] / modules / rostests / apitests / win32nt / ntgdi / NtGdiCreateBitmap.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for NtGdiCreateBitmap
5 * PROGRAMMERS:
6 */
7
8 #include <win32nt.h>
9
10 void Test_NtGdiCreateBitmap_Params(void)
11 {
12 HBITMAP hBmp;
13 BITMAP bitmap;
14 BYTE BitmapData[10] = {0x11, 0x22, 0x33};
15
16 /* Test simple params */
17 SetLastError(ERROR_SUCCESS);
18 TEST((hBmp = NtGdiCreateBitmap(1, 1, 1, 1, NULL)) != NULL);
19 TEST(GetLastError() == ERROR_SUCCESS);
20 DeleteObject(hBmp);
21
22 /* Test all zero */
23 SetLastError(ERROR_SUCCESS);
24 TEST(NtGdiCreateBitmap(0, 0, 0, 0, NULL) == NULL);
25 TEST(GetLastError() == ERROR_INVALID_PARAMETER);
26
27 /* Test cx == 0 */
28 SetLastError(ERROR_SUCCESS);
29 TEST(NtGdiCreateBitmap(0, 1, 1, 1, NULL) == NULL);
30 TEST(GetLastError() == ERROR_INVALID_PARAMETER);
31
32 /* Test negative cx */
33 SetLastError(ERROR_SUCCESS);
34 TEST(NtGdiCreateBitmap(-10, 1, 1, 1, NULL) == NULL);
35 TEST(GetLastError() == ERROR_INVALID_PARAMETER);
36
37 /* Test cy == 0 */
38 SetLastError(ERROR_SUCCESS);
39 TEST(NtGdiCreateBitmap(1, 0, 1, 1, NULL) == NULL);
40 TEST(GetLastError() == ERROR_INVALID_PARAMETER);
41
42 /* Test negative cy */
43 SetLastError(ERROR_SUCCESS);
44 TEST(NtGdiCreateBitmap(1, -2, 1, 1, NULL) == NULL);
45 TEST(GetLastError() == ERROR_INVALID_PARAMETER);
46
47 /* Test negative cy and valid bits */
48 SetLastError(ERROR_SUCCESS);
49 TEST(NtGdiCreateBitmap(1, -2, 1, 1, BitmapData) == NULL);
50 TEST(GetLastError() == ERROR_SUCCESS);
51
52 /* Test negative cy and invalid bits */
53 SetLastError(ERROR_SUCCESS);
54 TEST(NtGdiCreateBitmap(1, -2, 1, 1, (BYTE*)0x80001234) == NULL);
55 TEST(GetLastError() == ERROR_SUCCESS);
56
57 /* Test huge size */
58 SetLastError(ERROR_SUCCESS);
59 TEST(NtGdiCreateBitmap(100000, 100000, 1, 1, NULL) == NULL);
60 TEST(GetLastError() == ERROR_NOT_ENOUGH_MEMORY);
61
62 /* Test huge size and valid bits */
63 SetLastError(ERROR_SUCCESS);
64 TEST(NtGdiCreateBitmap(1000, 1000, 1, 1, BitmapData) == NULL);
65 TEST(GetLastError() == ERROR_SUCCESS);
66
67 /* Test huge size and invalid bits */
68 SetLastError(ERROR_SUCCESS);
69 TEST(NtGdiCreateBitmap(100000, 100000, 1, 1, (BYTE*)0x80001234) == NULL);
70 TEST(GetLastError() == ERROR_SUCCESS);
71
72 /* Test cPlanes == 0 */
73 SetLastError(ERROR_SUCCESS);
74 TEST((hBmp = NtGdiCreateBitmap(1, 1, 0, 1, NULL)) != NULL);
75 TEST(GetLastError() == ERROR_SUCCESS);
76 ASSERT(GetObject(hBmp, sizeof(BITMAP), &bitmap) == sizeof(BITMAP));
77 TEST(bitmap.bmType == 0);
78 TEST(bitmap.bmWidth == 1);
79 TEST(bitmap.bmHeight == 1);
80 TEST(bitmap.bmWidthBytes == 2);
81 TEST(bitmap.bmPlanes == 1);
82 TEST(bitmap.bmBitsPixel == 1);
83 DeleteObject(hBmp);
84
85 /* Test big cPlanes */
86 SetLastError(ERROR_SUCCESS);
87 TEST((hBmp = NtGdiCreateBitmap(1, 1, 32, 1, NULL)) != NULL);
88 TEST(GetLastError() == ERROR_SUCCESS);
89 DeleteObject(hBmp);
90
91 TEST(NtGdiCreateBitmap(1, 1, 33, 1, NULL) == NULL);
92 TEST(GetLastError() == ERROR_INVALID_PARAMETER);
93
94 /* Test cBPP == 0 */
95 SetLastError(ERROR_SUCCESS);
96 TEST((hBmp = NtGdiCreateBitmap(1, 1, 1, 0, NULL)) != NULL);
97 TEST(GetLastError() == ERROR_SUCCESS);
98 ASSERT(GetObject(hBmp, sizeof(BITMAP), &bitmap) == sizeof(BITMAP));
99 TEST(bitmap.bmType == 0);
100 TEST(bitmap.bmWidth == 1);
101 TEST(bitmap.bmHeight == 1);
102 TEST(bitmap.bmWidthBytes == 2);
103 TEST(bitmap.bmPlanes == 1);
104 TEST(bitmap.bmBitsPixel == 1);
105 DeleteObject(hBmp);
106
107 /* Test negative cBPP */
108 SetLastError(ERROR_SUCCESS);
109 TEST(NtGdiCreateBitmap(1, 1, 1, -1, NULL) == NULL);
110 TEST(GetLastError() == ERROR_INVALID_PARAMETER);
111
112 /* Test bad cBPP */
113 SetLastError(ERROR_SUCCESS);
114 TEST((hBmp = NtGdiCreateBitmap(1, 1, 1, 3, NULL)) != NULL);
115 ASSERT(GetObject(hBmp, sizeof(BITMAP), &bitmap) == sizeof(BITMAP));
116 TEST(bitmap.bmBitsPixel == 4);
117 DeleteObject(hBmp);
118
119 TEST((hBmp = NtGdiCreateBitmap(1, 1, 1, 6, NULL)) != NULL);
120 ASSERT(GetObject(hBmp, sizeof(BITMAP), &bitmap) == sizeof(BITMAP));
121 TEST(bitmap.bmBitsPixel == 8);
122 DeleteObject(hBmp);
123
124 TEST((hBmp = NtGdiCreateBitmap(1, 1, 1, 15, NULL)) != NULL);
125 ASSERT(GetObject(hBmp, sizeof(BITMAP), &bitmap) == sizeof(BITMAP));
126 TEST(bitmap.bmBitsPixel == 16);
127 DeleteObject(hBmp);
128
129 TEST((hBmp = NtGdiCreateBitmap(1, 1, 1, 17, NULL)) != NULL);
130 ASSERT(GetObject(hBmp, sizeof(BITMAP), &bitmap) == sizeof(BITMAP));
131 TEST(bitmap.bmBitsPixel == 24);
132 DeleteObject(hBmp);
133
134 TEST((hBmp = NtGdiCreateBitmap(1, 1, 3, 7, NULL)) != NULL);
135 ASSERT(GetObject(hBmp, sizeof(BITMAP), &bitmap) == sizeof(BITMAP));
136 TEST(bitmap.bmBitsPixel == 24);
137 DeleteObject(hBmp);
138
139 TEST((hBmp = NtGdiCreateBitmap(1, 1, 1, 25, NULL)) != NULL);
140 ASSERT(GetObject(hBmp, sizeof(BITMAP), &bitmap) == sizeof(BITMAP));
141 TEST(bitmap.bmBitsPixel == 32);
142 DeleteObject(hBmp);
143
144 TEST(GetLastError() == ERROR_SUCCESS);
145
146 TEST(NtGdiCreateBitmap(1, 1, 1, 33, NULL) == NULL);
147 TEST(GetLastError() == ERROR_INVALID_PARAMETER);
148
149 /* Test bad pointer */
150 SetLastError(ERROR_SUCCESS);
151 TEST(NtGdiCreateBitmap(1, 1, 1, 1, (BYTE*)0x80001234) == NULL);
152 TEST(GetLastError() == ERROR_SUCCESS);
153
154 /* Test pointer alignment */
155 SetLastError(ERROR_SUCCESS);
156 TEST((hBmp = NtGdiCreateBitmap(1, 1, 1, 1, &BitmapData[1])) != NULL);
157 TEST(GetLastError() == ERROR_SUCCESS);
158 DeleteObject(hBmp);
159
160 /* Test normal params */
161 SetLastError(ERROR_SUCCESS);
162 TEST((hBmp = NtGdiCreateBitmap(5, 7, 2, 4, NULL)) != NULL);
163 TEST(GetLastError() == ERROR_SUCCESS);
164 ASSERT(GetObject(hBmp, sizeof(BITMAP), &bitmap) == sizeof(BITMAP));
165 TEST(bitmap.bmType == 0);
166 TEST(bitmap.bmWidth == 5);
167 TEST(bitmap.bmHeight == 7);
168 TEST(bitmap.bmWidthBytes == 6);
169 TEST(bitmap.bmPlanes == 1);
170 TEST(bitmap.bmBitsPixel == 8);
171 DeleteObject(hBmp);
172
173
174 /* Test height 0 params */
175 SetLastError(ERROR_SUCCESS);
176 TEST(NtGdiCreateBitmap(1, 0, 1, 1, NULL) == NULL);
177 TEST(GetLastError() == ERROR_INVALID_PARAMETER);
178
179 /* Test height -1 params */
180 SetLastError(ERROR_SUCCESS);
181 TEST(NtGdiCreateBitmap(1, -1, 1, 1, NULL) == NULL);
182 TEST(GetLastError() == ERROR_INVALID_PARAMETER);
183
184 /* Test witdth 0 params */
185 SetLastError(ERROR_SUCCESS);
186 TEST(NtGdiCreateBitmap(0, 1, 1, 1, NULL) == NULL);
187 TEST(GetLastError() == ERROR_INVALID_PARAMETER);
188
189 /* Test witdth -1 params */
190 SetLastError(ERROR_SUCCESS);
191 TEST(NtGdiCreateBitmap(-1, 0, 1, 1, NULL) == NULL);
192 TEST(GetLastError() == ERROR_INVALID_PARAMETER);
193
194
195 /* Test witdth -1 params */
196 SetLastError(ERROR_SUCCESS);
197 TEST(NtGdiCreateBitmap(0, 0, 1, 1, NULL) == NULL);
198 TEST(GetLastError() == ERROR_INVALID_PARAMETER);
199 }
200
201 START_TEST(NtGdiCreateBitmap)
202 {
203
204 Test_NtGdiCreateBitmap_Params();
205 // Test_NtGdiCreateBitmap_Pixel();
206
207 }