1 /* 2 * PROJECT: ReactOS api tests 3 * LICENSE: GPL - See COPYING in the top level directory 4 * PURPOSE: Test for NtGdiSetBitmapBits 5 * PROGRAMMERS: Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com> 6 */ 7 8 #include "../win32nt.h" 9 10 START_TEST(NtGdiSetBitmapBits) 11 { 12 BYTE Bits[100] = {0,1,2,3,4,5,6,7,8,9}; 13 HBITMAP hBitmap; 14 HDC hDC; 15 BITMAPINFO bmi; 16 LPVOID pvBits; 17 LPBYTE LargeBits; 18 19 SetLastError(0xDEADFACE); 20 ok_long(NtGdiSetBitmapBits(0, 0, 0), 0); 21 ok_long(GetLastError(), 0xDEADFACE); 22 23 /* Test NULL bitnap handle */ 24 SetLastError(0xDEADFACE); 25 ok_long(NtGdiSetBitmapBits(0, 5, Bits), 0); 26 ok_long(GetLastError(), ERROR_INVALID_HANDLE); 27 28 /* Test invalid bitmap handle */ 29 hBitmap = (HBITMAP)CreatePen(PS_SOLID, 1, RGB(1,2,3)); 30 SetLastError(0xDEADFACE); 31 ok_long(NtGdiSetBitmapBits(hBitmap, 5, Bits), 0); 32 ok_long(GetLastError(), ERROR_INVALID_HANDLE); 33 DeleteObject(hBitmap); 34 35 hBitmap = CreateBitmap(3, 3, 1, 8, NULL); 36 ok(hBitmap != NULL, "hBitmap was NULL.\n"); 37 38 /* test NULL pointer and count buffer size != 0 */ 39 SetLastError(0xDEADFACE); 40 ok_long(NtGdiSetBitmapBits(hBitmap, 5, NULL), 0); 41 ok_long(GetLastError(), 0xDEADFACE); 42 43 /* test NULL pointer and buffer size == 0*/ 44 SetLastError(0xDEADFACE); 45 ok_long(NtGdiSetBitmapBits(hBitmap, 0, NULL), 0); 46 ok_long(GetLastError(), 0xDEADFACE); 47 48 /* test bad pointer */ 49 SetLastError(0xDEADFACE); 50 ok_long(NtGdiSetBitmapBits(hBitmap, 5, (PBYTE)0x500), 0); 51 ok_long(GetLastError(), 0xDEADFACE); 52 53 /* Test if we can set a number of bytes between lines */ 54 SetLastError(0xDEADFACE); 55 ok_long(NtGdiSetBitmapBits(hBitmap, 5, Bits), 5); 56 ok_long(GetLastError(), 0xDEADFACE); 57 58 /* Test alignment */ 59 SetLastError(0xDEADFACE); 60 ok_long(NtGdiSetBitmapBits(hBitmap, 4, Bits+1), 4); 61 ok_long(GetLastError(), 0xDEADFACE); 62 63 /* Test 1 byte too much */ 64 SetLastError(0xDEADFACE); 65 ok_long(NtGdiSetBitmapBits(hBitmap, 10, Bits), 10); 66 ok_long(GetLastError(), 0xDEADFACE); 67 68 /* Test one row too much */ 69 SetLastError(0xDEADFACE); 70 ok_long(NtGdiSetBitmapBits(hBitmap, 12, Bits), 12); 71 ok_long(GetLastError(), 0xDEADFACE); 72 73 SetLastError(0xDEADFACE); 74 ok_long(NtGdiSetBitmapBits(hBitmap, 13, Bits), 12); 75 ok_long(GetLastError(), 0xDEADFACE); 76 77 SetLastError(0xDEADFACE); 78 ok_long(NtGdiSetBitmapBits(hBitmap, 100, Bits), 12); 79 ok_long(GetLastError(), 0xDEADFACE); 80 81 /* Test large byte counts (with PAGE_NOACCESS) */ 82 LargeBits = VirtualAlloc(NULL, 0x100000 + PAGE_SIZE, MEM_RESERVE, PAGE_NOACCESS); 83 VirtualAlloc(LargeBits, 0x100000, MEM_COMMIT, PAGE_READWRITE); 84 CopyMemory(LargeBits, Bits, sizeof(Bits)); 85 86 SetLastError(0xDEADFACE); 87 ok_long(NtGdiSetBitmapBits(hBitmap, 0x100, LargeBits), 0xC); 88 ok_long(GetLastError(), 0xDEADFACE); 89 90 SetLastError(0xDEADFACE); 91 ok_long(NtGdiSetBitmapBits(hBitmap, 0x10000, LargeBits), 0xC); 92 ok_long(GetLastError(), 0xDEADFACE); 93 94 SetLastError(0xDEADFACE); 95 ok_long(NtGdiSetBitmapBits(hBitmap, 0x100000, LargeBits), 0xC); 96 ok_long(GetLastError(), 0xDEADFACE); 97 98 SetLastError(0xDEADFACE); 99 ok_long(NtGdiSetBitmapBits(hBitmap, 0x100001, LargeBits), 0x0); 100 ok_long(GetLastError(), 0xDEADFACE); 101 102 VirtualFree(LargeBits, 0, MEM_RELEASE); 103 104 /* Test large byte counts (with PAGE_READONLY) */ 105 LargeBits = VirtualAlloc(NULL, 0x100000 + PAGE_SIZE, MEM_RESERVE, PAGE_READONLY); 106 VirtualAlloc(LargeBits, 0x100000, MEM_COMMIT, PAGE_READWRITE); 107 CopyMemory(LargeBits, Bits, sizeof(Bits)); 108 109 SetLastError(0xDEADFACE); 110 ok_long(NtGdiSetBitmapBits(hBitmap, 0x100, LargeBits), 0xC); 111 ok_long(GetLastError(), 0xDEADFACE); 112 113 SetLastError(0xDEADFACE); 114 ok_long(NtGdiSetBitmapBits(hBitmap, 0x10000, LargeBits), 0xC); 115 ok_long(GetLastError(), 0xDEADFACE); 116 117 SetLastError(0xDEADFACE); 118 ok_long(NtGdiSetBitmapBits(hBitmap, 0x100000, LargeBits), 0xC); 119 ok_long(GetLastError(), 0xDEADFACE); 120 121 SetLastError(0xDEADFACE); 122 ok_long(NtGdiSetBitmapBits(hBitmap, 0x100001, LargeBits), 0x0); 123 ok_long(GetLastError(), 0xDEADFACE); 124 125 VirtualFree(LargeBits, 0, MEM_RELEASE); 126 127 DeleteObject(hBitmap); 128 129 /* ------------------------- */ 130 131 hBitmap = CreateBitmap(16, 16, 1, 1, NULL); 132 ok(hBitmap != NULL, "hBitmap was NULL.\n"); 133 134 FillMemory(Bits, sizeof(Bits), 0x55); 135 SetLastError(0xDEADFACE); 136 ok_long(NtGdiGetBitmapBits(hBitmap, 0, Bits), 0); 137 ok_long(GetLastError(), 0xDEADFACE); 138 ok_int(Bits[0], 0x55); 139 140 FillMemory(Bits, sizeof(Bits), 0x55); 141 142 SetLastError(0xDEADFACE); 143 ok_long(NtGdiGetBitmapBits(hBitmap, 1, Bits), 1); 144 ok_long(GetLastError(), 0xDEADFACE); 145 ok_int(Bits[0], 0); 146 ok_int(Bits[1], 0x55); 147 148 FillMemory(Bits, sizeof(Bits), 0x55); 149 SetLastError(0xDEADFACE); 150 ok_long(NtGdiGetBitmapBits(hBitmap, 2, Bits), 2); 151 ok_long(GetLastError(), 0xDEADFACE); 152 ok_int(Bits[0], 0); 153 ok_int(Bits[1], 0); 154 ok_int(Bits[2], 0x55); 155 156 FillMemory(Bits, sizeof(Bits), 0x33); 157 SetLastError(0xDEADFACE); 158 ok_long(NtGdiSetBitmapBits(hBitmap, 10, Bits), 10); 159 ok_long(GetLastError(), 0xDEADFACE); 160 161 FillMemory(Bits, sizeof(Bits), 0xAA); 162 SetLastError(0xDEADFACE); 163 ok_long(NtGdiSetBitmapBits(hBitmap, 1, Bits), 1); 164 ok_long(GetLastError(), 0xDEADFACE); 165 FillMemory(Bits, sizeof(Bits), 0x55); 166 SetLastError(0xDEADFACE); 167 ok_long(NtGdiGetBitmapBits(hBitmap, 1, Bits), 1); 168 ok_long(GetLastError(), 0xDEADFACE); 169 ok_int(Bits[0], 0xAA); 170 ok_int(Bits[1], 0x55); 171 SetLastError(0xDEADFACE); 172 ok_long(NtGdiGetBitmapBits(hBitmap, 2, Bits), 2); 173 ok_long(GetLastError(), 0xDEADFACE); 174 ok_int(Bits[0], 0xAA); 175 ok_int(Bits[1], 0x33); 176 ok_int(Bits[2], 0x55); 177 178 FillMemory(Bits, sizeof(Bits), 0xAA); 179 SetLastError(0xDEADFACE); 180 ok_long(NtGdiSetBitmapBits(hBitmap, 2, Bits), 2); 181 ok_long(GetLastError(), 0xDEADFACE); 182 FillMemory(Bits, sizeof(Bits), 0x55); 183 SetLastError(0xDEADFACE); 184 ok_long(NtGdiGetBitmapBits(hBitmap, 2, Bits), 2); 185 ok_long(GetLastError(), 0xDEADFACE); 186 ok_int(Bits[0], 0xAA); 187 ok_int(Bits[1], 0xAA); 188 ok_int(Bits[2], 0x55); 189 SetLastError(0xDEADFACE); 190 ok_long(NtGdiGetBitmapBits(hBitmap, 3, Bits), 3); 191 ok_long(GetLastError(), 0xDEADFACE); 192 ok_int(Bits[0], 0xAA); 193 ok_int(Bits[1], 0xAA); 194 ok_int(Bits[2], 0x33); 195 ok_int(Bits[3], 0x55); 196 197 FillMemory(Bits, sizeof(Bits), 0xAA); 198 SetLastError(0xDEADFACE); 199 ok_long(NtGdiSetBitmapBits(hBitmap, 3, Bits), 3); 200 ok_long(GetLastError(), 0xDEADFACE); 201 FillMemory(Bits, sizeof(Bits), 0x55); 202 SetLastError(0xDEADFACE); 203 ok_long(NtGdiGetBitmapBits(hBitmap, 3, Bits), 3); 204 ok_long(GetLastError(), 0xDEADFACE); 205 ok_int(Bits[0], 0xAA); 206 ok_int(Bits[1], 0xAA); 207 ok_int(Bits[2], 0xAA); 208 ok_int(Bits[3], 0x55); 209 SetLastError(0xDEADFACE); 210 ok_long(NtGdiGetBitmapBits(hBitmap, 4, Bits), 4); 211 ok_long(GetLastError(), 0xDEADFACE); 212 ok_int(Bits[0], 0xAA); 213 ok_int(Bits[1], 0xAA); 214 ok_int(Bits[2], 0xAA); 215 ok_int(Bits[3], 0x33); 216 ok_int(Bits[4], 0x55); 217 218 DeleteObject(hBitmap); 219 220 /* ------------------------- */ 221 222 hDC = CreateCompatibleDC(NULL); 223 224 ZeroMemory(&bmi, sizeof(bmi)); 225 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 226 bmi.bmiHeader.biWidth = 15; 227 bmi.bmiHeader.biHeight = 15; /* positive */ 228 bmi.bmiHeader.biPlanes = 1; 229 bmi.bmiHeader.biBitCount = 24; 230 hBitmap = CreateDIBSection(hDC, &bmi, DIB_RGB_COLORS, &pvBits, NULL, 0); 231 ok(hBitmap != NULL, "hBitmap was NULL.\n"); 232 233 FillMemory(Bits, sizeof(Bits), 0x55); 234 SetLastError(0xDEADFACE); 235 ok_long(NtGdiGetBitmapBits(hBitmap, 0, Bits), 0); 236 ok_long(GetLastError(), 0xDEADFACE); 237 ok_int(Bits[0], 0x55); 238 239 FillMemory(Bits, sizeof(Bits), 0x55); 240 SetLastError(0xDEADFACE); 241 ok_long(NtGdiGetBitmapBits(hBitmap, 1, Bits), 1); 242 ok_long(GetLastError(), 0xDEADFACE); 243 ok_int(Bits[0], 0); 244 ok_int(Bits[1], 0x55); 245 246 FillMemory(Bits, sizeof(Bits), 0x55); 247 SetLastError(0xDEADFACE); 248 ok_long(NtGdiGetBitmapBits(hBitmap, 2, Bits), 2); 249 ok_long(GetLastError(), 0xDEADFACE); 250 ok_int(Bits[0], 0); 251 ok_int(Bits[1], 0); 252 ok_int(Bits[2], 0x55); 253 254 FillMemory(Bits, sizeof(Bits), 0x33); 255 SetLastError(0xDEADFACE); 256 ok_long(NtGdiSetBitmapBits(hBitmap, 10, Bits), 10); 257 ok_long(GetLastError(), 0xDEADFACE); 258 259 FillMemory(Bits, sizeof(Bits), 0xAA); 260 SetLastError(0xDEADFACE); 261 ok_long(NtGdiSetBitmapBits(hBitmap, 1, Bits), 1); 262 ok_long(GetLastError(), 0xDEADFACE); 263 FillMemory(Bits, sizeof(Bits), 0x55); 264 SetLastError(0xDEADFACE); 265 ok_long(NtGdiGetBitmapBits(hBitmap, 1, Bits), 1); 266 ok_long(GetLastError(), 0xDEADFACE); 267 ok_int(Bits[0], 0xAA); 268 ok_int(Bits[1], 0x55); 269 SetLastError(0xDEADFACE); 270 ok_long(NtGdiGetBitmapBits(hBitmap, 2, Bits), 2); 271 ok_long(GetLastError(), 0xDEADFACE); 272 ok_int(Bits[0], 0xAA); 273 ok_int(Bits[1], 0x33); 274 ok_int(Bits[2], 0x55); 275 276 FillMemory(Bits, sizeof(Bits), 0xAA); 277 SetLastError(0xDEADFACE); 278 ok_long(NtGdiSetBitmapBits(hBitmap, 2, Bits), 2); 279 ok_long(GetLastError(), 0xDEADFACE); 280 FillMemory(Bits, sizeof(Bits), 0x55); 281 SetLastError(0xDEADFACE); 282 ok_long(NtGdiGetBitmapBits(hBitmap, 2, Bits), 2); 283 ok_long(GetLastError(), 0xDEADFACE); 284 ok_int(Bits[0], 0xAA); 285 ok_int(Bits[1], 0xAA); 286 ok_int(Bits[2], 0x55); 287 SetLastError(0xDEADFACE); 288 ok_long(NtGdiGetBitmapBits(hBitmap, 3, Bits), 3); 289 ok_long(GetLastError(), 0xDEADFACE); 290 ok_int(Bits[0], 0xAA); 291 ok_int(Bits[1], 0xAA); 292 ok_int(Bits[2], 0x33); 293 ok_int(Bits[3], 0x55); 294 295 FillMemory(Bits, sizeof(Bits), 0xAA); 296 SetLastError(0xDEADFACE); 297 ok_long(NtGdiSetBitmapBits(hBitmap, 3, Bits), 3); 298 ok_long(GetLastError(), 0xDEADFACE); 299 FillMemory(Bits, sizeof(Bits), 0x55); 300 SetLastError(0xDEADFACE); 301 ok_long(NtGdiGetBitmapBits(hBitmap, 3, Bits), 3); 302 ok_long(GetLastError(), 0xDEADFACE); 303 ok_int(Bits[0], 0xAA); 304 ok_int(Bits[1], 0xAA); 305 ok_int(Bits[2], 0xAA); 306 ok_int(Bits[3], 0x55); 307 SetLastError(0xDEADFACE); 308 ok_long(NtGdiGetBitmapBits(hBitmap, 4, Bits), 4); 309 ok_long(GetLastError(), 0xDEADFACE); 310 ok_int(Bits[0], 0xAA); 311 ok_int(Bits[1], 0xAA); 312 ok_int(Bits[2], 0xAA); 313 ok_int(Bits[3], 0x33); 314 ok_int(Bits[4], 0x55); 315 316 ok_long(*(LPDWORD)pvBits, 0); 317 ok_long(((LPDWORD)pvBits)[1], 0); 318 319 DeleteObject(hBitmap); 320 DeleteDC(hDC); 321 322 /* ------------------------- */ 323 324 hDC = CreateCompatibleDC(NULL); 325 326 ZeroMemory(&bmi, sizeof(bmi)); 327 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 328 bmi.bmiHeader.biWidth = 15; 329 bmi.bmiHeader.biHeight = -15; /* negative */ 330 bmi.bmiHeader.biPlanes = 1; 331 bmi.bmiHeader.biBitCount = 24; 332 hBitmap = CreateDIBSection(hDC, &bmi, DIB_RGB_COLORS, &pvBits, NULL, 0); 333 ok(hBitmap != NULL, "hBitmap was NULL.\n"); 334 335 FillMemory(Bits, sizeof(Bits), 0x55); 336 SetLastError(0xDEADFACE); 337 ok_long(NtGdiGetBitmapBits(hBitmap, 0, Bits), 0); 338 ok_long(GetLastError(), 0xDEADFACE); 339 ok_int(Bits[0], 0x55); 340 341 FillMemory(Bits, sizeof(Bits), 0x55); 342 SetLastError(0xDEADFACE); 343 ok_long(NtGdiGetBitmapBits(hBitmap, 1, Bits), 1); 344 ok_long(GetLastError(), 0xDEADFACE); 345 ok_int(Bits[0], 0); 346 ok_int(Bits[1], 0x55); 347 348 FillMemory(Bits, sizeof(Bits), 0x55); 349 SetLastError(0xDEADFACE); 350 ok_long(NtGdiGetBitmapBits(hBitmap, 2, Bits), 2); 351 ok_long(GetLastError(), 0xDEADFACE); 352 ok_int(Bits[0], 0); 353 ok_int(Bits[1], 0); 354 ok_int(Bits[2], 0x55); 355 356 FillMemory(Bits, sizeof(Bits), 0x33); 357 SetLastError(0xDEADFACE); 358 ok_long(NtGdiSetBitmapBits(hBitmap, 10, Bits), 10); 359 ok_long(GetLastError(), 0xDEADFACE); 360 361 FillMemory(Bits, sizeof(Bits), 0xAA); 362 SetLastError(0xDEADFACE); 363 ok_long(NtGdiSetBitmapBits(hBitmap, 1, Bits), 1); 364 ok_long(GetLastError(), 0xDEADFACE); 365 FillMemory(Bits, sizeof(Bits), 0x55); 366 SetLastError(0xDEADFACE); 367 ok_long(NtGdiGetBitmapBits(hBitmap, 1, Bits), 1); 368 ok_long(GetLastError(), 0xDEADFACE); 369 ok_int(Bits[0], 0xAA); 370 ok_int(Bits[1], 0x55); 371 SetLastError(0xDEADFACE); 372 ok_long(NtGdiGetBitmapBits(hBitmap, 2, Bits), 2); 373 ok_long(GetLastError(), 0xDEADFACE); 374 ok_int(Bits[0], 0xAA); 375 ok_int(Bits[1], 0x33); 376 ok_int(Bits[2], 0x55); 377 378 FillMemory(Bits, sizeof(Bits), 0xAA); 379 SetLastError(0xDEADFACE); 380 ok_long(NtGdiSetBitmapBits(hBitmap, 2, Bits), 2); 381 ok_long(GetLastError(), 0xDEADFACE); 382 FillMemory(Bits, sizeof(Bits), 0x55); 383 SetLastError(0xDEADFACE); 384 ok_long(NtGdiGetBitmapBits(hBitmap, 2, Bits), 2); 385 ok_long(GetLastError(), 0xDEADFACE); 386 ok_int(Bits[0], 0xAA); 387 ok_int(Bits[1], 0xAA); 388 ok_int(Bits[2], 0x55); 389 SetLastError(0xDEADFACE); 390 ok_long(NtGdiGetBitmapBits(hBitmap, 3, Bits), 3); 391 ok_long(GetLastError(), 0xDEADFACE); 392 ok_int(Bits[0], 0xAA); 393 ok_int(Bits[1], 0xAA); 394 ok_int(Bits[2], 0x33); 395 ok_int(Bits[3], 0x55); 396 397 FillMemory(Bits, sizeof(Bits), 0xAA); 398 SetLastError(0xDEADFACE); 399 ok_long(NtGdiSetBitmapBits(hBitmap, 3, Bits), 3); 400 ok_long(GetLastError(), 0xDEADFACE); 401 FillMemory(Bits, sizeof(Bits), 0x55); 402 SetLastError(0xDEADFACE); 403 ok_long(NtGdiGetBitmapBits(hBitmap, 3, Bits), 3); 404 ok_long(GetLastError(), 0xDEADFACE); 405 ok_int(Bits[0], 0xAA); 406 ok_int(Bits[1], 0xAA); 407 ok_int(Bits[2], 0xAA); 408 ok_int(Bits[3], 0x55); 409 SetLastError(0xDEADFACE); 410 ok_long(NtGdiGetBitmapBits(hBitmap, 4, Bits), 4); 411 ok_long(GetLastError(), 0xDEADFACE); 412 ok_int(Bits[0], 0xAA); 413 ok_int(Bits[1], 0xAA); 414 ok_int(Bits[2], 0xAA); 415 ok_int(Bits[3], 0x33); 416 ok_int(Bits[4], 0x55); 417 418 ok_long(*(LPDWORD)pvBits, 0x33AAAAAA); 419 ok_long(((LPDWORD)pvBits)[1], 0x33333333); 420 421 DeleteObject(hBitmap); 422 DeleteDC(hDC); 423 } 424