1 2 #include "precomp.h" 3 #include <versionhelpers.h> 4 5 #include <pseh/pseh2.h> 6 7 static BOOL IsBroken = FALSE; 8 9 void 10 Test_RtlFindMostSignificantBit(void) 11 { 12 ok_int(RtlFindMostSignificantBit(0), -1); 13 14 ok_int(RtlFindMostSignificantBit(0x0000000000000001ULL), 0); 15 ok_int(RtlFindMostSignificantBit(0x0000000000000002ULL), 1); 16 ok_int(RtlFindMostSignificantBit(0x1000000000000000ULL), 60); 17 ok_int(RtlFindMostSignificantBit(0x8000000000000000ULL), 63); 18 ok_int(RtlFindMostSignificantBit(0x8000000000000001ULL), 63); 19 ok_int(RtlFindMostSignificantBit(0xFFFFFFFFFFFFFFFFULL), 63); 20 ok_int(RtlFindMostSignificantBit(0x0000000070000000ULL), 30); 21 } 22 23 void 24 Test_RtlFindLeastSignificantBit(void) 25 { 26 ok_int(RtlFindLeastSignificantBit(0), -1); 27 28 ok_int(RtlFindLeastSignificantBit(0x0000000000000001ULL), 0); 29 ok_int(RtlFindLeastSignificantBit(0x0000000000000002ULL), 1); 30 ok_int(RtlFindLeastSignificantBit(0x1000000000000000ULL), 60); 31 ok_int(RtlFindLeastSignificantBit(0x8000000000000000ULL), 63); 32 ok_int(RtlFindLeastSignificantBit(0x8000000000000000ULL), 63); 33 ok_int(RtlFindLeastSignificantBit(0xFFFFFFFFFFFFFFFFULL), 0); 34 ok_int(RtlFindLeastSignificantBit(0x0000000070000000ULL), 28); 35 } 36 37 void 38 Test_RtlInitializeBitMap(void) 39 { 40 RTL_BITMAP BitMapHeader; 41 ULONG Buffer[2]; 42 BOOLEAN Exception = FALSE; 43 44 _SEH2_TRY 45 { 46 RtlInitializeBitMap(NULL, NULL, 0); 47 } 48 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) 49 { 50 Exception = TRUE; 51 } 52 _SEH2_END; 53 ok_int(Exception, 1); 54 55 RtlInitializeBitMap(&BitMapHeader, NULL, -1); 56 ok_int(BitMapHeader.SizeOfBitMap, -1); 57 ok_ptr(BitMapHeader.Buffer, NULL); 58 59 memset(Buffer, 0xcc, sizeof(Buffer)); 60 RtlInitializeBitMap(&BitMapHeader, Buffer, 0); 61 ok_int(BitMapHeader.SizeOfBitMap, 0); 62 ok_ptr(BitMapHeader.Buffer, Buffer); 63 ok_hex(Buffer[0], 0xcccccccc); 64 65 RtlInitializeBitMap(&BitMapHeader, Buffer, 8); 66 ok_int(BitMapHeader.SizeOfBitMap, 8); 67 ok_hex(Buffer[0], 0xcccccccc); 68 } 69 70 void 71 Test_RtlClearAllBits(void) 72 { 73 RTL_BITMAP BitMapHeader; 74 ULONG *Buffer; 75 ULONG BufferSize = 2 * sizeof(*Buffer); 76 77 Buffer = AllocateGuarded(BufferSize); 78 RtlInitializeBitMap(&BitMapHeader, Buffer, 19); 79 memset(Buffer, 0xcc, BufferSize); 80 RtlClearAllBits(&BitMapHeader); 81 ok_hex(Buffer[0], 0x00000000); 82 ok_hex(Buffer[1], 0xcccccccc); 83 84 RtlInitializeBitMap(&BitMapHeader, Buffer, 0); 85 memset(Buffer, 0xcc, BufferSize); 86 RtlClearAllBits(&BitMapHeader); 87 ok_hex(Buffer[0], 0xcccccccc); 88 ok_hex(Buffer[1], 0xcccccccc); 89 90 RtlInitializeBitMap(&BitMapHeader, Buffer, 64); 91 memset(Buffer, 0xcc, BufferSize); 92 RtlClearAllBits(&BitMapHeader); 93 ok_hex(Buffer[0], 0x00000000); 94 ok_hex(Buffer[1], 0x00000000); 95 FreeGuarded(Buffer); 96 } 97 98 void 99 Test_RtlSetAllBits(void) 100 { 101 RTL_BITMAP BitMapHeader; 102 ULONG *Buffer; 103 ULONG BufferSize = 2 * sizeof(*Buffer); 104 105 Buffer = AllocateGuarded(BufferSize); 106 RtlInitializeBitMap(&BitMapHeader, Buffer, 19); 107 memset(Buffer, 0xcc, BufferSize); 108 RtlSetAllBits(&BitMapHeader); 109 ok_hex(Buffer[0], 0xffffffff); 110 ok_hex(Buffer[1], 0xcccccccc); 111 112 RtlInitializeBitMap(&BitMapHeader, Buffer, 0); 113 memset(Buffer, 0xcc, BufferSize); 114 RtlSetAllBits(&BitMapHeader); 115 ok_hex(Buffer[0], 0xcccccccc); 116 ok_hex(Buffer[1], 0xcccccccc); 117 118 RtlInitializeBitMap(&BitMapHeader, Buffer, 64); 119 memset(Buffer, 0xcc, BufferSize); 120 RtlSetAllBits(&BitMapHeader); 121 ok_hex(Buffer[0], 0xffffffff); 122 ok_hex(Buffer[1], 0xffffffff); 123 FreeGuarded(Buffer); 124 } 125 126 void 127 Test_RtlClearBits(void) 128 { 129 RTL_BITMAP BitMapHeader; 130 ULONG *Buffer; 131 ULONG BufferSize = 2 * sizeof(*Buffer); 132 133 Buffer = AllocateGuarded(BufferSize); 134 RtlInitializeBitMap(&BitMapHeader, Buffer, 19); 135 136 memset(Buffer, 0xff, BufferSize); 137 RtlClearBits(&BitMapHeader, 0, 0); 138 ok_hex(Buffer[0], 0xffffffff); 139 ok_hex(Buffer[1], 0xffffffff); 140 141 memset(Buffer, 0xff, BufferSize); 142 RtlClearBits(&BitMapHeader, 0, 1); 143 ok_hex(Buffer[0], 0xfffffffe); 144 ok_hex(Buffer[1], 0xffffffff); 145 146 memset(Buffer, 0xff, BufferSize); 147 RtlClearBits(&BitMapHeader, 21, 1); 148 ok_hex(Buffer[0], 0xffdfffff); 149 ok_hex(Buffer[1], 0xffffffff); 150 151 memset(Buffer, 0xff, BufferSize); 152 RtlClearBits(&BitMapHeader, 7, 9); 153 ok_hex(Buffer[0], 0xffff007f); 154 ok_hex(Buffer[1], 0xffffffff); 155 156 memset(Buffer, 0xff, BufferSize); 157 RtlClearBits(&BitMapHeader, 13, 22); 158 ok_hex(Buffer[0], 0x00001fff); 159 ok_hex(Buffer[1], 0xfffffff8); 160 161 memset(Buffer, 0xff, BufferSize); 162 RtlClearBits(&BitMapHeader, 63, 1); 163 ok_hex(Buffer[0], 0xffffffff); 164 ok_hex(Buffer[1], 0x7fffffff); 165 166 memset(Buffer, 0xcc, BufferSize); 167 RtlClearBits(&BitMapHeader, 3, 6); 168 RtlClearBits(&BitMapHeader, 11, 5); 169 RtlClearBits(&BitMapHeader, 21, 7); 170 RtlClearBits(&BitMapHeader, 37, 4); 171 ok_hex(Buffer[0], 0xc00c0404); 172 ok_hex(Buffer[1], 0xcccccc0c); 173 FreeGuarded(Buffer); 174 } 175 176 void 177 Test_RtlSetBits(void) 178 { 179 RTL_BITMAP BitMapHeader; 180 ULONG *Buffer; 181 ULONG BufferSize = 2 * sizeof(*Buffer); 182 183 Buffer = AllocateGuarded(BufferSize); 184 RtlInitializeBitMap(&BitMapHeader, Buffer, 19); 185 186 memset(Buffer, 0x00, BufferSize); 187 RtlSetBits(&BitMapHeader, 0, 0); 188 ok_hex(Buffer[0], 0x00000000); 189 ok_hex(Buffer[1], 0x00000000); 190 191 memset(Buffer, 0x00, BufferSize); 192 RtlSetBits(&BitMapHeader, 0, 1); 193 ok_hex(Buffer[0], 0x00000001); 194 ok_hex(Buffer[1], 0x00000000); 195 196 memset(Buffer, 0x00, BufferSize); 197 RtlSetBits(&BitMapHeader, 21, 1); 198 ok_hex(Buffer[0], 0x00200000); 199 ok_hex(Buffer[1], 0x00000000); 200 201 memset(Buffer, 0x00, BufferSize); 202 RtlSetBits(&BitMapHeader, 7, 9); 203 ok_hex(Buffer[0], 0x0000ff80); 204 ok_hex(Buffer[1], 0x00000000); 205 206 memset(Buffer, 0x00, BufferSize); 207 RtlSetBits(&BitMapHeader, 13, 22); 208 ok_hex(Buffer[0], 0xffffe000); 209 ok_hex(Buffer[1], 0x00000007); 210 211 memset(Buffer, 0x00, BufferSize); 212 RtlSetBits(&BitMapHeader, 63, 1); 213 ok_hex(Buffer[0], 0x00000000); 214 ok_hex(Buffer[1], 0x80000000); 215 216 memset(Buffer, 0xcc, BufferSize); 217 RtlSetBits(&BitMapHeader, 3, 6); 218 RtlSetBits(&BitMapHeader, 11, 5); 219 RtlSetBits(&BitMapHeader, 21, 7); 220 RtlSetBits(&BitMapHeader, 37, 4); 221 ok_hex(Buffer[0], 0xcfecfdfc); 222 ok_hex(Buffer[1], 0xcccccdec); 223 FreeGuarded(Buffer); 224 } 225 226 void 227 Test_RtlAreBitsClear(void) 228 { 229 RTL_BITMAP BitMapHeader; 230 ULONG *Buffer; 231 232 Buffer = AllocateGuarded(2 * sizeof(*Buffer)); 233 RtlInitializeBitMap(&BitMapHeader, Buffer, 19); 234 Buffer[0] = 0x00ff00ff; 235 Buffer[1] = 0xc0cfc0cf; 236 237 ok_hex(RtlAreBitsClear(&BitMapHeader, 0, 8), FALSE); 238 ok_hex(RtlAreBitsClear(&BitMapHeader, 8, 8), TRUE); 239 ok_hex(RtlAreBitsClear(&BitMapHeader, 7, 8), FALSE); 240 ok_hex(RtlAreBitsClear(&BitMapHeader, 8, 9), FALSE); 241 ok_hex(RtlAreBitsClear(&BitMapHeader, 24, 1), FALSE); 242 243 RtlInitializeBitMap(&BitMapHeader, Buffer, 31); 244 ok_hex(RtlAreBitsClear(&BitMapHeader, 24, 1), TRUE); 245 ok_hex(RtlAreBitsClear(&BitMapHeader, 24, 7), TRUE); 246 ok_hex(RtlAreBitsClear(&BitMapHeader, 24, 8), FALSE); 247 248 RtlInitializeBitMap(&BitMapHeader, Buffer, 64); 249 ok_hex(RtlAreBitsClear(&BitMapHeader, 60, 4), FALSE); 250 FreeGuarded(Buffer); 251 } 252 253 void 254 Test_RtlAreBitsSet(void) 255 { 256 RTL_BITMAP BitMapHeader; 257 ULONG *Buffer; 258 259 Buffer = AllocateGuarded(2 * sizeof(*Buffer)); 260 RtlInitializeBitMap(&BitMapHeader, Buffer, 19); 261 Buffer[0] = 0xff00ff00; 262 Buffer[1] = 0x3F303F30; 263 264 ok_hex(RtlAreBitsSet(&BitMapHeader, 0, 8), FALSE); 265 ok_hex(RtlAreBitsSet(&BitMapHeader, 8, 8), TRUE); 266 ok_hex(RtlAreBitsSet(&BitMapHeader, 7, 8), FALSE); 267 ok_hex(RtlAreBitsSet(&BitMapHeader, 8, 9), FALSE); 268 ok_hex(RtlAreBitsSet(&BitMapHeader, 24, 1), FALSE); 269 270 RtlInitializeBitMap(&BitMapHeader, Buffer, 31); 271 ok_hex(RtlAreBitsSet(&BitMapHeader, 24, 1), TRUE); 272 ok_hex(RtlAreBitsSet(&BitMapHeader, 24, 7), TRUE); 273 ok_hex(RtlAreBitsSet(&BitMapHeader, 24, 8), FALSE); 274 275 RtlInitializeBitMap(&BitMapHeader, Buffer, 64); 276 ok_hex(RtlAreBitsSet(&BitMapHeader, 60, 4), FALSE); 277 FreeGuarded(Buffer); 278 } 279 280 void 281 Test_RtlNumberOfSetBits(void) 282 { 283 RTL_BITMAP BitMapHeader; 284 ULONG *Buffer; 285 286 Buffer = AllocateGuarded(2 * sizeof(*Buffer)); 287 Buffer[0] = 0xff00ff0f; 288 Buffer[1] = 0x3F303F30; 289 290 RtlInitializeBitMap(&BitMapHeader, Buffer, 64); 291 ok_int(RtlNumberOfSetBits(&BitMapHeader), 36); 292 ok_hex(Buffer[0], 0xff00ff0f); 293 ok_hex(Buffer[1], 0x3F303F30); 294 295 RtlInitializeBitMap(&BitMapHeader, Buffer, 56); 296 ok_int(RtlNumberOfSetBits(&BitMapHeader), 30); 297 ok_hex(Buffer[0], 0xff00ff0f); 298 ok_hex(Buffer[1], 0x3F303F30); 299 300 RtlInitializeBitMap(&BitMapHeader, Buffer, 31); 301 ok_int(RtlNumberOfSetBits(&BitMapHeader), 19); 302 ok_hex(Buffer[0], IsBroken ? 0x7f00ff0f : 0xff00ff0f); 303 ok_hex(Buffer[1], 0x3F303F30); 304 305 RtlInitializeBitMap(&BitMapHeader, Buffer, 4); 306 ok_int(RtlNumberOfSetBits(&BitMapHeader), 4); 307 ok_hex(Buffer[0], IsBroken ? 0x7f00ff0f : 0xff00ff0f); 308 ok_hex(Buffer[1], 0x3F303F30); 309 310 RtlInitializeBitMap(&BitMapHeader, Buffer, 0); 311 ok_int(RtlNumberOfSetBits(&BitMapHeader), 0); 312 ok_hex(Buffer[0], IsBroken ? 0x7f00ff0f : 0xff00ff0f); 313 ok_hex(Buffer[1], 0x3F303F30); 314 315 FreeGuarded(Buffer); 316 } 317 318 void 319 Test_RtlNumberOfClearBits(void) 320 { 321 RTL_BITMAP BitMapHeader; 322 ULONG *Buffer; 323 324 Buffer = AllocateGuarded(2 * sizeof(*Buffer)); 325 Buffer[0] = 0xff00fff0; 326 Buffer[1] = 0x3F303F30; 327 328 RtlInitializeBitMap(&BitMapHeader, Buffer, 64); 329 ok_int(RtlNumberOfClearBits(&BitMapHeader), 28); 330 ok_hex(Buffer[0], 0xff00fff0); 331 ok_hex(Buffer[1], 0x3F303F30); 332 333 RtlInitializeBitMap(&BitMapHeader, Buffer, 56); 334 ok_int(RtlNumberOfClearBits(&BitMapHeader), 26); 335 ok_hex(Buffer[0], 0xff00fff0); 336 ok_hex(Buffer[1], 0x3F303F30); 337 338 RtlInitializeBitMap(&BitMapHeader, Buffer, 31); 339 ok_int(RtlNumberOfClearBits(&BitMapHeader), 12); 340 ok_hex(Buffer[0], IsBroken ? 0x7f00fff0 : 0xff00fff0); 341 ok_hex(Buffer[1], 0x3F303F30); 342 343 RtlInitializeBitMap(&BitMapHeader, Buffer, 4); 344 ok_int(RtlNumberOfClearBits(&BitMapHeader), 4); 345 ok_hex(Buffer[0], IsBroken ? 0x7f00ff00 : 0xff00fff0); 346 ok_hex(Buffer[1], 0x3F303F30); 347 348 RtlInitializeBitMap(&BitMapHeader, Buffer, 0); 349 ok_int(RtlNumberOfClearBits(&BitMapHeader), 0); 350 ok_hex(Buffer[0], IsBroken ? 0x7f00ff00 : 0xff00fff0); 351 ok_hex(Buffer[1], 0x3F303F30); 352 353 FreeGuarded(Buffer); 354 } 355 356 void 357 Test_RtlFindClearBits(void) 358 { 359 RTL_BITMAP BitMapHeader; 360 ULONG *Buffer; 361 362 Buffer = AllocateGuarded(2 * sizeof(*Buffer)); 363 Buffer[0] = 0x060F874D; 364 Buffer[1] = 0x3F303F30; 365 366 RtlInitializeBitMap(&BitMapHeader, Buffer, 0); 367 ok_int(RtlFindClearBits(&BitMapHeader, 0, 0), 0); 368 ok_int(RtlFindClearBits(&BitMapHeader, 0, 3), 0); 369 ok_int(RtlFindClearBits(&BitMapHeader, 1, 0), -1); 370 ok_int(RtlFindClearBits(&BitMapHeader, 1, 1), -1); 371 372 RtlInitializeBitMap(&BitMapHeader, Buffer, 8); 373 ok_int(RtlFindClearBits(&BitMapHeader, 0, 3), 0); 374 ok_int(RtlFindClearBits(&BitMapHeader, 1, 0), 1); 375 ok_int(RtlFindClearBits(&BitMapHeader, 1, 1), 1); 376 ok_int(RtlFindClearBits(&BitMapHeader, 1, 2), 4); 377 378 ok_int(RtlFindClearBits(&BitMapHeader, 2, 0), 4); 379 ok_int(RtlFindClearBits(&BitMapHeader, 3, 0), -1); 380 381 RtlInitializeBitMap(&BitMapHeader, Buffer, 32); 382 ok_int(RtlFindClearBits(&BitMapHeader, 0, 3), 0); 383 ok_int(RtlFindClearBits(&BitMapHeader, 0, 21), 16); 384 ok_int(RtlFindClearBits(&BitMapHeader, 0, 12), 8); 385 ok_int(RtlFindClearBits(&BitMapHeader, 0, 31), 24); 386 ok_int(RtlFindClearBits(&BitMapHeader, 0, 32), 0); 387 ok_int(RtlFindClearBits(&BitMapHeader, 0, 39), 0); 388 ok_int(RtlFindClearBits(&BitMapHeader, 4, 0), 11); 389 ok_int(RtlFindClearBits(&BitMapHeader, 5, 0), 20); 390 ok_int(RtlFindClearBits(&BitMapHeader, 4, 11), 11); 391 ok_int(RtlFindClearBits(&BitMapHeader, 4, 12), 20); 392 ok_int(RtlFindClearBits(&BitMapHeader, 2, 11), 11); 393 ok_int(RtlFindClearBits(&BitMapHeader, 2, 12), 12); 394 ok_int(RtlFindClearBits(&BitMapHeader, 1, 32), 1); 395 ok_int(RtlFindClearBits(&BitMapHeader, 4, 32), 11); 396 ok_int(RtlFindClearBits(&BitMapHeader, 5, 32), 20); 397 398 RtlInitializeBitMap(&BitMapHeader, Buffer, 64); 399 ok_int(RtlFindClearBits(&BitMapHeader, 5, 64), 20); 400 ok_int(RtlFindClearBits(&BitMapHeader, 9, 28), 27); 401 ok_int(RtlFindClearBits(&BitMapHeader, 10, 0), -1); 402 Buffer[1] = 0xFF303F30; 403 ok_int(RtlFindClearBits(&BitMapHeader, 1, 56), 1); 404 FreeGuarded(Buffer); 405 } 406 407 void 408 Test_RtlFindSetBits(void) 409 { 410 RTL_BITMAP BitMapHeader; 411 ULONG *Buffer; 412 413 Buffer = AllocateGuarded(2 * sizeof(*Buffer)); 414 Buffer[0] = 0xF9F078B2; 415 Buffer[1] = 0x3F303F30; 416 417 RtlInitializeBitMap(&BitMapHeader, Buffer, 0); 418 ok_int(RtlFindSetBits(&BitMapHeader, 0, 0), 0); 419 ok_int(RtlFindSetBits(&BitMapHeader, 0, 3), 0); 420 ok_int(RtlFindSetBits(&BitMapHeader, 1, 0), -1); 421 ok_int(RtlFindSetBits(&BitMapHeader, 1, 1), -1); 422 423 RtlInitializeBitMap(&BitMapHeader, Buffer, 8); 424 ok_int(RtlFindSetBits(&BitMapHeader, 0, 3), 0); 425 ok_int(RtlFindSetBits(&BitMapHeader, 1, 0), 1); 426 ok_int(RtlFindSetBits(&BitMapHeader, 1, 1), 1); 427 ok_int(RtlFindSetBits(&BitMapHeader, 1, 2), 4); 428 429 ok_int(RtlFindSetBits(&BitMapHeader, 2, 0), 4); 430 ok_int(RtlFindSetBits(&BitMapHeader, 3, 0), -1); 431 432 RtlInitializeBitMap(&BitMapHeader, Buffer, 32); 433 ok_int(RtlFindSetBits(&BitMapHeader, 0, 3), 0); 434 ok_int(RtlFindSetBits(&BitMapHeader, 0, 21), 16); 435 ok_int(RtlFindSetBits(&BitMapHeader, 0, 12), 8); 436 ok_int(RtlFindSetBits(&BitMapHeader, 0, 31), 24); 437 ok_int(RtlFindSetBits(&BitMapHeader, 0, 32), 0); 438 ok_int(RtlFindSetBits(&BitMapHeader, 0, 39), 0); 439 ok_int(RtlFindSetBits(&BitMapHeader, 4, 0), 11); 440 ok_int(RtlFindSetBits(&BitMapHeader, 5, 0), 20); 441 ok_int(RtlFindSetBits(&BitMapHeader, 4, 11), 11); 442 ok_int(RtlFindSetBits(&BitMapHeader, 4, 12), 20); 443 ok_int(RtlFindSetBits(&BitMapHeader, 2, 11), 11); 444 ok_int(RtlFindSetBits(&BitMapHeader, 1, 32), 1); 445 ok_int(RtlFindSetBits(&BitMapHeader, 4, 32), 11); 446 ok_int(RtlFindSetBits(&BitMapHeader, 5, 32), 20); 447 448 RtlInitializeBitMap(&BitMapHeader, Buffer, 64); 449 ok_int(RtlFindSetBits(&BitMapHeader, 5, 64), 20); 450 ok_int(RtlFindSetBits(&BitMapHeader, 6, 57), 40); 451 ok_int(RtlFindSetBits(&BitMapHeader, 7, 0), -1); 452 ok_int(RtlFindSetBits(&BitMapHeader, 1, 62), 1); 453 FreeGuarded(Buffer); 454 } 455 456 void 457 Test_RtlFindClearBitsAndSet(void) 458 { 459 RTL_BITMAP BitMapHeader; 460 ULONG *Buffer; 461 462 Buffer = AllocateGuarded(2 * sizeof(*Buffer)); 463 Buffer[0] = 0x060F874D; 464 Buffer[1] = 0x3F303F30; 465 466 RtlInitializeBitMap(&BitMapHeader, Buffer, 0); 467 ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 0, 0), 0); 468 ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 0, 3), 0); 469 ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 1, 0), -1); 470 ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 1, 1), -1); 471 ok_hex(Buffer[0], 0x060F874D); 472 473 Buffer[0] = 0x060F874D; 474 RtlInitializeBitMap(&BitMapHeader, Buffer, 8); 475 ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 1, 0), 1); 476 ok_hex(Buffer[0], 0x60f874f); 477 ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 1, 1), 4); 478 ok_hex(Buffer[0], 0x60f875f); 479 ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 1, 2), 5); 480 ok_hex(Buffer[0], 0x60f877f); 481 ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 2, 0), -1); 482 ok_hex(Buffer[0], 0x60f877f); 483 484 Buffer[0] = 0x060F874D; 485 RtlInitializeBitMap(&BitMapHeader, Buffer, 32); 486 ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 4, 0), 11); 487 ok_hex(Buffer[0], 0x60fff4d); 488 ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 5, 0), 20); 489 ok_hex(Buffer[0], 0x7ffff4d); 490 ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 4, 11), 27); 491 ok_hex(Buffer[0], 0x7fffff4d); 492 493 Buffer[0] = 0x060F874D; 494 ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 4, 12), 20); 495 ok_hex(Buffer[0], 0x6ff874d); 496 ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 2, 11), 11); 497 ok_hex(Buffer[0], 0x6ff9f4d); 498 ok_int(RtlFindClearBitsAndSet(&BitMapHeader, 2, 12), 13); 499 ok_hex(Buffer[0], 0x6ffff4d); 500 FreeGuarded(Buffer); 501 } 502 503 void 504 Test_RtlFindSetBitsAndClear(void) 505 { 506 RTL_BITMAP BitMapHeader; 507 ULONG *Buffer; 508 509 Buffer = AllocateGuarded(2 * sizeof(*Buffer)); 510 Buffer[0] = 0xF9F078B2; 511 Buffer[1] = 0x3F303F30; 512 513 RtlInitializeBitMap(&BitMapHeader, Buffer, 0); 514 ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 0, 0), 0); 515 ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 0, 3), 0); 516 ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 1, 0), -1); 517 ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 1, 1), -1); 518 ok_hex(Buffer[0], 0xF9F078B2); 519 520 Buffer[0] = 0xF9F078B2; 521 RtlInitializeBitMap(&BitMapHeader, Buffer, 8); 522 ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 1, 0), 1); 523 ok_hex(Buffer[0], 0xf9f078b0); 524 ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 1, 1), 4); 525 ok_hex(Buffer[0], 0xf9f078a0); 526 ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 1, 2), 5); 527 ok_hex(Buffer[0], 0xf9f07880); 528 ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 2, 0), -1); 529 ok_hex(Buffer[0], 0xf9f07880); 530 531 Buffer[0] = 0xF9F078B2; 532 RtlInitializeBitMap(&BitMapHeader, Buffer, 32); 533 ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 4, 0), 11); 534 ok_hex(Buffer[0], 0xf9f000b2); 535 ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 5, 0), 20); 536 ok_hex(Buffer[0], 0xf80000b2); 537 ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 4, 11), 27); 538 ok_hex(Buffer[0], 0x800000b2); 539 540 Buffer[0] = 0xF9F078B2; 541 ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 4, 12), 20); 542 ok_hex(Buffer[0], 0xf90078b2); 543 ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 2, 11), 11); 544 ok_hex(Buffer[0], 0xf90060b2); 545 ok_int(RtlFindSetBitsAndClear(&BitMapHeader, 2, 12), 13); 546 ok_hex(Buffer[0], 0xf90000b2); 547 FreeGuarded(Buffer); 548 } 549 550 void 551 Test_RtlFindNextForwardRunClear(void) 552 { 553 RTL_BITMAP BitMapHeader; 554 ULONG *Buffer; 555 ULONG Index; 556 557 Buffer = AllocateGuarded(2 * sizeof(*Buffer)); 558 Buffer[0] = 0xF9F078B2; 559 Buffer[1] = 0x3F303F30; 560 561 RtlInitializeBitMap(&BitMapHeader, Buffer, 0); 562 ok_int(RtlFindNextForwardRunClear(&BitMapHeader, 0, &Index), 0); 563 ok_int(Index, 0); 564 ok_int(RtlFindNextForwardRunClear(&BitMapHeader, 1, &Index), 0); 565 ok_int(Index, 1); 566 567 Index = -1; 568 RtlInitializeBitMap(&BitMapHeader, Buffer, 8); 569 ok_int(RtlFindNextForwardRunClear(&BitMapHeader, 0, &Index), 1); 570 ok_int(Index, 0); 571 ok_int(RtlFindNextForwardRunClear(&BitMapHeader, 1, &Index), 2); 572 ok_int(Index, 2); 573 ok_int(RtlFindNextForwardRunClear(&BitMapHeader, 7, &Index), 0); 574 ok_int(Index, 8); 575 ok_int(RtlFindNextForwardRunClear(&BitMapHeader, 17, &Index), 0); 576 ok_int(Index, 17); 577 ok_int(RtlFindNextForwardRunClear(&BitMapHeader, 39, &Index), 0); 578 ok_int(Index, 39); 579 FreeGuarded(Buffer); 580 } 581 582 void 583 Test_RtlFindFirstRunClear(void) 584 { 585 } 586 587 void 588 Test_RtlFindLastBackwardRunClear(void) 589 { 590 } 591 592 void 593 Test_RtlFindClearRuns(void) 594 { 595 } 596 597 void 598 Test_RtlFindLongestRunClear(void) 599 { 600 } 601 602 603 START_TEST(RtlBitmap) 604 { 605 /* Windows 2003 has broken bitmap code that modifies the buffer */ 606 if (!IsWindows7OrGreater() && !IsReactOS()) 607 { 608 IsBroken = TRUE; 609 } 610 611 Test_RtlFindMostSignificantBit(); 612 Test_RtlFindLeastSignificantBit(); 613 Test_RtlInitializeBitMap(); 614 Test_RtlClearAllBits(); 615 Test_RtlSetAllBits(); 616 Test_RtlClearBits(); 617 Test_RtlSetBits(); 618 Test_RtlAreBitsClear(); 619 Test_RtlAreBitsSet(); 620 Test_RtlNumberOfSetBits(); 621 Test_RtlNumberOfClearBits(); 622 Test_RtlFindClearBits(); 623 Test_RtlFindSetBits(); 624 Test_RtlFindClearBitsAndSet(); 625 Test_RtlFindSetBitsAndClear(); 626 Test_RtlFindNextForwardRunClear(); 627 Test_RtlFindFirstRunClear(); 628 Test_RtlFindLastBackwardRunClear(); 629 Test_RtlFindClearRuns(); 630 Test_RtlFindLongestRunClear(); 631 } 632 633