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