2002-08-16 00:08:40 +02:00
|
|
|
/* Unit test suite for Rtl bitmap functions
|
|
|
|
*
|
|
|
|
* Copyright 2002 Jon Griffiths
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* We use function pointers here as some of the bitmap functions exist only
|
|
|
|
* in later versions of ntdll.
|
|
|
|
*/
|
2003-09-06 01:08:26 +02:00
|
|
|
|
2004-08-14 02:42:12 +02:00
|
|
|
#include "ntdll_test.h"
|
2002-08-16 00:08:40 +02:00
|
|
|
|
2004-09-01 03:29:18 +02:00
|
|
|
#ifdef __WINE_WINTERNL_H
|
|
|
|
|
2002-08-16 00:08:40 +02:00
|
|
|
/* Function ptrs for ordinal calls */
|
|
|
|
static HMODULE hntdll = 0;
|
|
|
|
static VOID (WINAPI *pRtlInitializeBitMap)(PRTL_BITMAP,LPBYTE,ULONG);
|
|
|
|
static VOID (WINAPI *pRtlSetAllBits)(PRTL_BITMAP);
|
|
|
|
static VOID (WINAPI *pRtlClearAllBits)(PRTL_BITMAP);
|
|
|
|
static VOID (WINAPI *pRtlSetBits)(PRTL_BITMAP,ULONG,ULONG);
|
|
|
|
static VOID (WINAPI *pRtlClearBits)(PRTL_BITMAP,ULONG,ULONG);
|
|
|
|
static BOOLEAN (WINAPI *pRtlAreBitsSet)(PRTL_BITMAP,ULONG,ULONG);
|
|
|
|
static BOOLEAN (WINAPI *pRtlAreBitsClear)(PRTL_BITMAP,ULONG,ULONG);
|
|
|
|
static ULONG (WINAPI *pRtlFindSetBitsAndClear)(PRTL_BITMAP,ULONG,ULONG);
|
|
|
|
static ULONG (WINAPI *pRtlFindClearBitsAndSet)(PRTL_BITMAP,ULONG,ULONG);
|
|
|
|
static CCHAR (WINAPI *pRtlFindMostSignificantBit)(ULONGLONG);
|
|
|
|
static CCHAR (WINAPI *pRtlFindLeastSignificantBit)(ULONGLONG);
|
|
|
|
static ULONG (WINAPI *pRtlFindSetRuns)(PRTL_BITMAP,PRTL_BITMAP_RUN,ULONG,BOOLEAN);
|
|
|
|
static ULONG (WINAPI *pRtlFindClearRuns)(PRTL_BITMAP,PRTL_BITMAP_RUN,ULONG,BOOLEAN);
|
|
|
|
static ULONG (WINAPI *pRtlNumberOfSetBits)(PRTL_BITMAP);
|
|
|
|
static ULONG (WINAPI *pRtlNumberOfClearBits)(PRTL_BITMAP);
|
|
|
|
static ULONG (WINAPI *pRtlFindLongestRunSet)(PRTL_BITMAP,PULONG);
|
|
|
|
static ULONG (WINAPI *pRtlFindLongestRunClear)(PRTL_BITMAP,PULONG);
|
|
|
|
|
|
|
|
static BYTE buff[256];
|
|
|
|
static RTL_BITMAP bm;
|
|
|
|
|
2005-06-16 17:52:44 +02:00
|
|
|
static void InitFunctionPtrs(void)
|
2002-08-16 00:08:40 +02:00
|
|
|
{
|
|
|
|
hntdll = LoadLibraryA("ntdll.dll");
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(hntdll != 0, "LoadLibrary failed\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
if (hntdll)
|
|
|
|
{
|
|
|
|
pRtlInitializeBitMap = (void *)GetProcAddress(hntdll, "RtlInitializeBitMap");
|
|
|
|
pRtlSetAllBits = (void *)GetProcAddress(hntdll, "RtlSetAllBits");
|
|
|
|
pRtlClearAllBits = (void *)GetProcAddress(hntdll, "RtlClearAllBits");
|
|
|
|
pRtlSetBits = (void *)GetProcAddress(hntdll, "RtlSetBits");
|
|
|
|
pRtlClearBits = (void *)GetProcAddress(hntdll, "RtlClearBits");
|
|
|
|
pRtlAreBitsSet = (void *)GetProcAddress(hntdll, "RtlAreBitsSet");
|
|
|
|
pRtlAreBitsClear = (void *)GetProcAddress(hntdll, "RtlAreBitsClear");
|
|
|
|
pRtlNumberOfSetBits = (void *)GetProcAddress(hntdll, "RtlNumberOfSetBits");
|
|
|
|
pRtlNumberOfClearBits = (void *)GetProcAddress(hntdll, "RtlNumberOfClearBits");
|
|
|
|
pRtlFindSetBitsAndClear = (void *)GetProcAddress(hntdll, "RtlFindSetBitsAndClear");
|
|
|
|
pRtlFindClearBitsAndSet = (void *)GetProcAddress(hntdll, "RtlFindClearBitsAndSet");
|
|
|
|
pRtlFindMostSignificantBit = (void *)GetProcAddress(hntdll, "RtlFindMostSignificantBit");
|
|
|
|
pRtlFindLeastSignificantBit = (void *)GetProcAddress(hntdll, "RtlFindLeastSignificantBit");
|
|
|
|
pRtlFindSetRuns = (void *)GetProcAddress(hntdll, "RtlFindSetRuns");
|
|
|
|
pRtlFindClearRuns = (void *)GetProcAddress(hntdll, "RtlFindClearRuns");
|
|
|
|
pRtlFindLongestRunSet = (void *)GetProcAddress(hntdll, "RtlFindLongestRunSet");
|
|
|
|
pRtlFindLongestRunClear = (void *)GetProcAddress(hntdll, "RtlFindLongestRunClear");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_RtlInitializeBitMap(void)
|
|
|
|
{
|
|
|
|
bm.SizeOfBitMap = 0;
|
2004-08-23 20:52:54 +02:00
|
|
|
bm.Buffer = 0;
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
memset(buff, 0, sizeof(buff));
|
|
|
|
buff[0] = 77; /* Check buffer is not written to during init */
|
|
|
|
buff[79] = 77;
|
|
|
|
|
|
|
|
pRtlInitializeBitMap(&bm, buff, 800);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(bm.SizeOfBitMap == 800, "size uninitialised\n");
|
2004-08-23 20:52:54 +02:00
|
|
|
ok(bm.Buffer == (PULONG)buff,"buffer uninitialised\n");
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(buff[0] == 77 && buff[79] == 77, "wrote to buffer\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_RtlSetAllBits(void)
|
|
|
|
{
|
|
|
|
if (!pRtlSetAllBits)
|
|
|
|
return;
|
|
|
|
|
|
|
|
memset(buff, 0 , sizeof(buff));
|
|
|
|
pRtlInitializeBitMap(&bm, buff, 1);
|
|
|
|
|
|
|
|
pRtlSetAllBits(&bm);
|
|
|
|
ok(buff[0] == 0xff && buff[1] == 0xff && buff[2] == 0xff &&
|
2004-02-07 02:02:48 +01:00
|
|
|
buff[3] == 0xff, "didn't round up size\n");
|
|
|
|
ok(buff[4] == 0, "set more than rounded size\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
}
|
|
|
|
|
2005-06-16 17:52:44 +02:00
|
|
|
static void test_RtlClearAllBits(void)
|
2002-08-16 00:08:40 +02:00
|
|
|
{
|
|
|
|
if (!pRtlClearAllBits)
|
|
|
|
return;
|
|
|
|
|
|
|
|
memset(buff, 0xff , sizeof(buff));
|
|
|
|
pRtlInitializeBitMap(&bm, buff, 1);
|
|
|
|
|
|
|
|
pRtlClearAllBits(&bm);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(!buff[0] && !buff[1] && !buff[2] && !buff[3], "didn't round up size\n");
|
|
|
|
ok(buff[4] == 0xff, "cleared more than rounded size\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
}
|
|
|
|
|
2005-06-16 17:52:44 +02:00
|
|
|
static void test_RtlSetBits(void)
|
2002-08-16 00:08:40 +02:00
|
|
|
{
|
|
|
|
if (!pRtlSetBits)
|
|
|
|
return;
|
|
|
|
|
|
|
|
memset(buff, 0 , sizeof(buff));
|
|
|
|
pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
|
|
|
|
|
|
|
|
pRtlSetBits(&bm, 0, 1);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(buff[0] == 1, "didn't set 1st bit\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
buff[0] = 0;
|
|
|
|
pRtlSetBits(&bm, 7, 2);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(buff[0] == 0x80 && buff[1] == 1, "didn't span w/len < 8\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
buff[0] = buff[1] = 0;
|
|
|
|
pRtlSetBits(&bm, 7, 10);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(buff[0] == 0x80 && buff[1] == 0xff && buff[2] == 1, "didn't span w/len > 8\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
buff[0] = buff[1] = buff[2] = 0;
|
|
|
|
pRtlSetBits(&bm, 0, 8); /* 1st byte */
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(buff[0] == 0xff, "didn't set all bits\n");
|
|
|
|
ok(!buff[1], "set too many bits\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
pRtlSetBits(&bm, sizeof(buff)*8-1, 1); /* last bit */
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(buff[sizeof(buff)-1] == 0x80, "didn't set last bit\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
}
|
|
|
|
|
2005-06-16 17:52:44 +02:00
|
|
|
static void test_RtlClearBits(void)
|
2002-08-16 00:08:40 +02:00
|
|
|
{
|
|
|
|
if (!pRtlClearBits)
|
|
|
|
return;
|
|
|
|
|
|
|
|
memset(buff, 0xff , sizeof(buff));
|
|
|
|
pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
|
|
|
|
|
|
|
|
pRtlClearBits(&bm, 0, 1);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(buff[0] == 0xfe, "didn't clear 1st bit\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
buff[0] = 0xff;
|
|
|
|
pRtlClearBits(&bm, 7, 2);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(buff[0] == 0x7f && buff[1] == 0xfe, "didn't span w/len < 8\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
buff[0] = buff[1] = 0xff;
|
|
|
|
pRtlClearBits(&bm, 7, 10);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(buff[0] == 0x7f && buff[1] == 0 && buff[2] == 0xfe, "didn't span w/len > 8\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
buff[0] = buff[1] = buff[2] = 0xff;
|
|
|
|
pRtlClearBits(&bm, 0, 8); /* 1st byte */
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(!buff[0], "didn't clear all bits\n");
|
|
|
|
ok(buff[1] == 0xff, "cleared too many bits\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
pRtlClearBits(&bm, sizeof(buff)*8-1, 1);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(buff[sizeof(buff)-1] == 0x7f, "didn't set last bit\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
}
|
|
|
|
|
2005-06-16 17:52:44 +02:00
|
|
|
static void test_RtlCheckBit(void)
|
2002-08-16 00:08:40 +02:00
|
|
|
{
|
|
|
|
BOOLEAN bRet;
|
|
|
|
|
|
|
|
memset(buff, 0 , sizeof(buff));
|
|
|
|
pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
|
|
|
|
pRtlSetBits(&bm, 0, 1);
|
|
|
|
pRtlSetBits(&bm, 7, 2);
|
|
|
|
pRtlSetBits(&bm, sizeof(buff)*8-1, 1);
|
|
|
|
|
|
|
|
bRet = RtlCheckBit(&bm, 0);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok (bRet, "didn't find set bit\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
bRet = RtlCheckBit(&bm, 7);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok (bRet, "didn't find set bit\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
bRet = RtlCheckBit(&bm, 8);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok (bRet, "didn't find set bit\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
bRet = RtlCheckBit(&bm, sizeof(buff)*8-1);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok (bRet, "didn't find set bit\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
bRet = RtlCheckBit(&bm, 1);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok (!bRet, "found non set bit\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
bRet = RtlCheckBit(&bm, sizeof(buff)*8-2);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok (!bRet, "found non set bit\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
}
|
|
|
|
|
2005-06-16 17:52:44 +02:00
|
|
|
static void test_RtlAreBitsSet(void)
|
2002-08-16 00:08:40 +02:00
|
|
|
{
|
|
|
|
BOOLEAN bRet;
|
|
|
|
|
|
|
|
if (!pRtlAreBitsSet)
|
|
|
|
return;
|
|
|
|
|
|
|
|
memset(buff, 0 , sizeof(buff));
|
|
|
|
pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
|
|
|
|
|
|
|
|
bRet = pRtlAreBitsSet(&bm, 0, 1);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok (!bRet, "found set bits after init\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
pRtlSetBits(&bm, 0, 1);
|
|
|
|
bRet = pRtlAreBitsSet(&bm, 0, 1);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok (bRet, "didn't find set bits\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
buff[0] = 0;
|
|
|
|
pRtlSetBits(&bm, 7, 2);
|
|
|
|
bRet = pRtlAreBitsSet(&bm, 7, 2);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(bRet, "didn't find w/len < 8\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
bRet = pRtlAreBitsSet(&bm, 6, 3);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(!bRet, "found non set bit\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
bRet = pRtlAreBitsSet(&bm, 7, 3);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(!bRet, "found non set bit\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
buff[0] = buff[1] = 0;
|
|
|
|
pRtlSetBits(&bm, 7, 10);
|
|
|
|
bRet = pRtlAreBitsSet(&bm, 7, 10);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(bRet, "didn't find w/len < 8\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
bRet = pRtlAreBitsSet(&bm, 6, 11);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(!bRet, "found non set bit\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
bRet = pRtlAreBitsSet(&bm, 7, 11);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(!bRet, "found non set bit\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
buff[0] = buff[1] = buff[2] = 0;
|
|
|
|
pRtlSetBits(&bm, 0, 8); /* 1st byte */
|
|
|
|
bRet = pRtlAreBitsSet(&bm, 0, 8);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(bRet, "didn't find whole byte\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
pRtlSetBits(&bm, sizeof(buff)*8-1, 1);
|
|
|
|
bRet = pRtlAreBitsSet(&bm, sizeof(buff)*8-1, 1);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(bRet, "didn't find last bit\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
}
|
|
|
|
|
2005-06-16 17:52:44 +02:00
|
|
|
static void test_RtlAreBitsClear(void)
|
2002-08-16 00:08:40 +02:00
|
|
|
{
|
|
|
|
BOOLEAN bRet;
|
|
|
|
|
|
|
|
if (!pRtlAreBitsClear)
|
|
|
|
return;
|
|
|
|
|
|
|
|
memset(buff, 0xff , sizeof(buff));
|
|
|
|
pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
|
|
|
|
|
|
|
|
bRet = pRtlAreBitsClear(&bm, 0, 1);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok (!bRet, "found clear bits after init\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
pRtlClearBits(&bm, 0, 1);
|
|
|
|
bRet = pRtlAreBitsClear(&bm, 0, 1);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok (bRet, "didn't find set bits\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
buff[0] = 0xff;
|
|
|
|
pRtlClearBits(&bm, 7, 2);
|
|
|
|
bRet = pRtlAreBitsClear(&bm, 7, 2);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(bRet, "didn't find w/len < 8\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
bRet = pRtlAreBitsClear(&bm, 6, 3);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(!bRet, "found non clear bit\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
bRet = pRtlAreBitsClear(&bm, 7, 3);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(!bRet, "found non clear bit\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
buff[0] = buff[1] = 0xff;
|
|
|
|
pRtlClearBits(&bm, 7, 10);
|
|
|
|
bRet = pRtlAreBitsClear(&bm, 7, 10);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(bRet, "didn't find w/len < 8\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
bRet = pRtlAreBitsClear(&bm, 6, 11);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(!bRet, "found non clear bit\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
bRet = pRtlAreBitsClear(&bm, 7, 11);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(!bRet, "found non clear bit\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
buff[0] = buff[1] = buff[2] = 0xff;
|
|
|
|
pRtlClearBits(&bm, 0, 8); /* 1st byte */
|
|
|
|
bRet = pRtlAreBitsClear(&bm, 0, 8);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(bRet, "didn't find whole byte\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
pRtlClearBits(&bm, sizeof(buff)*8-1, 1);
|
|
|
|
bRet = pRtlAreBitsClear(&bm, sizeof(buff)*8-1, 1);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(bRet, "didn't find last bit\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
}
|
|
|
|
|
2005-06-16 17:52:44 +02:00
|
|
|
static void test_RtlNumberOfSetBits(void)
|
2002-08-16 00:08:40 +02:00
|
|
|
{
|
|
|
|
ULONG ulCount;
|
|
|
|
|
|
|
|
if (!pRtlNumberOfSetBits)
|
|
|
|
return;
|
|
|
|
|
|
|
|
memset(buff, 0 , sizeof(buff));
|
|
|
|
pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
|
|
|
|
|
|
|
|
ulCount = pRtlNumberOfSetBits(&bm);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(ulCount == 0, "set bits after init\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
pRtlSetBits(&bm, 0, 1); /* Set 1st bit */
|
|
|
|
ulCount = pRtlNumberOfSetBits(&bm);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(ulCount == 1, "count wrong\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
pRtlSetBits(&bm, 7, 8); /* 8 more, spanning bytes 1-2 */
|
|
|
|
ulCount = pRtlNumberOfSetBits(&bm);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(ulCount == 8+1, "count wrong\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
pRtlSetBits(&bm, 17, 33); /* 33 more crossing ULONG boundary */
|
|
|
|
ulCount = pRtlNumberOfSetBits(&bm);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(ulCount == 8+1+33, "count wrong\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
pRtlSetBits(&bm, sizeof(buff)*8-1, 1); /* Set last bit */
|
|
|
|
ulCount = pRtlNumberOfSetBits(&bm);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(ulCount == 8+1+33+1, "count wrong\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
}
|
|
|
|
|
2005-06-16 17:52:44 +02:00
|
|
|
static void test_RtlNumberOfClearBits(void)
|
2002-08-16 00:08:40 +02:00
|
|
|
{
|
|
|
|
ULONG ulCount;
|
|
|
|
|
|
|
|
if (!pRtlNumberOfClearBits)
|
|
|
|
return;
|
|
|
|
|
|
|
|
memset(buff, 0xff , sizeof(buff));
|
|
|
|
pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
|
|
|
|
|
|
|
|
ulCount = pRtlNumberOfClearBits(&bm);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(ulCount == 0, "cleared bits after init\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
pRtlClearBits(&bm, 0, 1); /* Set 1st bit */
|
|
|
|
ulCount = pRtlNumberOfClearBits(&bm);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(ulCount == 1, "count wrong\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
pRtlClearBits(&bm, 7, 8); /* 8 more, spanning bytes 1-2 */
|
|
|
|
ulCount = pRtlNumberOfClearBits(&bm);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(ulCount == 8+1, "count wrong\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
pRtlClearBits(&bm, 17, 33); /* 33 more crossing ULONG boundary */
|
|
|
|
ulCount = pRtlNumberOfClearBits(&bm);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(ulCount == 8+1+33, "count wrong\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
pRtlClearBits(&bm, sizeof(buff)*8-1, 1); /* Set last bit */
|
|
|
|
ulCount = pRtlNumberOfClearBits(&bm);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(ulCount == 8+1+33+1, "count wrong\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Note: this tests RtlFindSetBits also */
|
2005-06-16 17:52:44 +02:00
|
|
|
static void test_RtlFindSetBitsAndClear(void)
|
2002-08-16 00:08:40 +02:00
|
|
|
{
|
|
|
|
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);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok (ulPos == 0, "didn't find bits\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
if(ulPos == 0)
|
|
|
|
{
|
|
|
|
bRet = pRtlAreBitsClear(&bm, 0, 32);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok (bRet, "found but didn't clear\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
memset(buff, 0 , sizeof(buff));
|
|
|
|
pRtlSetBits(&bm, 40, 77);
|
|
|
|
ulPos = pRtlFindSetBitsAndClear(&bm, 77, 0);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok (ulPos == 40, "didn't find bits\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
if(ulPos == 40)
|
|
|
|
{
|
|
|
|
bRet = pRtlAreBitsClear(&bm, 40, 77);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok (bRet, "found but didn't clear\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Note: this tests RtlFindClearBits also */
|
2005-06-16 17:52:44 +02:00
|
|
|
static void test_RtlFindClearBitsAndSet(void)
|
2002-08-16 00:08:40 +02:00
|
|
|
{
|
|
|
|
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);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok (ulPos == 0, "didn't find bits\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
if(ulPos == 0)
|
|
|
|
{
|
|
|
|
bRet = pRtlAreBitsClear(&bm, 0, 32);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok (bRet, "found but didn't clear\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
memset(buff, 0xff , sizeof(buff));
|
|
|
|
pRtlClearBits(&bm, 40, 77);
|
|
|
|
ulPos = pRtlFindClearBitsAndSet(&bm, 77, 50);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok (ulPos == 40, "didn't find bits\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
if(ulPos == 40)
|
|
|
|
{
|
|
|
|
bRet = pRtlAreBitsSet(&bm, 40, 77);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok (bRet, "found but didn't set\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-16 17:52:44 +02:00
|
|
|
static void test_RtlFindMostSignificantBit(void)
|
2002-08-16 00:08:40 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
CCHAR cPos;
|
|
|
|
ULONGLONG ulLong;
|
|
|
|
|
|
|
|
if (!pRtlFindMostSignificantBit)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < 64; i++)
|
|
|
|
{
|
|
|
|
ulLong = 1ul;
|
|
|
|
ulLong <<= i;
|
|
|
|
|
|
|
|
cPos = pRtlFindMostSignificantBit(ulLong);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok (cPos == i, "didn't find MSB %llx %d %d\n", ulLong, i, cPos);
|
2003-02-19 00:22:49 +01:00
|
|
|
|
|
|
|
/* Set all bits lower than bit i */
|
|
|
|
ulLong = ((ulLong - 1) << 1) | 1;
|
|
|
|
|
|
|
|
cPos = pRtlFindMostSignificantBit(ulLong);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok (cPos == i, "didn't find MSB %llx %d %d\n", ulLong, i, cPos);
|
2002-08-16 00:08:40 +02:00
|
|
|
}
|
|
|
|
cPos = pRtlFindMostSignificantBit(0);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok (cPos == -1, "found bit when not set\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
}
|
|
|
|
|
2005-06-16 17:52:44 +02:00
|
|
|
static void test_RtlFindLeastSignificantBit(void)
|
2002-08-16 00:08:40 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
CCHAR cPos;
|
|
|
|
ULONGLONG ulLong;
|
|
|
|
|
|
|
|
if (!pRtlFindLeastSignificantBit)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < 64; i++)
|
|
|
|
{
|
2003-03-18 21:01:45 +01:00
|
|
|
ulLong = (ULONGLONG)1 << i;
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
cPos = pRtlFindLeastSignificantBit(ulLong);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok (cPos == i, "didn't find LSB %llx %d %d\n", ulLong, i, cPos);
|
2003-02-19 00:22:49 +01:00
|
|
|
|
2003-03-18 21:01:45 +01:00
|
|
|
ulLong = ~((ULONGLONG)0) << i;
|
2003-02-19 00:22:49 +01:00
|
|
|
|
|
|
|
cPos = pRtlFindLeastSignificantBit(ulLong);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok (cPos == i, "didn't find LSB %llx %d %d\n", ulLong, i, cPos);
|
2002-08-16 00:08:40 +02:00
|
|
|
}
|
|
|
|
cPos = pRtlFindLeastSignificantBit(0);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok (cPos == -1, "found bit when not set\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Note: Also tests RtlFindLongestRunSet() */
|
2005-06-16 17:52:44 +02:00
|
|
|
static void test_RtlFindSetRuns(void)
|
2002-08-16 00:08:40 +02:00
|
|
|
{
|
|
|
|
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);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok (ulCount == 0, "found set bits in empty bitmap\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
memset(runs, 0, sizeof(runs));
|
|
|
|
memset(buff, 0xff, sizeof(buff));
|
|
|
|
ulCount = pRtlFindSetRuns(&bm, runs, 16, TRUE);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok (ulCount == 1, "didn't find set bits\n");
|
2004-08-23 20:52:54 +02:00
|
|
|
ok (runs[0].StartingIndex == 0,"bad start\n");
|
|
|
|
ok (runs[0].NumberOfBits == sizeof(buff)*8,"bad size\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
/* 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);
|
2004-08-23 20:52:54 +02:00
|
|
|
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");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
/* Get longest 3 */
|
|
|
|
memset(runs, 0, sizeof(runs));
|
|
|
|
ulCount = pRtlFindSetRuns(&bm, runs, 2, TRUE);
|
2004-08-23 20:52:54 +02:00
|
|
|
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");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
/* Get all 3 */
|
|
|
|
memset(runs, 0, sizeof(runs));
|
|
|
|
ulCount = pRtlFindSetRuns(&bm, runs, 3, TRUE);
|
2004-08-23 20:52:54 +02:00
|
|
|
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");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
if (pRtlFindLongestRunSet)
|
|
|
|
{
|
|
|
|
ULONG ulStart = 0;
|
|
|
|
|
|
|
|
ulCount = pRtlFindLongestRunSet(&bm, &ulStart);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(ulCount == 33 && ulStart == 1877,"didn't find longest %ld %ld\n",ulCount,ulStart);
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
memset(buff, 0, sizeof(buff));
|
|
|
|
ulCount = pRtlFindLongestRunSet(&bm, &ulStart);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(ulCount == 0,"found longest when none set\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Note: Also tests RtlFindLongestRunClear() */
|
2005-06-16 17:52:44 +02:00
|
|
|
static void test_RtlFindClearRuns(void)
|
2002-08-16 00:08:40 +02:00
|
|
|
{
|
|
|
|
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);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok (ulCount == 0, "found clear bits in full bitmap\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
memset(runs, 0, sizeof(runs));
|
|
|
|
memset(buff, 0, sizeof(buff));
|
|
|
|
ulCount = pRtlFindClearRuns(&bm, runs, 16, TRUE);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok (ulCount == 1, "didn't find clear bits\n");
|
2004-08-23 20:52:54 +02:00
|
|
|
ok (runs[0].StartingIndex == 0,"bad start\n");
|
|
|
|
ok (runs[0].NumberOfBits == sizeof(buff)*8,"bad size\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
/* 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);
|
2004-08-23 20:52:54 +02:00
|
|
|
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");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
/* Get longest 3 */
|
|
|
|
memset(runs, 0, sizeof(runs));
|
|
|
|
ulCount = pRtlFindClearRuns(&bm, runs, 2, TRUE);
|
2004-08-23 20:52:54 +02:00
|
|
|
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");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
/* Get all 3 */
|
|
|
|
memset(runs, 0, sizeof(runs));
|
|
|
|
ulCount = pRtlFindClearRuns(&bm, runs, 3, TRUE);
|
2004-08-23 20:52:54 +02:00
|
|
|
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");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
if (pRtlFindLongestRunClear)
|
|
|
|
{
|
|
|
|
ULONG ulStart = 0;
|
|
|
|
|
|
|
|
ulCount = pRtlFindLongestRunClear(&bm, &ulStart);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(ulCount == 33 && ulStart == 1877,"didn't find longest\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
memset(buff, 0xff, sizeof(buff));
|
|
|
|
ulCount = pRtlFindLongestRunClear(&bm, &ulStart);
|
2004-02-07 02:02:48 +01:00
|
|
|
ok(ulCount == 0,"found longest when none clear\n");
|
2002-08-16 00:08:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2004-09-01 03:29:18 +02:00
|
|
|
#endif
|
2002-08-16 00:08:40 +02:00
|
|
|
|
|
|
|
START_TEST(rtlbitmap)
|
|
|
|
{
|
2004-09-01 03:29:18 +02:00
|
|
|
#ifdef __WINE_WINTERNL_H
|
2002-08-16 00:08:40 +02:00
|
|
|
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();
|
|
|
|
}
|
2004-09-01 03:29:18 +02:00
|
|
|
#endif
|
2002-08-16 00:08:40 +02:00
|
|
|
}
|