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