📄 rtlbitmap.c
字号:
if (!pRtlNumberOfClearBits)
return;
memset(buff, 0xff , sizeof(buff));
pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
ulCount = pRtlNumberOfClearBits(&bm);
ok(ulCount == 0, "cleared bits after init\n");
pRtlClearBits(&bm, 0, 1); /* Set 1st bit */
ulCount = pRtlNumberOfClearBits(&bm);
ok(ulCount == 1, "count wrong\n");
pRtlClearBits(&bm, 7, 8); /* 8 more, spanning bytes 1-2 */
ulCount = pRtlNumberOfClearBits(&bm);
ok(ulCount == 8+1, "count wrong\n");
pRtlClearBits(&bm, 17, 33); /* 33 more crossing ULONG boundary */
ulCount = pRtlNumberOfClearBits(&bm);
ok(ulCount == 8+1+33, "count wrong\n");
pRtlClearBits(&bm, sizeof(buff)*8-1, 1); /* Set last bit */
ulCount = pRtlNumberOfClearBits(&bm);
ok(ulCount == 8+1+33+1, "count wrong\n");
}
/* Note: this tests RtlFindSetBits also */
static void test_RtlFindSetBitsAndClear(void)
{
BOOLEAN bRet;
ULONG ulPos;
if (!pRtlFindSetBitsAndClear)
return;
memset(buff, 0, sizeof(buff));
pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
pRtlSetBits(&bm, 0, 32);
ulPos = pRtlFindSetBitsAndClear(&bm, 32, 0);
ok (ulPos == 0, "didn't find bits\n");
if(ulPos == 0)
{
bRet = pRtlAreBitsClear(&bm, 0, 32);
ok (bRet, "found but didn't clear\n");
}
memset(buff, 0 , sizeof(buff));
pRtlSetBits(&bm, 40, 77);
ulPos = pRtlFindSetBitsAndClear(&bm, 77, 0);
ok (ulPos == 40, "didn't find bits\n");
if(ulPos == 40)
{
bRet = pRtlAreBitsClear(&bm, 40, 77);
ok (bRet, "found but didn't clear\n");
}
}
/* Note: this tests RtlFindClearBits also */
static void test_RtlFindClearBitsAndSet(void)
{
BOOLEAN bRet;
ULONG ulPos;
if (!pRtlFindClearBitsAndSet)
return;
pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
memset(buff, 0xff, sizeof(buff));
pRtlSetBits(&bm, 0, 32);
ulPos = pRtlFindSetBitsAndClear(&bm, 32, 0);
ok (ulPos == 0, "didn't find bits\n");
if(ulPos == 0)
{
bRet = pRtlAreBitsClear(&bm, 0, 32);
ok (bRet, "found but didn't clear\n");
}
memset(buff, 0xff , sizeof(buff));
pRtlClearBits(&bm, 40, 77);
ulPos = pRtlFindClearBitsAndSet(&bm, 77, 50);
ok (ulPos == 40, "didn't find bits\n");
if(ulPos == 40)
{
bRet = pRtlAreBitsSet(&bm, 40, 77);
ok (bRet, "found but didn't set\n");
}
}
static void test_RtlFindMostSignificantBit(void)
{
int i;
CCHAR cPos;
ULONGLONG ulLong;
if (!pRtlFindMostSignificantBit)
return;
for (i = 0; i < 64; i++)
{
ulLong = 1ul;
ulLong <<= i;
cPos = pRtlFindMostSignificantBit(ulLong);
ok (cPos == i, "didn't find MSB %llx %d %d\n", ulLong, i, cPos);
/* Set all bits lower than bit i */
ulLong = ((ulLong - 1) << 1) | 1;
cPos = pRtlFindMostSignificantBit(ulLong);
ok (cPos == i, "didn't find MSB %llx %d %d\n", ulLong, i, cPos);
}
cPos = pRtlFindMostSignificantBit(0);
ok (cPos == -1, "found bit when not set\n");
}
static void test_RtlFindLeastSignificantBit(void)
{
int i;
CCHAR cPos;
ULONGLONG ulLong;
if (!pRtlFindLeastSignificantBit)
return;
for (i = 0; i < 64; i++)
{
ulLong = (ULONGLONG)1 << i;
cPos = pRtlFindLeastSignificantBit(ulLong);
ok (cPos == i, "didn't find LSB %llx %d %d\n", ulLong, i, cPos);
ulLong = ~((ULONGLONG)0) << i;
cPos = pRtlFindLeastSignificantBit(ulLong);
ok (cPos == i, "didn't find LSB %llx %d %d\n", ulLong, i, cPos);
}
cPos = pRtlFindLeastSignificantBit(0);
ok (cPos == -1, "found bit when not set\n");
}
/* Note: Also tests RtlFindLongestRunSet() */
static void test_RtlFindSetRuns(void)
{
RTL_BITMAP_RUN runs[16];
ULONG ulCount;
if (!pRtlFindSetRuns)
return;
pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
memset(buff, 0, sizeof(buff));
ulCount = pRtlFindSetRuns(&bm, runs, 16, TRUE);
ok (ulCount == 0, "found set bits in empty bitmap\n");
memset(runs, 0, sizeof(runs));
memset(buff, 0xff, sizeof(buff));
ulCount = pRtlFindSetRuns(&bm, runs, 16, TRUE);
ok (ulCount == 1, "didn't find set bits\n");
ok (runs[0].StartingIndex == 0,"bad start\n");
ok (runs[0].NumberOfBits == sizeof(buff)*8,"bad size\n");
/* Set up 3 runs */
memset(runs, 0, sizeof(runs));
memset(buff, 0, sizeof(buff));
pRtlSetBits(&bm, 7, 19);
pRtlSetBits(&bm, 101, 3);
pRtlSetBits(&bm, 1877, 33);
/* Get first 2 */
ulCount = pRtlFindSetRuns(&bm, runs, 2, FALSE);
ok (runs[0].StartingIndex == 7 || runs[0].StartingIndex == 101,"bad find\n");
ok (runs[1].StartingIndex == 7 || runs[1].StartingIndex == 101,"bad find\n");
ok (runs[0].NumberOfBits + runs[1].NumberOfBits == 19 + 3,"bad size\n");
ok (runs[0].StartingIndex != runs[1].StartingIndex,"found run twice\n");
ok (runs[2].StartingIndex == 0,"found extra run\n");
/* Get longest 3 */
memset(runs, 0, sizeof(runs));
ulCount = pRtlFindSetRuns(&bm, runs, 2, TRUE);
ok (runs[0].StartingIndex == 7 || runs[0].StartingIndex == 1877,"bad find\n");
ok (runs[1].StartingIndex == 7 || runs[1].StartingIndex == 1877,"bad find\n");
ok (runs[0].NumberOfBits + runs[1].NumberOfBits == 33 + 19,"bad size\n");
ok (runs[0].StartingIndex != runs[1].StartingIndex,"found run twice\n");
ok (runs[2].StartingIndex == 0,"found extra run\n");
/* Get all 3 */
memset(runs, 0, sizeof(runs));
ulCount = pRtlFindSetRuns(&bm, runs, 3, TRUE);
ok (runs[0].StartingIndex == 7 || runs[0].StartingIndex == 101 ||
runs[0].StartingIndex == 1877,"bad find\n");
ok (runs[1].StartingIndex == 7 || runs[1].StartingIndex == 101 ||
runs[1].StartingIndex == 1877,"bad find\n");
ok (runs[2].StartingIndex == 7 || runs[2].StartingIndex == 101 ||
runs[2].StartingIndex == 1877,"bad find\n");
ok (runs[0].NumberOfBits + runs[1].NumberOfBits
+ runs[2].NumberOfBits == 19 + 3 + 33,"bad size\n");
ok (runs[0].StartingIndex != runs[1].StartingIndex,"found run twice\n");
ok (runs[1].StartingIndex != runs[2].StartingIndex,"found run twice\n");
ok (runs[3].StartingIndex == 0,"found extra run\n");
if (pRtlFindLongestRunSet)
{
ULONG ulStart = 0;
ulCount = pRtlFindLongestRunSet(&bm, &ulStart);
ok(ulCount == 33 && ulStart == 1877,"didn't find longest %ld %ld\n",ulCount,ulStart);
memset(buff, 0, sizeof(buff));
ulCount = pRtlFindLongestRunSet(&bm, &ulStart);
ok(ulCount == 0,"found longest when none set\n");
}
}
/* Note: Also tests RtlFindLongestRunClear() */
static void test_RtlFindClearRuns(void)
{
RTL_BITMAP_RUN runs[16];
ULONG ulCount;
if (!pRtlFindClearRuns)
return;
pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
memset(buff, 0xff, sizeof(buff));
ulCount = pRtlFindClearRuns(&bm, runs, 16, TRUE);
ok (ulCount == 0, "found clear bits in full bitmap\n");
memset(runs, 0, sizeof(runs));
memset(buff, 0, sizeof(buff));
ulCount = pRtlFindClearRuns(&bm, runs, 16, TRUE);
ok (ulCount == 1, "didn't find clear bits\n");
ok (runs[0].StartingIndex == 0,"bad start\n");
ok (runs[0].NumberOfBits == sizeof(buff)*8,"bad size\n");
/* Set up 3 runs */
memset(runs, 0, sizeof(runs));
memset(buff, 0xff, sizeof(buff));
pRtlClearBits(&bm, 7, 19);
pRtlClearBits(&bm, 101, 3);
pRtlClearBits(&bm, 1877, 33);
/* Get first 2 */
ulCount = pRtlFindClearRuns(&bm, runs, 2, FALSE);
ok (runs[0].StartingIndex == 7 || runs[0].StartingIndex == 101,"bad find\n");
ok (runs[1].StartingIndex == 7 || runs[1].StartingIndex == 101,"bad find\n");
ok (runs[0].NumberOfBits + runs[1].NumberOfBits == 19 + 3,"bad size\n");
ok (runs[0].StartingIndex != runs[1].StartingIndex,"found run twice\n");
ok (runs[2].StartingIndex == 0,"found extra run\n");
/* Get longest 3 */
memset(runs, 0, sizeof(runs));
ulCount = pRtlFindClearRuns(&bm, runs, 2, TRUE);
ok (runs[0].StartingIndex == 7 || runs[0].StartingIndex == 1877,"bad find\n");
ok (runs[1].StartingIndex == 7 || runs[1].StartingIndex == 1877,"bad find\n");
ok (runs[0].NumberOfBits + runs[1].NumberOfBits == 33 + 19,"bad size\n");
ok (runs[0].StartingIndex != runs[1].StartingIndex,"found run twice\n");
ok (runs[2].StartingIndex == 0,"found extra run\n");
/* Get all 3 */
memset(runs, 0, sizeof(runs));
ulCount = pRtlFindClearRuns(&bm, runs, 3, TRUE);
ok (runs[0].StartingIndex == 7 || runs[0].StartingIndex == 101 ||
runs[0].StartingIndex == 1877,"bad find\n");
ok (runs[1].StartingIndex == 7 || runs[1].StartingIndex == 101 ||
runs[1].StartingIndex == 1877,"bad find\n");
ok (runs[2].StartingIndex == 7 || runs[2].StartingIndex == 101 ||
runs[2].StartingIndex == 1877,"bad find\n");
ok (runs[0].NumberOfBits + runs[1].NumberOfBits
+ runs[2].NumberOfBits == 19 + 3 + 33,"bad size\n");
ok (runs[0].StartingIndex != runs[1].StartingIndex,"found run twice\n");
ok (runs[1].StartingIndex != runs[2].StartingIndex,"found run twice\n");
ok (runs[3].StartingIndex == 0,"found extra run\n");
if (pRtlFindLongestRunClear)
{
ULONG ulStart = 0;
ulCount = pRtlFindLongestRunClear(&bm, &ulStart);
ok(ulCount == 33 && ulStart == 1877,"didn't find longest\n");
memset(buff, 0xff, sizeof(buff));
ulCount = pRtlFindLongestRunClear(&bm, &ulStart);
ok(ulCount == 0,"found longest when none clear\n");
}
}
#endif
START_TEST(rtlbitmap)
{
#ifdef __WINE_WINTERNL_H
InitFunctionPtrs();
if (pRtlInitializeBitMap)
{
test_RtlInitializeBitMap();
test_RtlSetAllBits();
test_RtlClearAllBits();
test_RtlSetBits();
test_RtlClearBits();
test_RtlCheckBit();
test_RtlAreBitsSet();
test_RtlAreBitsClear();
test_RtlNumberOfSetBits();
test_RtlNumberOfClearBits();
test_RtlFindSetBitsAndClear();
test_RtlFindClearBitsAndSet();
test_RtlFindMostSignificantBit();
test_RtlFindLeastSignificantBit();
test_RtlFindSetRuns();
test_RtlFindClearRuns();
}
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -