usp10/tests: A spelling fix in an ok() message.
[wine.git] / dlls / ntdll / tests / rtlbitmap.c
blob3c3992e8fc9aabefae18689b0c540440c55ae308
1 /* Unit test suite for Rtl bitmap functions
3 * Copyright 2002 Jon Griffiths
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 * NOTES
20 * We use function pointers here as some of the bitmap functions exist only
21 * in later versions of ntdll.
24 #include "ntdll_test.h"
26 #ifdef __WINE_WINTERNL_H
28 /* Function ptrs for ordinal calls */
29 static HMODULE hntdll = 0;
30 static VOID (WINAPI *pRtlInitializeBitMap)(PRTL_BITMAP,LPBYTE,ULONG);
31 static VOID (WINAPI *pRtlSetAllBits)(PRTL_BITMAP);
32 static VOID (WINAPI *pRtlClearAllBits)(PRTL_BITMAP);
33 static VOID (WINAPI *pRtlSetBits)(PRTL_BITMAP,ULONG,ULONG);
34 static VOID (WINAPI *pRtlClearBits)(PRTL_BITMAP,ULONG,ULONG);
35 static BOOLEAN (WINAPI *pRtlAreBitsSet)(PRTL_BITMAP,ULONG,ULONG);
36 static BOOLEAN (WINAPI *pRtlAreBitsClear)(PRTL_BITMAP,ULONG,ULONG);
37 static ULONG (WINAPI *pRtlFindSetBitsAndClear)(PRTL_BITMAP,ULONG,ULONG);
38 static ULONG (WINAPI *pRtlFindClearBitsAndSet)(PRTL_BITMAP,ULONG,ULONG);
39 static CCHAR (WINAPI *pRtlFindMostSignificantBit)(ULONGLONG);
40 static CCHAR (WINAPI *pRtlFindLeastSignificantBit)(ULONGLONG);
41 static ULONG (WINAPI *pRtlFindSetRuns)(PRTL_BITMAP,PRTL_BITMAP_RUN,ULONG,BOOLEAN);
42 static ULONG (WINAPI *pRtlFindClearRuns)(PRTL_BITMAP,PRTL_BITMAP_RUN,ULONG,BOOLEAN);
43 static ULONG (WINAPI *pRtlFindNextForwardRunSet)(PRTL_BITMAP,ULONG,PULONG);
44 static ULONG (WINAPI *pRtlFindNextForwardRunClear)(PRTL_BITMAP,ULONG,PULONG);
45 static ULONG (WINAPI *pRtlNumberOfSetBits)(PRTL_BITMAP);
46 static ULONG (WINAPI *pRtlNumberOfClearBits)(PRTL_BITMAP);
47 static ULONG (WINAPI *pRtlFindLongestRunSet)(PRTL_BITMAP,PULONG);
48 static ULONG (WINAPI *pRtlFindLongestRunClear)(PRTL_BITMAP,PULONG);
50 static BYTE buff[256];
51 static RTL_BITMAP bm;
53 static void InitFunctionPtrs(void)
55 hntdll = LoadLibraryA("ntdll.dll");
56 ok(hntdll != 0, "LoadLibrary failed\n");
57 if (hntdll)
59 pRtlInitializeBitMap = (void *)GetProcAddress(hntdll, "RtlInitializeBitMap");
60 pRtlSetAllBits = (void *)GetProcAddress(hntdll, "RtlSetAllBits");
61 pRtlClearAllBits = (void *)GetProcAddress(hntdll, "RtlClearAllBits");
62 pRtlSetBits = (void *)GetProcAddress(hntdll, "RtlSetBits");
63 pRtlClearBits = (void *)GetProcAddress(hntdll, "RtlClearBits");
64 pRtlAreBitsSet = (void *)GetProcAddress(hntdll, "RtlAreBitsSet");
65 pRtlAreBitsClear = (void *)GetProcAddress(hntdll, "RtlAreBitsClear");
66 pRtlNumberOfSetBits = (void *)GetProcAddress(hntdll, "RtlNumberOfSetBits");
67 pRtlNumberOfClearBits = (void *)GetProcAddress(hntdll, "RtlNumberOfClearBits");
68 pRtlFindSetBitsAndClear = (void *)GetProcAddress(hntdll, "RtlFindSetBitsAndClear");
69 pRtlFindClearBitsAndSet = (void *)GetProcAddress(hntdll, "RtlFindClearBitsAndSet");
70 pRtlFindMostSignificantBit = (void *)GetProcAddress(hntdll, "RtlFindMostSignificantBit");
71 pRtlFindLeastSignificantBit = (void *)GetProcAddress(hntdll, "RtlFindLeastSignificantBit");
72 pRtlFindSetRuns = (void *)GetProcAddress(hntdll, "RtlFindSetRuns");
73 pRtlFindClearRuns = (void *)GetProcAddress(hntdll, "RtlFindClearRuns");
74 pRtlFindNextForwardRunSet = (void *)GetProcAddress(hntdll, "RtlFindNextForwardRunSet");
75 pRtlFindNextForwardRunClear = (void *)GetProcAddress(hntdll, "RtlFindNextForwardRunClear");
76 pRtlFindLongestRunSet = (void *)GetProcAddress(hntdll, "RtlFindLongestRunSet");
77 pRtlFindLongestRunClear = (void *)GetProcAddress(hntdll, "RtlFindLongestRunClear");
81 static void test_RtlInitializeBitMap(void)
83 bm.SizeOfBitMap = 0;
84 bm.Buffer = 0;
86 memset(buff, 0, sizeof(buff));
87 buff[0] = 77; /* Check buffer is not written to during init */
88 buff[79] = 77;
90 pRtlInitializeBitMap(&bm, buff, 800);
91 ok(bm.SizeOfBitMap == 800, "size uninitialised\n");
92 ok(bm.Buffer == (PULONG)buff,"buffer uninitialised\n");
93 ok(buff[0] == 77 && buff[79] == 77, "wrote to buffer\n");
96 static void test_RtlSetAllBits(void)
98 if (!pRtlSetAllBits)
99 return;
101 memset(buff, 0 , sizeof(buff));
102 pRtlInitializeBitMap(&bm, buff, 1);
104 pRtlSetAllBits(&bm);
105 ok(buff[0] == 0xff && buff[1] == 0xff && buff[2] == 0xff &&
106 buff[3] == 0xff, "didn't round up size\n");
107 ok(buff[4] == 0, "set more than rounded size\n");
110 static void test_RtlClearAllBits(void)
112 if (!pRtlClearAllBits)
113 return;
115 memset(buff, 0xff , sizeof(buff));
116 pRtlInitializeBitMap(&bm, buff, 1);
118 pRtlClearAllBits(&bm);
119 ok(!buff[0] && !buff[1] && !buff[2] && !buff[3], "didn't round up size\n");
120 ok(buff[4] == 0xff, "cleared more than rounded size\n");
123 static void test_RtlSetBits(void)
125 if (!pRtlSetBits)
126 return;
128 memset(buff, 0 , sizeof(buff));
129 pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
131 pRtlSetBits(&bm, 0, 1);
132 ok(buff[0] == 1, "didn't set 1st bit\n");
134 buff[0] = 0;
135 pRtlSetBits(&bm, 7, 2);
136 ok(buff[0] == 0x80 && buff[1] == 1, "didn't span w/len < 8\n");
138 buff[0] = buff[1] = 0;
139 pRtlSetBits(&bm, 7, 10);
140 ok(buff[0] == 0x80 && buff[1] == 0xff && buff[2] == 1, "didn't span w/len > 8\n");
142 buff[0] = buff[1] = buff[2] = 0;
143 pRtlSetBits(&bm, 0, 8); /* 1st byte */
144 ok(buff[0] == 0xff, "didn't set all bits\n");
145 ok(!buff[1], "set too many bits\n");
147 pRtlSetBits(&bm, sizeof(buff)*8-1, 1); /* last bit */
148 ok(buff[sizeof(buff)-1] == 0x80, "didn't set last bit\n");
151 static void test_RtlClearBits(void)
153 if (!pRtlClearBits)
154 return;
156 memset(buff, 0xff , sizeof(buff));
157 pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
159 pRtlClearBits(&bm, 0, 1);
160 ok(buff[0] == 0xfe, "didn't clear 1st bit\n");
162 buff[0] = 0xff;
163 pRtlClearBits(&bm, 7, 2);
164 ok(buff[0] == 0x7f && buff[1] == 0xfe, "didn't span w/len < 8\n");
166 buff[0] = buff[1] = 0xff;
167 pRtlClearBits(&bm, 7, 10);
168 ok(buff[0] == 0x7f && buff[1] == 0 && buff[2] == 0xfe, "didn't span w/len > 8\n");
170 buff[0] = buff[1] = buff[2] = 0xff;
171 pRtlClearBits(&bm, 0, 8); /* 1st byte */
172 ok(!buff[0], "didn't clear all bits\n");
173 ok(buff[1] == 0xff, "cleared too many bits\n");
175 pRtlClearBits(&bm, sizeof(buff)*8-1, 1);
176 ok(buff[sizeof(buff)-1] == 0x7f, "didn't set last bit\n");
179 static void test_RtlCheckBit(void)
181 BOOLEAN bRet;
183 memset(buff, 0 , sizeof(buff));
184 pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
185 pRtlSetBits(&bm, 0, 1);
186 pRtlSetBits(&bm, 7, 2);
187 pRtlSetBits(&bm, sizeof(buff)*8-1, 1);
189 bRet = RtlCheckBit(&bm, 0);
190 ok (bRet, "didn't find set bit\n");
191 bRet = RtlCheckBit(&bm, 7);
192 ok (bRet, "didn't find set bit\n");
193 bRet = RtlCheckBit(&bm, 8);
194 ok (bRet, "didn't find set bit\n");
195 bRet = RtlCheckBit(&bm, sizeof(buff)*8-1);
196 ok (bRet, "didn't find set bit\n");
197 bRet = RtlCheckBit(&bm, 1);
198 ok (!bRet, "found non set bit\n");
199 bRet = RtlCheckBit(&bm, sizeof(buff)*8-2);
200 ok (!bRet, "found non set bit\n");
203 static void test_RtlAreBitsSet(void)
205 BOOLEAN bRet;
207 if (!pRtlAreBitsSet)
208 return;
210 memset(buff, 0 , sizeof(buff));
211 pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
213 bRet = pRtlAreBitsSet(&bm, 0, 1);
214 ok (!bRet, "found set bits after init\n");
216 pRtlSetBits(&bm, 0, 1);
217 bRet = pRtlAreBitsSet(&bm, 0, 1);
218 ok (bRet, "didn't find set bits\n");
220 buff[0] = 0;
221 pRtlSetBits(&bm, 7, 2);
222 bRet = pRtlAreBitsSet(&bm, 7, 2);
223 ok(bRet, "didn't find w/len < 8\n");
224 bRet = pRtlAreBitsSet(&bm, 6, 3);
225 ok(!bRet, "found non set bit\n");
226 bRet = pRtlAreBitsSet(&bm, 7, 3);
227 ok(!bRet, "found non set bit\n");
229 buff[0] = buff[1] = 0;
230 pRtlSetBits(&bm, 7, 10);
231 bRet = pRtlAreBitsSet(&bm, 7, 10);
232 ok(bRet, "didn't find w/len < 8\n");
233 bRet = pRtlAreBitsSet(&bm, 6, 11);
234 ok(!bRet, "found non set bit\n");
235 bRet = pRtlAreBitsSet(&bm, 7, 11);
236 ok(!bRet, "found non set bit\n");
238 buff[0] = buff[1] = buff[2] = 0;
239 pRtlSetBits(&bm, 0, 8); /* 1st byte */
240 bRet = pRtlAreBitsSet(&bm, 0, 8);
241 ok(bRet, "didn't find whole byte\n");
243 pRtlSetBits(&bm, sizeof(buff)*8-1, 1);
244 bRet = pRtlAreBitsSet(&bm, sizeof(buff)*8-1, 1);
245 ok(bRet, "didn't find last bit\n");
248 static void test_RtlAreBitsClear(void)
250 BOOLEAN bRet;
252 if (!pRtlAreBitsClear)
253 return;
255 memset(buff, 0xff , sizeof(buff));
256 pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
258 bRet = pRtlAreBitsClear(&bm, 0, 1);
259 ok (!bRet, "found clear bits after init\n");
261 pRtlClearBits(&bm, 0, 1);
262 bRet = pRtlAreBitsClear(&bm, 0, 1);
263 ok (bRet, "didn't find set bits\n");
265 buff[0] = 0xff;
266 pRtlClearBits(&bm, 7, 2);
267 bRet = pRtlAreBitsClear(&bm, 7, 2);
268 ok(bRet, "didn't find w/len < 8\n");
269 bRet = pRtlAreBitsClear(&bm, 6, 3);
270 ok(!bRet, "found non clear bit\n");
271 bRet = pRtlAreBitsClear(&bm, 7, 3);
272 ok(!bRet, "found non clear bit\n");
274 buff[0] = buff[1] = 0xff;
275 pRtlClearBits(&bm, 7, 10);
276 bRet = pRtlAreBitsClear(&bm, 7, 10);
277 ok(bRet, "didn't find w/len < 8\n");
278 bRet = pRtlAreBitsClear(&bm, 6, 11);
279 ok(!bRet, "found non clear bit\n");
280 bRet = pRtlAreBitsClear(&bm, 7, 11);
281 ok(!bRet, "found non clear bit\n");
283 buff[0] = buff[1] = buff[2] = 0xff;
284 pRtlClearBits(&bm, 0, 8); /* 1st byte */
285 bRet = pRtlAreBitsClear(&bm, 0, 8);
286 ok(bRet, "didn't find whole byte\n");
288 pRtlClearBits(&bm, sizeof(buff)*8-1, 1);
289 bRet = pRtlAreBitsClear(&bm, sizeof(buff)*8-1, 1);
290 ok(bRet, "didn't find last bit\n");
293 static void test_RtlNumberOfSetBits(void)
295 ULONG ulCount;
297 if (!pRtlNumberOfSetBits)
298 return;
300 memset(buff, 0 , sizeof(buff));
301 pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
303 ulCount = pRtlNumberOfSetBits(&bm);
304 ok(ulCount == 0, "set bits after init\n");
306 pRtlSetBits(&bm, 0, 1); /* Set 1st bit */
307 ulCount = pRtlNumberOfSetBits(&bm);
308 ok(ulCount == 1, "count wrong\n");
310 pRtlSetBits(&bm, 7, 8); /* 8 more, spanning bytes 1-2 */
311 ulCount = pRtlNumberOfSetBits(&bm);
312 ok(ulCount == 8+1, "count wrong\n");
314 pRtlSetBits(&bm, 17, 33); /* 33 more crossing ULONG boundary */
315 ulCount = pRtlNumberOfSetBits(&bm);
316 ok(ulCount == 8+1+33, "count wrong\n");
318 pRtlSetBits(&bm, sizeof(buff)*8-1, 1); /* Set last bit */
319 ulCount = pRtlNumberOfSetBits(&bm);
320 ok(ulCount == 8+1+33+1, "count wrong\n");
323 static void test_RtlNumberOfClearBits(void)
325 ULONG ulCount;
327 if (!pRtlNumberOfClearBits)
328 return;
330 memset(buff, 0xff , sizeof(buff));
331 pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
333 ulCount = pRtlNumberOfClearBits(&bm);
334 ok(ulCount == 0, "cleared bits after init\n");
336 pRtlClearBits(&bm, 0, 1); /* Set 1st bit */
337 ulCount = pRtlNumberOfClearBits(&bm);
338 ok(ulCount == 1, "count wrong\n");
340 pRtlClearBits(&bm, 7, 8); /* 8 more, spanning bytes 1-2 */
341 ulCount = pRtlNumberOfClearBits(&bm);
342 ok(ulCount == 8+1, "count wrong\n");
344 pRtlClearBits(&bm, 17, 33); /* 33 more crossing ULONG boundary */
345 ulCount = pRtlNumberOfClearBits(&bm);
346 ok(ulCount == 8+1+33, "count wrong\n");
348 pRtlClearBits(&bm, sizeof(buff)*8-1, 1); /* Set last bit */
349 ulCount = pRtlNumberOfClearBits(&bm);
350 ok(ulCount == 8+1+33+1, "count wrong\n");
353 /* Note: this tests RtlFindSetBits also */
354 static void test_RtlFindSetBitsAndClear(void)
356 BOOLEAN bRet;
357 ULONG ulPos;
359 if (!pRtlFindSetBitsAndClear)
360 return;
362 memset(buff, 0, sizeof(buff));
363 pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
365 pRtlSetBits(&bm, 0, 32);
366 ulPos = pRtlFindSetBitsAndClear(&bm, 32, 0);
367 ok (ulPos == 0, "didn't find bits\n");
368 if(ulPos == 0)
370 bRet = pRtlAreBitsClear(&bm, 0, 32);
371 ok (bRet, "found but didn't clear\n");
374 memset(buff, 0 , sizeof(buff));
375 pRtlSetBits(&bm, 40, 77);
376 ulPos = pRtlFindSetBitsAndClear(&bm, 77, 0);
377 ok (ulPos == 40, "didn't find bits\n");
378 if(ulPos == 40)
380 bRet = pRtlAreBitsClear(&bm, 40, 77);
381 ok (bRet, "found but didn't clear\n");
385 /* Note: this tests RtlFindClearBits also */
386 static void test_RtlFindClearBitsAndSet(void)
388 BOOLEAN bRet;
389 ULONG ulPos;
391 if (!pRtlFindClearBitsAndSet)
392 return;
394 pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
396 memset(buff, 0xff, sizeof(buff));
397 pRtlSetBits(&bm, 0, 32);
398 ulPos = pRtlFindSetBitsAndClear(&bm, 32, 0);
399 ok (ulPos == 0, "didn't find bits\n");
400 if(ulPos == 0)
402 bRet = pRtlAreBitsClear(&bm, 0, 32);
403 ok (bRet, "found but didn't clear\n");
406 memset(buff, 0xff , sizeof(buff));
407 pRtlClearBits(&bm, 40, 77);
408 ulPos = pRtlFindClearBitsAndSet(&bm, 77, 50);
409 ok (ulPos == 40, "didn't find bits\n");
410 if(ulPos == 40)
412 bRet = pRtlAreBitsSet(&bm, 40, 77);
413 ok (bRet, "found but didn't set\n");
417 static void test_RtlFindMostSignificantBit(void)
419 int i;
420 signed char cPos;
421 ULONGLONG ulLong;
423 if (!pRtlFindMostSignificantBit)
424 return;
426 for (i = 0; i < 64; i++)
428 ulLong = 1ul;
429 ulLong <<= i;
431 cPos = pRtlFindMostSignificantBit(ulLong);
432 ok (cPos == i, "didn't find MSB 0x%s %d %d\n",
433 wine_dbgstr_longlong(ulLong ), i, cPos);
435 /* Set all bits lower than bit i */
436 ulLong = ((ulLong - 1) << 1) | 1;
438 cPos = pRtlFindMostSignificantBit(ulLong);
439 ok (cPos == i, "didn't find MSB 0x%s %d %d\n",
440 wine_dbgstr_longlong(ulLong ), i, cPos);
442 cPos = pRtlFindMostSignificantBit(0);
443 ok (cPos == -1, "found bit when not set\n");
446 static void test_RtlFindLeastSignificantBit(void)
448 int i;
449 signed char cPos;
450 ULONGLONG ulLong;
452 if (!pRtlFindLeastSignificantBit)
453 return;
455 for (i = 0; i < 64; i++)
457 ulLong = (ULONGLONG)1 << i;
459 cPos = pRtlFindLeastSignificantBit(ulLong);
460 ok (cPos == i, "didn't find LSB 0x%s %d %d\n",
461 wine_dbgstr_longlong(ulLong ), i, cPos);
463 ulLong = ~((ULONGLONG)0) << i;
465 cPos = pRtlFindLeastSignificantBit(ulLong);
466 ok (cPos == i, "didn't find LSB 0x%s %d %d\n",
467 wine_dbgstr_longlong(ulLong ), i, cPos);
469 cPos = pRtlFindLeastSignificantBit(0);
470 ok (cPos == -1, "found bit when not set\n");
473 /* Note: Also tests RtlFindLongestRunSet() */
474 static void test_RtlFindSetRuns(void)
476 RTL_BITMAP_RUN runs[16];
477 ULONG ulCount;
479 if (!pRtlFindSetRuns)
480 return;
482 pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
484 memset(buff, 0, sizeof(buff));
485 ulCount = pRtlFindSetRuns(&bm, runs, 16, TRUE);
486 ok (ulCount == 0, "found set bits in empty bitmap\n");
488 memset(runs, 0, sizeof(runs));
489 memset(buff, 0xff, sizeof(buff));
490 ulCount = pRtlFindSetRuns(&bm, runs, 16, TRUE);
491 ok (ulCount == 1, "didn't find set bits\n");
492 ok (runs[0].StartingIndex == 0,"bad start\n");
493 ok (runs[0].NumberOfBits == sizeof(buff)*8,"bad size\n");
495 /* Set up 3 runs */
496 memset(runs, 0, sizeof(runs));
497 memset(buff, 0, sizeof(buff));
498 pRtlSetBits(&bm, 7, 19);
499 pRtlSetBits(&bm, 101, 3);
500 pRtlSetBits(&bm, 1877, 33);
502 /* Get first 2 */
503 ulCount = pRtlFindSetRuns(&bm, runs, 2, FALSE);
504 ok(ulCount == 2, "RtlFindClearRuns returned %d, expected 2\n", ulCount);
505 ok (runs[0].StartingIndex == 7 || runs[0].StartingIndex == 101,"bad find\n");
506 ok (runs[1].StartingIndex == 7 || runs[1].StartingIndex == 101,"bad find\n");
507 ok (runs[0].NumberOfBits + runs[1].NumberOfBits == 19 + 3,"bad size\n");
508 ok (runs[0].StartingIndex != runs[1].StartingIndex,"found run twice\n");
509 ok (runs[2].StartingIndex == 0,"found extra run\n");
511 /* Get longest 3 */
512 memset(runs, 0, sizeof(runs));
513 ulCount = pRtlFindSetRuns(&bm, runs, 2, TRUE);
514 ok(ulCount == 2, "RtlFindClearRuns returned %d, expected 2\n", ulCount);
515 ok (runs[0].StartingIndex == 7 || runs[0].StartingIndex == 1877,"bad find\n");
516 ok (runs[1].StartingIndex == 7 || runs[1].StartingIndex == 1877,"bad find\n");
517 ok (runs[0].NumberOfBits + runs[1].NumberOfBits == 33 + 19,"bad size\n");
518 ok (runs[0].StartingIndex != runs[1].StartingIndex,"found run twice\n");
519 ok (runs[2].StartingIndex == 0,"found extra run\n");
521 /* Get all 3 */
522 memset(runs, 0, sizeof(runs));
523 ulCount = pRtlFindSetRuns(&bm, runs, 3, TRUE);
524 ok(ulCount == 3, "RtlFindClearRuns returned %d, expected 3\n", ulCount);
525 ok (runs[0].StartingIndex == 7 || runs[0].StartingIndex == 101 ||
526 runs[0].StartingIndex == 1877,"bad find\n");
527 ok (runs[1].StartingIndex == 7 || runs[1].StartingIndex == 101 ||
528 runs[1].StartingIndex == 1877,"bad find\n");
529 ok (runs[2].StartingIndex == 7 || runs[2].StartingIndex == 101 ||
530 runs[2].StartingIndex == 1877,"bad find\n");
531 ok (runs[0].NumberOfBits + runs[1].NumberOfBits
532 + runs[2].NumberOfBits == 19 + 3 + 33,"bad size\n");
533 ok (runs[0].StartingIndex != runs[1].StartingIndex,"found run twice\n");
534 ok (runs[1].StartingIndex != runs[2].StartingIndex,"found run twice\n");
535 ok (runs[3].StartingIndex == 0,"found extra run\n");
537 if (pRtlFindLongestRunSet)
539 ULONG ulStart = 0;
541 ulCount = pRtlFindLongestRunSet(&bm, &ulStart);
542 ok(ulCount == 33 && ulStart == 1877,"didn't find longest %d %d\n",ulCount,ulStart);
544 memset(buff, 0, sizeof(buff));
545 ulCount = pRtlFindLongestRunSet(&bm, &ulStart);
546 ok(ulCount == 0,"found longest when none set\n");
550 /* Note: Also tests RtlFindLongestRunClear() */
551 static void test_RtlFindClearRuns(void)
553 RTL_BITMAP_RUN runs[16];
554 ULONG ulCount;
556 if (!pRtlFindClearRuns)
557 return;
559 pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
561 memset(buff, 0xff, sizeof(buff));
562 ulCount = pRtlFindClearRuns(&bm, runs, 16, TRUE);
563 ok (ulCount == 0, "found clear bits in full bitmap\n");
565 memset(runs, 0, sizeof(runs));
566 memset(buff, 0, sizeof(buff));
567 ulCount = pRtlFindClearRuns(&bm, runs, 16, TRUE);
568 ok (ulCount == 1, "didn't find clear bits\n");
569 ok (runs[0].StartingIndex == 0,"bad start\n");
570 ok (runs[0].NumberOfBits == sizeof(buff)*8,"bad size\n");
572 /* Set up 3 runs */
573 memset(runs, 0, sizeof(runs));
574 memset(buff, 0xff, sizeof(buff));
575 pRtlClearBits(&bm, 7, 19);
576 pRtlClearBits(&bm, 101, 3);
577 pRtlClearBits(&bm, 1877, 33);
579 /* Get first 2 */
580 ulCount = pRtlFindClearRuns(&bm, runs, 2, FALSE);
581 ok(ulCount == 2, "RtlFindClearRuns returned %d, expected 2\n", ulCount);
582 ok (runs[0].StartingIndex == 7 || runs[0].StartingIndex == 101,"bad find\n");
583 ok (runs[1].StartingIndex == 7 || runs[1].StartingIndex == 101,"bad find\n");
584 ok (runs[0].NumberOfBits + runs[1].NumberOfBits == 19 + 3,"bad size\n");
585 ok (runs[0].StartingIndex != runs[1].StartingIndex,"found run twice\n");
586 ok (runs[2].StartingIndex == 0,"found extra run\n");
588 /* Get longest 3 */
589 memset(runs, 0, sizeof(runs));
590 ulCount = pRtlFindClearRuns(&bm, runs, 2, TRUE);
591 ok(ulCount == 2, "RtlFindClearRuns returned %d, expected 2\n", ulCount);
592 ok (runs[0].StartingIndex == 7 || runs[0].StartingIndex == 1877,"bad find\n");
593 ok (runs[1].StartingIndex == 7 || runs[1].StartingIndex == 1877,"bad find\n");
594 ok (runs[0].NumberOfBits + runs[1].NumberOfBits == 33 + 19,"bad size\n");
595 ok (runs[0].StartingIndex != runs[1].StartingIndex,"found run twice\n");
596 ok (runs[2].StartingIndex == 0,"found extra run\n");
598 /* Get all 3 */
599 memset(runs, 0, sizeof(runs));
600 ulCount = pRtlFindClearRuns(&bm, runs, 3, TRUE);
601 ok(ulCount == 3, "RtlFindClearRuns returned %d, expected 3\n", ulCount);
602 ok (runs[0].StartingIndex == 7 || runs[0].StartingIndex == 101 ||
603 runs[0].StartingIndex == 1877,"bad find\n");
604 ok (runs[1].StartingIndex == 7 || runs[1].StartingIndex == 101 ||
605 runs[1].StartingIndex == 1877,"bad find\n");
606 ok (runs[2].StartingIndex == 7 || runs[2].StartingIndex == 101 ||
607 runs[2].StartingIndex == 1877,"bad find\n");
608 ok (runs[0].NumberOfBits + runs[1].NumberOfBits
609 + runs[2].NumberOfBits == 19 + 3 + 33,"bad size\n");
610 ok (runs[0].StartingIndex != runs[1].StartingIndex,"found run twice\n");
611 ok (runs[1].StartingIndex != runs[2].StartingIndex,"found run twice\n");
612 ok (runs[3].StartingIndex == 0,"found extra run\n");
614 if (pRtlFindLongestRunClear)
616 ULONG ulStart = 0;
618 ulCount = pRtlFindLongestRunClear(&bm, &ulStart);
619 ok(ulCount == 33 && ulStart == 1877,"didn't find longest\n");
621 memset(buff, 0xff, sizeof(buff));
622 ulCount = pRtlFindLongestRunClear(&bm, &ulStart);
623 ok(ulCount == 0,"found longest when none clear\n");
628 static void test_RtlFindNextForwardRunSet(void)
630 BYTE mask[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff };
631 ULONG ulStart = 0;
632 ULONG ulCount, lpPos;
633 if (!pRtlFindNextForwardRunSet)
634 return;
636 pRtlInitializeBitMap(&bm, mask, 62);
637 ulCount = pRtlFindNextForwardRunSet(&bm, ulStart, &lpPos);
638 ok(ulCount == 6, "Invalid length of found set run: %d, expected 6\n", ulCount);
639 ok(lpPos == 56, "Invalid position of found set run: %d, expected 56\n", lpPos);
642 static void test_RtlFindNextForwardRunClear(void)
644 BYTE mask[8] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 };
645 ULONG ulStart = 0;
646 ULONG ulCount, lpPos;
647 if (!pRtlFindNextForwardRunClear)
648 return;
650 pRtlInitializeBitMap(&bm, mask, 62);
651 ulCount = pRtlFindNextForwardRunClear(&bm, ulStart, &lpPos);
652 ok(ulCount == 6, "Invalid length of found clear run: %d, expected 6\n", ulCount);
653 ok(lpPos == 56, "Invalid position of found clear run: %d, expected 56\n", lpPos);
656 #endif
658 START_TEST(rtlbitmap)
660 #ifdef __WINE_WINTERNL_H
661 InitFunctionPtrs();
663 if (pRtlInitializeBitMap)
665 test_RtlInitializeBitMap();
666 test_RtlSetAllBits();
667 test_RtlClearAllBits();
668 test_RtlSetBits();
669 test_RtlClearBits();
670 test_RtlCheckBit();
671 test_RtlAreBitsSet();
672 test_RtlAreBitsClear();
673 test_RtlNumberOfSetBits();
674 test_RtlNumberOfClearBits();
675 test_RtlFindSetBitsAndClear();
676 test_RtlFindClearBitsAndSet();
677 test_RtlFindMostSignificantBit();
678 test_RtlFindLeastSignificantBit();
679 test_RtlFindSetRuns();
680 test_RtlFindClearRuns();
681 test_RtlFindNextForwardRunSet();
682 test_RtlFindNextForwardRunClear();
684 #endif